summaryrefslogtreecommitdiff
path: root/tests/utils
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2019-03-22 11:17:29 +0900
committerTadashi G. Takaoka <takaoka@google.com>2019-03-22 18:04:30 +0900
commit9648d4b04bd0782aa670f8403cc3c18e7722c8ea (patch)
tree79d4b77f34a0f72448a7db2058134dfbb3c81d2b /tests/utils
parent75eaf771f8adff4be40e62ea891b728d05d98882 (diff)
Make SelectTest append selectTest argument from extended class
This CL also moves CoreTestsFilter to frameworks/base/test-util, so that FrameworksCoreTests, FrameworksServicesTests, and WmTests can use CoreTestsFilter. Test: Pass SelectTestTests $ atest WmTests:com.android.test.filters.SelectTestTests Test: Pass all 91 non-flaky presubmit tests in FrameworksCoreTests using CoreTestsFilter $ tradefed.sh run commandAndExit WmTests \ --instrumentation-arg selectTest=com.android.server.wm. \ --instrumentation-arg filter=com.android.server.wm.test.filters.CoreTestsFilter --include-annotation android.platform.test.annotations.Presubmit \ --exclude-annotation androidx.test.filters.FlakyTest Test: Pass all 740 non-flaky presubmit tests in WmTests using CoreTestsFilter $ tradefed.sh run commandAndExit WmTests \ --instrumentation-arg selectTest=com.android.server.wm. \ --instrumentation-arg filter=com.android.server.wm.test.filters.CoreTestsFilter --include-annotation android.platform.test.annotations.Presubmit \ --exclude-annotation androidx.test.filters.FlakyTest Bug: 122451194 Change-Id: I83d13d9ef82a92677bee67da5ee8a5faa0690f82
Diffstat (limited to 'tests/utils')
-rw-r--r--tests/utils/testutils/Android.bp5
-rw-r--r--tests/utils/testutils/java/com/android/server/wm/test/filters/CoreTestsFilter.java48
-rw-r--r--tests/utils/testutils/java/com/android/test/filters/SelectTest.java13
-rw-r--r--tests/utils/testutils/java/com/android/test/filters/SelectTestTests.java43
4 files changed, 106 insertions, 3 deletions
diff --git a/tests/utils/testutils/Android.bp b/tests/utils/testutils/Android.bp
index 0a9e964d8d8d..f71be7b0b7d3 100644
--- a/tests/utils/testutils/Android.bp
+++ b/tests/utils/testutils/Android.bp
@@ -19,7 +19,10 @@ java_library {
srcs: ["java/**/*.java"],
- static_libs: ["junit"],
+ static_libs: [
+ "junit",
+ "hamcrest-library",
+ ],
libs: [
"android.test.runner",
diff --git a/tests/utils/testutils/java/com/android/server/wm/test/filters/CoreTestsFilter.java b/tests/utils/testutils/java/com/android/server/wm/test/filters/CoreTestsFilter.java
new file mode 100644
index 000000000000..1a81c2c9fd41
--- /dev/null
+++ b/tests/utils/testutils/java/com/android/server/wm/test/filters/CoreTestsFilter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 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.server.wm.test.filters;
+
+import android.os.Bundle;
+
+import com.android.test.filters.SelectTest;
+
+/**
+ * JUnit test filter that select Window Manager Service related tests from FrameworksCoreTests.
+ *
+ * <p>Use this filter when running FrameworksCoreTests as
+ * <pre>
+ * adb shell am instrument -w \
+ * -e filter com.android.server.wm.test.filters.CoreTestsFilter \
+ * -e selectTest_verbose true \
+ * com.android.frameworks.coretests/androidx.test.runner.AndroidJUnitRunner
+ * </pre>
+ */
+public final class CoreTestsFilter extends SelectTest {
+
+ private static final String[] SELECTED_CORE_TESTS = {
+ "android.app.servertransaction.", // all tests under the package.
+ "android.view.DisplayCutoutTest",
+ "android.view.InsetsControllerTest",
+ "android.view.InsetsSourceTest",
+ "android.view.InsetsSourceConsumerTest",
+ "android.view.InsetsStateTest",
+ };
+
+ public CoreTestsFilter(Bundle testArgs) {
+ super(addSelectTest(testArgs, SELECTED_CORE_TESTS));
+ }
+}
diff --git a/tests/utils/testutils/java/com/android/test/filters/SelectTest.java b/tests/utils/testutils/java/com/android/test/filters/SelectTest.java
index d0350aff5ef5..d5b14c58512e 100644
--- a/tests/utils/testutils/java/com/android/test/filters/SelectTest.java
+++ b/tests/utils/testutils/java/com/android/test/filters/SelectTest.java
@@ -26,10 +26,12 @@ import com.android.internal.annotations.VisibleForTesting;
import org.junit.runner.Description;
import org.junit.runner.manipulation.Filter;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
@@ -131,7 +133,8 @@ public class SelectTest extends Filter {
*
* @param testArgs instrumentation test arguments.
* @param selectTests array of class name to be selected to run.
- * @return modified instrumentation test arguments.
+ * @return modified instrumentation test arguments. if {@link #OPTION_SELECT_TEST} argument
+ * already exists in {@code testArgs}, those are prepended before {@code selectTests}.
*/
@NonNull
protected static Bundle addSelectTest(
@@ -139,7 +142,13 @@ public class SelectTest extends Filter {
if (selectTests.length == 0) {
return testArgs;
}
- testArgs.putString(OPTION_SELECT_TEST, join(Arrays.asList(selectTests)));
+ final List<String> selectedTestList = new ArrayList<>();
+ final String selectTestArgs = testArgs.getString(OPTION_SELECT_TEST);
+ if (selectTestArgs != null) {
+ selectedTestList.addAll(Arrays.asList(selectTestArgs.split(ARGUMENT_ITEM_SEPARATOR)));
+ }
+ selectedTestList.addAll(Arrays.asList(selectTests));
+ testArgs.putString(OPTION_SELECT_TEST, join(selectedTestList));
return testArgs;
}
diff --git a/tests/utils/testutils/java/com/android/test/filters/SelectTestTests.java b/tests/utils/testutils/java/com/android/test/filters/SelectTestTests.java
index 163b00abafcd..df18985f77bf 100644
--- a/tests/utils/testutils/java/com/android/test/filters/SelectTestTests.java
+++ b/tests/utils/testutils/java/com/android/test/filters/SelectTestTests.java
@@ -19,7 +19,11 @@ package com.android.test.filters;
import static com.android.test.filters.SelectTest.OPTION_SELECT_TEST;
import static com.android.test.filters.SelectTest.OPTION_SELECT_TEST_VERBOSE;
+import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import android.os.Bundle;
@@ -146,6 +150,45 @@ public class SelectTestTests {
}
@Test
+ public void testAddSelectTest() {
+ final Bundle testArgs = new Bundle();
+
+ final Bundle modifiedTestArgs =
+ SelectTest.addSelectTest(testArgs, PACKAGE_A, CLASS_B3, METHOD_C5X);
+ assertSame(testArgs, modifiedTestArgs);
+
+ final String selectTestArgs = modifiedTestArgs.getString(OPTION_SELECT_TEST);
+ assertNotNull(selectTestArgs);
+ final String[] selectedTests = selectTestArgs.split(",");
+ assertThat(selectedTests, hasItemInArray(PACKAGE_A));
+ assertThat(selectedTests, hasItemInArray(CLASS_B3));
+ assertThat(selectedTests, hasItemInArray(METHOD_C5X));
+ }
+
+ @Test
+ public void testAddSelectTest_prependExistingTestArg() {
+ final Bundle testArgs = new Bundle();
+ testArgs.putString(OPTION_SELECT_TEST, new StringJoiner(",")
+ .add(PACKAGE_A)
+ .add(CLASS_B3)
+ .add(METHOD_C5X)
+ .toString());
+
+ final Bundle modifiedTestArgs =
+ SelectTest.addSelectTest(testArgs, PACKAGE_B, CLASS_B4, METHOD_C6Y);
+
+ final String selectTestArgs = modifiedTestArgs.getString(OPTION_SELECT_TEST);
+ assertNotNull(selectTestArgs);
+ final String[] selectedTests = selectTestArgs.split(",");
+ assertThat(selectedTests, hasItemInArray(PACKAGE_A));
+ assertThat(selectedTests, hasItemInArray(CLASS_B3));
+ assertThat(selectedTests, hasItemInArray(METHOD_C5X));
+ assertThat(selectedTests, hasItemInArray(PACKAGE_B));
+ assertThat(selectedTests, hasItemInArray(CLASS_B4));
+ assertThat(selectedTests, hasItemInArray(METHOD_C6Y));
+ }
+
+ @Test
public void testFilterDisabled() {
final Filter filter = mBuilder.build();
acceptTests(filter, TEST_ALL);