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" |
| 19 | "strings" |
| 20 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 21 | "android/soong/android" |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 22 | "android/soong/tradefed" |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 25 | type TestProperties struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 26 | // if set, build against the gtest library. Defaults to true. |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 27 | Gtest *bool |
Christopher Ferris | 9df92d6 | 2018-08-21 12:40:08 -0700 | [diff] [blame] | 28 | |
| 29 | // if set, use the isolated gtest runner. Defaults to false. |
| 30 | Isolated *bool |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 31 | } |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 32 | |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame^] | 33 | // Test option struct. |
| 34 | type TestOptions struct { |
| 35 | // The UID that you want to run the test as on a device. |
| 36 | Run_test_as *string |
| 37 | } |
| 38 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 39 | type TestBinaryProperties struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 40 | // Create a separate binary for each source file. Useful when there is |
| 41 | // global state that can not be torn down and reset between each test suite. |
| 42 | Test_per_src *bool |
Dan Willemsen | 3340d60 | 2016-12-27 14:40:40 -0800 | [diff] [blame] | 43 | |
| 44 | // Disables the creation of a test-specific directory when used with |
| 45 | // relative_install_path. Useful if several tests need to be in the same |
| 46 | // directory, but test_per_src doesn't work. |
| 47 | No_named_install_directory *bool |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 48 | |
| 49 | // list of files or filegroup modules that provide data that should be installed alongside |
| 50 | // the test |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 51 | Data []string `android:"path"` |
Colin Cross | a929db0 | 2017-03-27 16:27:50 -0700 | [diff] [blame] | 52 | |
| 53 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 54 | // installed into. |
Dan Willemsen | 15d54d5 | 2017-09-18 16:49:28 -0700 | [diff] [blame] | 55 | Test_suites []string `android:"arch_variant"` |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 56 | |
| 57 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 58 | // installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 59 | Test_config *string `android:"path,arch_variant"` |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 60 | |
| 61 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 62 | // should be installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 63 | Test_config_template *string `android:"path,arch_variant"` |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame^] | 64 | |
| 65 | // Test options. |
| 66 | Test_options TestOptions |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | func init() { |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 70 | android.RegisterModuleType("cc_test", TestFactory) |
| 71 | android.RegisterModuleType("cc_test_library", TestLibraryFactory) |
| 72 | android.RegisterModuleType("cc_benchmark", BenchmarkFactory) |
| 73 | android.RegisterModuleType("cc_test_host", TestHostFactory) |
| 74 | android.RegisterModuleType("cc_benchmark_host", BenchmarkHostFactory) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | // Module factory for tests |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 78 | func TestFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 79 | module := NewTest(android.HostAndDeviceSupported) |
| 80 | return module.Init() |
| 81 | } |
| 82 | |
| 83 | // Module factory for test libraries |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 84 | func TestLibraryFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 85 | module := NewTestLibrary(android.HostAndDeviceSupported) |
| 86 | return module.Init() |
| 87 | } |
| 88 | |
| 89 | // Module factory for benchmarks |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 90 | func BenchmarkFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 91 | module := NewBenchmark(android.HostAndDeviceSupported) |
| 92 | return module.Init() |
| 93 | } |
| 94 | |
| 95 | // Module factory for host tests |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 96 | func TestHostFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 97 | module := NewTest(android.HostSupported) |
| 98 | return module.Init() |
| 99 | } |
| 100 | |
| 101 | // Module factory for host benchmarks |
Steven Moreland | 87c9d7b | 2017-11-02 21:38:28 -0700 | [diff] [blame] | 102 | func BenchmarkHostFactory() android.Module { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 103 | module := NewBenchmark(android.HostSupported) |
| 104 | return module.Init() |
| 105 | } |
| 106 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 107 | type testPerSrc interface { |
| 108 | testPerSrc() bool |
| 109 | srcs() []string |
| 110 | setSrc(string, string) |
| 111 | } |
| 112 | |
| 113 | func (test *testBinary) testPerSrc() bool { |
| 114 | return Bool(test.Properties.Test_per_src) |
| 115 | } |
| 116 | |
| 117 | func (test *testBinary) srcs() []string { |
| 118 | return test.baseCompiler.Properties.Srcs |
| 119 | } |
| 120 | |
| 121 | func (test *testBinary) setSrc(name, src string) { |
| 122 | test.baseCompiler.Properties.Srcs = []string{src} |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 123 | test.binaryDecorator.Properties.Stem = StringPtr(name) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | var _ testPerSrc = (*testBinary)(nil) |
| 127 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 128 | func testPerSrcMutator(mctx android.BottomUpMutatorContext) { |
| 129 | if m, ok := mctx.Module().(*Module); ok { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 130 | if test, ok := m.linker.(testPerSrc); ok { |
| 131 | if test.testPerSrc() && len(test.srcs()) > 0 { |
Jooyung Han | a61ff2c | 2019-02-28 18:06:34 +0900 | [diff] [blame] | 132 | if duplicate, found := checkDuplicate(test.srcs()); found { |
| 133 | mctx.PropertyErrorf("srcs", "found a duplicate entry %q", duplicate) |
| 134 | return |
| 135 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 136 | testNames := make([]string, len(test.srcs())) |
| 137 | for i, src := range test.srcs() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 138 | testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src)) |
| 139 | } |
| 140 | tests := mctx.CreateLocalVariations(testNames...) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 141 | for i, src := range test.srcs() { |
| 142 | tests[i].(*Module).linker.(testPerSrc).setSrc(testNames[i], src) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
Jooyung Han | a61ff2c | 2019-02-28 18:06:34 +0900 | [diff] [blame] | 149 | func checkDuplicate(values []string) (duplicate string, found bool) { |
| 150 | seen := make(map[string]string) |
| 151 | for _, v := range values { |
| 152 | if duplicate, found = seen[v]; found { |
| 153 | return |
| 154 | } |
| 155 | seen[v] = v |
| 156 | } |
| 157 | return |
| 158 | } |
| 159 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 160 | type testDecorator struct { |
| 161 | Properties TestProperties |
| 162 | linker *baseLinker |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 165 | func (test *testDecorator) gtest() bool { |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 166 | return BoolDefault(test.Properties.Gtest, true) |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 169 | func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 170 | if !test.gtest() { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 171 | return flags |
| 172 | } |
| 173 | |
| 174 | flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING") |
| 175 | if ctx.Host() { |
| 176 | flags.CFlags = append(flags.CFlags, "-O0", "-g") |
| 177 | |
| 178 | switch ctx.Os() { |
| 179 | case android.Windows: |
| 180 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS") |
| 181 | case android.Linux: |
| 182 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 183 | case android.Darwin: |
| 184 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_MAC") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 185 | } |
| 186 | } else { |
| 187 | flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID") |
| 188 | } |
| 189 | |
| 190 | return flags |
| 191 | } |
| 192 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 193 | func (test *testDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 194 | if test.gtest() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 195 | if ctx.useSdk() && ctx.Device() { |
Dan Albert | 7dd5899 | 2018-02-09 15:22:59 -0800 | [diff] [blame] | 196 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_c++", "libgtest_ndk_c++") |
Christopher Ferris | 9df92d6 | 2018-08-21 12:40:08 -0700 | [diff] [blame] | 197 | } else if BoolDefault(test.Properties.Isolated, false) { |
| 198 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_isolated_main") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 199 | } else { |
| 200 | deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest") |
| 201 | } |
| 202 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 203 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 204 | return deps |
| 205 | } |
| 206 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 207 | func (test *testDecorator) linkerInit(ctx BaseModuleContext, linker *baseLinker) { |
yangbill | b3174d1 | 2018-05-07 06:41:20 +0000 | [diff] [blame] | 208 | // 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] | 209 | // find out/host/linux-x86/lib[64]/library.so |
yangbill | b3174d1 | 2018-05-07 06:41:20 +0000 | [diff] [blame] | 210 | // 2. Add ../../../lib[64] to rpath so that out/host/linux-x86/testcases/<test dir>/<CPU>/<test> can |
| 211 | // also find out/host/linux-x86/lib[64]/library.so |
| 212 | runpaths := []string{"../../lib", "../../../lib"} |
| 213 | for _, runpath := range runpaths { |
| 214 | if ctx.toolchain().Is64Bit() { |
| 215 | runpath += "64" |
| 216 | } |
| 217 | linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, runpath) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 218 | } |
Colin Cross | bd75e1d | 2017-06-30 17:27:55 -0700 | [diff] [blame] | 219 | |
| 220 | // add "" to rpath so that test binaries can find libraries in their own test directory |
| 221 | linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, "") |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 224 | func (test *testDecorator) linkerProps() []interface{} { |
| 225 | return []interface{}{&test.Properties} |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 228 | func NewTestInstaller() *baseInstaller { |
| 229 | return NewBaseInstaller("nativetest", "nativetest64", InstallInData) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 232 | type testBinary struct { |
| 233 | testDecorator |
| 234 | *binaryDecorator |
| 235 | *baseCompiler |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 236 | Properties TestBinaryProperties |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 237 | data android.Paths |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 238 | testConfig android.Path |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | func (test *testBinary) linkerProps() []interface{} { |
| 242 | props := append(test.testDecorator.linkerProps(), test.binaryDecorator.linkerProps()...) |
| 243 | props = append(props, &test.Properties) |
| 244 | return props |
| 245 | } |
| 246 | |
| 247 | func (test *testBinary) linkerInit(ctx BaseModuleContext) { |
| 248 | test.testDecorator.linkerInit(ctx, test.binaryDecorator.baseLinker) |
| 249 | test.binaryDecorator.linkerInit(ctx) |
| 250 | } |
| 251 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 252 | func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 253 | deps = test.testDecorator.linkerDeps(ctx, deps) |
| 254 | deps = test.binaryDecorator.linkerDeps(ctx, deps) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 255 | return deps |
| 256 | } |
| 257 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 258 | func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 259 | flags = test.binaryDecorator.linkerFlags(ctx, flags) |
| 260 | flags = test.testDecorator.linkerFlags(ctx, flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 261 | return flags |
| 262 | } |
| 263 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 264 | func (test *testBinary) install(ctx ModuleContext, file android.Path) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 265 | test.data = android.PathsForModuleSrc(ctx, test.Properties.Data) |
Julien Desprez | eb7398e | 2019-02-28 08:45:28 -0800 | [diff] [blame] | 266 | optionsMap := map[string]string{} |
| 267 | if Bool(test.testDecorator.Properties.Isolated) { |
| 268 | optionsMap["not-shardable"] = "true" |
| 269 | } |
yelinhsieh | 9fc6040 | 2018-10-01 19:23:14 +0800 | [diff] [blame^] | 270 | |
| 271 | if test.Properties.Test_options.Run_test_as != nil { |
| 272 | optionsMap["run-test-as"] = String(test.Properties.Test_options.Run_test_as) |
| 273 | } |
| 274 | |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 275 | test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config, |
Julien Desprez | eb7398e | 2019-02-28 08:45:28 -0800 | [diff] [blame] | 276 | test.Properties.Test_config_template, |
| 277 | test.Properties.Test_suites, optionsMap) |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 278 | |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 279 | test.binaryDecorator.baseInstaller.dir = "nativetest" |
| 280 | test.binaryDecorator.baseInstaller.dir64 = "nativetest64" |
Dan Willemsen | 3340d60 | 2016-12-27 14:40:40 -0800 | [diff] [blame] | 281 | |
| 282 | if !Bool(test.Properties.No_named_install_directory) { |
| 283 | test.binaryDecorator.baseInstaller.relative = ctx.ModuleName() |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 284 | } else if String(test.binaryDecorator.baseInstaller.Properties.Relative_install_path) == "" { |
Dan Willemsen | 3340d60 | 2016-12-27 14:40:40 -0800 | [diff] [blame] | 285 | ctx.PropertyErrorf("no_named_install_directory", "Module install directory may only be disabled if relative_install_path is set") |
| 286 | } |
| 287 | |
Dan Willemsen | 1d577e2 | 2016-08-29 15:53:15 -0700 | [diff] [blame] | 288 | test.binaryDecorator.baseInstaller.install(ctx, file) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | func NewTest(hod android.HostOrDeviceSupported) *Module { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 292 | module, binary := NewBinary(hod) |
| 293 | module.multilib = android.MultilibBoth |
Dan Willemsen | 1d577e2 | 2016-08-29 15:53:15 -0700 | [diff] [blame] | 294 | binary.baseInstaller = NewTestInstaller() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 295 | |
| 296 | test := &testBinary{ |
| 297 | testDecorator: testDecorator{ |
| 298 | linker: binary.baseLinker, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 299 | }, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 300 | binaryDecorator: binary, |
| 301 | baseCompiler: NewBaseCompiler(), |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 302 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 303 | module.compiler = test |
| 304 | module.linker = test |
| 305 | module.installer = test |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 306 | return module |
| 307 | } |
| 308 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 309 | type testLibrary struct { |
| 310 | testDecorator |
| 311 | *libraryDecorator |
| 312 | } |
| 313 | |
| 314 | func (test *testLibrary) linkerProps() []interface{} { |
| 315 | return append(test.testDecorator.linkerProps(), test.libraryDecorator.linkerProps()...) |
| 316 | } |
| 317 | |
| 318 | func (test *testLibrary) linkerInit(ctx BaseModuleContext) { |
| 319 | test.testDecorator.linkerInit(ctx, test.libraryDecorator.baseLinker) |
| 320 | test.libraryDecorator.linkerInit(ctx) |
| 321 | } |
| 322 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 323 | func (test *testLibrary) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 324 | deps = test.testDecorator.linkerDeps(ctx, deps) |
| 325 | deps = test.libraryDecorator.linkerDeps(ctx, deps) |
| 326 | return deps |
| 327 | } |
| 328 | |
| 329 | func (test *testLibrary) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
| 330 | flags = test.libraryDecorator.linkerFlags(ctx, flags) |
| 331 | flags = test.testDecorator.linkerFlags(ctx, flags) |
| 332 | return flags |
| 333 | } |
| 334 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 335 | func NewTestLibrary(hod android.HostOrDeviceSupported) *Module { |
Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 336 | module, library := NewLibrary(android.HostAndDeviceSupported) |
Dan Willemsen | 28bda51 | 2016-08-31 16:32:55 -0700 | [diff] [blame] | 337 | library.baseInstaller = NewTestInstaller() |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 338 | test := &testLibrary{ |
| 339 | testDecorator: testDecorator{ |
| 340 | linker: library.baseLinker, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 341 | }, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 342 | libraryDecorator: library, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 343 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 344 | module.linker = test |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 345 | return module |
| 346 | } |
| 347 | |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 348 | type BenchmarkProperties struct { |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 349 | // list of files or filegroup modules that provide data that should be installed alongside |
| 350 | // the test |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 351 | Data []string `android:"path"` |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 352 | |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 353 | // list of compatibility suites (for example "cts", "vts") that the module should be |
| 354 | // installed into. |
Julien Desprez | e146e39 | 2018-08-02 15:00:46 -0700 | [diff] [blame] | 355 | Test_suites []string `android:"arch_variant"` |
| 356 | |
| 357 | // the name of the test configuration (for example "AndroidTest.xml") that should be |
| 358 | // installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 359 | Test_config *string `android:"path,arch_variant"` |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 360 | |
| 361 | // the name of the test configuration template (for example "AndroidTestTemplate.xml") that |
| 362 | // should be installed with the module. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 363 | Test_config_template *string `android:"path,arch_variant"` |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 366 | type benchmarkDecorator struct { |
| 367 | *binaryDecorator |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 368 | Properties BenchmarkProperties |
Anders Lewis | b97e818 | 2017-07-14 15:20:13 -0700 | [diff] [blame] | 369 | data android.Paths |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 370 | testConfig android.Path |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 373 | func (benchmark *benchmarkDecorator) linkerInit(ctx BaseModuleContext) { |
| 374 | runpath := "../../lib" |
| 375 | if ctx.toolchain().Is64Bit() { |
| 376 | runpath += "64" |
| 377 | } |
| 378 | benchmark.baseLinker.dynamicProperties.RunPaths = append(benchmark.baseLinker.dynamicProperties.RunPaths, runpath) |
| 379 | benchmark.binaryDecorator.linkerInit(ctx) |
| 380 | } |
| 381 | |
Colin Cross | e28f4e2 | 2017-04-24 18:10:29 -0700 | [diff] [blame] | 382 | func (benchmark *benchmarkDecorator) linkerProps() []interface{} { |
| 383 | props := benchmark.binaryDecorator.linkerProps() |
| 384 | props = append(props, &benchmark.Properties) |
| 385 | return props |
| 386 | } |
| 387 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 388 | func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 389 | deps = benchmark.binaryDecorator.linkerDeps(ctx, deps) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 390 | deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark") |
| 391 | return deps |
| 392 | } |
| 393 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 394 | func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 395 | benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data) |
Jack He | 3333889 | 2018-09-19 02:21:28 -0700 | [diff] [blame] | 396 | benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config, |
yangbill | 4f41bc2 | 2019-02-13 21:45:47 +0800 | [diff] [blame] | 397 | benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites) |
Colin Cross | 303e21f | 2018-08-07 16:49:25 -0700 | [diff] [blame] | 398 | |
Colin Cross | 28690e9 | 2017-09-08 16:20:30 -0700 | [diff] [blame] | 399 | benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName()) |
| 400 | benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName()) |
Dan Willemsen | 1d577e2 | 2016-08-29 15:53:15 -0700 | [diff] [blame] | 401 | benchmark.binaryDecorator.baseInstaller.install(ctx, file) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 404 | func NewBenchmark(hod android.HostOrDeviceSupported) *Module { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 405 | module, binary := NewBinary(hod) |
| 406 | module.multilib = android.MultilibBoth |
Colin Cross | 28690e9 | 2017-09-08 16:20:30 -0700 | [diff] [blame] | 407 | binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 408 | |
| 409 | benchmark := &benchmarkDecorator{ |
| 410 | binaryDecorator: binary, |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 411 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 412 | module.linker = benchmark |
| 413 | module.installer = benchmark |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 414 | return module |
| 415 | } |