blob: f9baa465cb7ba7fdbd734d343cbbc6f5355a8e75 [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 (
18 "android/soong/android"
yelinhsieh80880a32018-11-06 11:49:55 +080019 "android/soong/tradefed"
Nan Zhang5323f8e2017-05-10 13:37:54 -070020)
21
22// This file contains the module types for building Python test.
23
24func init() {
25 android.RegisterModuleType("python_test_host", PythonTestHostFactory)
Nan Zhangd9ec5e72017-12-01 20:00:31 +000026 android.RegisterModuleType("python_test", PythonTestFactory)
Nan Zhang5323f8e2017-05-10 13:37:54 -070027}
28
Dan Shid79572f2020-11-13 14:33:46 -080029// Test option struct.
30type TestOptions struct {
31 // If the test is a hostside(no device required) unittest that shall be run during presubmit check.
32 Unit_test *bool
33}
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
48 // Test options.
49 Test_options TestOptions
Julien Despreze146e392018-08-02 15:00:46 -070050}
51
Nan Zhangd4e641b2017-07-12 12:55:28 -070052type testDecorator struct {
53 *binaryDecorator
Julien Despreze146e392018-08-02 15:00:46 -070054
55 testProperties TestProperties
yelinhsieh80880a32018-11-06 11:49:55 +080056
57 testConfig android.Path
Dan Shi31949122020-09-21 12:11:02 -070058
59 data []android.DataPath
Julien Despreze146e392018-08-02 15:00:46 -070060}
61
62func (test *testDecorator) bootstrapperProps() []interface{} {
63 return append(test.binaryDecorator.bootstrapperProps(), &test.testProperties)
Nan Zhang5323f8e2017-05-10 13:37:54 -070064}
65
Nan Zhangd4e641b2017-07-12 12:55:28 -070066func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) {
yelinhsieh80880a32018-11-06 11:49:55 +080067 test.testConfig = tradefed.AutoGenPythonBinaryHostTestConfig(ctx, test.testProperties.Test_config,
Dan Shi6ffaaa82019-09-26 11:41:36 -070068 test.testProperties.Test_config_template, test.binaryDecorator.binaryProperties.Test_suites,
69 test.binaryDecorator.binaryProperties.Auto_gen_config)
yelinhsieh80880a32018-11-06 11:49:55 +080070
Nan Zhangd9ec5e72017-12-01 20:00:31 +000071 test.binaryDecorator.pythonInstaller.dir = "nativetest"
72 test.binaryDecorator.pythonInstaller.dir64 = "nativetest64"
73
74 test.binaryDecorator.pythonInstaller.relative = ctx.ModuleName()
75
76 test.binaryDecorator.pythonInstaller.install(ctx, file)
Dan Shi31949122020-09-21 12:11:02 -070077
78 dataSrcPaths := android.PathsForModuleSrc(ctx, test.testProperties.Data)
79
80 for _, dataSrcPath := range dataSrcPaths {
81 test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
82 }
Nan Zhang5323f8e2017-05-10 13:37:54 -070083}
84
Nan Zhangd4e641b2017-07-12 12:55:28 -070085func NewTest(hod android.HostOrDeviceSupported) *Module {
86 module, binary := NewBinary(hod)
87
Nan Zhangd9ec5e72017-12-01 20:00:31 +000088 binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64")
Nan Zhangd4e641b2017-07-12 12:55:28 -070089
90 test := &testDecorator{binaryDecorator: binary}
91
92 module.bootstrapper = test
93 module.installer = test
94
95 return module
Nan Zhang5323f8e2017-05-10 13:37:54 -070096}
97
Colin Cross36242852017-06-23 15:06:31 -070098func PythonTestHostFactory() android.Module {
Nan Zhangd4e641b2017-07-12 12:55:28 -070099 module := NewTest(android.HostSupportedNoCross)
Nan Zhang5323f8e2017-05-10 13:37:54 -0700100
Nan Zhangd4e641b2017-07-12 12:55:28 -0700101 return module.Init()
Nan Zhang5323f8e2017-05-10 13:37:54 -0700102}
Nan Zhangd9ec5e72017-12-01 20:00:31 +0000103
104func PythonTestFactory() android.Module {
105 module := NewTest(android.HostAndDeviceSupported)
106 module.multilib = android.MultilibBoth
107
108 return module.Init()
109}