[vogar] r299 committed - Adding back support for Dalvik....

5 views
Skip to first unread message

vo...@googlecode.com

unread,
Aug 5, 2014, 10:22:02 AM8/5/14
to voga...@googlegroups.com
Revision: 299
Author: nfu...@google.com
Date: Tue Aug 5 14:21:42 2014 UTC
Log: Adding back support for Dalvik.
Laying groundwork for 64-bit ART support (--var)
Fixing app_process / activity modes.
Refactoring / renaming classes to better
reflect their purpose.

--mode device and --mode host are for ART-only
releases.
--mode device_dalvik and --mode host_dalvik are
for Dalvik releases.
--mode device_art_kitkat and --mode host_art_kitkat
are for running ART on KitKat releases. Host mode
appears broken, not sure why.

--mode app_process is ART-specific now unless run with
an SDK.

--mode activity didn't appear to work. It works for
simple tests now with ART or with an SDK.

L introduced some changes to System property
behavior which broke TestEnvironment and have been
worked around.

http://code.google.com/p/vogar/source/detail?r=299

Added:
/trunk/src/vogar/Variant.java
/trunk/src/vogar/android/DeviceRuntime.java
/trunk/src/vogar/android/HostRuntime.java
Deleted:
/trunk/src/vogar/android/AppProcessMode.java
/trunk/src/vogar/android/DeviceDalvikVm.java
/trunk/src/vogar/android/HostDalvikVm.java
Modified:
/trunk/src/vogar/ModeId.java
/trunk/src/vogar/Run.java
/trunk/src/vogar/Vogar.java
/trunk/src/vogar/android/AndroidSdk.java
/trunk/src/vogar/target/TestEnvironment.java

