Merge "Add support for test_suites to cc_test_library"
This commit is contained in:
commit
85b935eff2
4 changed files with 116 additions and 23 deletions
|
@ -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) {
|
||||
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) {
|
||||
ctx.subAndroidMk(entries, test.binaryDecorator)
|
||||
ctx.subAndroidMk(entries, test.testDecorator)
|
||||
|
||||
entries.Class = "NATIVE_TESTS"
|
||||
if Bool(test.Properties.Test_per_src) {
|
||||
entries.SubName = "_" + String(test.binaryDecorator.Properties.Stem)
|
||||
}
|
||||
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 {
|
||||
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) {
|
||||
ctx.subAndroidMk(entries, test.libraryDecorator)
|
||||
ctx.subAndroidMk(entries, test.testDecorator)
|
||||
}
|
||||
|
||||
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{},
|
||||
&FlagExporterProperties{},
|
||||
&BinaryLinkerProperties{},
|
||||
&TestProperties{},
|
||||
&TestLinkerProperties{},
|
||||
&TestInstallerProperties{},
|
||||
&TestBinaryProperties{},
|
||||
&BenchmarkProperties{},
|
||||
&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) {
|
||||
ctx := testCcNoVndk(t, `
|
||||
cc_library {
|
||||
|
|
60
cc/test.go
60
cc/test.go
|
@ -25,7 +25,8 @@ import (
|
|||
"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.
|
||||
Gtest *bool
|
||||
|
||||
|
@ -33,6 +34,12 @@ type TestProperties struct {
|
|||
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.
|
||||
type TestOptions struct {
|
||||
// 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
|
||||
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
|
||||
// installed with the module.
|
||||
Test_config *string `android:"path,arch_variant"`
|
||||
|
@ -243,12 +246,14 @@ func TestPerSrcMutator(mctx android.BottomUpMutatorContext) {
|
|||
}
|
||||
|
||||
type testDecorator struct {
|
||||
Properties TestProperties
|
||||
linker *baseLinker
|
||||
LinkerProperties TestLinkerProperties
|
||||
InstallerProperties TestInstallerProperties
|
||||
installer *baseInstaller
|
||||
linker *baseLinker
|
||||
}
|
||||
|
||||
func (test *testDecorator) gtest() bool {
|
||||
return BoolDefault(test.Properties.Gtest, true)
|
||||
return BoolDefault(test.LinkerProperties.Gtest, true)
|
||||
}
|
||||
|
||||
func (test *testDecorator) testBinary() bool {
|
||||
|
@ -283,7 +288,7 @@ func (test *testDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
|||
if test.gtest() {
|
||||
if ctx.useSdk() && ctx.Device() {
|
||||
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")
|
||||
// The isolated library requires liblog, but adding it
|
||||
// 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{} {
|
||||
return []interface{}{&test.Properties}
|
||||
return []interface{}{&test.LinkerProperties}
|
||||
}
|
||||
|
||||
func (test *testDecorator) installerProps() []interface{} {
|
||||
return []interface{}{&test.InstallerProperties}
|
||||
}
|
||||
|
||||
func NewTestInstaller() *baseInstaller {
|
||||
|
@ -324,7 +333,7 @@ func NewTestInstaller() *baseInstaller {
|
|||
}
|
||||
|
||||
type testBinary struct {
|
||||
testDecorator
|
||||
*testDecorator
|
||||
*binaryDecorator
|
||||
*baseCompiler
|
||||
Properties TestBinaryProperties
|
||||
|
@ -358,6 +367,10 @@ func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) 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) {
|
||||
// TODO: (b/167308193) Switch to /data/local/tests/unrestricted as the default install base.
|
||||
testInstallBase := "/data/local/tmp"
|
||||
|
@ -411,7 +424,7 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
|||
var options []tradefed.Option
|
||||
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"})
|
||||
}
|
||||
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.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)
|
||||
|
||||
|
@ -466,8 +479,9 @@ func NewTest(hod android.HostOrDeviceSupported) *Module {
|
|||
binary.baseInstaller = NewTestInstaller()
|
||||
|
||||
test := &testBinary{
|
||||
testDecorator: testDecorator{
|
||||
linker: binary.baseLinker,
|
||||
testDecorator: &testDecorator{
|
||||
linker: binary.baseLinker,
|
||||
installer: binary.baseInstaller,
|
||||
},
|
||||
binaryDecorator: binary,
|
||||
baseCompiler: NewBaseCompiler(),
|
||||
|
@ -479,12 +493,14 @@ func NewTest(hod android.HostOrDeviceSupported) *Module {
|
|||
}
|
||||
|
||||
type testLibrary struct {
|
||||
testDecorator
|
||||
*testDecorator
|
||||
*libraryDecorator
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -504,16 +520,22 @@ func (test *testLibrary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|||
return flags
|
||||
}
|
||||
|
||||
func (test *testLibrary) installerProps() []interface{} {
|
||||
return append(test.baseInstaller.installerProps(), test.testDecorator.installerProps()...)
|
||||
}
|
||||
|
||||
func NewTestLibrary(hod android.HostOrDeviceSupported) *Module {
|
||||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||
library.baseInstaller = NewTestInstaller()
|
||||
test := &testLibrary{
|
||||
testDecorator: testDecorator{
|
||||
linker: library.baseLinker,
|
||||
testDecorator: &testDecorator{
|
||||
linker: library.baseLinker,
|
||||
installer: library.baseInstaller,
|
||||
},
|
||||
libraryDecorator: library,
|
||||
}
|
||||
module.linker = test
|
||||
module.installer = test
|
||||
return module
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue