summaryrefslogtreecommitdiff
path: root/tradefed_modules
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2025-02-11 14:58:07 -0800
committer Colin Cross <ccross@android.com> 2025-02-12 10:36:48 -0800
commit90607e9056f6ff4cec2447fdd7a8b252d67ffde7 (patch)
treed4e244bc76e8e13a8438bcd921fd9003bce46730 /tradefed_modules
parentd8db8faba62a3cb77f75294e96deda9e53c15786 (diff)
Don't panic in ModuleForTests and friends
Panicking in ModuleForTests and similar test helper functions was a mistake. Go's test runner stops running tests as soon as any test panics, which means debugging multiple tests panicking requires rerunning all the tests after fixing each panic to find the next one. Pass the *testing.T into ModuleForTests and friends so that it can call t.Fatalf instead. Test: all soong tests pass Change-Id: I5d0f2424eaf04fb795079e6d1e4b9469d8c7033c
Diffstat (limited to 'tradefed_modules')
-rw-r--r--tradefed_modules/test_module_config_test.go16
-rw-r--r--tradefed_modules/test_suite_test.go4
2 files changed, 10 insertions, 10 deletions
diff --git a/tradefed_modules/test_module_config_test.go b/tradefed_modules/test_module_config_test.go
index 037dcea04..302f9a9d5 100644
--- a/tradefed_modules/test_module_config_test.go
+++ b/tradefed_modules/test_module_config_test.go
@@ -65,13 +65,13 @@ func TestModuleConfigAndroidTest(t *testing.T) {
android.FixtureRegisterWithContext(RegisterTestModuleConfigBuildComponents),
).RunTestWithBp(t, bp)
- derived := ctx.ModuleForTests("derived_test", variant)
+ derived := ctx.ModuleForTests(t, "derived_test", variant)
// Assert there are rules to create these files.
derived.Output("test_module_config.manifest")
derived.Output("test_config_fixer/derived_test.config")
// Ensure some basic rules exist.
- ctx.ModuleForTests("base", "android_common").Output("package-res.apk")
+ ctx.ModuleForTests(t, "base", "android_common").Output("package-res.apk")
entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, derived.Module())[0]
// Ensure some entries from base are there, specifically support files for data and helper apps.
@@ -136,7 +136,7 @@ func TestModuleConfigShTest(t *testing.T) {
options: [{name: "SomeName", value: "OptionValue"}],
}
`)
- derived := ctx.ModuleForTests("conch", variant) //
+ derived := ctx.ModuleForTests(t, "conch", variant) //
conch := derived.Module().(*testModuleConfigModule)
android.AssertArrayString(t, "TestcaseRelDataFiles", []string{"arm64/testdata/data1", "arm64/testdata/sub/data2"}, conch.provider.TestcaseRelDataFiles)
android.AssertStringEquals(t, "Rel OutputFile", "test.sh", conch.provider.OutputFile.Rel())
@@ -191,7 +191,7 @@ func TestModuleConfigOptions(t *testing.T) {
).RunTestWithBp(t, bp)
// Check that we generate a rule to make a new AndroidTest.xml/Module.config file.
- derived := ctx.ModuleForTests("derived_test", variant)
+ derived := ctx.ModuleForTests(t, "derived_test", variant)
rule_cmd := derived.Rule("fix_test_config").RuleParams.Command
android.AssertStringDoesContain(t, "Bad FixConfig rule inputs", rule_cmd,
`--test-runner-options='[{"Name":"exclude-filter","Key":"","Value":"android.test.example.devcodelab.DevCodelabTest#testHelloFail"},{"Name":"include-annotation","Key":"","Value":"android.platform.test.annotations.LargeTest"}]'`)
@@ -288,7 +288,7 @@ func TestModuleConfigNoFiltersOrAnnotationsShouldFail(t *testing.T) {
).ExtendWithErrorHandler(
android.FixtureExpectsAtLeastOneErrorMatchingPattern("Test options must be given")).
RunTestWithBp(t, badBp)
- ctx.ModuleForTests("derived_test", variant)
+ ctx.ModuleForTests(t, "derived_test", variant)
}
func TestModuleConfigMultipleDerivedTestsWriteDistinctMakeEntries(t *testing.T) {
@@ -326,7 +326,7 @@ func TestModuleConfigMultipleDerivedTestsWriteDistinctMakeEntries(t *testing.T)
).RunTestWithBp(t, multiBp)
{
- derived := ctx.ModuleForTests("derived_test", variant)
+ derived := ctx.ModuleForTests(t, "derived_test", variant)
entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, derived.Module())[0]
// All these should be the same in both derived tests
android.AssertStringPathsRelativeToTopEquals(t, "support-files", ctx.Config,
@@ -342,7 +342,7 @@ func TestModuleConfigMultipleDerivedTestsWriteDistinctMakeEntries(t *testing.T)
}
{
- derived := ctx.ModuleForTests("another_derived_test", variant)
+ derived := ctx.ModuleForTests(t, "another_derived_test", variant)
entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, derived.Module())[0]
// All these should be the same in both derived tests
android.AssertStringPathsRelativeToTopEquals(t, "support-files", ctx.Config,
@@ -381,7 +381,7 @@ func TestModuleConfigHostBasics(t *testing.T) {
).RunTestWithBp(t, bp)
variant := ctx.Config.BuildOS.String() + "_common"
- derived := ctx.ModuleForTests("derived_test", variant)
+ derived := ctx.ModuleForTests(t, "derived_test", variant)
mod := derived.Module().(*testModuleConfigHostModule)
allEntries := android.AndroidMkEntriesForTest(t, ctx.TestContext, mod)
entries := allEntries[0]
diff --git a/tradefed_modules/test_suite_test.go b/tradefed_modules/test_suite_test.go
index 3c0a9eb2c..3e1472cee 100644
--- a/tradefed_modules/test_suite_test.go
+++ b/tradefed_modules/test_suite_test.go
@@ -46,7 +46,7 @@ func TestTestSuites(t *testing.T) {
]
}
`)
- manifestPath := ctx.ModuleForTests("my-suite", "android_common").Output("out/soong/test_suites/my-suite/my-suite.json")
+ manifestPath := ctx.ModuleForTests(t, "my-suite", "android_common").Output("out/soong/test_suites/my-suite/my-suite.json")
var actual testSuiteManifest
if err := json.Unmarshal([]byte(android.ContentFromFileRuleForTests(t, ctx.TestContext, manifestPath)), &actual); err != nil {
t.Errorf("failed to unmarshal manifest: %v", err)
@@ -106,7 +106,7 @@ func TestTestSuitesWithNested(t *testing.T) {
]
}
`)
- manifestPath := ctx.ModuleForTests("my-all-tests-suite", "android_common").Output("out/soong/test_suites/my-all-tests-suite/my-all-tests-suite.json")
+ manifestPath := ctx.ModuleForTests(t, "my-all-tests-suite", "android_common").Output("out/soong/test_suites/my-all-tests-suite/my-all-tests-suite.json")
var actual testSuiteManifest
if err := json.Unmarshal([]byte(android.ContentFromFileRuleForTests(t, ctx.TestContext, manifestPath)), &actual); err != nil {
t.Errorf("failed to unmarshal manifest: %v", err)