blob: c735fd91f4b44496b5694ddf355e0e3015aec7d0 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// 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
15package cc
16
17import (
18 "path/filepath"
19 "strings"
20
Colin Cross4d9c2d12016-07-29 12:48:20 -070021 "android/soong/android"
Colin Cross303e21f2018-08-07 16:49:25 -070022 "android/soong/tradefed"
Colin Cross4d9c2d12016-07-29 12:48:20 -070023)
24
Colin Crossb916a382016-07-29 17:28:03 -070025type TestProperties struct {
Colin Cross4d9c2d12016-07-29 12:48:20 -070026 // if set, build against the gtest library. Defaults to true.
Colin Cross600c9df2016-09-13 12:26:16 -070027 Gtest *bool
Christopher Ferris9df92d62018-08-21 12:40:08 -070028
29 // if set, use the isolated gtest runner. Defaults to false.
30 Isolated *bool
Colin Crossb916a382016-07-29 17:28:03 -070031}
Colin Cross4d9c2d12016-07-29 12:48:20 -070032
yelinhsieh9fc60402018-10-01 19:23:14 +080033// Test option struct.
34type TestOptions struct {
35 // The UID that you want to run the test as on a device.
36 Run_test_as *string
37}
38
Colin Crossb916a382016-07-29 17:28:03 -070039type TestBinaryProperties struct {
Colin Cross4d9c2d12016-07-29 12:48:20 -070040 // Create a separate binary for each source file. Useful when there is
41 // global state that can not be torn down and reset between each test suite.
42 Test_per_src *bool
Dan Willemsen3340d602016-12-27 14:40:40 -080043
44 // Disables the creation of a test-specific directory when used with
45 // relative_install_path. Useful if several tests need to be in the same
46 // directory, but test_per_src doesn't work.
47 No_named_install_directory *bool
Colin Crossfaeb7aa2017-02-01 14:12:44 -080048
49 // list of files or filegroup modules that provide data that should be installed alongside
50 // the test
Colin Cross27b922f2019-03-04 22:35:41 -080051 Data []string `android:"path"`
Colin Crossa929db02017-03-27 16:27:50 -070052
53 // list of compatibility suites (for example "cts", "vts") that the module should be
54 // installed into.
Dan Willemsen15d54d52017-09-18 16:49:28 -070055 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -070056
57 // the name of the test configuration (for example "AndroidTest.xml") that should be
58 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -080059 Test_config *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -070060
61 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
62 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -080063 Test_config_template *string `android:"path,arch_variant"`
yelinhsieh9fc60402018-10-01 19:23:14 +080064
65 // Test options.
66 Test_options TestOptions
Dan Shi37ee3b82019-06-06 16:23:32 -070067
68 // Add RootTargetPreparer to auto generated test config. This guarantees the test to run
69 // with root permission.
70 Require_root *bool
Colin Cross4d9c2d12016-07-29 12:48:20 -070071}
72
73func init() {
Steven Moreland87c9d7b2017-11-02 21:38:28 -070074 android.RegisterModuleType("cc_test", TestFactory)
75 android.RegisterModuleType("cc_test_library", TestLibraryFactory)
76 android.RegisterModuleType("cc_benchmark", BenchmarkFactory)
77 android.RegisterModuleType("cc_test_host", TestHostFactory)
78 android.RegisterModuleType("cc_benchmark_host", BenchmarkHostFactory)
Colin Cross4d9c2d12016-07-29 12:48:20 -070079}
80
Patrice Arrudac249c712019-03-19 17:00:29 -070081// cc_test generates a test config file and an executable binary file to test
82// specific functionality on a device. The executable binary gets an implicit
83// static_libs dependency on libgtests unless the gtest flag is set to false.
Steven Moreland87c9d7b2017-11-02 21:38:28 -070084func TestFactory() android.Module {
Colin Cross4d9c2d12016-07-29 12:48:20 -070085 module := NewTest(android.HostAndDeviceSupported)
86 return module.Init()
87}
88
Patrice Arrudac249c712019-03-19 17:00:29 -070089// cc_test_library creates an archive of files (i.e. .o files) which is later
90// referenced by another module (such as cc_test, cc_defaults or cc_test_library)
91// for archiving or linking.
Steven Moreland87c9d7b2017-11-02 21:38:28 -070092func TestLibraryFactory() android.Module {
Colin Cross4d9c2d12016-07-29 12:48:20 -070093 module := NewTestLibrary(android.HostAndDeviceSupported)
94 return module.Init()
95}
96
Patrice Arrudac249c712019-03-19 17:00:29 -070097// cc_benchmark compiles an executable binary that performs benchmark testing
98// of a specific component in a device. Additional files such as test suites
99// and test configuration are installed on the side of the compiled executed
100// binary.
Steven Moreland87c9d7b2017-11-02 21:38:28 -0700101func BenchmarkFactory() android.Module {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700102 module := NewBenchmark(android.HostAndDeviceSupported)
103 return module.Init()
104}
105
Patrice Arrudac249c712019-03-19 17:00:29 -0700106// cc_test_host compiles a test host binary.
Steven Moreland87c9d7b2017-11-02 21:38:28 -0700107func TestHostFactory() android.Module {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700108 module := NewTest(android.HostSupported)
109 return module.Init()
110}
111
Patrice Arrudac249c712019-03-19 17:00:29 -0700112// cc_benchmark_host compiles an executable binary that performs benchmark
113// testing of a specific component in the host. Additional files such as
114// test suites and test configuration are installed on the side of the
115// compiled executed binary.
Steven Moreland87c9d7b2017-11-02 21:38:28 -0700116func BenchmarkHostFactory() android.Module {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700117 module := NewBenchmark(android.HostSupported)
118 return module.Init()
119}
120
Colin Crossb916a382016-07-29 17:28:03 -0700121type testPerSrc interface {
122 testPerSrc() bool
123 srcs() []string
124 setSrc(string, string)
125}
126
127func (test *testBinary) testPerSrc() bool {
128 return Bool(test.Properties.Test_per_src)
129}
130
131func (test *testBinary) srcs() []string {
132 return test.baseCompiler.Properties.Srcs
133}
134
135func (test *testBinary) setSrc(name, src string) {
136 test.baseCompiler.Properties.Srcs = []string{src}
Nan Zhang0007d812017-11-07 10:57:05 -0800137 test.binaryDecorator.Properties.Stem = StringPtr(name)
Colin Crossb916a382016-07-29 17:28:03 -0700138}
139
140var _ testPerSrc = (*testBinary)(nil)
141
Colin Cross4d9c2d12016-07-29 12:48:20 -0700142func testPerSrcMutator(mctx android.BottomUpMutatorContext) {
143 if m, ok := mctx.Module().(*Module); ok {
Colin Crossb916a382016-07-29 17:28:03 -0700144 if test, ok := m.linker.(testPerSrc); ok {
145 if test.testPerSrc() && len(test.srcs()) > 0 {
Jooyung Hana61ff2c2019-02-28 18:06:34 +0900146 if duplicate, found := checkDuplicate(test.srcs()); found {
147 mctx.PropertyErrorf("srcs", "found a duplicate entry %q", duplicate)
148 return
149 }
Colin Crossb916a382016-07-29 17:28:03 -0700150 testNames := make([]string, len(test.srcs()))
151 for i, src := range test.srcs() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700152 testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src))
153 }
154 tests := mctx.CreateLocalVariations(testNames...)
Colin Crossb916a382016-07-29 17:28:03 -0700155 for i, src := range test.srcs() {
156 tests[i].(*Module).linker.(testPerSrc).setSrc(testNames[i], src)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700157 }
158 }
159 }
160 }
161}
162
Jooyung Hana61ff2c2019-02-28 18:06:34 +0900163func checkDuplicate(values []string) (duplicate string, found bool) {
164 seen := make(map[string]string)
165 for _, v := range values {
166 if duplicate, found = seen[v]; found {
167 return
168 }
169 seen[v] = v
170 }
171 return
172}
173
Colin Crossb916a382016-07-29 17:28:03 -0700174type testDecorator struct {
175 Properties TestProperties
176 linker *baseLinker
Colin Cross4d9c2d12016-07-29 12:48:20 -0700177}
178
Colin Cross600c9df2016-09-13 12:26:16 -0700179func (test *testDecorator) gtest() bool {
Colin Cross38b40df2018-04-10 16:14:46 -0700180 return BoolDefault(test.Properties.Gtest, true)
Colin Cross600c9df2016-09-13 12:26:16 -0700181}
182
Colin Crossb916a382016-07-29 17:28:03 -0700183func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross600c9df2016-09-13 12:26:16 -0700184 if !test.gtest() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700185 return flags
186 }
187
188 flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING")
189 if ctx.Host() {
190 flags.CFlags = append(flags.CFlags, "-O0", "-g")
191
192 switch ctx.Os() {
193 case android.Windows:
194 flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS")
195 case android.Linux:
196 flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700197 case android.Darwin:
198 flags.CFlags = append(flags.CFlags, "-DGTEST_OS_MAC")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700199 }
200 } else {
201 flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID")
202 }
203
204 return flags
205}
206
Colin Crossb916a382016-07-29 17:28:03 -0700207func (test *testDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
Colin Cross600c9df2016-09-13 12:26:16 -0700208 if test.gtest() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700209 if ctx.useSdk() && ctx.Device() {
Dan Albert7dd58992018-02-09 15:22:59 -0800210 deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_c++", "libgtest_ndk_c++")
Christopher Ferris9df92d62018-08-21 12:40:08 -0700211 } else if BoolDefault(test.Properties.Isolated, false) {
212 deps.StaticLibs = append(deps.StaticLibs, "libgtest_isolated_main")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700213 } else {
214 deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest")
215 }
216 }
Colin Crossb916a382016-07-29 17:28:03 -0700217
Colin Cross4d9c2d12016-07-29 12:48:20 -0700218 return deps
219}
220
Colin Crossb916a382016-07-29 17:28:03 -0700221func (test *testDecorator) linkerInit(ctx BaseModuleContext, linker *baseLinker) {
yangbillb3174d12018-05-07 06:41:20 +0000222 // 1. Add ../../lib[64] to rpath so that out/host/linux-x86/nativetest/<test dir>/<test> can
Colin Crossbd75e1d2017-06-30 17:27:55 -0700223 // find out/host/linux-x86/lib[64]/library.so
yangbillb3174d12018-05-07 06:41:20 +0000224 // 2. Add ../../../lib[64] to rpath so that out/host/linux-x86/testcases/<test dir>/<CPU>/<test> can
225 // also find out/host/linux-x86/lib[64]/library.so
226 runpaths := []string{"../../lib", "../../../lib"}
227 for _, runpath := range runpaths {
228 if ctx.toolchain().Is64Bit() {
229 runpath += "64"
230 }
231 linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, runpath)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700232 }
Colin Crossbd75e1d2017-06-30 17:27:55 -0700233
234 // add "" to rpath so that test binaries can find libraries in their own test directory
235 linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, "")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700236}
237
Colin Crossb916a382016-07-29 17:28:03 -0700238func (test *testDecorator) linkerProps() []interface{} {
239 return []interface{}{&test.Properties}
Colin Cross4d9c2d12016-07-29 12:48:20 -0700240}
241
Colin Crossb916a382016-07-29 17:28:03 -0700242func NewTestInstaller() *baseInstaller {
243 return NewBaseInstaller("nativetest", "nativetest64", InstallInData)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700244}
245
Colin Crossb916a382016-07-29 17:28:03 -0700246type testBinary struct {
247 testDecorator
248 *binaryDecorator
249 *baseCompiler
Colin Crossb916a382016-07-29 17:28:03 -0700250 Properties TestBinaryProperties
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800251 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -0700252 testConfig android.Path
Colin Crossb916a382016-07-29 17:28:03 -0700253}
254
255func (test *testBinary) linkerProps() []interface{} {
256 props := append(test.testDecorator.linkerProps(), test.binaryDecorator.linkerProps()...)
257 props = append(props, &test.Properties)
258 return props
259}
260
261func (test *testBinary) linkerInit(ctx BaseModuleContext) {
262 test.testDecorator.linkerInit(ctx, test.binaryDecorator.baseLinker)
263 test.binaryDecorator.linkerInit(ctx)
264}
265
Colin Cross37047f12016-12-13 17:06:13 -0800266func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Crossb916a382016-07-29 17:28:03 -0700267 deps = test.testDecorator.linkerDeps(ctx, deps)
268 deps = test.binaryDecorator.linkerDeps(ctx, deps)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700269 return deps
270}
271
Colin Crossb916a382016-07-29 17:28:03 -0700272func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
273 flags = test.binaryDecorator.linkerFlags(ctx, flags)
274 flags = test.testDecorator.linkerFlags(ctx, flags)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700275 return flags
276}
277
Colin Crossb916a382016-07-29 17:28:03 -0700278func (test *testBinary) install(ctx ModuleContext, file android.Path) {
Colin Cross8a497952019-03-05 22:25:09 -0800279 test.data = android.PathsForModuleSrc(ctx, test.Properties.Data)
Dan Shi37ee3b82019-06-06 16:23:32 -0700280 var configs []tradefed.Config
281 if Bool(test.Properties.Require_root) {
282 configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer"})
Julien Desprezeb7398e2019-02-28 08:45:28 -0800283 }
Dan Shi37ee3b82019-06-06 16:23:32 -0700284 if Bool(test.testDecorator.Properties.Isolated) {
285 configs = append(configs, tradefed.Option{"not-shardable", "true"})
286 }
yelinhsieh9fc60402018-10-01 19:23:14 +0800287 if test.Properties.Test_options.Run_test_as != nil {
Dan Shi37ee3b82019-06-06 16:23:32 -0700288 configs = append(configs, tradefed.Option{"run-test-as", String(test.Properties.Test_options.Run_test_as)})
yelinhsieh9fc60402018-10-01 19:23:14 +0800289 }
290
Jack He33338892018-09-19 02:21:28 -0700291 test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
Dan Shi37ee3b82019-06-06 16:23:32 -0700292 test.Properties.Test_config_template, test.Properties.Test_suites, configs)
Colin Crossfaeb7aa2017-02-01 14:12:44 -0800293
Colin Cross600c9df2016-09-13 12:26:16 -0700294 test.binaryDecorator.baseInstaller.dir = "nativetest"
295 test.binaryDecorator.baseInstaller.dir64 = "nativetest64"
Dan Willemsen3340d602016-12-27 14:40:40 -0800296
297 if !Bool(test.Properties.No_named_install_directory) {
298 test.binaryDecorator.baseInstaller.relative = ctx.ModuleName()
Nan Zhang0007d812017-11-07 10:57:05 -0800299 } else if String(test.binaryDecorator.baseInstaller.Properties.Relative_install_path) == "" {
Dan Willemsen3340d602016-12-27 14:40:40 -0800300 ctx.PropertyErrorf("no_named_install_directory", "Module install directory may only be disabled if relative_install_path is set")
301 }
302
Dan Willemsen1d577e22016-08-29 15:53:15 -0700303 test.binaryDecorator.baseInstaller.install(ctx, file)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700304}
305
306func NewTest(hod android.HostOrDeviceSupported) *Module {
Colin Crossb916a382016-07-29 17:28:03 -0700307 module, binary := NewBinary(hod)
308 module.multilib = android.MultilibBoth
Dan Willemsen1d577e22016-08-29 15:53:15 -0700309 binary.baseInstaller = NewTestInstaller()
Colin Crossb916a382016-07-29 17:28:03 -0700310
311 test := &testBinary{
312 testDecorator: testDecorator{
313 linker: binary.baseLinker,
Colin Cross4d9c2d12016-07-29 12:48:20 -0700314 },
Colin Crossb916a382016-07-29 17:28:03 -0700315 binaryDecorator: binary,
316 baseCompiler: NewBaseCompiler(),
Colin Cross4d9c2d12016-07-29 12:48:20 -0700317 }
Colin Crossb916a382016-07-29 17:28:03 -0700318 module.compiler = test
319 module.linker = test
320 module.installer = test
Colin Cross4d9c2d12016-07-29 12:48:20 -0700321 return module
322}
323
Colin Crossb916a382016-07-29 17:28:03 -0700324type testLibrary struct {
325 testDecorator
326 *libraryDecorator
327}
328
329func (test *testLibrary) linkerProps() []interface{} {
330 return append(test.testDecorator.linkerProps(), test.libraryDecorator.linkerProps()...)
331}
332
333func (test *testLibrary) linkerInit(ctx BaseModuleContext) {
334 test.testDecorator.linkerInit(ctx, test.libraryDecorator.baseLinker)
335 test.libraryDecorator.linkerInit(ctx)
336}
337
Colin Cross37047f12016-12-13 17:06:13 -0800338func (test *testLibrary) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Crossb916a382016-07-29 17:28:03 -0700339 deps = test.testDecorator.linkerDeps(ctx, deps)
340 deps = test.libraryDecorator.linkerDeps(ctx, deps)
341 return deps
342}
343
344func (test *testLibrary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
345 flags = test.libraryDecorator.linkerFlags(ctx, flags)
346 flags = test.testDecorator.linkerFlags(ctx, flags)
347 return flags
348}
349
Colin Cross4d9c2d12016-07-29 12:48:20 -0700350func NewTestLibrary(hod android.HostOrDeviceSupported) *Module {
Colin Crossab3b7322016-12-09 14:46:15 -0800351 module, library := NewLibrary(android.HostAndDeviceSupported)
Dan Willemsen28bda512016-08-31 16:32:55 -0700352 library.baseInstaller = NewTestInstaller()
Colin Crossb916a382016-07-29 17:28:03 -0700353 test := &testLibrary{
354 testDecorator: testDecorator{
355 linker: library.baseLinker,
Colin Cross4d9c2d12016-07-29 12:48:20 -0700356 },
Colin Crossb916a382016-07-29 17:28:03 -0700357 libraryDecorator: library,
Colin Cross4d9c2d12016-07-29 12:48:20 -0700358 }
Colin Crossb916a382016-07-29 17:28:03 -0700359 module.linker = test
Colin Cross4d9c2d12016-07-29 12:48:20 -0700360 return module
361}
362
Colin Crosse28f4e22017-04-24 18:10:29 -0700363type BenchmarkProperties struct {
Anders Lewisb97e8182017-07-14 15:20:13 -0700364 // list of files or filegroup modules that provide data that should be installed alongside
365 // the test
Colin Cross27b922f2019-03-04 22:35:41 -0800366 Data []string `android:"path"`
Anders Lewisb97e8182017-07-14 15:20:13 -0700367
Colin Crosse28f4e22017-04-24 18:10:29 -0700368 // list of compatibility suites (for example "cts", "vts") that the module should be
369 // installed into.
Julien Despreze146e392018-08-02 15:00:46 -0700370 Test_suites []string `android:"arch_variant"`
371
372 // the name of the test configuration (for example "AndroidTest.xml") that should be
373 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -0800374 Test_config *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -0700375
376 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
377 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -0800378 Test_config_template *string `android:"path,arch_variant"`
Dan Shi37ee3b82019-06-06 16:23:32 -0700379
380 // Add RootTargetPreparer to auto generated test config. This guarantees the test to run
381 // with root permission.
382 Require_root *bool
Colin Crosse28f4e22017-04-24 18:10:29 -0700383}
384
Colin Crossb916a382016-07-29 17:28:03 -0700385type benchmarkDecorator struct {
386 *binaryDecorator
Colin Crosse28f4e22017-04-24 18:10:29 -0700387 Properties BenchmarkProperties
Anders Lewisb97e8182017-07-14 15:20:13 -0700388 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -0700389 testConfig android.Path
Colin Cross4d9c2d12016-07-29 12:48:20 -0700390}
391
Colin Crossb916a382016-07-29 17:28:03 -0700392func (benchmark *benchmarkDecorator) linkerInit(ctx BaseModuleContext) {
393 runpath := "../../lib"
394 if ctx.toolchain().Is64Bit() {
395 runpath += "64"
396 }
397 benchmark.baseLinker.dynamicProperties.RunPaths = append(benchmark.baseLinker.dynamicProperties.RunPaths, runpath)
398 benchmark.binaryDecorator.linkerInit(ctx)
399}
400
Colin Crosse28f4e22017-04-24 18:10:29 -0700401func (benchmark *benchmarkDecorator) linkerProps() []interface{} {
402 props := benchmark.binaryDecorator.linkerProps()
403 props = append(props, &benchmark.Properties)
404 return props
405}
406
Colin Cross37047f12016-12-13 17:06:13 -0800407func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Crossb916a382016-07-29 17:28:03 -0700408 deps = benchmark.binaryDecorator.linkerDeps(ctx, deps)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700409 deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark")
410 return deps
411}
412
Colin Crossb916a382016-07-29 17:28:03 -0700413func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) {
Colin Cross8a497952019-03-05 22:25:09 -0800414 benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data)
Dan Shi37ee3b82019-06-06 16:23:32 -0700415 var configs []tradefed.Config
416 if Bool(benchmark.Properties.Require_root) {
417 configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer"})
418 }
Jack He33338892018-09-19 02:21:28 -0700419 benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config,
Dan Shi37ee3b82019-06-06 16:23:32 -0700420 benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs)
Colin Cross303e21f2018-08-07 16:49:25 -0700421
Colin Cross28690e92017-09-08 16:20:30 -0700422 benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName())
423 benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName())
Dan Willemsen1d577e22016-08-29 15:53:15 -0700424 benchmark.binaryDecorator.baseInstaller.install(ctx, file)
Colin Crossb916a382016-07-29 17:28:03 -0700425}
426
Colin Cross4d9c2d12016-07-29 12:48:20 -0700427func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
Colin Crossb916a382016-07-29 17:28:03 -0700428 module, binary := NewBinary(hod)
429 module.multilib = android.MultilibBoth
Colin Cross28690e92017-09-08 16:20:30 -0700430 binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData)
Colin Crossb916a382016-07-29 17:28:03 -0700431
432 benchmark := &benchmarkDecorator{
433 binaryDecorator: binary,
Colin Cross4d9c2d12016-07-29 12:48:20 -0700434 }
Colin Crossb916a382016-07-29 17:28:03 -0700435 module.linker = benchmark
436 module.installer = benchmark
Colin Cross4d9c2d12016-07-29 12:48:20 -0700437 return module
438}