blob: b9b34654955058200e42201773e1db1c15db2fd1 [file] [log] [blame]
Nan Zhang5323f8e2017-05-10 13:37:54 -07001// 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
15package python
16
17import (
Julien Desprez66534a02021-02-09 09:27:39 -080018 "github.com/google/blueprint/proptools"
19
Nan Zhang5323f8e2017-05-10 13:37:54 -070020 "android/soong/android"
yelinhsieh80880a32018-11-06 11:49:55 +080021 "android/soong/tradefed"
Nan Zhang5323f8e2017-05-10 13:37:54 -070022)
23
24// This file contains the module types for building Python test.
25
26func init() {
Paul Duffind0890452021-03-17 21:57:08 +000027 registerPythonTestComponents(android.InitRegistrationContext)
28}
29
30func registerPythonTestComponents(ctx android.RegistrationContext) {
31 ctx.RegisterModuleType("python_test_host", PythonTestHostFactory)
32 ctx.RegisterModuleType("python_test", PythonTestFactory)
Nan Zhang5323f8e2017-05-10 13:37:54 -070033}
34
Julien Despreze146e392018-08-02 15:00:46 -070035type TestProperties struct {
36 // the name of the test configuration (for example "AndroidTest.xml") that should be
37 // installed with the module.
Colin Crossa6384822020-06-09 15:09:22 -070038 Test_config *string `android:"path,arch_variant"`
yelinhsieh80880a32018-11-06 11:49:55 +080039
40 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
41 // should be installed with the module.
Colin Crossa6384822020-06-09 15:09:22 -070042 Test_config_template *string `android:"path,arch_variant"`
Dan Shi31949122020-09-21 12:11:02 -070043
44 // list of files or filegroup modules that provide data that should be installed alongside
45 // the test
46 Data []string `android:"path,arch_variant"`
Dan Shid79572f2020-11-13 14:33:46 -080047
Colin Cross1bc63932020-11-22 20:12:45 -080048 // list of java modules that provide data that should be installed alongside the test.
49 Java_data []string
50
Dan Shid79572f2020-11-13 14:33:46 -080051 // Test options.
Zhenhuang Wang0ac5a432022-08-12 18:49:20 +080052 Test_options android.CommonTestOptions
Julien Despreze146e392018-08-02 15:00:46 -070053}
54
Nan Zhangd4e641b2017-07-12 12:55:28 -070055type testDecorator struct {
56 *binaryDecorator
Julien Despreze146e392018-08-02 15:00:46 -070057
58 testProperties TestProperties
yelinhsieh80880a32018-11-06 11:49:55 +080059
60 testConfig android.Path
Dan Shi31949122020-09-21 12:11:02 -070061
62 data []android.DataPath
Julien Despreze146e392018-08-02 15:00:46 -070063}
64
65func (test *testDecorator) bootstrapperProps() []interface{} {
66 return append(test.binaryDecorator.bootstrapperProps(), &test.testProperties)
Nan Zhang5323f8e2017-05-10 13:37:54 -070067}
68
Nan Zhangd4e641b2017-07-12 12:55:28 -070069func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) {
yelinhsieh80880a32018-11-06 11:49:55 +080070 test.testConfig = tradefed.AutoGenPythonBinaryHostTestConfig(ctx, test.testProperties.Test_config,
Dan Shi6ffaaa82019-09-26 11:41:36 -070071 test.testProperties.Test_config_template, test.binaryDecorator.binaryProperties.Test_suites,
72 test.binaryDecorator.binaryProperties.Auto_gen_config)
yelinhsieh80880a32018-11-06 11:49:55 +080073
Nan Zhangd9ec5e72017-12-01 20:00:31 +000074 test.binaryDecorator.pythonInstaller.dir = "nativetest"
75 test.binaryDecorator.pythonInstaller.dir64 = "nativetest64"
76
77 test.binaryDecorator.pythonInstaller.relative = ctx.ModuleName()
78
79 test.binaryDecorator.pythonInstaller.install(ctx, file)
Dan Shi31949122020-09-21 12:11:02 -070080
81 dataSrcPaths := android.PathsForModuleSrc(ctx, test.testProperties.Data)
82
83 for _, dataSrcPath := range dataSrcPaths {
84 test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
85 }
Colin Cross1bc63932020-11-22 20:12:45 -080086
87 // Emulate the data property for java_data dependencies.
88 for _, javaData := range ctx.GetDirectDepsWithTag(javaDataTag) {
89 for _, javaDataSrcPath := range android.OutputFilesForModule(ctx, javaData, "") {
90 test.data = append(test.data, android.DataPath{SrcPath: javaDataSrcPath})
91 }
92 }
Nan Zhang5323f8e2017-05-10 13:37:54 -070093}
94
Nan Zhangd4e641b2017-07-12 12:55:28 -070095func NewTest(hod android.HostOrDeviceSupported) *Module {
96 module, binary := NewBinary(hod)
97
Rupert Shuttleworthffc4cc42021-11-03 09:07:26 +000098 binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64")
Nan Zhangd4e641b2017-07-12 12:55:28 -070099
100 test := &testDecorator{binaryDecorator: binary}
Julien Desprez66534a02021-02-09 09:27:39 -0800101 if hod == android.HostSupportedNoCross && test.testProperties.Test_options.Unit_test == nil {
102 test.testProperties.Test_options.Unit_test = proptools.BoolPtr(true)
103 }
Nan Zhangd4e641b2017-07-12 12:55:28 -0700104
105 module.bootstrapper = test
106 module.installer = test
107
108 return module
Nan Zhang5323f8e2017-05-10 13:37:54 -0700109}
110
Colin Cross36242852017-06-23 15:06:31 -0700111func PythonTestHostFactory() android.Module {
Nan Zhangd4e641b2017-07-12 12:55:28 -0700112 module := NewTest(android.HostSupportedNoCross)
Nan Zhang5323f8e2017-05-10 13:37:54 -0700113
Liz Kammerd737d022020-11-16 15:42:51 -0800114 return module.init()
Nan Zhang5323f8e2017-05-10 13:37:54 -0700115}
Nan Zhangd9ec5e72017-12-01 20:00:31 +0000116
117func PythonTestFactory() android.Module {
118 module := NewTest(android.HostAndDeviceSupported)
119 module.multilib = android.MultilibBoth
120
Liz Kammerd737d022020-11-16 15:42:51 -0800121 return module.init()
Nan Zhangd9ec5e72017-12-01 20:00:31 +0000122}