diff options
-rw-r--r-- | android/test_asserts.go | 17 | ||||
-rw-r--r-- | java/app.go | 3 | ||||
-rw-r--r-- | java/app_test.go | 70 |
3 files changed, 90 insertions, 0 deletions
diff --git a/android/test_asserts.go b/android/test_asserts.go index c33ade5a2..22472c5c2 100644 --- a/android/test_asserts.go +++ b/android/test_asserts.go @@ -33,6 +33,23 @@ func AssertSame(t *testing.T, message string, expected interface{}, actual inter } } +// AssertSame checks if the expected and actual values are equal and if they are not then +// it reports an error prefixed with the supplied message and including a reason for why it failed. +func AssertSameArray[T comparable](t *testing.T, message string, expected []T, actual []T) { + t.Helper() + if len(actual) != len(expected) { + t.Errorf("%s: expected %d (%v), actual (%d) %v", message, len(expected), expected, len(actual), actual) + return + } + for i := range actual { + if actual[i] != expected[i] { + t.Errorf("%s: expected %d-th, %v (%v), actual %v (%v)", + message, i, expected[i], expected, actual[i], actual) + return + } + } +} + // AssertBoolEquals checks if the expected and actual values are equal and if they are not then it // reports an error prefixed with the supplied message and including a reason for why it failed. func AssertBoolEquals(t *testing.T, message string, expected bool, actual bool) { diff --git a/java/app.go b/java/app.go index b0dcbb003..d56ea5f73 100644 --- a/java/app.go +++ b/java/app.go @@ -1565,6 +1565,9 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { } a.generateAndroidBuildActions(ctx) + for _, c := range a.testProperties.Test_options.Tradefed_options { + configs = append(configs, c) + } for _, module := range a.testProperties.Test_mainline_modules { configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module}) } diff --git a/java/app_test.go b/java/app_test.go index 4e915d2e9..bde801b32 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -18,6 +18,7 @@ import ( "fmt" "path/filepath" "reflect" + "regexp" "sort" "strings" "testing" @@ -4589,6 +4590,75 @@ func TestTestOnlyApp(t *testing.T) { assertTestOnlyAndTopLevel(t, ctx, expectedTestOnly, expectedTopLevel) } +func TestTestConfigTemplate(t *testing.T) { + t.Parallel() + ctx := android.GroupFixturePreparers( + prepareForJavaTest, + ).RunTestWithBp(t, ` + android_test { + name: "android-test", + test_config_template: "AndroidTestTemplate.xml", + test_options: { + tradefed_options: [ + { + name: "name1", + key: "key1", + value: "value1", + }, + { + name: "name2", + key: "key2", + value: "value2", + }, + ], + test_runner_options: [ + { + name: "name3", + key: "key3", + value: "value3", + }, + { + name: "name4", + key: "key4", + value: "value4", + }, + ], + }, + } + `) + type option struct { + name string + key string + value string + } + re := regexp.MustCompile(`<option name="(.*)" key="(.*)" value="(.*)" />`) + parse_options := func(optionsString string) []option { + lines := strings.Split(optionsString, `\n`) + var ret []option + for _, l := range lines { + sm := re.FindStringSubmatch(l) + if sm == nil { + continue + } + ret = append(ret, option{sm[1], sm[2], sm[3]}) + } + return ret + } + rule := ctx.ModuleForTests("android-test", "android_common").Rule("autogenInstrumentationTest") + android.AssertSameArray(t, "extraConfigs mismatch", + []option{ + {"name1", "key1", "value1"}, + {"name2", "key2", "value2"}, + }, + parse_options(rule.Args["extraConfigs"])) + android.AssertSameArray(t, "extraTestRunnerConfigs mismatch", + []option{ + {"name3", "key3", "value3"}, + {"name4", "key4", "value4"}, + }, + parse_options(rule.Args["extraTestRunnerConfigs"])) +} + func TestAppStem(t *testing.T) { ctx := testApp(t, ` android_app { |