am 0d4a4a3b: am d35f8eb4: Adding CTS test samples device- and host-side tests.

* commit '0d4a4a3bc49e421210634507e1f4b9a258cf0ce0':
  Adding CTS test samples device- and host-side tests.
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index dab7b67..dbf82c9 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -39,6 +39,7 @@
     CtsDeviceAdmin \
     CtsMonkeyApp \
     CtsMonkeyApp2 \
+    CtsSampleDeviceApp \
     CtsSomeAccessibilityServices \
     CtsTestStubs \
     SignatureTest \
@@ -82,7 +83,6 @@
     CtsDreamsTestCases \
     CtsDrmTestCases \
     CtsEffectTestCases \
-    CtsExampleTestCases \
     CtsGestureTestCases \
     CtsGraphicsTestCases \
     CtsGraphics2TestCases \
@@ -107,6 +107,7 @@
     CtsRenderscriptTestCases \
     CtsRenderscriptGraphicsTestCases \
     CtsRsCppTestCases \
+    CtsSampleDeviceTestCases \
     CtsSaxTestCases \
     CtsSecurityTestCases \
     CtsSpeechTestCases \
@@ -124,7 +125,6 @@
 	$(cts_support_packages) \
 	$(cts_test_packages)
 
-
 # Host side only tests
 cts_host_libraries := \
     CtsHostUi \
@@ -132,9 +132,9 @@
     CtsAdbTests \
     CtsAppSecurityTests \
     CtsMonkeyTestCases \
+    CtsSampleHostTestCases \
     CtsUsbTests
 
-
 # Native test executables that need to have associated test XMLs.
 cts_native_exes := \
 	NativeMediaTest_SL \
diff --git a/build/test_package.mk b/build/test_package.mk
index 73f2a13..a0adb5f 100644
--- a/build/test_package.mk
+++ b/build/test_package.mk
@@ -36,12 +36,12 @@
 $(cts_package_xml): PRIVATE_PATH := $(LOCAL_PATH)
 $(cts_package_xml): PRIVATE_INSTRUMENTATION := $(LOCAL_INSTRUMENTATION_FOR)
 $(cts_package_xml): PRIVATE_PACKAGE := $(LOCAL_PACKAGE_NAME)
-ifneq ($(filter cts/suite/cts/%, $(LOCAL_PATH)),) # CTS
-PRIVATE_CTS_TEST_PACKAGE_NANE_ := com.android.cts.$(notdir $(LOCAL_PATH))
-else # CTS
-PRIVATE_CTS_TEST_PACKAGE_NANE_ := android.$(notdir $(LOCAL_PATH))
-endif # CTS
-$(cts_package_xml): PRIVATE_TEST_PACKAGE := $(PRIVATE_CTS_TEST_PACKAGE_NANE_)
+ifneq ($(filter cts/suite/cts/%, $(LOCAL_PATH)),)
+PRIVATE_CTS_TEST_PACKAGE_NAME_ := com.android.cts.$(notdir $(LOCAL_PATH))
+else
+PRIVATE_CTS_TEST_PACKAGE_NAME_ := android.$(notdir $(LOCAL_PATH))
+endif
+$(cts_package_xml): PRIVATE_TEST_PACKAGE := $(PRIVATE_CTS_TEST_PACKAGE_NAME_)
 $(cts_package_xml): PRIVATE_MANIFEST := $(LOCAL_PATH)/AndroidManifest.xml
 $(cts_package_xml): PRIVATE_TEST_TYPE := $(if $(LOCAL_CTS_TEST_RUNNER),$(LOCAL_CTS_TEST_RUNNER),'')
 $(cts_package_xml): $(call intermediates-dir-for,APPS,$(LOCAL_PACKAGE_NAME))/package.apk $(CTS_EXPECTATIONS) $(CTS_JAVA_TEST_SCANNER_DOCLET) $(CTS_JAVA_TEST_SCANNER) $(CTS_XML_GENERATOR)
