| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 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 |  | 
|  | 15 | package python | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
| yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 19 | "android/soong/tradefed" | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 20 | ) | 
|  | 21 |  | 
|  | 22 | // This file contains the module types for building Python test. | 
|  | 23 |  | 
|  | 24 | func init() { | 
|  | 25 | android.RegisterModuleType("python_test_host", PythonTestHostFactory) | 
| Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 26 | android.RegisterModuleType("python_test", PythonTestFactory) | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 27 | } | 
|  | 28 |  | 
| Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 29 | type 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"` | 
| yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 33 |  | 
|  | 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 Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 39 | type testDecorator struct { | 
|  | 40 | *binaryDecorator | 
| Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 41 |  | 
|  | 42 | testProperties TestProperties | 
| yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 43 |  | 
|  | 44 | testConfig android.Path | 
| Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 45 | } | 
|  | 46 |  | 
|  | 47 | func (test *testDecorator) bootstrapperProps() []interface{} { | 
|  | 48 | return append(test.binaryDecorator.bootstrapperProps(), &test.testProperties) | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 51 | func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) { | 
| yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 52 | test.testConfig = tradefed.AutoGenPythonBinaryHostTestConfig(ctx, test.testProperties.Test_config, | 
| Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 53 | test.testProperties.Test_config_template, test.binaryDecorator.binaryProperties.Test_suites, | 
|  | 54 | test.binaryDecorator.binaryProperties.Auto_gen_config) | 
| yelinhsieh | 80880a3 | 2018-11-06 11:49:55 +0800 | [diff] [blame] | 55 |  | 
| Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 56 | 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 Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 62 | } | 
|  | 63 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 64 | func NewTest(hod android.HostOrDeviceSupported) *Module { | 
|  | 65 | module, binary := NewBinary(hod) | 
|  | 66 |  | 
| Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 67 | binary.pythonInstaller = NewPythonInstaller("nativetest", "nativetest64") | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 68 |  | 
|  | 69 | test := &testDecorator{binaryDecorator: binary} | 
|  | 70 |  | 
|  | 71 | module.bootstrapper = test | 
|  | 72 | module.installer = test | 
|  | 73 |  | 
|  | 74 | return module | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 75 | } | 
|  | 76 |  | 
| Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 77 | func PythonTestHostFactory() android.Module { | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 78 | module := NewTest(android.HostSupportedNoCross) | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 79 |  | 
| Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 80 | return module.Init() | 
| Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 81 | } | 
| Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 82 |  | 
|  | 83 | func PythonTestFactory() android.Module { | 
|  | 84 | module := NewTest(android.HostAndDeviceSupported) | 
|  | 85 | module.multilib = android.MultilibBoth | 
|  | 86 |  | 
|  | 87 | return module.Init() | 
|  | 88 | } |