summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-27 23:22:08 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-27 23:22:08 +0000
commit2ce1728b5e7cd2609162e679e00db0bfbfcd65df (patch)
tree7cb1c9452b569f107ddda536f7837892b149fefb
parent7806bbf06c24b9cc5e762245bb7f86337b5a7269 (diff)
parent948cb8137494a9049b3914bae3defa31c58409a7 (diff)
downloadcatbox-android14-d1-s4-release.tar.gz
Change-Id: I91ab2bb780ba49d281f444b73404444b3afa1791
-rw-r--r--target_preparers/src/com/android/catbox/targetpreparer/SkipTestPreparer.java126
-rw-r--r--tools/catbox-common/res/config/catbox-performance-multiuser-base.xml9
2 files changed, 134 insertions, 1 deletions
diff --git a/target_preparers/src/com/android/catbox/targetpreparer/SkipTestPreparer.java b/target_preparers/src/com/android/catbox/targetpreparer/SkipTestPreparer.java
new file mode 100644
index 0000000..efe97e0
--- /dev/null
+++ b/target_preparers/src/com/android/catbox/targetpreparer/SkipTestPreparer.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2023 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.ddmlib.Log.LogLevel;
+
+import com.android.tradefed.build.IBuildInfo;
+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.log.LogUtil.CLog;
+
+import com.android.tradefed.targetprep.BaseTargetPreparer;
+import com.android.tradefed.targetprep.BuildError;
+import com.android.tradefed.targetprep.TargetSetupError;
+
+import com.google.common.collect.ImmutableSet;
+
+import java.util.Set;
+
+/**
+ * SkipTestPreparer is an {@link ITargetPreparer} that skips tests based on values of
+ * certain ADB properties on the device
+ */
+@OptionClass(alias = "skip-test-preparer")
+public class SkipTestPreparer extends BaseTargetPreparer {
+
+ @Option(name = "comp-property", description = "ADB property of device to check against")
+ private String mCompProp;
+
+ @Option(
+ name = "comp-property-int-value",
+ description = "Integer value of ADB property to check against")
+ private int mPropVal;
+
+ @Option(
+ name = "int-comparison-operator",
+ description = "Operator to compare expected and actual int values")
+ private String mCompOperator;
+
+ private static final Set<String> supportedOperators = ImmutableSet.of("lt", "gt", "eq", "neq");
+
+ @Override
+ public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
+ BuildError, DeviceNotAvailableException {
+
+ // Skip this preparer if @Option values are not provided
+ if (mCompProp == null || mCompOperator == null) {
+ CLog.logAndDisplay(LogLevel.INFO,
+ "Missing value for comp-property or comp-property-int-value. Skipping preparer.");
+ return;
+ }
+
+ boolean skipTestFlag = false;
+
+ if (!supportedOperators.contains(mCompOperator)) {
+ CLog.logAndDisplay(LogLevel.WARN,
+ String.format("Incompatible operator %s. Skipping preparer", mCompOperator));
+ CLog.logAndDisplay(LogLevel.INFO,
+ String.format("Supported operators are %s", String.join(",", supportedOperators)));
+ return;
+ }
+
+ int devicePropertyValue =
+ Integer.parseInt(
+ device.executeShellCommand(String.format("getprop %s", mCompProp)).trim());
+ CLog.logAndDisplay(LogLevel.INFO,
+ String.format("%s returned %d", mCompProp, devicePropertyValue)
+ );
+
+ skipTestFlag = getSkipTestFlag(devicePropertyValue);
+
+ if (skipTestFlag) {
+ CLog.logAndDisplay(LogLevel.INFO, "Skip condition satisfied. Skipping test module.");
+ throw new TargetSetupError(
+ String.format("Test incompatible with %s = %d", mCompProp, devicePropertyValue),
+ device.getDeviceDescriptor());
+ } else {
+ CLog.logAndDisplay(LogLevel.INFO,
+ "Skip condition not satisfied. Proceeding with test module.");
+ }
+ }
+
+ private boolean getSkipTestFlag(int devicePropertyValue) {
+ switch (mCompOperator) {
+ case "lt":
+ CLog.logAndDisplay(LogLevel.INFO,
+ "Checking skip condition %d < %d", devicePropertyValue, mPropVal);
+ return devicePropertyValue < mPropVal;
+
+ case "gt":
+ CLog.logAndDisplay(LogLevel.INFO,
+ "Checking skip condition %d > %d", devicePropertyValue, mPropVal);
+ return devicePropertyValue > mPropVal;
+
+ case "eq":
+ CLog.logAndDisplay(LogLevel.INFO,
+ "Checking skip condition %d == %d", devicePropertyValue, mPropVal);
+ return devicePropertyValue == mPropVal;
+
+ case "neq":
+ CLog.logAndDisplay(LogLevel.INFO,
+ "Checking condition %d != %d", devicePropertyValue, mPropVal);
+ return devicePropertyValue != mPropVal;
+
+ default:
+ return false;
+ }
+ }
+}
diff --git a/tools/catbox-common/res/config/catbox-performance-multiuser-base.xml b/tools/catbox-common/res/config/catbox-performance-multiuser-base.xml
index e9fea7b..efb6131 100644
--- a/tools/catbox-common/res/config/catbox-performance-multiuser-base.xml
+++ b/tools/catbox-common/res/config/catbox-performance-multiuser-base.xml
@@ -17,6 +17,13 @@
<configuration description="Base config for Multi-User latency metrics">
<include name="catbox-performance-base" />
+ <!-- Skip the test if skip conditions are met -->
+ <target_preparer class="com.android.catbox.targetpreparer.SkipTestPreparer">
+ <option name="comp-property" value="ro.build.version.sdk"/>
+ <option name="comp-property-int-value" value="33"/>
+ <option name="int-comparison-operator" value="lt"/>
+ </target_preparer>
+
<!-- TradeFed test harness -->
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:runner:androidx.test.runner.AndroidJUnitRunner" />
<option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.scenario.multiuser" />
@@ -36,4 +43,4 @@
<!-- Default metrics post processor -->
<include name="catbox-performance-postprocessors" />
-</configuration> \ No newline at end of file
+</configuration>