summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cole Faust <colefaust@google.com> 2025-03-11 18:31:15 -0700
committer Cole Faust <colefaust@google.com> 2025-03-11 18:31:15 -0700
commit725f838e8a98ffb00ae8d54651c3ee2a5bee6ced (patch)
tree4979be56d65e23fb2194d443992d056f59a999d0
parent9697c5303c4ee46cc43064f715b86e9bef712774 (diff)
Dedup test suite building code
In preparation for adding more test suites, dedup the code in common of the two test suites we're already building. Bug: 388850000 Test: Verified ninja files did not change Change-Id: I151c31242aad61a68f916e04602d1ff5d6fcb4ea
-rw-r--r--android/test_suites.go58
1 files changed, 13 insertions, 45 deletions
diff --git a/android/test_suites.go b/android/test_suites.go
index 39317ec62..9eaf78549 100644
--- a/android/test_suites.go
+++ b/android/test_suites.go
@@ -29,10 +29,7 @@ func testSuiteFilesFactory() Singleton {
return &testSuiteFiles{}
}
-type testSuiteFiles struct {
- robolectric []Path
- ravenwood []Path
-}
+type testSuiteFiles struct{}
type TestSuiteModule interface {
Module
@@ -61,51 +58,22 @@ func (t *testSuiteFiles) GenerateBuildActions(ctx SingletonContext) {
}
})
- t.robolectric = robolectricTestSuite(ctx, files["robolectric-tests"])
- ctx.Phony("robolectric-tests", t.robolectric...)
-
- t.ravenwood = ravenwoodTestSuite(ctx, files["ravenwood-tests"])
- ctx.Phony("ravenwood-tests", t.ravenwood...)
- ctx.DistForGoal("robolectric-tests", t.robolectric...)
- ctx.DistForGoal("ravenwood-tests", t.ravenwood...)
-}
-
-func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) []Path {
- var installedPaths InstallPaths
- for _, module := range SortedKeys(files) {
- installedPaths = append(installedPaths, files[module]...)
- }
-
- outputFile := pathForPackaging(ctx, "robolectric-tests.zip")
- rule := NewRuleBuilder(pctx, ctx)
- rule.Command().BuiltTool("soong_zip").
- FlagWithOutput("-o ", outputFile).
- FlagWithArg("-P ", "host/testcases").
- FlagWithArg("-C ", pathForTestCases(ctx).String()).
- FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths()).
- Flag("-sha256") // necessary to save cas_uploader's time
-
- testList := buildTestList(ctx, "robolectric-tests_list", installedPaths)
- testListZipOutputFile := pathForPackaging(ctx, "robolectric-tests_list.zip")
-
- rule.Command().BuiltTool("soong_zip").
- FlagWithOutput("-o ", testListZipOutputFile).
- FlagWithArg("-C ", pathForPackaging(ctx).String()).
- FlagWithInput("-f ", testList).
- Flag("-sha256")
-
- rule.Build("robolectric_tests_zip", "robolectric-tests.zip")
+ robolectricZip, robolectrictListZip := buildTestSuite(ctx, "robolectric-tests", files["robolectric-tests"])
+ ctx.Phony("robolectric-tests", robolectricZip, robolectrictListZip)
+ ctx.DistForGoal("robolectric-tests", robolectricZip, robolectrictListZip)
- return []Path{outputFile, testListZipOutputFile}
+ ravenwoodZip, ravenwoodListZip := buildTestSuite(ctx, "ravenwood-tests", files["ravenwood-tests"])
+ ctx.Phony("ravenwood-tests", ravenwoodZip, ravenwoodListZip)
+ ctx.DistForGoal("ravenwood-tests", ravenwoodZip, ravenwoodListZip)
}
-func ravenwoodTestSuite(ctx SingletonContext, files map[string]InstallPaths) []Path {
+func buildTestSuite(ctx SingletonContext, suiteName string, files map[string]InstallPaths) (Path, Path) {
var installedPaths InstallPaths
for _, module := range SortedKeys(files) {
installedPaths = append(installedPaths, files[module]...)
}
- outputFile := pathForPackaging(ctx, "ravenwood-tests.zip")
+ outputFile := pathForPackaging(ctx, suiteName+".zip")
rule := NewRuleBuilder(pctx, ctx)
rule.Command().BuiltTool("soong_zip").
FlagWithOutput("-o ", outputFile).
@@ -114,8 +82,8 @@ func ravenwoodTestSuite(ctx SingletonContext, files map[string]InstallPaths) []P
FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths()).
Flag("-sha256") // necessary to save cas_uploader's time
- testList := buildTestList(ctx, "ravenwood-tests_list", installedPaths)
- testListZipOutputFile := pathForPackaging(ctx, "ravenwood-tests_list.zip")
+ testList := buildTestList(ctx, suiteName+"_list", installedPaths)
+ testListZipOutputFile := pathForPackaging(ctx, suiteName+"_list.zip")
rule.Command().BuiltTool("soong_zip").
FlagWithOutput("-o ", testListZipOutputFile).
@@ -123,9 +91,9 @@ func ravenwoodTestSuite(ctx SingletonContext, files map[string]InstallPaths) []P
FlagWithInput("-f ", testList).
Flag("-sha256")
- rule.Build("ravenwood_tests_zip", "ravenwood-tests.zip")
+ rule.Build(strings.ReplaceAll(suiteName, "-", "_")+"_zip", suiteName+".zip")
- return []Path{outputFile, testListZipOutputFile}
+ return outputFile, testListZipOutputFile
}
func buildTestList(ctx SingletonContext, listFile string, installedPaths InstallPaths) Path {