test_suites.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. package android
  15. func init() {
  16. RegisterParallelSingletonType("testsuites", testSuiteFilesFactory)
  17. }
  18. func testSuiteFilesFactory() Singleton {
  19. return &testSuiteFiles{}
  20. }
  21. type testSuiteFiles struct {
  22. robolectric WritablePath
  23. }
  24. type TestSuiteModule interface {
  25. Module
  26. TestSuites() []string
  27. }
  28. func (t *testSuiteFiles) GenerateBuildActions(ctx SingletonContext) {
  29. files := make(map[string]map[string]InstallPaths)
  30. ctx.VisitAllModules(func(m Module) {
  31. if tsm, ok := m.(TestSuiteModule); ok {
  32. for _, testSuite := range tsm.TestSuites() {
  33. if files[testSuite] == nil {
  34. files[testSuite] = make(map[string]InstallPaths)
  35. }
  36. name := ctx.ModuleName(m)
  37. files[testSuite][name] = append(files[testSuite][name], tsm.FilesToInstall()...)
  38. }
  39. }
  40. })
  41. t.robolectric = robolectricTestSuite(ctx, files["robolectric-tests"])
  42. ctx.Phony("robolectric-tests", t.robolectric)
  43. }
  44. func (t *testSuiteFiles) MakeVars(ctx MakeVarsContext) {
  45. ctx.DistForGoal("robolectric-tests", t.robolectric)
  46. }
  47. func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath {
  48. var installedPaths InstallPaths
  49. for _, module := range SortedKeys(files) {
  50. installedPaths = append(installedPaths, files[module]...)
  51. }
  52. testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases", false)
  53. outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip")
  54. rule := NewRuleBuilder(pctx, ctx)
  55. rule.Command().BuiltTool("soong_zip").
  56. FlagWithOutput("-o ", outputFile).
  57. FlagWithArg("-P ", "host/testcases").
  58. FlagWithArg("-C ", testCasesDir.String()).
  59. FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths())
  60. rule.Build("robolectric_tests_zip", "robolectric-tests.zip")
  61. return outputFile
  62. }