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