summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-04-11 05:08:51 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-11 05:08:51 +0000
commit8af5867b05caaa6276305c363030f0d2822e2c60 (patch)
treeeeceb34f2090f91e019943625c750d1235d2adad
parentf9c7e649812e4b8b35f4b7f1cec29f79f08810ea (diff)
parent5aad562242d6fae61414ecaa8b8c1676eecc39b3 (diff)
downloadplatform_testing-8af5867b05caaa6276305c363030f0d2822e2c60.tar.gz
Merge "Add an option for package name in CompilationFilterRule" into main
-rw-r--r--libraries/health/rules/src/android/platform/test/rule/CompilationFilterRule.java16
-rw-r--r--libraries/health/rules/tests/src/android/platform/test/rule/CompilationFilterRuleTest.java47
2 files changed, 49 insertions, 14 deletions
diff --git a/libraries/health/rules/src/android/platform/test/rule/CompilationFilterRule.java b/libraries/health/rules/src/android/platform/test/rule/CompilationFilterRule.java
index 1b495f1e2..e06eba12b 100644
--- a/libraries/health/rules/src/android/platform/test/rule/CompilationFilterRule.java
+++ b/libraries/health/rules/src/android/platform/test/rule/CompilationFilterRule.java
@@ -20,12 +20,12 @@ import static java.util.stream.Collectors.joining;
import android.os.SystemClock;
import android.util.Log;
+
import androidx.annotation.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import org.junit.runner.Description;
-import org.junit.runners.model.InitializationError;
import java.util.HashSet;
import java.util.Set;
@@ -42,14 +42,16 @@ public class CompilationFilterRule extends TestWatcher {
@VisibleForTesting static final String SPEED_PROFILE_FILTER = "speed-profile";
private static final String PROFILE_SAVE_TIMEOUT = "profile-save-timeout";
@VisibleForTesting static final String COMPILE_FILTER_OPTION = "compilation-filter";
+
+ @VisibleForTesting
+ static final String COMPILE_PACKAGE_NAMES_OPTION = "compilation-package-names";
+
@VisibleForTesting static final String COMPILE_SUCCESS = "Success";
@VisibleForTesting static Set<String> mCompiledTests = new HashSet<>();
- private final String[] mApplications;
+ private String[] mApplications;
- public CompilationFilterRule() throws InitializationError {
- throw new InitializationError("Must supply an application to compile.");
- }
+ public CompilationFilterRule() {}
public CompilationFilterRule(String... applications) {
mApplications = applications;
@@ -83,6 +85,10 @@ public class CompilationFilterRule extends TestWatcher {
"Unknown compiler filter: %s, not part of %s", filter, filterOptions));
}
+ if (getArguments().getString(COMPILE_PACKAGE_NAMES_OPTION) != null) {
+ mApplications = getArguments().getString(COMPILE_PACKAGE_NAMES_OPTION).split(",");
+ }
+
for (String app : mApplications) {
// For speed profile compilation, ART team recommended to wait for 5 secs when app
// is in the foreground, dump the profile, wait for another 5 secs before
diff --git a/libraries/health/rules/tests/src/android/platform/test/rule/CompilationFilterRuleTest.java b/libraries/health/rules/tests/src/android/platform/test/rule/CompilationFilterRuleTest.java
index 8d9b81859..e04f1f8e1 100644
--- a/libraries/health/rules/tests/src/android/platform/test/rule/CompilationFilterRuleTest.java
+++ b/libraries/health/rules/tests/src/android/platform/test/rule/CompilationFilterRuleTest.java
@@ -15,9 +15,10 @@
*/
package android.platform.test.rule;
-import static org.junit.Assert.fail;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.fail;
+
import android.os.Bundle;
import org.junit.After;
@@ -25,7 +26,6 @@ import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import java.util.ArrayList;
@@ -41,14 +41,43 @@ public class CompilationFilterRuleTest {
CompilationFilterRule.mCompiledTests.clear();
}
- /** Tests that this rule will fail to register if no apps are supplied. */
+ /** Tests that this rule will do nothing if no package are supplied. */
@Test
- public void testNoAppToCompileFails() throws InitializationError {
- try {
- CompilationFilterRule rule = new CompilationFilterRule();
- fail("An initialization error should have been thrown, but wasn't.");
- } catch (InitializationError e) {
- }
+ public void testNoAppToCompile() throws Throwable {
+ Bundle filterBundle = new Bundle();
+ filterBundle.putString(CompilationFilterRule.COMPILE_PACKAGE_NAMES_OPTION, "");
+ TestableCompilationFilterRule rule =
+ new TestableCompilationFilterRule(filterBundle) {
+ @Override
+ protected String executeShellCommand(String cmd) {
+ super.executeShellCommand(cmd);
+ return CompilationFilterRule.COMPILE_SUCCESS;
+ }
+ };
+ rule.apply(rule.getTestStatement(), Description.createTestDescription("clzz", "mthd1"))
+ .evaluate();
+ }
+
+ /** Tests that this rule will compile the app after the test, if supplied. */
+ @Test
+ public void testSingleAppToCompile() throws Throwable {
+ Bundle filterBundle = new Bundle();
+ filterBundle.putString(CompilationFilterRule.COMPILE_FILTER_OPTION, "speed");
+ filterBundle.putString(
+ CompilationFilterRule.COMPILE_PACKAGE_NAMES_OPTION, "example.package");
+ TestableCompilationFilterRule rule =
+ new TestableCompilationFilterRule(filterBundle) {
+ @Override
+ protected String executeShellCommand(String cmd) {
+ super.executeShellCommand(cmd);
+ return CompilationFilterRule.COMPILE_SUCCESS;
+ }
+ };
+ rule.apply(rule.getTestStatement(), Description.createTestDescription("clzz", "mthd2"))
+ .evaluate();
+ String compileCmd =
+ String.format(CompilationFilterRule.COMPILE_CMD_FORMAT, "speed", "example.package");
+ assertThat(rule.getOperations()).containsExactly("test", compileCmd).inOrder();
}
/** Tests that this rule will fail to run and throw if the option is bad. */