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