Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 cc |
| 16 | |
| 17 | import ( |
| 18 | "path/filepath" |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 19 | "strconv" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 20 | "strings" |
| 21 | |
Julien Desprez | 3b933d3 | 2021-01-14 11:49:15 -0800 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
| 23 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 24 | "android/soong/android" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 25 | "android/soong/tradefed" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 28 | type TestProperties struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 29 | // if set, build against the gtest library. Defaults to true. |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 30 | Gtest *bool |
Christopher Ferris | 9df92d6 | 2018-08-21 12:40:08 -0700 | [diff] [blame] | 31 | |
| 32 | // if set, use the isolated gtest runner. Defaults to false. |
| 33 | Isolated *bool |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 34 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 35 | |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame] | 36 | // Test option struct. |
| 37 | type TestOptions struct { |
| 38 | // The UID that you want to run the test as on a device. |
| 39 | Run_test_as *string |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 40 | |
David Srbecky | 519db27 | 2020-06-18 18:07:00 +0100 | [diff] [blame] | 41 | // A list of free-formed strings without spaces that categorize the test. |
| 42 | Test_suite_tag []string |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 43 | |
| 44 | // a list of extra test configuration files that should be installed with the module. |
| 45 | Extra_test_configs []string `android:"path,arch_variant"` |
Dan Shi | d79572f | 2020-11-13 14:33:46 -0800 | [diff] [blame] | 46 | |
| 47 | // If the test is a hostside(no device required) unittest that shall be run during presubmit check. |
| 48 | Unit_test *bool |
Justin Yun | 46f6605 | 2021-05-04 18:42:24 +0900 | [diff] [blame] | 49 | |
| 50 | // Add ShippingApiLevelModuleController to auto generated test config. If the device properties |
Justin Yun | a364cfb | 2021-05-13 12:39:42 +0900 | [diff] [blame] | 51 | // for the shipping api level is less than the min_shipping_api_level, skip this module. |
| 52 | Min_shipping_api_level *int64 |
| 53 | |
| 54 | // Add ShippingApiLevelModuleController to auto generated test config. If any of the device |
| 55 | // shipping api level and vendor api level properties are less than the |
| 56 | // vsr_min_shipping_api_level, skip this module. |
| 57 | // As this includes the shipping api level check, it is not allowed to define |
| 58 | // min_shipping_api_level at the same time with this property. |
| 59 | Vsr_min_shipping_api_level *int64 |
Justin Yun | 46f6605 | 2021-05-04 18:42:24 +0900 | [diff] [blame] | 60 | |
| 61 | // Add MinApiLevelModuleController with ro.vndk.version property. If ro.vndk.version has an |
Justin Yun | a364cfb | 2021-05-13 12:39:42 +0900 | [diff] [blame] | 62 | // integer value and the value is less than the min_vndk_version, skip this module. |
| 63 | Min_vndk_version *int64 |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 66 | type TestBinaryProperties struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 67 | // Create a separate binary for each source file. Useful when there is |
| 68 | // global state that can not be torn down and reset between each test suite. |
| 69 | Test_per_src *bool |
Dan Willemsen | 3340d60 | 2016-12-27 14:40:40 -0800 | [diff] [blame] | 70 | |
| 71 | // Disables the creation of a test-specific directory when used with |
| 72 | // relative_install_path. Useful if several tests need to be in the same |
| 73 | // directory, but test_per_src doesn't work. |
| 74 | No_named_install_directory *bool |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 75 | |
| 76 | // list of files or filegroup modules that provide data that should be installed alongside |
| 77 | // the test |
Dan Shi | 67a8834 | 2020-02-25 16:34:39 -0800 | [diff] [blame] | 78 | Data []string `android:"path,arch_variant"` |
Colin Cross | a929db0 | 2017-03-27 16:27:50 -0700 | [diff] [blame] | 79 | |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 80 | // list of shared library modules that should be installed alongside the test |
| 81 | Data_libs []string `android:"arch_variant"` |
| 82 | |
Colin Cross | a929db0 | 2017-03-27 16:27:50 -0700 | [diff] [blame] | 83 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 84 | // installed into. |
Dan Willemsen | 15d54d5 | 2017-09-18 16:49:28 -0700 | [diff] [blame] | 85 | Test_suites []string `android:"arch_variant"` |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 86 | |
| 87 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 88 | // installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 89 | Test_config *string `android:"path,arch_variant"` |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 90 | |
| 91 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 92 | // should be installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 93 | Test_config_template *string `android:"path,arch_variant"` |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame] | 94 | |
| 95 | // Test options. |
| 96 | Test_options TestOptions |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 97 | |
| 98 | // Add RootTargetPreparer to auto generated test config. This guarantees the test to run |
| 99 | // with root permission. |
| 100 | Require_root *bool |
Dan Shi | 20ccd21 | 2019-08-27 10:37:24 -0700 | [diff] [blame] | 101 | |
| 102 | // Add RunCommandTargetPreparer to stop framework before the test and start it after the test. |
| 103 | Disable_framework *bool |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 104 | |
Justin Yun | 107a4cb | 2021-02-10 13:46:50 +0900 | [diff] [blame] | 105 | // Add ShippingApiLevelModuleController to auto generated test config. If the device properties |
| 106 | // for the shipping api level is less than the test_min_api_level, skip this module. |
Justin Yun | a364cfb | 2021-05-13 12:39:42 +0900 | [diff] [blame] | 107 | // Deprecated (b/187258404). Use test_options.min_shipping_api_level instead. |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 108 | Test_min_api_level *int64 |
| 109 | |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 110 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml |
| 111 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true |
| 112 | // explicitly. |
| 113 | Auto_gen_config *bool |
easoncylee | 1e3fdcd | 2020-04-30 10:08:33 +0800 | [diff] [blame] | 114 | |
| 115 | // Add parameterized mainline modules to auto generated test config. The options will be |
| 116 | // handled by TradeFed to download and install the specified modules on the device. |
| 117 | Test_mainline_modules []string |
Colin Cross | cfb0f5e | 2021-09-24 15:47:17 -0700 | [diff] [blame^] | 118 | |
| 119 | // Install the test into a folder named for the module in all test suites. |
| 120 | Per_testcase_directory *bool |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | func init() { |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 124 | android.RegisterModuleType("cc_test", TestFactory) |
| 125 | android.RegisterModuleType("cc_test_library", TestLibraryFactory) |
| 126 | android.RegisterModuleType("cc_benchmark", BenchmarkFactory) |
| 127 | android.RegisterModuleType("cc_test_host", TestHostFactory) |
| 128 | android.RegisterModuleType("cc_benchmark_host", BenchmarkHostFactory) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 131 | // cc_test generates a test config file and an executable binary file to test |
| 132 | // specific functionality on a device. The executable binary gets an implicit |
| 133 | // static_libs dependency on libgtests unless the gtest flag is set to false. |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 134 | func TestFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 135 | module := NewTest(android.HostAndDeviceSupported) |
| 136 | return module.Init() |
| 137 | } |
| 138 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 139 | // cc_test_library creates an archive of files (i.e. .o files) which is later |
| 140 | // referenced by another module (such as cc_test, cc_defaults or cc_test_library) |
| 141 | // for archiving or linking. |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 142 | func TestLibraryFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 143 | module := NewTestLibrary(android.HostAndDeviceSupported) |
| 144 | return module.Init() |
| 145 | } |
| 146 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 147 | // cc_benchmark compiles an executable binary that performs benchmark testing |
| 148 | // of a specific component in a device. Additional files such as test suites |
| 149 | // and test configuration are installed on the side of the compiled executed |
| 150 | // binary. |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 151 | func BenchmarkFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 152 | module := NewBenchmark(android.HostAndDeviceSupported) |
| 153 | return module.Init() |
| 154 | } |
| 155 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 156 | // cc_test_host compiles a test host binary. |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 157 | func TestHostFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 158 | module := NewTest(android.HostSupported) |
| 159 | return module.Init() |
| 160 | } |
| 161 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 162 | // cc_benchmark_host compiles an executable binary that performs benchmark |
| 163 | // testing of a specific component in the host. Additional files such as |
| 164 | // test suites and test configuration are installed on the side of the |
| 165 | // compiled executed binary. |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 166 | func BenchmarkHostFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 167 | module := NewBenchmark(android.HostSupported) |
| 168 | return module.Init() |
| 169 | } |
| 170 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 171 | type testPerSrc interface { |
| 172 | testPerSrc() bool |
| 173 | srcs() []string |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 174 | isAllTestsVariation() bool |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 175 | setSrc(string, string) |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 176 | unsetSrc() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | func (test *testBinary) testPerSrc() bool { |
| 180 | return Bool(test.Properties.Test_per_src) |
| 181 | } |
| 182 | |
| 183 | func (test *testBinary) srcs() []string { |
| 184 | return test.baseCompiler.Properties.Srcs |
| 185 | } |
| 186 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 187 | func (test *testBinary) dataPaths() []android.DataPath { |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 188 | return test.data |
| 189 | } |
| 190 | |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 191 | func (test *testBinary) isAllTestsVariation() bool { |
| 192 | stem := test.binaryDecorator.Properties.Stem |
| 193 | return stem != nil && *stem == "" |
| 194 | } |
| 195 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 196 | func (test *testBinary) setSrc(name, src string) { |
| 197 | test.baseCompiler.Properties.Srcs = []string{src} |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 198 | test.binaryDecorator.Properties.Stem = StringPtr(name) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 201 | func (test *testBinary) unsetSrc() { |
| 202 | test.baseCompiler.Properties.Srcs = nil |
| 203 | test.binaryDecorator.Properties.Stem = StringPtr("") |
| 204 | } |
| 205 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 206 | var _ testPerSrc = (*testBinary)(nil) |
| 207 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 208 | func TestPerSrcMutator(mctx android.BottomUpMutatorContext) { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 209 | if m, ok := mctx.Module().(*Module); ok { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 210 | if test, ok := m.linker.(testPerSrc); ok { |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 211 | numTests := len(test.srcs()) |
| 212 | if test.testPerSrc() && numTests > 0 { |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 213 | if duplicate, found := android.CheckDuplicate(test.srcs()); found { |
Jooyung Han | a61ff2c | 2019-02-28 18:06:34 +0900 | [diff] [blame] | 214 | mctx.PropertyErrorf("srcs", "found a duplicate entry %q", duplicate) |
| 215 | return |
| 216 | } |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 217 | testNames := make([]string, numTests) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 218 | for i, src := range test.srcs() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 219 | testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src)) |
| 220 | } |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 221 | // In addition to creating one variation per test source file, |
| 222 | // create an additional "all tests" variation named "", and have it |
| 223 | // depends on all other test_per_src variations. This is useful to |
| 224 | // create subsequent dependencies of a given module on all |
| 225 | // test_per_src variations created above: by depending on |
| 226 | // variation "", that module will transitively depend on all the |
| 227 | // other test_per_src variations without the need to know their |
| 228 | // name or even their number. |
| 229 | testNames = append(testNames, "") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 230 | tests := mctx.CreateLocalVariations(testNames...) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 231 | allTests := tests[numTests] |
| 232 | allTests.(*Module).linker.(testPerSrc).unsetSrc() |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 233 | // Prevent the "all tests" variation from being installable nor |
| 234 | // exporting to Make, as it won't create any output file. |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 235 | allTests.(*Module).Properties.PreventInstall = true |
| 236 | allTests.(*Module).Properties.HideFromMake = true |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 237 | for i, src := range test.srcs() { |
| 238 | tests[i].(*Module).linker.(testPerSrc).setSrc(testNames[i], src) |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 239 | mctx.AddInterVariantDependency(testPerSrcDepTag, allTests, tests[i]) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 240 | } |
Colin Cross | 90dab34 | 2020-08-21 15:55:50 -0700 | [diff] [blame] | 241 | mctx.AliasVariation("") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 247 | type testDecorator struct { |
| 248 | Properties TestProperties |
| 249 | linker *baseLinker |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 252 | func (test *testDecorator) gtest() bool { |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 253 | return BoolDefault(test.Properties.Gtest, true) |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 256 | func (test *testDecorator) testBinary() bool { |
| 257 | return true |
| 258 | } |
| 259 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 260 | func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 261 | if !test.gtest() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 262 | return flags |
| 263 | } |
| 264 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 265 | flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_HAS_STD_STRING") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 266 | if ctx.Host() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 267 | flags.Local.CFlags = append(flags.Local.CFlags, "-O0", "-g") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 268 | |
| 269 | switch ctx.Os() { |
| 270 | case android.Windows: |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 271 | flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_WINDOWS") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 272 | case android.Linux: |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 273 | flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 274 | case android.Darwin: |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 275 | flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_MAC") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 276 | } |
| 277 | } else { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 278 | flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX_ANDROID") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | return flags |
| 282 | } |
| 283 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 284 | func (test *testDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 285 | if test.gtest() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 286 | if ctx.useSdk() && ctx.Device() { |
Dan Albert | 7dd5899 | 2018-02-09 15:22:59 -0800 | [diff] [blame] | 287 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_c++", "libgtest_ndk_c++") |
Christopher Ferris | 9df92d6 | 2018-08-21 12:40:08 -0700 | [diff] [blame] | 288 | } else if BoolDefault(test.Properties.Isolated, false) { |
| 289 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_isolated_main") |
Christopher Ferris | 34cbba6 | 2019-07-17 15:46:29 -0700 | [diff] [blame] | 290 | // The isolated library requires liblog, but adding it |
| 291 | // as a static library means unit tests cannot override |
| 292 | // liblog functions. Instead make it a shared library |
| 293 | // dependency. |
| 294 | deps.SharedLibs = append(deps.SharedLibs, "liblog") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 295 | } else { |
| 296 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest") |
| 297 | } |
| 298 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 299 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 300 | return deps |
| 301 | } |
| 302 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 303 | func (test *testDecorator) linkerInit(ctx BaseModuleContext, linker *baseLinker) { |
yangbill | b3174d1 | 2018-05-07 06:41:20 +0000 | [diff] [blame] | 304 | // 1. Add ../../lib[64] to rpath so that out/host/linux-x86/nativetest/<test dir>/<test> can |
Colin Cross | bd75e1d | 2017-06-30 17:27:55 -0700 | [diff] [blame] | 305 | // find out/host/linux-x86/lib[64]/library.so |
yangbill | b3174d1 | 2018-05-07 06:41:20 +0000 | [diff] [blame] | 306 | // 2. Add ../../../lib[64] to rpath so that out/host/linux-x86/testcases/<test dir>/<CPU>/<test> can |
| 307 | // also find out/host/linux-x86/lib[64]/library.so |
| 308 | runpaths := []string{"../../lib", "../../../lib"} |
| 309 | for _, runpath := range runpaths { |
| 310 | if ctx.toolchain().Is64Bit() { |
| 311 | runpath += "64" |
| 312 | } |
| 313 | linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, runpath) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 314 | } |
Colin Cross | bd75e1d | 2017-06-30 17:27:55 -0700 | [diff] [blame] | 315 | |
| 316 | // add "" to rpath so that test binaries can find libraries in their own test directory |
| 317 | linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, "") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 320 | func (test *testDecorator) linkerProps() []interface{} { |
| 321 | return []interface{}{&test.Properties} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 324 | func NewTestInstaller() *baseInstaller { |
| 325 | return NewBaseInstaller("nativetest", "nativetest64", InstallInData) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 328 | type testBinary struct { |
| 329 | testDecorator |
| 330 | *binaryDecorator |
| 331 | *baseCompiler |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 332 | Properties TestBinaryProperties |
| 333 | data []android.DataPath |
| 334 | testConfig android.Path |
| 335 | extraTestConfigs android.Paths |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | func (test *testBinary) linkerProps() []interface{} { |
| 339 | props := append(test.testDecorator.linkerProps(), test.binaryDecorator.linkerProps()...) |
| 340 | props = append(props, &test.Properties) |
| 341 | return props |
| 342 | } |
| 343 | |
| 344 | func (test *testBinary) linkerInit(ctx BaseModuleContext) { |
| 345 | test.testDecorator.linkerInit(ctx, test.binaryDecorator.baseLinker) |
| 346 | test.binaryDecorator.linkerInit(ctx) |
| 347 | } |
| 348 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 349 | func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 350 | deps = test.testDecorator.linkerDeps(ctx, deps) |
| 351 | deps = test.binaryDecorator.linkerDeps(ctx, deps) |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 352 | deps.DataLibs = append(deps.DataLibs, test.Properties.Data_libs...) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 353 | return deps |
| 354 | } |
| 355 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 356 | func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 357 | flags = test.binaryDecorator.linkerFlags(ctx, flags) |
| 358 | flags = test.testDecorator.linkerFlags(ctx, flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 359 | return flags |
| 360 | } |
| 361 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 362 | func (test *testBinary) install(ctx ModuleContext, file android.Path) { |
Guang Zhu | 5c97bc6 | 2021-09-22 04:19:19 +0000 | [diff] [blame] | 363 | // TODO: (b/167308193) Switch to /data/local/tests/unrestricted as the default install base. |
| 364 | testInstallBase := "/data/local/tmp" |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 365 | if ctx.inVendor() || ctx.useVndk() { |
| 366 | testInstallBase = "/data/local/tests/vendor" |
| 367 | } |
| 368 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 369 | dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data) |
| 370 | |
| 371 | for _, dataSrcPath := range dataSrcPaths { |
| 372 | test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath}) |
| 373 | } |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 374 | |
| 375 | ctx.VisitDirectDepsWithTag(dataLibDepTag, func(dep android.Module) { |
| 376 | depName := ctx.OtherModuleName(dep) |
| 377 | ccDep, ok := dep.(LinkableInterface) |
| 378 | |
| 379 | if !ok { |
| 380 | ctx.ModuleErrorf("data_lib %q is not a linkable cc module", depName) |
| 381 | } |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 382 | ccModule, ok := dep.(*Module) |
| 383 | if !ok { |
| 384 | ctx.ModuleErrorf("data_lib %q is not a cc module", depName) |
| 385 | } |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 386 | if ccDep.OutputFile().Valid() { |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 387 | test.data = append(test.data, |
| 388 | android.DataPath{SrcPath: ccDep.OutputFile().Path(), |
| 389 | RelativeInstallPath: ccModule.installer.relativeInstallPath()}) |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 390 | } |
| 391 | }) |
| 392 | |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 393 | var configs []tradefed.Config |
easoncylee | 1e3fdcd | 2020-04-30 10:08:33 +0800 | [diff] [blame] | 394 | for _, module := range test.Properties.Test_mainline_modules { |
| 395 | configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module}) |
| 396 | } |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 397 | if Bool(test.Properties.Require_root) { |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 398 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) |
Dan Shi | bc0f260 | 2019-09-17 02:43:50 +0000 | [diff] [blame] | 399 | } else { |
| 400 | var options []tradefed.Option |
easoncylee | 1e3fdcd | 2020-04-30 10:08:33 +0800 | [diff] [blame] | 401 | options = append(options, tradefed.Option{Name: "force-root", Value: "false"}) |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 402 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options}) |
Dan Shi | 20ccd21 | 2019-08-27 10:37:24 -0700 | [diff] [blame] | 403 | } |
| 404 | if Bool(test.Properties.Disable_framework) { |
| 405 | var options []tradefed.Option |
Dan Shi | 8aa4010 | 2020-05-12 13:50:12 -0700 | [diff] [blame] | 406 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.StopServicesSetup", options}) |
Julien Desprez | eb7398e | 2019-02-28 08:45:28 -0800 | [diff] [blame] | 407 | } |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 408 | if Bool(test.testDecorator.Properties.Isolated) { |
easoncylee | 1e3fdcd | 2020-04-30 10:08:33 +0800 | [diff] [blame] | 409 | configs = append(configs, tradefed.Option{Name: "not-shardable", Value: "true"}) |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 410 | } |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame] | 411 | if test.Properties.Test_options.Run_test_as != nil { |
easoncylee | 1e3fdcd | 2020-04-30 10:08:33 +0800 | [diff] [blame] | 412 | configs = append(configs, tradefed.Option{Name: "run-test-as", Value: String(test.Properties.Test_options.Run_test_as)}) |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame] | 413 | } |
David Srbecky | 519db27 | 2020-06-18 18:07:00 +0100 | [diff] [blame] | 414 | for _, tag := range test.Properties.Test_options.Test_suite_tag { |
| 415 | configs = append(configs, tradefed.Option{Name: "test-suite-tag", Value: tag}) |
| 416 | } |
Justin Yun | a364cfb | 2021-05-13 12:39:42 +0900 | [diff] [blame] | 417 | if test.Properties.Test_options.Min_shipping_api_level != nil { |
| 418 | if test.Properties.Test_options.Vsr_min_shipping_api_level != nil { |
| 419 | ctx.PropertyErrorf("test_options.min_shipping_api_level", "must not be set at the same time as 'vsr_min_shipping_api_level'.") |
| 420 | } |
Justin Yun | 46f6605 | 2021-05-04 18:42:24 +0900 | [diff] [blame] | 421 | var options []tradefed.Option |
Justin Yun | a364cfb | 2021-05-13 12:39:42 +0900 | [diff] [blame] | 422 | options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_options.Min_shipping_api_level), 10)}) |
Justin Yun | 46f6605 | 2021-05-04 18:42:24 +0900 | [diff] [blame] | 423 | configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options}) |
| 424 | } else if test.Properties.Test_min_api_level != nil { |
| 425 | // TODO: (b/187258404) Remove test.Properties.Test_min_api_level |
Justin Yun | a364cfb | 2021-05-13 12:39:42 +0900 | [diff] [blame] | 426 | if test.Properties.Test_options.Vsr_min_shipping_api_level != nil { |
| 427 | ctx.PropertyErrorf("test_min_api_level", "must not be set at the same time as 'vsr_min_shipping_api_level'.") |
| 428 | } |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 429 | var options []tradefed.Option |
Justin Yun | 107a4cb | 2021-02-10 13:46:50 +0900 | [diff] [blame] | 430 | options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_min_api_level), 10)}) |
| 431 | configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options}) |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 432 | } |
Justin Yun | a364cfb | 2021-05-13 12:39:42 +0900 | [diff] [blame] | 433 | if test.Properties.Test_options.Vsr_min_shipping_api_level != nil { |
Justin Yun | 46f6605 | 2021-05-04 18:42:24 +0900 | [diff] [blame] | 434 | var options []tradefed.Option |
Justin Yun | a364cfb | 2021-05-13 12:39:42 +0900 | [diff] [blame] | 435 | options = append(options, tradefed.Option{Name: "vsr-min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_options.Vsr_min_shipping_api_level), 10)}) |
| 436 | configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options}) |
| 437 | } |
| 438 | if test.Properties.Test_options.Min_vndk_version != nil { |
| 439 | var options []tradefed.Option |
| 440 | options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_options.Min_vndk_version), 10)}) |
Justin Yun | 46f6605 | 2021-05-04 18:42:24 +0900 | [diff] [blame] | 441 | options = append(options, tradefed.Option{Name: "api-level-prop", Value: "ro.vndk.version"}) |
| 442 | configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.MinApiLevelModuleController", options}) |
| 443 | } |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame] | 444 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 445 | test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config, |
yangbill | 5ec4555 | 2020-08-13 16:16:56 +0800 | [diff] [blame] | 446 | test.Properties.Test_config_template, test.Properties.Test_suites, configs, test.Properties.Auto_gen_config, testInstallBase) |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 447 | |
Dan Shi | 95d1942 | 2020-08-15 12:24:26 -0700 | [diff] [blame] | 448 | test.extraTestConfigs = android.PathsForModuleSrc(ctx, test.Properties.Test_options.Extra_test_configs) |
| 449 | |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 450 | test.binaryDecorator.baseInstaller.dir = "nativetest" |
| 451 | test.binaryDecorator.baseInstaller.dir64 = "nativetest64" |
Dan Willemsen | 3340d60 | 2016-12-27 14:40:40 -0800 | [diff] [blame] | 452 | |
| 453 | if !Bool(test.Properties.No_named_install_directory) { |
| 454 | test.binaryDecorator.baseInstaller.relative = ctx.ModuleName() |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 455 | } else if String(test.binaryDecorator.baseInstaller.Properties.Relative_install_path) == "" { |
Dan Willemsen | 3340d60 | 2016-12-27 14:40:40 -0800 | [diff] [blame] | 456 | ctx.PropertyErrorf("no_named_install_directory", "Module install directory may only be disabled if relative_install_path is set") |
| 457 | } |
| 458 | |
Julien Desprez | 8908b37 | 2021-02-04 10:10:16 -0800 | [diff] [blame] | 459 | if ctx.Host() && test.gtest() && test.Properties.Test_options.Unit_test == nil { |
Julien Desprez | 3b933d3 | 2021-01-14 11:49:15 -0800 | [diff] [blame] | 460 | test.Properties.Test_options.Unit_test = proptools.BoolPtr(true) |
| 461 | } |
Dan Willemsen | 1d577e2 | 2016-08-29 15:53:15 -0700 | [diff] [blame] | 462 | test.binaryDecorator.baseInstaller.install(ctx, file) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | func NewTest(hod android.HostOrDeviceSupported) *Module { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 466 | module, binary := NewBinary(hod) |
| 467 | module.multilib = android.MultilibBoth |
Dan Willemsen | 1d577e2 | 2016-08-29 15:53:15 -0700 | [diff] [blame] | 468 | binary.baseInstaller = NewTestInstaller() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 469 | |
| 470 | test := &testBinary{ |
| 471 | testDecorator: testDecorator{ |
| 472 | linker: binary.baseLinker, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 473 | }, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 474 | binaryDecorator: binary, |
| 475 | baseCompiler: NewBaseCompiler(), |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 476 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 477 | module.compiler = test |
| 478 | module.linker = test |
| 479 | module.installer = test |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 480 | return module |
| 481 | } |
| 482 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 483 | type testLibrary struct { |
| 484 | testDecorator |
| 485 | *libraryDecorator |
| 486 | } |
| 487 | |
| 488 | func (test *testLibrary) linkerProps() []interface{} { |
| 489 | return append(test.testDecorator.linkerProps(), test.libraryDecorator.linkerProps()...) |
| 490 | } |
| 491 | |
| 492 | func (test *testLibrary) linkerInit(ctx BaseModuleContext) { |
| 493 | test.testDecorator.linkerInit(ctx, test.libraryDecorator.baseLinker) |
| 494 | test.libraryDecorator.linkerInit(ctx) |
| 495 | } |
| 496 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 497 | func (test *testLibrary) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 498 | deps = test.testDecorator.linkerDeps(ctx, deps) |
| 499 | deps = test.libraryDecorator.linkerDeps(ctx, deps) |
| 500 | return deps |
| 501 | } |
| 502 | |
| 503 | func (test *testLibrary) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 504 | flags = test.libraryDecorator.linkerFlags(ctx, flags) |
| 505 | flags = test.testDecorator.linkerFlags(ctx, flags) |
| 506 | return flags |
| 507 | } |
| 508 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 509 | func NewTestLibrary(hod android.HostOrDeviceSupported) *Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 510 | module, library := NewLibrary(android.HostAndDeviceSupported) |
Dan Willemsen | 28bda51 | 2016-08-31 16:32:55 -0700 | [diff] [blame] | 511 | library.baseInstaller = NewTestInstaller() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 512 | test := &testLibrary{ |
| 513 | testDecorator: testDecorator{ |
| 514 | linker: library.baseLinker, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 515 | }, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 516 | libraryDecorator: library, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 517 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 518 | module.linker = test |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 519 | return module |
| 520 | } |
| 521 | |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 522 | type BenchmarkProperties struct { |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 523 | // list of files or filegroup modules that provide data that should be installed alongside |
| 524 | // the test |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 525 | Data []string `android:"path"` |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 526 | |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 527 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 528 | // installed into. |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 529 | Test_suites []string `android:"arch_variant"` |
| 530 | |
| 531 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 532 | // installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 533 | Test_config *string `android:"path,arch_variant"` |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 534 | |
| 535 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 536 | // should be installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 537 | Test_config_template *string `android:"path,arch_variant"` |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 538 | |
| 539 | // Add RootTargetPreparer to auto generated test config. This guarantees the test to run |
| 540 | // with root permission. |
| 541 | Require_root *bool |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 542 | |
| 543 | // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml |
| 544 | // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true |
| 545 | // explicitly. |
| 546 | Auto_gen_config *bool |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 549 | type benchmarkDecorator struct { |
| 550 | *binaryDecorator |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 551 | Properties BenchmarkProperties |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 552 | data android.Paths |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 553 | testConfig android.Path |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 556 | func (benchmark *benchmarkDecorator) linkerInit(ctx BaseModuleContext) { |
| 557 | runpath := "../../lib" |
| 558 | if ctx.toolchain().Is64Bit() { |
| 559 | runpath += "64" |
| 560 | } |
| 561 | benchmark.baseLinker.dynamicProperties.RunPaths = append(benchmark.baseLinker.dynamicProperties.RunPaths, runpath) |
| 562 | benchmark.binaryDecorator.linkerInit(ctx) |
| 563 | } |
| 564 | |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 565 | func (benchmark *benchmarkDecorator) linkerProps() []interface{} { |
| 566 | props := benchmark.binaryDecorator.linkerProps() |
| 567 | props = append(props, &benchmark.Properties) |
| 568 | return props |
| 569 | } |
| 570 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 571 | func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 572 | deps = benchmark.binaryDecorator.linkerDeps(ctx, deps) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 573 | deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark") |
| 574 | return deps |
| 575 | } |
| 576 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 577 | func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 578 | benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data) |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 579 | |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 580 | var configs []tradefed.Config |
| 581 | if Bool(benchmark.Properties.Require_root) { |
nelsonli | 0d7111e | 2019-09-17 16:35:23 +0800 | [diff] [blame] | 582 | configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) |
Dan Shi | 37ee3b8 | 2019-06-06 16:23:32 -0700 | [diff] [blame] | 583 | } |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 584 | benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config, |
Dan Shi | 6ffaaa8 | 2019-09-26 11:41:36 -0700 | [diff] [blame] | 585 | benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs, benchmark.Properties.Auto_gen_config) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 586 | |
Colin Cross | 28690e9 | 2017-09-08 16:20:30 -0700 | [diff] [blame] | 587 | benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName()) |
| 588 | benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName()) |
Dan Willemsen | 1d577e2 | 2016-08-29 15:53:15 -0700 | [diff] [blame] | 589 | benchmark.binaryDecorator.baseInstaller.install(ctx, file) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 592 | func NewBenchmark(hod android.HostOrDeviceSupported) *Module { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 593 | module, binary := NewBinary(hod) |
| 594 | module.multilib = android.MultilibBoth |
Colin Cross | 28690e9 | 2017-09-08 16:20:30 -0700 | [diff] [blame] | 595 | binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 596 | |
| 597 | benchmark := &benchmarkDecorator{ |
| 598 | binaryDecorator: binary, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 599 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 600 | module.linker = benchmark |
| 601 | module.installer = benchmark |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 602 | return module |
| 603 | } |