blob: adcc15a6e97dde899f204fef1f7dc94cd72de6f7 [file] [log] [blame]
Colin Cross8eebb132020-01-29 20:07:03 -08001// 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
15package android
16
17func init() {
LaMont Jones0c10e4d2023-05-16 00:58:37 +000018 RegisterParallelSingletonType("testsuites", testSuiteFilesFactory)
Colin Cross8eebb132020-01-29 20:07:03 -080019}
20
21func testSuiteFilesFactory() Singleton {
22 return &testSuiteFiles{}
23}
24
25type testSuiteFiles struct {
26 robolectric WritablePath
Makoto Onuki4a9869d2023-10-20 10:42:47 -070027 ravenwood WritablePath
Colin Cross8eebb132020-01-29 20:07:03 -080028}
29
30type TestSuiteModule interface {
31 Module
32 TestSuites() []string
33}
34
35func (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 Park4dc2a1a2020-09-28 17:46:22 +090045 files[testSuite][name] = append(files[testSuite][name], tsm.FilesToInstall()...)
Colin Cross8eebb132020-01-29 20:07:03 -080046 }
47 }
48 })
49
50 t.robolectric = robolectricTestSuite(ctx, files["robolectric-tests"])
Colin Crosscf0e4222020-07-20 17:19:02 -070051 ctx.Phony("robolectric-tests", t.robolectric)
Makoto Onuki4a9869d2023-10-20 10:42:47 -070052
53 t.ravenwood = ravenwoodTestSuite(ctx, files["ravenwood-tests"])
54 ctx.Phony("ravenwood-tests", t.ravenwood)
Colin Cross8eebb132020-01-29 20:07:03 -080055}
56
57func (t *testSuiteFiles) MakeVars(ctx MakeVarsContext) {
Colin Crosscf0e4222020-07-20 17:19:02 -070058 ctx.DistForGoal("robolectric-tests", t.robolectric)
Makoto Onuki4a9869d2023-10-20 10:42:47 -070059 ctx.DistForGoal("ravenwood-tests", t.ravenwood)
Colin Cross8eebb132020-01-29 20:07:03 -080060}
61
62func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath {
63 var installedPaths InstallPaths
Cole Faust18994c72023-02-28 16:02:16 -080064 for _, module := range SortedKeys(files) {
Colin Cross8eebb132020-01-29 20:07:03 -080065 installedPaths = append(installedPaths, files[module]...)
66 }
Cole Faust3b703f32023-10-16 13:30:51 -070067 testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases")
Colin Cross8eebb132020-01-29 20:07:03 -080068
69 outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip")
Colin Crossf1a035e2020-11-16 17:32:30 -080070 rule := NewRuleBuilder(pctx, ctx)
71 rule.Command().BuiltTool("soong_zip").
Colin Cross8eebb132020-01-29 20:07:03 -080072 FlagWithOutput("-o ", outputFile).
73 FlagWithArg("-P ", "host/testcases").
74 FlagWithArg("-C ", testCasesDir.String()).
Julien Desprezf3680732023-06-27 20:48:04 +000075 FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths()).
Cole Faust3b703f32023-10-16 13:30:51 -070076 Flag("-sha256")
Colin Crossf1a035e2020-11-16 17:32:30 -080077 rule.Build("robolectric_tests_zip", "robolectric-tests.zip")
Colin Cross8eebb132020-01-29 20:07:03 -080078
79 return outputFile
80}
Makoto Onuki4a9869d2023-10-20 10:42:47 -070081
82func 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}