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 15package cc 16 17import ( 18 "path/filepath" 19 "strconv" 20 21 "github.com/google/blueprint/proptools" 22 23 "android/soong/android" 24 "android/soong/tradefed" 25) 26 27// TestLinkerProperties properties to be registered via the linker 28type TestLinkerProperties struct { 29 // if set, build against the gtest library. Defaults to true. 30 Gtest *bool 31 32 // if set, use the isolated gtest runner. Defaults to true if gtest is also true and the arch is Windows, false 33 // otherwise. 34 Isolated *bool 35} 36 37// TestInstallerProperties properties to be registered via the installer 38type TestInstallerProperties struct { 39 // list of compatibility suites (for example "cts", "vts") that the module should be installed into. 40 Test_suites []string `android:"arch_variant"` 41} 42 43// Test option struct. 44type TestOptions struct { 45 android.CommonTestOptions 46 47 // The UID that you want to run the test as on a device. 48 Run_test_as *string 49 50 // A list of free-formed strings without spaces that categorize the test. 51 Test_suite_tag []string 52 53 // a list of extra test configuration files that should be installed with the module. 54 Extra_test_configs []string `android:"path,arch_variant"` 55 56 // Add ShippingApiLevelModuleController to auto generated test config. If the device properties 57 // for the shipping api level is less than the min_shipping_api_level, skip this module. 58 Min_shipping_api_level *int64 59 60 // Add ShippingApiLevelModuleController to auto generated test config. If any of the device 61 // shipping api level and vendor api level properties are less than the 62 // vsr_min_shipping_api_level, skip this module. 63 // As this includes the shipping api level check, it is not allowed to define 64 // min_shipping_api_level at the same time with this property. 65 Vsr_min_shipping_api_level *int64 66 67 // Add MinApiLevelModuleController with ro.vndk.version property. If ro.vndk.version has an 68 // integer value and the value is less than the min_vndk_version, skip this module. 69 Min_vndk_version *int64 70 71 // Extra <option> tags to add to the auto generated test xml file under the test runner, e.g., GTest. 72 // The "key" is optional in each of these. 73 Test_runner_options []tradefed.Option 74} 75 76type TestBinaryProperties struct { 77 // Disables the creation of a test-specific directory when used with 78 // relative_install_path. Useful if several tests need to be in the same 79 // directory. 80 No_named_install_directory *bool 81 82 // list of files or filegroup modules that provide data that should be installed alongside 83 // the test 84 Data []string `android:"path,arch_variant"` 85 86 // Same as data, but adds depedencies on modules using the device's os variant, and common 87 // architecture's variant. Can be useful to add device-built apps to the data of a host 88 // test. 89 Device_common_data []string `android:"path_device_common"` 90 91 // Same as data, but adds depedencies on modules using the device's os variant, and the device's 92 // first architecture's variant. Can be useful to add device-built apps to the data of a host 93 // test. 94 Device_first_data []string `android:"path_device_first"` 95 96 // list of shared library modules that should be installed alongside the test 97 Data_libs []string `android:"arch_variant"` 98 99 // list of binary modules that should be installed alongside the test 100 Data_bins []string `android:"arch_variant"` 101 102 // the name of the test configuration (for example "AndroidTest.xml") that should be 103 // installed with the module. 104 Test_config *string `android:"path,arch_variant"` 105 106 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that 107 // should be installed with the module. 108 Test_config_template *string `android:"path,arch_variant"` 109 110 // Test options. 111 Test_options TestOptions 112 113 // Add RootTargetPreparer to auto generated test config. This guarantees the test to run 114 // with root permission. 115 Require_root *bool 116 117 // Add RunCommandTargetPreparer to stop framework before the test and start it after the test. 118 Disable_framework *bool 119 120 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml 121 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true 122 // explicitly. 123 Auto_gen_config *bool 124 125 // Add parameterized mainline modules to auto generated test config. The options will be 126 // handled by TradeFed to download and install the specified modules on the device. 127 Test_mainline_modules []string 128 129 // Install the test into a folder named for the module in all test suites. 130 Per_testcase_directory *bool 131} 132 133func init() { 134 android.RegisterModuleType("cc_test", TestFactory) 135 android.RegisterModuleType("cc_test_library", TestLibraryFactory) 136 android.RegisterModuleType("cc_benchmark", BenchmarkFactory) 137 android.RegisterModuleType("cc_test_host", TestHostFactory) 138 android.RegisterModuleType("cc_benchmark_host", BenchmarkHostFactory) 139} 140 141// cc_test generates a test config file and an executable binary file to test 142// specific functionality on a device. The executable binary gets an implicit 143// static_libs dependency on libgtests unless the gtest flag is set to false. 144func TestFactory() android.Module { 145 module := NewTest(android.HostAndDeviceSupported) 146 return module.Init() 147} 148 149// cc_test_library creates an archive of files (i.e. .o files) which is later 150// referenced by another module (such as cc_test, cc_defaults or cc_test_library) 151// for archiving or linking. 152func TestLibraryFactory() android.Module { 153 module := NewTestLibrary(android.HostAndDeviceSupported) 154 return module.Init() 155} 156 157// cc_benchmark compiles an executable binary that performs benchmark testing 158// of a specific component in a device. Additional files such as test suites 159// and test configuration are installed on the side of the compiled executed 160// binary. 161func BenchmarkFactory() android.Module { 162 module := NewBenchmark(android.HostAndDeviceSupported) 163 module.testModule = true 164 return module.Init() 165} 166 167// cc_test_host compiles a test host binary. 168func TestHostFactory() android.Module { 169 module := NewTest(android.HostSupported) 170 return module.Init() 171} 172 173// cc_benchmark_host compiles an executable binary that performs benchmark 174// testing of a specific component in the host. Additional files such as 175// test suites and test configuration are installed on the side of the 176// compiled executed binary. 177func BenchmarkHostFactory() android.Module { 178 module := NewBenchmark(android.HostSupported) 179 return module.Init() 180} 181 182func (test *testBinary) dataPaths() []android.DataPath { 183 return test.data 184} 185 186func (test *testBinary) testBinary() bool { 187 return true 188} 189 190type testDecorator struct { 191 LinkerProperties TestLinkerProperties 192 InstallerProperties TestInstallerProperties 193 installer *baseInstaller 194 linker *baseLinker 195} 196 197func (test *testDecorator) gtest() bool { 198 return BoolDefault(test.LinkerProperties.Gtest, true) 199} 200 201func (test *testDecorator) isolated(ctx android.EarlyModuleContext) bool { 202 return BoolDefault(test.LinkerProperties.Isolated, false) 203} 204 205// NOTE: Keep this in sync with cc/cc_test.bzl#gtest_copts 206func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { 207 if !test.gtest() { 208 return flags 209 } 210 211 flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_HAS_STD_STRING") 212 if ctx.Host() { 213 flags.Local.CFlags = append(flags.Local.CFlags, "-O0", "-g") 214 215 switch ctx.Os() { 216 case android.Windows: 217 flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_WINDOWS") 218 case android.Linux: 219 flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX") 220 case android.Darwin: 221 flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_MAC") 222 } 223 } else { 224 flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX_ANDROID") 225 } 226 227 return flags 228} 229 230func (test *testDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { 231 if test.gtest() { 232 if ctx.useSdk() && ctx.Device() { 233 deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_c++", "libgtest_ndk_c++") 234 } else if test.isolated(ctx) { 235 deps.StaticLibs = append(deps.StaticLibs, "libgtest_isolated_main") 236 // The isolated library requires liblog, but adding it 237 // as a static library means unit tests cannot override 238 // liblog functions. Instead make it a shared library 239 // dependency. 240 deps.SharedLibs = append(deps.SharedLibs, "liblog") 241 } else { 242 deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest") 243 } 244 } 245 246 return deps 247} 248 249func (test *testDecorator) linkerProps() []interface{} { 250 return []interface{}{&test.LinkerProperties} 251} 252 253func (test *testDecorator) installerProps() []interface{} { 254 return []interface{}{&test.InstallerProperties} 255} 256 257func (test *testDecorator) moduleInfoJSON(ctx android.ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) { 258 if android.PrefixInList(moduleInfoJSON.CompatibilitySuites, "mts-") && 259 !android.InList("mts", moduleInfoJSON.CompatibilitySuites) { 260 moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "mts") 261 } 262} 263 264func NewTestInstaller() *baseInstaller { 265 return NewBaseInstaller("nativetest", "nativetest64", InstallInData) 266} 267 268type testBinary struct { 269 *testDecorator 270 *binaryDecorator 271 *baseCompiler 272 Properties TestBinaryProperties 273 data []android.DataPath 274 testConfig android.Path 275 extraTestConfigs android.Paths 276} 277 278func (test *testBinary) linkerProps() []interface{} { 279 props := append(test.testDecorator.linkerProps(), test.binaryDecorator.linkerProps()...) 280 props = append(props, &test.Properties) 281 return props 282} 283 284func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps { 285 deps = test.testDecorator.linkerDeps(ctx, deps) 286 deps = test.binaryDecorator.linkerDeps(ctx, deps) 287 deps.DataLibs = append(deps.DataLibs, test.Properties.Data_libs...) 288 deps.DataBins = append(deps.DataBins, test.Properties.Data_bins...) 289 return deps 290} 291 292func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags { 293 flags = test.binaryDecorator.linkerFlags(ctx, flags) 294 flags = test.testDecorator.linkerFlags(ctx, flags) 295 296 // Add a default rpath to allow tests to dlopen libraries specified in data_libs. 297 // Host modules already get an rpath specified in linker.go. 298 if !ctx.Host() { 299 flags.Global.LdFlags = append(flags.Global.LdFlags, `-Wl,-rpath,\$$ORIGIN`) 300 } 301 return flags 302} 303 304func (test *testBinary) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) { 305 if ctx.Host() && Bool(test.Properties.Test_options.Unit_test) { 306 moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "host-unit-tests") 307 } 308 moduleInfoJSON.TestOptionsTags = append(moduleInfoJSON.TestOptionsTags, test.Properties.Test_options.Tags...) 309 moduleInfoJSON.TestMainlineModules = append(moduleInfoJSON.TestMainlineModules, test.Properties.Test_mainline_modules...) 310 if test.testConfig != nil { 311 if _, ok := test.testConfig.(android.WritablePath); ok { 312 moduleInfoJSON.AutoTestConfig = []string{"true"} 313 } 314 moduleInfoJSON.TestConfig = append(moduleInfoJSON.TestConfig, test.testConfig.String()) 315 } 316 moduleInfoJSON.TestConfig = append(moduleInfoJSON.TestConfig, test.extraTestConfigs.Strings()...) 317 318 moduleInfoJSON.DataDependencies = append(moduleInfoJSON.DataDependencies, test.Properties.Data_bins...) 319 320 if len(test.InstallerProperties.Test_suites) > 0 { 321 moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, test.InstallerProperties.Test_suites...) 322 } else { 323 moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "null-suite") 324 } 325 326 test.binaryDecorator.moduleInfoJSON(ctx, moduleInfoJSON) 327 test.testDecorator.moduleInfoJSON(ctx, moduleInfoJSON) 328 moduleInfoJSON.Class = []string{"NATIVE_TESTS"} 329 330} 331 332func (test *testBinary) installerProps() []interface{} { 333 return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...) 334} 335 336func (test *testBinary) install(ctx ModuleContext, file android.Path) { 337 dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data) 338 dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Device_common_data)...) 339 dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Device_first_data)...) 340 341 for _, dataSrcPath := range dataSrcPaths { 342 test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath}) 343 } 344 345 ctx.VisitDirectDepsWithTag(dataLibDepTag, func(dep android.Module) { 346 depName := ctx.OtherModuleName(dep) 347 linkableDep, ok := dep.(LinkableInterface) 348 if !ok { 349 ctx.ModuleErrorf("data_lib %q is not a LinkableInterface module", depName) 350 } 351 if linkableDep.OutputFile().Valid() { 352 test.data = append(test.data, 353 android.DataPath{SrcPath: linkableDep.OutputFile().Path(), 354 RelativeInstallPath: linkableDep.RelativeInstallPath()}) 355 } 356 }) 357 ctx.VisitDirectDepsWithTag(dataBinDepTag, func(dep android.Module) { 358 depName := ctx.OtherModuleName(dep) 359 linkableDep, ok := dep.(LinkableInterface) 360 if !ok { 361 ctx.ModuleErrorf("data_bin %q is not a LinkableInterface module", depName) 362 } 363 if linkableDep.OutputFile().Valid() { 364 test.data = append(test.data, 365 android.DataPath{SrcPath: linkableDep.OutputFile().Path(), 366 RelativeInstallPath: linkableDep.RelativeInstallPath()}) 367 } 368 }) 369 370 testInstallBase := getTestInstallBase(ctx.InVendorOrProduct()) 371 configs := getTradefedConfigOptions(ctx, &test.Properties, test.isolated(ctx), ctx.Device()) 372 373 test.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ 374 TestConfigProp: test.Properties.Test_config, 375 TestConfigTemplateProp: test.Properties.Test_config_template, 376 TestSuites: test.testDecorator.InstallerProperties.Test_suites, 377 Config: configs, 378 TestRunnerOptions: test.Properties.Test_options.Test_runner_options, 379 AutoGenConfig: test.Properties.Auto_gen_config, 380 TestInstallBase: testInstallBase, 381 DeviceTemplate: "${NativeTestConfigTemplate}", 382 HostTemplate: "${NativeHostTestConfigTemplate}", 383 }) 384 385 test.extraTestConfigs = android.PathsForModuleSrc(ctx, test.Properties.Test_options.Extra_test_configs) 386 387 test.binaryDecorator.baseInstaller.dir = "nativetest" 388 test.binaryDecorator.baseInstaller.dir64 = "nativetest64" 389 390 if !Bool(test.Properties.No_named_install_directory) { 391 test.binaryDecorator.baseInstaller.relative = ctx.ModuleName() 392 } else if String(test.binaryDecorator.baseInstaller.Properties.Relative_install_path) == "" { 393 ctx.PropertyErrorf("no_named_install_directory", "Module install directory may only be disabled if relative_install_path is set") 394 } 395 396 if ctx.Host() && test.gtest() && test.Properties.Test_options.Unit_test == nil { 397 test.Properties.Test_options.Unit_test = proptools.BoolPtr(true) 398 } 399 400 test.binaryDecorator.baseInstaller.installTestData(ctx, test.data) 401 test.binaryDecorator.baseInstaller.install(ctx, file) 402} 403 404func getTestInstallBase(useVendor bool) string { 405 // TODO: (b/167308193) Switch to /data/local/tests/unrestricted as the default install base. 406 testInstallBase := "/data/local/tmp" 407 if useVendor { 408 testInstallBase = "/data/local/tests/vendor" 409 } 410 return testInstallBase 411} 412 413func getTradefedConfigOptions(ctx android.EarlyModuleContext, properties *TestBinaryProperties, isolated bool, device bool) []tradefed.Config { 414 var configs []tradefed.Config 415 416 for _, module := range properties.Test_mainline_modules { 417 configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module}) 418 } 419 if device { 420 if Bool(properties.Require_root) { 421 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) 422 } else { 423 var options []tradefed.Option 424 options = append(options, tradefed.Option{Name: "force-root", Value: "false"}) 425 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options}) 426 } 427 if Bool(properties.Disable_framework) { 428 var options []tradefed.Option 429 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.StopServicesSetup", options}) 430 } 431 } 432 if isolated { 433 configs = append(configs, tradefed.Option{Name: "not-shardable", Value: "true"}) 434 } 435 if properties.Test_options.Run_test_as != nil { 436 configs = append(configs, tradefed.Option{Name: "run-test-as", Value: String(properties.Test_options.Run_test_as)}) 437 } 438 for _, tag := range properties.Test_options.Test_suite_tag { 439 configs = append(configs, tradefed.Option{Name: "test-suite-tag", Value: tag}) 440 } 441 if properties.Test_options.Min_shipping_api_level != nil { 442 if properties.Test_options.Vsr_min_shipping_api_level != nil { 443 ctx.PropertyErrorf("test_options.min_shipping_api_level", "must not be set at the same time as 'vsr_min_shipping_api_level'.") 444 } 445 var options []tradefed.Option 446 options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*properties.Test_options.Min_shipping_api_level), 10)}) 447 configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options}) 448 } 449 if properties.Test_options.Vsr_min_shipping_api_level != nil { 450 var options []tradefed.Option 451 options = append(options, tradefed.Option{Name: "vsr-min-api-level", Value: strconv.FormatInt(int64(*properties.Test_options.Vsr_min_shipping_api_level), 10)}) 452 configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options}) 453 } 454 if properties.Test_options.Min_vndk_version != nil { 455 var options []tradefed.Option 456 options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*properties.Test_options.Min_vndk_version), 10)}) 457 options = append(options, tradefed.Option{Name: "api-level-prop", Value: "ro.vndk.version"}) 458 configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.MinApiLevelModuleController", options}) 459 } 460 return configs 461} 462 463func NewTest(hod android.HostOrDeviceSupported) *Module { 464 module, binary := newBinary(hod) 465 module.multilib = android.MultilibBoth 466 module.testModule = true 467 binary.baseInstaller = NewTestInstaller() 468 469 test := &testBinary{ 470 testDecorator: &testDecorator{ 471 linker: binary.baseLinker, 472 installer: binary.baseInstaller, 473 }, 474 binaryDecorator: binary, 475 baseCompiler: NewBaseCompiler(), 476 } 477 module.compiler = test 478 module.linker = test 479 module.installer = test 480 return module 481} 482 483type testLibrary struct { 484 *testDecorator 485 *libraryDecorator 486} 487 488func (test *testLibrary) testLibrary() bool { 489 return true 490} 491 492func (test *testLibrary) linkerProps() []interface{} { 493 var props []interface{} 494 props = append(props, test.testDecorator.linkerProps()...) 495 return append(props, test.libraryDecorator.linkerProps()...) 496} 497 498func (test *testLibrary) linkerDeps(ctx DepsContext, deps Deps) Deps { 499 deps = test.testDecorator.linkerDeps(ctx, deps) 500 deps = test.libraryDecorator.linkerDeps(ctx, deps) 501 return deps 502} 503 504func (test *testLibrary) linkerFlags(ctx ModuleContext, flags Flags) Flags { 505 flags = test.libraryDecorator.linkerFlags(ctx, flags) 506 flags = test.testDecorator.linkerFlags(ctx, flags) 507 return flags 508} 509 510func (test *testLibrary) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) { 511 if len(test.InstallerProperties.Test_suites) > 0 { 512 moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, test.InstallerProperties.Test_suites...) 513 } 514 515 test.libraryDecorator.moduleInfoJSON(ctx, moduleInfoJSON) 516 test.testDecorator.moduleInfoJSON(ctx, moduleInfoJSON) 517} 518 519func (test *testLibrary) installerProps() []interface{} { 520 return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...) 521} 522 523func NewTestLibrary(hod android.HostOrDeviceSupported) *Module { 524 module, library := NewLibrary(android.HostAndDeviceSupported) 525 library.baseInstaller = NewTestInstaller() 526 test := &testLibrary{ 527 testDecorator: &testDecorator{ 528 linker: library.baseLinker, 529 installer: library.baseInstaller, 530 }, 531 libraryDecorator: library, 532 } 533 module.linker = test 534 module.installer = test 535 return module 536} 537 538type BenchmarkProperties struct { 539 // list of files or filegroup modules that provide data that should be installed alongside 540 // the test 541 Data []string `android:"path"` 542 543 // list of compatibility suites (for example "cts", "vts") that the module should be 544 // installed into. 545 Test_suites []string `android:"arch_variant"` 546 547 // the name of the test configuration (for example "AndroidTest.xml") that should be 548 // installed with the module. 549 Test_config *string `android:"path,arch_variant"` 550 551 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that 552 // should be installed with the module. 553 Test_config_template *string `android:"path,arch_variant"` 554 555 // Add RootTargetPreparer to auto generated test config. This guarantees the test to run 556 // with root permission. 557 Require_root *bool 558 559 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml 560 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true 561 // explicitly. 562 Auto_gen_config *bool 563} 564 565type benchmarkDecorator struct { 566 *binaryDecorator 567 Properties BenchmarkProperties 568 data []android.DataPath 569 testConfig android.Path 570} 571 572func (benchmark *benchmarkDecorator) benchmarkBinary() bool { 573 return true 574} 575 576func (benchmark *benchmarkDecorator) linkerProps() []interface{} { 577 props := benchmark.binaryDecorator.linkerProps() 578 props = append(props, &benchmark.Properties) 579 return props 580} 581 582func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { 583 deps = benchmark.binaryDecorator.linkerDeps(ctx, deps) 584 deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark") 585 return deps 586} 587 588func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) { 589 for _, d := range android.PathsForModuleSrc(ctx, benchmark.Properties.Data) { 590 benchmark.data = append(benchmark.data, android.DataPath{SrcPath: d}) 591 } 592 593 var configs []tradefed.Config 594 if Bool(benchmark.Properties.Require_root) { 595 configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) 596 } 597 benchmark.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ 598 TestConfigProp: benchmark.Properties.Test_config, 599 TestConfigTemplateProp: benchmark.Properties.Test_config_template, 600 TestSuites: benchmark.Properties.Test_suites, 601 Config: configs, 602 AutoGenConfig: benchmark.Properties.Auto_gen_config, 603 DeviceTemplate: "${NativeBenchmarkTestConfigTemplate}", 604 HostTemplate: "${NativeBenchmarkTestConfigTemplate}", 605 }) 606 607 benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName()) 608 benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName()) 609 benchmark.binaryDecorator.baseInstaller.installTestData(ctx, benchmark.data) 610 benchmark.binaryDecorator.baseInstaller.install(ctx, file) 611} 612 613func (benchmark *benchmarkDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) { 614 benchmark.binaryDecorator.moduleInfoJSON(ctx, moduleInfoJSON) 615 616 moduleInfoJSON.Class = []string{"NATIVE_TESTS"} 617 if len(benchmark.Properties.Test_suites) > 0 { 618 moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, benchmark.Properties.Test_suites...) 619 } else { 620 moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "null-suite") 621 } 622 623 if android.PrefixInList(moduleInfoJSON.CompatibilitySuites, "mts-") && 624 !android.InList("mts", moduleInfoJSON.CompatibilitySuites) { 625 moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "mts") 626 } 627 628 if benchmark.testConfig != nil { 629 if _, ok := benchmark.testConfig.(android.WritablePath); ok { 630 moduleInfoJSON.AutoTestConfig = []string{"true"} 631 } 632 moduleInfoJSON.TestConfig = []string{benchmark.testConfig.String()} 633 } 634} 635 636func NewBenchmark(hod android.HostOrDeviceSupported) *Module { 637 module, binary := newBinary(hod) 638 module.multilib = android.MultilibBoth 639 binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData) 640 641 benchmark := &benchmarkDecorator{ 642 binaryDecorator: binary, 643 } 644 module.linker = benchmark 645 module.installer = benchmark 646 return module 647} 648