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