diff --git a/hostsidetests/sample/Android.mk b/hostsidetests/sample/Android.mk
new file mode 100644
index 0000000..1d3ddc8
--- /dev/null
+++ b/hostsidetests/sample/Android.mk
@@ -0,0 +1,32 @@
+# 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_MODULE_TAGS := optional
+
+# Must match the package name in CtsTestCaseList.mk
+LOCAL_MODULE := CtsSampleHostTestCases
+
+LOCAL_JAVA_LIBRARIES := cts-tradefed ddmlib-prebuilt tradefed-prebuilt
+
+LOCAL_CTS_TEST_PACKAGE := android.host.sample
+
+include $(BUILD_CTS_HOST_JAVA_LIBRARY)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/tests/example/Android.mk b/hostsidetests/sample/app/Android.mk
similarity index 76%
copy from tests/tests/example/Android.mk
copy to hostsidetests/sample/app/Android.mk
index c6ef67b..4af45b9 100644
--- a/tests/tests/example/Android.mk
+++ b/hostsidetests/sample/app/Android.mk
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 The Android Open Source Project
+# 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.
@@ -16,22 +16,16 @@
 
 include $(CLEAR_VARS)
 
-# Replace "Example" with your name.
-LOCAL_PACKAGE_NAME := CtsExampleTestCases
-
 # Don't include this package in any target.
 LOCAL_MODULE_TAGS := optional
 
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-# All tests should include android.test.runner.
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
-
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
+LOCAL_PACKAGE_NAME := CtsSampleDeviceApp
+
 LOCAL_SDK_VERSION := current
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/sample/app/AndroidManifest.xml b/hostsidetests/sample/app/AndroidManifest.xml
new file mode 100755
index 0000000..c087435
--- /dev/null
+++ b/hostsidetests/sample/app/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="android.sample.app">
+
+    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+    <application>
+        <activity android:name=".SampleDeviceActivity" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
+
diff --git a/hostsidetests/sample/app/src/android/sample/app/SampleDeviceActivity.java b/hostsidetests/sample/app/src/android/sample/app/SampleDeviceActivity.java
new file mode 100644
index 0000000..d7efc0c
--- /dev/null
+++ b/hostsidetests/sample/app/src/android/sample/app/SampleDeviceActivity.java
@@ -0,0 +1,44 @@
+/*
+ * 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.sample.app;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+
+import java.lang.Override;
+
+/**
+ * A simple activity which logs to Logcat.
+ */
+public class SampleDeviceActivity extends Activity {
+
+    private static final String TAG = SampleDeviceActivity.class.getSimpleName();
+
+    /**
+     * The test string to log.
+     */
+    private static final String TEST_STRING = "SampleTestString";
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        // Log the test string to Logcat.
+        Log.i(TAG, TEST_STRING);
+    }
+
+}
diff --git a/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java b/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java
new file mode 100644
index 0000000..a3bc08f
--- /dev/null
+++ b/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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.sample.cts;
+
+import com.android.cts.tradefed.build.CtsBuildHelper;
+import com.android.cts.tradefed.util.HostReportLog;
+import com.android.cts.util.MeasureRun;
+import com.android.cts.util.MeasureTime;
+import com.android.cts.util.ResultType;
+import com.android.cts.util.ResultUnit;
+import com.android.cts.util.ReportLog;
+import com.android.cts.util.Stat;
+import com.android.ddmlib.Log;
+import com.android.ddmlib.IDevice;
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.testtype.DeviceTestCase;
+import com.android.tradefed.testtype.IBuildReceiver;
+import com.android.tradefed.util.CommandResult;
+import com.android.tradefed.util.CommandStatus;
+import com.android.tradefed.util.FileUtil;
+import com.android.tradefed.util.RunUtil;
+
+import java.io.File;
+import java.lang.Exception;
+
+/**
+ * Test to measure the transfer time of a file from the host to the device.
+ */
+public class SampleHostResultTest extends DeviceTestCase implements IBuildReceiver {
+
+    private static final String TAG = SampleHostResultTest.class.getSimpleName();
+
+    /**
+     * The number of times to repeat the test.
+     */
+    private static final int REPEAT = 5;
+
+    /**
+     * The name of the plan to transfer.
+     *
+     * In this case we will transfer the CTS.xml file.
+     */
+    private static final String PLAN_NAME = "CTS";
+
+    /**
+     * A reference to the build.
+     */
+    private CtsBuildHelper mBuild;
+
+    /**
+     * A reference to the device under test.
+     */
+    private ITestDevice mDevice;
+
+    @Override
+    public void setBuild(IBuildInfo buildInfo) {
+        // Get the build, this is used to access the APK.
+        mBuild = CtsBuildHelper.createBuildHelper(buildInfo);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        // Get the device, this gives a handle to run commands and install APKs.
+        mDevice = getDevice();
+    }
+
+    /**
+     * Measures the time taken to transfer a file to the device and then back.
+     *
+     * The workload is repeated several times and the report is populated with the result.
+     *
+     * @throws Exception
+     */
+    public void testTransferTime() throws Exception {
+        final ITestDevice device = mDevice;
+        // Get the external storage location and ensure its not null.
+        final String externalStorePath = mDevice.getMountPoint(IDevice.MNT_EXTERNAL_STORAGE);
+        assertNotNull("External storage location no found", externalStorePath);
+        // Create the device side path where the file will be transfered.
+        final String devicePath = String.format("%s/%s", externalStorePath, "tmp_testPushPull.txt");
+        // Get the file from the build.
+        final File testFile = mBuild.getTestPlanFile(PLAN_NAME);
+        double[] result = MeasureTime.measure(REPEAT, new MeasureRun() {
+            @Override
+            public void prepare(int i) throws Exception {
+                device.executeShellCommand(String.format("rm %s", devicePath));
+            }
+            @Override
+            public void run(int i) throws Exception {
+                // Create a temporary file to compare with.
+                File tmpFile = FileUtil.createTempFile("tmp", "txt");
+                try {
+                    // Push the file across and ensure it exists.
+                    assertTrue("Could not push file", device.pushFile(testFile, devicePath));
+                    assertTrue("Unsuccessful transfer", device.doesFileExist(devicePath));
+                    // Pull the file back and ensure it is the same.
+                    assertTrue("Could not pull file", device.pullFile(devicePath, tmpFile));
+                    assertFilesAreEqual(testFile, tmpFile);
+                } finally {
+                    // Clean up.
+                    tmpFile.delete();
+                    device.executeShellCommand(String.format("rm %s", devicePath));
+                }
+            }
+        });
+        // Compute the stats.
+        Stat.StatResult stat = Stat.getStat(result);
+        // Get the report for this test and add the results to record.
+        HostReportLog report = new HostReportLog(mDevice.getSerialNumber(),
+                ReportLog.getClassMethodNames());
+        report.printArray("Times", result, ResultType.LOWER_BETTER, ResultUnit.MS);
+        report.printValue("Min", stat.mMin, ResultType.LOWER_BETTER, ResultUnit.MS);
+        report.printValue("Max", stat.mMax, ResultType.LOWER_BETTER, ResultUnit.MS);
+        // Every report must have a summary,
+        report.printSummary("Average", stat.mAverage, ResultType.LOWER_BETTER, ResultUnit.MS);
+        // Send the report to Tradefed.
+        report.deliverReportToHost();
+    }
+
+    /**
+     * Asserts the two given files are equal using the diff utility.
+     *
+     * @throws Exception
+     */
+    private static void assertFilesAreEqual(File first, File second) throws Exception {
+        CommandResult result = RunUtil.getDefault().runTimedCmd(5000, "diff",
+                first.getAbsolutePath(), second.getAbsolutePath());
+        assertTrue("Diff failed to run", result.getStatus() == CommandStatus.SUCCESS);
+        assertTrue("Files are not equivalent", "".equals(result.getStdout()));
+    }
+
+}
diff --git a/hostsidetests/sample/src/android/sample/cts/SampleHostTest.java b/hostsidetests/sample/src/android/sample/cts/SampleHostTest.java
new file mode 100644
index 0000000..7ccde0e
--- /dev/null
+++ b/hostsidetests/sample/src/android/sample/cts/SampleHostTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.sample.cts;
+
+import com.android.cts.tradefed.build.CtsBuildHelper;
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.testtype.DeviceTestCase;
+import com.android.tradefed.testtype.IBuildReceiver;
+
+import java.io.File;
+import java.lang.String;
+import java.util.Scanner;
+
+/**
+ * Test to check the APK logs to Logcat.
+ *
+ * When this test builds, it also builds {@see android.sample.app.SampleDeviceActivity} into an APK
+ * which it then installs at runtime and starts. The activity simply prints a message to Logcat and
+ * then gets uninstalled.
+ */
+public class SampleHostTest extends DeviceTestCase implements IBuildReceiver {
+
+    /**
+     * The package name of the APK.
+     */
+    private static final String PACKAGE = "android.sample.app";
+
+    /**
+     * The file name of the APK.
+     */
+    private static final String APK = "CtsSampleDeviceApp.apk";
+
+    /**
+     * The class name of the main activity in the APK.
+     */
+    private static final String CLASS = "SampleDeviceActivity";
+
+    /**
+     * The command to launch the main activity.
+     */
+    private static final String START_COMMAND = String.format(
+            "am start -W -a android.intent.action.MAIN -n %s/%s.%s", PACKAGE, PACKAGE, CLASS);
+
+    /**
+     * The test string to look for.
+     */
+    private static final String TEST_STRING = "SampleTestString";
+
+    /**
+     * A reference to the build.
+     */
+    private CtsBuildHelper mBuild;
+
+    /**
+     * A reference to the device under test.
+     */
+    private ITestDevice mDevice;
+
+    @Override
+    public void setBuild(IBuildInfo buildInfo) {
+        // Get the build, this is used to access the APK.
+        mBuild = CtsBuildHelper.createBuildHelper(buildInfo);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        // Get the device, this gives a handle to run commands and install APKs.
+        mDevice = getDevice();
+        // Remove any previously installed versions of this APK.
+        mDevice.uninstallPackage(PACKAGE);
+        // Get the APK from the build.
+        File app = mBuild.getTestApp(APK);
+        // Install the APK on the device.
+        mDevice.installPackage(app, false);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        // Remove the package once complete.
+        mDevice.uninstallPackage(PACKAGE);
+        super.tearDown();
+    }
+
+    /**
+     * Tests the string was successfully logged to Logcat from the activity.
+     *
+     * @throws Exception
+     */
+    public void testLogcat() throws Exception {
+        // Clear logcat.
+        mDevice.executeAdbCommand("logcat", "-c");
+        // Start the APK and wait for it to complete.
+        mDevice.executeShellCommand(START_COMMAND);
+        // Dump logcat.
+        String logs = mDevice.executeAdbCommand("logcat", "-d", CLASS + ":I", "*:S");
+        // Search for string.
+        String testString = "";
+        Scanner in = new Scanner(logs);
+        while (in.hasNextLine()) {
+            String line = in.nextLine();
+            if(line.startsWith("I/"+CLASS)) {
+                testString = line.split(":")[1].trim();
+            }
+        }
+        // Assert the logged string matches the test string.
+        assertEquals("Incorrect test string", TEST_STRING, testString);
+    }
+}
diff --git a/libs/commonutil/src/com/android/cts/util/MeasureTime.java b/libs/commonutil/src/com/android/cts/util/MeasureTime.java
index c158228..fd22ef2 100644
--- a/libs/commonutil/src/com/android/cts/util/MeasureTime.java
+++ b/libs/commonutil/src/com/android/cts/util/MeasureTime.java
@@ -23,9 +23,9 @@
      * @param count
      * @param run
      * @return array of time taken in each run in msec.
