2016-07-29 21:48:20 +02:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
2019-09-17 10:35:23 +02:00
|
|
|
"strconv"
|
2016-07-29 21:48:20 +02:00
|
|
|
"strings"
|
|
|
|
|
2021-01-14 20:49:15 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
"android/soong/android"
|
2018-08-08 01:49:25 +02:00
|
|
|
"android/soong/tradefed"
|
2016-07-29 21:48:20 +02:00
|
|
|
)
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type TestProperties struct {
|
2016-07-29 21:48:20 +02:00
|
|
|
// if set, build against the gtest library. Defaults to true.
|
2016-09-13 21:26:16 +02:00
|
|
|
Gtest *bool
|
2018-08-21 21:40:08 +02:00
|
|
|
|
|
|
|
// if set, use the isolated gtest runner. Defaults to false.
|
|
|
|
Isolated *bool
|
2016-07-30 02:28:03 +02:00
|
|
|
}
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2018-10-01 13:23:14 +02:00
|
|
|
// Test option struct.
|
|
|
|
type TestOptions struct {
|
|
|
|
// The UID that you want to run the test as on a device.
|
|
|
|
Run_test_as *string
|
2020-08-15 21:24:26 +02:00
|
|
|
|
2020-06-18 19:07:00 +02:00
|
|
|
// A list of free-formed strings without spaces that categorize the test.
|
|
|
|
Test_suite_tag []string
|
2020-08-15 21:24:26 +02:00
|
|
|
|
|
|
|
// a list of extra test configuration files that should be installed with the module.
|
|
|
|
Extra_test_configs []string `android:"path,arch_variant"`
|
2020-11-13 23:33:46 +01:00
|
|
|
|
|
|
|
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
|
|
|
|
Unit_test *bool
|
2021-05-04 11:42:24 +02:00
|
|
|
|
|
|
|
// Add ShippingApiLevelModuleController to auto generated test config. If the device properties
|
2021-05-13 05:39:42 +02:00
|
|
|
// for the shipping api level is less than the min_shipping_api_level, skip this module.
|
|
|
|
Min_shipping_api_level *int64
|
|
|
|
|
|
|
|
// Add ShippingApiLevelModuleController to auto generated test config. If any of the device
|
|
|
|
// shipping api level and vendor api level properties are less than the
|
|
|
|
// vsr_min_shipping_api_level, skip this module.
|
|
|
|
// As this includes the shipping api level check, it is not allowed to define
|
|
|
|
// min_shipping_api_level at the same time with this property.
|
|
|
|
Vsr_min_shipping_api_level *int64
|
2021-05-04 11:42:24 +02:00
|
|
|
|
|
|
|
// Add MinApiLevelModuleController with ro.vndk.version property. If ro.vndk.version has an
|
2021-05-13 05:39:42 +02:00
|
|
|
// integer value and the value is less than the min_vndk_version, skip this module.
|
|
|
|
Min_vndk_version *int64
|
2018-10-01 13:23:14 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type TestBinaryProperties struct {
|
2016-07-29 21:48:20 +02:00
|
|
|
// Create a separate binary for each source file. Useful when there is
|
|
|
|
// global state that can not be torn down and reset between each test suite.
|
|
|
|
Test_per_src *bool
|
2016-12-27 23:40:40 +01:00
|
|
|
|
|
|
|
// Disables the creation of a test-specific directory when used with
|
|
|
|
// relative_install_path. Useful if several tests need to be in the same
|
|
|
|
// directory, but test_per_src doesn't work.
|
|
|
|
No_named_install_directory *bool
|
2017-02-01 23:12:44 +01:00
|
|
|
|
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test
|
2020-02-26 01:34:39 +01:00
|
|
|
Data []string `android:"path,arch_variant"`
|
2017-03-28 01:27:50 +02:00
|
|
|
|
2020-06-05 23:26:16 +02:00
|
|
|
// list of shared library modules that should be installed alongside the test
|
|
|
|
Data_libs []string `android:"arch_variant"`
|
|
|
|
|
2021-09-25 01:50:14 +02:00
|
|
|
// list of binary modules that should be installed alongside the test
|
|
|
|
Data_bins []string `android:"arch_variant"`
|
|
|
|
|
2017-03-28 01:27:50 +02:00
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
2017-09-19 01:49:28 +02:00
|
|
|
Test_suites []string `android:"arch_variant"`
|
2018-08-03 00:00:46 +02:00
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2018-09-19 11:21:28 +02:00
|
|
|
|
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
2018-10-01 13:23:14 +02:00
|
|
|
|
|
|
|
// Test options.
|
|
|
|
Test_options TestOptions
|
2019-06-07 01:23:32 +02:00
|
|
|
|
|
|
|
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
|
|
|
|
// with root permission.
|
|
|
|
Require_root *bool
|
2019-08-27 19:37:24 +02:00
|
|
|
|
|
|
|
// Add RunCommandTargetPreparer to stop framework before the test and start it after the test.
|
|
|
|
Disable_framework *bool
|
2019-09-17 10:35:23 +02:00
|
|
|
|
2019-09-26 20:41:36 +02:00
|
|
|
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
|
|
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
|
|
|
// explicitly.
|
|
|
|
Auto_gen_config *bool
|
2020-04-30 04:08:33 +02:00
|
|
|
|
|
|
|
// Add parameterized mainline modules to auto generated test config. The options will be
|
|
|
|
// handled by TradeFed to download and install the specified modules on the device.
|
|
|
|
Test_mainline_modules []string
|
2021-09-25 00:47:17 +02:00
|
|
|
|
|
|
|
// Install the test into a folder named for the module in all test suites.
|
|
|
|
Per_testcase_directory *bool
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2017-11-03 05:38:28 +01:00
|
|
|
android.RegisterModuleType("cc_test", TestFactory)
|
|
|
|
android.RegisterModuleType("cc_test_library", TestLibraryFactory)
|
|
|
|
android.RegisterModuleType("cc_benchmark", BenchmarkFactory)
|
|
|
|
android.RegisterModuleType("cc_test_host", TestHostFactory)
|
|
|
|
android.RegisterModuleType("cc_benchmark_host", BenchmarkHostFactory)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2019-03-20 01:00:29 +01:00
|
|
|
// cc_test generates a test config file and an executable binary file to test
|
|
|
|
// specific functionality on a device. The executable binary gets an implicit
|
|
|
|
// static_libs dependency on libgtests unless the gtest flag is set to false.
|
2017-11-03 05:38:28 +01:00
|
|
|
func TestFactory() android.Module {
|
2016-07-29 21:48:20 +02:00
|
|
|
module := NewTest(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-20 01:00:29 +01:00
|
|
|
// cc_test_library creates an archive of files (i.e. .o files) which is later
|
|
|
|
// referenced by another module (such as cc_test, cc_defaults or cc_test_library)
|
|
|
|
// for archiving or linking.
|
2017-11-03 05:38:28 +01:00
|
|
|
func TestLibraryFactory() android.Module {
|
2016-07-29 21:48:20 +02:00
|
|
|
module := NewTestLibrary(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-20 01:00:29 +01:00
|
|
|
// cc_benchmark compiles an executable binary that performs benchmark testing
|
|
|
|
// of a specific component in a device. Additional files such as test suites
|
|
|
|
// and test configuration are installed on the side of the compiled executed
|
|
|
|
// binary.
|
2017-11-03 05:38:28 +01:00
|
|
|
func BenchmarkFactory() android.Module {
|
2016-07-29 21:48:20 +02:00
|
|
|
module := NewBenchmark(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-20 01:00:29 +01:00
|
|
|
// cc_test_host compiles a test host binary.
|
2017-11-03 05:38:28 +01:00
|
|
|
func TestHostFactory() android.Module {
|
2016-07-29 21:48:20 +02:00
|
|
|
module := NewTest(android.HostSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-20 01:00:29 +01:00
|
|
|
// cc_benchmark_host compiles an executable binary that performs benchmark
|
|
|
|
// testing of a specific component in the host. Additional files such as
|
|
|
|
// test suites and test configuration are installed on the side of the
|
|
|
|
// compiled executed binary.
|
2017-11-03 05:38:28 +01:00
|
|
|
func BenchmarkHostFactory() android.Module {
|
2016-07-29 21:48:20 +02:00
|
|
|
module := NewBenchmark(android.HostSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type testPerSrc interface {
|
|
|
|
testPerSrc() bool
|
|
|
|
srcs() []string
|
2019-06-28 16:41:19 +02:00
|
|
|
isAllTestsVariation() bool
|
2016-07-30 02:28:03 +02:00
|
|
|
setSrc(string, string)
|
2019-06-28 16:41:19 +02:00
|
|
|
unsetSrc()
|
2016-07-30 02:28:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (test *testBinary) testPerSrc() bool {
|
|
|
|
return Bool(test.Properties.Test_per_src)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (test *testBinary) srcs() []string {
|
|
|
|
return test.baseCompiler.Properties.Srcs
|
|
|
|
}
|
|
|
|
|
2020-07-09 23:12:52 +02:00
|
|
|
func (test *testBinary) dataPaths() []android.DataPath {
|
2020-05-13 00:26:55 +02:00
|
|
|
return test.data
|
|
|
|
}
|
|
|
|
|
2019-06-28 16:41:19 +02:00
|
|
|
func (test *testBinary) isAllTestsVariation() bool {
|
|
|
|
stem := test.binaryDecorator.Properties.Stem
|
|
|
|
return stem != nil && *stem == ""
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testBinary) setSrc(name, src string) {
|
|
|
|
test.baseCompiler.Properties.Srcs = []string{src}
|
2017-11-07 19:57:05 +01:00
|
|
|
test.binaryDecorator.Properties.Stem = StringPtr(name)
|
2016-07-30 02:28:03 +02:00
|
|
|
}
|
|
|
|
|
2019-06-28 16:41:19 +02:00
|
|
|
func (test *testBinary) unsetSrc() {
|
|
|
|
test.baseCompiler.Properties.Srcs = nil
|
|
|
|
test.binaryDecorator.Properties.Stem = StringPtr("")
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
var _ testPerSrc = (*testBinary)(nil)
|
|
|
|
|
2019-06-28 16:41:19 +02:00
|
|
|
func TestPerSrcMutator(mctx android.BottomUpMutatorContext) {
|
2016-07-29 21:48:20 +02:00
|
|
|
if m, ok := mctx.Module().(*Module); ok {
|
2016-07-30 02:28:03 +02:00
|
|
|
if test, ok := m.linker.(testPerSrc); ok {
|
2019-06-28 16:41:19 +02:00
|
|
|
numTests := len(test.srcs())
|
|
|
|
if test.testPerSrc() && numTests > 0 {
|
2019-10-25 05:47:54 +02:00
|
|
|
if duplicate, found := android.CheckDuplicate(test.srcs()); found {
|
2019-02-28 10:06:34 +01:00
|
|
|
mctx.PropertyErrorf("srcs", "found a duplicate entry %q", duplicate)
|
|
|
|
return
|
|
|
|
}
|
2019-06-28 16:41:19 +02:00
|
|
|
testNames := make([]string, numTests)
|
2016-07-30 02:28:03 +02:00
|
|
|
for i, src := range test.srcs() {
|
2016-07-29 21:48:20 +02:00
|
|
|
testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src))
|
|
|
|
}
|
2019-06-28 16:41:19 +02:00
|
|
|
// In addition to creating one variation per test source file,
|
|
|
|
// create an additional "all tests" variation named "", and have it
|
|
|
|
// depends on all other test_per_src variations. This is useful to
|
|
|
|
// create subsequent dependencies of a given module on all
|
|
|
|
// test_per_src variations created above: by depending on
|
|
|
|
// variation "", that module will transitively depend on all the
|
|
|
|
// other test_per_src variations without the need to know their
|
|
|
|
// name or even their number.
|
|
|
|
testNames = append(testNames, "")
|
2016-07-29 21:48:20 +02:00
|
|
|
tests := mctx.CreateLocalVariations(testNames...)
|
2020-12-21 18:11:10 +01:00
|
|
|
allTests := tests[numTests]
|
|
|
|
allTests.(*Module).linker.(testPerSrc).unsetSrc()
|
2019-06-28 16:41:19 +02:00
|
|
|
// Prevent the "all tests" variation from being installable nor
|
|
|
|
// exporting to Make, as it won't create any output file.
|
2020-12-21 18:11:10 +01:00
|
|
|
allTests.(*Module).Properties.PreventInstall = true
|
|
|
|
allTests.(*Module).Properties.HideFromMake = true
|
2016-07-30 02:28:03 +02:00
|
|
|
for i, src := range test.srcs() {
|
|
|
|
tests[i].(*Module).linker.(testPerSrc).setSrc(testNames[i], src)
|
2020-12-21 18:11:10 +01:00
|
|
|
mctx.AddInterVariantDependency(testPerSrcDepTag, allTests, tests[i])
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2020-08-22 00:55:50 +02:00
|
|
|
mctx.AliasVariation("")
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type testDecorator struct {
|
|
|
|
Properties TestProperties
|
|
|
|
linker *baseLinker
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-09-13 21:26:16 +02:00
|
|
|
func (test *testDecorator) gtest() bool {
|
2018-04-11 01:14:46 +02:00
|
|
|
return BoolDefault(test.Properties.Gtest, true)
|
2016-09-13 21:26:16 +02:00
|
|
|
}
|
|
|
|
|
2020-04-29 00:09:12 +02:00
|
|
|
func (test *testDecorator) testBinary() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
2016-09-13 21:26:16 +02:00
|
|
|
if !test.gtest() {
|
2016-07-29 21:48:20 +02:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_HAS_STD_STRING")
|
2016-07-29 21:48:20 +02:00
|
|
|
if ctx.Host() {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-O0", "-g")
|
2016-07-29 21:48:20 +02:00
|
|
|
|
|
|
|
switch ctx.Os() {
|
|
|
|
case android.Windows:
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_WINDOWS")
|
2016-07-29 21:48:20 +02:00
|
|
|
case android.Linux:
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX")
|
2016-07-29 21:48:20 +02:00
|
|
|
case android.Darwin:
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_MAC")
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
} else {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX_ANDROID")
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
2016-09-13 21:26:16 +02:00
|
|
|
if test.gtest() {
|
2017-09-28 02:01:44 +02:00
|
|
|
if ctx.useSdk() && ctx.Device() {
|
2018-02-10 00:22:59 +01:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_c++", "libgtest_ndk_c++")
|
2018-08-21 21:40:08 +02:00
|
|
|
} else if BoolDefault(test.Properties.Isolated, false) {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_isolated_main")
|
2019-07-18 00:46:29 +02:00
|
|
|
// The isolated library requires liblog, but adding it
|
|
|
|
// as a static library means unit tests cannot override
|
|
|
|
// liblog functions. Instead make it a shared library
|
|
|
|
// dependency.
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, "liblog")
|
2016-07-29 21:48:20 +02:00
|
|
|
} else {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
return deps
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testDecorator) linkerInit(ctx BaseModuleContext, linker *baseLinker) {
|
2018-05-07 08:41:20 +02:00
|
|
|
// 1. Add ../../lib[64] to rpath so that out/host/linux-x86/nativetest/<test dir>/<test> can
|
2017-07-01 02:27:55 +02:00
|
|
|
// find out/host/linux-x86/lib[64]/library.so
|
2018-05-07 08:41:20 +02:00
|
|
|
// 2. Add ../../../lib[64] to rpath so that out/host/linux-x86/testcases/<test dir>/<CPU>/<test> can
|
|
|
|
// also find out/host/linux-x86/lib[64]/library.so
|
|
|
|
runpaths := []string{"../../lib", "../../../lib"}
|
|
|
|
for _, runpath := range runpaths {
|
|
|
|
if ctx.toolchain().Is64Bit() {
|
|
|
|
runpath += "64"
|
|
|
|
}
|
|
|
|
linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, runpath)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2017-07-01 02:27:55 +02:00
|
|
|
|
|
|
|
// add "" to rpath so that test binaries can find libraries in their own test directory
|
|
|
|
linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, "")
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testDecorator) linkerProps() []interface{} {
|
|
|
|
return []interface{}{&test.Properties}
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func NewTestInstaller() *baseInstaller {
|
|
|
|
return NewBaseInstaller("nativetest", "nativetest64", InstallInData)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type testBinary struct {
|
|
|
|
testDecorator
|
|
|
|
*binaryDecorator
|
|
|
|
*baseCompiler
|
2020-08-15 21:24:26 +02:00
|
|
|
Properties TestBinaryProperties
|
|
|
|
data []android.DataPath
|
|
|
|
testConfig android.Path
|
|
|
|
extraTestConfigs android.Paths
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testBinary) linkerProps() []interface{} {
|
|
|
|
props := append(test.testDecorator.linkerProps(), test.binaryDecorator.linkerProps()...)
|
|
|
|
props = append(props, &test.Properties)
|
|
|
|
return props
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testBinary) linkerInit(ctx BaseModuleContext) {
|
|
|
|
test.testDecorator.linkerInit(ctx, test.binaryDecorator.baseLinker)
|
|
|
|
test.binaryDecorator.linkerInit(ctx)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-12-14 02:06:13 +01:00
|
|
|
func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-30 02:28:03 +02:00
|
|
|
deps = test.testDecorator.linkerDeps(ctx, deps)
|
|
|
|
deps = test.binaryDecorator.linkerDeps(ctx, deps)
|
2020-06-05 23:26:16 +02:00
|
|
|
deps.DataLibs = append(deps.DataLibs, test.Properties.Data_libs...)
|
2021-09-25 01:50:14 +02:00
|
|
|
deps.DataBins = append(deps.DataBins, test.Properties.Data_bins...)
|
2016-07-29 21:48:20 +02:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = test.binaryDecorator.linkerFlags(ctx, flags)
|
|
|
|
flags = test.testDecorator.linkerFlags(ctx, flags)
|
|
|
|
return flags
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
2021-09-22 06:19:19 +02:00
|
|
|
// TODO: (b/167308193) Switch to /data/local/tests/unrestricted as the default install base.
|
|
|
|
testInstallBase := "/data/local/tmp"
|
2020-08-13 10:16:56 +02:00
|
|
|
if ctx.inVendor() || ctx.useVndk() {
|
|
|
|
testInstallBase = "/data/local/tests/vendor"
|
|
|
|
}
|
|
|
|
|
2020-07-09 23:12:52 +02:00
|
|
|
dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data)
|
|
|
|
|
|
|
|
for _, dataSrcPath := range dataSrcPaths {
|
|
|
|
test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
|
|
|
|
}
|
2020-06-05 23:26:16 +02:00
|
|
|
|
|
|
|
ctx.VisitDirectDepsWithTag(dataLibDepTag, func(dep android.Module) {
|
|
|
|
depName := ctx.OtherModuleName(dep)
|
2021-11-04 19:09:38 +01:00
|
|
|
linkableDep, ok := dep.(LinkableInterface)
|
2020-07-09 23:12:52 +02:00
|
|
|
if !ok {
|
2021-11-04 19:09:38 +01:00
|
|
|
ctx.ModuleErrorf("data_lib %q is not a LinkableInterface module", depName)
|
2020-07-09 23:12:52 +02:00
|
|
|
}
|
2021-11-04 19:09:38 +01:00
|
|
|
if linkableDep.OutputFile().Valid() {
|
2020-07-09 23:12:52 +02:00
|
|
|
test.data = append(test.data,
|
2021-11-04 19:09:38 +01:00
|
|
|
android.DataPath{SrcPath: linkableDep.OutputFile().Path(),
|
|
|
|
RelativeInstallPath: linkableDep.RelativeInstallPath()})
|
2021-09-25 01:50:14 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
ctx.VisitDirectDepsWithTag(dataBinDepTag, func(dep android.Module) {
|
|
|
|
depName := ctx.OtherModuleName(dep)
|
2021-11-04 19:09:38 +01:00
|
|
|
linkableDep, ok := dep.(LinkableInterface)
|
2021-09-25 01:50:14 +02:00
|
|
|
if !ok {
|
2021-11-04 19:09:38 +01:00
|
|
|
ctx.ModuleErrorf("data_bin %q is not a LinkableInterface module", depName)
|
2021-09-25 01:50:14 +02:00
|
|
|
}
|
2021-11-04 19:09:38 +01:00
|
|
|
if linkableDep.OutputFile().Valid() {
|
2021-09-25 01:50:14 +02:00
|
|
|
test.data = append(test.data,
|
2021-11-04 19:09:38 +01:00
|
|
|
android.DataPath{SrcPath: linkableDep.OutputFile().Path(),
|
|
|
|
RelativeInstallPath: linkableDep.RelativeInstallPath()})
|
2020-06-05 23:26:16 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-06-07 01:23:32 +02:00
|
|
|
var configs []tradefed.Config
|
2020-04-30 04:08:33 +02:00
|
|
|
for _, module := range test.Properties.Test_mainline_modules {
|
|
|
|
configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module})
|
|
|
|
}
|
2019-06-07 01:23:32 +02:00
|
|
|
if Bool(test.Properties.Require_root) {
|
2019-09-17 10:35:23 +02:00
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
2019-09-17 04:43:50 +02:00
|
|
|
} else {
|
|
|
|
var options []tradefed.Option
|
2020-04-30 04:08:33 +02:00
|
|
|
options = append(options, tradefed.Option{Name: "force-root", Value: "false"})
|
2019-09-17 10:35:23 +02:00
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
|
2019-08-27 19:37:24 +02:00
|
|
|
}
|
|
|
|
if Bool(test.Properties.Disable_framework) {
|
|
|
|
var options []tradefed.Option
|
2020-05-12 22:50:12 +02:00
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.StopServicesSetup", options})
|
2019-06-07 01:23:32 +02:00
|
|
|
}
|
2019-02-28 17:45:28 +01:00
|
|
|
if Bool(test.testDecorator.Properties.Isolated) {
|
2020-04-30 04:08:33 +02:00
|
|
|
configs = append(configs, tradefed.Option{Name: "not-shardable", Value: "true"})
|
2019-02-28 17:45:28 +01:00
|
|
|
}
|
2018-10-01 13:23:14 +02:00
|
|
|
if test.Properties.Test_options.Run_test_as != nil {
|
2020-04-30 04:08:33 +02:00
|
|
|
configs = append(configs, tradefed.Option{Name: "run-test-as", Value: String(test.Properties.Test_options.Run_test_as)})
|
2018-10-01 13:23:14 +02:00
|
|
|
}
|
2020-06-18 19:07:00 +02:00
|
|
|
for _, tag := range test.Properties.Test_options.Test_suite_tag {
|
|
|
|
configs = append(configs, tradefed.Option{Name: "test-suite-tag", Value: tag})
|
|
|
|
}
|
2021-05-13 05:39:42 +02:00
|
|
|
if test.Properties.Test_options.Min_shipping_api_level != nil {
|
|
|
|
if test.Properties.Test_options.Vsr_min_shipping_api_level != nil {
|
|
|
|
ctx.PropertyErrorf("test_options.min_shipping_api_level", "must not be set at the same time as 'vsr_min_shipping_api_level'.")
|
|
|
|
}
|
2021-05-04 11:42:24 +02:00
|
|
|
var options []tradefed.Option
|
2021-05-13 05:39:42 +02:00
|
|
|
options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_options.Min_shipping_api_level), 10)})
|
2021-05-04 11:42:24 +02:00
|
|
|
configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options})
|
2019-09-17 10:35:23 +02:00
|
|
|
}
|
2021-05-13 05:39:42 +02:00
|
|
|
if test.Properties.Test_options.Vsr_min_shipping_api_level != nil {
|
|
|
|
var options []tradefed.Option
|
|
|
|
options = append(options, tradefed.Option{Name: "vsr-min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_options.Vsr_min_shipping_api_level), 10)})
|
|
|
|
configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.ShippingApiLevelModuleController", options})
|
|
|
|
}
|
|
|
|
if test.Properties.Test_options.Min_vndk_version != nil {
|
2021-05-04 11:42:24 +02:00
|
|
|
var options []tradefed.Option
|
2021-05-13 05:39:42 +02:00
|
|
|
options = append(options, tradefed.Option{Name: "min-api-level", Value: strconv.FormatInt(int64(*test.Properties.Test_options.Min_vndk_version), 10)})
|
2021-05-04 11:42:24 +02:00
|
|
|
options = append(options, tradefed.Option{Name: "api-level-prop", Value: "ro.vndk.version"})
|
|
|
|
configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.MinApiLevelModuleController", options})
|
|
|
|
}
|
2018-10-01 13:23:14 +02:00
|
|
|
|
2018-09-19 11:21:28 +02:00
|
|
|
test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
|
2020-08-13 10:16:56 +02:00
|
|
|
test.Properties.Test_config_template, test.Properties.Test_suites, configs, test.Properties.Auto_gen_config, testInstallBase)
|
2017-02-01 23:12:44 +01:00
|
|
|
|
2020-08-15 21:24:26 +02:00
|
|
|
test.extraTestConfigs = android.PathsForModuleSrc(ctx, test.Properties.Test_options.Extra_test_configs)
|
|
|
|
|
2016-09-13 21:26:16 +02:00
|
|
|
test.binaryDecorator.baseInstaller.dir = "nativetest"
|
|
|
|
test.binaryDecorator.baseInstaller.dir64 = "nativetest64"
|
2016-12-27 23:40:40 +01:00
|
|
|
|
|
|
|
if !Bool(test.Properties.No_named_install_directory) {
|
|
|
|
test.binaryDecorator.baseInstaller.relative = ctx.ModuleName()
|
2017-11-07 19:57:05 +01:00
|
|
|
} else if String(test.binaryDecorator.baseInstaller.Properties.Relative_install_path) == "" {
|
2016-12-27 23:40:40 +01:00
|
|
|
ctx.PropertyErrorf("no_named_install_directory", "Module install directory may only be disabled if relative_install_path is set")
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:10:16 +01:00
|
|
|
if ctx.Host() && test.gtest() && test.Properties.Test_options.Unit_test == nil {
|
2021-01-14 20:49:15 +01:00
|
|
|
test.Properties.Test_options.Unit_test = proptools.BoolPtr(true)
|
|
|
|
}
|
2016-08-30 00:53:15 +02:00
|
|
|
test.binaryDecorator.baseInstaller.install(ctx, file)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewTest(hod android.HostOrDeviceSupported) *Module {
|
2021-11-01 20:32:43 +01:00
|
|
|
module, binary := newBinary(hod, false)
|
2016-07-30 02:28:03 +02:00
|
|
|
module.multilib = android.MultilibBoth
|
2016-08-30 00:53:15 +02:00
|
|
|
binary.baseInstaller = NewTestInstaller()
|
2016-07-30 02:28:03 +02:00
|
|
|
|
|
|
|
test := &testBinary{
|
|
|
|
testDecorator: testDecorator{
|
|
|
|
linker: binary.baseLinker,
|
2016-07-29 21:48:20 +02:00
|
|
|
},
|
2016-07-30 02:28:03 +02:00
|
|
|
binaryDecorator: binary,
|
|
|
|
baseCompiler: NewBaseCompiler(),
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2016-07-30 02:28:03 +02:00
|
|
|
module.compiler = test
|
|
|
|
module.linker = test
|
|
|
|
module.installer = test
|
2016-07-29 21:48:20 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type testLibrary struct {
|
|
|
|
testDecorator
|
|
|
|
*libraryDecorator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (test *testLibrary) linkerProps() []interface{} {
|
|
|
|
return append(test.testDecorator.linkerProps(), test.libraryDecorator.linkerProps()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (test *testLibrary) linkerInit(ctx BaseModuleContext) {
|
|
|
|
test.testDecorator.linkerInit(ctx, test.libraryDecorator.baseLinker)
|
|
|
|
test.libraryDecorator.linkerInit(ctx)
|
|
|
|
}
|
|
|
|
|
2016-12-14 02:06:13 +01:00
|
|
|
func (test *testLibrary) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-30 02:28:03 +02:00
|
|
|
deps = test.testDecorator.linkerDeps(ctx, deps)
|
|
|
|
deps = test.libraryDecorator.linkerDeps(ctx, deps)
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
|
|
|
func (test *testLibrary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|
|
|
flags = test.libraryDecorator.linkerFlags(ctx, flags)
|
|
|
|
flags = test.testDecorator.linkerFlags(ctx, flags)
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func NewTestLibrary(hod android.HostOrDeviceSupported) *Module {
|
2016-12-09 23:46:15 +01:00
|
|
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
2016-09-01 01:32:55 +02:00
|
|
|
library.baseInstaller = NewTestInstaller()
|
2016-07-30 02:28:03 +02:00
|
|
|
test := &testLibrary{
|
|
|
|
testDecorator: testDecorator{
|
|
|
|
linker: library.baseLinker,
|
2016-07-29 21:48:20 +02:00
|
|
|
},
|
2016-07-30 02:28:03 +02:00
|
|
|
libraryDecorator: library,
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2016-07-30 02:28:03 +02:00
|
|
|
module.linker = test
|
2016-07-29 21:48:20 +02:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2017-04-25 03:10:29 +02:00
|
|
|
type BenchmarkProperties struct {
|
2017-07-15 00:20:13 +02:00
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test
|
2019-03-05 07:35:41 +01:00
|
|
|
Data []string `android:"path"`
|
2017-07-15 00:20:13 +02:00
|
|
|
|
2017-04-25 03:10:29 +02:00
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
2018-08-03 00:00:46 +02:00
|
|
|
Test_suites []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2018-09-19 11:21:28 +02:00
|
|
|
|
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
2019-03-05 07:35:41 +01:00
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
2019-06-07 01:23:32 +02:00
|
|
|
|
|
|
|
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
|
|
|
|
// with root permission.
|
|
|
|
Require_root *bool
|
2019-09-26 20:41:36 +02:00
|
|
|
|
|
|
|
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
|
|
|
|
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
|
|
|
|
// explicitly.
|
|
|
|
Auto_gen_config *bool
|
2017-04-25 03:10:29 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
type benchmarkDecorator struct {
|
|
|
|
*binaryDecorator
|
2017-04-25 03:10:29 +02:00
|
|
|
Properties BenchmarkProperties
|
2017-07-15 00:20:13 +02:00
|
|
|
data android.Paths
|
2018-08-08 01:49:25 +02:00
|
|
|
testConfig android.Path
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2021-11-01 20:32:43 +01:00
|
|
|
func (benchmark *benchmarkDecorator) benchmarkBinary() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (benchmark *benchmarkDecorator) linkerInit(ctx BaseModuleContext) {
|
|
|
|
runpath := "../../lib"
|
|
|
|
if ctx.toolchain().Is64Bit() {
|
|
|
|
runpath += "64"
|
|
|
|
}
|
|
|
|
benchmark.baseLinker.dynamicProperties.RunPaths = append(benchmark.baseLinker.dynamicProperties.RunPaths, runpath)
|
|
|
|
benchmark.binaryDecorator.linkerInit(ctx)
|
|
|
|
}
|
|
|
|
|
2017-04-25 03:10:29 +02:00
|
|
|
func (benchmark *benchmarkDecorator) linkerProps() []interface{} {
|
|
|
|
props := benchmark.binaryDecorator.linkerProps()
|
|
|
|
props = append(props, &benchmark.Properties)
|
|
|
|
return props
|
|
|
|
}
|
|
|
|
|
2016-12-14 02:06:13 +01:00
|
|
|
func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-30 02:28:03 +02:00
|
|
|
deps = benchmark.binaryDecorator.linkerDeps(ctx, deps)
|
2016-07-29 21:48:20 +02:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark")
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-07-30 02:28:03 +02:00
|
|
|
func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) {
|
2019-03-06 07:25:09 +01:00
|
|
|
benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data)
|
2020-06-05 23:26:16 +02:00
|
|
|
|
2019-06-07 01:23:32 +02:00
|
|
|
var configs []tradefed.Config
|
|
|
|
if Bool(benchmark.Properties.Require_root) {
|
2019-09-17 10:35:23 +02:00
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
2019-06-07 01:23:32 +02:00
|
|
|
}
|
2018-09-19 11:21:28 +02:00
|
|
|
benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config,
|
2019-09-26 20:41:36 +02:00
|
|
|
benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs, benchmark.Properties.Auto_gen_config)
|
2018-08-08 01:49:25 +02:00
|
|
|
|
2017-09-09 01:20:30 +02:00
|
|
|
benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName())
|
|
|
|
benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName())
|
2016-08-30 00:53:15 +02:00
|
|
|
benchmark.binaryDecorator.baseInstaller.install(ctx, file)
|
2016-07-30 02:28:03 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
|
2021-11-01 20:32:43 +01:00
|
|
|
module, binary := newBinary(hod, false)
|
2016-07-30 02:28:03 +02:00
|
|
|
module.multilib = android.MultilibBoth
|
2017-09-09 01:20:30 +02:00
|
|
|
binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData)
|
2016-07-30 02:28:03 +02:00
|
|
|
|
|
|
|
benchmark := &benchmarkDecorator{
|
|
|
|
binaryDecorator: binary,
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
2016-07-30 02:28:03 +02:00
|
|
|
module.linker = benchmark
|
|
|
|
module.installer = benchmark
|
2016-07-29 21:48:20 +02:00
|
|
|
return module
|
|
|
|
}
|