Merge "Add support for test_suites to cc_test_library" am: 85b935eff2
am: 030b1e4dc0
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2042844 Change-Id: I6c491bffc4a1e9436d11f1e9fb5404f8b3276acf Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -331,6 +331,14 @@ func (object *objectLinker) AndroidMkEntries(ctx AndroidMkContext, entries *andr
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (test *testDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
||||||
|
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
||||||
|
if len(test.InstallerProperties.Test_suites) > 0 {
|
||||||
|
entries.AddCompatibilityTestSuites(test.InstallerProperties.Test_suites...)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (binary *binaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
func (binary *binaryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
||||||
ctx.subAndroidMk(entries, binary.baseInstaller)
|
ctx.subAndroidMk(entries, binary.baseInstaller)
|
||||||
|
|
||||||
@@ -379,14 +387,13 @@ func (benchmark *benchmarkDecorator) AndroidMkEntries(ctx AndroidMkContext, entr
|
|||||||
|
|
||||||
func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
||||||
ctx.subAndroidMk(entries, test.binaryDecorator)
|
ctx.subAndroidMk(entries, test.binaryDecorator)
|
||||||
|
ctx.subAndroidMk(entries, test.testDecorator)
|
||||||
|
|
||||||
entries.Class = "NATIVE_TESTS"
|
entries.Class = "NATIVE_TESTS"
|
||||||
if Bool(test.Properties.Test_per_src) {
|
if Bool(test.Properties.Test_per_src) {
|
||||||
entries.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
|
entries.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
|
||||||
}
|
}
|
||||||
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
||||||
if len(test.Properties.Test_suites) > 0 {
|
|
||||||
entries.AddCompatibilityTestSuites(test.Properties.Test_suites...)
|
|
||||||
}
|
|
||||||
if test.testConfig != nil {
|
if test.testConfig != nil {
|
||||||
entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
|
entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
|
||||||
}
|
}
|
||||||
@@ -445,6 +452,7 @@ func (fuzz *fuzzBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.
|
|||||||
|
|
||||||
func (test *testLibrary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
func (test *testLibrary) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
||||||
ctx.subAndroidMk(entries, test.libraryDecorator)
|
ctx.subAndroidMk(entries, test.libraryDecorator)
|
||||||
|
ctx.subAndroidMk(entries, test.testDecorator)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (installer *baseInstaller) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
func (installer *baseInstaller) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
|
||||||
|
3
cc/cc.go
3
cc/cc.go
@@ -3595,7 +3595,8 @@ func DefaultsFactory(props ...interface{}) android.Module {
|
|||||||
&SharedProperties{},
|
&SharedProperties{},
|
||||||
&FlagExporterProperties{},
|
&FlagExporterProperties{},
|
||||||
&BinaryLinkerProperties{},
|
&BinaryLinkerProperties{},
|
||||||
&TestProperties{},
|
&TestLinkerProperties{},
|
||||||
|
&TestInstallerProperties{},
|
||||||
&TestBinaryProperties{},
|
&TestBinaryProperties{},
|
||||||
&BenchmarkProperties{},
|
&BenchmarkProperties{},
|
||||||
&fuzz.FuzzProperties{},
|
&fuzz.FuzzProperties{},
|
||||||
|
@@ -779,6 +779,68 @@ func TestDataLibsRelativeInstallPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTestBinaryTestSuites(t *testing.T) {
|
||||||
|
bp := `
|
||||||
|
cc_test {
|
||||||
|
name: "main_test",
|
||||||
|
srcs: ["main_test.cpp"],
|
||||||
|
test_suites: [
|
||||||
|
"suite_1",
|
||||||
|
"suite_2",
|
||||||
|
],
|
||||||
|
gtest: false,
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext
|
||||||
|
module := ctx.ModuleForTests("main_test", "android_arm_armv7-a-neon").Module()
|
||||||
|
|
||||||
|
entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
|
||||||
|
compatEntries := entries.EntryMap["LOCAL_COMPATIBILITY_SUITE"]
|
||||||
|
if len(compatEntries) != 2 {
|
||||||
|
t.Errorf("expected two elements in LOCAL_COMPATIBILITY_SUITE. got %d", len(compatEntries))
|
||||||
|
}
|
||||||
|
if compatEntries[0] != "suite_1" {
|
||||||
|
t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_1`,"+
|
||||||
|
" but was '%s'", compatEntries[0])
|
||||||
|
}
|
||||||
|
if compatEntries[1] != "suite_2" {
|
||||||
|
t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_2`,"+
|
||||||
|
" but was '%s'", compatEntries[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTestLibraryTestSuites(t *testing.T) {
|
||||||
|
bp := `
|
||||||
|
cc_test_library {
|
||||||
|
name: "main_test_lib",
|
||||||
|
srcs: ["main_test_lib.cpp"],
|
||||||
|
test_suites: [
|
||||||
|
"suite_1",
|
||||||
|
"suite_2",
|
||||||
|
],
|
||||||
|
gtest: false,
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
ctx := prepareForCcTest.RunTestWithBp(t, bp).TestContext
|
||||||
|
module := ctx.ModuleForTests("main_test_lib", "android_arm_armv7-a-neon_shared").Module()
|
||||||
|
|
||||||
|
entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
|
||||||
|
compatEntries := entries.EntryMap["LOCAL_COMPATIBILITY_SUITE"]
|
||||||
|
if len(compatEntries) != 2 {
|
||||||
|
t.Errorf("expected two elements in LOCAL_COMPATIBILITY_SUITE. got %d", len(compatEntries))
|
||||||
|
}
|
||||||
|
if compatEntries[0] != "suite_1" {
|
||||||
|
t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_1`,"+
|
||||||
|
" but was '%s'", compatEntries[0])
|
||||||
|
}
|
||||||
|
if compatEntries[1] != "suite_2" {
|
||||||
|
t.Errorf("expected LOCAL_COMPATIBILITY_SUITE to be`suite_2`,"+
|
||||||
|
" but was '%s'", compatEntries[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
|
func TestVndkWhenVndkVersionIsNotSet(t *testing.T) {
|
||||||
ctx := testCcNoVndk(t, `
|
ctx := testCcNoVndk(t, `
|
||||||
cc_library {
|
cc_library {
|
||||||
|
60
cc/test.go
60
cc/test.go
@@ -25,7 +25,8 @@ import (
|
|||||||
"android/soong/tradefed"
|
"android/soong/tradefed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestProperties struct {
|
// TestLinkerProperties properties to be registered via the linker
|
||||||
|
type TestLinkerProperties struct {
|
||||||
// if set, build against the gtest library. Defaults to true.
|
// if set, build against the gtest library. Defaults to true.
|
||||||
Gtest *bool
|
Gtest *bool
|
||||||
|
|
||||||
@@ -33,6 +34,12 @@ type TestProperties struct {
|
|||||||
Isolated *bool
|
Isolated *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestInstallerProperties properties to be registered via the installer
|
||||||
|
type TestInstallerProperties struct {
|
||||||
|
// list of compatibility suites (for example "cts", "vts") that the module should be installed into.
|
||||||
|
Test_suites []string `android:"arch_variant"`
|
||||||
|
}
|
||||||
|
|
||||||
// Test option struct.
|
// Test option struct.
|
||||||
type TestOptions struct {
|
type TestOptions struct {
|
||||||
// The UID that you want to run the test as on a device.
|
// The UID that you want to run the test as on a device.
|
||||||
@@ -83,10 +90,6 @@ type TestBinaryProperties struct {
|
|||||||
// list of binary modules that should be installed alongside the test
|
// list of binary modules that should be installed alongside the test
|
||||||
Data_bins []string `android:"arch_variant"`
|
Data_bins []string `android:"arch_variant"`
|
||||||
|
|
||||||
// list of compatibility suites (for example "cts", "vts") that the module should be
|
|
||||||
// installed into.
|
|
||||||
Test_suites []string `android:"arch_variant"`
|
|
||||||
|
|
||||||
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
// the name of the test configuration (for example "AndroidTest.xml") that should be
|
||||||
// installed with the module.
|
// installed with the module.
|
||||||
Test_config *string `android:"path,arch_variant"`
|
Test_config *string `android:"path,arch_variant"`
|
||||||
@@ -243,12 +246,14 @@ func TestPerSrcMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testDecorator struct {
|
type testDecorator struct {
|
||||||
Properties TestProperties
|
LinkerProperties TestLinkerProperties
|
||||||
linker *baseLinker
|
InstallerProperties TestInstallerProperties
|
||||||
|
installer *baseInstaller
|
||||||
|
linker *baseLinker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testDecorator) gtest() bool {
|
func (test *testDecorator) gtest() bool {
|
||||||
return BoolDefault(test.Properties.Gtest, true)
|
return BoolDefault(test.LinkerProperties.Gtest, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testDecorator) testBinary() bool {
|
func (test *testDecorator) testBinary() bool {
|
||||||
@@ -283,7 +288,7 @@ func (test *testDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
|||||||
if test.gtest() {
|
if test.gtest() {
|
||||||
if ctx.useSdk() && ctx.Device() {
|
if ctx.useSdk() && ctx.Device() {
|
||||||
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_c++", "libgtest_ndk_c++")
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_main_ndk_c++", "libgtest_ndk_c++")
|
||||||
} else if BoolDefault(test.Properties.Isolated, false) {
|
} else if BoolDefault(test.LinkerProperties.Isolated, false) {
|
||||||
deps.StaticLibs = append(deps.StaticLibs, "libgtest_isolated_main")
|
deps.StaticLibs = append(deps.StaticLibs, "libgtest_isolated_main")
|
||||||
// The isolated library requires liblog, but adding it
|
// The isolated library requires liblog, but adding it
|
||||||
// as a static library means unit tests cannot override
|
// as a static library means unit tests cannot override
|
||||||
@@ -316,7 +321,11 @@ func (test *testDecorator) linkerInit(ctx BaseModuleContext, linker *baseLinker)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (test *testDecorator) linkerProps() []interface{} {
|
func (test *testDecorator) linkerProps() []interface{} {
|
||||||
return []interface{}{&test.Properties}
|
return []interface{}{&test.LinkerProperties}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (test *testDecorator) installerProps() []interface{} {
|
||||||
|
return []interface{}{&test.InstallerProperties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestInstaller() *baseInstaller {
|
func NewTestInstaller() *baseInstaller {
|
||||||
@@ -324,7 +333,7 @@ func NewTestInstaller() *baseInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testBinary struct {
|
type testBinary struct {
|
||||||
testDecorator
|
*testDecorator
|
||||||
*binaryDecorator
|
*binaryDecorator
|
||||||
*baseCompiler
|
*baseCompiler
|
||||||
Properties TestBinaryProperties
|
Properties TestBinaryProperties
|
||||||
@@ -358,6 +367,10 @@ func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (test *testBinary) installerProps() []interface{} {
|
||||||
|
return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...)
|
||||||
|
}
|
||||||
|
|
||||||
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
||||||
// TODO: (b/167308193) Switch to /data/local/tests/unrestricted as the default install base.
|
// TODO: (b/167308193) Switch to /data/local/tests/unrestricted as the default install base.
|
||||||
testInstallBase := "/data/local/tmp"
|
testInstallBase := "/data/local/tmp"
|
||||||
@@ -411,7 +424,7 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
|||||||
var options []tradefed.Option
|
var options []tradefed.Option
|
||||||
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.StopServicesSetup", options})
|
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.StopServicesSetup", options})
|
||||||
}
|
}
|
||||||
if Bool(test.testDecorator.Properties.Isolated) {
|
if Bool(test.testDecorator.LinkerProperties.Isolated) {
|
||||||
configs = append(configs, tradefed.Option{Name: "not-shardable", Value: "true"})
|
configs = append(configs, tradefed.Option{Name: "not-shardable", Value: "true"})
|
||||||
}
|
}
|
||||||
if test.Properties.Test_options.Run_test_as != nil {
|
if test.Properties.Test_options.Run_test_as != nil {
|
||||||
@@ -441,7 +454,7 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
|
test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
|
||||||
test.Properties.Test_config_template, test.Properties.Test_suites, configs, test.Properties.Auto_gen_config, testInstallBase)
|
test.Properties.Test_config_template, test.testDecorator.InstallerProperties.Test_suites, configs, test.Properties.Auto_gen_config, testInstallBase)
|
||||||
|
|
||||||
test.extraTestConfigs = android.PathsForModuleSrc(ctx, test.Properties.Test_options.Extra_test_configs)
|
test.extraTestConfigs = android.PathsForModuleSrc(ctx, test.Properties.Test_options.Extra_test_configs)
|
||||||
|
|
||||||
@@ -466,8 +479,9 @@ func NewTest(hod android.HostOrDeviceSupported) *Module {
|
|||||||
binary.baseInstaller = NewTestInstaller()
|
binary.baseInstaller = NewTestInstaller()
|
||||||
|
|
||||||
test := &testBinary{
|
test := &testBinary{
|
||||||
testDecorator: testDecorator{
|
testDecorator: &testDecorator{
|
||||||
linker: binary.baseLinker,
|
linker: binary.baseLinker,
|
||||||
|
installer: binary.baseInstaller,
|
||||||
},
|
},
|
||||||
binaryDecorator: binary,
|
binaryDecorator: binary,
|
||||||
baseCompiler: NewBaseCompiler(),
|
baseCompiler: NewBaseCompiler(),
|
||||||
@@ -479,12 +493,14 @@ func NewTest(hod android.HostOrDeviceSupported) *Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testLibrary struct {
|
type testLibrary struct {
|
||||||
testDecorator
|
*testDecorator
|
||||||
*libraryDecorator
|
*libraryDecorator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testLibrary) linkerProps() []interface{} {
|
func (test *testLibrary) linkerProps() []interface{} {
|
||||||
return append(test.testDecorator.linkerProps(), test.libraryDecorator.linkerProps()...)
|
var props []interface{}
|
||||||
|
props = append(props, test.testDecorator.linkerProps()...)
|
||||||
|
return append(props, test.libraryDecorator.linkerProps()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testLibrary) linkerInit(ctx BaseModuleContext) {
|
func (test *testLibrary) linkerInit(ctx BaseModuleContext) {
|
||||||
@@ -504,16 +520,22 @@ func (test *testLibrary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (test *testLibrary) installerProps() []interface{} {
|
||||||
|
return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...)
|
||||||
|
}
|
||||||
|
|
||||||
func NewTestLibrary(hod android.HostOrDeviceSupported) *Module {
|
func NewTestLibrary(hod android.HostOrDeviceSupported) *Module {
|
||||||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||||
library.baseInstaller = NewTestInstaller()
|
library.baseInstaller = NewTestInstaller()
|
||||||
test := &testLibrary{
|
test := &testLibrary{
|
||||||
testDecorator: testDecorator{
|
testDecorator: &testDecorator{
|
||||||
linker: library.baseLinker,
|
linker: library.baseLinker,
|
||||||
|
installer: library.baseInstaller,
|
||||||
},
|
},
|
||||||
libraryDecorator: library,
|
libraryDecorator: library,
|
||||||
}
|
}
|
||||||
module.linker = test
|
module.linker = test
|
||||||
|
module.installer = test
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user