From 57420bf883ce8c11ae7a1e3acd8f1eebe71edd56 Mon Sep 17 00:00:00 2001 From: Guang Zhu Date: Thu, 5 Jan 2012 15:07:16 -0800 Subject: Small tweaks to Tile Benchmark test * tag the module as 'tests' so the apk gets includes in test build * merge the instrumentation into TileBenchmark app and eliminate the test apk entirely * changed the default test suite to 'alexa25_2011' which is a suite of pages based on top 25 news sites from alexa, includes primarily english sites, and 3 CJK sites Change-Id: Icd40a70b560bfd7c521adf8ad4b1068483698103 --- tests/TileBenchmark/Android.mk | 10 +- tests/TileBenchmark/AndroidManifest.xml | 4 + .../com/test/tilebenchmark/PerformanceTest.java | 167 +++++++++++++++++++++ tests/TileBenchmark/tests/Android.mk | 16 -- tests/TileBenchmark/tests/AndroidManifest.xml | 27 ---- .../com/test/tilebenchmark/PerformanceTest.java | 167 --------------------- 6 files changed, 174 insertions(+), 217 deletions(-) create mode 100644 tests/TileBenchmark/src/com/test/tilebenchmark/PerformanceTest.java delete mode 100644 tests/TileBenchmark/tests/Android.mk delete mode 100644 tests/TileBenchmark/tests/AndroidManifest.xml delete mode 100644 tests/TileBenchmark/tests/src/com/test/tilebenchmark/PerformanceTest.java (limited to 'tests/TileBenchmark') diff --git a/tests/TileBenchmark/Android.mk b/tests/TileBenchmark/Android.mk index 430f0f1..5851113 100644 --- a/tests/TileBenchmark/Android.mk +++ b/tests/TileBenchmark/Android.mk @@ -21,12 +21,8 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := TileBenchmark -include $(BUILD_PACKAGE) +LOCAL_MODULE_TAGS := tests -################################################## -include $(CLEAR_VARS) - -include $(BUILD_MULTI_PREBUILT) +LOCAL_JAVA_LIBRARIES := android.test.runner -# Use the folloing include to make our test apk. -include $(call all-makefiles-under,$(LOCAL_PATH)) +include $(BUILD_PACKAGE) \ No newline at end of file diff --git a/tests/TileBenchmark/AndroidManifest.xml b/tests/TileBenchmark/AndroidManifest.xml index ab61a9e..f125c70 100644 --- a/tests/TileBenchmark/AndroidManifest.xml +++ b/tests/TileBenchmark/AndroidManifest.xml @@ -18,5 +18,9 @@ android:label="@string/playback_activity" android:theme="@android:style/Theme.Holo.NoActionBar"> + + diff --git a/tests/TileBenchmark/src/com/test/tilebenchmark/PerformanceTest.java b/tests/TileBenchmark/src/com/test/tilebenchmark/PerformanceTest.java new file mode 100644 index 0000000..cc39b75 --- /dev/null +++ b/tests/TileBenchmark/src/com/test/tilebenchmark/PerformanceTest.java @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2011 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.test.tilebenchmark; + +import com.test.tilebenchmark.ProfileActivity.ProfileCallback; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import android.content.res.Resources; +import android.os.Bundle; +import android.os.Environment; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; + +public class PerformanceTest extends + ActivityInstrumentationTestCase2 { + + private class StatAggregator extends PlaybackGraphs { + private HashMap mDataMap = new HashMap(); + private int mCount = 0; + + public void aggregate() { + mCount++; + Resources resources = mView.getResources(); + for (int metricIndex = 0; metricIndex < Metrics.length; metricIndex++) { + for (int statIndex = 0; statIndex < Stats.length; statIndex++) { + String metricLabel = resources.getString( + Metrics[metricIndex].getLabelId()); + String statLabel = resources.getString( + Stats[statIndex].getLabelId()); + + String label = metricLabel + " " + statLabel; + double aggVal = mDataMap.containsKey(label) ? mDataMap + .get(label) : 0; + + aggVal += mStats[metricIndex][statIndex]; + mDataMap.put(label, aggVal); + } + } + for (Map.Entry e : mSingleStats.entrySet()) { + double aggVal = mDataMap.containsKey(e.getKey()) + ? mDataMap.get(e.getKey()) : 0; + mDataMap.put(e.getKey(), aggVal + e.getValue()); + } + } + + public Bundle getBundle() { + Bundle b = new Bundle(); + int count = 0 == mCount ? Integer.MAX_VALUE : mCount; + for (Map.Entry e : mDataMap.entrySet()) { + b.putDouble(e.getKey(), e.getValue() / count); + } + return b; + } + } + + ProfileActivity mActivity; + ProfiledWebView mView; + StatAggregator mStats = new StatAggregator(); + + private static final String LOGTAG = "PerformanceTest"; + private static final String TEST_LOCATION = "webkit/page_cycler"; + private static final String URL_PREFIX = "file://"; + private static final String URL_POSTFIX = "/index.html?skip=true"; + private static final int MAX_ITERATIONS = 4; + private static final String TEST_DIRS[] = { + "alexa25_2011"//, "alexa_us", "android", "dom", "intl2", "moz", "moz2" + }; + + public PerformanceTest() { + super(ProfileActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mActivity = getActivity(); + mView = (ProfiledWebView) mActivity.findViewById(R.id.web); + } + + private boolean loadUrl(final String url) { + try { + Log.d(LOGTAG, "test starting for url " + url); + mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + mView.loadUrl(url); + } + }); + synchronized (mStats) { + mStats.wait(); + } + mStats.aggregate(); + } catch (InterruptedException e) { + e.printStackTrace(); + return false; + } + return true; + } + + private boolean runIteration() { + File sdFile = Environment.getExternalStorageDirectory(); + for (String testDirName : TEST_DIRS) { + File testDir = new File(sdFile, TEST_LOCATION + "/" + testDirName); + Log.d(LOGTAG, "Testing dir: '" + testDir.getAbsolutePath() + + "', exists=" + testDir.exists()); + for (File siteDir : testDir.listFiles()) { + if (!siteDir.isDirectory()) + continue; + + if (!loadUrl(URL_PREFIX + siteDir.getAbsolutePath() + + URL_POSTFIX)) { + return false; + } + } + } + return true; + } + + public void testMetrics() { + String state = Environment.getExternalStorageState(); + + if (!Environment.MEDIA_MOUNTED.equals(state) + && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { + Log.d(LOGTAG, "ARG Can't access sd card!"); + // Can't read the SD card, fail and die! + getInstrumentation().sendStatus(1, null); + return; + } + + // use mGraphs as a condition variable between the UI thread and + // this(the testing) thread + mActivity.setCallback(new ProfileCallback() { + @Override + public void profileCallback(RunData data) { + Log.d(LOGTAG, "test completion callback"); + mStats.setData(data); + synchronized (mStats) { + mStats.notify(); + } + } + }); + + for (int i = 0; i < MAX_ITERATIONS; i++) + if (!runIteration()) { + getInstrumentation().sendStatus(1, null); + return; + } + getInstrumentation().sendStatus(0, mStats.getBundle()); + } +} diff --git a/tests/TileBenchmark/tests/Android.mk b/tests/TileBenchmark/tests/Android.mk deleted file mode 100644 index 8b235ec..0000000 --- a/tests/TileBenchmark/tests/Android.mk +++ /dev/null @@ -1,16 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -# We only want this apk build for tests. -LOCAL_MODULE_TAGS := tests - -LOCAL_JAVA_LIBRARIES := android.test.runner - -# Include all test java files. -LOCAL_SRC_FILES := $(call all-java-files-under, src) - -LOCAL_PACKAGE_NAME := TileBenchmarkTests - -LOCAL_INSTRUMENTATION_FOR := TileBenchmark - -include $(BUILD_PACKAGE) diff --git a/tests/TileBenchmark/tests/AndroidManifest.xml b/tests/TileBenchmark/tests/AndroidManifest.xml deleted file mode 100644 index 703b152..0000000 --- a/tests/TileBenchmark/tests/AndroidManifest.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - diff --git a/tests/TileBenchmark/tests/src/com/test/tilebenchmark/PerformanceTest.java b/tests/TileBenchmark/tests/src/com/test/tilebenchmark/PerformanceTest.java deleted file mode 100644 index 6bf6f6b..0000000 --- a/tests/TileBenchmark/tests/src/com/test/tilebenchmark/PerformanceTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (C) 2011 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.test.tilebenchmark; - -import com.test.tilebenchmark.ProfileActivity.ProfileCallback; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import android.content.res.Resources; -import android.os.Bundle; -import android.os.Environment; -import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; - -public class PerformanceTest extends - ActivityInstrumentationTestCase2 { - - private class StatAggregator extends PlaybackGraphs { - private HashMap mDataMap = new HashMap(); - private int mCount = 0; - - public void aggregate() { - mCount++; - Resources resources = mView.getResources(); - for (int metricIndex = 0; metricIndex < Metrics.length; metricIndex++) { - for (int statIndex = 0; statIndex < Stats.length; statIndex++) { - String metricLabel = resources.getString( - Metrics[metricIndex].getLabelId()); - String statLabel = resources.getString( - Stats[statIndex].getLabelId()); - - String label = metricLabel + " " + statLabel; - double aggVal = mDataMap.containsKey(label) ? mDataMap - .get(label) : 0; - - aggVal += mStats[metricIndex][statIndex]; - mDataMap.put(label, aggVal); - } - } - for (Map.Entry e : mSingleStats.entrySet()) { - double aggVal = mDataMap.containsKey(e.getKey()) - ? mDataMap.get(e.getKey()) : 0; - mDataMap.put(e.getKey(), aggVal + e.getValue()); - } - } - - public Bundle getBundle() { - Bundle b = new Bundle(); - int count = 0 == mCount ? Integer.MAX_VALUE : mCount; - for (Map.Entry e : mDataMap.entrySet()) { - b.putDouble(e.getKey(), e.getValue() / count); - } - return b; - } - } - - ProfileActivity mActivity; - ProfiledWebView mView; - StatAggregator mStats = new StatAggregator(); - - private static final String LOGTAG = "PerformanceTest"; - private static final String TEST_LOCATION = "webkit/page_cycler"; - private static final String URL_PREFIX = "file://"; - private static final String URL_POSTFIX = "/index.html?skip=true"; - private static final int MAX_ITERATIONS = 4; - private static final String TEST_DIRS[] = { - "intl1"//, "alexa_us", "android", "dom", "intl2", "moz", "moz2" - }; - - public PerformanceTest() { - super(ProfileActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - mActivity = getActivity(); - mView = (ProfiledWebView) mActivity.findViewById(R.id.web); - } - - private boolean loadUrl(final String url) { - try { - Log.d(LOGTAG, "test starting for url " + url); - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - mView.loadUrl(url); - } - }); - synchronized (mStats) { - mStats.wait(); - } - mStats.aggregate(); - } catch (InterruptedException e) { - e.printStackTrace(); - return false; - } - return true; - } - - private boolean runIteration() { - File sdFile = Environment.getExternalStorageDirectory(); - for (String testDirName : TEST_DIRS) { - File testDir = new File(sdFile, TEST_LOCATION + "/" + testDirName); - Log.d(LOGTAG, "Testing dir: '" + testDir.getAbsolutePath() - + "', exists=" + testDir.exists()); - for (File siteDir : testDir.listFiles()) { - if (!siteDir.isDirectory()) - continue; - - if (!loadUrl(URL_PREFIX + siteDir.getAbsolutePath() - + URL_POSTFIX)) { - return false; - } - } - } - return true; - } - - public void testMetrics() { - String state = Environment.getExternalStorageState(); - - if (!Environment.MEDIA_MOUNTED.equals(state) - && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { - Log.d(LOGTAG, "ARG Can't access sd card!"); - // Can't read the SD card, fail and die! - getInstrumentation().sendStatus(1, null); - return; - } - - // use mGraphs as a condition variable between the UI thread and - // this(the testing) thread - mActivity.setCallback(new ProfileCallback() { - @Override - public void profileCallback(RunData data) { - Log.d(LOGTAG, "test completion callback"); - mStats.setData(data); - synchronized (mStats) { - mStats.notify(); - } - } - }); - - for (int i = 0; i < MAX_ITERATIONS; i++) - if (!runIteration()) { - getInstrumentation().sendStatus(1, null); - return; - } - getInstrumentation().sendStatus(0, mStats.getBundle()); - } -} -- cgit v1.1