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