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