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