Merge "Move common test_options properties into the android package"

This commit is contained in:
Zhenhuang Wang
2022-08-17 15:22:18 +00:00
committed by Gerrit Code Review
11 changed files with 93 additions and 59 deletions

View File

@@ -936,6 +936,20 @@ type distProperties struct {
Dists []Dist `android:"arch_variant"` Dists []Dist `android:"arch_variant"`
} }
// CommonTestOptions represents the common `test_options` properties in
// Android.bp.
type CommonTestOptions struct {
// If the test is a hostside (no device required) unittest that shall be run
// during presubmit check.
Unit_test *bool
}
// SetAndroidMkEntries sets AndroidMkEntries according to the value of base
// `test_options`.
func (t *CommonTestOptions) SetAndroidMkEntries(entries *AndroidMkEntries) {
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(t.Unit_test))
}
// The key to use in TaggedDistFiles when a Dist structure does not specify a // The key to use in TaggedDistFiles when a Dist structure does not specify a
// tag property. This intentionally does not use "" as the default because that // tag property. This intentionally does not use "" as the default because that
// would mean that an empty tag would have a different meaning when used in a dist // would mean that an empty tag would have a different meaning when used in a dist
@@ -1095,7 +1109,7 @@ func InitAndroidModule(m Module) {
// property structs for architecture-specific versions of generic properties tagged with // property structs for architecture-specific versions of generic properties tagged with
// `android:"arch_variant"`. // `android:"arch_variant"`.
// //
// InitAndroidModule should not be called if InitAndroidArchModule was called. // InitAndroidModule should not be called if InitAndroidArchModule was called.
func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) {
InitAndroidModule(m) InitAndroidModule(m)
@@ -1336,30 +1350,30 @@ func productVariableConfigEnableLabels(ctx *topDownMutatorContext) []bazel.Label
// //
// For example: // For example:
// //
// import ( // import (
// "android/soong/android" // "android/soong/android"
// ) // )
// //
// type myModule struct { // type myModule struct {
// android.ModuleBase // android.ModuleBase
// properties struct { // properties struct {
// MyProperty string // MyProperty string
// } // }
// } // }
// //
// func NewMyModule() android.Module { // func NewMyModule() android.Module {
// m := &myModule{} // m := &myModule{}
// m.AddProperties(&m.properties) // m.AddProperties(&m.properties)
// android.InitAndroidModule(m) // android.InitAndroidModule(m)
// return m // return m
// } // }
// //
// func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { // func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// // Get the CPU architecture for the current build variant. // // Get the CPU architecture for the current build variant.
// variantArch := ctx.Arch() // variantArch := ctx.Arch()
// //
// // ... // // ...
// } // }
type ModuleBase struct { type ModuleBase struct {
// Putting the curiously recurring thing pointing to the thing that contains // Putting the curiously recurring thing pointing to the thing that contains
// the thing pattern to good use. // the thing pattern to good use.

View File

@@ -911,3 +911,45 @@ func TestSortedUniqueNamedPaths(t *testing.T) {
}) })
} }
} }
func TestProcessCommonTestOptions(t *testing.T) {
tests := []struct {
name string
testOptions CommonTestOptions
expected map[string][]string
}{
{
name: "empty",
testOptions: CommonTestOptions{},
expected: map[string][]string{},
},
{
name: "is unit test",
testOptions: CommonTestOptions{
Unit_test: boolPtr(true),
},
expected: map[string][]string{
"LOCAL_IS_UNIT_TEST": []string{"true"},
},
},
{
name: "is not unit test",
testOptions: CommonTestOptions{
Unit_test: boolPtr(false),
},
expected: map[string][]string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actualEntries := AndroidMkEntries{
EntryMap: map[string][]string{},
}
tt.testOptions.SetAndroidMkEntries(&actualEntries)
actual := actualEntries.EntryMap
t.Logf("actual: %v", actual)
t.Logf("expected: %v", tt.expected)
AssertDeepEquals(t, "TestProcessCommonTestOptions ", tt.expected, actual)
})
}
}

View File

@@ -411,14 +411,13 @@ func (test *testBinary) AndroidMkEntries(ctx AndroidMkContext, entries *android.
entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true) entries.SetBool("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", true)
} }
entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", test.Properties.Test_mainline_modules...) entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", test.Properties.Test_mainline_modules...)
if Bool(test.Properties.Test_options.Unit_test) {
entries.SetBool("LOCAL_IS_UNIT_TEST", true)
}
entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(test.Properties.Per_testcase_directory)) entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(test.Properties.Per_testcase_directory))
if len(test.Properties.Data_bins) > 0 { if len(test.Properties.Data_bins) > 0 {
entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...) entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...)
} }
test.Properties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries)
}) })
AndroidMkWriteTestData(test.data, entries) AndroidMkWriteTestData(test.data, entries)

View File

