-
Notifications
You must be signed in to change notification settings - Fork 14
/
Regression.scala
73 lines (59 loc) · 3.37 KB
/
Regression.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.File
import edu.colorado.droidel.constants.DroidelConstants
import edu.colorado.droidel.driver.{AbsurdityIdentifier, AndroidAppTransformer, AndroidCGBuilder}
import edu.colorado.walautil.{Timer, Util}
import scala.collection.JavaConversions._
object Regression {
def main(args: Array[String]) = {
if (args.length == 0) sys.error("Usage: sbt test:run <android_jar>")
else {
val androidJar = new File(args(0))
assert(androidJar.exists(), s"Couldn't find Android JAR ${androidJar.getAbsolutePath()}")
val testPrefix = s"src${File.separator}test${File.separator}resources${File.separator}regression${File.separator}"
val tests =
Iterable("HoistTest1", "HoistTest2", "ProtectedCallback", "LifecycleAndInterfaceCallback", "ViewLookup",
"SupportFragment", "SystemService")
// our tests should have all the library dependencies included, so we don't need JPhantom
val useJPhantom = false
tests.foreach(test => {
val testPath = s"$testPrefix$test"
val droidelOutBinDir = new File(s"${testPath}/${DroidelConstants.DROIDEL_BIN_SUFFIX}")
// clear Droidel output if it already exists
if (droidelOutBinDir.exists()) Util.deleteAllFiles(droidelOutBinDir)
// generate stubs and a specialized harness for the app
val transformer = new AndroidAppTransformer(testPath, androidJar,
droidelHome = ".",
instrumentLibs = false,
useJPhantom = useJPhantom,
// we don't want to keep the generated source files for the stubs/harness
cleanupGeneratedFiles = true)
transformer.transformApp() // do it
// make sure Droidel did something
assert(droidelOutBinDir.exists(), s"No Droidel output found in ${droidelOutBinDir.getAbsolutePath()}")
// now, build a call graph and points-to analysis with the generated stubs/harness
val analysisScope = transformer.makeAnalysisScope(useHarness = true)
val timer = new Timer()
timer.start()
println("Building call graph")
val walaRes =
new AndroidCGBuilder(analysisScope, transformer.harnessClassName, transformer.harnessMethodName)
.makeAndroidCallGraph
timer.printTimeTaken("Building call graph")
val packagePrefix = test.toLowerCase
assert(walaRes.cg.exists(n => n.getMethod.getDeclaringClass.getName.toString.toLowerCase.contains(packagePrefix)),
"No application classes reachable in call graph!")
// walk over the call call graph / points-to analysis and check that they are free of absurdities
println("Checking for absurdities")
val absurdities = new AbsurdityIdentifier(transformer.harnessClassName).getAbsurdities(walaRes)
timer.printTimeTaken("Checking for absurdities")
assert(absurdities.isEmpty, s"After harness generation, expected no absurdities for test $test")
// clean up after ourselves
Util.deleteAllFiles(droidelOutBinDir)
if (useJPhantom) {
val jphantomBinDir = new File(s"${testPath}/${DroidelConstants.JPHANTOMIZED_BIN_SUFFIX}")
if (jphantomBinDir.exists()) Util.deleteAllFiles(jphantomBinDir)
}
})
}
}
}