From cdecb319ec73675cad72fb4977188ec70ca8adf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Mendes=20Freire?= Date: Thu, 5 Jan 2023 16:44:34 +0000 Subject: [PATCH] Add new version of stopUser performance test Similar to what was done for switchUser, this commit adds a new version of the stopUser test. In this variation, a single user is created per test run (instead of one per iteration of the run) and a wait for cool down was added in between iterations. Bug: 261621873 Test: atest UserLifecycleTests#stopUser_realistic Change-Id: Ief41deeea82392e6d44ff5520acffebfcc53f69d --- .../android/multiuser/UserLifecycleTests.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java index 3f9b54cb8578a..acb8a5f634e36 100644 --- a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java +++ b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java @@ -397,6 +397,32 @@ public class UserLifecycleTests { } } + /** Tests stopping a background user, with wait times between iterations. The hypothesis is + * that the effects of the user creation could impact the measured times, so in this variant we + * create one user per run, instead of one per iteration */ + @Test(timeout = TIMEOUT_MAX_TEST_TIME_MS) + public void stopUser_realistic() throws RemoteException { + final int userId = createUserNoFlags(); + waitCoolDownPeriod(); + while (mRunner.keepRunning()) { + mRunner.pauseTiming(); + runThenWaitForBroadcasts(userId, ()-> { + mIam.startUserInBackground(userId); + }, Intent.ACTION_USER_STARTED, Intent.ACTION_MEDIA_MOUNTED); + waitCoolDownPeriod(); + Log.d(TAG, "Starting timer"); + mRunner.resumeTiming(); + + stopUser(userId, false); + + mRunner.pauseTiming(); + Log.d(TAG, "Stopping timer"); + + mRunner.resumeTimingForNextIteration(); + } + removeUser(userId); + } + /** Tests reaching LOOKED_BOOT_COMPLETE when switching to uninitialized user. */ @Test(timeout = TIMEOUT_MAX_TEST_TIME_MS) public void lockedBootCompleted() throws RemoteException {