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
This commit is contained in:
Tadashi G. Takaoka
2019-03-22 11:17:29 +09:00
parent 75eaf771f8
commit 9648d4b04b
4 changed files with 58 additions and 3 deletions

View File

@@ -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));
}
}

View File

@@ -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;
}

View File

@@ -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;
@@ -145,6 +149,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();