summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeng-Hui Zhu <ztenghui@google.com>2016-06-24 14:23:19 -0700
committerTeng-Hui Zhu <ztenghui@google.com>2016-06-27 14:07:00 -0700
commit119265d05e16c11d84bc51194dd0af6234a7ca4e (patch)
tree5e385ed1b2161664d0230c5247a1800cb632eda6
parent57fc7599e89ff37e2a92d315baa6576b9dc80dde (diff)
Use new Rule to report status when success
b/28980976 Change-Id: Ib5e718ca8bfa2753eedcc40d41843f202c8c23cb
-rw-r--r--apct-tests/perftests/core/src/android/widget/TextViewSetTextLocalePerfTest.java15
-rw-r--r--apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java10
-rw-r--r--apct-tests/perftests/utils/Android.mk19
-rw-r--r--apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java87
4 files changed, 108 insertions, 23 deletions
diff --git a/apct-tests/perftests/core/src/android/widget/TextViewSetTextLocalePerfTest.java b/apct-tests/perftests/core/src/android/widget/TextViewSetTextLocalePerfTest.java
index 030bd2cb94b7..7fc5e4f8635c 100644
--- a/apct-tests/perftests/core/src/android/widget/TextViewSetTextLocalePerfTest.java
+++ b/apct-tests/perftests/core/src/android/widget/TextViewSetTextLocalePerfTest.java
@@ -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;
@@ -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"}
});
}
@@ -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);
}
}
diff --git a/apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java b/apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java
index fc203ee04f0d..2af3b04b6d1e 100644
--- a/apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java
+++ b/apct-tests/perftests/graphics/src/android/graphics/perftests/VectorDrawablePerfTest.java
@@ -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;
@@ -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() {
@@ -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.
@@ -86,8 +87,5 @@ public class VectorDrawablePerfTest {
if (DUMP_BITMAP) {
BitmapUtils.saveBitmapIntoPNG(activity, bmp, resId);
}
-
- state.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(),
- KEY_VECTORDRAWABLE_DRAW_TIME);
}
}
diff --git a/apct-tests/perftests/utils/Android.mk b/apct-tests/perftests/utils/Android.mk
index 2dc7d4c7915b..55c13b087626 100644
--- a/apct-tests/perftests/utils/Android.mk
+++ b/apct-tests/perftests/utils/Android.mk
@@ -1,14 +1,13 @@
- LOCAL_PATH := $(call my-dir)
- include $(CLEAR_VARS)
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
- # Build all java files in the java subdirectory
- LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
- # Any libraries that this library depends on
- LOCAL_JAVA_LIBRARIES := android.test.runner
+# Build all java files in the java subdirectory
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
- # The name of the jar file to create
- LOCAL_MODULE := apct-perftests-utils
+# The name of the jar file to create
+LOCAL_MODULE := apct-perftests-utils
- # Build a static jar file.
- include $(BUILD_STATIC_JAVA_LIBRARY) \ No newline at end of file
+# Build a static jar file.
+include $(BUILD_STATIC_JAVA_LIBRARY) \ No newline at end of file
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java b/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java
new file mode 100644
index 000000000000..3933b57753dc
--- /dev/null
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java
@@ -0,0 +1,87 @@
+/*
+ * 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);
+ }
+
+}