OSDN Git Service

Remove TestRunner.success field / Make postCompileTest return void
[android-x86/dalvik.git] / libcore / tools / runner / java / dalvik / runner / DeviceDalvikVm.java
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package dalvik.runner;
18
19 import java.io.File;
20 import java.util.List;
21 import java.util.logging.Logger;
22
23 /**
24  * Execute tests on a Dalvik VM using an Android device or emulator.
25  */
26 final class DeviceDalvikVm extends Vm {
27
28     // TODO: Don't assume we can put files in /system/framework,
29     // so we can run on production devices.
30     private static final Classpath RUNTIME_SUPPORT_CLASSPATH = Classpath.of(
31             new File("/system/framework/core-tests.jar"),
32             new File("/system/framework/caliper.jar"),
33             new File("/system/framework/guava.jar"),
34             new File("/system/framework/jsr305.jar"));
35
36     private static final Logger logger = Logger.getLogger(DeviceDalvikVm.class.getName());
37
38     DeviceDalvikVm(Integer debugPort, long timeoutSeconds, File sdkJar,
39             File localTemp, List<String> additionalVmArgs,
40             boolean cleanBefore, boolean cleanAfter, File runnerDir) {
41         super(new EnvironmentDevice(cleanBefore, cleanAfter, debugPort, localTemp, runnerDir),
42                 timeoutSeconds, sdkJar, additionalVmArgs);
43     }
44
45     private EnvironmentDevice getEnvironmentDevice() {
46         return (EnvironmentDevice) environment;
47     }
48
49     @Override protected void postCompileTestRunner() {
50         postCompile("testrunner", environment.testRunnerClassesDir());
51     }
52
53     @Override protected void postCompileTest(TestRun testRun) {
54         postCompile(testRun.getQualifiedName(), environment.testClassesDir(testRun));
55     }
56
57     private void postCompile(String name, File dir) {
58         logger.fine("dex and push " + name);
59
60         // make the local dex (inside a jar)
61         File localDex = new File(dir.getPath() + ".jar");
62         new Dx().dex(localDex, Classpath.of(dir));
63
64         // post the local dex to the device
65         File deviceDex = deviceDexFile(name);
66         getEnvironmentDevice().adb.push(localDex, deviceDex);
67     }
68
69     private File deviceDexFile(String name) {
70         return new File(getEnvironmentDevice().runnerDir, name + ".jar");
71     }
72
73     @Override protected VmCommandBuilder newVmCommandBuilder(
74             File workingDirectory) {
75         // ignore the working directory; it's device-local and we can't easily
76         // set the working directory for commands run via adb shell.
77         return new VmCommandBuilder()
78                 .vmCommand("adb", "shell", "dalvikvm")
79                 .vmArgs("-Duser.name=root")
80                 .vmArgs("-Duser.language=en")
81                 .vmArgs("-Duser.region=US")
82                 .vmArgs("-Djavax.net.ssl.trustStore=/system/etc/security/cacerts.bks")
83                 .temp(getEnvironmentDevice().testTemp);
84     }
85
86     @Override protected Classpath getRuntimeSupportClasspath(TestRun testRun) {
87         Classpath classpath = new Classpath();
88         classpath.addAll(deviceDexFile(testRun.getQualifiedName()));
89         classpath.addAll(deviceDexFile("testrunner"));
90         classpath.addAll(RUNTIME_SUPPORT_CLASSPATH);
91         return classpath;
92     }
93 }