am 71ba6555: am 402ef734: am 81c1ef94: Merge "Add bionic unit tests to CTS."

* commit '71ba65556b1938e059a3e4934742de16f5d603c0':
  Add bionic unit tests to CTS.
diff --git a/suite/pts/PtsBenchmarkingList.mk b/suite/pts/PtsBenchmarkingList.mk
index 4a59c4f..7945f6d 100644
--- a/suite/pts/PtsBenchmarkingList.mk
+++ b/suite/pts/PtsBenchmarkingList.mk
@@ -30,12 +30,13 @@
     PtsDeviceTaskswitchingAppA \
     PtsDeviceTaskswitchingAppB \
     PtsDeviceTaskswitchingControl \
+    PtsDeviceUi \
     PtsDeviceOpenGl
 
 PTS_HOST_CASES := \
     PtsHostBootup \
     PtsHostUi \
-    PtsHostJankOpenGl
+    PtsHostJank
 
 pts_device_lib_tests := \
-    PtsDeviceJankOpenGl
\ No newline at end of file
+    PtsDeviceJank
\ No newline at end of file
diff --git a/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLPrimitiveBenchmark.java b/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLPrimitiveBenchmark.java
index 4477f3b..053e0cf 100644
--- a/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLPrimitiveBenchmark.java
+++ b/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLPrimitiveBenchmark.java
@@ -120,9 +120,8 @@
         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_ITERATIONS, numIterations);
         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, timeout);
 
-        GLPrimitiveActivity activity = null;
         setActivityIntent(intent);
-        activity = getActivity();
+        GLPrimitiveActivity activity = getActivity();
         if (activity != null) {
             activity.waitForCompletion();
             double[] fpsValues = activity.mFpsValues;
diff --git a/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/reference/GLReferenceBenchmark.java b/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/reference/GLReferenceBenchmark.java
index 0f01759..cc98bab 100644
--- a/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/reference/GLReferenceBenchmark.java
+++ b/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/reference/GLReferenceBenchmark.java
@@ -49,9 +49,8 @@
         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, NUM_FRAMES);
         intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, TIMEOUT);
 
-        GLReferenceActivity activity = null;
         setActivityIntent(intent);
