2016-07-30 03:48:20 +08: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 16:35:23 +08:00
|
|
|
"strconv"
|
2016-07-30 03:48:20 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2018-08-08 07:49:25 +08:00
|
|
|
"android/soong/tradefed"
|
2016-07-30 03:48:20 +08:00
|
|
|
)
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
type TestProperties struct {
|
2016-07-30 03:48:20 +08:00
|
|
|
// if set, build against the gtest library. Defaults to true.
|
2016-09-14 03:26:16 +08:00
|
|
|
Gtest *bool
|
2018-08-22 03:40:08 +08:00
|
|
|
|
|
|
|
// if set, use the isolated gtest runner. Defaults to false.
|
|
|
|
Isolated *bool
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2018-10-01 19:23:14 +08: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-16 03:24:26 +08:00
|
|
|
|
2020-06-19 01:07:00 +08:00
|
|
|
// A list of free-formed strings without spaces that categorize the test.
|
|
|
|
Test_suite_tag []string
|
2020-08-16 03:24:26 +08: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-14 06:33:46 +08:00
|
|
|
|
|
|
|
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
|
|
|
|
Unit_test *bool
|
2018-10-01 19:23:14 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
type TestBinaryProperties struct {
|
2016-07-30 03:48:20 +08: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-28 06:40:40 +08: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-02 06:12:44 +08:00
|
|
|
|
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test
|
2020-02-26 08:34:39 +08:00
|
|
|
Data []string `android:"path,arch_variant"`
|
2017-03-28 07:27:50 +08:00
|
|
|
|
2020-06-06 05:26:16 +08:00
|
|
|
// list of shared library modules that should be installed alongside the test
|
|
|
|
Data_libs []string `android:"arch_variant"`
|
|
|
|
|
2017-03-28 07:27:50 +08:00
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
2017-09-19 07:49:28 +08:00
|
|
|
Test_suites []string `android:"arch_variant"`
|
2018-08-03 06:00:46 +08:00
|
|
|
|
|
|
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
|
|
|
// installed with the module.
|
2019-03-05 14:35:41 +08:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2018-09-19 17:21:28 +08:00
|
|
|
|
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
2019-03-05 14:35:41 +08:00
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
2018-10-01 19:23:14 +08:00
|
|
|
|
|
|
|
// Test options.
|
|
|
|
Test_options TestOptions
|
2019-06-07 07:23:32 +08:00
|
|
|
|
|
|
|
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
|
|
|
|
// with root permission.
|
|
|
|
Require_root *bool
|
2019-08-28 01:37:24 +08:00
|
|
|
|
|
|
|
// Add RunCommandTargetPreparer to stop framework before the test and start it after the test.
|
|
|
|
Disable_framework *bool
|
2019-09-17 16:35:23 +08:00
|
|
|
|
|
|
|
// Add MinApiLevelModuleController to auto generated test config. If the device property of
|
|
|
|
// "ro.product.first_api_level" < Test_min_api_level, then skip this module.
|
|
|
|
Test_min_api_level *int64
|
|
|
|
|
|
|
|
// Add MinApiLevelModuleController to auto generated test config. If the device property of
|
|
|
|
// "ro.build.version.sdk" < Test_min_sdk_version, then skip this module.
|
|
|
|
Test_min_sdk_version *int64
|
2019-09-27 02:41:36 +08: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 10:08:33 +08: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
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2017-11-03 12:38:28 +08: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-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-20 08:00:29 +08: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 12:38:28 +08:00
|
|
|
func TestFactory() android.Module {
|
2016-07-30 03:48:20 +08:00
|
|
|
module := NewTest(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-20 08:00:29 +08: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 12:38:28 +08:00
|
|
|
func TestLibraryFactory() android.Module {
|
2016-07-30 03:48:20 +08:00
|
|
|
module := NewTestLibrary(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-20 08:00:29 +08: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 12:38:28 +08:00
|
|
|
func BenchmarkFactory() android.Module {
|
2016-07-30 03:48:20 +08:00
|
|
|
module := NewBenchmark(android.HostAndDeviceSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-20 08:00:29 +08:00
|
|
|
// cc_test_host compiles a test host binary.
|
2017-11-03 12:38:28 +08:00
|
|
|
func TestHostFactory() android.Module {
|
2016-07-30 03:48:20 +08:00
|
|
|
module := NewTest(android.HostSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2019-03-20 08:00:29 +08: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 12:38:28 +08:00
|
|
|
func BenchmarkHostFactory() android.Module {
|
2016-07-30 03:48:20 +08:00
|
|
|
module := NewBenchmark(android.HostSupported)
|
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
type testPerSrc interface {
|
|
|
|
testPerSrc() bool
|
|
|
|
srcs() []string
|
2019-06-28 22:41:19 +08:00
|
|
|
isAllTestsVariation() bool
|
2016-07-30 08:28:03 +08:00
|
|
|
setSrc(string, string)
|
2019-06-28 22:41:19 +08:00
|
|
|
unsetSrc()
|
2016-07-30 08:28:03 +08: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-10 05:12:52 +08:00
|
|
|
func (test *testBinary) dataPaths() []android.DataPath {
|
2020-05-13 06:26:55 +08:00
|
|
|
return test.data
|
|
|
|
}
|
|
|
|
|
2019-06-28 22:41:19 +08:00
|
|
|
func (test *testBinary) isAllTestsVariation() bool {
|
|
|
|
stem := test.binaryDecorator.Properties.Stem
|
|
|
|
return stem != nil && *stem == ""
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (test *testBinary) setSrc(name, src string) {
|
|
|
|
test.baseCompiler.Properties.Srcs = []string{src}
|
2017-11-08 02:57:05 +08:00
|
|
|
test.binaryDecorator.Properties.Stem = StringPtr(name)
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
|
2019-06-28 22:41:19 +08:00
|
|
|
func (test *testBinary) unsetSrc() {
|
|
|
|
test.baseCompiler.Properties.Srcs = nil
|
|
|
|
test.binaryDecorator.Properties.Stem = StringPtr("")
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
var _ testPerSrc = (*testBinary)(nil)
|
|
|
|
|
2019-06-28 22:41:19 +08:00
|
|
|
func TestPerSrcMutator(mctx android.BottomUpMutatorContext) {
|
2016-07-30 03:48:20 +08:00
|
|
|
if m, ok := mctx.Module().(*Module); ok {
|
2016-07-30 08:28:03 +08:00
|
|
|
if test, ok := m.linker.(testPerSrc); ok {
|
2019-06-28 22:41:19 +08:00
|
|
|
numTests := len(test.srcs())
|
|
|
|
if test.testPerSrc() && numTests > 0 {
|
2019-10-25 11:47:54 +08:00
|
|
|
if duplicate, found := android.CheckDuplicate(test.srcs()); found {
|
2019-02-28 17:06:34 +08:00
|
|
|
mctx.PropertyErrorf("srcs", "found a duplicate entry %q", duplicate)
|
|
|
|
return
|
|
|
|
}
|
2019-06-28 22:41:19 +08:00
|
|
|
testNames := make([]string, numTests)
|
2016-07-30 08:28:03 +08:00
|
|
|
for i, src := range test.srcs() {
|
2016-07-30 03:48:20 +08:00
|
|
|
testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src))
|
|
|
|
}
|
2019-06-28 22:41:19 +08: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-30 03:48:20 +08:00
|
|
|
tests := mctx.CreateLocalVariations(testNames...)
|
2020-12-22 01:11:10 +08:00
|
|
|
allTests := tests[numTests]
|
|
|
|
allTests.(*Module).linker.(testPerSrc).unsetSrc()
|
2019-06-28 22:41:19 +08:00
|
|
|
// Prevent the "all tests" variation from being installable nor
|
|
|
|
// exporting to Make, as it won't create any output file.
|
2020-12-22 01:11:10 +08:00
|
|
|
allTests.(*Module).Properties.PreventInstall = true
|
|
|
|
allTests.(*Module).Properties.HideFromMake = true
|
2016-07-30 08:28:03 +08:00
|
|
|
for i, src := range test.srcs() {
|
|
|
|
tests[i].(*Module).linker.(testPerSrc).setSrc(testNames[i], src)
|
2020-12-22 01:11:10 +08:00
|
|
|
mctx.AddInterVariantDependency(testPerSrcDepTag, allTests, tests[i])
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2020-08-22 06:55:50 +08:00
|
|
|
mctx.AliasVariation("")
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
type testDecorator struct {
|
|
|
|
Properties TestProperties
|
|
|
|
linker *baseLinker
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-14 03:26:16 +08:00
|
|
|
func (test *testDecorator) gtest() bool {
|
2018-04-11 07:14:46 +08:00
|
|
|
return BoolDefault(test.Properties.Gtest, true)
|
2016-09-14 03:26:16 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
2016-09-14 03:26:16 +08:00
|
|
|
if !test.gtest() {
|
2016-07-30 03:48:20 +08:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_HAS_STD_STRING")
|
2016-07-30 03:48:20 +08:00
|
|
|
if ctx.Host() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-O0", "-g")
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
switch ctx.Os() {
|
|
|
|
case android.Windows:
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_WINDOWS")
|
2016-07-30 03:48:20 +08:00
|
|
|
case android.Linux:
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX")
|
2016-07-30 03:48:20 +08:00
|
|
|
case android.Darwin:
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_MAC")
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
} else {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX_ANDROID")
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (test *testDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
2016-09-14 03:26:16 +08:00
|
|
|
if test.gtest() {
|
2017-09-28 08:01:44 +08:00
|
|
|
if ctx.useSdk() && ctx.Device() {
|
2018-02-10 07:22:59 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_c++", "libgtest_ndk_c++")
|
2018-08-22 03:40:08 +08:00
|
|
|
} else if BoolDefault(test.Properties.Isolated, false) {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_isolated_main")
|
2019-07-18 06:46:29 +08: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-30 03:48:20 +08:00
|
|
|
} else {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main", "libgtest")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
return deps
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (test *testDecorator) linkerInit(ctx BaseModuleContext, linker *baseLinker) {
|
2018-05-07 14:41:20 +08:00
|
|
|
// 1. Add ../../lib[64] to rpath so that out/host/linux-x86/nativetest/<test dir>/<test> can
|
2017-07-01 08:27:55 +08:00
|
|
|
// find out/host/linux-x86/lib[64]/library.so
|
2018-05-07 14:41:20 +08: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-30 03:48:20 +08:00
|
|
|
}
|
2017-07-01 08:27:55 +08: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-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (test *testDecorator) linkerProps() []interface{} {
|
|
|
|
return []interface{}{&test.Properties}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func NewTestInstaller() *baseInstaller {
|
|
|
|
return NewBaseInstaller("nativetest", "nativetest64", InstallInData)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
type testBinary struct {
|
|
|
|
testDecorator
|
|
|
|
*binaryDecorator
|
|
|
|
*baseCompiler
|
2020-08-16 03:24:26 +08:00
|
|
|
Properties TestBinaryProperties
|
|
|
|
data []android.DataPath
|
|
|
|
testConfig android.Path
|
|
|
|
extraTestConfigs android.Paths
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (test *testBinary) linkerProps() []interface{} {
|
|
|
|
props := append(test.testDecorator.linkerProps(), test.binaryDecorator.linkerProps()...)
|
|
|
|
props = append(props, &test.Properties)
|
|
|
|
return props
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (test *testBinary) linkerInit(ctx BaseModuleContext) {
|
|
|
|
test.testDecorator.linkerInit(ctx, test.binaryDecorator.baseLinker)
|
|
|
|
test.binaryDecorator.linkerInit(ctx)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-12-14 09:06:13 +08:00
|
|
|
func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-30 08:28:03 +08:00
|
|
|
deps = test.testDecorator.linkerDeps(ctx, deps)
|
|
|
|
deps = test.binaryDecorator.linkerDeps(ctx, deps)
|
2020-06-06 05:26:16 +08:00
|
|
|
deps.DataLibs = append(deps.DataLibs, test.Properties.Data_libs...)
|
2016-07-30 03:48:20 +08:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08: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-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
2020-08-13 16:16:56 +08:00
|
|
|
// TODO: (b/167308193) Switch to /data/local/tests/unrestricted as the default install base.
|
|
|
|
testInstallBase := "/data/local/tmp"
|
|
|
|
if ctx.inVendor() || ctx.useVndk() {
|
|
|
|
testInstallBase = "/data/local/tests/vendor"
|
|
|
|
}
|
|
|
|
|
2020-07-10 05:12:52 +08:00
|
|
|
dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data)
|
|
|
|
|
|
|
|
for _, dataSrcPath := range dataSrcPaths {
|
|
|
|
test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
|
|
|
|
}
|
2020-06-06 05:26:16 +08:00
|
|
|
|
|
|
|
ctx.VisitDirectDepsWithTag(dataLibDepTag, func(dep android.Module) {
|
|
|
|
depName := ctx.OtherModuleName(dep)
|
|
|
|
ccDep, ok := dep.(LinkableInterface)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
ctx.ModuleErrorf("data_lib %q is not a linkable cc module", depName)
|
|
|
|
}
|
2020-07-10 05:12:52 +08:00
|
|
|
ccModule, ok := dep.(*Module)
|
|
|
|
if !ok {
|
|
|
|
ctx.ModuleErrorf("data_lib %q is not a cc module", depName)
|
|
|
|
}
|
2020-06-06 05:26:16 +08:00
|
|
|
if ccDep.OutputFile().Valid() {
|
2020-07-10 05:12:52 +08:00
|
|
|
test.data = append(test.data,
|
|
|
|
android.DataPath{SrcPath: ccDep.OutputFile().Path(),
|
|
|
|
RelativeInstallPath: ccModule.installer.relativeInstallPath()})
|
2020-06-06 05:26:16 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-12-22 01:11:10 +08:00
|
|
|
var apiLevelProp string
|
2019-06-07 07:23:32 +08:00
|
|
|
var configs []tradefed.Config
|
2020-12-22 01:11:10 +08:00
|
|
|
var minLevel string
|
2020-04-30 10:08:33 +08: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 07:23:32 +08:00
|
|
|
if Bool(test.Properties.Require_root) {
|
2019-09-17 16:35:23 +08:00
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
2019-09-17 10:43:50 +08:00
|
|
|
} else {
|
|
|
|
var options []tradefed.Option
|
2020-04-30 10:08:33 +08:00
|
|
|
options = append(options, tradefed.Option{Name: "force-root", Value: "false"})
|
2019-09-17 16:35:23 +08:00
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
|
2019-08-28 01:37:24 +08:00
|
|
|
}
|
|
|
|
if Bool(test.Properties.Disable_framework) {
|
|
|
|
var options []tradefed.Option
|
2020-05-13 04:50:12 +08:00
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.StopServicesSetup", options})
|
2019-06-07 07:23:32 +08:00
|
|
|
}
|
2019-03-01 00:45:28 +08:00
|
|
|
if Bool(test.testDecorator.Properties.Isolated) {
|
2020-04-30 10:08:33 +08:00
|
|
|
configs = append(configs, tradefed.Option{Name: "not-shardable", Value: "true"})
|
2019-03-01 00:45:28 +08:00
|
|
|
}
|
2018-10-01 19:23:14 +08:00
|
|
|
if test.Properties.Test_options.Run_test_as != nil {
|
2020-04-30 10:08:33 +08:00
|
|
|
configs = append(configs, tradefed.Option{Name: "run-test-as", Value: String(test.Properties.Test_options.Run_test_as)})
|
2018-10-01 19:23:14 +08:00
|
|
|
}
|
2020-06-19 01:07:00 +08:00
|
|
|
for _, tag := range test.Properties.Test_options.Test_suite_tag {
|
|
|
|
configs = append(configs, tradefed.Option{Name: "test-suite-tag", Value: tag})
|
|
|
|
}
|
2019-09-17 16:35:23 +08:00
|
|
|
if test.Properties.Test_min_api_level != nil && test.Properties.Test_min_sdk_version != nil {
|
|
|
|
ctx.PropertyErrorf("test_min_api_level", "'test_min_api_level' and 'test_min_sdk_version' should not be set at the same time.")
|
|
|
|
} else if test.Properties.Test_min_api_level != nil {
|
2020-12-22 01:11:10 +08:00
|
|
|
apiLevelProp = "ro.product.first_api_level"
|
|
|
|
minLevel = strconv.FormatInt(int64(*test.Properties.Test_min_api_level), 10)
|
2019-09-17 16:35:23 +08:00
|
|
|
} else if test.Properties.Test_min_sdk_version != nil {
|
2020-12-22 01:11:10 +08:00
|
|
|
apiLevelProp = "ro.build.version.sdk"
|
|
|
|
minLevel = strconv.FormatInt(int64(*test.Properties.Test_min_sdk_version), 10)
|
2019-09-17 16:35:23 +08:00
|
|
|
}
|
2020-12-22 01:11:10 +08:00
|
|
|
if apiLevelProp != "" {
|
2019-09-17 16:35:23 +08:00
|
|
|
var options []tradefed.Option
|
2020-12-22 01:11:10 +08:00
|
|
|
options = append(options, tradefed.Option{Name: "min-api-level", Value: minLevel})
|
|
|
|
options = append(options, tradefed.Option{Name: "api-level-prop", Value: apiLevelProp})
|
2019-09-17 16:35:23 +08:00
|
|
|
configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.MinApiLevelModuleController", options})
|
|
|
|
}
|
2018-10-01 19:23:14 +08:00
|
|
|
|
2018-09-19 17:21:28 +08:00
|
|
|
test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
|
2020-08-13 16:16:56 +08:00
|
|
|
test.Properties.Test_config_template, test.Properties.Test_suites, configs, test.Properties.Auto_gen_config, testInstallBase)
|
2017-02-02 06:12:44 +08:00
|
|
|
|
2020-08-16 03:24:26 +08:00
|
|
|
test.extraTestConfigs = android.PathsForModuleSrc(ctx, test.Properties.Test_options.Extra_test_configs)
|
|
|
|
|
2016-09-14 03:26:16 +08:00
|
|
|
test.binaryDecorator.baseInstaller.dir = "nativetest"
|
|
|
|
test.binaryDecorator.baseInstaller.dir64 = "nativetest64"
|
2016-12-28 06:40:40 +08:00
|
|
|
|
|
|
|
if !Bool(test.Properties.No_named_install_directory) {
|
|
|
|
test.binaryDecorator.baseInstaller.relative = ctx.ModuleName()
|
2017-11-08 02:57:05 +08:00
|
|
|
} else if String(test.binaryDecorator.baseInstaller.Properties.Relative_install_path) == "" {
|
2016-12-28 06:40:40 +08:00
|
|
|
ctx.PropertyErrorf("no_named_install_directory", "Module install directory may only be disabled if relative_install_path is set")
|
|
|
|
}
|
|
|
|
|
2016-08-30 06:53:15 +08:00
|
|
|
test.binaryDecorator.baseInstaller.install(ctx, file)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewTest(hod android.HostOrDeviceSupported) *Module {
|
2016-07-30 08:28:03 +08:00
|
|
|
module, binary := NewBinary(hod)
|
|
|
|
module.multilib = android.MultilibBoth
|
2016-08-30 06:53:15 +08:00
|
|
|
binary.baseInstaller = NewTestInstaller()
|
2016-07-30 08:28:03 +08:00
|
|
|
|
|
|
|
test := &testBinary{
|
|
|
|
testDecorator: testDecorator{
|
|
|
|
linker: binary.baseLinker,
|
2016-07-30 03:48:20 +08:00
|
|
|
},
|
2016-07-30 08:28:03 +08:00
|
|
|
binaryDecorator: binary,
|
|
|
|
baseCompiler: NewBaseCompiler(),
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2016-07-30 08:28:03 +08:00
|
|
|
module.compiler = test
|
|
|
|
module.linker = test
|
|
|
|
module.installer = test
|
2016-07-30 03:48:20 +08:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08: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 09:06:13 +08:00
|
|
|
func (test *testLibrary) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-30 08:28:03 +08: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-30 03:48:20 +08:00
|
|
|
func NewTestLibrary(hod android.HostOrDeviceSupported) *Module {
|
2016-12-10 06:46:15 +08:00
|
|
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
2016-09-01 07:32:55 +08:00
|
|
|
library.baseInstaller = NewTestInstaller()
|
2016-07-30 08:28:03 +08:00
|
|
|
test := &testLibrary{
|
|
|
|
testDecorator: testDecorator{
|
|
|
|
linker: library.baseLinker,
|
2016-07-30 03:48:20 +08:00
|
|
|
},
|
2016-07-30 08:28:03 +08:00
|
|
|
libraryDecorator: library,
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2016-07-30 08:28:03 +08:00
|
|
|
module.linker = test
|
2016-07-30 03:48:20 +08:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2017-04-25 09:10:29 +08:00
|
|
|
type BenchmarkProperties struct {
|
2017-07-15 06:20:13 +08:00
|
|
|
// list of files or filegroup modules that provide data that should be installed alongside
|
|
|
|
// the test
|
2019-03-05 14:35:41 +08:00
|
|
|
Data []string `android:"path"`
|
2017-07-15 06:20:13 +08:00
|
|
|
|
2017-04-25 09:10:29 +08:00
|
|
|
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
|
|
// installed into.
|
2018-08-03 06:00:46 +08: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 14:35:41 +08:00
|
|
|
Test_config *string `android:"path,arch_variant"`
|
2018-09-19 17:21:28 +08:00
|
|
|
|
|
|
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
|
|
|
// should be installed with the module.
|
2019-03-05 14:35:41 +08:00
|
|
|
Test_config_template *string `android:"path,arch_variant"`
|
2019-06-07 07:23:32 +08:00
|
|
|
|
|
|
|
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
|
|
|
|
// with root permission.
|
|
|
|
Require_root *bool
|
2019-09-27 02:41:36 +08: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 09:10:29 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
type benchmarkDecorator struct {
|
|
|
|
*binaryDecorator
|
2017-04-25 09:10:29 +08:00
|
|
|
Properties BenchmarkProperties
|
2017-07-15 06:20:13 +08:00
|
|
|
data android.Paths
|
2018-08-08 07:49:25 +08:00
|
|
|
testConfig android.Path
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08: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 09:10:29 +08:00
|
|
|
func (benchmark *benchmarkDecorator) linkerProps() []interface{} {
|
|
|
|
props := benchmark.binaryDecorator.linkerProps()
|
|
|
|
props = append(props, &benchmark.Properties)
|
|
|
|
return props
|
|
|
|
}
|
|
|
|
|
2016-12-14 09:06:13 +08:00
|
|
|
func (benchmark *benchmarkDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-30 08:28:03 +08:00
|
|
|
deps = benchmark.binaryDecorator.linkerDeps(ctx, deps)
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgoogle-benchmark")
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) {
|
2019-03-06 14:25:09 +08:00
|
|
|
benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data)
|
2020-06-06 05:26:16 +08:00
|
|
|
|
2019-06-07 07:23:32 +08:00
|
|
|
var configs []tradefed.Config
|
|
|
|
if Bool(benchmark.Properties.Require_root) {
|
2019-09-17 16:35:23 +08:00
|
|
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
2019-06-07 07:23:32 +08:00
|
|
|
}
|
2018-09-19 17:21:28 +08:00
|
|
|
benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config,
|
2019-09-27 02:41:36 +08:00
|
|
|
benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs, benchmark.Properties.Auto_gen_config)
|
2018-08-08 07:49:25 +08:00
|
|
|
|
2017-09-09 07:20:30 +08:00
|
|
|
benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName())
|
|
|
|
benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName())
|
2016-08-30 06:53:15 +08:00
|
|
|
benchmark.binaryDecorator.baseInstaller.install(ctx, file)
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
|
2016-07-30 08:28:03 +08:00
|
|
|
module, binary := NewBinary(hod)
|
|
|
|
module.multilib = android.MultilibBoth
|
2017-09-09 07:20:30 +08:00
|
|
|
binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData)
|
2016-07-30 08:28:03 +08:00
|
|
|
|
|
|
|
benchmark := &benchmarkDecorator{
|
|
|
|
binaryDecorator: binary,
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2016-07-30 08:28:03 +08:00
|
|
|
module.linker = benchmark
|
|
|
|
module.installer = benchmark
|
2016-07-30 03:48:20 +08:00
|
|
|
return module
|
|
|
|
}
|