diff options
author | Elliott Hughes <enh@google.com> | 2010-02-17 15:46:05 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-02-17 15:46:05 -0800 |
commit | 84e78740de61045cfcb9c30a0f8582962fac3e8f (patch) | |
tree | 70a73f20eda4f87300a62d20ce5748be2cda6c47 /tools/runner/java | |
parent | 73c8bbb045404420ffe4440bb1c7c5578ca160a7 (diff) | |
download | libcore-84e78740de61045cfcb9c30a0f8582962fac3e8f.zip libcore-84e78740de61045cfcb9c30a0f8582962fac3e8f.tar.gz libcore-84e78740de61045cfcb9c30a0f8582962fac3e8f.tar.bz2 |
Make DalvikRunner work on production devices too.
Place pre-built .jar files in our lib/ directory, and dex/push them on demand.
Change DalvikRunner to somewhat reduce the number of different classpaths in
play. My feeling is that we just want one true classpath: we should build with
it on the host, we should run with it on the host, we should dex everything on
it, we should upload everything to the device, and we should run with it on the
device.
Also add a convenience script for running DalvikRunner. ("Vogar" is the
proposed open source name for DalvikRunner, which really isn't as
dalvikvm-specific as the name might imply.)
There's a noticeable performance regression here, so my next change will be to
add a cache.
Diffstat (limited to 'tools/runner/java')
-rw-r--r-- | tools/runner/java/dalvik/runner/CaliperFinder.java | 11 | ||||
-rw-r--r-- | tools/runner/java/dalvik/runner/DeviceDalvikVm.java | 36 | ||||
-rw-r--r-- | tools/runner/java/dalvik/runner/Dx.java | 2 | ||||
-rw-r--r-- | tools/runner/java/dalvik/runner/EnvironmentDevice.java | 1 | ||||
-rw-r--r-- | tools/runner/java/dalvik/runner/Mode.java | 19 |
5 files changed, 41 insertions, 28 deletions
diff --git a/tools/runner/java/dalvik/runner/CaliperFinder.java b/tools/runner/java/dalvik/runner/CaliperFinder.java index 094609a..3609471 100644 --- a/tools/runner/java/dalvik/runner/CaliperFinder.java +++ b/tools/runner/java/dalvik/runner/CaliperFinder.java @@ -41,15 +41,6 @@ class CaliperFinder extends NamingPatternCodeFinder { } public Classpath getRunnerClasspath() { - return Classpath.of( - // TODO: we should be able to work with a shipping SDK, not depend on out/... - // TODO: have a pre-packaged caliper-all.jar in our lib directory, with the jtreg stuff. - // external/caliper - new File("out/target/common/obj/JAVA_LIBRARIES/caliper_intermediates/classes.jar").getAbsoluteFile(), - // external/guava for external/caliper - new File("out/target/common/obj/JAVA_LIBRARIES/guava_intermediates/classes.jar").getAbsoluteFile(), - // external/jsr305 for external/guava - new File("out/target/common/obj/JAVA_LIBRARIES/jsr305_intermediates/classes.jar").getAbsoluteFile()); - + return new Classpath(); } } diff --git a/tools/runner/java/dalvik/runner/DeviceDalvikVm.java b/tools/runner/java/dalvik/runner/DeviceDalvikVm.java index fec3463..7bdf482 100644 --- a/tools/runner/java/dalvik/runner/DeviceDalvikVm.java +++ b/tools/runner/java/dalvik/runner/DeviceDalvikVm.java @@ -24,15 +24,6 @@ import java.util.logging.Logger; * Execute tests on a Dalvik VM using an Android device or emulator. */ final class DeviceDalvikVm extends Vm { - - // TODO: Don't assume we can put files in /system/framework, - // so we can run on production devices. - private static final Classpath RUNTIME_SUPPORT_CLASSPATH = Classpath.of( - new File("/system/framework/core-tests.jar"), - new File("/system/framework/caliper.jar"), - new File("/system/framework/guava.jar"), - new File("/system/framework/jsr305.jar")); - private static final Logger logger = Logger.getLogger(DeviceDalvikVm.class.getName()); DeviceDalvikVm(Integer debugPort, long timeoutSeconds, File sdkJar, @@ -47,7 +38,24 @@ final class DeviceDalvikVm extends Vm { } @Override protected void postCompileTestRunner() { + // TODO: does this really need to be a special case? postCompile("testrunner", environment.testRunnerClassesDir()); + + // dex everything on the classpath and push it to the device. + for (File classpathElement : testClasspath.getElements()) { + String name = basenameOfJar(classpathElement); + logger.fine("dex and push " + name); + // make the local dex (inside a jar) + // TODO: this is *really* expensive. we need a cache! + File outputFile = getEnvironmentDevice().testDir(name + ".jar"); + new Dx().dex(outputFile, Classpath.of(classpathElement)); + // push the local dex to the device + getEnvironmentDevice().adb.push(outputFile, deviceDexFile(name)); + } + } + + private String basenameOfJar(File jarFile) { + return jarFile.getName().replaceAll("\\.jar$", ""); } @Override protected void postCompileTest(TestRun testRun) { @@ -74,8 +82,12 @@ final class DeviceDalvikVm extends Vm { File workingDirectory) { // ignore the working directory; it's device-local and we can't easily // set the working directory for commands run via adb shell. + // TODO: we only *need* to set ANDROID_DATA on production devices. + // We set "user.home" to /sdcard because code might reasonably assume it can write to + // that directory. return new VmCommandBuilder() - .vmCommand("adb", "shell", "dalvikvm") + .vmCommand("adb", "shell", "ANDROID_DATA=/sdcard", "dalvikvm") + .vmArgs("-Duser.home=/sdcard") .vmArgs("-Duser.name=root") .vmArgs("-Duser.language=en") .vmArgs("-Duser.region=US") @@ -87,7 +99,9 @@ final class DeviceDalvikVm extends Vm { Classpath classpath = new Classpath(); classpath.addAll(deviceDexFile(testRun.getQualifiedName())); classpath.addAll(deviceDexFile("testrunner")); - classpath.addAll(RUNTIME_SUPPORT_CLASSPATH); + for (File testClasspathElement : testClasspath.getElements()) { + classpath.addAll(deviceDexFile(basenameOfJar(testClasspathElement))); + } return classpath; } } diff --git a/tools/runner/java/dalvik/runner/Dx.java b/tools/runner/java/dalvik/runner/Dx.java index 09772bd..1190bce 100644 --- a/tools/runner/java/dalvik/runner/Dx.java +++ b/tools/runner/java/dalvik/runner/Dx.java @@ -33,7 +33,7 @@ final class Dx { * yourself. * * Memory options pulled from build/core/definitions.mk to - * handle larged dx input when building dex for APK. + * handle large dx input when building dex for APK. */ new Command.Builder() .args("dx") diff --git a/tools/runner/java/dalvik/runner/EnvironmentDevice.java b/tools/runner/java/dalvik/runner/EnvironmentDevice.java index c44152d..9ac1c64 100644 --- a/tools/runner/java/dalvik/runner/EnvironmentDevice.java +++ b/tools/runner/java/dalvik/runner/EnvironmentDevice.java @@ -41,6 +41,7 @@ class EnvironmentDevice extends Environment { } adb.mkdir(runnerDir); adb.mkdir(testTemp); + adb.mkdir(new File("/sdcard/dalvik-cache")); // TODO: only necessary on production devices. if (debugPort != null) { adb.forwardTcp(debugPort, debugPort); } diff --git a/tools/runner/java/dalvik/runner/Mode.java b/tools/runner/java/dalvik/runner/Mode.java index c30e023..b4f851f 100644 --- a/tools/runner/java/dalvik/runner/Mode.java +++ b/tools/runner/java/dalvik/runner/Mode.java @@ -62,12 +62,15 @@ abstract class Mode { protected final Classpath testRunnerClasspath = new Classpath(); protected final Classpath testClasspath = Classpath.of( + new File("dalvik/libcore/tools/runner/lib/jsr305.jar"), + new File("dalvik/libcore/tools/runner/lib/guava.jar"), + new File("dalvik/libcore/tools/runner/lib/caliper.jar"), // TODO: we should be able to work with a shipping SDK, not depend on out/... - // dalvik/libcore for tests - new File("out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/classes.jar").getAbsoluteFile(), - // framework/base for tests - new File("out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar").getAbsoluteFile()); - + // dalvik/libcore/**/test/ for junit + // TODO: jar up just the junit classes and drop the jar in our lib/ directory. + new File("out/target/common/obj/JAVA_LIBRARIES/core-tests_intermediates/classes.jar").getAbsoluteFile()); + // framework/base for tests (TODO: for what exactly?) + //new File("out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar").getAbsoluteFile()); Mode(Environment environment, long timeoutSeconds, File sdkJar) { this.environment = environment; @@ -90,11 +93,15 @@ abstract class Mode { private void compileTestRunner() { logger.fine("build testrunner"); + Classpath classpath = new Classpath(); + classpath.addAll(testClasspath); + classpath.addAll(testRunnerClasspath); + File base = environment.testRunnerClassesDir(); new Mkdir().mkdirs(base); new Javac() .bootClasspath(sdkJar) - .classpath(testRunnerClasspath) + .classpath(classpath) .sourcepath(DalvikRunner.HOME_JAVA) .destination(base) .compile(testRunnerJava); |