-     * @throws IOException
+     * @throws Exception
      */
-    public static double[] measure(int count, MeasureRun run)  throws Exception {
+    public static double[] measure(int count, MeasureRun run) throws Exception {
         double[] result = new double[count];
 
         for (int i = 0; i < count; i++) {
diff --git a/tests/tests/example/Android.mk b/tests/sample/Android.mk
old mode 100644
new mode 100755
similarity index 82%
rename from tests/tests/example/Android.mk
rename to tests/sample/Android.mk
index c6ef67b..e1a9408
--- a/tests/tests/example/Android.mk
+++ b/tests/sample/Android.mk
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 The Android Open Source Project
+# 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.
@@ -16,9 +16,6 @@
 
 include $(CLEAR_VARS)
 
-# Replace "Example" with your name.
-LOCAL_PACKAGE_NAME := CtsExampleTestCases
-
 # Don't include this package in any target.
 LOCAL_MODULE_TAGS := optional
 
@@ -28,10 +25,13 @@
 # All tests should include android.test.runner.
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctstestrunner
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
+# Must match the package name in CtsTestCaseList.mk
+LOCAL_PACKAGE_NAME := CtsSampleDeviceTestCases
+
 LOCAL_SDK_VERSION := current
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/sample/AndroidManifest.xml b/tests/sample/AndroidManifest.xml
new file mode 100755
index 0000000..ae58f0a
--- /dev/null
+++ b/tests/sample/AndroidManifest.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="android.sample.cts">
+
+    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+    <application>
+        <uses-library android:name="android.test.runner" />
+        <activity android:name="android.sample.SampleDeviceActivity" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+    <!--  self-instrumenting test package. -->
+    <instrumentation
+        android:name="android.test.InstrumentationCtsTestRunner"
+        android:label="CTS sample tests"
+        android:targetPackage="android.sample.cts" />
+
+</manifest>
+
diff --git a/tests/sample/src/android/sample/SampleDeviceActivity.java b/tests/sample/src/android/sample/SampleDeviceActivity.java
new file mode 100644
index 0000000..8fd8fde
--- /dev/null
+++ b/tests/sample/src/android/sample/SampleDeviceActivity.java
@@ -0,0 +1,78 @@
+/*
+ * 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.sample;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.os.Bundle;
+
+import java.lang.Override;
+
+/**
+ * A simple activity for using the SharedPreferences API.
+ */
+public class SampleDeviceActivity extends Activity {
+
+    private SharedPreferences mPreferences;
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        // Get a reference to this context's shared preference.
+        mPreferences = getPreferences(Context.MODE_PRIVATE);
+    }
+
+    /**
+     * Saves the given key value pair to the shared preferences.
+     *
+     * @param key
+     * @param value
+     */
+    public void savePreference(String key, String value) {
+        // Get an editor to modify the preferences.
+        Editor editor = mPreferences.edit();
+        // Insert the key value pair.
+        editor.putString(key, value);
+        // Commit the changes - important.
+        editor.commit();
+    }
+
+    /**
+     * Looks up the given key in the shared preferences.
+     *
+     * @param key
+     * @return
+     */
+    public String getPreference(String key) {
+        return mPreferences.getString(key, null);
+    }
+
+    /**
+     * Deletes all entries in the shared preferences.
+     */
+    public void clearPreferences() {
+        // Get an editor to modify the preferences.
+        Editor editor = mPreferences.edit();
+        // Delete all entries.
+        editor.clear();
+        // Commit the changes - important.
+        editor.commit();
+    }
+
+}
diff --git a/tests/sample/src/android/sample/cts/SampleDeviceResultTest.java b/tests/sample/src/android/sample/cts/SampleDeviceResultTest.java
new file mode 100644
index 0000000..6bf883f
--- /dev/null
+++ b/tests/sample/src/android/sample/cts/SampleDeviceResultTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.sample.cts;
+
+import com.android.cts.util.MeasureRun;
+import com.android.cts.util.MeasureTime;
+import com.android.cts.util.ReportLog;
+import com.android.cts.util.ResultType;
+import com.android.cts.util.ResultUnit;
+import com.android.cts.util.Stat;
+
+import android.cts.util.CtsAndroidTestCase;
+
+/**
+ * A simple compatibility test which includes results in the report.
+ *
+ * This test measures the time taken to run a workload and adds in the report.
+ */
+public class SampleDeviceResultTest extends CtsAndroidTestCase {
+
+    /**
+     * The number of times to repeat the test.
+     */
+    private static final int REPEAT = 5;
+
+    /**
+     * The input number for the factorial.
+     */
+    private static final int IN = 15;
+
+    /**
+     * The expected output number for the factorial.
+     */
+    private static final long OUT = 1307674368000L;
+
+    /**
+     * Measures the time taken to compute the factorial of 15 with a recursive method.
+     *
+     * @throws Exception
+     */
+    public void testFactorialRecursive() throws Exception {
+        runTest(new MeasureRun() {
+            @Override
+            public void run(int i) throws Exception {
+                // Compute the factorial and assert it is correct.
+                assertEquals("Incorrect result", OUT, factorialRecursive(IN));
+            }
+        });
+    }
+
+    /**
+     * Measures the time taken to compute the factorial of 15 with a iterative method.
+     *
+     * @throws Exception
+     */
+    public void testFactorialIterative() throws Exception {
+        runTest(new MeasureRun() {
+            @Override
+            public void run(int i) throws Exception {
+                // Compute the factorial and assert it is correct.
+                assertEquals("Incorrect result", OUT, factorialIterative(IN));
+            }
+        });
+    }
+
+    /**
+     * Computes the factorial of a number with a recursive method.
+     *
+     * @param num The number to compute the factorial of.
+     */
+    private static long factorialRecursive(int num) {
+        if (num <= 0) {
+            return 1;
+        }
+        return num * factorialRecursive(num - 1);
+    }
+
+    /**
+     * Computes the factorial of a number with a iterative method.
+     *
+     * @param num The number to compute the factorial of.
+     */
+    private static long factorialIterative(int num) {
+        long result = 1;
+        for (int i = 2; i <= num; i++) {
+            result *= i;
+        }
+        return result;
+    }
+
+    /**
+     * Runs the workload and records the result to the report log.
+     *
+     * @param workload
+     */
+    private void runTest(MeasureRun workload) throws Exception {
+        // MeasureTime runs the workload N times and records the time taken by each run.
+        double[] result = MeasureTime.measure(REPEAT, workload);
+        // Compute the stats.
+        Stat.StatResult stat = Stat.getStat(result);
+        // Get the report for this test and add the results to record.
+        ReportLog log = getReportLog();
+        log.printArray("Times", result, ResultType.LOWER_BETTER, ResultUnit.MS);
+        log.printValue("Min", stat.mMin, ResultType.LOWER_BETTER, ResultUnit.MS);
+        log.printValue("Max", stat.mMax, ResultType.LOWER_BETTER, ResultUnit.MS);
+        // Every report must have a summary,
+        log.printSummary("Average", stat.mAverage, ResultType.LOWER_BETTER, ResultUnit.MS);
+    }
+}
diff --git a/tests/sample/src/android/sample/cts/SampleDeviceTest.java b/tests/sample/src/android/sample/cts/SampleDeviceTest.java
new file mode 100644
index 0000000..13b7ea6
--- /dev/null
+++ b/tests/sample/src/android/sample/cts/SampleDeviceTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.sample.cts;
+
+import android.sample.SampleDeviceActivity;
+import android.test.ActivityInstrumentationTestCase2;
+
+/**
+ * A simple compatibility test which tests the SharedPreferences API.
+ *
+ * This test uses {@link android.test.ActivityInstrumentationTestCase2} to instrument the
+ * {@link android.sample.SampleDeviceActivity}.
+ */
+public class SampleDeviceTest extends ActivityInstrumentationTestCase2<SampleDeviceActivity> {
+
+    private static final String KEY = "foo";
+
+    private static final String VALUE = "bar";
+
+    /**
+     * A reference to the activity whose shared preferences are being tested.
+     */
+    private SampleDeviceActivity mActivity;
+
+    public SampleDeviceTest() {
+        super(SampleDeviceActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        // Start the activity and get a reference to it.
+        mActivity = getActivity();
+        // Wait for the UI Thread to become idle.
+        getInstrumentation().waitForIdleSync();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        // Scrub the activity so it can be freed. The next time the setUp will create a new activity
+        // rather than reusing the old one.
+        mActivity = null;
+        super.tearDown();
+    }
+
+    /**
+     * Tests the SharedPreferences API.
+     *
+     * This inserts the key value pair and assert they can be retrieved. Then it clears the
+     * preferences and asserts they can no longer be retrieved.
+     *
+     * @throws Exception
+     */
+    public void testSharedPreferences() throws Exception {
+        // Save the key value pair to the preferences and assert they were saved.
+        mActivity.savePreference(KEY, VALUE);
+        assertEquals("Preferences were not saved", VALUE, mActivity.getPreference(KEY));
+
+        // Clear the shared preferences and assert the data was removed.
+        mActivity.clearPreferences();
+        assertNull("Preferences were not cleared", mActivity.getPreference(KEY));
+    }
+}
diff --git a/tests/tests/example/AndroidManifest.xml b/tests/tests/example/AndroidManifest.xml
deleted file mode 100644
index ba41cce..0000000
--- a/tests/tests/example/AndroidManifest.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-
-<!-- Replace all the "example" stuff below with your package name, and
-     remove this comment.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.android.cts.example">
-
-    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
-    <application>
-        <uses-library android:name="android.test.runner" />
-    </application>
-
-    <!-- This is a self-instrumenting test package. -->
-    <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
-                     android:targetPackage="com.android.cts.example"
-                     android:label="CTS tests of example component"/>
-
-</manifest>
-
diff --git a/tests/tests/example/src/android/example/Example.java b/tests/tests/example/src/android/example/Example.java
deleted file mode 100644
index bc22d9a..0000000
--- a/tests/tests/example/src/android/example/Example.java
+++ /dev/null
@@ -1,42 +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 android.example;
-
-/**
- * Example class being tested. In a real test, the classes to test would
- * live somewhere other than in the test package, but for the sake of
- * brevity, we include this one here instead.
- */
-public class Example {
-    /**
-     * Return the standard string indication of a successfuly blorting.
-     *
-     * @returns {@code "blort"}, always
-     */
-    public static String blort() {
-        return "blort";
-    }
-
-    /**
-     * Return the standard string indication of a successfuly zorching.
-     *
-     * @returns {@code "zorch"}, always
-     */
-    public static String zorch() {
-        return "zorch";
-    }
-}
diff --git a/tests/tests/example/src/android/example/cts/ExampleSecondaryTest.java b/tests/tests/example/src/android/example/cts/ExampleSecondaryTest.java
deleted file mode 100644
index d2b78dc..0000000
--- a/tests/tests/example/src/android/example/cts/ExampleSecondaryTest.java
+++ /dev/null
@@ -1,47 +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 android.example.cts;
-
-import android.example.Example;
-
-import junit.framework.TestCase;
-
-/**
- * Example test to demonstrate how tests work as well as to serve as a
- * smoke test for the CTS. This secondary test exists to demonstrate
- * that you may have more than one test class. Typically you will
- * separate your test classes by what class or major piece of
- * functionality is being tested.
- */
-public class ExampleSecondaryTest extends TestCase {
-    /*
-     * You can define standard JUnit setUp() and tearDown() methods here,
-     * if needed.
-     *
-     * @Override protected void setUp() throws Exception { ... }
-     * @Override protected void tearDown() throws Exception { ... }
-     */
-
-    /**
-     * Test {@link Example#zorch}.
-     */
-    public void testZorch() {
-        assertEquals("zorch", Example.zorch());
-    }
-
-    // Add more tests here.
-}
diff --git a/tests/tests/example/src/android/example/cts/ExampleTest.java b/tests/tests/example/src/android/example/cts/ExampleTest.java
deleted file mode 100644
index db907cc..0000000
--- a/tests/tests/example/src/android/example/cts/ExampleTest.java
+++ /dev/null
@@ -1,46 +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 android.example.cts;
-
-import android.example.Example;
-
-import junit.framework.TestCase;
-
-/**
- * Example test to demonstrate how tests work as well as to serve as
- * a smoke test for the CTS. (If the example test is "broken," then it
- * probably means that there's something fundamentally wrong with your
- * setup.)
- */
-public class ExampleTest extends TestCase {
-    /*
-     * You can define standard JUnit setUp() and tearDown() methods here,
-     * if needed.
-     *
-     * @Override protected void setUp() throws Exception { ... }
-     * @Override protected void tearDown() throws Exception { ... }
-     */
-
-    /**
-     * Test {@link Example#blort}.
-     */
-    public void testBlort() {
-        assertEquals("blort", Example.blort());
-    }
-
-    // Add more tests here.
-}