@@ -43,6 +43,8 @@ type TestInstallerProperties struct {
// Test option struct. // Test option struct.
type TestOptions struct { type TestOptions struct {
android.CommonTestOptions
// 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.
Run_test_as *string Run_test_as *string
@@ -52,9 +54,6 @@ type TestOptions struct {
// a list of extra test configuration files that should be installed with the module. // a list of extra test configuration files that should be installed with the module.
Extra_test_configs []string `android:"path,arch_variant"` Extra_test_configs []string `android:"path,arch_variant"`
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
Unit_test *bool
// Add ShippingApiLevelModuleController to auto generated test config. If the device properties // Add ShippingApiLevelModuleController to auto generated test config. If the device properties
// for the shipping api level is less than the min_shipping_api_level, skip this module. // for the shipping api level is less than the min_shipping_api_level, skip this module.
Min_shipping_api_level *int64 Min_shipping_api_level *int64

View File

@@ -167,9 +167,8 @@ func (j *Test) AndroidMkEntries() []android.AndroidMkEntries {
entries.SetString("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", "true") entries.SetString("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", "true")
} }
entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", j.testProperties.Test_mainline_modules...) entries.AddStrings("LOCAL_TEST_MAINLINE_MODULES", j.testProperties.Test_mainline_modules...)
if Bool(j.testProperties.Test_options.Unit_test) {
entries.SetBool("LOCAL_IS_UNIT_TEST", true) j.testProperties.Test_options.CommonTestOptions.SetAndroidMkEntries(entries)
}
}) })
return entriesList return entriesList

View File

@@ -852,11 +852,10 @@ func LibraryHostFactory() android.Module {
// Test option struct. // Test option struct.
type TestOptions struct { type TestOptions struct {
android.CommonTestOptions
// a list of extra test configuration files that should be installed with the module. // a list of extra test configuration files that should be installed with the module.
Extra_test_configs []string `android:"path,arch_variant"` Extra_test_configs []string `android:"path,arch_variant"`
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
Unit_test *bool
} }
type testProperties struct { type testProperties struct {

View File

@@ -69,7 +69,7 @@ func (p *testDecorator) AndroidMk(base *Module, entries *android.AndroidMkEntrie
entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...) entries.AddStrings("LOCAL_TEST_DATA", android.AndroidMkDataPaths(p.data)...)
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(p.testProperties.Test_options.Unit_test)) p.testProperties.Test_options.SetAndroidMkEntries(entries)
}) })
base.subAndroidMk(entries, p.binaryDecorator.pythonInstaller) base.subAndroidMk(entries, p.binaryDecorator.pythonInstaller)
} }

View File

@@ -32,12 +32,6 @@ func registerPythonTestComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("python_test", PythonTestFactory) ctx.RegisterModuleType("python_test", PythonTestFactory)
} }
// Test option struct.
type TestOptions struct {
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
Unit_test *bool
}
type TestProperties struct { type TestProperties struct {
// 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.
@@ -55,7 +49,7 @@ type TestProperties struct {
Java_data []string Java_data []string
// Test options. // Test options.
Test_options TestOptions Test_options android.CommonTestOptions
} }
type testDecorator struct { type testDecorator struct {

View File

@@ -105,10 +105,11 @@ func (test *testDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidM
entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String()) entries.SetString("LOCAL_FULL_TEST_CONFIG", test.testConfig.String())
} }
entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true)) entries.SetBoolIfTrue("LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG", !BoolDefault(test.Properties.Auto_gen_config, true))
entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", Bool(test.Properties.Test_options.Unit_test))
if test.Properties.Data_bins != nil { if test.Properties.Data_bins != nil {
entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...) entries.AddStrings("LOCAL_TEST_DATA_BINS", test.Properties.Data_bins...)
} }
test.Properties.Test_options.SetAndroidMkEntries(entries)
}) })
cc.AndroidMkWriteTestData(test.data, ret) cc.AndroidMkWriteTestData(test.data, ret)

View File

@@ -24,12 +24,6 @@ import (
"android/soong/tradefed" "android/soong/tradefed"
) )
// Test option struct.
type TestOptions struct {
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
Unit_test *bool
}
type TestProperties struct { type TestProperties struct {
// Disables the creation of a test-specific directory when used with // Disables the creation of a test-specific directory when used with
// relative_install_path. Useful if several tests need to be in the same // relative_install_path. Useful if several tests need to be in the same
@@ -67,7 +61,7 @@ type TestProperties struct {
Test_harness *bool Test_harness *bool
// Test options. // Test options.
Test_options TestOptions Test_options android.CommonTestOptions
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run // Add RootTargetPreparer to auto generated test config. This guarantees the test to run
// with root permission. // with root permission.

View File

@@ -103,12 +103,6 @@ type shBinaryProperties struct {
Recovery_available *bool Recovery_available *bool
} }
// Test option struct.
type TestOptions struct {
// If the test is a hostside(no device required) unittest that shall be run during presubmit check.
Unit_test *bool
}
type TestProperties struct { type TestProperties struct {
// list of compatibility suites (for example "cts", "vts") that the module should be // list of compatibility suites (for example "cts", "vts") that the module should be
// installed into. // installed into.
@@ -153,7 +147,7 @@ type TestProperties struct {
Per_testcase_directory *bool Per_testcase_directory *bool
// Test options. // Test options.
Test_options TestOptions Test_options android.CommonTestOptions
} }
type ShBinary struct { type ShBinary struct {
@@ -464,10 +458,9 @@ func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
if s.testProperties.Data_bins != nil { if s.testProperties.Data_bins != nil {
entries.AddStrings("LOCAL_TEST_DATA_BINS", s.testProperties.Data_bins...) entries.AddStrings("LOCAL_TEST_DATA_BINS", s.testProperties.Data_bins...)
} }
if Bool(s.testProperties.Test_options.Unit_test) {
entries.SetBool("LOCAL_IS_UNIT_TEST", true)
}
entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(s.testProperties.Per_testcase_directory)) entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(s.testProperties.Per_testcase_directory))
s.testProperties.Test_options.SetAndroidMkEntries(entries)
}, },
}, },
}} }}