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