diff options
54 files changed, 2439 insertions, 36 deletions
diff --git a/build/tasks/tests/instrumentation_test_list.mk b/build/tasks/tests/instrumentation_test_list.mk index 2b174842e..786284e74 100644 --- a/build/tasks/tests/instrumentation_test_list.mk +++ b/build/tasks/tests/instrumentation_test_list.mk @@ -59,7 +59,7 @@ instrumentation_tests := \ SettingsLibTests \ RSTest \ PrintSpoolerOutOfProcessTests \ - CellBroadcastReceiverPlatformUnitTests \ + CellBroadcastReceiverUnitTests \ TelephonyProviderTests \ CarrierConfigTests \ TeleServiceTests \ diff --git a/build/tasks/tests/platform_test_list.mk b/build/tasks/tests/platform_test_list.mk index ba1b9edaa..d793ea69f 100644 --- a/build/tasks/tests/platform_test_list.mk +++ b/build/tasks/tests/platform_test_list.mk @@ -58,6 +58,8 @@ platform_tests += \ FrameworksUtilTests \ InternalLocTestApp \ JankMicroBenchmarkTests \ + libbluetooth_gd \ + libgrpc++_unsecure \ MemoryUsage \ MultiDexLegacyTestApp \ MultiDexLegacyTestApp2 \ @@ -99,6 +101,7 @@ platform_tests += \ UiBench \ UiBenchJankTests \ UiBenchJankTestsWear \ + UiBenchMicrobenchmark \ UpdateExternalLocTestApp_v1_ext \ UpdateExternalLocTestApp_v2_none \ UpdateExtToIntLocTestApp_v1_ext \ diff --git a/libraries/collectors-helper/perfetto/src/com/android/helpers/PerfettoHelper.java b/libraries/collectors-helper/perfetto/src/com/android/helpers/PerfettoHelper.java index c1d7aeef8..abf92e25c 100644 --- a/libraries/collectors-helper/perfetto/src/com/android/helpers/PerfettoHelper.java +++ b/libraries/collectors-helper/perfetto/src/com/android/helpers/PerfettoHelper.java @@ -40,6 +40,8 @@ public class PerfettoHelper { private static final String PERFETTO_START_CMD = "perfetto --background -c %s%s -o %s"; private static final String PERFETTO_TMP_OUTPUT_FILE = "/data/misc/perfetto-traces/trace_output.pb"; + // Additional arg to indicate that the perfetto config file is text format. + private static final String PERFETTO_TXT_PROTO_ARG = " --txt"; // Command to stop (i.e kill) the perfetto tracing. private static final String PERFETTO_STOP_CMD = "pkill -INT perfetto"; // Command to check the perfetto process id. @@ -62,9 +64,10 @@ public class PerfettoHelper { * /data/misc/perfetto-traces/ folder in the device. * * @param configFileName used for collecting the perfetto trace. + * @param isTextProtoConfig true if the config file is textproto format otherwise false. * @return true if trace collection started successfully otherwise return false. */ - public boolean startCollecting(String configFileName) { + public boolean startCollecting(String configFileName, boolean isTextProtoConfig) { mUIDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); if (configFileName == null || configFileName.isEmpty()) { Log.e(LOG_TAG, "Perfetto config file name is null or empty."); @@ -79,15 +82,22 @@ public class PerfettoHelper { return false; } } + // Remove already existing temporary output trace file if any. String output = mUIDevice.executeShellCommand(String.format(REMOVE_CMD, PERFETTO_TMP_OUTPUT_FILE)); Log.i(LOG_TAG, String.format("Perfetto output file cleanup - %s", output)); + String perfettoCmd = String.format(PERFETTO_START_CMD, + PERFETTO_ROOT_DIR, configFileName, PERFETTO_TMP_OUTPUT_FILE); + + if(isTextProtoConfig) { + perfettoCmd = perfettoCmd + PERFETTO_TXT_PROTO_ARG; + } + // Start perfetto tracing. Log.i(LOG_TAG, "Starting perfetto tracing."); - String startOutput = mUIDevice.executeShellCommand(String.format(PERFETTO_START_CMD, - PERFETTO_ROOT_DIR, configFileName, PERFETTO_TMP_OUTPUT_FILE)); + String startOutput = mUIDevice.executeShellCommand(perfettoCmd); Log.i(LOG_TAG, String.format("Perfetto start command output - %s", startOutput)); // TODO : Once the output status is available use that for additional validation. if (!isPerfettoRunning()) { diff --git a/libraries/collectors-helper/perfetto/test/src/com/android/helpers/tests/PerfettoHelperTest.java b/libraries/collectors-helper/perfetto/test/src/com/android/helpers/tests/PerfettoHelperTest.java index 66b4f3bfe..a81499d01 100644 --- a/libraries/collectors-helper/perfetto/test/src/com/android/helpers/tests/PerfettoHelperTest.java +++ b/libraries/collectors-helper/perfetto/test/src/com/android/helpers/tests/PerfettoHelperTest.java @@ -37,6 +37,7 @@ import static org.junit.Assert.assertTrue; * * To run: * Have a valid perfetto config under /data/misc/perfetto-traces/valid_config.pb + * Have a valid text perfetto config under /data/misc/perfetto-traces/valid_text_config.textproto * TODO: b/119020380 to keep track of automating the above step. * atest CollectorsHelperTest:com.android.helpers.tests.PerfettoHelperTest */ @@ -64,7 +65,7 @@ public class PerfettoHelperTest { */ @Test public void testNullConfigName() throws Exception { - assertFalse(perfettoHelper.startCollecting(null)); + assertFalse(perfettoHelper.startCollecting(null, false)); } /** @@ -72,7 +73,7 @@ public class PerfettoHelperTest { */ @Test public void testEmptyConfigName() throws Exception { - assertFalse(perfettoHelper.startCollecting("")); + assertFalse(perfettoHelper.startCollecting("", false)); } /** @@ -80,7 +81,7 @@ public class PerfettoHelperTest { */ @Test public void testNoConfigFile() throws Exception { - assertFalse(perfettoHelper.startCollecting("no_config.pb")); + assertFalse(perfettoHelper.startCollecting("no_config.pb", false)); } /** @@ -88,7 +89,7 @@ public class PerfettoHelperTest { */ @Test public void testPerfettoStartSuccess() throws Exception { - assertTrue(perfettoHelper.startCollecting("valid_config.pb")); + assertTrue(perfettoHelper.startCollecting("valid_config.pb", false)); } /** @@ -96,7 +97,7 @@ public class PerfettoHelperTest { */ @Test public void testPerfettoValidOutputPath() throws Exception { - assertTrue(perfettoHelper.startCollecting("valid_config.pb")); + assertTrue(perfettoHelper.startCollecting("valid_config.pb", false)); assertTrue(perfettoHelper.stopCollecting(1000, "data/local/tmp/out.pb")); } @@ -105,7 +106,7 @@ public class PerfettoHelperTest { */ @Test public void testPerfettoInvalidOutputPath() throws Exception { - assertTrue(perfettoHelper.startCollecting("valid_config.pb")); + assertTrue(perfettoHelper.startCollecting("valid_config.pb", false)); // Don't have permission to create new folder under /data assertFalse(perfettoHelper.stopCollecting(1000, "/data/dummy/xyz/out.pb")); } @@ -116,7 +117,7 @@ public class PerfettoHelperTest { */ @Test public void testPerfettoSuccess() throws Exception { - assertTrue(perfettoHelper.startCollecting("valid_config.pb")); + assertTrue(perfettoHelper.startCollecting("valid_config.pb", false)); assertTrue(perfettoHelper.stopCollecting(1000, "/data/local/tmp/out.pb")); UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); String[] fileStats = uiDevice.executeShellCommand(String.format( @@ -125,4 +126,18 @@ public class PerfettoHelperTest { assertTrue(fileSize > 0); } + /** + * Test perfetto collection returns true and output file size greater than zero + * if the valid perfetto config file used. + */ + @Test + public void testTextProtoConfigSuccess() throws Exception { + assertTrue(perfettoHelper.startCollecting("valid_text_config.textproto", true)); + assertTrue(perfettoHelper.stopCollecting(1000, "/data/local/tmp/out.pb")); + UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + String[] fileStats = uiDevice.executeShellCommand(String.format( + FILE_SIZE_IN_BYTES, "/data/local/tmp/out.pb")).split(" "); + int fileSize = Integer.parseInt(fileStats[0].trim()); + assertTrue(fileSize > 0); + } } diff --git a/libraries/device-collectors/src/hostsidetests/src/com/android/collectors/DeviceCollectorsTest.java b/libraries/device-collectors/src/hostsidetests/src/com/android/collectors/DeviceCollectorsTest.java index 6d264b5fb..d2f4582df 100644 --- a/libraries/device-collectors/src/hostsidetests/src/com/android/collectors/DeviceCollectorsTest.java +++ b/libraries/device-collectors/src/hostsidetests/src/com/android/collectors/DeviceCollectorsTest.java @@ -205,6 +205,7 @@ public class DeviceCollectorsTest extends BaseHostJUnit4Test { public void testScheduledListenerRuns() throws Exception { mTestRunner.addInstrumentationArg("listener", SCHEDULED_COLLECTOR); mTestRunner.addInstrumentationArg("interval", "100"); + mTestRunner.setClassName("android.device.collectors.BaseMetricListenerInstrumentedTest"); CollectingTestListener listener = new CollectingTestListener(); assertTrue(getDevice().runInstrumentationTests(mTestRunner, listener)); Collection<TestRunResult> results = listener.getRunResults(); @@ -227,6 +228,7 @@ public class DeviceCollectorsTest extends BaseHostJUnit4Test { mTestRunner.addInstrumentationArg("listener", SCHEDULED_COLLECTOR); // Invalid interval will results in the default period to be used. mTestRunner.addInstrumentationArg("interval", "-100"); + mTestRunner.setClassName("android.device.collectors.BaseMetricListenerInstrumentedTest"); CollectingTestListener listener = new CollectingTestListener(); assertTrue(getDevice().runInstrumentationTests(mTestRunner, listener)); Collection<TestRunResult> results = listener.getRunResults(); diff --git a/libraries/device-collectors/src/main/java/android/device/collectors/PerfettoListener.java b/libraries/device-collectors/src/main/java/android/device/collectors/PerfettoListener.java index 8c0891e5f..9ba0e8b9d 100644 --- a/libraries/device-collectors/src/main/java/android/device/collectors/PerfettoListener.java +++ b/libraries/device-collectors/src/main/java/android/device/collectors/PerfettoListener.java @@ -46,6 +46,8 @@ public class PerfettoListener extends BaseMetricListener { private static final String DEFAULT_WAIT_TIME_MSECS = "3000"; // Default output folder to store the perfetto output traces. private static final String DEFAULT_OUTPUT_ROOT = "/sdcard/test_results"; + // Argument to indicate the perfetto config file is text proto file. + public static final String PERFETTO_CONFIG_TEXT_PROTO = "perfetto_config_text_proto"; // Argument to get custom config file name for collecting the trace. private static final String PERFETTO_CONFIG_FILE_ARG = "perfetto_config_file"; // Argument to get custom time in millisecs to wait before dumping the trace. @@ -75,6 +77,7 @@ public class PerfettoListener extends BaseMetricListener { // Store the method name and invocation count to create unique file name for each trace. private Map<String, Integer> mTestIdInvocationCount = new HashMap<>(); private boolean mPerfettoStartSuccess = false; + private boolean mIsConfigTextProto = false; private boolean mIsCollectPerRun; private PerfettoHelper mPerfettoHelper = new PerfettoHelper(); @@ -123,10 +126,14 @@ public class PerfettoListener extends BaseMetricListener { // Whether to collect the for the entire test run or per test. mIsCollectPerRun = Boolean.parseBoolean(args.getString(COLLECT_PER_RUN)); + // Whether the config is text proto or not. By default set to false. + mIsConfigTextProto = Boolean.parseBoolean(args.getString(PERFETTO_CONFIG_TEXT_PROTO)); + // Perfetto config file has to be under /data/misc/perfetto-traces/ // defaulted to trace_config.pb is perfetto_config_file is not passed. mConfigFileName = args.getString(PERFETTO_CONFIG_FILE_ARG, DEFAULT_CONFIG_FILE); + // Whether to hold wakelocks on all Prefetto tracing functions. You may want to enable // this if your device is not USB connected. This option prevents the device from // going into suspend mode while this listener is running intensive tasks. @@ -288,16 +295,22 @@ public class PerfettoListener extends BaseMetricListener { @VisibleForTesting public void acquireWakelock(WakeLock wakelock) { if (wakelock != null) { + Log.d(getTag(), "wakelock.isHeld: " + wakelock.isHeld()); Log.d(getTag(), "acquiring wakelock."); wakelock.acquire(); + Log.d(getTag(), "wakelock acquired."); + Log.d(getTag(), "wakelock.isHeld: " + wakelock.isHeld()); } } @VisibleForTesting public void releaseWakelock(WakeLock wakelock) { if (wakelock != null) { + Log.d(getTag(), "wakelock.isHeld: " + wakelock.isHeld()); Log.d(getTag(), "releasing wakelock."); wakelock.release(); + Log.d(getTag(), "wakelock released."); + Log.d(getTag(), "wakelock.isHeld: " + wakelock.isHeld()); } } @@ -313,7 +326,8 @@ public class PerfettoListener extends BaseMetricListener { * Start perfetto tracing using the given config file. */ private void startPerfettoTracing() { - mPerfettoStartSuccess = mPerfettoHelper.startCollecting(mConfigFileName); + mPerfettoStartSuccess = mPerfettoHelper.startCollecting(mConfigFileName, + mIsConfigTextProto); if (!mPerfettoStartSuccess) { Log.e(getTag(), "Perfetto did not start successfully."); } diff --git a/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/README.md b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/README.md index acd59ed75..a6bc18c42 100644 --- a/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/README.md +++ b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/README.md @@ -9,11 +9,14 @@ A config tells statsd what metrics to collect from the device during a test. For ## Checking in a config -To check in a config, follow these steps: - -1. Create a directory under this directory for the new config (e.g. `app-start`). -2. Put the new config in the subdirectory using the directory name + `.pb` extension. -3. Write a README file explaining what the config does and put it under the new subdirectory. +To check in config(s) for a new set of metrics, follow these steps: + +1. Create a directory under this directory for the new metrics (e.g. `app-start`). +2. Put the new config(s) in the subdirectory using the directory name and optionally with additional +suffixes if there are multiple configs related to the overarching metrics, with `.pb` extension. +This ensures that each config has a unique name. +3. Write a README file explaining what the config(s) in the new subdirectory does and put it under +the new subdirectory. # (Internal only) Creating a config diff --git a/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/README.md b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/README.md new file mode 100644 index 000000000..558107aae --- /dev/null +++ b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/README.md @@ -0,0 +1,4 @@ +# Remaining Battery Capacity Configs + +These configs are used to collect the remaining battery capacity on the device as defined in the +RemainingBatteryCapacity (Colomb counter) atom. diff --git a/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/remaining-battery-capacity-run-level.pb b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/remaining-battery-capacity-run-level.pb Binary files differnew file mode 100644 index 000000000..ab1f5c2d4 --- /dev/null +++ b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/remaining-battery-capacity-run-level.pb diff --git a/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/remaining-battery-capacity-test-level.pb b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/remaining-battery-capacity-test-level.pb Binary files differnew file mode 100644 index 000000000..55a8f3d1b --- /dev/null +++ b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/remaining-battery-capacity/remaining-battery-capacity-test-level.pb diff --git a/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/README.md b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/README.md new file mode 100644 index 000000000..63c917e01 --- /dev/null +++ b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/README.md @@ -0,0 +1,4 @@ +# WiFi Bytes Transfer Configs + +The configs here collects the WiFi bytes transferred on the start and end of tests or test run, +respectively. diff --git a/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/wifi-bytes-transfer-run-level.pb b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/wifi-bytes-transfer-run-level.pb Binary files differnew file mode 100644 index 000000000..ef522ac4f --- /dev/null +++ b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/wifi-bytes-transfer-run-level.pb diff --git a/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/wifi-bytes-transfer-test-level.pb b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/wifi-bytes-transfer-test-level.pb Binary files differnew file mode 100644 index 000000000..f022f329a --- /dev/null +++ b/libraries/device-collectors/src/main/platform-collectors/res/statsd-configs/wifi-bytes-transfer/wifi-bytes-transfer-test-level.pb diff --git a/libraries/device-collectors/src/test/java/android/device/collectors/LogcatOnFailureCollectorTest.java b/libraries/device-collectors/src/test/java/android/device/collectors/LogcatOnFailureCollectorTest.java index 31e11b21a..119211c80 100644 --- a/libraries/device-collectors/src/test/java/android/device/collectors/LogcatOnFailureCollectorTest.java +++ b/libraries/device-collectors/src/test/java/android/device/collectors/LogcatOnFailureCollectorTest.java @@ -26,6 +26,7 @@ import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.Description; import org.junit.runner.notification.Failure; @@ -223,6 +224,7 @@ public final class LogcatOnFailureCollectorTest { } /** Test that the logcat retrieved are within the time bounds of the test. */ + @Ignore @Test public void testLogcatTimespan() throws Exception { LogcatOnFailureCollector listener = initListener(); diff --git a/libraries/device-collectors/src/test/java/android/device/collectors/PerfettoListenerTest.java b/libraries/device-collectors/src/test/java/android/device/collectors/PerfettoListenerTest.java index c51ded8cf..20ae4d63c 100644 --- a/libraries/device-collectors/src/test/java/android/device/collectors/PerfettoListenerTest.java +++ b/libraries/device-collectors/src/test/java/android/device/collectors/PerfettoListenerTest.java @@ -18,6 +18,7 @@ package android.device.collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; @@ -113,14 +114,14 @@ public class PerfettoListenerTest { public void testPerfettoPerTestSuccessFlow() throws Exception { Bundle b = new Bundle(); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior mListener.testRunStarted(mRunDesc); // Test test start behavior mListener.testStarted(mTest1Desc); - verify(mPerfettoHelper, times(1)).startCollecting(anyString()); + verify(mPerfettoHelper, times(1)).startCollecting(anyString(), anyBoolean()); mListener.onTestEnd(mDataRecord, mTest1Desc); verify(mPerfettoHelper, times(1)).stopCollecting(anyLong(), anyString()); @@ -135,14 +136,14 @@ public class PerfettoListenerTest { Bundle b = new Bundle(); b.putString(PerfettoListener.COLLECT_PER_RUN, "true"); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior mListener.onTestRunStart(mListener.createDataRecord(), FAKE_DESCRIPTION); - verify(mPerfettoHelper, times(1)).startCollecting(anyString()); + verify(mPerfettoHelper, times(1)).startCollecting(anyString(), anyBoolean()); mListener.testStarted(mTest1Desc); - verify(mPerfettoHelper, times(1)).startCollecting(anyString()); + verify(mPerfettoHelper, times(1)).startCollecting(anyString(), anyBoolean()); mListener.onTestEnd(mDataRecord, mTest1Desc); verify(mPerfettoHelper, times(0)).stopCollecting(anyLong(), anyString()); mListener.onTestRunEnd(mListener.createDataRecord(), new Result()); @@ -185,7 +186,7 @@ public class PerfettoListenerTest { b.putString(PerfettoListener.COLLECT_PER_RUN, "true"); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior @@ -204,7 +205,7 @@ public class PerfettoListenerTest { Bundle b = new Bundle(); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior @@ -225,7 +226,7 @@ public class PerfettoListenerTest { b.putString(PerfettoListener.COLLECT_PER_RUN, "true"); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior @@ -243,7 +244,7 @@ public class PerfettoListenerTest { b.putString(PerfettoListener.HOLD_WAKELOCK_WHILE_COLLECTING, "true"); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior @@ -264,7 +265,7 @@ public class PerfettoListenerTest { b.putString(PerfettoListener.HOLD_WAKELOCK_WHILE_COLLECTING, "true"); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior @@ -290,7 +291,7 @@ public class PerfettoListenerTest { b.putString(PerfettoListener.COLLECT_PER_RUN, "true"); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior @@ -315,11 +316,11 @@ public class PerfettoListenerTest { Bundle b = new Bundle(); b.putString(PerfettoListener.COLLECT_PER_RUN, "true"); mListener = initListener(b); - doReturn(false).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(false).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); // Test run start behavior mListener.onTestRunStart(mListener.createDataRecord(), FAKE_DESCRIPTION); - verify(mPerfettoHelper, times(1)).startCollecting(anyString()); + verify(mPerfettoHelper, times(1)).startCollecting(anyString(), anyBoolean()); mListener.onTestRunEnd(mListener.createDataRecord(), new Result()); verify(mPerfettoHelper, times(0)).stopCollecting(anyLong(), anyString()); } @@ -331,14 +332,14 @@ public class PerfettoListenerTest { public void testPerfettoStartFailureFlow() throws Exception { Bundle b = new Bundle(); mListener = initListener(b); - doReturn(false).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(false).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); // Test run start behavior mListener.testRunStarted(mRunDesc); // Test test start behavior mListener.testStarted(mTest1Desc); - verify(mPerfettoHelper, times(1)).startCollecting(anyString()); + verify(mPerfettoHelper, times(1)).startCollecting(anyString(), anyBoolean()); mListener.onTestEnd(mDataRecord, mTest1Desc); verify(mPerfettoHelper, times(0)).stopCollecting(anyLong(), anyString()); } @@ -351,7 +352,7 @@ public class PerfettoListenerTest { public void testPerfettoInvocationCount() throws Exception { Bundle b = new Bundle(); mListener = initListener(b); - doReturn(true).when(mPerfettoHelper).startCollecting(anyString()); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); // Test run start behavior @@ -359,19 +360,19 @@ public class PerfettoListenerTest { // Test1 invocation 1 start behavior mListener.testStarted(mTest1Desc); - verify(mPerfettoHelper, times(1)).startCollecting(anyString()); + verify(mPerfettoHelper, times(1)).startCollecting(anyString(), anyBoolean()); mListener.onTestEnd(mDataRecord, mTest1Desc); verify(mPerfettoHelper, times(1)).stopCollecting(anyLong(), anyString()); // Test1 invocation 2 start behaviour mListener.testStarted(mTest1Desc); - verify(mPerfettoHelper, times(2)).startCollecting(anyString()); + verify(mPerfettoHelper, times(2)).startCollecting(anyString(), anyBoolean()); mListener.onTestEnd(mDataRecord, mTest1Desc); verify(mPerfettoHelper, times(2)).stopCollecting(anyLong(), anyString()); // Test2 invocation 1 start behaviour mListener.testStarted(mTest2Desc); - verify(mPerfettoHelper, times(3)).startCollecting(anyString()); + verify(mPerfettoHelper, times(3)).startCollecting(anyString(), anyBoolean()); mDataRecord = mListener.createDataRecord(); mListener.onTestEnd(mDataRecord, mTest2Desc); verify(mPerfettoHelper, times(3)).stopCollecting(anyLong(), anyString()); @@ -381,4 +382,27 @@ public class PerfettoListenerTest { assertEquals(1, (int) mInvocationCount.get(mListener.getTestFileName(mTest2Desc))); } + + /* + * Verify perfetto start and stop collection methods called when the text + * proto config option is enabled + */ + @Test + public void testPerfettoSuccessFlowWithTextConfig() throws Exception { + Bundle b = new Bundle(); + b.putString(PerfettoListener.PERFETTO_CONFIG_TEXT_PROTO, "true"); + mListener = initListener(b); + doReturn(true).when(mPerfettoHelper).startCollecting(anyString(), anyBoolean()); + doReturn(true).when(mPerfettoHelper).stopCollecting(anyLong(), anyString()); + // Test run start behavior + mListener.testRunStarted(mRunDesc); + + // Test test start behavior + mListener.testStarted(mTest1Desc); + verify(mPerfettoHelper, times(1)).startCollecting(anyString(), anyBoolean()); + mListener.onTestEnd(mDataRecord, mTest1Desc); + verify(mPerfettoHelper, times(1)).stopCollecting(anyLong(), anyString()); + + } + } diff --git a/libraries/health/rules/src/android/platform/test/rule/UnlockScreenRule.java b/libraries/health/rules/src/android/platform/test/rule/UnlockScreenRule.java new file mode 100644 index 000000000..a1ca34ac5 --- /dev/null +++ b/libraries/health/rules/src/android/platform/test/rule/UnlockScreenRule.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019 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.platform.test.rule; + +import android.os.RemoteException; +import android.support.test.uiautomator.By; +import android.support.test.uiautomator.BySelector; + +import org.junit.runner.Description; + +/** This rule will unlock phone screen before a test case. */ +public class UnlockScreenRule extends TestWatcher { + + protected static final BySelector SCREEN_LOCK = + By.res("com.android.systemui", "keyguard_bottom_area"); + + @Override + protected void starting(Description description) { + try { + // Turn on the screen if necessary. + if (!getUiDevice().isScreenOn()) { + getUiDevice().wakeUp(); + } + if (getUiDevice().hasObject(SCREEN_LOCK)) { + getUiDevice().pressMenu(); + getUiDevice().waitForIdle(); + } + } catch (RemoteException e) { + throw new RuntimeException("Could not unlock device.", e); + } + } +} diff --git a/libraries/health/rules/tests/src/android/platform/test/rule/UnlockScreenRuleTest.java b/libraries/health/rules/tests/src/android/platform/test/rule/UnlockScreenRuleTest.java new file mode 100644 index 000000000..475e43f14 --- /dev/null +++ b/libraries/health/rules/tests/src/android/platform/test/rule/UnlockScreenRuleTest.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2018 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.platform.test.rule; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.os.RemoteException; +import android.support.test.uiautomator.UiDevice; + +import org.junit.Test; +import org.junit.runner.Description; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.junit.runners.model.Statement; + +import org.mockito.Mockito; + +/** Unit test the logic for {@link UnlockScreenRule} */ +@RunWith(JUnit4.class) +public class UnlockScreenRuleTest { + + /** Tests that unlock a screen off and locked phone before the test. */ + @Test + public void testScreenOff() throws Throwable { + TestableUnlockScreenRule rule = new TestableUnlockScreenRule(false, false); + Statement testStatement = + new Statement() { + @Override + public void evaluate() throws Throwable { + // Assert that the device wake up and unlock screen. + verify(rule.getUiDevice(), times(1)).wakeUp(); + verify(rule.getUiDevice(), times(1)).pressMenu(); + } + }; + rule.apply(testStatement, Description.createTestDescription("clzz", "mthd")).evaluate(); + } + + /** Tests that unlock a screen on but locked phone before the test. */ + @Test + public void testScreenLocked() throws Throwable { + TestableUnlockScreenRule rule = new TestableUnlockScreenRule(true, false); + Statement testStatement = + new Statement() { + @Override + public void evaluate() throws Throwable { + // Assert that the device has unlocked screen. + verify(rule.getUiDevice(), times(0)).wakeUp(); + verify(rule.getUiDevice(), times(1)).pressMenu(); + } + }; + rule.apply(testStatement, Description.createTestDescription("clzz", "mthd")).evaluate(); + } + + /** Tests that unlock a phone which is already screen on before the test. */ + @Test + public void testScreenOn() throws Throwable { + TestableUnlockScreenRule rule = new TestableUnlockScreenRule(true, true); + Statement testStatement = + new Statement() { + @Override + public void evaluate() throws Throwable { + // Assert that the device did nothing. + verify(rule.getUiDevice(), times(0)).wakeUp(); + verify(rule.getUiDevice(), times(0)).pressMenu(); + } + }; + rule.apply(testStatement, Description.createTestDescription("clzz", "mthd")).evaluate(); + } + + private static class TestableUnlockScreenRule extends UnlockScreenRule { + private UiDevice mUiDevice; + private boolean mIsScreenOn; + private boolean mIsUnlocked; + + public TestableUnlockScreenRule(boolean isScreenOn, boolean isUnlocked) { + mUiDevice = Mockito.mock(UiDevice.class); + mIsScreenOn = isScreenOn; + mIsUnlocked = isUnlocked; + } + + @Override + protected UiDevice getUiDevice() { + try { + when(mUiDevice.isScreenOn()).thenReturn(mIsScreenOn); + when(mUiDevice.hasObject(SCREEN_LOCK)).thenReturn(!mIsUnlocked); + } catch (RemoteException e) { + throw new RuntimeException("Could not unlock device.", e); + } + return mUiDevice; + } + } +} diff --git a/tests/microbenchmarks/uibench/Android.bp b/tests/microbenchmarks/uibench/Android.bp new file mode 100644 index 000000000..4e61679dc --- /dev/null +++ b/tests/microbenchmarks/uibench/Android.bp @@ -0,0 +1,32 @@ +// Copyright 2019 Google Inc. All Rights Reserved. +// +// 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. + +android_test { + name: "UiBenchMicrobenchmark", + srcs: ["src/**/*.java"], + + static_libs: [ + "collector-device-lib", + "ub-uiautomator", + "junit", + "microbenchmark-device-lib", + "launcher-helper-lib", + ], + + libs: ["android.test.base.stubs"], + + sdk_version: "test_current", + + test_suites: ["device-tests"], +} diff --git a/tests/microbenchmarks/uibench/AndroidManifest.xml b/tests/microbenchmarks/uibench/AndroidManifest.xml new file mode 100644 index 000000000..5243c9684 --- /dev/null +++ b/tests/microbenchmarks/uibench/AndroidManifest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2019 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="com.android.uibench.microbenchmark"> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation + android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="com.android.uibench.microbenchmark" + android:label="Platform UiBench Scenario-Based microbenchmark Tests" /> +</manifest> diff --git a/tests/microbenchmarks/uibench/AndroidTest.xml b/tests/microbenchmarks/uibench/AndroidTest.xml new file mode 100644 index 000000000..5021fff5a --- /dev/null +++ b/tests/microbenchmarks/uibench/AndroidTest.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2019 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. +--> +<configuration description="Runs Platform UiBench Microbenchmark Tests."> + + <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/> + <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> + <option name="push-file" key="trace_config_detailed.textproto" value="/data/misc/perfetto-traces/trace_config.textproto" /> + </target_preparer> + + <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup"> + <option name="test-file-name" value="UiBenchMicrobenchmark.apk" /> + <option name="test-file-name" value="UiBench.apk" /> + </target_preparer> + + <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector"> + <option name="pull-pattern-keys" value="perfetto_file_path" /> + </metrics_collector> + + <option name="post-boot-command" value="am broadcast -a com.google.android.clockwork.action.TEST_MODE" /> + <option name="post-boot-command" value="setprop debug.hwui.filter_test_overhead true" /> + <option name="post-boot-command" value="settings put secure accessibility_disable_animations 0" /> + + <option name="test-tag" value="UiBenchMicrobenchmarks" /> + + <test class="com.android.tradefed.testtype.AndroidJUnitTest" > + <option name="package" value="com.android.uibench.microbenchmark" /> + <option name="class" value="com.android.uibench.microbenchmark.UiBenchDialogListFlingMicrobenchmark#testDialogListFling" /> + <option name="device-listeners" value="android.device.collectors.PerfettoListener" /> + <option name="instrumentation-arg" key="per_run" value="true" /> + <option name="instrumentation-arg" key="perfetto_config_text_proto" value="true" /> + <option name="instrumentation-arg" key="perfetto_config_file" value="trace_config.textproto" /> + <option name="instrumentation-arg" key="newRunListenerMode" value="true" /> + </test> + +</configuration> diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/IUiBenchJankHelper.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/IUiBenchJankHelper.java new file mode 100644 index 000000000..ee0ea3205 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/IUiBenchJankHelper.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.IAppHelper; + +public interface IUiBenchJankHelper extends IAppHelper { + void clickImage(String imageName); + + void flingDownUp(int flingCount); + + void flingUpDown(int flingCount); + + void openActivityTransition(); + + void openBitmapUpload(); + + void openClippedListView(); + + void openDialogList(); + + void openEditTextTyping(); + + void openFadingEdgeListView(); + + void openFullscreenOverdraw(); + + void openGLTextureView(); + + void openInflatingEmojiListView(); + + void openInflatingHanListView(); + + void openInflatingListView(); + + void openInflatingLongStringListView(); + + void openInvalidate(); + + void openInvalidateTree(); + + void openLayoutCacheHighHitrate(); + + void openLayoutCacheLowHitrate(); + + void openLeanbackActivity( + boolean extraBitmapUpload, + boolean extraShowFastLane, + String activityName, + String expectedText); + + void openNavigationDrawerActivity(); + + void openNotificationShade(); + + void openSaveLayerInterleaveActivity(); + + void openScrollableWebView(); + + void openSlowBindRecyclerView(); + + void openSlowNestedRecyclerView(); + + void openTrivialAnimation(); + + void openTrivialListView(); + + void openTrivialRecyclerView(); + + void openRenderingList(); + + void openResizeHWLayer(); + + void scrollDownAndUp(int count); + + void slowSingleFlingDown(); + + void swipeRightLeft(int swipeCount); +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchActivityTransitionsAnimationMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchActivityTransitionsAnimationMicrobenchmark.java new file mode 100644 index 000000000..03106d2b1 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchActivityTransitionsAnimationMicrobenchmark.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchActivityTransitionsAnimationMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openActivityTransition(); + } + + // Measures jank for activity transition animation + @Test + public void testActivityTransitionsAnimation() { + sHelper.get().clickImage("ducky"); + sHelper.get().clickImage("woot"); + sHelper.get().clickImage("ball"); + sHelper.get().clickImage("block"); + sHelper.get().clickImage("jellies"); + sHelper.get().clickImage("mug"); + sHelper.get().clickImage("pencil"); + sHelper.get().clickImage("scissors"); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBitmapUploadJankMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBitmapUploadJankMicrobenchmark.java new file mode 100644 index 000000000..19cfcf9d9 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBitmapUploadJankMicrobenchmark.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchBitmapUploadJankMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openBitmapUpload(); + } + + // Test Bitmap Upload jank + @Test + public void testBitmapUploadJank() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseContentScrollMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseContentScrollMicrobenchmark.java new file mode 100644 index 000000000..489dbe7da --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseContentScrollMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchBrowseContentScrollMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openLeanbackActivity(true, false, "leanback.BrowseActivity", "Row"); + } + + @Test + public void testBrowseContentScroll() { + sHelper.get().scrollDownAndUp(3); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseContentScrollNoBitmapUploadMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseContentScrollNoBitmapUploadMicrobenchmark.java new file mode 100644 index 000000000..c71fa2738 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseContentScrollNoBitmapUploadMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchBrowseContentScrollNoBitmapUploadMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openLeanbackActivity(false, false, "leanback.BrowseActivity", "Row"); + } + + @Test + public void testBrowseContentScrollNoBitmapUpload() { + sHelper.get().scrollDownAndUp(3); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseFastLaneScrollMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseFastLaneScrollMicrobenchmark.java new file mode 100644 index 000000000..3ac0dc2f0 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseFastLaneScrollMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchBrowseFastLaneScrollMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openLeanbackActivity(true, true, "leanback.BrowseActivity", "Row"); + } + + /** Vertically scroll BrowseFragment in the fast lane */ + @Test + public void testBrowseFastLaneScroll() { + sHelper.get().scrollDownAndUp(3); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseFastLaneScrollNoBitmapUploadMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseFastLaneScrollNoBitmapUploadMicrobenchmark.java new file mode 100644 index 000000000..d2d7b35c4 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchBrowseFastLaneScrollNoBitmapUploadMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchBrowseFastLaneScrollNoBitmapUploadMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openLeanbackActivity(false, true, "leanback.BrowseActivity", "Row"); + } + + @Test + public void testBrowseFastLaneScrollNoBitmapUpload() { + sHelper.get().scrollDownAndUp(3); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchClippedListViewMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchClippedListViewMicrobenchmark.java new file mode 100644 index 000000000..79752c50d --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchClippedListViewMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchClippedListViewMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openClippedListView(); + } + + @Test + public void testClippedListView() { + sHelper.get().swipeRightLeft(4); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchDialogListFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchDialogListFlingMicrobenchmark.java new file mode 100644 index 000000000..e65186f23 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchDialogListFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchDialogListFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openDialogList(); + } + + @Test + public void testDialogListFling() { + sHelper.get().flingUpDown(1); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchEditTextTypingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchEditTextTypingMicrobenchmark.java new file mode 100644 index 000000000..9e148b2d0 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchEditTextTypingMicrobenchmark.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchEditTextTypingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openEditTextTyping(); + } + + // Measure jank metrics for EditText Typing + // Note: Disable/comment the test if it is flaky (see b/62917134). + @Test + public void testEditTextTyping() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchFadingEdgeListViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchFadingEdgeListViewFlingMicrobenchmark.java new file mode 100644 index 000000000..212ef782d --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchFadingEdgeListViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchFadingEdgeListViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openFadingEdgeListView(); + } + + @Test + public void testFadingEdgeListViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchFullscreenOverdrawMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchFullscreenOverdrawMicrobenchmark.java new file mode 100644 index 000000000..9c51488a2 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchFullscreenOverdrawMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchFullscreenOverdrawMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openFullscreenOverdraw(); + } + + @Test + public void testFullscreenOverdraw() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchGLTextureViewMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchGLTextureViewMicrobenchmark.java new file mode 100644 index 000000000..1c5543843 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchGLTextureViewMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchGLTextureViewMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openGLTextureView(); + } + + @Test + public void testGLTextureView() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingEmojiListViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingEmojiListViewFlingMicrobenchmark.java new file mode 100644 index 000000000..2faead6c7 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingEmojiListViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchInflatingEmojiListViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openInflatingEmojiListView(); + } + + @Test + public void testInflatingEmojiListViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingHanListViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingHanListViewFlingMicrobenchmark.java new file mode 100644 index 000000000..0fea51348 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingHanListViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchInflatingHanListViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openInflatingHanListView(); + } + + @Test + public void testInflatingHanListViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingListViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingListViewFlingMicrobenchmark.java new file mode 100644 index 000000000..8ba892109 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingListViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchInflatingListViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openInflatingListView(); + } + + @Test + public void testInflatingListViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingLongStringListViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingLongStringListViewFlingMicrobenchmark.java new file mode 100644 index 000000000..27ae7ce57 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInflatingLongStringListViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchInflatingLongStringListViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openInflatingLongStringListView(); + } + + @Test + public void testInflatingLongStringListViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInvalidateMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInvalidateMicrobenchmark.java new file mode 100644 index 000000000..1d28e5267 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInvalidateMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchInvalidateMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openInvalidate(); + } + + @Test + public void testInvalidate() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInvalidateTreeMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInvalidateTreeMicrobenchmark.java new file mode 100644 index 000000000..2f333ef1e --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchInvalidateTreeMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchInvalidateTreeMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openInvalidateTree(); + } + + @Test + public void testInvalidateTree() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchJankHelper.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchJankHelper.java new file mode 100644 index 000000000..3180d6ddf --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchJankHelper.java @@ -0,0 +1,344 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.app.Instrumentation; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.SystemClock; +import android.platform.helpers.AbstractStandardAppHelper; +import android.support.test.uiautomator.By; +import android.support.test.uiautomator.Direction; +import android.support.test.uiautomator.UiObject2; +import android.support.test.uiautomator.Until; +import android.util.DisplayMetrics; +import android.view.KeyEvent; +import android.widget.ListView; + +import junit.framework.Assert; + +public class UiBenchJankHelper extends AbstractStandardAppHelper implements IUiBenchJankHelper { + public static final int LONG_TIMEOUT = 5000; + public static final int FULL_TEST_DURATION = 25000; + public static final int FIND_OBJECT_TIMEOUT = 250; + public static final int SHORT_TIMEOUT = 2000; + public static final int EXPECTED_FRAMES = 100; + public static final int KEY_DELAY = 1000; + public static final String EXTRA_BITMAP_UPLOAD = "extra_bitmap_upload"; + public static final String EXTRA_SHOW_FAST_LANE = "extra_show_fast_lane"; + + /** + * Only to be used for initial-fling tests, or similar cases where perf during brief experience + * is important. + */ + public static final int SHORT_EXPECTED_FRAMES = 30; + + public static final String PACKAGE_NAME = "com.android.test.uibench"; + + public static final String APP_LAUNCHER_NAME = "UiBench"; + + private static final int SLOW_FLING_SPEED = 3000; // compare to UiObject2#DEFAULT_FLING_SPEED + + // Main UiObject2 exercised by the test. + private UiObject2 mContents; + + public UiBenchJankHelper(Instrumentation instr) { + super(instr); + } + + /** {@inheritDoc} */ + @Override + public String getPackage() { + return PACKAGE_NAME; + } + + /** {@inheritDoc} */ + @Override + public String getLauncherName() { + return APP_LAUNCHER_NAME; + } + + /** {@inheritDoc} */ + @Override + public void dismissInitialDialogs() {} + + /** Launch activity using intent */ + void launchActivity(String activityName, Bundle extras, String verifyText) { + ComponentName cn = + new ComponentName(PACKAGE_NAME, String.format("%s.%s", PACKAGE_NAME, activityName)); + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + if (extras != null) { + intent.putExtras(extras); + } + intent.setComponent(cn); + // Launch the activity + mInstrumentation.getContext().startActivity(intent); + UiObject2 expectedTextCmp = + mDevice.wait(Until.findObject(By.text(verifyText)), LONG_TIMEOUT); + Assert.assertNotNull(String.format("Issue in opening %s", activityName), expectedTextCmp); + } + + void launchActivity(String activityName, String verifyText) { + launchActivity(activityName, null, verifyText); + } + + void launchActivityAndAssert(String activityName, String verifyText) { + launchActivity(activityName, verifyText); + mContents = + mDevice.wait(Until.findObject(By.res("android", "content")), FIND_OBJECT_TIMEOUT); + Assert.assertNotNull(activityName + " isn't found", mContents); + } + + /** To perform the fling down and up on given content for flingCount number of times */ + @Override + public void flingUpDown(int flingCount) { + flingUpDown(flingCount, false); + } + + @Override + public void flingDownUp(int flingCount) { + flingUpDown(flingCount, true); + } + + void flingUpDown(int flingCount, boolean reverse) { + for (int count = 0; count < flingCount; count++) { + SystemClock.sleep(SHORT_TIMEOUT); + mContents.fling(reverse ? Direction.UP : Direction.DOWN); + SystemClock.sleep(SHORT_TIMEOUT); + mContents.fling(reverse ? Direction.DOWN : Direction.UP); + } + } + + /** To perform the swipe right and left on given content for swipeCount number of times */ + @Override + public void swipeRightLeft(int swipeCount) { + for (int count = 0; count < swipeCount; count++) { + SystemClock.sleep(SHORT_TIMEOUT); + mContents.swipe(Direction.RIGHT, 1); + SystemClock.sleep(SHORT_TIMEOUT); + mContents.swipe(Direction.LEFT, 1); + } + } + + @Override + public void slowSingleFlingDown() { + SystemClock.sleep(SHORT_TIMEOUT); + Context context = mInstrumentation.getContext(); + DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); + mContents.fling(Direction.DOWN, (int) (SLOW_FLING_SPEED * displayMetrics.density)); + mDevice.waitForIdle(); + } + + @Override + public void openDialogList() { + launchActivity("DialogListActivity", "Dialog"); + mContents = mDevice.wait(Until.findObject(By.clazz(ListView.class)), FIND_OBJECT_TIMEOUT); + Assert.assertNotNull("Dialog List View isn't found", mContents); + } + + @Override + public void openFullscreenOverdraw() { + launchActivity("FullscreenOverdrawActivity", "General/Fullscreen Overdraw"); + } + + @Override + public void openGLTextureView() { + launchActivity("GlTextureViewActivity", "General/GL TextureView"); + } + + @Override + public void openInvalidate() { + launchActivity("InvalidateActivity", "General/Invalidate"); + } + + @Override + public void openInvalidateTree() { + launchActivity("InvalidateTreeActivity", "General/Invalidate Tree"); + } + + @Override + public void openTrivialAnimation() { + launchActivity("TrivialAnimationActivity", "General/Trivial Animation"); + } + + @Override + public void openTrivialListView() { + launchActivityAndAssert("TrivialListActivity", "General/Trivial ListView"); + } + + @Override + public void openFadingEdgeListView() { + launchActivityAndAssert("FadingEdgeListActivity", "General/Fading Edge ListView"); + } + + @Override + public void openSaveLayerInterleaveActivity() { + launchActivityAndAssert("SaveLayerInterleaveActivity", "General/SaveLayer Animation"); + } + + @Override + public void openTrivialRecyclerView() { + launchActivityAndAssert("TrivialRecyclerViewActivity", "General/Trivial RecyclerView"); + } + + @Override + public void openSlowBindRecyclerView() { + launchActivityAndAssert("SlowBindRecyclerViewActivity", "General/Slow Bind RecyclerView"); + } + + @Override + public void openSlowNestedRecyclerView() { + launchActivityAndAssert( + "SlowNestedRecyclerViewActivity", "General/Slow Nested RecyclerView"); + } + + @Override + public void openInflatingListView() { + launchActivityAndAssert("InflatingListActivity", "Inflation/Inflating ListView"); + } + + @Override + public void openInflatingEmojiListView() { + launchActivityAndAssert( + "InflatingEmojiListActivity", "Inflation/Inflating ListView with Emoji"); + } + + @Override + public void openInflatingHanListView() { + launchActivityAndAssert( + "InflatingHanListActivity", "Inflation/Inflating ListView with Han Characters"); + } + + @Override + public void openInflatingLongStringListView() { + launchActivityAndAssert( + "InflatingLongStringListActivity", "Inflation/Inflating ListView with long string"); + } + + @Override + public void openNavigationDrawerActivity() { + launchActivityAndAssert("NavigationDrawerActivity", "Navigation Drawer Activity"); + mContents.setGestureMargins(0, 0, 10, 0); + } + + @Override + public void openNotificationShade() { + launchActivityAndAssert("NotificationShadeActivity", "Notification Shade"); + } + + @Override + public void openResizeHWLayer() { + launchActivity("ResizeHWLayerActivity", "General/Resize HW Layer"); + } + + @Override + public void openClippedListView() { + launchActivityAndAssert("ClippedListActivity", "General/Clipped ListView"); + } + + @Override + public void openLeanbackActivity( + boolean extraBitmapUpload, + boolean extraShowFastLane, + String activityName, + String expectedText) { + Bundle extrasBundle = new Bundle(); + extrasBundle.putBoolean(EXTRA_BITMAP_UPLOAD, extraBitmapUpload); + extrasBundle.putBoolean(EXTRA_SHOW_FAST_LANE, extraShowFastLane); + launchActivity(activityName, extrasBundle, expectedText); + } + + void pressKeyCode(int keyCode) { + SystemClock.sleep(KEY_DELAY); + mDevice.pressKeyCode(keyCode); + } + + @Override + public void scrollDownAndUp(int count) { + for (int i = 0; i < count; i++) { + pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN); + } + for (int i = 0; i < count; i++) { + pressKeyCode(KeyEvent.KEYCODE_DPAD_UP); + } + } + + // Open Bitmap Upload + @Override + public void openBitmapUpload() { + launchActivity("BitmapUploadActivity", "Rendering/Bitmap Upload"); + } + + // Open Shadow Grid + @Override + public void openRenderingList() { + launchActivity("ShadowGridActivity", "Rendering/Shadow Grid"); + mContents = mDevice.wait(Until.findObject(By.clazz(ListView.class)), FIND_OBJECT_TIMEOUT); + Assert.assertNotNull("Shadow Grid list isn't found", mContents); + } + + // Open EditText Typing + @Override + public void openEditTextTyping() { + launchActivity("EditTextTypeActivity", "Text/EditText Typing"); + } + + // Open Layout Cache High Hitrate + @Override + public void openLayoutCacheHighHitrate() { + launchActivity("TextCacheHighHitrateActivity", "Text/Layout Cache High Hitrate"); + mContents = mDevice.wait(Until.findObject(By.clazz(ListView.class)), FIND_OBJECT_TIMEOUT); + Assert.assertNotNull("LayoutCacheHighHitrateContents isn't found", mContents); + } + + // Open Layout Cache Low Hitrate + @Override + public void openLayoutCacheLowHitrate() { + launchActivity("TextCacheLowHitrateActivity", "Text/Layout Cache Low Hitrate"); + mContents = mDevice.wait(Until.findObject(By.clazz(ListView.class)), FIND_OBJECT_TIMEOUT); + Assert.assertNotNull("LayoutCacheLowHitrateContents isn't found", mContents); + } + + // Open Transitions + @Override + public void openActivityTransition() { + launchActivity("ActivityTransition", "Transitions/Activity Transition"); + } + + // Get the image to click + @Override + public void clickImage(String imageName) { + UiObject2 image = + mDevice.wait( + Until.findObject(By.res(PACKAGE_NAME, imageName)), FIND_OBJECT_TIMEOUT); + Assert.assertNotNull(imageName + "Image not found", image); + image.clickAndWait(Until.newWindow(), FIND_OBJECT_TIMEOUT); + mDevice.pressBack(); + } + + // Open Scrollable WebView from WebView test + @Override + public void openScrollableWebView() { + launchActivity("ScrollableWebViewActivity", "WebView/Scrollable WebView"); + mContents = + mDevice.wait(Until.findObject(By.res("android", "content")), FIND_OBJECT_TIMEOUT); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchLayoutCacheHighHitrateFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchLayoutCacheHighHitrateFlingMicrobenchmark.java new file mode 100644 index 000000000..5314b82ac --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchLayoutCacheHighHitrateFlingMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchLayoutCacheHighHitrateFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openLayoutCacheHighHitrate(); + } + + // Test Layout Cache High Hitrate fling + @Test + public void testLayoutCacheHighHitrateFling() { + sHelper.get().flingUpDown(3); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchLayoutCacheLowHitrateFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchLayoutCacheLowHitrateFlingMicrobenchmark.java new file mode 100644 index 000000000..37ca6dc65 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchLayoutCacheLowHitrateFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchLayoutCacheLowHitrateFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openLayoutCacheLowHitrate(); + } + + @Test + public void testLayoutCacheLowHitrateFling() { + sHelper.get().flingUpDown(3); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchOpenNavigationDrawerMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchOpenNavigationDrawerMicrobenchmark.java new file mode 100644 index 000000000..a1ed02f5b --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchOpenNavigationDrawerMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchOpenNavigationDrawerMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openNavigationDrawerActivity(); + } + + @Test + public void testOpenNavigationDrawer() { + sHelper.get().swipeRightLeft(4); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchOpenNotificationShadeMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchOpenNotificationShadeMicrobenchmark.java new file mode 100644 index 000000000..b5f5cf6f7 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchOpenNotificationShadeMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchOpenNotificationShadeMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openNotificationShade(); + } + + @Test + public void testOpenNotificationShade() { + sHelper.get().flingDownUp(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchResizeHWLayerMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchResizeHWLayerMicrobenchmark.java new file mode 100644 index 000000000..8405d8d99 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchResizeHWLayerMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchResizeHWLayerMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openResizeHWLayer(); + } + + @Test + public void testResizeHWLayer() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSaveLayerAnimationMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSaveLayerAnimationMicrobenchmark.java new file mode 100644 index 000000000..e723c4b27 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSaveLayerAnimationMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchSaveLayerAnimationMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openSaveLayerInterleaveActivity(); + } + + @Test + public void testSaveLayerAnimation() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchShadowGridListFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchShadowGridListFlingMicrobenchmark.java new file mode 100644 index 000000000..e7bd447ab --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchShadowGridListFlingMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchShadowGridListFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openRenderingList(); + } + + // Test Shadow Grid fling + @Test + public void testShadowGridListFling() { + sHelper.get().flingUpDown(1); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowBindRecyclerViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowBindRecyclerViewFlingMicrobenchmark.java new file mode 100644 index 000000000..0869bec8e --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowBindRecyclerViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchSlowBindRecyclerViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openSlowBindRecyclerView(); + } + + @Test + public void testSlowBindRecyclerViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowNestedRecyclerViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowNestedRecyclerViewFlingMicrobenchmark.java new file mode 100644 index 000000000..622248856 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowNestedRecyclerViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchSlowNestedRecyclerViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openSlowNestedRecyclerView(); + } + + @Test + public void testSlowNestedRecyclerViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowNestedRecyclerViewInitialFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowNestedRecyclerViewInitialFlingMicrobenchmark.java new file mode 100644 index 000000000..1d9f82cce --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchSlowNestedRecyclerViewInitialFlingMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchSlowNestedRecyclerViewInitialFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openSlowNestedRecyclerView(); + } + + @Test + public void testSlowNestedRecyclerViewInitialFling() { + /* NOTE: relaunch between loops */ + sHelper.get().slowSingleFlingDown(); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialAnimationMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialAnimationMicrobenchmark.java new file mode 100644 index 000000000..35c8e9479 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialAnimationMicrobenchmark.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.os.SystemClock; +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchTrivialAnimationMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openTrivialAnimation(); + } + + @Test + public void testTrivialAnimation() { + SystemClock.sleep(UiBenchJankHelper.FULL_TEST_DURATION); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialListViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialListViewFlingMicrobenchmark.java new file mode 100644 index 000000000..63dcde396 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialListViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchTrivialListViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openTrivialListView(); + } + + @Test + public void testTrivialListViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialRecyclerListViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialRecyclerListViewFlingMicrobenchmark.java new file mode 100644 index 000000000..ff0969366 --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchTrivialRecyclerListViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchTrivialRecyclerListViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openTrivialRecyclerView(); + } + + @Test + public void testTrivialRecyclerListViewFling() { + sHelper.get().flingUpDown(2); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} diff --git a/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchWebViewFlingMicrobenchmark.java b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchWebViewFlingMicrobenchmark.java new file mode 100644 index 000000000..8744e3b5a --- /dev/null +++ b/tests/microbenchmarks/uibench/src/com/android/uibench/microbenchmark/UiBenchWebViewFlingMicrobenchmark.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 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.uibench.microbenchmark; + +import android.platform.helpers.HelperAccessor; +import android.platform.test.microbenchmark.Microbenchmark; +import android.platform.test.rule.NaturalOrientationRule; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Microbenchmark.class) +public class UiBenchWebViewFlingMicrobenchmark { + @ClassRule public static NaturalOrientationRule orientationRule = new NaturalOrientationRule(); + + private static HelperAccessor<IUiBenchJankHelper> sHelper = + new HelperAccessor<>(IUiBenchJankHelper.class); + + @BeforeClass + public static void openApp() { + sHelper.get().openScrollableWebView(); + } + + @Test + public void testWebViewFling() { + sHelper.get().flingUpDown(1); + } + + @AfterClass + public static void closeApp() { + sHelper.get().exit(); + } +} |