[automerger skipped] Merge Android 24Q2 Release (ab/11526283) to aosp-main-future am: de7f22609c -s ours
am skip reason: Merged-In I4fade3c5f344cd7942273606986a3b43882e5441 with SHA-1 0d22a4544d is already in history
Original change: https://googleplex-android-review.googlesource.com/c/platform/test/catbox/+/27270748
Change-Id: I647e0b3e02dddcc9842fbbfe342a510635fb75e7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/target_preparers/src/com/android/catbox/targetpreparer/LowPerformanceTargetPreparer.java b/target_preparers/src/com/android/catbox/targetpreparer/LowPerformanceTargetPreparer.java
new file mode 100644
index 0000000..17a24ab
--- /dev/null
+++ b/target_preparers/src/com/android/catbox/targetpreparer/LowPerformanceTargetPreparer.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2024 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.catbox.targetpreparer;
+
+import com.android.tradefed.config.Option;
+import com.android.tradefed.config.OptionClass;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.invoker.TestInformation;
+import com.android.tradefed.log.LogUtil;
+import com.android.tradefed.result.error.InfraErrorIdentifier;
+import com.android.tradefed.targetprep.BaseTargetPreparer;
+import com.android.tradefed.targetprep.BuildError;
+import com.android.tradefed.targetprep.TargetSetupError;
+import com.android.tradefed.util.CommandResult;
+
+import java.util.Objects;
+
+/**
+ * Sets the device into a low performance state for the test duration
+ */
+@OptionClass(alias = "low-performance")
+public class LowPerformanceTargetPreparer extends BaseTargetPreparer {
+ /**
+ * An object containing strings with device info data
+ */
+ private static class OemDeviceInfo {
+ private final String mNrCpus;
+ private final String mMem;
+
+ public OemDeviceInfo(String nrCpus, String mem) {
+ mNrCpus = nrCpus;
+ mMem = mem;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof OemDeviceInfo o) {
+ return o.mMem.equals(this.mMem) && o.mNrCpus.equals(this.mNrCpus);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mNrCpus, mMem);
+ }
+ }
+
+ @Option(name = "nr-cpus", description = "Limit number of cores")
+ private String mNrCpus = "4";
+
+ @Option(name = "mem", description = "Limit memory in gb")
+ private String mMem = "4";
+
+ private OemDeviceInfo mLowPerformanceDeviceInfo;
+ private OemDeviceInfo mInitialDeviceInfo;
+
+ /** {@inheritDoc} */
+ @Override
+ public void setUp(TestInformation testInformation)
+ throws TargetSetupError, BuildError, DeviceNotAvailableException {
+ mLowPerformanceDeviceInfo = new OemDeviceInfo(mNrCpus, mMem);
+
+ ITestDevice device = testInformation.getDevice();
+ device.rebootIntoBootloader();
+ try {
+ mInitialDeviceInfo = getOemDeviceInfo(device);
+ executeFastbootCommand(device,
+ String.format("oem nr-cpus %s", mLowPerformanceDeviceInfo.mNrCpus));
+ executeFastbootCommand(device,
+ String.format("oem mem %s", mLowPerformanceDeviceInfo.mMem));
+ if (!isDeviceInLowPerformanceState(device)) {
+ throw new TargetSetupError("Device is not in a low performance state after setUp.",
+ device.getDeviceDescriptor(),
+ InfraErrorIdentifier.INVOCATION_CANCELLED);
+ }
+ } finally {
+ device.reboot();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void tearDown(TestInformation testInformation, Throwable e)
+ throws DeviceNotAvailableException {
+ ITestDevice device = testInformation.getDevice();
+ device.rebootIntoBootloader();
+ try {
+ executeFastbootCommand(device, String.format("oem mem %s", mInitialDeviceInfo.mMem));
+ executeFastbootCommand(device,
+ String.format("oem nr-cpus %s", mInitialDeviceInfo.mNrCpus));
+ if (isDeviceInLowPerformanceState(device)) {
+ throw new TargetSetupError("Failed to reset device to the initial state.");
+ }
+ } catch (TargetSetupError exception) {
+ LogUtil.CLog.e(exception);
+ throw new DeviceNotAvailableException("Failed to reset device to the initial state.",
+ exception,
+ device.getSerialNumber());
+ } finally {
+ device.reboot();
+ }
+ }
+
+ private CommandResult executeFastbootCommand(ITestDevice device, String command)
+ throws DeviceNotAvailableException, TargetSetupError {
+ if (!device.isStateBootloaderOrFastbootd()) {
+ throw new TargetSetupError(
+ "Device is not in fastboot mode",
+ device.getDeviceDescriptor(),
+ InfraErrorIdentifier.OPTION_CONFIGURATION_ERROR
+ );
+ }
+ LogUtil.CLog.v(String.format("Executing fastboot command: %s", command));
+ final CommandResult result = device.executeFastbootCommand(command.split("\\s+"));
+ if (result.getExitCode() != 0) {
+ throw new TargetSetupError(
+ String.format(
+ "Command %s failed, stdout = [%s], stderr = [%s].",
+ command, result.getStdout(), result.getStderr()),
+ device.getDeviceDescriptor(),
+ InfraErrorIdentifier.OPTION_CONFIGURATION_ERROR);
+ }
+ LogUtil.CLog.v(String.format(
+ "Command %s returned: stdout = [%s], stderr = [%s].",
+ command, result.getStdout(), result.getStderr()));
+ return result;
+ }
+
+ private OemDeviceInfo getOemDeviceInfo(ITestDevice device)
+ throws DeviceNotAvailableException, TargetSetupError {
+ String mem = "";
+ String nrCpus = "";
+
+ CommandResult deviceInfoCmdResult = executeFastbootCommand(device, "oem device-info");
+ for (String line : deviceInfoCmdResult.getStderr().split("\n")) {
+ // (bootloader) Nr cpus: 4
+ // (bootloader) Mem Size: 4G
+ String[] split = line.split(": ");
+ if (split.length == 2) {
+ if (split[0].equals("(bootloader) Nr cpus")) {
+ nrCpus = split[1];
+ }
+ if (split[0].equals("(bootloader) Mem Size")) {
+ mem = split[1].replaceAll("\\D", "");
+ }
+ }
+ }
+ if (nrCpus.isBlank() || mem.isBlank()) {
+ throw new TargetSetupError(String.format(
+ "Couldn't get current memory or CPU cores values. CPU: %s. Memory: %s.",
+ nrCpus, mem), device.getDeviceDescriptor(),
+ InfraErrorIdentifier.OPTION_CONFIGURATION_ERROR);
+ }
+ return new OemDeviceInfo(nrCpus, mem);
+ }
+
+ private boolean isDeviceInLowPerformanceState(ITestDevice device)
+ throws DeviceNotAvailableException, TargetSetupError {
+ return mLowPerformanceDeviceInfo.equals(getOemDeviceInfo(device));
+ }
+}
diff --git a/tools/catbox-common/res/config/catbox-preparer.xml b/tools/catbox-common/res/config/catbox-preparer.xml
index 21109c5..53ca96e 100644
--- a/tools/catbox-common/res/config/catbox-preparer.xml
+++ b/tools/catbox-common/res/config/catbox-preparer.xml
@@ -34,6 +34,11 @@
<option name="set-secure-setting" key="location_mode" value="1" />
</target_preparer>
+ <!-- Target Preparers - Limit resources on the device for low performance testing -->
+ <target_preparer class="com.android.catbox.targetpreparer.LowPerformanceTargetPreparer">
+ <option name="disable" value="true" />
+ </target_preparer>
+
<!-- Target Preparers - ADB Root -->
<target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer" />
diff --git a/tools/catbox-tradefed/res/config/catbox-functional-admin-user-grant-permissions.xml b/tools/catbox-tradefed/res/config/catbox-functional-admin-user-grant-permissions.xml
index ea1afcd..0a7e913 100644
--- a/tools/catbox-tradefed/res/config/catbox-functional-admin-user-grant-permissions.xml
+++ b/tools/catbox-tradefed/res/config/catbox-functional-admin-user-grant-permissions.xml
@@ -20,6 +20,9 @@
<!-- Device Preparers -->
<include name="catbox-preparer"/>
+ <!-- Enable system user target preparer to run as user 0 -->
+ <option name="run-on-system-user:disable" value="false" />
+
<!-- Plan -->
<option name="plan" value=" functional_tests.catbox_functional_admin_user_grant_permissions
"/>
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-dialer.xml b/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-dialer.xml
index b1bf271..7cbb12a 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-dialer.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-dialer.xml
@@ -42,7 +42,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.dial" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveDialScenarioTests android.platform.test.scenario.dial.OpenAppMicrobenchmark#testOpen" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveDialScenarioTests android.platform.test.scenario.dial.OpenAppMicrobenchmark" />
<!-- Test Metrics Report Options -->
<option name="report-log-name" value="CatboxPerformanceTests" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-mediacenter.xml b/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-mediacenter.xml
index 50d39fa..4a75c5c 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-mediacenter.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-mediacenter.xml
@@ -42,7 +42,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.mediacenter" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterScenarioTests android.platform.test.scenario.mediacenter.OpenAppMicrobenchmark#testOpen" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterScenarioTests android.platform.test.scenario.mediacenter.OpenAppMicrobenchmark" />
<!-- Test Metrics Report Options -->
<option name="report-log-name" value="CatboxPerformanceTests" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-settings.xml b/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-settings.xml
index df05367..94649b6 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-settings.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-cold-app-start-up-settings.xml
@@ -42,7 +42,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.settings" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveSettingsScenarioTests android.platform.test.scenario.settings.OpenAppMicrobenchmark#testOpen" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveSettingsScenarioTests android.platform.test.scenario.settings.OpenAppMicrobenchmark" />
<!-- Test Metrics Report Options -->
<option name="report-log-name" value="CatboxPerformanceTests" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-dialer.xml b/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-dialer.xml
index 32f8c08..a182b80 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-dialer.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-dialer.xml
@@ -42,7 +42,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.dial" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveDialScenarioTests android.platform.test.scenario.dial.OpenAppMicrobenchmark#testOpen" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveDialScenarioTests android.platform.test.scenario.dial.OpenAppMicrobenchmark" />
<!-- Test Metrics Report Options -->
<option name="report-log-name" value="CatboxPerformanceTests" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-mediacenter.xml b/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-mediacenter.xml
index e7e23a5..b2aa489 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-mediacenter.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-mediacenter.xml
@@ -42,7 +42,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.mediacenter" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterScenarioTests android.platform.test.scenario.mediacenter.OpenAppMicrobenchmark#testOpen" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterScenarioTests android.platform.test.scenario.mediacenter.OpenAppMicrobenchmark" />
<!-- Test Metrics Report Options -->
<option name="report-log-name" value="CatboxPerformanceTests" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-settings.xml b/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-settings.xml
index 4294da8..45b190b 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-settings.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-hot-app-start-up-settings.xml
@@ -42,7 +42,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.settings" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveSettingsScenarioTests android.platform.test.scenario.settings.OpenAppMicrobenchmark#testOpen" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveSettingsScenarioTests android.platform.test.scenario.settings.OpenAppMicrobenchmark" />
<!-- Test Metrics Report Options -->
<option name="report-log-name" value="CatboxPerformanceTests" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-jank-appgrid.xml b/tools/catbox-tradefed/res/config/catbox-performance-jank-appgrid.xml
index be24379..acf5e76 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-jank-appgrid.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-jank-appgrid.xml
@@ -37,7 +37,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.appgrid" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveAppGridScenarioTests android.platform.test.scenario.appgrid.ScrollMicrobenchmark#testScrollForwardAndBackward" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveAppGridScenarioTests android.platform.test.scenario.appgrid.ScrollMicrobenchmark" />
<!-- Jank Package -->
<option name="compatibility:module-arg" value="AndroidAutomotiveAppGridScenarioTests:instrumentation-arg:jank-package-names:=com.android.car.carlauncher" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-jank-contact-list.xml b/tools/catbox-tradefed/res/config/catbox-performance-jank-contact-list.xml
index 76d0469..defd204 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-jank-contact-list.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-jank-contact-list.xml
@@ -37,7 +37,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.dial" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveDialScenarioTests android.platform.test.scenario.dial.ScrollContactListMicrobenchmark#testScrollDownAndUp" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveDialScenarioTests android.platform.test.scenario.dial.ScrollContactListMicrobenchmark" />
<!-- Jank Package -->
<option name="compatibility:module-arg" value="AndroidAutomotiveDialScenarioTests:instrumentation-arg:jank-package-names:=com.android.car.dialer" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-jank-media-switch-playback.xml b/tools/catbox-tradefed/res/config/catbox-performance-jank-media-switch-playback.xml
index f0fea15..9f5af76 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-jank-media-switch-playback.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-jank-media-switch-playback.xml
@@ -38,7 +38,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.mediacenter" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterScenarioTests android.platform.test.scenario.mediacenter.SwitchPlaybackMicrobenchmark#testSwitchPlayback" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterScenarioTests android.platform.test.scenario.mediacenter.SwitchPlaybackMicrobenchmark" />
<!-- Jank Package -->
<option name="compatibility:module-arg" value="AndroidAutomotiveMediaCenterScenarioTests:instrumentation-arg:jank-package-names:=com.android.car.media" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-jank-media.xml b/tools/catbox-tradefed/res/config/catbox-performance-jank-media.xml
index 4212fa3..7a0dd7d 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-jank-media.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-jank-media.xml
@@ -37,7 +37,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.mediacenter" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterScenarioTests android.platform.test.scenario.mediacenter.ScrollMicrobenchmark#testScrollDownAndUp" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterScenarioTests android.platform.test.scenario.mediacenter.ScrollMicrobenchmark" />
<!-- Jank Package -->
<option name="compatibility:module-arg" value="AndroidAutomotiveMediaCenterScenarioTests:instrumentation-arg:jank-package-names:=com.android.car.media" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-jank-notifications.xml b/tools/catbox-tradefed/res/config/catbox-performance-jank-notifications.xml
index 34d1883..42266cc 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-jank-notifications.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-jank-notifications.xml
@@ -37,7 +37,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.notification" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveNotificationScenarioTests android.platform.test.scenario.notification.ScrollMicrobenchmark#testScrollUpAndDown" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveNotificationScenarioTests android.platform.test.scenario.notification.ScrollMicrobenchmark" />
<!-- Jank Package -->
<option name="compatibility:module-arg" value="AndroidAutomotiveNotificationScenarioTests:instrumentation-arg:jank-package-names:=com.android.systemui" />
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-jank-settings.xml b/tools/catbox-tradefed/res/config/catbox-performance-jank-settings.xml
index d7f384f..688efa0 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-jank-settings.xml
+++ b/tools/catbox-tradefed/res/config/catbox-performance-jank-settings.xml
@@ -37,7 +37,7 @@
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.test.scenario.settings" />
<!-- Test -->
- <option name="compatibility:include-filter" value="AndroidAutomotiveSettingsScenarioTests android.platform.test.scenario.settings.ScrollInAppMicrobenchmark#testScrollDownAndUp" />
+ <option name="compatibility:include-filter" value="AndroidAutomotiveSettingsScenarioTests android.platform.test.scenario.settings.ScrollInAppMicrobenchmark" />
<!-- Jank Package -->
<option name="compatibility:module-arg" value="AndroidAutomotiveSettingsScenarioTests:instrumentation-arg:jank-package-names:=com.android.car.settings" />