am d5a56e13: am eb90db91: Merge "Add libcore.conscrypt tests back to CTS" into klp-dev

* commit 'd5a56e13eef9b80de2054061469ca3ff66ba16a4':
  Add libcore.conscrypt tests back 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/media/src/android/media/cts/DecoderTest.java b/tests/tests/media/src/android/media/cts/DecoderTest.java
index ca5f31c..4a4947c 100644
--- a/tests/tests/media/src/android/media/cts/DecoderTest.java
+++ b/tests/tests/media/src/android/media/cts/DecoderTest.java
@@ -32,6 +32,7 @@
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.zip.CRC32;
 
 public class DecoderTest extends MediaPlayerTestBase {
@@ -100,7 +101,7 @@
     }
 
     private void monoTest(int res) throws Exception {
-        short [] mono = decodeToMemory(res, false);
+        short [] mono = decodeToMemory(res, false, -1, null);
         if (mono.length == 44100) {
             // expected
             return;
@@ -115,7 +116,7 @@
         }
 
         // we should get the same data when reconfiguring the codec
-        short [] mono2 = decodeToMemory(res, true);
+        short [] mono2 = decodeToMemory(res, true, -1, null);
         Arrays.equals(mono, mono2);
     }
 
@@ -126,7 +127,7 @@
      */
     private void decode(int testinput, float maxerror) throws IOException {
 
-        short [] decoded = decodeToMemory(testinput, false);
+        short [] decoded = decodeToMemory(testinput, false, -1, null);
 
         assertEquals("wrong data size", mMasterBuffer.length, decoded.length);
 
@@ -143,14 +144,15 @@
         double rmse = Math.sqrt(avgErrorSquared);
         assertTrue("decoding error too big: " + rmse, rmse <= maxerror);
 
-        short [] decoded2 = decodeToMemory(testinput, true);
+        short [] decoded2 = decodeToMemory(testinput, true, -1, null);
         assertEquals("count different with reconfigure", decoded.length, decoded2.length);
         for (int i = 0; i < decoded.length; i++) {
             assertEquals("samples don't match", decoded[i], decoded2[i]);
         }
     }
 
-    private short[] decodeToMemory(int testinput, boolean reconfigure) throws IOException {
+    private short[] decodeToMemory(int testinput, boolean reconfigure,
+            int eossample, List<Long> timestamps) throws IOException {
 
         short [] decoded = new short[0];
         int decodedIdx = 0;
@@ -194,6 +196,7 @@
         boolean sawInputEOS = false;
         boolean sawOutputEOS = false;
         int noOutputCounter = 0;
+        int samplecounter = 0;
         while (!sawOutputEOS && noOutputCounter < 50) {
             noOutputCounter++;
             if (!sawInputEOS) {
@@ -207,14 +210,20 @@
 
                     long presentationTimeUs = 0;
 
+                    if (sampleSize < 0 && eossample > 0) {
+                        fail("test is broken: never reached eos sample");
+                    }
                     if (sampleSize < 0) {
                         Log.d(TAG, "saw input EOS.");
                         sawInputEOS = true;
                         sampleSize = 0;
                     } else {
+                        if (samplecounter == eossample) {
+                            sawInputEOS = true;
+                        }
+                        samplecounter++;
                         presentationTimeUs = extractor.getSampleTime();
                     }
-
                     codec.queueInputBuffer(
                             inputBufIndex,
                             0 /* offset */,
@@ -235,6 +244,9 @@
 
                 if (info.size > 0) {
                     noOutputCounter = 0;
+                    if (timestamps != null) {
+                        timestamps.add(info.presentationTimeUs);
+                    }
                 }
                 if (info.size > 0 && reconfigure) {
                     // once we've gotten some data out of the decoder, reconfigure it again
@@ -246,6 +258,10 @@
                     codec.start();
                     codecInputBuffers = codec.getInputBuffers();
                     codecOutputBuffers = codec.getOutputBuffers();
+                    if (timestamps != null) {
+                        timestamps.clear();
+                    }
+                    samplecounter = 0;
                     continue;
                 }
 
@@ -278,12 +294,69 @@
                 Log.d(TAG, "dequeueOutputBuffer returned " + res);
             }
         }
+        if (noOutputCounter >= 50) {
+            fail("decoder stopped outputing data");
+        }
 
         codec.stop();
         codec.release();
         return decoded;
     }
 
+    public void testDecodeWithEOSOnLastBuffer() throws Exception {
+        testDecodeWithEOSOnLastBuffer(R.raw.sinesweepm4a);
+        testDecodeWithEOSOnLastBuffer(R.raw.sinesweepmp3lame);
+        testDecodeWithEOSOnLastBuffer(R.raw.sinesweepmp3smpb);
+        testDecodeWithEOSOnLastBuffer(R.raw.sinesweepwav);
+        testDecodeWithEOSOnLastBuffer(R.raw.sinesweepflac);
+        testDecodeWithEOSOnLastBuffer(R.raw.sinesweepogg);
+    }
+
+    /* setting EOS on the last full input buffer should be equivalent to setting EOS on an empty
+     * input buffer after all the full ones. */
+    private void testDecodeWithEOSOnLastBuffer(int res) throws Exception {
+        int numsamples = countSamples(res);
+        assertTrue(numsamples != 0);
+
+        List<Long> timestamps1 = new ArrayList<Long>();
+        short[] decode1 = decodeToMemory(res, false, -1, timestamps1);
+
+        List<Long> timestamps2 = new ArrayList<Long>();
+        short[] decode2 = decodeToMemory(res, false, numsamples - 1, timestamps2);
+
+        // check that the data and the timestamps are the same for EOS-on-last and EOS-after-last
+        assertEquals(decode1.length, decode2.length);
+        assertTrue(Arrays.equals(decode1, decode2));
+        assertEquals(timestamps1.size(), timestamps2.size());
+        assertTrue(timestamps1.equals(timestamps2));
+
+        // ... and that this is also true when reconfiguring the codec
+        timestamps2.clear();
+        decode2 = decodeToMemory(res, true, -1, timestamps2);
+        assertTrue(Arrays.equals(decode1, decode2));
+        assertTrue(timestamps1.equals(timestamps2));
+        timestamps2.clear();
+        decode2 = decodeToMemory(res, true, numsamples - 1, timestamps2);
+        assertEquals(decode1.length, decode2.length);
+        assertTrue(Arrays.equals(decode1, decode2));
+        assertTrue(timestamps1.equals(timestamps2));
+    }
+
+    private int countSamples(int res) throws IOException {
+        AssetFileDescriptor testFd = mResources.openRawResourceFd(res);
+
+        MediaExtractor extractor = new MediaExtractor();
+        extractor.setDataSource(testFd.getFileDescriptor(), testFd.getStartOffset(),
+                testFd.getLength());
+        testFd.close();
+        extractor.selectTrack(0);
+        int numsamples = 0;
+        while (extractor.advance()) {
+            numsamples++;
+        }
+        return numsamples;
+    }
+
     public void testCodecBasicH264() throws Exception {
         Surface s = getActivity().getSurfaceHolder().getSurface();
         int frames1 = countFrames(
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);
     }