From 5bcff5d1fdb127663e7acd5882d3e6462c33fbc9 Mon Sep 17 00:00:00 2001 From: easoncylee Date: Thu, 30 Apr 2020 14:57:06 +0800 Subject: [PATCH] Add test_mainline_modules to the auto-gen test config(AndroidJUnitTest 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 (search for auto-generated pattern) Bug: 155238134 Test: add "test_mainline_modules: [some.apk]" to TetheringTests, and build the modules, confirm the parameterized option is added in the test config. Change-Id: I41ba8749ce46da62db402a8b8a555d4874e1cfc0 --- java/app.go | 7 ++++++- java/java.go | 4 ++++ tradefed/autogen.go | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/java/app.go b/java/app.go index f1af2adf4..d5ad0d8f9 100755 --- a/java/app.go +++ b/java/app.go @@ -835,6 +835,7 @@ func (a *AndroidTest) InstallInTestcases() bool { } func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { + var configs []tradefed.Config if a.appTestProperties.Instrumentation_target_package != nil { a.additionalAaptFlags = append(a.additionalAaptFlags, "--rename-instrumentation-target-package "+*a.appTestProperties.Instrumentation_target_package) @@ -847,8 +848,12 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { } a.generateAndroidBuildActions(ctx) + for _, module := range a.testProperties.Test_mainline_modules { + configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: "mainline-param", Value: module}) + } + testConfig := tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, - a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, a.testProperties.Auto_gen_config) + a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, a.testProperties.Auto_gen_config, configs) a.testConfig = a.FixTestConfig(ctx, testConfig) a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) } diff --git a/java/java.go b/java/java.go index 9d75c74c7..7d31f669d 100644 --- a/java/java.go +++ b/java/java.go @@ -2033,6 +2033,10 @@ type testProperties struct { // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true // explicitly. Auto_gen_config *bool + + // Add parameterized mainline modules to auto generated test config. The options will be + // handled by TradeFed to do downloading and installing the specified modules on the device. + Test_mainline_modules []string } type testHelperLibraryProperties struct { diff --git a/tradefed/autogen.go b/tradefed/autogen.go index 596284beb..be44cac5d 100644 --- a/tradefed/autogen.go +++ b/tradefed/autogen.go @@ -219,31 +219,39 @@ func AutoGenRustTestConfig(ctx android.ModuleContext, name string, testConfigPro } var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", blueprint.RuleParams{ - Command: "${AutoGenTestConfigScript} $out $in ${EmptyTestConfig} $template", + Command: "${AutoGenTestConfigScript} $out $in ${EmptyTestConfig} $template ${extraConfigs}", CommandDeps: []string{ "${AutoGenTestConfigScript}", "${EmptyTestConfig}", "$template", }, -}, "name", "template") +}, "name", "template", "extraConfigs") func AutoGenInstrumentationTestConfig(ctx android.ModuleContext, testConfigProp *string, - testConfigTemplateProp *string, manifest android.Path, testSuites []string, autoGenConfig *bool) android.Path { + testConfigTemplateProp *string, manifest android.Path, testSuites []string, autoGenConfig *bool, configs []Config) android.Path { path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp) + var configStrings []string if autogenPath != nil { template := "${InstrumentationTestConfigTemplate}" moduleTemplate := getTestConfigTemplate(ctx, testConfigTemplateProp) if moduleTemplate.Valid() { template = moduleTemplate.String() } + for _, config := range configs { + configStrings = append(configStrings, config.Config()) + } + extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent)) + extraConfigs = fmt.Sprintf("--extra-configs '%s'", extraConfigs) + ctx.Build(pctx, android.BuildParams{ Rule: autogenInstrumentationTest, Description: "test config", Input: manifest, Output: autogenPath, Args: map[string]string{ - "name": ctx.ModuleName(), - "template": template, + "name": ctx.ModuleName(), + "template": template, + "extraConfigs": extraConfigs, }, }) return autogenPath