summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gopinath Elanchezhian <gelanchezhian@google.com> 2021-02-05 14:28:27 -0800
committer Gopinath Elanchezhian <gelanchezhian@google.com> 2021-02-16 02:01:39 +0000
commit1a60b7c871a321692d058430ea6dcb0bbf17b2f6 (patch)
tree3ba6dccf5b00d4404f1b3579ad29169e095b2358
parent816122d8a09db66ec4b7db1ffee5ed497d921346 (diff)
Use AndroidJUnitRunner for documentsui perf test.
Do not use deprecated InstrumentationTestCase. Bug: b/172498596 Test: atest DocumentsUIAppPerfTests Change-Id: I4472deace40e21a53a2087f74641389364816f1b
-rw-r--r--app-perf-tests/Android.bp2
-rw-r--r--app-perf-tests/AndroidManifest.xml2
-rw-r--r--app-perf-tests/AndroidTest.xml2
-rw-r--r--app-perf-tests/src/com/android/documentsui/FilesAppPerfTest.java51
4 files changed, 45 insertions, 12 deletions
diff --git a/app-perf-tests/Android.bp b/app-perf-tests/Android.bp
index 5c21977f4..c556edc45 100644
--- a/app-perf-tests/Android.bp
+++ b/app-perf-tests/Android.bp
@@ -14,9 +14,9 @@ android_test {
static_libs: [
"androidx.legacy_legacy-support-v4",
+ "collector-device-lib",
"mockito-target",
"ub-uiautomator",
- "collector-device-lib",
],
platform_apis: true,
diff --git a/app-perf-tests/AndroidManifest.xml b/app-perf-tests/AndroidManifest.xml
index 0013b6b7b..0ed5e4540 100644
--- a/app-perf-tests/AndroidManifest.xml
+++ b/app-perf-tests/AndroidManifest.xml
@@ -13,7 +13,7 @@
<!-- This package instrumentates itself, so the DocumentsUI process can be killed without
killing the testing package. -->
- <instrumentation android:name="android.test.InstrumentationTestRunner"
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.documentsui.appperftests"
android:label="App performance tests for DocumentsUI" />
diff --git a/app-perf-tests/AndroidTest.xml b/app-perf-tests/AndroidTest.xml
index c8dd9a105..a55322673 100644
--- a/app-perf-tests/AndroidTest.xml
+++ b/app-perf-tests/AndroidTest.xml
@@ -22,7 +22,7 @@
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
- <option name="runner" value="android.test.InstrumentationTestRunner" />
+ <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
<option name="package" value="com.android.documentsui.appperftests" />
</test>
</configuration>
diff --git a/app-perf-tests/src/com/android/documentsui/FilesAppPerfTest.java b/app-perf-tests/src/com/android/documentsui/FilesAppPerfTest.java
index d39b49cb9..be8fd9852 100644
--- a/app-perf-tests/src/com/android/documentsui/FilesAppPerfTest.java
+++ b/app-perf-tests/src/com/android/documentsui/FilesAppPerfTest.java
@@ -28,12 +28,19 @@ import android.support.test.uiautomator.UiDevice;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.LargeTest;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
-@LargeTest
-public class FilesAppPerfTest extends InstrumentationTestCase {
+@RunWith(AndroidJUnit4.class)
+public class FilesAppPerfTest {
// Keys used to report metrics to APCT.
private static final String KEY_FILES_COLD_START_PERFORMANCE_MEDIAN =
@@ -46,17 +53,19 @@ public class FilesAppPerfTest extends InstrumentationTestCase {
private static final int NUM_MEASUREMENTS = 10;
private LauncherActivity mActivity;
- private UiDevice mDevice;
+ private static UiDevice mDevice;
- @Override
- public void setUp() {
- mDevice = UiDevice.getInstance(getInstrumentation());
+ @BeforeClass
+ public static void setUp() {
+ mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
}
+ @Test
public void testFilesColdStartPerformance() throws Exception {
runFilesStartPerformanceTest(true);
}
+ @Test
public void testFilesWarmStartPerformance() throws Exception {
runFilesStartPerformanceTest(false);
}
@@ -72,7 +81,9 @@ public class FilesAppPerfTest extends InstrumentationTestCase {
mDevice.waitForIdle();
LauncherActivity.testCaseLatch = new CountDownLatch(1);
- mActivity = launchActivity(getInstrumentation().getTargetContext().getPackageName(),
+ mActivity = launchActivity(
+ InstrumentationRegistry.getInstrumentation().getTargetContext()
+ .getPackageName(),
LauncherActivity.class, null);
LauncherActivity.testCaseLatch.await();
measurements[i] = LauncherActivity.measurement;
@@ -88,11 +99,11 @@ public class FilesAppPerfTest extends InstrumentationTestCase {
final long median = measurements[NUM_MEASUREMENTS / 2 - 1];
status.putDouble(key, median);
- getInstrumentation().sendStatus(Activity.RESULT_OK, status);
+ InstrumentationRegistry.getInstrumentation().sendStatus(Activity.RESULT_OK, status);
}
private void killProviders() throws Exception {
- final Context context = getInstrumentation().getContext();
+ final Context context = InstrumentationRegistry.getInstrumentation().getContext();
final PackageManager pm = context.getPackageManager();
final ActivityManager am = (ActivityManager) context.getSystemService(
Context.ACTIVITY_SERVICE);
@@ -103,4 +114,26 @@ public class FilesAppPerfTest extends InstrumentationTestCase {
am.killBackgroundProcesses(packageName);
}
}
+
+ private final <T extends Activity> T launchActivity(
+ String pkg,
+ Class<T> activityCls,
+ Bundle extras) {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ if (extras != null) {
+ intent.putExtras(extras);
+ }
+ return launchActivityWithIntent(pkg, activityCls, intent);
+ }
+
+ private final <T extends Activity> T launchActivityWithIntent(
+ String pkg,
+ Class<T> activityCls,
+ Intent intent) {
+ intent.setClassName(pkg, activityCls.getName());
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ T activity = (T) InstrumentationRegistry.getInstrumentation().startActivitySync(intent);
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+ return activity;
+ }
}