-        activity = getActivity();
+        GLReferenceActivity activity = getActivity();
         if (activity != null) {
             activity.waitForCompletion();
             double totalTime = 0;
diff --git a/suite/pts/deviceTests/ui/Android.mk b/suite/pts/deviceTests/ui/Android.mk
index 3790342..d9b17aa 100644
--- a/suite/pts/deviceTests/ui/Android.mk
+++ b/suite/pts/deviceTests/ui/Android.mk
@@ -24,13 +24,7 @@
 
 LOCAL_STATIC_JAVA_LIBRARIES := ptsutil ctsutil ctstestrunner
 
-LOCAL_JNI_SHARED_LIBRARIES := libctsopenglperf_jni
-
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
-# re-use existing openglperf code for CTS. Do not include any test from that dir.
-LOCAL_SRC_FILES += $(filter-out %Test.java,$(call all-java-files-under, ../../../../tests/tests/openglperf/src))
-# do not use its own assets for this package.
-LOCAL_ASSET_DIR := $(LOCAL_PATH)/../../../../tests/tests/openglperf/assets
 
 LOCAL_PACKAGE_NAME := PtsDeviceUi
 
diff --git a/suite/pts/deviceTests/ui/AndroidManifest.xml b/suite/pts/deviceTests/ui/AndroidManifest.xml
index 839e8aa..2a74791 100644
--- a/suite/pts/deviceTests/ui/AndroidManifest.xml
+++ b/suite/pts/deviceTests/ui/AndroidManifest.xml
@@ -26,17 +26,13 @@
 
         <activity
             android:name=".ScrollingActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
-            android:screenOrientation="portrait" >
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-        <activity
-            android:name="android.openglperf.cts.GlPlanetsActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" />
     </application>
 
     <instrumentation
diff --git a/suite/pts/deviceTests/ui/src/com/android/pts/ui/FpsTest.java b/suite/pts/deviceTests/ui/src/com/android/pts/ui/FpsTest.java
deleted file mode 100644
index 08a6ad8..0000000
--- a/suite/pts/deviceTests/ui/src/com/android/pts/ui/FpsTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2012 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.pts.ui;
-
-import android.content.Context;
-import android.content.Intent;
-import android.openglperf.cts.GlPlanetsActivity;
-import android.util.Log;
-import android.view.Display;
-import android.view.WindowManager;
-
-import com.android.pts.util.ResultType;
-import com.android.pts.util.ResultUnit;
-import com.android.pts.util.PtsActivityInstrumentationTestCase2;
-import com.android.pts.util.ReportLog;
-import com.android.pts.util.Stat;
-
-/**
- * measure time taken to render n frames with OpenGL.
- * This will measure the jankiness of the Gl rendering.
- * If some frames are delayed, total time will take longer than n x refresh_rate
- */
-public class FpsTest extends PtsActivityInstrumentationTestCase2<GlPlanetsActivity> {
-    private static final String TAG = "FpsTest";
-    private static final int NUM_FRAMES_TO_RENDER = 60 * 60;
-    private static final long RENDERING_TIMEOUT = NUM_FRAMES_TO_RENDER / 10;
-    private GlPlanetsActivity mActivity;
-
-    public FpsTest() {
-        super(GlPlanetsActivity.class);
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        mActivity = null;
-        super.tearDown();
-    }
-
-    public void testFrameJankiness() throws Exception {
-        Intent intent = new Intent();
-        intent.putExtra(GlPlanetsActivity.INTENT_EXTRA_NUM_FRAMES,
-                NUM_FRAMES_TO_RENDER);
-        intent.putExtra(GlPlanetsActivity.INTENT_EXTRA_NUM_PLANETS, 0);
-        intent.putExtra(GlPlanetsActivity.INTENT_EXTRA_USE_VBO_VERTICES, true);
-        intent.putExtra(GlPlanetsActivity.INTENT_EXTRA_USE_VBO_INDICES, true);
-        intent.putExtra(GlPlanetsActivity.INTENT_EXTRA_NUM_INDEX_BUFFERS, 10);
-
-        setActivityIntent(intent);
-        mActivity = getActivity();
-        boolean waitResult = mActivity.waitForGlPlanetsCompletionWithTimeout(RENDERING_TIMEOUT);
-        assertTrue("timeout while waiting for rendering completion", waitResult);
-
-        int[] frameInterval = mActivity.getFrameInterval();
-        assertTrue(frameInterval.length == NUM_FRAMES_TO_RENDER);
-        double fpsMeasured = mActivity.getAverageFps();
-        WindowManager wm = (WindowManager)mActivity.getSystemService(Context.WINDOW_SERVICE);
-        Display dpy = wm.getDefaultDisplay();
-        double fpsNominal = dpy.getRefreshRate();
-        double frameIntervalNominalInMs = 1000.0 / fpsNominal;
-
-        // first one not valid, and should be thrown away
-        double[] intervals = new double[NUM_FRAMES_TO_RENDER - 1];
-        double[] jankiness = new double[NUM_FRAMES_TO_RENDER - 2];
-        for (int i = 0; i < NUM_FRAMES_TO_RENDER - 1; i++) {
-            intervals[i] = frameInterval[i + 1];
-        }
-        int jankNumber = 0;
-        double totalJanks = 0.0;
-        for (int i = 0; i < NUM_FRAMES_TO_RENDER - 2; i++) {
-            double delta = intervals[i + 1] - intervals[i];
-            double normalizedDelta = delta / frameIntervalNominalInMs;
-            // This makes delay over 1.5 * frameIntervalNomial a jank.
-            // Note that too big delay is not excluded here as there should be no pause.
-            jankiness[i] = (int)Math.round(Math.max(normalizedDelta, 0.0));
-            if (jankiness[i] > 0) {
-                jankNumber++;
-            }
-            totalJanks += jankiness[i];
-        }
-
-        Log.i(TAG, " fps nominal " + fpsNominal + " fps measured " + fpsMeasured);
-        getReportLog().printArray("intervals", intervals, ResultType.NEUTRAL,
-                ResultUnit.MS);
-        getReportLog().printArray("jankiness", jankiness, ResultType.LOWER_BETTER,
-                ResultUnit.COUNT);
-        getReportLog().printValue("number of jank", jankNumber, ResultType.LOWER_BETTER,
-                ResultUnit.COUNT);
-        getReportLog().printSummary("total janks", totalJanks, ResultType.LOWER_BETTER,
-                ResultUnit.COUNT);
-    }
-}
diff --git a/suite/pts/deviceTests/ui/src/com/android/pts/ui/ScrollingActivity.java b/suite/pts/deviceTests/ui/src/com/android/pts/ui/ScrollingActivity.java
index fbec65d..c69b4c5 100644
--- a/suite/pts/deviceTests/ui/src/com/android/pts/ui/ScrollingActivity.java
+++ b/suite/pts/deviceTests/ui/src/com/android/pts/ui/ScrollingActivity.java
@@ -31,16 +31,20 @@
  */
 public class ScrollingActivity extends ListActivity implements OnScrollListener {
     static final String TAG = "ScrollingActivity";
-    private static final int NUMBER_ELEMENTS = 10000;
+    private static final String NUM_ELEMENTS_EXTRA = "num_elements";
+    private static final int NUM_ELEMENTS_DEFAULT = 10000;
     private static final int SCROLL_TIME_IN_MS = 1;
     private static final int WAIT_TIMEOUT_IN_SECS = 5 * 60;
-    private String[] mItems = new String[NUMBER_ELEMENTS];
+    private String[] mItems;
     private CountDownLatch mLatchStop = null;
     private int mTargetLoc;
+    private int mNumElements;
 
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
-        for (int i = 0; i < NUMBER_ELEMENTS; i++) {
+        mNumElements = getIntent().getIntExtra(NUM_ELEMENTS_EXTRA, NUM_ELEMENTS_DEFAULT);
+        mItems = new String[mNumElements];
+        for (int i = 0; i < mNumElements; i++) {
             mItems[i] = Integer.toString(i);
         }
         setListAdapter(new ArrayAdapter<String>(this,
@@ -53,7 +57,7 @@
         return doScroll(0);
     }
     public boolean scrollToBottom() {
-        return doScroll(NUMBER_ELEMENTS - 1);
+        return doScroll(mNumElements - 1);
     }
 
     private boolean doScroll(final int loc) {
diff --git a/suite/pts/hostTests/jank/Android.mk b/suite/pts/hostTests/jank/Android.mk
index 1d5346c..c1fd2d6 100644
--- a/suite/pts/hostTests/jank/Android.mk
+++ b/suite/pts/hostTests/jank/Android.mk
@@ -20,20 +20,20 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_MODULE := PtsHostJankOpenGl
+LOCAL_MODULE := PtsHostJank
 
 LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed-prebuilt ddmlib-prebuilt ptscommonutilhost
 
-LOCAL_CTS_TEST_PACKAGE := com.android.pts.jank.opengl
+LOCAL_CTS_TEST_PACKAGE := com.android.pts.jank
 
-LOCAL_DEVICE_JAR_ := PtsDeviceJankOpenGl
+LOCAL_DEVICE_JAR_ := PtsDeviceJank
 cts_library_jar_ := $(CTS_TESTCASES_OUT)/$(LOCAL_DEVICE_JAR_).jar
 
 $(cts_library_jar_): $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_DEVICE_JAR_))/javalib.jar | $(ACP)
 	$(hide) mkdir -p $(CTS_TESTCASES_OUT)
 	$(hide) $(ACP) -fp $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_DEVICE_JAR_))/javalib.jar $@
 
-$(CTS_TESTCASES_OUT)/PtsHostJankOpenGl.xml: $(cts_library_jar_)
+$(CTS_TESTCASES_OUT)/PtsHostJank.xml: $(cts_library_jar_)
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/suite/pts/hostTests/jank/app/Android.mk b/suite/pts/hostTests/jank/app/Android.mk
index 81f5f73..62b950d 100644
--- a/suite/pts/hostTests/jank/app/Android.mk
+++ b/suite/pts/hostTests/jank/app/Android.mk
@@ -18,7 +18,7 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE := PtsDeviceJankOpenGl
+LOCAL_MODULE := PtsDeviceJank
 LOCAL_DEX_PREOPT := false
 
 LOCAL_JAVA_LIBRARIES := uiautomator.core
diff --git a/suite/pts/hostTests/jank/app/src/com/android/pts/jank/PtsJankTestBase.java b/suite/pts/hostTests/jank/app/src/com/android/pts/jank/PtsJankTestBase.java
new file mode 100644
index 0000000..cbb6969
--- /dev/null
+++ b/suite/pts/hostTests/jank/app/src/com/android/pts/jank/PtsJankTestBase.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2013 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.pts.jank;
+
+import android.os.Bundle;
+import android.util.Log;
+
+import com.android.uiautomator.platform.JankTestBase;
+import com.android.uiautomator.platform.SurfaceFlingerHelper;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Scanner;
+
+public class PtsJankTestBase extends JankTestBase {
+    private final static String TAG = PtsJankTestBase.class.getName();
+    protected final static String START_CMD = "am start -W -a android.intent.action.MAIN -n %s";
+    protected final static String STOP_CMD = "am force-stop %s";
+    protected final static String INTENT_STRING_EXTRA = " --es %s %s";
+    protected final static String INTENT_BOOLEAN_EXTRA = " --ez %s %b";
+    protected final static String INTENT_INTEGER_EXTRA = " --ei %s %d";
+    protected static long SLEEP_TIME = 2000; // 2 seconds
+    protected static int NUM_ITERATIONS = 5;
+    protected static int TRACE_TIME = 5;
+
+    @Override
+    protected String getPropertyString(Bundle params, String key)
+            throws FileNotFoundException, IOException {
+        if (key.equals("iteration")) {
+            return NUM_ITERATIONS + "";
+        }
+        if (key.equals("tracetime")) {
+            return TRACE_TIME + "";
+        }
+        return super.getPropertyString(params, key);
+    }
+
+    protected void runShellCommand(String command) throws Exception {
+        Process p = null;
+        Scanner out = null;
+        Scanner err = null;
+        try {
+            p = Runtime.getRuntime().exec(command);
+
+            StringBuilder outStr = new StringBuilder();
+            StringBuilder errStr = new StringBuilder();
+            out = new Scanner(p.getInputStream());
+            err = new Scanner(p.getErrorStream());
+            boolean read = true;
+            while (read) {
+                if (out.hasNextLine()) {
+                    outStr.append(out.nextLine());
+                    outStr.append("\n");
+                } else if (err.hasNextLine()) {
+                    errStr.append(err.nextLine());
+                    errStr.append("\n");
+                } else {
+                    read = false;
+                }
+            }
+            Log.i(TAG, command);
+            if (outStr.length() > 0) {
+                Log.i(TAG, outStr.toString());
+            }
+            if (errStr.length() > 0) {
+                Log.e(TAG, errStr.toString());
+            }
+        } finally {
+            if (p != null) {
+                int status = p.waitFor();
+                if (status != 0) {
+                    throw new RuntimeException(
+                            String.format("Run shell command: %s, status: %s", command, status));
+                }
+                p.destroy();
+                p = null;
+            }
+            if (out != null) {
+                out.close();
+            }
+            if (err != null) {
+                err.close();
+            }
+        }
+    }
+}
diff --git a/suite/pts/hostTests/jank/app/src/com/android/pts/jank/opengl/PtsDeviceJankOpenGl.java b/suite/pts/hostTests/jank/app/src/com/android/pts/jank/opengl/PtsDeviceJankOpenGl.java
index 259649c..715de4b 100644
--- a/suite/pts/hostTests/jank/app/src/com/android/pts/jank/opengl/PtsDeviceJankOpenGl.java
+++ b/suite/pts/hostTests/jank/app/src/com/android/pts/jank/opengl/PtsDeviceJankOpenGl.java
@@ -14,43 +14,17 @@
 
 package com.android.pts.jank.opengl;
 
-import android.os.Bundle;
 import android.util.Log;
 
-import com.android.uiautomator.platform.JankTestBase;
+import com.android.pts.jank.PtsJankTestBase;
 import com.android.uiautomator.platform.SurfaceFlingerHelper;
 
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Scanner;
-import java.util.concurrent.Semaphore;
-
-public class PtsDeviceJankOpenGl extends JankTestBase {
-    private final static String TAG = "JankTest";
+public class PtsDeviceJankOpenGl extends PtsJankTestBase {
+    private final static String TAG = PtsDeviceJankOpenGl.class.getName();
     private final static String PACKAGE = "com.android.pts.opengl";
     private final static String COMPONENT =
             PACKAGE + "/" + PACKAGE + ".primitive.GLPrimitiveActivity";
-    private final static String START_CMD = "am start -W -a android.intent.action.MAIN -n %s";
-    private final static String STOP_CMD = "am force-stop %s";
-    private final static String INTENT_STRING_EXTRA = " --es %s %s";
-    private final static String INTENT_BOOLEAN_EXTRA = " --ez %s %b";
-    private final static String INTENT_INTEGER_EXTRA = " --ei %s %d";
     private static String APP_WINDOW_NAME = "SurfaceView";
-    private static long SLEEP_TIME = 2000; // 2 seconds
-    private static int NUM_ITERATIONS = 5;
-    private static int TRACE_TIME = 5;
-
-    @Override
-    protected String getPropertyString(Bundle params, String key)
-            throws FileNotFoundException, IOException {
-        if (key.equals("iteration")) {
-            return NUM_ITERATIONS + "";
-        }
-        if (key.equals("tracetime")) {
-            return TRACE_TIME + "";
-        }
-        return super.getPropertyString(params, key);
-    }
 
     /**
      * Runs the full OpenGL ES 2.0 pipeline test.
@@ -105,9 +79,11 @@
             // Start activity
             runShellCommand(startCommand);
 
+            // Wait for the activity to start
+            sleep(SLEEP_TIME / 2);
+
             // Start systrace
-            // TODO(jgennis): Systrace has been commented out because of read-tgid permission error
-            // startTrace(mTestCaseName, i);
+            startTrace(mTestCaseName, i);
 
             // Clear SurfaceFlinger buffer
             Log.i(TAG, "Clearing SurfaceFlinger buffer");
@@ -122,7 +98,7 @@
             assertTrue("SurfaceFlingerHelper could not get timestamps", result);
 
             // Stop systrace
-            // endTrace();
+            endTrace();
 
             // Record results
             recordResults(mTestCaseName, i);
@@ -132,54 +108,4 @@
         // Stop any remaining instances
         runShellCommand(stopCommand);
     }
-
-    private void runShellCommand(String command) throws Exception {
-        Process p = null;
-        Scanner out = null;
-        Scanner err = null;
-        try {
-            p = Runtime.getRuntime().exec(command);
-
-            StringBuilder outStr = new StringBuilder();
-            StringBuilder errStr = new StringBuilder();
-            out = new Scanner(p.getInputStream());
-            err = new Scanner(p.getErrorStream());
-            boolean read = true;
-            while (read) {
-                if (out.hasNextLine()) {
-                    outStr.append(out.nextLine());
-                    outStr.append("\n");
-                } else if (err.hasNextLine()) {
-                    errStr.append(err.nextLine());
-                    errStr.append("\n");
-                } else {
-                    read = false;
-                }
-            }
-            Log.i(TAG, command);
-            if (outStr.length() > 0) {
-                Log.i(TAG, outStr.toString());
-            }
-            if (errStr.length() > 0) {
-                Log.e(TAG, errStr.toString());
-            }
-        } finally {
-            if (p != null) {
-                int status = p.waitFor();
-                if (status != 0) {
-                    throw new RuntimeException(
-                            String.format("Run shell command: %s, status: %s", command, status));
-                }
-                p.destroy();
-                p = null;
-            }
-            if (out != null) {
-                out.close();
-            }
-            if (err != null) {
-                err.close();
-            }
-        }
-    }
-
 }
diff --git a/suite/pts/hostTests/jank/app/src/com/android/pts/jank/ui/PtsDeviceJankUi.java b/suite/pts/hostTests/jank/app/src/com/android/pts/jank/ui/PtsDeviceJankUi.java
new file mode 100644
index 0000000..02d466e
--- /dev/null
+++ b/suite/pts/hostTests/jank/app/src/com/android/pts/jank/ui/PtsDeviceJankUi.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2013 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.pts.jank.ui;
+
+import android.util.Log;
+import android.widget.ListView;
+
+import com.android.pts.jank.PtsJankTestBase;
+import com.android.uiautomator.core.UiScrollable;
+import com.android.uiautomator.core.UiSelector;
+import com.android.uiautomator.platform.SurfaceFlingerHelper;
+
+public class PtsDeviceJankUi extends PtsJankTestBase {
+    private final static String TAG = PtsDeviceJankUi.class.getName();
+    private final static String PACKAGE = "com.android.pts.ui";
+    private final static String COMPONENT =
+            PACKAGE + "/" + PACKAGE + ".ScrollingActivity";
+    private final static int NUM_ELEMENTS = 1000;
+    private static String APP_WINDOW_NAME = COMPONENT;
+
+    // TODO(stuartscott): expand deviceTests/ui app to have a more complex UI
+    /**
+     * Runs the ScrollingActivity and measures jank during a scroll.
+     */
+    public void testScrolling() throws Exception {
+        // Start activity command
+        final StringBuilder sb = new StringBuilder();
+        sb.append(String.format(START_CMD, COMPONENT));
+        sb.append(String.format(INTENT_INTEGER_EXTRA, "num_elements", NUM_ELEMENTS));
+        final String startCommand = sb.toString();
+        final String stopCommand = String.format(STOP_CMD, PACKAGE);
+
+        Log.i(TAG, "Start command: " + startCommand);
+        Log.i(TAG, "Stop command: " + stopCommand);
+
+        setIteration(NUM_ITERATIONS);
+        for (int i = 0; i < NUM_ITERATIONS; i++) {
+            // Stop any existing instances
+            runShellCommand(stopCommand);
+            // Start activity
+            runShellCommand(startCommand);
+
+            // Wait for the activity to start
+            sleep(SLEEP_TIME / 2);
+
+            UiScrollable list = new UiScrollable(
+                    new UiSelector().className(ListView.class.getName()));
+
+            // Start systrace
+            startTrace(mTestCaseName, i);
+
+            // Clear SurfaceFlinger buffer
+            Log.i(TAG, "Clearing SurfaceFlinger buffer");
+            SurfaceFlingerHelper.clearBuffer(APP_WINDOW_NAME);
+
+            list.flingToEnd(2);
+
+            // Dump SurfaceFlinger buffer
+            Log.i(TAG, "Dumping SurfaceFlinger buffer");
+            boolean result = SurfaceFlingerHelper.dumpFrameLatency(APP_WINDOW_NAME, true);
+            assertTrue("SurfaceFlingerHelper could not get timestamps", result);
+
+            // Stop systrace
+            endTrace();
+
+            // Record results
+            recordResults(mTestCaseName, i);
+        }
+        // Save aggregated results
+        saveResults(mTestCaseName);
+        // Stop any remaining instances
+        runShellCommand(stopCommand);
+    }
+}
diff --git a/suite/pts/hostTests/jank/src/com/android/pts/jank/PtsHostJankTest.java b/suite/pts/hostTests/jank/src/com/android/pts/jank/PtsHostJankTest.java
index 1264786..9c2b481 100644
--- a/suite/pts/hostTests/jank/src/com/android/pts/jank/PtsHostJankTest.java
+++ b/suite/pts/hostTests/jank/src/com/android/pts/jank/PtsHostJankTest.java
@@ -14,7 +14,6 @@
 package com.android.pts.jank;
 
 import com.android.cts.tradefed.build.CtsBuildHelper;
-import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
 import com.android.ddmlib.IShellOutputReceiver;
 import com.android.ddmlib.Log;
 import com.android.ddmlib.Log.LogLevel;
@@ -24,17 +23,10 @@
 import com.android.pts.util.ResultUnit;
 import com.android.tradefed.build.IBuildInfo;
 import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.result.CollectingTestListener;
-import com.android.tradefed.result.TestRunResult;
 import com.android.tradefed.testtype.DeviceTestCase;
 import com.android.tradefed.testtype.IBuildReceiver;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Scanner;
 
diff --git a/suite/pts/hostTests/jank/src/com/android/pts/jank/opengl/PtsHostJankOpenGl.java b/suite/pts/hostTests/jank/src/com/android/pts/jank/opengl/PtsHostJankOpenGl.java
index aea0b11..8d9c3e7 100644
--- a/suite/pts/hostTests/jank/src/com/android/pts/jank/opengl/PtsHostJankOpenGl.java
+++ b/suite/pts/hostTests/jank/src/com/android/pts/jank/opengl/PtsHostJankOpenGl.java
@@ -13,20 +13,18 @@
  */
 package com.android.pts.jank.opengl;
 
-import com.android.ddmlib.Log;
-import com.android.ddmlib.Log.LogLevel;
 import com.android.pts.jank.PtsHostJankTest;
 
 import java.io.File;
 
 public class PtsHostJankOpenGl extends PtsHostJankTest {
 
-    private static final String APK_PACKAGE = "com.android.pts.opengl";
+    private static final String APK_PACKAGE = "com.android.pts";
     private static final String APK = "PtsDeviceOpenGl.apk";
     private static final String PACKAGE = "com.android.pts.jank.opengl";
     private static final String HOST_CLASS = PtsHostJankOpenGl.class.getName();
     private static final String DEVICE_CLASS = PACKAGE + ".PtsDeviceJankOpenGl";
-    private static final String JAR_NAME = "PtsDeviceJankOpenGl.jar";
+    private static final String JAR_NAME = "PtsDeviceJank.jar";
 
     public PtsHostJankOpenGl() {
         super(JAR_NAME, DEVICE_CLASS, HOST_CLASS);
diff --git a/suite/pts/hostTests/jank/src/com/android/pts/jank/ui/PtsHostJankUi.java b/suite/pts/hostTests/jank/src/com/android/pts/jank/ui/PtsHostJankUi.java
new file mode 100644
index 0000000..245a892
--- /dev/null
+++ b/suite/pts/hostTests/jank/src/com/android/pts/jank/ui/PtsHostJankUi.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 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.pts.jank.ui;
+
+import com.android.pts.jank.PtsHostJankTest;
+
+import java.io.File;
+
+public class PtsHostJankUi extends PtsHostJankTest {
+
+    private static final String APK_PACKAGE = "com.android.pts";
+    private static final String APK = "PtsDeviceUi.apk";
+    private static final String PACKAGE = "com.android.pts.jank.ui";
+    private static final String HOST_CLASS = PtsHostJankUi.class.getName();
+    private static final String DEVICE_CLASS = PACKAGE + ".PtsDeviceJankUi";
+    private static final String JAR_NAME = "PtsDeviceJank.jar";
+
+    public PtsHostJankUi() {
+        super(JAR_NAME, DEVICE_CLASS, HOST_CLASS);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        // Install the app.
+        mDevice.uninstallPackage(APK_PACKAGE);
+        File app = mBuild.getTestApp(APK);
+        mDevice.installPackage(app, false);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        // Uninstall the app.
+        mDevice.uninstallPackage(APK_PACKAGE);
+        super.tearDown();
+    }
+
+    public void testScrolling() throws Exception {
+        runUiAutomatorTest("testScrolling");
+    }
+}
diff --git a/tests/core/libcore/com/Android.mk b/tests/core/libcore/com/Android.mk
index 02dc3de..db08dbd 100644
--- a/tests/core/libcore/com/Android.mk
+++ b/tests/core/libcore/com/Android.mk
@@ -14,10 +14,6 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-ifeq ($(BUILD_CTSCORE_PACKAGE),)
-    $(error BUILD_CTSCORE_PACKAGE must be defined)
-endif
-
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.com
 LOCAL_STATIC_JAVA_LIBRARIES := core-tests
diff --git a/tests/core/libcore/dalvik/Android.mk b/tests/core/libcore/dalvik/Android.mk
index 7b77a75..42d14f3 100644
--- a/tests/core/libcore/dalvik/Android.mk
+++ b/tests/core/libcore/dalvik/Android.mk
@@ -14,10 +14,6 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-ifeq ($(BUILD_CTSCORE_PACKAGE),)
-    $(error BUILD_CTSCORE_PACKAGE must be defined)
-endif
-
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.dalvik
 LOCAL_STATIC_JAVA_LIBRARIES := core-tests
diff --git a/tests/core/libcore/jsr166/Android.mk b/tests/core/libcore/jsr166/Android.mk
new file mode 100644
index 0000000..3f9871e
--- /dev/null
+++ b/tests/core/libcore/jsr166/Android.mk
@@ -0,0 +1,20 @@
+# Copyright (C) 2013 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_PACKAGE_NAME := android.core.tests.libcore.package.jsr166
+LOCAL_STATIC_JAVA_LIBRARIES := jsr166-tests
+include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/core/libcore/jsr166/AndroidManifest.xml b/tests/core/libcore/jsr166/AndroidManifest.xml
new file mode 100644
index 0000000..3a0150e
--- /dev/null
+++ b/tests/core/libcore/jsr166/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2013 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.core.tests.libcore.package.jsr166">
+    <uses-permission android:name="android.permission.INTERNET" />
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
+                     android:targetPackage="android.core.tests.runner"
+                     android:label="cts framework tests"/>
+
+</manifest>
diff --git a/tests/core/libcore/libcore/Android.mk b/tests/core/libcore/libcore/Android.mk
index 382b386..a86d2c0 100644
--- a/tests/core/libcore/libcore/Android.mk
+++ b/tests/core/libcore/libcore/Android.mk
@@ -14,10 +14,6 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-ifeq ($(BUILD_CTSCORE_PACKAGE),)
-    $(error BUILD_CTSCORE_PACKAGE must be defined)
-endif
-
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.libcore
 LOCAL_STATIC_JAVA_LIBRARIES := core-tests
diff --git a/tests/core/libcore/org/Android.mk b/tests/core/libcore/org/Android.mk
index d7a96b3..0f3f0ca 100644
--- a/tests/core/libcore/org/Android.mk
+++ b/tests/core/libcore/org/Android.mk
@@ -14,10 +14,6 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-ifeq ($(BUILD_CTSCORE_PACKAGE),)
-    $(error BUILD_CTSCORE_PACKAGE must be defined)
-endif
-
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.org
 LOCAL_STATIC_JAVA_LIBRARIES := core-tests
diff --git a/tests/core/libcore/sun/Android.mk b/tests/core/libcore/sun/Android.mk
index 44d3d70..ed6d2c7 100644
--- a/tests/core/libcore/sun/Android.mk
+++ b/tests/core/libcore/sun/Android.mk
@@ -14,10 +14,6 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-ifeq ($(BUILD_CTSCORE_PACKAGE),)
-    $(error BUILD_CTSCORE_PACKAGE must be defined)
-endif
-
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.sun
 LOCAL_STATIC_JAVA_LIBRARIES := core-tests
diff --git a/tests/core/libcore/tests/Android.mk b/tests/core/libcore/tests/Android.mk
index bfd235f..54ffd31 100644
--- a/tests/core/libcore/tests/Android.mk
+++ b/tests/core/libcore/tests/Android.mk
@@ -14,10 +14,6 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-ifeq ($(BUILD_CTSCORE_PACKAGE),)
-    $(error BUILD_CTSCORE_PACKAGE must be defined)
-endif
-
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.tests
 LOCAL_STATIC_JAVA_LIBRARIES := core-tests
diff --git a/tests/tests/security/jni/Android.mk b/tests/tests/security/jni/Android.mk
index 8ca3279..58bab14 100644
--- a/tests/tests/security/jni/Android.mk
+++ b/tests/tests/security/jni/Android.mk
@@ -24,8 +24,9 @@
 LOCAL_SRC_FILES := \
 		CtsSecurityJniOnLoad.cpp \
 		android_security_cts_CharDeviceTest.cpp \
+		android_security_cts_LinuxRngTest.cpp \
+		android_security_cts_LoadEffectLibraryTest.cpp \
 		android_security_cts_NativeCodeTest.cpp \
-		android_security_cts_LoadEffectLibraryTest.cpp
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
diff --git a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
index 87445c7..b9aeaf5 100644
--- a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
+++ b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
@@ -18,6 +18,7 @@
 #include <stdio.h>
 
 extern int register_android_security_cts_CharDeviceTest(JNIEnv*);
+extern int register_android_security_cts_LinuxRngTest(JNIEnv*);
 extern int register_android_security_cts_NativeCodeTest(JNIEnv*);
 extern int register_android_security_cts_LoadEffectLibraryTest(JNIEnv*);
 
@@ -32,6 +33,10 @@
         return JNI_ERR;
     }
 
+    if (register_android_security_cts_LinuxRngTest(env)) {
+        return JNI_ERR;
+    }
+
     if (register_android_security_cts_NativeCodeTest(env)) {
         return JNI_ERR;
     }
diff --git a/tests/tests/security/jni/android_security_cts_LinuxRngTest.cpp b/tests/tests/security/jni/android_security_cts_LinuxRngTest.cpp
new file mode 100644
index 0000000..671226b
--- /dev/null
+++ b/tests/tests/security/jni/android_security_cts_LinuxRngTest.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <errno.h>
+#include <jni.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+/*
+ * Native methods used by
+ * cts/tests/tests/permission/src/android/security/cts/LinuxRngTest.java
+ */
+
+static void throwIOException(JNIEnv* env, const char *format, ...) {
+    va_list ap;
+    va_start(ap, format);
+
+    char *message;
+    vasprintf(&message, format, ap);
+
+    va_end(ap);
+
+    jclass cls = env->FindClass("java/io/IOException");
+    env->ThrowNew(cls, message);
+
+    free(message);
+}
+
+jint android_security_cts_LinuxRngTest_getCharDeviceMajor(JNIEnv* env,
+        jobject thiz, jstring name)
+{
+    const char* nameStr = env->GetStringUTFChars(name, NULL);
+
+    jint result = -1;
+    struct stat st;
+    if (stat(nameStr, &st) == -1) {
+        throwIOException(env, "Failed to stat %s: %s", nameStr, strerror(errno));
+        goto ret;
+    }
+
+    if (!S_ISCHR(st.st_mode)) {
+        throwIOException(env, "%s is not a character device: mode is 0%o", nameStr, st.st_mode);
+        goto ret;
+    }
+
+    result = major(st.st_rdev);
+
+ret:
+    if (nameStr != NULL) {
+        env->ReleaseStringUTFChars(name, nameStr);
+    }
+    return result;
+}
+
+jint android_security_cts_LinuxRngTest_getCharDeviceMinor(JNIEnv* env,
+        jobject thiz, jstring name)
+{
+    const char* nameStr = env->GetStringUTFChars(name, NULL);
+
+    jint result = -1;
+    struct stat st;
+    if (stat(nameStr, &st) == -1) {
+        throwIOException(env, "Failed to stat %s: %s", nameStr, strerror(errno));
+        goto ret;
+    }
+
+    if (!S_ISCHR(st.st_mode)) {
+        throwIOException(env, "%s is not a character device: mode is 0%o", nameStr, st.st_mode);
+        goto ret;
+    }
+
+    result = minor(st.st_rdev);
+
+ret:
+    if (nameStr != NULL) {
+        env->ReleaseStringUTFChars(name, nameStr);
+    }
+    return result;
+}
+
+static JNINativeMethod gMethods[] = {
+    {  "getCharDeviceMajor", "(Ljava/lang/String;)I",
+            (void *) android_security_cts_LinuxRngTest_getCharDeviceMajor },
+    {  "getCharDeviceMinor", "(Ljava/lang/String;)I",
+            (void *) android_security_cts_LinuxRngTest_getCharDeviceMinor },
+};
+
+int register_android_security_cts_LinuxRngTest(JNIEnv* env)
+{
+    jclass clazz = env->FindClass("android/security/cts/LinuxRngTest");
+    return env->RegisterNatives(clazz, gMethods,
+            sizeof(gMethods) / sizeof(JNINativeMethod));
+}
diff --git a/tests/tests/security/src/android/security/cts/LinuxRngTest.java b/tests/tests/security/src/android/security/cts/LinuxRngTest.java
new file mode 100644
index 0000000..6bc5fd3
--- /dev/null
+++ b/tests/tests/security/src/android/security/cts/LinuxRngTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2013 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.security.cts;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+
+public class LinuxRngTest extends TestCase {
+    static {
+        System.loadLibrary("ctssecurity_jni");
+    }
+
+    public void testDevRandomMajorMinor() throws Exception {
+        // Based on Linux kernel's drivers/char/random.c
+        assertEquals("/dev/random major", 1, getCharDeviceMajor("/dev/random"));
+        assertEquals("/dev/random minor", 8, getCharDeviceMinor("/dev/random"));
+    }
+
+    public void testDevUrandomMajorMinor() throws Exception {
+        // Based on Linux kernel's drivers/char/random.c
+        assertEquals("/dev/urandom major", 1, getCharDeviceMajor("/dev/urandom"));
+        assertEquals("/dev/urandom minor", 9, getCharDeviceMinor("/dev/urandom"));
+    }
+
+    public static native int getCharDeviceMajor(String file) throws IOException;
+    public static native int getCharDeviceMinor(String file) throws IOException;
+}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
index 71c093b..426eb9e 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
@@ -26,7 +26,6 @@
 import com.android.tradefed.build.IFolderBuildInfo;
 import com.android.tradefed.config.Option;
 import com.android.tradefed.log.LogUtil.CLog;
-import com.android.tradefed.result.ILogFileSaver;
 import com.android.tradefed.result.ITestInvocationListener;
 import com.android.tradefed.result.InputStreamSource;
 import com.android.tradefed.result.LogDataType;
@@ -212,11 +211,11 @@
     }
 
     /**
-     * Return the {@link ILogFileSaver} to use.
+     * Return the {@link LogFileSaver} to use.
      * <p/>
      * Exposed for unit testing.
      */
-    ILogFileSaver getLogFileSaver() {
+    LogFileSaver getLogFileSaver() {
         return new LogFileSaver(mLogDir);
     }