Merge "Add some verification on test_suite for test_module_config" into main

This commit is contained in:
Ronald Braunstein
2024-08-07 22:45:44 +00:00
committed by Gerrit Code Review
2 changed files with 45 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"slices"
"strings"
"github.com/google/blueprint"
@@ -174,6 +175,20 @@ func (m *testModuleConfigModule) validateTestSuites(ctx android.ModuleContext) b
return false
}
var extra_derived_suites []string
// Ensure all suites listed are also in base.
for _, s := range m.tradefedProperties.Test_suites {
if !slices.Contains(m.provider.TestSuites, s) {
extra_derived_suites = append(extra_derived_suites, s)
}
}
if len(extra_derived_suites) != 0 {
ctx.ModuleErrorf("Suites: [%s] listed but do not exist in base module: %s",
strings.Join(extra_derived_suites, ", "),
*m.tradefedProperties.Base)
return false
}
return true
}

View File

@@ -40,6 +40,7 @@ const bp = `
name: "base",
sdk_version: "current",
data: [":HelperApp", "data/testfile"],
test_suites: ["general-tests"],
}
test_module_config {
@@ -160,7 +161,7 @@ func TestModuleConfigBadBaseShouldFailWithGeneralMessage(t *testing.T) {
java.PrepareForTestWithJavaDefaultModules,
android.FixtureRegisterWithContext(RegisterTestModuleConfigBuildComponents),
).ExtendWithErrorHandler(
android.FixtureExpectsOneErrorPattern("'base' module used as base but it is not a 'android_test' module.")).
android.FixtureExpectsAtLeastOneErrorMatchingPattern("'base' module used as base but it is not a 'android_test' module.")).
RunTestWithBp(t, badBp)
}
@@ -193,6 +194,7 @@ func TestModuleConfigNoFiltersOrAnnotationsShouldFail(t *testing.T) {
name: "base",
sdk_version: "current",
srcs: ["a.java"],
test_suites: ["general-tests"],
}
test_module_config {
@@ -218,6 +220,7 @@ func TestModuleConfigMultipleDerivedTestsWriteDistinctMakeEntries(t *testing.T)
sdk_version: "current",
srcs: ["a.java"],
data: [":HelperApp", "data/testfile"],
test_suites: ["general-tests"],
}
android_test_helper_app {
@@ -362,6 +365,31 @@ func TestModuleConfigHostNeedsATestSuite(t *testing.T) {
RunTestWithBp(t, badBp)
}
func TestModuleConfigNonMatchingTestSuitesGiveErrors(t *testing.T) {
badBp := `
java_test_host {
name: "base",
srcs: ["a.java"],
test_suites: ["general-tests", "some-compat"],
}
test_module_config_host {
name: "derived_test",
base: "base",
exclude_filters: ["android.test.example.devcodelab.DevCodelabTest#testHelloFail"],
include_annotations: ["android.platform.test.annotations.LargeTest"],
test_suites: ["device-tests", "random-suite"],
}`
android.GroupFixturePreparers(
java.PrepareForTestWithJavaDefaultModules,
android.FixtureRegisterWithContext(RegisterTestModuleConfigBuildComponents),
).ExtendWithErrorHandler(
// Use \\ to escape bracket so it isn't used as [] set for regex.
android.FixtureExpectsAtLeastOneErrorMatchingPattern("Suites: \\[device-tests, random-suite] listed but do not exist in base module")).
RunTestWithBp(t, badBp)
}
func TestTestOnlyProvider(t *testing.T) {
t.Parallel()
ctx := android.GroupFixturePreparers(
@@ -389,6 +417,7 @@ func TestTestOnlyProvider(t *testing.T) {
name: "base",
sdk_version: "current",
data: ["data/testfile"],
test_suites: ["general-tests"],
}
java_test_host {