Support test runnner option in auto generated test configs

Bug: 284179405
Bug: 236980335
Test: unittest
Change-Id: Ifae3d556ff79153ca6c3067347fc259b665fb2e1
This commit is contained in:
Dan Shi
2023-05-26 04:21:44 +00:00
parent 1befe407a1
commit ec7314336a
4 changed files with 59 additions and 12 deletions

View File

@@ -70,6 +70,10 @@ type TestOptions struct {
// Add MinApiLevelModuleController with ro.vndk.version property. If ro.vndk.version has an // Add MinApiLevelModuleController with ro.vndk.version property. If ro.vndk.version has an
// integer value and the value is less than the min_vndk_version, skip this module. // integer value and the value is less than the min_vndk_version, skip this module.
Min_vndk_version *int64 Min_vndk_version *int64
// Extra <option> tags to add to the auto generated test xml file under the test runner, e.g., GTest.
// The "key" is optional in each of these.
Test_runner_options []tradefed.Option
} }
type TestBinaryProperties struct { type TestBinaryProperties struct {
@@ -398,6 +402,7 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
TestConfigTemplateProp: test.Properties.Test_config_template, TestConfigTemplateProp: test.Properties.Test_config_template,
TestSuites: test.testDecorator.InstallerProperties.Test_suites, TestSuites: test.testDecorator.InstallerProperties.Test_suites,
Config: configs, Config: configs,
TestRunnerOptions: test.Properties.Test_options.Test_runner_options,
AutoGenConfig: test.Properties.Auto_gen_config, AutoGenConfig: test.Properties.Auto_gen_config,
TestInstallBase: testInstallBase, TestInstallBase: testInstallBase,
DeviceTemplate: "${NativeTestConfigTemplate}", DeviceTemplate: "${NativeTestConfigTemplate}",

View File

@@ -936,6 +936,10 @@ type TestOptions struct {
// Extra <option> tags to add to the auto generated test xml file. The "key" // Extra <option> tags to add to the auto generated test xml file. The "key"
// is optional in each of these. // is optional in each of these.
Tradefed_options []tradefed.Option Tradefed_options []tradefed.Option
// Extra <option> tags to add to the auto generated test xml file under the test runner, e.g., AndroidJunitTest.
// The "key" is optional in each of these.
Test_runner_options []tradefed.Option
} }
type testProperties struct { type testProperties struct {
@@ -1218,6 +1222,7 @@ func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext,
TestSuites: j.testProperties.Test_suites, TestSuites: j.testProperties.Test_suites,
Config: configs, Config: configs,
OptionsForAutogenerated: j.testProperties.Test_options.Tradefed_options, OptionsForAutogenerated: j.testProperties.Test_options.Tradefed_options,
TestRunnerOptions: j.testProperties.Test_options.Test_runner_options,
AutoGenConfig: j.testProperties.Auto_gen_config, AutoGenConfig: j.testProperties.Auto_gen_config,
UnitTest: j.testProperties.Test_options.Unit_test, UnitTest: j.testProperties.Test_options.Unit_test,
DeviceTemplate: "${JavaTestConfigTemplate}", DeviceTemplate: "${JavaTestConfigTemplate}",

View File

@@ -2298,3 +2298,27 @@ java_test_host {
t.Errorf("Expected args[\"extraConfigs\"] to equal %q, was %q", expected, args["extraConfigs"]) t.Errorf("Expected args[\"extraConfigs\"] to equal %q, was %q", expected, args["extraConfigs"])
} }
} }
func TestTestRunnerOptions(t *testing.T) {
result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, `
java_test_host {
name: "foo",
test_options: {
test_runner_options: [
{
name: "test-timeout",
value: "10m"
}
]
}
}
`)
buildOS := result.Config.BuildOS.String()
args := result.ModuleForTests("foo", buildOS+"_common").
Output("out/soong/.intermediates/foo/" + buildOS + "_common/foo.config").Args
expected := proptools.NinjaAndShellEscape("<option name=\"test-timeout\" value=\"10m\" />\\n ")
if args["extraTestRunnerConfigs"] != expected {
t.Errorf("Expected args[\"extraTestRunnerConfigs\"] to equal %q, was %q", expected, args["extraTestRunnerConfigs"])
}
}

View File

