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