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