=======================================
--- /dev/null
+++ /trunk/src/vogar/Variant.java Tue Aug 5 14:21:42 2014 UTC
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package vogar;
+
+/**
+ * Supported runtime variants. e.g. for selecting different architectures.
+ */
+public enum Variant {
+ /** 32-bit */
+ X32
+}
=======================================
--- /dev/null
+++ /trunk/src/vogar/android/DeviceRuntime.java Tue Aug 5 14:21:42 2014 UTC
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package vogar.android;
+
+import com.google.common.collect.Iterables;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import vogar.Action;
+import vogar.Variant;
+import vogar.Classpath;
+import vogar.Mode;
+import vogar.ModeId;
+import vogar.Run;
+import vogar.commands.VmCommandBuilder;
+import vogar.tasks.RunActionTask;
+import vogar.tasks.Task;
+
+/**
+ * Execute actions on an Android device or emulator using "app_process" or
the runtime directly.
+ */
+public final class DeviceRuntime implements Mode {
+ private final Run run;
+ private final ModeId modeId;
+
+ public DeviceRuntime(Run run, ModeId modeId, Variant variant) {
+ if (!modeId.isDevice() || !modeId.supportsVariant(variant)) {
+ throw new IllegalArgumentException("Unsupported mode:" +
modeId +
+ " or variant: " + variant);
+ }
+ this.run = run;
+ this.modeId = modeId;
+ }
+
+ @Override public Set<Task> installTasks() {
+ Set<Task> result = new HashSet<Task>();
+ // dex everything on the classpath and push it to the device.
+ for (File classpathElement : run.classpath.getElements()) {
+ dexAndPush(result, run.basenameOfJar(classpathElement),
+ classpathElement, null);
+ }
+ return result;
+ }
+
+ @Override public Set<Task> installActionTasks(Action action, File jar)
{
+ Set<Task> result = new HashSet<Task>();
+ dexAndPush(result, action.getName(), jar, action);
+ return result;
+ }
+
+ @Override public Task executeActionTask(Action action, boolean
useLargeTimeout) {
+ return new RunActionTask(run, action, useLargeTimeout);
+ }
+
+ private void dexAndPush(Set<Task> tasks, String name, File jar, Action
action) {
+ File localDex = run.localDexFile(name);
+ File deviceDex = run.targetDexFile(name);
+ Task dex = new DexTask(run.androidSdk, run.classpath,
run.benchmark, name, jar, action,
+ localDex);
+ tasks.add(dex);
+ tasks.add(run.target.pushTask(localDex,
deviceDex).afterSuccess(dex));
+ }
+
+ @Override public VmCommandBuilder newVmCommandBuilder(Action action,
File workingDirectory) {
+ List<String> vmCommand = new ArrayList<String>();
+ vmCommand.addAll(run.target.targetProcessPrefix(workingDirectory));
+ vmCommand.add(run.getAndroidData());
+ Iterables.addAll(vmCommand, run.invokeWith());
+ vmCommand.add(run.vmCommand);
+
+ // If you edit this, see also HostRuntime...
+ VmCommandBuilder vmCommandBuilder = new VmCommandBuilder(run.log)
+ .vmCommand(vmCommand)
+ .vmArgs("-Duser.home=" + run.deviceUserHome)
+ .maxLength(1024);
+ if (modeId == ModeId.APP_PROCESS) {
+ return vmCommandBuilder
+ .vmArgs(action.getUserDir().getPath())
+ .classpathViaProperty(true);
+ }
+
+ vmCommandBuilder
+ .vmArgs("-Duser.name=" + run.target.getDeviceUserName())
+ .vmArgs("-Duser.language=en")
+ .vmArgs("-Duser.region=US");
+
+ if (modeId == ModeId.DEVICE_ART_KITKAT) {
+ // Required for KitKat to select the ART runtime. Default is
Dalvik.
+ vmCommandBuilder.vmArgs("-XXlib:libart.so");
+ }
+ if (!run.benchmark) {
+ vmCommandBuilder.vmArgs("-Xverify:none");
+ vmCommandBuilder.vmArgs("-Xdexopt:none");
+ vmCommandBuilder.vmArgs("-Xcheck:jni");
+ }
+ // dalvikvm defaults to no limit, but the framework sets the limit
at 2000.
+ vmCommandBuilder.vmArgs("-Xjnigreflimit:2000");
+ return vmCommandBuilder;
+ }
+
+ @Override public Set<Task> cleanupTasks(Action action) {
+ return
Collections.singleton(run.target.rmTask(action.getUserDir()));
+ }
+
+ @Override public Classpath getRuntimeClasspath(Action action) {
+ Classpath result = new Classpath();
+ result.addAll(run.targetDexFile(action.getName()));
+ if (!run.benchmark) {
+ for (File classpathElement : run.classpath.getElements()) {
+
result.addAll(run.targetDexFile(run.basenameOfJar(classpathElement)));
+ }
+ }
+ // Note we intentionally do not add run.resourceClasspath on
+ // the device since it contains host path names.
+ return result;
+ }
+}
=======================================
--- /dev/null
+++ /trunk/src/vogar/android/HostRuntime.java Tue Aug 5 14:21:42 2014 UTC
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package vogar.android;
+
+import com.google.common.collect.Iterables;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import vogar.Action;
+import vogar.Classpath;
+import vogar.Mode;
+import vogar.ModeId;
+import vogar.Run;
+import vogar.Variant;
+import vogar.commands.VmCommandBuilder;
+import vogar.tasks.MkdirTask;
+import vogar.tasks.RunActionTask;
+import vogar.tasks.Task;
+
+/**
+ * Executes actions on a Dalvik or ART runtime on a Linux desktop.
+ */
+public final class HostRuntime implements Mode {
+ private final Run run;
+ private final ModeId modeId;
+
+ public HostRuntime(Run run, ModeId modeId, Variant variant) {
+ if (!modeId.isHost() || !modeId.supportsVariant(variant)) {
+ throw new IllegalArgumentException("Unsupported mode:" +
modeId +
+ " or variant: " + variant);
+ }
+ this.run = run;
+ this.modeId = modeId;
+ }
+
+ @Override public Task executeActionTask(Action action, boolean
useLargeTimeout) {
+ return new RunActionTask(run, action, useLargeTimeout);
+ }
+
+ private File dalvikCache() {
+ return run.localFile("android-data", run.dalvikCache);
+ }
+
+ @Override public Set<Task> installTasks() {
+ Set<Task> result = new HashSet<Task>();
+ for (File classpathElement : run.classpath.getElements()) {
+ String name = run.basenameOfJar(classpathElement);
+ result.add(new DexTask(run.androidSdk, run.classpath,
run.benchmark, name,
+ classpathElement, null, run.localDexFile(name)));
+ }
+ result.add(new MkdirTask(run.mkdir, dalvikCache()));
+ return result;
+ }
+
+ @Override public Set<Task> cleanupTasks(Action action) {
+ return Collections.emptySet();
+ }
+
+ @Override public Set<Task> installActionTasks(Action action, File jar)
{
+ return Collections.<Task>singleton(new DexTask(run.androidSdk,
Classpath.of(jar),
+ run.benchmark, action.getName(), jar, action,
run.localDexFile(action.getName())));
+ }
+
+ @Override public VmCommandBuilder newVmCommandBuilder(Action action,
File workingDirectory) {
+ String buildRoot = System.getenv("ANDROID_BUILD_TOP");
+
+ List<File> jars = new ArrayList<File>();
+ for (String jar : modeId.getJarNames()) {
+ jars.add(new File(buildRoot, "out/host/linux-x86/framework/" +
jar + ".jar"));
+ }
+ Classpath bootClasspath = Classpath.of(jars);
+
+ VmCommandBuilder builder = new VmCommandBuilder(run.log)
+ .userDir(workingDirectory)
+ .env("ANDROID_PRINTF_LOG", "tag")
+ .env("ANDROID_LOG_TAGS", "*:i")
+ .env("ANDROID_DATA", dalvikCache().getParent());
+
+ List<String> vmCommand = new ArrayList<String>();
+ Iterables.addAll(vmCommand, run.invokeWith());
+
+ vmCommand.add(buildRoot + "/out/host/linux-x86/bin/" +
run.vmCommand);
+
+ String libDir = buildRoot + "/out/host/linux-x86/lib";
+ builder.env("ANDROID_ROOT", buildRoot + "/out/host/linux-x86")
+ .env("LD_LIBRARY_PATH", libDir)
+ .env("DYLD_LIBRARY_PATH", libDir);
+
+ // If you edit this, see also DeviceRuntime...
+ builder.vmCommand(vmCommand)
+ .vmArgs("-Xbootclasspath:" + bootClasspath.toString())
+ .vmArgs("-Duser.language=en")
+ .vmArgs("-Duser.region=US");
+ if (!run.benchmark) {
+ builder.vmArgs("-Xverify:none");
+ builder.vmArgs("-Xdexopt:none");
+ builder.vmArgs("-Xcheck:jni");
+ }
+ if (modeId == ModeId.HOST_ART_KITKAT) {
+ // Required for KitKat to select the ART runtime. Default is
Dalvik.
+ builder.vmArgs("-XXlib:libart.so");
+ }
+ // dalvikvm defaults to no limit, but the framework sets the limit
at 2000.
+ builder.vmArgs("-Xjnigreflimit:2000");
+ return builder;
+ }
+
+ @Override public Classpath getRuntimeClasspath(Action action) {
+ Classpath result = new Classpath();
+ result.addAll(run.localDexFile(action.getName()));
+ for (File classpathElement : run.classpath.getElements()) {
+
result.addAll(run.localDexFile(run.basenameOfJar(classpathElement)));
+ }
+ result.addAll(run.resourceClasspath);
+ return result;
+ }
+}
=======================================
--- /trunk/src/vogar/android/AppProcessMode.java Fri Apr 19 00:30:59 2013
UTC
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package vogar.android;
-
-import com.google.common.collect.Iterables;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import vogar.Action;
-import vogar.Run;
-import vogar.commands.VmCommandBuilder;
-
-/**
- * Execute actions using the app_process command on using an Android
device or emulator.
- */
-public final class AppProcessMode extends DeviceDalvikVm {
- public AppProcessMode(Run run) {
- super(run);
- }
-
- @Override public VmCommandBuilder newVmCommandBuilder(Action action,
File workingDirectory) {
- List<String> vmCommand = new ArrayList<String>();
- vmCommand.addAll(run.target.targetProcessPrefix(workingDirectory));
- vmCommand.add(run.getAndroidData());
- Iterables.addAll(vmCommand, run.invokeWith());
- vmCommand.add(run.vmCommand);
-
- return new VmCommandBuilder(run.log)
- .vmCommand(vmCommand)
- .vmArgs(action.getUserDir().getPath())
- .classpathViaProperty(true)
- .maxLength(1024);
- }
-}
=======================================
--- /trunk/src/vogar/android/DeviceDalvikVm.java Fri Apr 19 00:30:59 2013
UTC
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package vogar.android;
-
-import com.google.common.collect.Iterables;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import vogar.Action;
-import vogar.Classpath;
-import vogar.Mode;
-import vogar.Run;
-import vogar.commands.VmCommandBuilder;
-import vogar.tasks.RunActionTask;
-import vogar.tasks.Task;
-
-/**
- * Execute actions on a Dalvik VM using an Android device or emulator.
- */
-public class DeviceDalvikVm implements Mode {
- protected final Run run;
-
- public DeviceDalvikVm(Run run) {
- this.run = run;
- }
-
- @Override public Set<Task> installTasks() {
- Set<Task> result = new HashSet<Task>();
- // dex everything on the classpath and push it to the device.
- for (File classpathElement : run.classpath.getElements()) {
- dexAndPush(result, run.basenameOfJar(classpathElement),
- classpathElement, null);
- }
- return result;
- }
-
- @Override public Set<Task> installActionTasks(Action action, File jar)
{
- Set<Task> result = new HashSet<Task>();
- dexAndPush(result, action.getName(), jar, action);
- return result;
- }
-
- @Override public Task executeActionTask(Action action, boolean
useLargeTimeout) {
- return new RunActionTask(run, action, useLargeTimeout);
- }
-
- private void dexAndPush(Set<Task> tasks, String name, File jar, Action
action) {
- File localDex = run.localDexFile(name);
- File deviceDex = run.targetDexFile(name);
- Task dex = new DexTask(run.androidSdk, run.classpath,
run.benchmark, name, jar, action,
- localDex);
- tasks.add(dex);
- tasks.add(run.target.pushTask(localDex,
deviceDex).afterSuccess(dex));
- }
-
- @Override public VmCommandBuilder newVmCommandBuilder(Action action,
File workingDirectory) {
- List<String> vmCommand = new ArrayList<String>();
- vmCommand.addAll(run.target.targetProcessPrefix(workingDirectory));
- vmCommand.add(run.getAndroidData());
- Iterables.addAll(vmCommand, run.invokeWith());
- vmCommand.add(run.vmCommand);
-
- // If you edit this, see also HostDalvikVm...
- VmCommandBuilder vmCommandBuilder = new VmCommandBuilder(run.log)
- .vmCommand(vmCommand)
- .vmArgs("-Duser.home=" + run.deviceUserHome)
- .vmArgs("-Duser.name=" + run.target.getDeviceUserName())
- .vmArgs("-Duser.language=en")
- .vmArgs("-Duser.region=US")
- .maxLength(1024);
- if (!run.benchmark) {
- vmCommandBuilder.vmArgs("-Xverify:none");
- vmCommandBuilder.vmArgs("-Xdexopt:none");
- vmCommandBuilder.vmArgs("-Xcheck:jni");
- }
- // dalvikvm defaults to no limit, but the framework sets the limit
at 2000.
- vmCommandBuilder.vmArgs("-Xjnigreflimit:2000");
- return vmCommandBuilder;
- }
-
- @Override public Set<Task> cleanupTasks(Action action) {
- return
Collections.singleton(run.target.rmTask(action.getUserDir()));
- }
-
- @Override public Classpath getRuntimeClasspath(Action action) {
- Classpath result = new Classpath();
- result.addAll(run.targetDexFile(action.getName()));
- if (!run.benchmark) {
- for (File classpathElement : run.classpath.getElements()) {
-
result.addAll(run.targetDexFile(run.basenameOfJar(classpathElement)));
- }
- }
- // Note we intentionally do not add run.resourceClasspath on
- // the device since it contains host path names.
- return result;
- }
-}
=======================================
--- /trunk/src/vogar/android/HostDalvikVm.java Fri Apr 19 00:30:59 2013 UTC
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package vogar.android;
-
-import com.google.common.collect.Iterables;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import vogar.Action;
-import vogar.Classpath;
-import vogar.Mode;
-import vogar.Run;
-import vogar.commands.VmCommandBuilder;
-import vogar.tasks.MkdirTask;
-import vogar.tasks.RunActionTask;
-import vogar.tasks.Task;
-
-/**
- * Executes actions on a Dalvik VM on a Linux desktop.
- */
-public final class HostDalvikVm implements Mode {
- private final Run run;
-
- public HostDalvikVm(Run run) {
- this.run = run;
- }
-
- @Override public Task executeActionTask(Action action, boolean
useLargeTimeout) {
- return new RunActionTask(run, action, useLargeTimeout);
- }
-
- private File dalvikCache() {
- return run.localFile("android-data", run.dalvikCache);
- }
-
- @Override public Set<Task> installTasks() {
- Set<Task> result = new HashSet<Task>();
- for (File classpathElement : run.classpath.getElements()) {
- String name = run.basenameOfJar(classpathElement);
- result.add(new DexTask(run.androidSdk, run.classpath,
run.benchmark, name,
- classpathElement, null, run.localDexFile(name)));
- }
- result.add(new MkdirTask(run.mkdir, dalvikCache()));
- return result;
- }
-
- @Override public Set<Task> cleanupTasks(Action action) {
- return Collections.emptySet();
- }
-
- @Override public Set<Task> installActionTasks(Action action, File jar)
{
- return Collections.<Task>singleton(new DexTask(run.androidSdk,
Classpath.of(jar),
- run.benchmark, action.getName(), jar, action,
run.localDexFile(action.getName())));
- }
-
- @Override public VmCommandBuilder newVmCommandBuilder(Action action,
File workingDirectory) {
- String buildRoot = System.getenv("ANDROID_BUILD_TOP");
-
- List<File> jars = new ArrayList<File>();
- for (String jar : AndroidSdk.HOST_BOOTCLASSPATH) {
- jars.add(new File(buildRoot, "out/host/linux-x86/framework/" +
jar + ".jar"));
- }
- Classpath bootClasspath = Classpath.of(jars);
-
- VmCommandBuilder builder = new VmCommandBuilder(run.log)
- .userDir(workingDirectory)
- .env("ANDROID_PRINTF_LOG", "tag")
- .env("ANDROID_LOG_TAGS", "*:i")
- .env("ANDROID_DATA", dalvikCache().getParent());
-
- List<String> vmCommand = new ArrayList<String>();
- Iterables.addAll(vmCommand, run.invokeWith());
-
- vmCommand.add(buildRoot + "/out/host/linux-x86/bin/" +
run.vmCommand);
- builder.env("ANDROID_ROOT", buildRoot + "/out/host/linux-x86")
- .env("LD_LIBRARY_PATH", buildRoot
+ "/out/host/linux-x86/lib")
- .env("DYLD_LIBRARY_PATH", buildRoot
+ "/out/host/linux-x86/lib");
-
- // If you edit this, see also DeviceDalvikVm...
- builder.vmCommand(vmCommand)
- .vmArgs("-Xbootclasspath:" + bootClasspath.toString())
- .vmArgs("-Duser.language=en")
- .vmArgs("-Duser.region=US");
- if (!run.benchmark) {
- builder.vmArgs("-Xverify:none");
- builder.vmArgs("-Xdexopt:none");
- builder.vmArgs("-Xcheck:jni");
- }
- // dalvikvm defaults to no limit, but the framework sets the limit
at 2000.
- builder.vmArgs("-Xjnigreflimit:2000");
- return builder;
- }
-
- @Override public Classpath getRuntimeClasspath(Action action) {
- Classpath result = new Classpath();
- result.addAll(run.localDexFile(action.getName()));
- for (File classpathElement : run.classpath.getElements()) {
-
result.addAll(run.localDexFile(run.basenameOfJar(classpathElement)));
- }
- result.addAll(run.resourceClasspath);
- return result;
- }
-}
=======================================
--- /trunk/src/vogar/ModeId.java Fri Apr 19 00:30:59 2013 UTC
+++ /trunk/src/vogar/ModeId.java Tue Aug 5 14:21:42 2014 UTC
@@ -16,31 +16,143 @@

package vogar;

+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
public enum ModeId {
- DEVICE, JVM, ACTIVITY, HOST, APP_PROCESS;
+ /** ART (works >= L) */
+ DEVICE,
+ /** Dalvik (works <= KitKat) */
+ DEVICE_DALVIK,
+ /** ART (for KitKat only, use DEVICE_DALVIK otherwise) */
+ DEVICE_ART_KITKAT,
+
+ /** ART (works >= L) */
+ HOST,
+ /** Dalvik (works <= KitKat) */
+ HOST_DALVIK,
+ /** ART for KitKat only */
+ HOST_ART_KITKAT,
+ /** Local Java */
+ JVM,
+ /** Device, execution as an Android app with Zygote */
+ ACTIVITY,
+ /** Device using app_process binary */
+ APP_PROCESS;
+
+ // $BOOTCLASSPATH defined by system/core/rootdir/init.rc
+ private static final String[] DALVIK_DEVICE_JARS = new String[]
{"core"};
+ private static final String[] ART_DEVICE_JARS = new String[]
{"core-libart"};
+ private static final String[] COMMON_DEVICE_JARS = new String[] {
+ "conscrypt",
+ "okhttp",
+ "core-junit",
+ "bouncycastle",
+ "ext",
+ "framework",
+ "telephony-common",
+ "mms-common",
+ "framework",
+ "android.policy",
+ "services",
+ "apache-xml"};
+
+ private static final String[] DALVIK_HOST_JARS = new String[]
{"core-hostdex"};
+ private static final String[] ART_HOST_JARS = new String[]
{"core-libart-hostdex"};
+ private static final String[] COMMON_HOST_JARS = new String[] {
+ "conscrypt-hostdex",
+ "okhttp-hostdex",
+ "bouncycastle-hostdex",
+ "apache-xml-hostdex",
+ };

public boolean acceptsVmArgs() {
return this != ACTIVITY;
}

+ /**
+ * Returns {@code true} if execution happens on the local machine.
e.g. host-mode android or a
+ * JVM.
+ */
+ public boolean isLocal() {
+ return isHost() || this == ModeId.JVM;
+ }
+
+ /** Returns {@code true} if execution takes place with a host-mode
Android runtime */
public boolean isHost() {
- return this == JVM || this == HOST;
+ return this == HOST || this == HOST_DALVIK || this ==
ModeId.HOST_ART_KITKAT;
+ }
+
+ /** Returns {@code true} if execution takes place with a device-mode
Android runtime */
+ public boolean isDevice() {
+ return this == ModeId.DEVICE || this == ModeId.DEVICE_ART_KITKAT
+ || this == ModeId.DEVICE_DALVIK || this ==
ModeId.APP_PROCESS;
}

public boolean requiresAndroidSdk() {
return this != JVM;
}

- public String defaultVmCommand() {
- if (this == DEVICE || this == HOST) {
- return "dalvikvm";
+ public boolean supportsVariant(Variant variant) {
+ return variant == Variant.X32;
+ }
+
+ /** The default command to use for the mode unless overridden by
--vm-command */
+ public String defaultVmCommand(Variant variant) {
+ if (variant != Variant.X32) {
+ throw new IllegalArgumentException("Unsupported architecture
variant");
}
- if (this == JVM) {
- return "java";
+ switch (this) {
+ case DEVICE:
+ case HOST:
+ return "dalvikvm32";
+ case DEVICE_DALVIK:
+ case DEVICE_ART_KITKAT:
+ case HOST_DALVIK:
+ case HOST_ART_KITKAT:
+ return "dalvikvm";
+ case JVM:
+ return "java";
+ case APP_PROCESS:
+ return "app_process";
+ case ACTIVITY:
+ return null;
+ default:
+ throw new IllegalArgumentException("Unknown mode: " +
this);
}
- if (this == APP_PROCESS) {
- return "app_process";
+ }
+
+ /**
+ * Return the names of jars required to compile in this mode when
android.jar is not being used.
+ * Also used to generated the classpath in HOST* and DEVICE* modes.
+ */
+ public String[] getJarNames() {
+ List<String> jarNames = new ArrayList<String>();
+ switch (this) {
+ case DEVICE_DALVIK:
+ jarNames.addAll(Arrays.asList(DALVIK_DEVICE_JARS));
+ jarNames.addAll(Arrays.asList(COMMON_DEVICE_JARS));
+ break;
+ case ACTIVITY:
+ case APP_PROCESS:
+ case DEVICE:
+ case DEVICE_ART_KITKAT:
+ jarNames.addAll(Arrays.asList(ART_DEVICE_JARS));
+ jarNames.addAll(Arrays.asList(COMMON_DEVICE_JARS));
+ break;
+ case HOST_DALVIK:
+ jarNames.addAll(Arrays.asList(DALVIK_HOST_JARS));
+ jarNames.addAll(Arrays.asList(COMMON_HOST_JARS));
+ break;
+ case HOST:
+ case HOST_ART_KITKAT:
+ jarNames.addAll(Arrays.asList(ART_HOST_JARS));
+ jarNames.addAll(Arrays.asList(COMMON_HOST_JARS));
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported mode: " +
this);
}
- return null;
+ return jarNames.toArray(new String[jarNames.size()]);
}
}
=======================================
--- /trunk/src/vogar/Run.java Fri Jun 27 09:49:45 2014 UTC
+++ /trunk/src/vogar/Run.java Tue Aug 5 14:21:42 2014 UTC
@@ -29,10 +29,9 @@
import vogar.android.ActivityMode;
import vogar.android.AdbTarget;
import vogar.android.AndroidSdk;
-import vogar.android.AppProcessMode;
-import vogar.android.DeviceDalvikVm;
import vogar.android.DeviceFileCache;
-import vogar.android.HostDalvikVm;
+import vogar.android.DeviceRuntime;
+import vogar.android.HostRuntime;
import vogar.commands.Mkdir;
import vogar.commands.Rm;
import vogar.tasks.TaskQueue;
@@ -111,7 +110,7 @@

if (vogar.sshHost != null) {
this.target = new SshTarget(vogar.sshHost, log);
- } else if (vogar.mode.isHost()) {
+ } else if (vogar.modeId.isLocal()) {
this.target = new LocalTarget(this);
} else {
this.target = new AdbTarget(this);
@@ -136,7 +135,7 @@
this.javacArgs = vogar.javacArgs;
this.javaHome = vogar.javaHome;
this.largeTimeoutSeconds = vogar.timeoutSeconds *
Vogar.LARGE_TIMEOUT_MULTIPLIER;
- this.maxConcurrentActions = (vogar.stream || vogar.mode ==
ModeId.ACTIVITY)
+ this.maxConcurrentActions = (vogar.stream || vogar.modeId ==
ModeId.ACTIVITY)
? 1
: Vogar.NUM_PROCESSORS;
this.timeoutSeconds = vogar.timeoutSeconds;
@@ -160,36 +159,24 @@
this.classpath = Classpath.of(vogar.classpath);
this.classpath.addAll(vogarJar());

- if (vogar.mode.requiresAndroidSdk()) {
- androidSdk = new AndroidSdk(log, mkdir, vogar.mode);
+ if (vogar.modeId.requiresAndroidSdk()) {
+ androidSdk = new AndroidSdk(log, mkdir, vogar.modeId);
androidSdk.setCaches(new HostFileCache(log, mkdir),
new DeviceFileCache(log, runnerDir, androidSdk));
} else {
androidSdk = null;
}

- expectationStore = ExpectationStore.parse(console,
vogar.expectationFiles, vogar.mode);
+ expectationStore = ExpectationStore.parse(console,
vogar.expectationFiles, vogar.modeId);
if (vogar.openBugsCommand != null) {
expectationStore.loadBugStatuses(new CommandBugDatabase(log,
vogar.openBugsCommand));
}

- if (vogar.mode == ModeId.JVM) {
- this.mode = new JavaVm(this);
- } else if (vogar.mode == ModeId.HOST) {
- this.mode = new HostDalvikVm(this);
- } else if (vogar.mode == ModeId.DEVICE) {
- this.mode = new DeviceDalvikVm(this);
- } else if (vogar.mode == ModeId.ACTIVITY) {
- this.mode = new ActivityMode(this);
- } else if (vogar.mode == ModeId.APP_PROCESS) {
- this.mode = new AppProcessMode(this);
- } else {
- throw new IllegalStateException();
- }
+ this.mode = createMode(vogar.modeId, vogar.variant);

this.buildClasspath = Classpath.of(vogar.buildClasspath);
- if (vogar.mode.requiresAndroidSdk()) {
- buildClasspath.addAll(androidSdk.getAndroidClasses());
+ if (vogar.modeId.requiresAndroidSdk()) {
+ buildClasspath.addAll(androidSdk.getCompilationClasspath());
}

this.classFileIndex = new ClassFileIndex(log, mkdir,
vogar.jarSearchDirs);
@@ -205,6 +192,26 @@
this.driver = new Driver(this);
this.taskQueue = new TaskQueue(console, maxConcurrentActions);
}
+
+ private Mode createMode(ModeId modeId, Variant variant) {
+ switch (modeId) {
+ case JVM:
+ return new JavaVm(this);
+ case HOST:
+ case HOST_DALVIK:
+ case HOST_ART_KITKAT:
+ return new HostRuntime(this, modeId, variant);
+ case DEVICE:
+ case DEVICE_DALVIK:
+ case DEVICE_ART_KITKAT:
+ case APP_PROCESS:
+ return new DeviceRuntime(this, modeId, variant);
+ case ACTIVITY:
+ return new ActivityMode(this);
+ default:
+ throw new IllegalArgumentException("Unsupported mode: " +
modeId);
+ }
+ }

public final File localFile(Object... path) {
return new File(localTemp + "/" + Strings.join("/", path));
=======================================
--- /trunk/src/vogar/Vogar.java Fri Apr 19 00:30:59 2013 UTC
+++ /trunk/src/vogar/Vogar.java Tue Aug 5 14:21:42 2014 UTC
@@ -51,7 +51,10 @@
}

@Option(names = { "--mode" })
- ModeId mode = ModeId.DEVICE;
+ ModeId modeId = ModeId.DEVICE;
+
+ @Option(names = { "--var" })
+ Variant variant = Variant.X32;

@Option(names = { "--ssh" })
String sshHost;
@@ -202,12 +205,20 @@
System.out.println();
System.out.println("GENERAL OPTIONS");
System.out.println();
- System.out.println(" --mode <activity|device|host|jvm>: specify
which environment to run in.");
+ System.out.println(" --mode <activity|device|device_dalvik|host|
host_dalvik|jvm>: specify which environment to run in.");
System.out.println(" activity: runs in an Android application
on a device or emulator");
- System.out.println(" device: runs in a Dalvik VM on a device
or emulator");
- System.out.println(" host: runs in a Dalvik VM on the local
desktop built with any lunch combo.");
+ System.out.println(" device: runs in an ART runtime on a
device or emulator");
+ System.out.println(" device_dalvik: runs in a Dalvik runtime
on a device or emulator");
+ System.out.println(" device_art_kitkat: runs in a KitKat ART
runtime on a device or emulator");
+ System.out.println(" host: runs in an ART runtime on the
local desktop built with any lunch combo.");
+ System.out.println(" host_dalvik: runs in a Dalvik runtime on
the local desktop built with any lunch combo.");
+ System.out.println(" host_art_kitkat: runs in a KitKat ART
runtime on the local desktop built with any lunch combo.");
System.out.println(" jvm: runs in a Java VM on the local
desktop");
- System.out.println(" Default is: " + mode);
+ System.out.println(" Default is: " + modeId);
+ System.out.println();
+ System.out.println(" --variant <x32>: specify which architecture
variant to execute with.");
+ System.out.println(" x32: 32-bit");
+ System.out.println(" Default is: " + variant);
System.out.println();
System.out.println(" --ssh <host:port>: target a remote machine
via SSH.");
System.out.println();
@@ -285,7 +296,7 @@
System.out.println(" virtual machine. Examples: -Xint:fast,
-ea, -Xmx16M");
System.out.println();
System.out.println(" --vm-command <argument>: override default vm
executable name.");
- System.out.println(" Default is java for the host and
dalvikvm for the target.");
+ System.out.println(" Default is 'java' for the JVM and a
version of dalvikvm for the host and target.");
System.out.println();
System.out.println(" --java-home <java_home>: execute the actions
on the local workstation");
System.out.println(" using the specified java home directory.
This does not impact");
@@ -389,8 +400,14 @@
}

// check vm option consistency
- if (!mode.acceptsVmArgs() && !vmArgs.isEmpty()) {
- System.out.println("VM args " + vmArgs + " should not be
specified for mode " + mode);
+ if (!modeId.acceptsVmArgs() && !vmArgs.isEmpty()) {
+ System.out.println("VM args " + vmArgs + " should not be
specified for mode " + modeId);
+ return false;
+ }
+
+ // Check variant / mode compatibility.
+ if (!modeId.supportsVariant(variant)) {
+ System.out.println("Variant " + variant + " not supported for
mode " + modeId);
return false;
}

@@ -409,7 +426,7 @@
//

if (vmCommand == null) {
- vmCommand = mode.defaultVmCommand();
+ vmCommand = modeId.defaultVmCommand(variant);
}

// disable timeout when benchmarking or debugging
@@ -418,7 +435,7 @@
}

if (firstMonitorPort == -1) {
- firstMonitorPort = mode.isHost() ? 8788 : 8787;
+ firstMonitorPort = modeId.isLocal() ? 8788 : 8787;
}

if (profileFile == null) {
@@ -455,8 +472,8 @@
return false;
}

- if (!mode.acceptsVmArgs() && !targetArgs.isEmpty()) {
- System.out.println("Target args " + targetArgs + " should not
be specified for mode " + mode);
+ if (!modeId.acceptsVmArgs() && !targetArgs.isEmpty()) {
+ System.out.println("Target args " + targetArgs + " should not
be specified for mode " + modeId);
return false;
}

=======================================
--- /trunk/src/vogar/android/AndroidSdk.java Fri Jun 27 09:49:45 2014 UTC
+++ /trunk/src/vogar/android/AndroidSdk.java Tue Aug 5 14:21:42 2014 UTC
@@ -64,7 +64,7 @@

private final Log log;
private final Mkdir mkdir;
- private final File[] androidClasses;
+ private final File[] compilationClasspath;
public final DeviceFilesystem deviceFilesystem;

private Md5Cache dexCache;
@@ -80,7 +80,7 @@
return (files != null) ? Arrays.asList(files) :
Collections.<File>emptyList();
}

- public AndroidSdk(Log log, Mkdir mkdir, ModeId mode) {
+ public AndroidSdk(Log log, Mkdir mkdir, ModeId modeId) {
this.log = log;
this.mkdir = mkdir;
this.deviceFilesystem = new DeviceFilesystem(log, "adb", "shell");
@@ -103,7 +103,7 @@
* <sdk>/platform-tools/dx
* <sdk>/platforms/android-?/android.jar
*
- * Android build tree:
+ * Android build tree (target):
* <source>/out/host/linux-x86/bin/aapt
* <source>/out/host/linux-x86/bin/adb
* <source>/out/host/linux-x86/bin/dx
@@ -114,7 +114,7 @@
File sdkRoot = adb.getParentFile().getParentFile();
File newestPlatform = getNewestPlatform(sdkRoot);
log.verbose("using android platform: " + newestPlatform);
- androidClasses = new File[] { new
File(newestPlatform, "android.jar") };
+ compilationClasspath = new File[] { new
File(newestPlatform, "android.jar") };
log.verbose("using android sdk: " + sdkRoot);
} else if ("bin".equals(parentFileName)) {
File sourceRoot = adb.getParentFile().getParentFile()
@@ -122,14 +122,15 @@
log.verbose("using android build tree: " + sourceRoot);

String pattern
= "out/target/common/obj/JAVA_LIBRARIES/%s_intermediates/classes.jar";
- if (mode == ModeId.HOST) {
- pattern
= "out/host/common/obj/JAVA_LIBRARIES/%s-hostdex_intermediates/classes.jar";
+ if (modeId.isHost()) {
+ pattern
= "out/host/common/obj/JAVA_LIBRARIES/%s_intermediates/classes.jar";
}

- androidClasses = new File[BOOTCLASSPATH.length];
- for (int i = 0; i < BOOTCLASSPATH.length; i++) {
- String jar = BOOTCLASSPATH[i];
- androidClasses[i] = new File(sourceRoot,
String.format(pattern, jar));
+ String[] jarNames = modeId.getJarNames();
+ compilationClasspath = new File[jarNames.length];
+ for (int i = 0; i < jarNames.length; i++) {
+ String jar = jarNames[i];
+ compilationClasspath[i] = new File(sourceRoot,
String.format(pattern, jar));
}
} else {
throw new RuntimeException("Couldn't derive Android home
from " + adb);
@@ -182,8 +183,8 @@
return result;
}

- public File[] getAndroidClasses() {
- return androidClasses;
+ public File[] getCompilationClasspath() {
+ return compilationClasspath;
}

public void setCaches(HostFileCache hostFileCache, DeviceFileCache
deviceCache) {
@@ -234,10 +235,6 @@
"-F",
apk.getPath(),
"-M",
manifest.getPath(),
"-I", "prebuilts/sdk/current/android.jar"));
- for (File jar : androidClasses) {
- aapt.add("-I");
- aapt.add(jar.getPath());
- }
new Command(log, aapt).execute();
}

=======================================
--- /trunk/src/vogar/target/TestEnvironment.java Tue Dec 10 17:28:01 2013
UTC
+++ /trunk/src/vogar/target/TestEnvironment.java Tue Aug 5 14:21:42 2014
UTC
@@ -48,16 +48,25 @@
private static final String JAVA_VM_INFO =
System.getProperty("java.vm.info");
private static final String JAVA_VM_VERSION =
System.getProperty("java.vm.version");
private static final String JAVA_VM_VENDOR =
System.getProperty("java.vm.vendor");
- private static final String JAVA_VM_NAME =
System.getProperty("java.vm.name");
+ private static final String JAVA_VM_NAME =
System.getProperty("java.vm.name");
+
+ private final String tmpDir;

public TestEnvironment() {
+ this.tmpDir = System.getProperty("java.io.tmpdir");
+ if (tmpDir == null || tmpDir.length() == 0) {
+ throw new AssertionError("tmpDir is null or empty: " + tmpDir);
+ }
System.setProperties(null); // Reset.
- String tmpDir = System.getProperty("java.io.tmpdir");
+
+ // From "L" release onwards, calling System.setProperties(null)
clears the java.io.tmpdir,
+ // so we set it again. No-op on earlier releases.
+ System.setProperty("java.io.tmpdir", tmpDir);
+
String userHome = System.getProperty("user.home");
String userDir = System.getProperty("user.dir");
- if (tmpDir == null || userHome == null || userDir == null) {
- throw new NullPointerException("java.io.tmpdir=" + tmpDir + ",
user.home="
- + userHome + "user.dir=" + userDir);
+ if (userHome == null || userDir == null) {
+ throw new NullPointerException("user.home=" + userHome + ",
user.dir=" + userDir);
}

defaultHostnameVerifier =
HttpsURLConnection.getDefaultHostnameVerifier();
@@ -70,6 +79,10 @@
// Reset system properties.
System.setProperties(null);

+ // From "L" release onwards, calling System.setProperties(null)
clears the java.io.tmpdir,
+ // so we set it again. No-op on earlier releases.
+ System.setProperty("java.io.tmpdir", tmpDir);
+
if (JAVA_RUNTIME_VERSION != null) {
System.setProperty("java.runtime.version",
JAVA_RUNTIME_VERSION);
}
@@ -87,7 +100,6 @@
}

// Require writable java.home and user.dir directories for
preferences
- String tmpDir = System.getProperty("java.io.tmpdir");
if ("Dalvik".equals(System.getProperty("java.vm.name"))) {
String javaHome = tmpDir + "/java.home";
IoUtils.safeMkdirs(new File(javaHome));
@@ -134,6 +146,14 @@
}

private static void resetPreferences(Preferences root) {
+ try {
+ root.sync();
+ } catch (BackingStoreException e) {
+ // Indicates that Preferences is probably not working. It's
not really supported on
+ // Android so ignore.
+ return;
+ }
+
try {
for (String child : root.childrenNames()) {
root.node(child).removeNode();
Reply all
Reply to author
Forward
0 new messages