Add test_mainline_modules to the auto-gen test config(GTest only).

To support parameterized mainline modules in Test Mapping, we plan to
add a new parameter called test_mainline_modules in build system to
auto-generate the test config based on the parameter.

For detailed information: go/test-mapping-mainline-gcl
(serach for auto-generated pattern)

Bug: 155238134
Test: add "test_mainline_modules: [some.apk]" to libstatspull_test,
and build the modules, confirm the parameterized option is added
in the test config.

Change-Id: I31d6dfbb71881d7a7026cf2f36ba6ca6a97870ad
This commit is contained in:
easoncylee 2020-04-30 10:08:33 +08:00
parent b407131a0e
commit 1e3fdcd182
2 changed files with 18 additions and 7 deletions

View File

@ -90,6 +90,10 @@ type TestBinaryProperties struct {
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
// explicitly. // explicitly.
Auto_gen_config *bool Auto_gen_config *bool
// 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
} }
func init() { func init() {
@ -329,24 +333,27 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
var api_level_prop string var api_level_prop string
var configs []tradefed.Config var configs []tradefed.Config
var min_level string var min_level string
for _, module := range test.Properties.Test_mainline_modules {
configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module})
}
if Bool(test.Properties.Require_root) { if Bool(test.Properties.Require_root) {
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
} else { } else {
var options []tradefed.Option var options []tradefed.Option
options = append(options, tradefed.Option{"force-root", "false"}) options = append(options, tradefed.Option{Name: "force-root", Value: "false"})
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options}) configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
} }
if Bool(test.Properties.Disable_framework) { if Bool(test.Properties.Disable_framework) {
var options []tradefed.Option var options []tradefed.Option
options = append(options, tradefed.Option{"run-command", "stop"}) options = append(options, tradefed.Option{Name: "run-command", Value: "stop"})
options = append(options, tradefed.Option{"teardown-command", "start"}) options = append(options, tradefed.Option{Name: "teardown-command", Value: "start"})
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RunCommandTargetPreparer", options}) configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RunCommandTargetPreparer", options})
} }
if Bool(test.testDecorator.Properties.Isolated) { if Bool(test.testDecorator.Properties.Isolated) {
configs = append(configs, tradefed.Option{"not-shardable", "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 {
configs = append(configs, tradefed.Option{"run-test-as", String(test.Properties.Test_options.Run_test_as)}) configs = append(configs, tradefed.Option{Name: "run-test-as", Value: String(test.Properties.Test_options.Run_test_as)})
} }
if test.Properties.Test_min_api_level != nil && test.Properties.Test_min_sdk_version != nil { 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.") ctx.PropertyErrorf("test_min_api_level", "'test_min_api_level' and 'test_min_sdk_version' should not be set at the same time.")
@ -359,8 +366,8 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
} }
if api_level_prop != "" { if api_level_prop != "" {
var options []tradefed.Option var options []tradefed.Option
options = append(options, tradefed.Option{"min-api-level", min_level}) options = append(options, tradefed.Option{Name: "min-api-level", Value: min_level})
options = append(options, tradefed.Option{"api-level-prop", api_level_prop}) options = append(options, tradefed.Option{Name: "api-level-prop", Value: api_level_prop})
configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.MinApiLevelModuleController", options}) configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.MinApiLevelModuleController", options})
} }

View File

@ -64,12 +64,16 @@ type Config interface {
type Option struct { type Option struct {
Name string Name string
Key string
Value string Value string
} }
var _ Config = Option{} var _ Config = Option{}
func (o Option) Config() string { func (o Option) Config() string {
if o.Key != "" {
return fmt.Sprintf(`<option name="%s" key="%s" value="%s" />`, o.Name, o.Key, o.Value)
}
return fmt.Sprintf(`<option name="%s" value="%s" />`, o.Name, o.Value) return fmt.Sprintf(`<option name="%s" value="%s" />`, o.Name, o.Value)
} }