Settings performance testing

1. Add storage page as test target.
2. Set screen timeout to 2 hours to avoid screen timeout during testing.
3. Force close settings before launching each page.
4. Reset screen timeout after testing.
5. Increase test times from 10 to 100.

Test: atest SettingsPerfTests:LaunchSettingsTest
Change-Id: I52c4f15e47a2a83219212de1262a13b3b196c21c
This commit is contained in:
youtengliang
2020-05-08 11:13:04 +08:00
parent a502c55a5c
commit 9de3878944

View File

@@ -56,8 +56,10 @@ public class LaunchSettingsTest {
} }
} }
private static final String SCREEN_TIME_OUT = "7200000";
private static final String DEFAULT_SCREEN_TIMEOUT = "15000";
private static final int TIME_OUT = 5000; private static final int TIME_OUT = 5000;
private static final int TEST_TIME = 10; private static final int TEST_TIME = 100;
private static final Pattern PATTERN = Pattern.compile("TotalTime:\\s[0-9]*"); private static final Pattern PATTERN = Pattern.compile("TotalTime:\\s[0-9]*");
private static final Page[] PAGES; private static final Page[] PAGES;
@@ -67,7 +69,8 @@ public class LaunchSettingsTest {
new Page("android.settings.WIFI_SETTINGS", "Use WiFi", "Wi-Fi"), new Page("android.settings.WIFI_SETTINGS", "Use WiFi", "Wi-Fi"),
new Page("android.settings.BLUETOOTH_SETTINGS", "Connected devices", "BlueTooth"), new Page("android.settings.BLUETOOTH_SETTINGS", "Connected devices", "BlueTooth"),
new Page("android.settings.APPLICATION_SETTINGS", "App info", "Application"), new Page("android.settings.APPLICATION_SETTINGS", "App info", "Application"),
new Page("android.intent.action.POWER_USAGE_SUMMARY", "Battery", "Battery") new Page("android.intent.action.POWER_USAGE_SUMMARY", "Battery", "Battery"),
new Page("android.settings.INTERNAL_STORAGE_SETTINGS", "Storage", "Storage")
}; };
} }
@@ -75,6 +78,7 @@ public class LaunchSettingsTest {
private UiDevice mDevice; private UiDevice mDevice;
private Instrumentation mInstrumentation; private Instrumentation mInstrumentation;
private Map<String, ArrayList<Integer>> mResult; private Map<String, ArrayList<Integer>> mResult;
private String mDefaultScreenTimeout;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@@ -82,6 +86,9 @@ public class LaunchSettingsTest {
mDevice = UiDevice.getInstance(getInstrumentation()); mDevice = UiDevice.getInstance(getInstrumentation());
mInstrumentation = InstrumentationRegistry.getInstrumentation(); mInstrumentation = InstrumentationRegistry.getInstrumentation();
mResult = new LinkedHashMap<>(); mResult = new LinkedHashMap<>();
mDefaultScreenTimeout = mDevice.executeShellCommand(
"settings get system screen_off_timeout");
setScreenTimeOut(SCREEN_TIME_OUT);
mDevice.pressHome(); mDevice.pressHome();
mDevice.waitForIdle(TIME_OUT); mDevice.waitForIdle(TIME_OUT);
@@ -94,6 +101,8 @@ public class LaunchSettingsTest {
public void tearDown() throws Exception { public void tearDown() throws Exception {
putResultToBundle(); putResultToBundle();
mInstrumentation.sendStatus(0, mBundle); mInstrumentation.sendStatus(0, mBundle);
resetScreenTimeout();
closeApp();
} }
@Test @Test
@@ -107,11 +116,11 @@ public class LaunchSettingsTest {
private void executePreformanceTest(String action, String displayName, String title) private void executePreformanceTest(String action, String displayName, String title)
throws Exception { throws Exception {
closeApp();
mDevice.waitForIdle(TIME_OUT);
final String mString = mDevice.executeShellCommand("am start -W -a" + action); final String mString = mDevice.executeShellCommand("am start -W -a" + action);
mDevice.wait(Until.findObject(By.text(displayName)), TIME_OUT); mDevice.wait(Until.findObject(By.text(displayName)), TIME_OUT);
handleLaunchResult(title, mString); handleLaunchResult(title, mString);
closeApp();
mDevice.waitForIdle(TIME_OUT);
} }
private void handleLaunchResult(String title, String s) { private void handleLaunchResult(String title, String s) {
@@ -150,4 +159,16 @@ public class LaunchSettingsTest {
private String getAvg(ArrayList<Integer> launchResult) { private String getAvg(ArrayList<Integer> launchResult) {
return String.valueOf((int) launchResult.stream().mapToInt(i -> i).average().orElse(0)); return String.valueOf((int) launchResult.stream().mapToInt(i -> i).average().orElse(0));
} }
private void setScreenTimeOut(String timeout) throws Exception {
mDevice.executeShellCommand("settings put system screen_off_timeout " + timeout);
}
private void resetScreenTimeout() throws Exception {
String timeout = DEFAULT_SCREEN_TIMEOUT;
if (!mDefaultScreenTimeout.isEmpty()) {
timeout = mDefaultScreenTimeout;
}
setScreenTimeOut(timeout);
}
} }