Merge "Support test runnner option in auto generated test configs"
This commit is contained in:
commit
b25cbb3449
4 changed files with 59 additions and 12 deletions
|
@ -70,6 +70,10 @@ type TestOptions struct {
|
|||
// 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.
|
||||
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 {
|
||||
|
@ -398,6 +402,7 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
|||
TestConfigTemplateProp: test.Properties.Test_config_template,
|
||||
TestSuites: test.testDecorator.InstallerProperties.Test_suites,
|
||||
Config: configs,
|
||||
TestRunnerOptions: test.Properties.Test_options.Test_runner_options,
|
||||
AutoGenConfig: test.Properties.Auto_gen_config,
|
||||
TestInstallBase: testInstallBase,
|
||||
DeviceTemplate: "${NativeTestConfigTemplate}",
|
||||
|
|
|
@ -936,6 +936,10 @@ type TestOptions struct {
|
|||
// Extra <option> tags to add to the auto generated test xml file. The "key"
|
||||
// is optional in each of these.
|
||||
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 {
|
||||
|
@ -1218,6 +1222,7 @@ func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext,
|
|||
TestSuites: j.testProperties.Test_suites,
|
||||
Config: configs,
|
||||
OptionsForAutogenerated: j.testProperties.Test_options.Tradefed_options,
|
||||
TestRunnerOptions: j.testProperties.Test_options.Test_runner_options,
|
||||
AutoGenConfig: j.testProperties.Auto_gen_config,
|
||||
UnitTest: j.testProperties.Test_options.Unit_test,
|
||||
DeviceTemplate: "${JavaTestConfigTemplate}",
|
||||
|
|
|
@ -2298,3 +2298,27 @@ java_test_host {
|
|||
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"])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ func getTestConfig(ctx android.ModuleContext, prop *string) android.Path {
|
|||
}
|
||||
|
||||
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"},
|
||||
}, "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) {
|
||||
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 == "" {
|
||||
ctx.ModuleErrorf("Empty template")
|
||||
}
|
||||
|
@ -118,6 +118,16 @@ func autogenTemplate(ctx android.ModuleContext, name string, output android.Writ
|
|||
extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent))
|
||||
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{
|
||||
Rule: autogenTestConfig,
|
||||
Description: "test config",
|
||||
|
@ -128,6 +138,7 @@ func autogenTemplate(ctx android.ModuleContext, name string, output android.Writ
|
|||
"extraConfigs": extraConfigs,
|
||||
"outputFileName": outputFileName,
|
||||
"testInstallBase": testInstallBase,
|
||||
"extraTestRunnerConfigs": extraTestRunnerConfigs,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -142,6 +153,7 @@ type AutoGenTestConfigOptions struct {
|
|||
TestSuites []string
|
||||
Config []Config
|
||||
OptionsForAutogenerated []Option
|
||||
TestRunnerOptions []Option
|
||||
AutoGenConfig *bool
|
||||
UnitTest *bool
|
||||
TestInstallBase string
|
||||
|
@ -155,6 +167,7 @@ func AutoGenTestConfig(ctx android.ModuleContext, options AutoGenTestConfigOptio
|
|||
for _, c := range options.OptionsForAutogenerated {
|
||||
configs = append(configs, c)
|
||||
}
|
||||
testRunnerConfigs := append([]Option{}, options.TestRunnerOptions...)
|
||||
name := options.Name
|
||||
if name == "" {
|
||||
name = ctx.ModuleName()
|
||||
|
@ -163,15 +176,15 @@ func AutoGenTestConfig(ctx android.ModuleContext, options AutoGenTestConfigOptio
|
|||
if autogenPath != nil {
|
||||
templatePath := getTestConfigTemplate(ctx, options.TestConfigTemplateProp)
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
autogenTemplate(ctx, name, autogenPath, options.HostTemplate, configs, options.OutputFileName, options.TestInstallBase)
|
||||
autogenTemplate(ctx, name, autogenPath, options.HostTemplate, configs, testRunnerConfigs, options.OutputFileName, options.TestInstallBase)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue