Loading apct-tests/perftests/core/src/android/widget/TextViewSetTextLocalePerfTest.java +8 −7 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.widget; import android.app.Activity; import android.os.Bundle; import android.perftests.utils.PerfStatusReporter; import android.util.Log; import android.perftests.utils.BenchmarkState; Loading @@ -40,12 +41,11 @@ import org.junit.runner.RunWith; @LargeTest @RunWith(Parameterized.class) public class TextViewSetTextLocalePerfTest { @Parameters @Parameters(name = "{0}") public static Collection locales() { return Arrays.asList(new Object[][] { { "TextView_setTextLocale_SameLocale", "en-US", "en-US" }, { "TextView_setTextLocale_DifferentLocale", "en-US", "ja-JP"} { "SameLocale", "en-US", "en-US" }, { "DifferentLocale", "en-US", "ja-JP"} }); } Loading @@ -63,17 +63,18 @@ public class TextViewSetTextLocalePerfTest { @Rule public ActivityTestRule<StubActivity> mActivityRule = new ActivityTestRule(StubActivity.class); @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); @Test public void testSetTextLocale() { TextView textView = new TextView(mActivityRule.getActivity()); BenchmarkState state = new BenchmarkState(); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { textView.setTextLocale(mFirstLocale); textView.setTextLocale(mSecondLocale); } state.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(), mMetricKey); } } apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java +4 −6 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.graphics.Color; import android.graphics.drawable.VectorDrawable; import android.perftests.utils.BenchmarkState; import android.perftests.utils.BitmapUtils; import android.perftests.utils.PerfStatusReporter; import android.perftests.utils.StubActivity; import android.support.test.InstrumentationRegistry; import android.support.test.rule.ActivityTestRule; Loading @@ -48,12 +49,12 @@ public class VectorDrawablePerfTest { private int[] mTestWidths = {1024, 512}; private int[] mTestHeights = {512, 1024}; private String KEY_VECTORDRAWABLE_DRAW_TIME = "VectorDrawable_Draw_Time_NanoSec"; @Rule public ActivityTestRule<StubActivity> mActivityRule = new ActivityTestRule(StubActivity.class); @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); @Test public void testBitmapDrawPerf() { Loading @@ -66,7 +67,7 @@ public class VectorDrawablePerfTest { Bitmap bmp = Bitmap.createBitmap(w, h, conf); Canvas canvas = new Canvas(bmp); BenchmarkState state = new BenchmarkState(); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); int i = 0; while (state.keepRunning()) { // Use different width / height each to force the vectorDrawable abandon the cache. Loading @@ -86,8 +87,5 @@ public class VectorDrawablePerfTest { if (DUMP_BITMAP) { BitmapUtils.saveBitmapIntoPNG(activity, bmp, resId); } state.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(), KEY_VECTORDRAWABLE_DRAW_TIME); } } apct-tests/perftests/utils/Android.mk +9 −10 Original line number Diff line number Diff line LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_STATIC_JAVA_LIBRARIES := android-support-test # Build all java files in the java subdirectory LOCAL_SRC_FILES := $(call all-subdir-java-files) # Any libraries that this library depends on LOCAL_JAVA_LIBRARIES := android.test.runner # The name of the jar file to create LOCAL_MODULE := apct-perftests-utils Loading apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java 0 → 100644 +87 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 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.perftests.utils; import android.support.test.InstrumentationRegistry; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; /** * Use this rule to make sure we report the status after the test success. * * <code> * * @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); * @Test public void functionName() { * ... * BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); * while (state.keepRunning()) { * // DO YOUR TEST HERE! * } * ... * } * </code> * * When test succeeded, the status report will use the key as * "functionName[optional subTestName]_*" * * Notice that optional subTestName can't be just numbers, that means each sub test needs to have a * name when using parameterization. */ public class PerfStatusReporter extends TestWatcher { private final BenchmarkState mState = new BenchmarkState(); public BenchmarkState getBenchmarkState() { return mState; } @Override protected void succeeded(Description description) { String invokeMethodName = description.getMethodName(); // validate and simplify the function name. // First, remove the "test" prefix which normally comes from CTS test. // Then make sure the [subTestName] is valid, not just numbers like [0]. if (invokeMethodName.startsWith("test")) { assertTrue("The test name " + invokeMethodName + " is too short", invokeMethodName.length() > 5); invokeMethodName = invokeMethodName.substring(4, 5).toLowerCase() + invokeMethodName.substring(5); } int index = invokeMethodName.lastIndexOf('['); if (index > 0) { boolean allDigits = true; for (int i = index + 1; i < invokeMethodName.length() - 1; i++) { if (!Character.isDigit(invokeMethodName.charAt(i))) { allDigits = false; break; } } assertFalse("The name in [] can't contain only digits for " + invokeMethodName, allDigits); } mState.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(), invokeMethodName); } } Loading
apct-tests/perftests/core/src/android/widget/TextViewSetTextLocalePerfTest.java +8 −7 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.widget; import android.app.Activity; import android.os.Bundle; import android.perftests.utils.PerfStatusReporter; import android.util.Log; import android.perftests.utils.BenchmarkState; Loading @@ -40,12 +41,11 @@ import org.junit.runner.RunWith; @LargeTest @RunWith(Parameterized.class) public class TextViewSetTextLocalePerfTest { @Parameters @Parameters(name = "{0}") public static Collection locales() { return Arrays.asList(new Object[][] { { "TextView_setTextLocale_SameLocale", "en-US", "en-US" }, { "TextView_setTextLocale_DifferentLocale", "en-US", "ja-JP"} { "SameLocale", "en-US", "en-US" }, { "DifferentLocale", "en-US", "ja-JP"} }); } Loading @@ -63,17 +63,18 @@ public class TextViewSetTextLocalePerfTest { @Rule public ActivityTestRule<StubActivity> mActivityRule = new ActivityTestRule(StubActivity.class); @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); @Test public void testSetTextLocale() { TextView textView = new TextView(mActivityRule.getActivity()); BenchmarkState state = new BenchmarkState(); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { textView.setTextLocale(mFirstLocale); textView.setTextLocale(mSecondLocale); } state.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(), mMetricKey); } }
apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java +4 −6 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.graphics.Color; import android.graphics.drawable.VectorDrawable; import android.perftests.utils.BenchmarkState; import android.perftests.utils.BitmapUtils; import android.perftests.utils.PerfStatusReporter; import android.perftests.utils.StubActivity; import android.support.test.InstrumentationRegistry; import android.support.test.rule.ActivityTestRule; Loading @@ -48,12 +49,12 @@ public class VectorDrawablePerfTest { private int[] mTestWidths = {1024, 512}; private int[] mTestHeights = {512, 1024}; private String KEY_VECTORDRAWABLE_DRAW_TIME = "VectorDrawable_Draw_Time_NanoSec"; @Rule public ActivityTestRule<StubActivity> mActivityRule = new ActivityTestRule(StubActivity.class); @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); @Test public void testBitmapDrawPerf() { Loading @@ -66,7 +67,7 @@ public class VectorDrawablePerfTest { Bitmap bmp = Bitmap.createBitmap(w, h, conf); Canvas canvas = new Canvas(bmp); BenchmarkState state = new BenchmarkState(); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); int i = 0; while (state.keepRunning()) { // Use different width / height each to force the vectorDrawable abandon the cache. Loading @@ -86,8 +87,5 @@ public class VectorDrawablePerfTest { if (DUMP_BITMAP) { BitmapUtils.saveBitmapIntoPNG(activity, bmp, resId); } state.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(), KEY_VECTORDRAWABLE_DRAW_TIME); } }
apct-tests/perftests/utils/Android.mk +9 −10 Original line number Diff line number Diff line LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_STATIC_JAVA_LIBRARIES := android-support-test # Build all java files in the java subdirectory LOCAL_SRC_FILES := $(call all-subdir-java-files) # Any libraries that this library depends on LOCAL_JAVA_LIBRARIES := android.test.runner # The name of the jar file to create LOCAL_MODULE := apct-perftests-utils Loading
apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java 0 → 100644 +87 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 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.perftests.utils; import android.support.test.InstrumentationRegistry; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; /** * Use this rule to make sure we report the status after the test success. * * <code> * * @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); * @Test public void functionName() { * ... * BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); * while (state.keepRunning()) { * // DO YOUR TEST HERE! * } * ... * } * </code> * * When test succeeded, the status report will use the key as * "functionName[optional subTestName]_*" * * Notice that optional subTestName can't be just numbers, that means each sub test needs to have a * name when using parameterization. */ public class PerfStatusReporter extends TestWatcher { private final BenchmarkState mState = new BenchmarkState(); public BenchmarkState getBenchmarkState() { return mState; } @Override protected void succeeded(Description description) { String invokeMethodName = description.getMethodName(); // validate and simplify the function name. // First, remove the "test" prefix which normally comes from CTS test. // Then make sure the [subTestName] is valid, not just numbers like [0]. if (invokeMethodName.startsWith("test")) { assertTrue("The test name " + invokeMethodName + " is too short", invokeMethodName.length() > 5); invokeMethodName = invokeMethodName.substring(4, 5).toLowerCase() + invokeMethodName.substring(5); } int index = invokeMethodName.lastIndexOf('['); if (index > 0) { boolean allDigits = true; for (int i = index + 1; i < invokeMethodName.length() - 1; i++) { if (!Character.isDigit(invokeMethodName.charAt(i))) { allDigits = false; break; } } assertFalse("The name in [] can't contain only digits for " + invokeMethodName, allDigits); } mState.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(), invokeMethodName); } }