diff options
author | Becky Wen <jinghuanwen@google.com> | 2024-04-04 12:00:17 -0700 |
---|---|---|
committer | Becky Wen <jinghuanwen@google.com> | 2024-04-10 14:22:07 -0700 |
commit | 5aad562242d6fae61414ecaa8b8c1676eecc39b3 (patch) | |
tree | 13b01199a4ce882fda51e6401b2fa544fe131678 | |
parent | dc701bc885e2714a0b2750357d6f67303085b125 (diff) | |
download | platform_testing-5aad562242d6fae61414ecaa8b8c1676eecc39b3.tar.gz |
Add an option for package name in CompilationFilterRule
Test: CompilationFilterRuleTest
Bug: 331670804
Change-Id: I4f4dc67c88813aca0a4d2e1fe81a8db8b8f26adb
-rw-r--r-- | libraries/health/rules/src/android/platform/test/rule/CompilationFilterRule.java | 16 | ||||
-rw-r--r-- | libraries/health/rules/tests/src/android/platform/test/rule/CompilationFilterRuleTest.java | 47 |
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. */ |