From 6ffaaa830dd7311509aa07322810013a874ff8e6 Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Thu, 26 Sep 2019 11:41:36 -0700 Subject: [PATCH] Allow test to specify whether or not to auto-generate test config Attribute `auto_gen_config` is added to test modules. Test config will be generated if: the attribute is not set and AndroidTest.xml doesn't exists or the attribute is set to true, whether or not AndroidTest.xml exists. Test config will NOT be auto-generated if: the attribute is not set and AndroidTest.xml exists or the attribute is set to false, whether or not AndroidTest.xml exists. Bug: 141684102 Test: build test module with auto_gen_config set to true Change-Id: I64fb003a83d8c32a967835e5f8d12fe4476043be --- cc/test.go | 14 ++++++++++++-- java/app.go | 8 +++++++- java/java.go | 8 +++++++- python/binary.go | 5 +++++ python/test.go | 3 ++- tradefed/autogen.go | 32 +++++++++++++++++++------------- 6 files changed, 52 insertions(+), 18 deletions(-) diff --git a/cc/test.go b/cc/test.go index ba0b7e482..0e66e288e 100644 --- a/cc/test.go +++ b/cc/test.go @@ -80,6 +80,11 @@ type TestBinaryProperties struct { // Add MinApiLevelModuleController to auto generated test config. If the device property of // "ro.build.version.sdk" < Test_min_sdk_version, then skip this module. Test_min_sdk_version *int64 + + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml + // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true + // explicitly. + Auto_gen_config *bool } func init() { @@ -362,7 +367,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.Test_config_template, test.Properties.Test_suites, configs, test.Properties.Auto_gen_config) test.binaryDecorator.baseInstaller.dir = "nativetest" test.binaryDecorator.baseInstaller.dir64 = "nativetest64" @@ -453,6 +458,11 @@ type BenchmarkProperties struct { // Add RootTargetPreparer to auto generated test config. This guarantees the test to run // with root permission. Require_root *bool + + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml + // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true + // explicitly. + Auto_gen_config *bool } type benchmarkDecorator struct { @@ -490,7 +500,7 @@ func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Pat configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) } benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config, - benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs) + benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs, benchmark.Properties.Auto_gen_config) benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName()) benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName()) diff --git a/java/app.go b/java/app.go index d00c4c031..afddb6a3e 100644 --- a/java/app.go +++ b/java/app.go @@ -608,7 +608,8 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { } a.generateAndroidBuildActions(ctx) - a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config, a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites) + a.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.data = android.PathsForModuleSrc(ctx, a.testProperties.Data) } @@ -656,6 +657,11 @@ type appTestHelperAppProperties struct { // list of compatibility suites (for example "cts", "vts") that the module should be // installed into. Test_suites []string `android:"arch_variant"` + + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml + // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true + // explicitly. + Auto_gen_config *bool } type AndroidTestHelperApp struct { diff --git a/java/java.go b/java/java.go index 4dd6a490e..ce72c2760 100644 --- a/java/java.go +++ b/java/java.go @@ -1685,6 +1685,11 @@ type testProperties struct { // list of files or filegroup modules that provide data that should be installed alongside // the test Data []string `android:"path"` + + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml + // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true + // explicitly. + Auto_gen_config *bool } type testHelperLibraryProperties struct { @@ -1709,7 +1714,8 @@ type TestHelperLibrary struct { } func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { - j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, j.testProperties.Test_suites) + j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, + j.testProperties.Test_suites, j.testProperties.Auto_gen_config) j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) j.Library.GenerateAndroidBuildActions(ctx) diff --git a/python/binary.go b/python/binary.go index 140f07af9..695fa123b 100644 --- a/python/binary.go +++ b/python/binary.go @@ -47,6 +47,11 @@ type BinaryProperties struct { // false it will act much like the normal `python` executable, but with the sources and // libraries automatically included in the PYTHONPATH. Autorun *bool `android:"arch_variant"` + + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml + // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true + // explicitly. + Auto_gen_config *bool } type binaryDecorator struct { diff --git a/python/test.go b/python/test.go index 55b0ab53a..f684fd51d 100644 --- a/python/test.go +++ b/python/test.go @@ -50,7 +50,8 @@ func (test *testDecorator) bootstrapperProps() []interface{} { func (test *testDecorator) install(ctx android.ModuleContext, file android.Path) { test.testConfig = tradefed.AutoGenPythonBinaryHostTestConfig(ctx, test.testProperties.Test_config, - test.testProperties.Test_config_template, test.binaryDecorator.binaryProperties.Test_suites) + test.testProperties.Test_config_template, test.binaryDecorator.binaryProperties.Test_suites, + test.binaryDecorator.binaryProperties.Auto_gen_config) test.binaryDecorator.pythonInstaller.dir = "nativetest" test.binaryDecorator.pythonInstaller.dir64 = "nativetest64" diff --git a/tradefed/autogen.go b/tradefed/autogen.go index 1400345e5..3d30cfa13 100644 --- a/tradefed/autogen.go +++ b/tradefed/autogen.go @@ -44,10 +44,11 @@ var autogenTestConfig = pctx.StaticRule("autogenTestConfig", blueprint.RuleParam CommandDeps: []string{"$template"}, }, "name", "template", "extraConfigs") -func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string) (path android.Path, autogenPath android.WritablePath) { - if p := getTestConfig(ctx, prop); p != nil { +func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string, autoGenConfig *bool) (path android.Path, autogenPath android.WritablePath) { + p := getTestConfig(ctx, prop) + if !Bool(autoGenConfig) && p != nil { return p, nil - } else if !android.InList("cts", testSuites) { + } else if !android.InList("cts", testSuites) && BoolDefault(autoGenConfig, true) { outputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".config") return nil, outputFile } else { @@ -124,8 +125,8 @@ func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, tem } func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string, - testConfigTemplateProp *string, testSuites []string, config []Config) android.Path { - path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) + testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool) android.Path { + path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig) if autogenPath != nil { templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) if templatePath.Valid() { @@ -143,8 +144,8 @@ func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string, } func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp *string, - testConfigTemplateProp *string, testSuites []string, configs []Config) android.Path { - path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) + testConfigTemplateProp *string, testSuites []string, configs []Config, autoGenConfig *bool) android.Path { + path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig) if autogenPath != nil { templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) if templatePath.Valid() { @@ -157,8 +158,9 @@ func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp return path } -func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, testSuites []string) android.Path { - path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) +func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, + testSuites []string, autoGenConfig *bool) android.Path { + path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig) if autogenPath != nil { templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) if templatePath.Valid() { @@ -176,9 +178,9 @@ func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, te } func AutoGenPythonBinaryHostTestConfig(ctx android.ModuleContext, testConfigProp *string, - testConfigTemplateProp *string, testSuites []string) android.Path { + testConfigTemplateProp *string, testSuites []string, autoGenConfig *bool) android.Path { - path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) + path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig) if autogenPath != nil { templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) if templatePath.Valid() { @@ -200,8 +202,9 @@ var autogenInstrumentationTest = pctx.StaticRule("autogenInstrumentationTest", b }, }, "name", "template") -func AutoGenInstrumentationTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, manifest android.Path, testSuites []string) android.Path { - path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites) +func AutoGenInstrumentationTestConfig(ctx android.ModuleContext, testConfigProp *string, + testConfigTemplateProp *string, manifest android.Path, testSuites []string, autoGenConfig *bool) android.Path { + path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig) if autogenPath != nil { template := "${InstrumentationTestConfigTemplate}" moduleTemplate := getTestConfigTemplate(ctx, testConfigTemplateProp) @@ -222,3 +225,6 @@ func AutoGenInstrumentationTestConfig(ctx android.ModuleContext, testConfigProp } return path } + +var Bool = proptools.Bool +var BoolDefault = proptools.BoolDefault