am d46649e6: am 7aea03ae: am 15bdbb70: am 78860c44: Merge "Adds Java scanner and placeholders for Native Scanner and Xml Generators." into jb-dev

* commit 'd46649e6214ec4bb757f8a5378612356a04c720b':
  Adds Java scanner and placeholders for Native Scanner and Xml Generators.
diff --git a/common/device-side/device-setup/Android.mk b/common/device-side/device-setup/Android.mk
index 7326ccc..bc7c504 100644
--- a/common/device-side/device-setup/Android.mk
+++ b/common/device-side/device-setup/Android.mk
@@ -20,8 +20,24 @@
 
 LOCAL_MODULE_TAGS := optional
 
-LOCAL_MODULE := cts-common-device-setup_v2
+LOCAL_MODULE := compatibility-device-setup_v2
 
 LOCAL_SDK_VERSION := current
 
 include $(BUILD_STATIC_JAVA_LIBRARY)
+
+###############################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := junit
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := compatibility-device-setup-tests_v2
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/device-side/device-setup/src/android/cts/devicesetup/DeviceInfoConstants.java b/common/device-side/device-setup/src/com/android/compatibility/common/devicesetup/DeviceInfoConstants.java
similarity index 96%
rename from common/device-side/device-setup/src/android/cts/devicesetup/DeviceInfoConstants.java
rename to common/device-side/device-setup/src/com/android/compatibility/common/devicesetup/DeviceInfoConstants.java
index 5500d5e..7b19b00 100644
--- a/common/device-side/device-setup/src/android/cts/devicesetup/DeviceInfoConstants.java
+++ b/common/device-side/device-setup/src/com/android/compatibility/common/devicesetup/DeviceInfoConstants.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.devicesetup;
+package com.android.compatibility.common.devicesetup;
 
 /**
  * Constants for device info attributes to be sent as instrumentation keys.
@@ -72,7 +72,7 @@
     public static final String STORAGE_DEVICES = "storageDevices";
     public static final String SYS_LIBRARIES = "systemLibraries";
 
-    public static final String TOUCH_SCREEN = "touch";
+    public static final String TOUCH = "touch";
 
     public static final String VERSION_RELEASE = "versionRelease";
     public static final String VERSION_SDK_INT = "versionSdkInt";
diff --git a/common/util/src/android/cts/util/MeasureRun.java b/common/device-side/device-setup/tests/src/com/android/compatibility/common/devicesetup/DeviceSetupTest.java
similarity index 63%
copy from common/util/src/android/cts/util/MeasureRun.java
copy to common/device-side/device-setup/tests/src/com/android/compatibility/common/devicesetup/DeviceSetupTest.java
index 2256033..ee55a66 100644
--- a/common/util/src/android/cts/util/MeasureRun.java
+++ b/common/device-side/device-setup/tests/src/com/android/compatibility/common/devicesetup/DeviceSetupTest.java
@@ -14,18 +14,12 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.devicesetup;
 
-/**
- * Interface for measuring time for each run.
- */
-public abstract class MeasureRun {
-    /**
-     *  Called before each run. not included in time measurement.
-     */
-    public void prepare(int i) throws Exception {
-        // default empty implementation
-    };
+import junit.framework.TestCase;
 
-    abstract public void run(int i) throws Exception;
+public class DeviceSetupTest extends TestCase {
+
+    // TODO(stuartscott): Add tests when there is something to test.
+
 }
diff --git a/common/device-side/util/Android.mk b/common/device-side/util/Android.mk
index 5224c1f..c8104bf 100644
--- a/common/device-side/util/Android.mk
+++ b/common/device-side/util/Android.mk
@@ -18,12 +18,28 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_STATIC_JAVA_LIBRARIES := cts-common-util-device_v2
+LOCAL_STATIC_JAVA_LIBRARIES := compatibility-common-util-devicesidelib_v2
 
 LOCAL_MODULE_TAGS := optional
 
-LOCAL_MODULE := cts-device-util_v2
+LOCAL_MODULE := compatibility-device-util_v2
 
 LOCAL_SDK_VERSION := current
 
 include $(BUILD_STATIC_JAVA_LIBRARY)
+
+################################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := junit
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := compatibility-device-util-tests_v2
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/device-side/util/src/android/cts/util/DeviceReportLog.java b/common/device-side/util/src/com/android/compatibility/common/util/DeviceReportLog.java
similarity index 77%
rename from common/device-side/util/src/android/cts/util/DeviceReportLog.java
rename to common/device-side/util/src/com/android/compatibility/common/util/DeviceReportLog.java
index 75f937a..273cdf5 100644
--- a/common/device-side/util/src/android/cts/util/DeviceReportLog.java
+++ b/common/device-side/util/src/com/android/compatibility/common/util/DeviceReportLog.java
@@ -14,28 +14,29 @@
  * limitations under the License.
  */
 
-package android.cts.util;
-
-import android.cts.util.ReportLog;
+package com.android.compatibility.common.util;
 
 import android.app.Instrumentation;
 import android.os.Bundle;
 import android.util.Log;
 
+import com.android.compatibility.common.util.ReportLog;
+
 /**
  * Handles adding results to the report for device side tests.
  *
- * NOTE: tests MUST call {@link #submit(Instrumentation)} in the test's tearDown method.
+ * NOTE: tests MUST call {@link #submit(Instrumentation)} if and only if the test passes in order to
+ * send the results to the runner.
  */
 public class DeviceReportLog extends ReportLog {
     private static final String TAG = DeviceReportLog.class.getSimpleName();
-    private static final String CTS_RESULT = "CTS_RESULT";
+    private static final String RESULT = "RESULT";
     private static final int INST_STATUS_IN_PROGRESS = 2;
 
     public void submit(Instrumentation instrumentation) {
         Log.i(TAG, "submit");
         Bundle output = new Bundle();
-        output.putSerializable(CTS_RESULT, this);
+        output.putSerializable(RESULT, this);
         instrumentation.sendStatus(INST_STATUS_IN_PROGRESS, output);
     }
 }
diff --git a/common/device-side/util/src/android/cts/util/EvaluateJsResultPollingCheck.java b/common/device-side/util/src/com/android/compatibility/common/util/EvaluateJsResultPollingCheck.java
similarity index 95%
rename from common/device-side/util/src/android/cts/util/EvaluateJsResultPollingCheck.java
rename to common/device-side/util/src/com/android/compatibility/common/util/EvaluateJsResultPollingCheck.java
index 65fb614..521dc40 100644
--- a/common/device-side/util/src/android/cts/util/EvaluateJsResultPollingCheck.java
+++ b/common/device-side/util/src/com/android/compatibility/common/util/EvaluateJsResultPollingCheck.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 import android.webkit.ValueCallback;
 
diff --git a/common/device-side/util/src/android/cts/util/FileCopyHelper.java b/common/device-side/util/src/com/android/compatibility/common/util/FileCopyHelper.java
similarity index 92%
rename from common/device-side/util/src/android/cts/util/FileCopyHelper.java
rename to common/device-side/util/src/com/android/compatibility/common/util/FileCopyHelper.java
index 8b5a8dc..02be372 100644
--- a/common/device-side/util/src/android/cts/util/FileCopyHelper.java
+++ b/common/device-side/util/src/com/android/compatibility/common/util/FileCopyHelper.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 import android.content.Context;
 
@@ -26,8 +26,8 @@
 import java.util.ArrayList;
 
 /**
- * The Class FileCopyHelper is used to copy files from resources to the
- * application directory and responsible for deleting the files.
+ * FileCopyHelper is used to copy files from resources to the application directory and responsible
+ * for deleting the files.
  *
  * @see MediaStore_VideoTest
  * @see MediaStore_Images_MediaTest
@@ -51,7 +51,7 @@
     }
 
     /**
-     * Copy the file from the resources with a filename .
+     * Copy the file from the resources with a filename.
      *
      * @param resId the res id
      * @param fileName the file name
diff --git a/common/device-side/util/src/android/cts/util/PollingCheck.java b/common/device-side/util/src/com/android/compatibility/common/util/PollingCheck.java
similarity index 97%
rename from common/device-side/util/src/android/cts/util/PollingCheck.java
rename to common/device-side/util/src/com/android/compatibility/common/util/PollingCheck.java
index 5f2fe61..a976a92 100644
--- a/common/device-side/util/src/android/cts/util/PollingCheck.java
+++ b/common/device-side/util/src/com/android/compatibility/common/util/PollingCheck.java
@@ -14,13 +14,14 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 import java.util.concurrent.Callable;
 
 import junit.framework.Assert;
 
 public abstract class PollingCheck {
+
     private static final long TIME_SLICE = 50;
     private long mTimeoutMs = 3000;
 
diff --git a/common/device-side/util/src/android/cts/util/CtsResult.java b/common/device-side/util/src/com/android/compatibility/common/util/Result.java
similarity index 69%
rename from common/device-side/util/src/android/cts/util/CtsResult.java
rename to common/device-side/util/src/com/android/compatibility/common/util/Result.java
index b8dfbce..0d8a29a 100644
--- a/common/device-side/util/src/android/cts/util/CtsResult.java
+++ b/common/device-side/util/src/com/android/compatibility/common/util/Result.java
@@ -14,10 +14,18 @@
  * the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
-public interface CtsResult {
+/**
+ * Represents the result of a test.
+ */
+public interface Result {
     public static final int RESULT_OK = 1;
     public static final int RESULT_FAIL = 2;
-    public void setResult(int resultCode);
+    /**
+     * Sets the test result of this object.
+     *
+     * @param resultCode The test result, either {@code RESULT_OK} or {@code RESULT_FAIL}.
+     */
+    void setResult(int resultCode);
 }
diff --git a/common/device-side/util/src/android/cts/util/SystemUtil.java b/common/device-side/util/src/com/android/compatibility/common/util/SystemUtil.java
similarity index 96%
rename from common/device-side/util/src/android/cts/util/SystemUtil.java
rename to common/device-side/util/src/com/android/compatibility/common/util/SystemUtil.java
index 8849c9b..2ec9bef 100644
--- a/common/device-side/util/src/android/cts/util/SystemUtil.java
+++ b/common/device-side/util/src/com/android/compatibility/common/util/SystemUtil.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 import android.app.ActivityManager;
 import android.app.ActivityManager.MemoryInfo;
diff --git a/common/device-side/util/src/android/cts/util/WatchDog.java b/common/device-side/util/src/com/android/compatibility/common/util/WatchDog.java
similarity index 95%
rename from common/device-side/util/src/android/cts/util/WatchDog.java
rename to common/device-side/util/src/com/android/compatibility/common/util/WatchDog.java
index 6511930..4862323 100644
--- a/common/device-side/util/src/android/cts/util/WatchDog.java
+++ b/common/device-side/util/src/com/android/compatibility/common/util/WatchDog.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
@@ -23,8 +23,7 @@
 import junit.framework.Assert;
 
 /**
- * class for checking if function is alive or not.
- * panic if watch-dog is not reset over certain amount of time
+ * Used to fail a test if a function takes more than a certain amount of time.
  */
 public class WatchDog implements Runnable {
     private static final String TAG = WatchDog.class.getSimpleName();
diff --git a/common/util/src/android/cts/util/MeasureRun.java b/common/device-side/util/tests/src/com/android/compatibility/common/util/DeviceUtilTest.java
similarity index 63%
copy from common/util/src/android/cts/util/MeasureRun.java
copy to common/device-side/util/tests/src/com/android/compatibility/common/util/DeviceUtilTest.java
index 2256033..a7e81d7 100644
--- a/common/util/src/android/cts/util/MeasureRun.java
+++ b/common/device-side/util/tests/src/com/android/compatibility/common/util/DeviceUtilTest.java
@@ -14,18 +14,10 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
-/**
- * Interface for measuring time for each run.
- */
-public abstract class MeasureRun {
-    /**
-     *  Called before each run. not included in time measurement.
-     */
-    public void prepare(int i) throws Exception {
-        // default empty implementation
-    };
+import junit.framework.TestCase;
 
-    abstract public void run(int i) throws Exception;
+public class DeviceUtilTest extends TestCase {
+
 }
diff --git a/common/host-side/java-scanner/Android.mk b/common/host-side/java-scanner/Android.mk
new file mode 100644
index 0000000..3acf988
--- /dev/null
+++ b/common/host-side/java-scanner/Android.mk
@@ -0,0 +1,47 @@
+# 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAR_MANIFEST := MANIFEST.mf
+
+LOCAL_CLASSPATH := $(HOST_JDK_TOOLS_JAR)
+
+LOCAL_JAVA_LIBRARIES := junit
+
+LOCAL_MODULE := compatibility-java-scanner_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+################################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := compatibility-tradefed_v2 compatibility-java-scanner_v2 junit
+
+LOCAL_MODULE := compatibility-java-scanner-tests_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/host-side/java-scanner/MANIFEST.mf b/common/host-side/java-scanner/MANIFEST.mf
new file mode 100644
index 0000000..a04249a
--- /dev/null
+++ b/common/host-side/java-scanner/MANIFEST.mf
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+Main-Class: com.android.compatibility.common.scanner.JavaScanner
diff --git a/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScanner.java b/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScanner.java
new file mode 100644
index 0000000..c423290
--- /dev/null
+++ b/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScanner.java
@@ -0,0 +1,146 @@
+/*
+ * 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 com.android.compatibility.common.scanner;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Scans a source directory for java tests and outputs a list of test classes and methods.
+ */
+public class JavaScanner {
+
+    static final String[] SOURCE_PATHS = {
+        "./frameworks/base/core/java",
+        "./frameworks/base/test-runner/src",
+        "./external/junit/src",
+        "./development/tools/hosttestlib/src",
+        "./libcore/dalvik/src/main/java",
+        "./common/device-side/util/src",
+        "./common/host-side/tradefed/src",
+        "./common/util/src"
+    };
+    static final String[] CLASS_PATHS = {
+        "./prebuilts/misc/common/tradefed/tradefed-prebuilt.java",
+        "./prebuilts/misc/common/ub-uiautomator/ub-uiautomator.java"
+    };
+    private final File mSourceDir;
+    private final File mDocletDir;
+
+    /**
+     * @param sourceDir The directory holding the source to scan.
+     * @param docletDir The directory holding the doclet (or its jar).
+     */
+    JavaScanner(File sourceDir, File docletDir) {
+        this.mSourceDir = sourceDir;
+        this.mDocletDir = docletDir;
+    }
+
+    int scan() throws Exception {
+        final List<String> args = new ArrayList<String>();
+        args.add("javadoc");
+        args.add("-doclet");
+        args.add("com.android.compatibility.common.scanner.JavaScannerDoclet");
+        args.add("-sourcepath");
+        args.add(getSourcePath(mSourceDir));
+        args.add("-classpath");
+        args.add(getClassPath());
+        args.add("-docletpath");
+        args.add(mDocletDir.toString());
+        args.addAll(getSourceFiles(mSourceDir));
+
+        // Dont want p to get blocked due to a full pipe.
+        final Process p = new ProcessBuilder(args).redirectErrorStream(true).start();
+        final BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+        try {
+            String line = null;
+            while ((line = in.readLine()) != null) {
+                if (line.startsWith("suite:") ||
+                    line.startsWith("case:") ||
+                    line.startsWith("test:")) {
+                    System.out.println(line);
+                }
+            }
+        } finally {
+          if (in != null) {
+              in.close();
+          }
+        }
+
+        return p.waitFor();
+    }
+
+    private static String getSourcePath(File sourceDir) {
+        List<String> sourcePath = new ArrayList<String>(Arrays.asList(SOURCE_PATHS));
+        sourcePath.add(sourceDir.toString());
+        return join(sourcePath, ":");
+    }
+
+    private static String getClassPath() {
+        return join(Arrays.asList(CLASS_PATHS), ":");
+    }
+
+    private static List<String> getSourceFiles(File sourceDir) {
+        List<String> sourceFiles = new ArrayList<String>();
+        final File[] files = sourceDir.listFiles(new FileFilter() {
+            public boolean accept(File pathname) {
+                return pathname.isDirectory() || pathname.toString().endsWith(".java");
+            }
+        });
+        for (File f : files) {
+            if (f.isDirectory()) {
+                sourceFiles.addAll(getSourceFiles(f));
+            } else {
+                sourceFiles.add(f.toString());
+            }
+        }
+        return sourceFiles;
+    }
+
+    private static String join(List<String> list, String delimiter) {
+        StringBuilder builder = new StringBuilder();
+        for (String s : list) {
+            builder.append(s);
+            builder.append(delimiter);
+        }
+        // Adding the delimiter each time and then removing the last one at the end is more
+        // efficient than doing a check in each iteration of the loop.
+        return builder.substring(0, builder.length() - delimiter.length());
+    }
+
+    public static void main(String[] args) throws Exception {
+        String sourcePath = null;
+        String docletPath = null;
+        for (int i = 0; i < args.length; i++) {
+            if (args[i].equals("-s") && ++i < args.length) {
+                sourcePath = args[i];
+            } else if (args[i].equals("-d") && ++i < args.length) {
+                docletPath = args[i];
+            }
+        }
+        if (sourcePath == null || docletPath == null) {
+            System.err.println("Usage: javascanner -s SOURCE_DIR -d DOCLET_PATH");
+            System.exit(1);
+        }
+        System.exit(new JavaScanner(new File(sourcePath), new File(docletPath)).scan());
+    }
+}
diff --git a/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScannerDoclet.java b/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScannerDoclet.java
new file mode 100644
index 0000000..94eccd0
--- /dev/null
+++ b/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScannerDoclet.java
@@ -0,0 +1,73 @@
+/*
+ * 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 com.android.compatibility.common.scanner;
+
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.Doclet;
+import com.sun.javadoc.MethodDoc;
+import com.sun.javadoc.RootDoc;
+
+import java.io.PrintWriter;
+
+/**
+ * Doclet that scans java files looking for tests.
+ *
+ * Sample Ouput;
+ * suite:com.android.sample.cts
+ * case:SampleDeviceTest
+ * test:testSharedPreferences
+ */
+public class JavaScannerDoclet extends Doclet {
+
+    private static final String JUNIT_TEST_CASE_CLASS_NAME = "junit.framework.testcase";
+
+    public static boolean start(RootDoc root) {
+        ClassDoc[] classes = root.classes();
+        if (classes == null) {
+            return false;
+        }
+
+        PrintWriter writer = new PrintWriter(System.out);
+
+        for (ClassDoc clazz : classes) {
+            if (clazz.isAbstract() || !isValidJUnitTestCase(clazz)) {
+                continue;
+            }
+            writer.append("suite:").println(clazz.containingPackage().name());
+            writer.append("case:").println(clazz.name());
+            for (; clazz != null; clazz = clazz.superclass()) {
+                for (MethodDoc method : clazz.methods()) {
+                    if (method.name().startsWith("test")) {
+                        writer.append("test:").println(method.name());
+                    }
+                }
+            }
+        }
+
+        writer.close();
+        return true;
+    }
+
+    private static boolean isValidJUnitTestCase(ClassDoc clazz) {
+        while ((clazz = clazz.superclass()) != null) {
+            if (JUNIT_TEST_CASE_CLASS_NAME.equals(clazz.qualifiedName().toLowerCase())) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
diff --git a/common/host-side/java-scanner/tests/src/com/android/compatibility/common/scanner/JavaScannerTest.java b/common/host-side/java-scanner/tests/src/com/android/compatibility/common/scanner/JavaScannerTest.java
new file mode 100644
index 0000000..e18cf16
--- /dev/null
+++ b/common/host-side/java-scanner/tests/src/com/android/compatibility/common/scanner/JavaScannerTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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 com.android.compatibility.common.scanner;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class JavaScannerTest extends TestCase {
+
+    private static final String JAR = "out/host/linux-x86/framework/compatibility-java-scanner_v2.jar";
+    private static final String VALID_RESULT =
+        "suite:com.android.test" +
+        "case:ValidTest" +
+        "test:testA";
+
+    private static final String VALID_FILENAME = "ValidTest";
+    private static final String VALID =
+        "package com.android.test;" +
+        "import junit.framework.TestCase;" +
+        "public class ValidTest extends TestCase {" +
+        "  public void testA() throws Exception {" +
+        "    helper();" +
+        "  }" +
+        "  public void helper() {" +
+        "    fail();" +
+        "  }" +
+        "}";
+
+    // TestCases must have TestCase in their hierarchy
+    private static final String INVALID_A_FILENAME = "NotTestCase";
+    private static final String INVALID_A =
+        "package com.android.test;" +
+        "public class NotTestCase {" +
+        "  public void testA() throws Exception {" +
+        "    helper();" +
+        "  }" +
+        "  public void helper() {" +
+        "    fail();" +
+        "  }" +
+        "}";
+
+    // TestCases cant be abstract classes
+    private static final String INVALID_B_FILENAME = "AbstractClass";
+    private static final String INVALID_B =
+        "package com.android.test;" +
+        "import junit.framework.TestCase;" +
+        "public abstract class AbstractClass extends TestCase {" +
+        "  public void testA() throws Exception {" +
+        "    helper();" +
+        "  }" +
+        "  public void helper() {" +
+        "    fail();" +
+        "  }" +
+        "}";
+
+    public void testValidFile() throws Exception {
+        String result = runScanner(VALID_FILENAME, VALID);
+        assertEquals(VALID_RESULT, result);
+    }
+
+    public void testInvalidFileA() throws Exception {
+        assertEquals("", runScanner(INVALID_A_FILENAME, INVALID_A));
+    }
+
+    public void testInvalidFileB() throws Exception {
+        assertEquals("", runScanner(INVALID_B_FILENAME, INVALID_B));
+    }
+
+    private static String runScanner(String filename, String content) throws Exception {
+        final File parent0 = new File(System.getProperty("java.io.tmpdir"));
+        final File parent1 = new File(parent0, "tmp" + System.currentTimeMillis());
+        final File parent2 = new File(parent1, "com");
+        final File parent3 = new File(parent2, "android");
+        final File parent4 = new File(parent3, "test");
+        File f = null;
+        try {
+            parent4.mkdirs();
+            f = new File(parent4, filename + ".java");
+            final PrintWriter out = new PrintWriter(f);
+            out.print(content);
+            out.flush();
+            out.close();
+            List<String> args = new ArrayList<String>();
+            args.add("java");
+            args.add("-jar");
+            args.add(JAR);
+            args.add("-s");
+            args.add(parent1.toString());
+            args.add("-d");
+            args.add(JAR);
+
+            final Process p = new ProcessBuilder(args).start();
+            final StringBuilder output = new StringBuilder();
+            final BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            String line = null;
+            while ((line = in.readLine()) != null) {
+                output.append(line);
+            }
+            int ret = p.waitFor();
+            if (ret == 0) {
+                return output.toString();
+            }
+        } finally {
+            if (f != null) {
+                f.delete();
+            }
+            parent4.delete();
+            parent3.delete();
+            parent2.delete();
+            parent1.delete();
+        }
+        return null;
+    }
+}
diff --git a/common/host-side/native-scanner/Android.mk b/common/host-side/native-scanner/Android.mk
new file mode 100644
index 0000000..8d3242f
--- /dev/null
+++ b/common/host-side/native-scanner/Android.mk
@@ -0,0 +1,47 @@
+# 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAR_MANIFEST := MANIFEST.mf
+
+LOCAL_CLASSPATH := $(HOST_JDK_TOOLS_JAR)
+
+LOCAL_JAVA_LIBRARIES := junit
+
+LOCAL_MODULE := compatibility-native-scanner_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+################################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := compatibility-tradefed_v2 compatibility-native-scanner_v2 junit
+
+LOCAL_MODULE := compatibility-native-scanner-tests_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/host-side/native-scanner/MANIFEST.mf b/common/host-side/native-scanner/MANIFEST.mf
new file mode 100644
index 0000000..86a7212
--- /dev/null
+++ b/common/host-side/native-scanner/MANIFEST.mf
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+Main-Class: com.android.compatibility.common.scanner.NativeScanner
diff --git a/common/host-side/native-scanner/src/com/android/compatibility/common/scanner/NativeScanner.java b/common/host-side/native-scanner/src/com/android/compatibility/common/scanner/NativeScanner.java
new file mode 100644
index 0000000..581ee0b
--- /dev/null
+++ b/common/host-side/native-scanner/src/com/android/compatibility/common/scanner/NativeScanner.java
@@ -0,0 +1,30 @@
+/*
+ * 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 com.android.compatibility.common.scanner;
+
+/**
+ * Passes the gtest output and outputs a list of test classes and methods.
+ */
+public class NativeScanner {
+
+    public static void main(String[] args) throws Exception {
+        // TODO(stuartscott): Parse the gtest output comming from System.in and output in the format
+        // suite:com.android.sample.cts
+        // case:SampleDeviceTest
+        // test:testSharedPreferences
+    }
+}
diff --git a/common/util/src/android/cts/util/MeasureRun.java b/common/host-side/native-scanner/tests/src/com/android/compatibility/common/scanner/NativeScannerTest.java
similarity index 63%
copy from common/util/src/android/cts/util/MeasureRun.java
copy to common/host-side/native-scanner/tests/src/com/android/compatibility/common/scanner/NativeScannerTest.java
index 2256033..3e9ba17 100644
--- a/common/util/src/android/cts/util/MeasureRun.java
+++ b/common/host-side/native-scanner/tests/src/com/android/compatibility/common/scanner/NativeScannerTest.java
@@ -14,18 +14,12 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.scanner;
 
-/**
- * Interface for measuring time for each run.
- */
-public abstract class MeasureRun {
-    /**
-     *  Called before each run. not included in time measurement.
-     */
-    public void prepare(int i) throws Exception {
-        // default empty implementation
-    };
+import junit.framework.TestCase;
 
-    abstract public void run(int i) throws Exception;
+public class NativeScannerTest extends TestCase {
+
+    // TODO(stuartscott): Add tests when there is something to test.
+
 }
diff --git a/common/host-side/scripts/compatibility-tests_v2 b/common/host-side/scripts/compatibility-tests_v2
new file mode 100755
index 0000000..b9e479a
--- /dev/null
+++ b/common/host-side/scripts/compatibility-tests_v2
@@ -0,0 +1,61 @@
+#!/bin/bash
+#
+# 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.
+
+checkFile() {
+    if [ ! -f "$1" ]; then
+        echo "Unable to locate $1"
+        exit
+    fi;
+}
+
+HOST_JAR_DIR=${ANDROID_HOST_OUT}/framework
+HOST_JARS="ddmlib-prebuilt.jar tradefed-prebuilt.jar hosttestlib.jar\
+    compatibility-tradefed_v2.jar compatibility-tradefed-tests_v2.jar\
+    compatibility-java-scanner_v2.jar compatibility-java-scanner-tests_v2.jar\
+    compatibility-native-scanner_v2.jar compatibility-native-scanner-tests_v2.jar\
+    compatibility-xml-plan-generator_v2.jar compatibility-xml-plan-generator-tests_v2.jar\
+    compatibility-device-util-tests_v2.jar compatibility-device-setup-tests_v2.jar\
+    compatibility-common-util-hostsidelib_v2.jar compatibility-common-util-tests_v2.jar"
+
+for JAR in ${HOST_JARS}; do
+    checkFile ${HOST_JAR_DIR}/${JAR}
+    JAR_PATH=${JAR_PATH}:${HOST_JAR_DIR}/${JAR}
+done
+
+DEVICE_LIBS_DIR=${ANDROID_PRODUCT_OUT}/obj/JAVA_LIBRARIES
+DEVICE_LIBS="compatibility-common-util-devicesidelib_v2 compatibility-device-util_v2\
+    compatibility-device-setup_v2"
+
+for LIB in ${DEVICE_LIBS}; do
+    checkFile ${DEVICE_LIBS_DIR}/${LIB}_intermediates/javalib.jar
+    JAR_PATH=${JAR_PATH}:${DEVICE_LIBS_DIR}/${LIB}_intermediates/javalib.jar
+done
+
+# TODO(stuartscott): Currently the test classes are explicitly set here, but
+# once our wrappers for tradefed are in place we can make it scan and generate
+# the list of test at runtime.
+TEST_CLASSES="com.android.compatibility.common.devicesetup.DeviceSetupTest\
+    com.android.compatibility.common.scanner.JavaScannerTest\
+    com.android.compatibility.common.scanner.NativeScannerTest\
+    com.android.compatibility.common.tradefed.TradefedTest\
+    com.android.compatibility.common.util.DeviceUtilTest\
+    com.android.compatibility.common.util.CommonUtilTest\
+    com.android.compatibility.common.xmlgenerator.XmlPlanGeneratorTest"
+
+for CLASS in ${TEST_CLASSES}; do
+    java $RDBG_FLAG -cp ${JAR_PATH} com.android.compatibility.common.tradefed.command.CompatibilityConsole run\
+            singleCommand host -n --class ${CLASS} "$@"
+done
diff --git a/common/host-side/tradefed/cts-tradefed_v2 b/common/host-side/scripts/compatibility-tradefed_v2
old mode 100644
new mode 100755
similarity index 100%
rename from common/host-side/tradefed/cts-tradefed_v2
rename to common/host-side/scripts/compatibility-tradefed_v2
diff --git a/common/host-side/tradefed/Android.mk b/common/host-side/tradefed/Android.mk
index 5b5f15c..2cb559a 100644
--- a/common/host-side/tradefed/Android.mk
+++ b/common/host-side/tradefed/Android.mk
@@ -12,7 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Builds the cts tradefed host library
+###############################################################################
+# Builds the compatibility tradefed host library
+###############################################################################
 
 LOCAL_PATH := $(call my-dir)
 
@@ -22,37 +24,27 @@
 
 #LOCAL_JAVA_RESOURCE_DIRS := res
 
-LOCAL_MODULE := cts-tradefed_v2
+LOCAL_MODULE := compatibility-tradefed_v2
 
 LOCAL_MODULE_TAGS := optional
 
-LOCAL_JAVA_LIBRARIES := ddmlib-prebuilt tradefed-prebuilt hosttestlib cts-common-util-host_v2
+LOCAL_JAVA_LIBRARIES := ddmlib-prebuilt tradefed-prebuilt hosttestlib compatibility-common-util-hostsidelib_v2
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
 ###############################################################################
-# Builds the cts tradefed executable
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_PREBUILT_EXECUTABLES := cts-tradefed_v2
-
-include $(BUILD_HOST_PREBUILT)
-
+# Build the compatibility tradefed tests
 ###############################################################################
-# Builds the cts tradefed tests
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES := $(call all-java-files-under, tests)
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
 
-LOCAL_MODULE := cts-tradefed-tests_v2
+LOCAL_MODULE := compatibility-tradefed-tests_v2
 
 LOCAL_MODULE_TAGS := optional
 
-LOCAL_JAVA_LIBRARIES := ddmlib-prebuilt tradefed-prebuilt cts-tradefed_v2
+LOCAL_JAVA_LIBRARIES := ddmlib-prebuilt tradefed-prebuilt compatibility-tradefed_v2 junit
 
 LOCAL_STATIC_JAVA_LIBRARIES := easymock
 
diff --git a/common/host-side/tradefed/src/android/cts/tradefed/util/HostReportLog.java b/common/host-side/tradefed/src/android/cts/tradefed/util/HostReportLog.java
deleted file mode 100644
index 8857b5e..0000000
--- a/common/host-side/tradefed/src/android/cts/tradefed/util/HostReportLog.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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 android.cts.tradefed.util;
-
-import android.cts.util.ReportLog;
-
-/**
- * ReportLog for host tests
- * Note that setTestInfo should be set before throwing report
- */
-public class HostReportLog extends ReportLog {
-
-    private String mKey;
-
-    /**
-     * @param deviceSerial serial number of the device
-     */
-    public HostReportLog(String deviceSerial) {
-        final StackTraceElement e = Thread.currentThread().getStackTrace()[1];
-        mKey = String.format("%s#%s#%s", deviceSerial, e.getClassName(), e.getMethodName());
-    }
-
-    public void submit() {
-        ResultStore.addResult(mKey, this);
-    }
-}
diff --git a/common/host-side/tradefed/src/android/cts/tradefed/util/ResultStore.java b/common/host-side/tradefed/src/android/cts/tradefed/util/ResultStore.java
deleted file mode 100644
index 0e2be7c..0000000
--- a/common/host-side/tradefed/src/android/cts/tradefed/util/ResultStore.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 android.cts.tradefed.util;
-
-import android.cts.util.ReportLog;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Utility class for storing Cts Results.
- * This is necessary for host tests where test metrics cannot be passed.
- */
-public class ResultStore {
-
-    // needs concurrent verion as there can be multiple client accessing this.
-    // But there is no additional protection for the same key as that should not happen.
-    private static final ConcurrentHashMap<String, ReportLog> mMap =
-            new ConcurrentHashMap<String, ReportLog>();
-
-    /**
-     * Stores CTS result. Existing result with the same key will be replaced.
-     * Note that key is generated in the form of device_serial#class#method_name.
-     * So there should be no concurrent test for the same (serial, class, method).
-     * @param key
-     * @param result CTS result
-     */
-    public static void addResult(String key, ReportLog result) {
-        mMap.put(key, result);
-    }
-
-    /**
-     * retrieves a CTS result for the given condition and remove it from the internal
-     * storage. If there is no result for the given condition, it will return null.
-     */
-    public static ReportLog removeResult(String key) {
-        return mMap.remove(key);
-    }
-
-}
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/command/CompatibilityConsole.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/command/CompatibilityConsole.java
new file mode 100644
index 0000000..56f7db8
--- /dev/null
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/command/CompatibilityConsole.java
@@ -0,0 +1,30 @@
+/*
+ * 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 com.android.compatibility.common.tradefed.command;
+
+import com.android.tradefed.command.Console;
+
+/**
+ * An extension of Tradefed's console which adds features specific to compatibility testing.
+ */
+public class CompatibilityConsole extends Console {
+
+    public static void main(String[] args) throws InterruptedException {
+        CompatibilityConsole console = new CompatibilityConsole();
+        Console.startConsole(console, args);
+    }
+}
diff --git a/common/util/src/android/cts/util/MeasureRun.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/TradefedTest.java
similarity index 63%
copy from common/util/src/android/cts/util/MeasureRun.java
copy to common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/TradefedTest.java
index 2256033..ab19369 100644
--- a/common/util/src/android/cts/util/MeasureRun.java
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/TradefedTest.java
@@ -14,18 +14,12 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.tradefed;
 
-/**
- * Interface for measuring time for each run.
- */
-public abstract class MeasureRun {
-    /**
-     *  Called before each run. not included in time measurement.
-     */
-    public void prepare(int i) throws Exception {
-        // default empty implementation
-    };
+import junit.framework.TestCase;
 
-    abstract public void run(int i) throws Exception;
+public class TradefedTest extends TestCase {
+
+    // TODO(stuartscott): Add tests when there is something to test.
+
 }
diff --git a/common/host-side/xml-plan-generator/Android.mk b/common/host-side/xml-plan-generator/Android.mk
new file mode 100644
index 0000000..36491bd
--- /dev/null
+++ b/common/host-side/xml-plan-generator/Android.mk
@@ -0,0 +1,45 @@
+# 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAR_MANIFEST := MANIFEST.mf
+
+LOCAL_CLASSPATH := $(HOST_JDK_TOOLS_JAR)
+
+LOCAL_MODULE := compatibility-xml-plan-generator_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+###############################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := compatibility-tradefed_v2 compatibility-xml-plan-generator_v2 junit
+
+LOCAL_MODULE := compatibility-xml-plan-generator-tests_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/host-side/xml-plan-generator/MANIFEST.mf b/common/host-side/xml-plan-generator/MANIFEST.mf
new file mode 100644
index 0000000..c021388
--- /dev/null
+++ b/common/host-side/xml-plan-generator/MANIFEST.mf
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+Main-Class: com.android.compatibility.common.xmlgenerator.XmlPlanGenerator
diff --git a/common/util/src/android/cts/util/MeasureRun.java b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/XmlPlanGenerator.java
similarity index 64%
copy from common/util/src/android/cts/util/MeasureRun.java
copy to common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/XmlPlanGenerator.java
index 2256033..510c935 100644
--- a/common/util/src/android/cts/util/MeasureRun.java
+++ b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/XmlPlanGenerator.java
@@ -14,18 +14,14 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.xmlgenerator;
 
 /**
- * Interface for measuring time for each run.
+ * Passes the scanner output and outputs an xml description of the tests.
  */
-public abstract class MeasureRun {
-    /**
-     *  Called before each run. not included in time measurement.
-     */
-    public void prepare(int i) throws Exception {
-        // default empty implementation
-    };
+public class XmlPlanGenerator {
 
-    abstract public void run(int i) throws Exception;
+    public static void main(String[] args) throws Exception {
+        // TODO(stuartscott)
+    }
 }
diff --git a/common/util/src/android/cts/util/MeasureRun.java b/common/host-side/xml-plan-generator/tests/src/com/android/compatibility/common/xmlgenerator/XmlPlanGeneratorTest.java
similarity index 63%
copy from common/util/src/android/cts/util/MeasureRun.java
copy to common/host-side/xml-plan-generator/tests/src/com/android/compatibility/common/xmlgenerator/XmlPlanGeneratorTest.java
index 2256033..35bcb02 100644
--- a/common/util/src/android/cts/util/MeasureRun.java
+++ b/common/host-side/xml-plan-generator/tests/src/com/android/compatibility/common/xmlgenerator/XmlPlanGeneratorTest.java
@@ -14,18 +14,11 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.xmlgenerator;
 
-/**
- * Interface for measuring time for each run.
- */
-public abstract class MeasureRun {
-    /**
-     *  Called before each run. not included in time measurement.
-     */
-    public void prepare(int i) throws Exception {
-        // default empty implementation
-    };
+import junit.framework.TestCase;
 
-    abstract public void run(int i) throws Exception;
+public class XmlPlanGeneratorTest extends TestCase {
+
+    // TODO(stuartscott): Add tests when there is something to test.
 }
diff --git a/common/util/Android.mk b/common/util/Android.mk
index 6b40a8d..b7842559 100644
--- a/common/util/Android.mk
+++ b/common/util/Android.mk
@@ -12,6 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+###############################################################################
+# Build the common utility library for use device-side
+###############################################################################
+
 LOCAL_PATH:= $(call my-dir)
 
 include $(CLEAR_VARS)
@@ -20,13 +24,15 @@
 
 LOCAL_MODULE_TAGS := optional
 
-LOCAL_MODULE := cts-common-util-device_v2
+LOCAL_MODULE := compatibility-common-util-devicesidelib_v2
 
 LOCAL_SDK_VERSION := current
 
 include $(BUILD_STATIC_JAVA_LIBRARY)
 
 ###############################################################################
+# Build the common utility library for use host-side
+###############################################################################
 
 include $(CLEAR_VARS)
 
@@ -34,6 +40,22 @@
 
 LOCAL_MODULE_TAGS := optional
 
-LOCAL_MODULE := cts-common-util-host_v2
+LOCAL_MODULE := compatibility-common-util-hostsidelib_v2
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+###############################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := junit
+
+LOCAL_MODULE := compatibility-common-util-tests_v2
+
+LOCAL_MODULE_TAGS := optional
 
 include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/util/src/android/cts/util/ReportLog.java b/common/util/src/android/cts/util/ReportLog.java
deleted file mode 100644
index fe2a15d..0000000
--- a/common/util/src/android/cts/util/ReportLog.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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 android.cts.util;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Utility class to add results to the report.
- */
-public abstract class ReportLog implements Serializable {
-
-    private Result mSummary;
-    private final List<Result> mDetails = new ArrayList<Result>();
-
-    private class Result implements Serializable {
-        private static final int DEPTH = 2;// 0:constructor, 1:addValues/setSummary, 2:caller
-        private String mLocation;
-        private String mMessage;
-        private double[] mValues;
-        private ResultType mType;
-        private ResultUnit mUnit;
-
-        private Result(String message, double[] values, ResultType type, ResultUnit unit) {
-            final StackTraceElement e = Thread.currentThread().getStackTrace()[DEPTH];
-            mLocation = String.format("%s#%s:%d",
-                    e.getClassName(), e.getMethodName(), e.getLineNumber());
-            mMessage = message;
-            mValues = values;
-            mType = type;
-            mUnit = unit;
-        }
-
-    }
-
-    /**
-     * Adds an array of values to the report.
-     */
-    public void addValues(String message, double[] values, ResultType type, ResultUnit unit) {
-        mDetails.add(new Result(message, values, type, unit));
-    }
-
-    /**
-     * Adds a value to the report.
-     */
-    public void addValue(String message, double value, ResultType type, ResultUnit unit) {
-        mDetails.add(new Result(message, new double[] {value}, type, unit));
-    }
-
-    /**
-     * Sets the summary of the report.
-     */
-    public void setSummary(String message, double value, ResultType type, ResultUnit unit) {
-        mSummary = new Result(message, new double[] {value}, type, unit);
-    }
-
-}
diff --git a/common/util/src/android/cts/util/MeasureRun.java b/common/util/src/com/android/compatibility/common/util/MeasureRun.java
similarity index 94%
rename from common/util/src/android/cts/util/MeasureRun.java
rename to common/util/src/com/android/compatibility/common/util/MeasureRun.java
index 2256033..d58b8d4 100644
--- a/common/util/src/android/cts/util/MeasureRun.java
+++ b/common/util/src/com/android/compatibility/common/util/MeasureRun.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 /**
  * Interface for measuring time for each run.
diff --git a/common/util/src/android/cts/util/MeasureTime.java b/common/util/src/com/android/compatibility/common/util/MeasureTime.java
similarity index 96%
rename from common/util/src/android/cts/util/MeasureTime.java
rename to common/util/src/com/android/compatibility/common/util/MeasureTime.java
index 073ed08..102b96a 100644
--- a/common/util/src/android/cts/util/MeasureTime.java
+++ b/common/util/src/com/android/compatibility/common/util/MeasureTime.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 /**
  * Provides a mechanism to measure the time taken to run a piece of code.
diff --git a/common/util/src/com/android/compatibility/common/util/ReportLog.java b/common/util/src/com/android/compatibility/common/util/ReportLog.java
new file mode 100644
index 0000000..9e733e4
--- /dev/null
+++ b/common/util/src/com/android/compatibility/common/util/ReportLog.java
@@ -0,0 +1,111 @@
+/*
+ * 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 com.android.compatibility.common.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Utility class to add results to the report.
+ */
+public abstract class ReportLog implements Serializable {
+
+    private Result mSummary;
+    private final List<Result> mDetails = new ArrayList<Result>();
+
+    private class Result implements Serializable {
+        private static final int BASE_DEPTH = 2;// 0:constructor, 1:addValues/setSummary, 2:caller
+        private String mLocation;
+        private String mMessage;
+        private double[] mValues;
+        private ResultType mType;
+        private ResultUnit mUnit;
+
+        /**
+         * Creates a result object to be included in the report. Each object has a message
+         * describing its values and enums to interpret them. In addition, each result also includes
+         * class, method and line number information about the test which added this result which is
+         * collected by looking at the stack trace.
+         *
+         * @param message A string describing the values
+         * @param values An array of the values
+         * @param type Represents how to interpret the values (eg. A lower score is better)
+         * @param unit Represents the unit in which the values are (eg. Milliseconds)
+         * @param depth A number used to increase the depth the stack is queried. This should only
+         * be given in the case that the report is populated by a helper function, in which case it
+         * would be 1, or else 0.
+         */
+        private Result(String message, double[] values, ResultType type,
+                ResultUnit unit, int depth) {
+            final StackTraceElement[] trace = Thread.currentThread().getStackTrace();
+            final StackTraceElement e = trace[Math.min(BASE_DEPTH + depth, trace.length - 1)];
+            mLocation = String.format("%s#%s:%d",
+                    e.getClassName(), e.getMethodName(), e.getLineNumber());
+            mMessage = message;
+            mValues = values;
+            mType = type;
+            mUnit = unit;
+        }
+
+    }
+
+    /**
+     * Adds an array of values to the report.
+     */
+    public void addValues(String message, double[] values, ResultType type, ResultUnit unit) {
+        mDetails.add(new Result(message, values, type, unit, 0));
+    }
+
+    /**
+     * Adds an array of values to the report.
+     */
+    public void addValues(String message, double[] values, ResultType type,
+            ResultUnit unit, int depth) {
+        mDetails.add(new Result(message, values, type, unit, depth));
+    }
+
+    /**
+     * Adds a value to the report.
+     */
+    public void addValue(String message, double value, ResultType type, ResultUnit unit) {
+        mDetails.add(new Result(message, new double[] {value}, type, unit, 0));
+    }
+
+    /**
+     * Adds a value to the report.
+     */
+    public void addValue(String message, double value, ResultType type,
+            ResultUnit unit, int depth) {
+        mDetails.add(new Result(message, new double[] {value}, type, unit, depth));
+    }
+
+    /**
+     * Sets the summary of the report.
+     */
+    public void setSummary(String message, double value, ResultType type, ResultUnit unit) {
+        mSummary = new Result(message, new double[] {value}, type, unit, 0);
+    }
+
+    /**
+     * Sets the summary of the report.
+     */
+    public void setSummary(String message, double value, ResultType type,
+            ResultUnit unit, int depth) {
+        mSummary = new Result(message, new double[] {value}, type, unit, depth);
+    }
+}
diff --git a/common/util/src/android/cts/util/ResultType.java b/common/util/src/com/android/compatibility/common/util/ResultType.java
similarity index 91%
rename from common/util/src/android/cts/util/ResultType.java
rename to common/util/src/com/android/compatibility/common/util/ResultType.java
index cb6be4d..779c6d0 100644
--- a/common/util/src/android/cts/util/ResultType.java
+++ b/common/util/src/com/android/compatibility/common/util/ResultType.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 /**
  * Enum for distinguishing results.
@@ -30,7 +30,7 @@
     WARNING;
 
     /**
-     * Return string used in CTS XML report
+     * Return string used in the XML report
      */
     public String getXmlString() {
         return name().toLowerCase();
diff --git a/common/util/src/android/cts/util/ResultUnit.java b/common/util/src/com/android/compatibility/common/util/ResultUnit.java
similarity index 92%
rename from common/util/src/android/cts/util/ResultUnit.java
rename to common/util/src/com/android/compatibility/common/util/ResultUnit.java
index 964309c..f38ddae 100644
--- a/common/util/src/android/cts/util/ResultUnit.java
+++ b/common/util/src/com/android/compatibility/common/util/ResultUnit.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 /**
  * Enum for representing the unit of results.
@@ -40,7 +40,7 @@
     SCORE;
 
     /**
-     * Return string used in CTS XML report
+     * Return string used in the XML report
      */
     public String getXmlString() {
         return name().toLowerCase();
diff --git a/common/util/src/android/cts/util/Stat.java b/common/util/src/com/android/compatibility/common/util/Stat.java
similarity index 98%
rename from common/util/src/android/cts/util/Stat.java
rename to common/util/src/com/android/compatibility/common/util/Stat.java
index b4596c3..8bf9bf7 100644
--- a/common/util/src/android/cts/util/Stat.java
+++ b/common/util/src/com/android/compatibility/common/util/Stat.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
 import java.util.Arrays;
 
@@ -101,7 +101,7 @@
                     min = data[i];
                 }
             }
-            //TODO report rejected data
+            // TODO report rejected data
         }
         double stddev;
         if (validDataCounter > 0) {
diff --git a/common/util/src/android/cts/util/MeasureRun.java b/common/util/tests/src/com/android/compatibility/common/util/CommonUtilTest.java
similarity index 63%
copy from common/util/src/android/cts/util/MeasureRun.java
copy to common/util/tests/src/com/android/compatibility/common/util/CommonUtilTest.java
index 2256033..a376373 100644
--- a/common/util/src/android/cts/util/MeasureRun.java
+++ b/common/util/tests/src/com/android/compatibility/common/util/CommonUtilTest.java
@@ -14,18 +14,12 @@
  * limitations under the License.
  */
 
-package android.cts.util;
+package com.android.compatibility.common.util;
 
-/**
- * Interface for measuring time for each run.
- */
-public abstract class MeasureRun {
-    /**
-     *  Called before each run. not included in time measurement.
-     */
-    public void prepare(int i) throws Exception {
-        // default empty implementation
-    };
+import junit.framework.TestCase;
 
-    abstract public void run(int i) throws Exception;
+public class CommonUtilTest extends TestCase {
+
+    // TODO(stuartscott): Add tests when there is something to test.
+
 }