blob: f684fd51dbe700fb3552c9b126587e36529a4676 [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
Julien Despreze146e392018-08-02 15:00:46 -070029type TestProperties struct {
30 // the name of the test configuration (for example "AndroidTest.xml") that should be
31 // installed with the module.
32 Test_config *string `android:"arch_variant"`
yelinhsieh80880a32018-11-06 11:49:55 +080033
34 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
35 // should be installed with the module.
36 Test_config_template *string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -070037}
38
Nan Zhangd4e641b2017-07-12 12:55:28 -070039type testDecorator struct {
40 *binaryDecorator
Julien Despreze146e392018-08-02 15:00:46 -070041
42 testProperties TestProperties
yelinhsieh80880a32018-11-06 11:49:55 +080043
44 testConfig android.Path
Julien Despreze146e392018-08-02 15:00:46 -070045}
46
47func (test *testDecorator) bootstrapperProps() []interface{} {
48 return append(test.binaryDecorator.bootstrapperProps(), &test.testProperties)
Nan Zhang5323f8e2017-05-10 13:37:54 -070049}
50
Nan Zhangd4e641b2017-07-12 12:55:28 -070051func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) {
yelinhsieh80880a32018-11-06 11:49:55 +080052 test.testConfig = tradefed.AutoGenPythonBinaryHostTestConfig(ctx, test.testProperties.Test_config,
Dan Shi6ffaaa82019-09-26 11:41:36 -070053 test.testProperties.Test_config_template, test.binaryDecorator.binaryProperties.Test_suites,
54 test.binaryDecorator.binaryProperties.Auto_gen_config)
yelinhsieh80880a32018-11-06 11:49:55 +080055
Nan Zhangd9ec5e72017-12-01 20:00:31 +000056 test.binaryDecorator.pythonInstaller.dir = "nativetest"
57 test.binaryDecorator.pythonInstaller.dir64 = "nativetest64"
58
59 test.binaryDecorator.pythonInstaller.relative = ctx.ModuleName()
60
61 test.binaryDecorator.pythonInstaller.install(ctx, file)
Nan Zhang5323f8e2017-05-10 13:37:54 -070062}
63
Nan Zhangd4e641b2017-07-12 12:55:28 -070064func NewTest(hod android.HostOrDeviceSupported) *Module {
65 module, binary := NewBinary(hod)
66
Nan Zhangd9ec5e72017-12-01 20:00:31 +000067 binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64")
Nan Zhangd4e641b2017-07-12 12:55:28 -070068
69 test := &testDecorator{binaryDecorator: binary}
70
71 module.bootstrapper = test
72 module.installer = test
73
74 return module
Nan Zhang5323f8e2017-05-10 13:37:54 -070075}
76
Colin Cross36242852017-06-23 15:06:31 -070077func PythonTestHostFactory() android.Module {
Nan Zhangd4e641b2017-07-12 12:55:28 -070078 module := NewTest(android.HostSupportedNoCross)
Nan Zhang5323f8e2017-05-10 13:37:54 -070079
Nan Zhangd4e641b2017-07-12 12:55:28 -070080 return module.Init()
Nan Zhang5323f8e2017-05-10 13:37:54 -070081}
Nan Zhangd9ec5e72017-12-01 20:00:31 +000082
83func PythonTestFactory() android.Module {
84 module := NewTest(android.HostAndDeviceSupported)
85 module.multilib = android.MultilibBoth
86
87 return module.Init()
88}