test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2017 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 python
  15. import (
  16. "github.com/google/blueprint/proptools"
  17. "android/soong/android"
  18. "android/soong/tradefed"
  19. )
  20. // This file contains the module types for building Python test.
  21. func init() {
  22. registerPythonTestComponents(android.InitRegistrationContext)
  23. }
  24. func registerPythonTestComponents(ctx android.RegistrationContext) {
  25. ctx.RegisterModuleType("python_test_host", PythonTestHostFactory)
  26. ctx.RegisterModuleType("python_test", PythonTestFactory)
  27. }
  28. type TestProperties struct {
  29. // the name of the test configuration (for example "AndroidTest.xml") that should be
  30. // installed with the module.
  31. Test_config *string `android:"path,arch_variant"`
  32. // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
  33. // should be installed with the module.
  34. Test_config_template *string `android:"path,arch_variant"`
  35. // list of files or filegroup modules that provide data that should be installed alongside
  36. // the test
  37. Data []string `android:"path,arch_variant"`
  38. // list of java modules that provide data that should be installed alongside the test.
  39. Java_data []string
  40. // Test options.
  41. Test_options android.CommonTestOptions
  42. }
  43. type testDecorator struct {
  44. *binaryDecorator
  45. testProperties TestProperties
  46. testConfig android.Path
  47. data []android.DataPath
  48. }
  49. func (test *testDecorator) bootstrapperProps() []interface{} {
  50. return append(test.binaryDecorator.bootstrapperProps(), &test.testProperties)
  51. }
  52. func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) {
  53. test.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
  54. TestConfigProp: test.testProperties.Test_config,
  55. TestConfigTemplateProp: test.testProperties.Test_config_template,
  56. TestSuites: test.binaryDecorator.binaryProperties.Test_suites,
  57. AutoGenConfig: test.binaryDecorator.binaryProperties.Auto_gen_config,
  58. DeviceTemplate: "${PythonBinaryHostTestConfigTemplate}",
  59. HostTemplate: "${PythonBinaryHostTestConfigTemplate}",
  60. })
  61. test.binaryDecorator.pythonInstaller.dir = "nativetest"
  62. test.binaryDecorator.pythonInstaller.dir64 = "nativetest64"
  63. test.binaryDecorator.pythonInstaller.relative = ctx.ModuleName()
  64. test.binaryDecorator.pythonInstaller.install(ctx, file)
  65. dataSrcPaths := android.PathsForModuleSrc(ctx, test.testProperties.Data)
  66. for _, dataSrcPath := range dataSrcPaths {
  67. test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
  68. }
  69. // Emulate the data property for java_data dependencies.
  70. for _, javaData := range ctx.GetDirectDepsWithTag(javaDataTag) {
  71. for _, javaDataSrcPath := range android.OutputFilesForModule(ctx, javaData, "") {
  72. test.data = append(test.data, android.DataPath{SrcPath: javaDataSrcPath})
  73. }
  74. }
  75. }
  76. func NewTest(hod android.HostOrDeviceSupported) *Module {
  77. module, binary := NewBinary(hod)
  78. binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64")
  79. test := &testDecorator{binaryDecorator: binary}
  80. if hod == android.HostSupportedNoCross && test.testProperties.Test_options.Unit_test == nil {
  81. test.testProperties.Test_options.Unit_test = proptools.BoolPtr(true)
  82. }
  83. module.bootstrapper = test
  84. module.installer = test
  85. return module
  86. }
  87. func PythonTestHostFactory() android.Module {
  88. module := NewTest(android.HostSupportedNoCross)
  89. return module.init()
  90. }
  91. func PythonTestFactory() android.Module {
  92. module := NewTest(android.HostAndDeviceSupported)
  93. module.multilib = android.MultilibBoth
  94. return module.init()
  95. }