@@ -40,9 +40,9 @@ func getTestConfig(ctx android.ModuleContext, prop *string) android.Path {
} }
var autogenTestConfig = pctx.StaticRule("autogenTestConfig", blueprint.RuleParams{ var autogenTestConfig = pctx.StaticRule("autogenTestConfig", blueprint.RuleParams{
Command: "sed 's&{MODULE}&${name}&g;s&{EXTRA_CONFIGS}&'${extraConfigs}'&g;s&{OUTPUT_FILENAME}&'${outputFileName}'&g;s&{TEST_INSTALL_BASE}&'${testInstallBase}'&g' $template > $out", Command: "sed 's&{MODULE}&${name}&g;s&{EXTRA_CONFIGS}&'${extraConfigs}'&g;s&{EXTRA_TEST_RUNNER_CONFIGS}&'${extraTestRunnerConfigs}'&g;s&{OUTPUT_FILENAME}&'${outputFileName}'&g;s&{TEST_INSTALL_BASE}&'${testInstallBase}'&g' $template > $out",
CommandDeps: []string{"$template"}, CommandDeps: []string{"$template"},
}, "name", "template", "extraConfigs", "outputFileName", "testInstallBase") }, "name", "template", "extraConfigs", "outputFileName", "testInstallBase", "extraTestRunnerConfigs")
func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string, autoGenConfig *bool, testConfigTemplateProp *string) (path android.Path, autogenPath android.WritablePath) { func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string, autoGenConfig *bool, testConfigTemplateProp *string) (path android.Path, autogenPath android.WritablePath) {
p := getTestConfig(ctx, prop) p := getTestConfig(ctx, prop)
@@ -107,7 +107,7 @@ func (ob Object) Config() string {
} }
func autogenTemplate(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, outputFileName string, testInstallBase string) { func autogenTemplate(ctx android.ModuleContext, name string, output android.WritablePath, template string, configs []Config, testRunnerConfigs []Option, outputFileName string, testInstallBase string) {
if template == "" { if template == "" {
ctx.ModuleErrorf("Empty template") ctx.ModuleErrorf("Empty template")
} }
@@ -118,16 +118,27 @@ func autogenTemplate(ctx android.ModuleContext, name string, output android.Writ
extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent)) extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent))
extraConfigs = proptools.NinjaAndShellEscape(extraConfigs) extraConfigs = proptools.NinjaAndShellEscape(extraConfigs)
var testRunnerConfigStrings []string
for _, config := range testRunnerConfigs {
testRunnerConfigStrings = append(testRunnerConfigStrings, config.Config())
}
extraTestRunnerConfigs := strings.Join(testRunnerConfigStrings, fmt.Sprintf("\\n%s%s", test_xml_indent, test_xml_indent))
if len(extraTestRunnerConfigs) > 0 {
extraTestRunnerConfigs += fmt.Sprintf("\\n%s%s", test_xml_indent, test_xml_indent)
}
extraTestRunnerConfigs = proptools.NinjaAndShellEscape(extraTestRunnerConfigs)
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: autogenTestConfig, Rule: autogenTestConfig,
Description: "test config", Description: "test config",
Output: output, Output: output,
Args: map[string]string{ Args: map[string]string{
"name": name, "name": name,
"template": template, "template": template,
"extraConfigs": extraConfigs, "extraConfigs": extraConfigs,
"outputFileName": outputFileName, "outputFileName": outputFileName,
"testInstallBase": testInstallBase, "testInstallBase": testInstallBase,
"extraTestRunnerConfigs": extraTestRunnerConfigs,
}, },
}) })
} }
@@ -142,6 +153,7 @@ type AutoGenTestConfigOptions struct {
TestSuites []string TestSuites []string
Config []Config Config []Config
OptionsForAutogenerated []Option OptionsForAutogenerated []Option
TestRunnerOptions []Option
AutoGenConfig *bool AutoGenConfig *bool
UnitTest *bool UnitTest *bool
TestInstallBase string TestInstallBase string
@@ -155,6 +167,7 @@ func AutoGenTestConfig(ctx android.ModuleContext, options AutoGenTestConfigOptio
for _, c := range options.OptionsForAutogenerated { for _, c := range options.OptionsForAutogenerated {
configs = append(configs, c) configs = append(configs, c)
} }
testRunnerConfigs := append([]Option{}, options.TestRunnerOptions...)
name := options.Name name := options.Name
if name == "" { if name == "" {
name = ctx.ModuleName() name = ctx.ModuleName()
@@ -163,15 +176,15 @@ func AutoGenTestConfig(ctx android.ModuleContext, options AutoGenTestConfigOptio
if autogenPath != nil { if autogenPath != nil {
templatePath := getTestConfigTemplate(ctx, options.TestConfigTemplateProp) templatePath := getTestConfigTemplate(ctx, options.TestConfigTemplateProp)
if templatePath.Valid() { if templatePath.Valid() {
autogenTemplate(ctx, name, autogenPath, templatePath.String(), configs, options.OutputFileName, options.TestInstallBase) autogenTemplate(ctx, name, autogenPath, templatePath.String(), configs, testRunnerConfigs, options.OutputFileName, options.TestInstallBase)
} else { } else {
if ctx.Device() { if ctx.Device() {
autogenTemplate(ctx, name, autogenPath, options.DeviceTemplate, configs, options.OutputFileName, options.TestInstallBase) autogenTemplate(ctx, name, autogenPath, options.DeviceTemplate, configs, testRunnerConfigs, options.OutputFileName, options.TestInstallBase)
} else { } else {
if Bool(options.UnitTest) { if Bool(options.UnitTest) {
autogenTemplate(ctx, name, autogenPath, options.HostUnitTestTemplate, configs, options.OutputFileName, options.TestInstallBase) autogenTemplate(ctx, name, autogenPath, options.HostUnitTestTemplate, configs, testRunnerConfigs, options.OutputFileName, options.TestInstallBase)
} else { } else {
autogenTemplate(ctx, name, autogenPath, options.HostTemplate, configs, options.OutputFileName, options.TestInstallBase) autogenTemplate(ctx, name, autogenPath, options.HostTemplate, configs, testRunnerConfigs, options.OutputFileName, options.TestInstallBase)
} }
} }
} }