Test Mapping Global Validation: Ignore checking tests if hit ANY of
the following conditions:
1. Test has keyword setting.
2. Test isn't in group presubmit or postsubmit.
Bug: 129475290
Test: unittests
tradefed.sh run commandAndExit google/template/lab-base --log-level-display VERBOSE --template:map lab-preparers=empty --template:map test=google/tf/test-mappings-validation --template:map reporters=google/template/reporters/blackbox --additional-files-filter .*/test_mappings.zip --additional-files-filter .*/module-info.json --skip-download DEVICE_IMAGE --hostname atp-manager.googleplex.com --protocol https --use-build-api --branch git_master --build-flavor test_suites_x86_64 --build-os linux --build-id 5472471
Change-Id: Iba322e516fc18938d9355ee0383a64b7ab70b9e2
diff --git a/src/com/android/tradefed/presubmit/TestMappingsValidation.java b/src/com/android/tradefed/presubmit/TestMappingsValidation.java
index d9912f4..408f136 100644
--- a/src/com/android/tradefed/presubmit/TestMappingsValidation.java
+++ b/src/com/android/tradefed/presubmit/TestMappingsValidation.java
@@ -31,6 +31,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -69,6 +70,9 @@
private static final String LOCAL_COMPATIBILITY_SUITES = "compatibility_suites";
private static final String GENERAL_TESTS = "general-tests";
private static final String DEVICE_TESTS = "device-tests";
+ // Only Check the tests with group in presubmit or postsubmit.
+ private static final Set<String> TEST_GROUPS_TO_VALIDATE =
+ new HashSet<>(Arrays.asList("presubmit", "postsubmit"));
private File testMappingsDir = null;
private IDeviceBuildInfo deviceBuildInfo = null;
@@ -115,8 +119,12 @@
public void testTestSuiteSetting() throws JSONException {
List<String> errors = new ArrayList<>();
for (String testGroup : allTests.keySet()) {
+ if (!TEST_GROUPS_TO_VALIDATE.contains(testGroup)) {
+ CLog.d("Skip checking tests with group: %s", testGroup);
+ continue;
+ }
for (TestInfo testInfo : allTests.get(testGroup)) {
- if (!validateSuiteSetting(testInfo.getName())) {
+ if (!validateSuiteSetting(testInfo.getName(), testInfo.getKeywords())) {
errors.add(
String.format(
"Missing test_suite setting for test: %s, test group: %s, " +
@@ -242,11 +250,17 @@
* Validate if the name exists in module-info.json and with the correct suite setting.
*
* @param name A {@code String} name of the test.
+ * @param keywords A {@code Set<String>} keywords of the test.
* @return true if name exists in module-info.json and matches either "general-tests" or
- * "device-tests".
+ * "device-tests", or name doesn't exist but has keywords attribute set.
*/
- private boolean validateSuiteSetting(String name) throws JSONException {
+ private boolean validateSuiteSetting(String name, Set<String> keywords) throws JSONException {
if (!moduleInfo.has(name)) {
+ if (!keywords.isEmpty()) {
+ CLog.d("Test Module: %s can't be found in module-info.json, but it has " +
+ "keyword setting. Ignore checking...", name);
+ return true;
+ }
CLog.w("Test Module: %s can't be found in module-info.json.", name);
return false;
}