Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 1 | // Copyright 2020 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package android |
| 16 | |
| 17 | func init() { |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 18 | RegisterParallelSingletonType("testsuites", testSuiteFilesFactory) |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | func testSuiteFilesFactory() Singleton { |
| 22 | return &testSuiteFiles{} |
| 23 | } |
| 24 | |
| 25 | type testSuiteFiles struct { |
| 26 | robolectric WritablePath |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame^] | 27 | ravenwood WritablePath |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | type TestSuiteModule interface { |
| 31 | Module |
| 32 | TestSuites() []string |
| 33 | } |
| 34 | |
| 35 | func (t *testSuiteFiles) GenerateBuildActions(ctx SingletonContext) { |
| 36 | files := make(map[string]map[string]InstallPaths) |
| 37 | |
| 38 | ctx.VisitAllModules(func(m Module) { |
| 39 | if tsm, ok := m.(TestSuiteModule); ok { |
| 40 | for _, testSuite := range tsm.TestSuites() { |
| 41 | if files[testSuite] == nil { |
| 42 | files[testSuite] = make(map[string]InstallPaths) |
| 43 | } |
| 44 | name := ctx.ModuleName(m) |
Jiyong Park | 4dc2a1a | 2020-09-28 17:46:22 +0900 | [diff] [blame] | 45 | files[testSuite][name] = append(files[testSuite][name], tsm.FilesToInstall()...) |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | }) |
| 49 | |
| 50 | t.robolectric = robolectricTestSuite(ctx, files["robolectric-tests"]) |
Colin Cross | cf0e422 | 2020-07-20 17:19:02 -0700 | [diff] [blame] | 51 | ctx.Phony("robolectric-tests", t.robolectric) |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame^] | 52 | |
| 53 | t.ravenwood = ravenwoodTestSuite(ctx, files["ravenwood-tests"]) |
| 54 | ctx.Phony("ravenwood-tests", t.ravenwood) |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | func (t *testSuiteFiles) MakeVars(ctx MakeVarsContext) { |
Colin Cross | cf0e422 | 2020-07-20 17:19:02 -0700 | [diff] [blame] | 58 | ctx.DistForGoal("robolectric-tests", t.robolectric) |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame^] | 59 | ctx.DistForGoal("ravenwood-tests", t.ravenwood) |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath { |
| 63 | var installedPaths InstallPaths |
Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 64 | for _, module := range SortedKeys(files) { |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 65 | installedPaths = append(installedPaths, files[module]...) |
| 66 | } |
Cole Faust | 3b703f3 | 2023-10-16 13:30:51 -0700 | [diff] [blame] | 67 | testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases") |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 68 | |
| 69 | outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 70 | rule := NewRuleBuilder(pctx, ctx) |
| 71 | rule.Command().BuiltTool("soong_zip"). |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 72 | FlagWithOutput("-o ", outputFile). |
| 73 | FlagWithArg("-P ", "host/testcases"). |
| 74 | FlagWithArg("-C ", testCasesDir.String()). |
Julien Desprez | f368073 | 2023-06-27 20:48:04 +0000 | [diff] [blame] | 75 | FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths()). |
Cole Faust | 3b703f3 | 2023-10-16 13:30:51 -0700 | [diff] [blame] | 76 | Flag("-sha256") |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 77 | rule.Build("robolectric_tests_zip", "robolectric-tests.zip") |
Colin Cross | 8eebb13 | 2020-01-29 20:07:03 -0800 | [diff] [blame] | 78 | |
| 79 | return outputFile |
| 80 | } |
Makoto Onuki | 4a9869d | 2023-10-20 10:42:47 -0700 | [diff] [blame^] | 81 | |
| 82 | func ravenwoodTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath { |
| 83 | var installedPaths InstallPaths |
| 84 | for _, module := range SortedKeys(files) { |
| 85 | installedPaths = append(installedPaths, files[module]...) |
| 86 | } |
| 87 | testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases") |
| 88 | |
| 89 | outputFile := PathForOutput(ctx, "packaging", "ravenwood-tests.zip") |
| 90 | rule := NewRuleBuilder(pctx, ctx) |
| 91 | rule.Command().BuiltTool("soong_zip"). |
| 92 | FlagWithOutput("-o ", outputFile). |
| 93 | FlagWithArg("-P ", "host/testcases"). |
| 94 | FlagWithArg("-C ", testCasesDir.String()). |
| 95 | FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths()). |
| 96 | Flag("-sha256") |
| 97 | rule.Build("ravenwood_tests_zip", "ravenwood-tests.zip") |
| 98 | |
| 99 | return outputFile |
| 100 | } |