diff options
author | yelinhsieh <yelinhsieh@google.com> | 2018-10-01 19:23:14 +0800 |
---|---|---|
committer | yelinhsieh <yelinhsieh@google.com> | 2018-10-22 14:14:29 +0800 |
commit | d30b940dffa10b1a2e703178af386d4b5a8616ae (patch) | |
tree | 82315efd1bbea09ee32845b61d971da474cb4a88 /tradefed | |
parent | 109029fb5c0eb7f9c8263223adff063bb6d6ff03 (diff) | |
download | build_soong-d30b940dffa10b1a2e703178af386d4b5a8616ae.tar.gz build_soong-d30b940dffa10b1a2e703178af386d4b5a8616ae.tar.bz2 build_soong-d30b940dffa10b1a2e703178af386d4b5a8616ae.zip |
ATest: GTest auto gen config support run_test_as in Android.bp .
Feature request from developer, support setting uid in Android.bp.
Bug:113359343
Test: source build/envsetup.sh ; lunch
vim platform_testing/tests/example/native/Android.bp
add
test_options: {
run_test_as: "1234",
},
in cc_test
make hello_world_test
cat out/target/product/xxxx/testcases/hello_world_test/hello_world_test.config
Will see <option name="run-test-as" value="1234" />
below <test class="com.android.tradefed.testtype.GTest" >
Change-Id: I5604af5f20c45728d19f4c01396a20a74997f8a8
Diffstat (limited to 'tradefed')
-rw-r--r-- | tradefed/autogen.go | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/tradefed/autogen.go b/tradefed/autogen.go index 131fdc44..5fb85c3c 100644 --- a/tradefed/autogen.go +++ b/tradefed/autogen.go @@ -15,6 +15,7 @@ package tradefed import ( + "fmt" "strings" "github.com/google/blueprint" @@ -36,9 +37,10 @@ func getTestConfig(ctx android.ModuleContext, prop *string) android.Path { } var autogenTestConfig = pctx.StaticRule("autogenTestConfig", blueprint.RuleParams{ - Command: "sed 's&{MODULE}&${name}&g' $template > $out", + Command: "sed 's&{MODULE}&${name}&g' $template > $out &&" + + "${optionCmd} $out", CommandDeps: []string{"$template"}, -}, "name", "template") +}, "name", "template", "optionCmd") func testConfigPath(ctx android.ModuleContext, prop *string) (path android.Path, autogenPath android.WritablePath) { if p := getTestConfig(ctx, prop); p != nil { @@ -54,30 +56,44 @@ func testConfigPath(ctx android.ModuleContext, prop *string) (path android.Path, } } -func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string) { +func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, optionsMap map[string]string) { + // If no test option found, delete {UID_OPTION} line. + // If found, replace it with corresponding options format. + optionCmd := "sed -i '/{UID_OPTION}/d'" + if optionsMap != nil { + //Append options + var options []string + for optionName, value := range optionsMap { + if value != "" { + options = append(options, fmt.Sprintf("<option name=\"%s\" value=\"%s\" />", optionName, value)) + } + } + optionCmd = fmt.Sprintf("sed -i 's&{UID_OPTION}&%s&g'", strings.Join(options, "\\n ")) + } ctx.Build(pctx, android.BuildParams{ Rule: autogenTestConfig, Description: "test config", Output: output, Args: map[string]string{ - "name": ctx.ModuleName(), - "template": template, + "name": ctx.ModuleName(), + "template": template, + "optionCmd": optionCmd, }, }) } func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string, - testConfigTemplateProp *string) android.Path { + testConfigTemplateProp *string, optionsMap map[string]string) android.Path { path, autogenPath := testConfigPath(ctx, testConfigProp) if autogenPath != nil { templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) if templatePath.Valid() { - autogenTemplate(ctx, autogenPath, templatePath.String()) + autogenTemplate(ctx, autogenPath, templatePath.String(), optionsMap) } else { if ctx.Device() { - autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}") + autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}", optionsMap) } else { - autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}") + autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}", optionsMap) } } return autogenPath @@ -91,9 +107,9 @@ func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp if autogenPath != nil { templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) if templatePath.Valid() { - autogenTemplate(ctx, autogenPath, templatePath.String()) + autogenTemplate(ctx, autogenPath, templatePath.String(), nil) } else { - autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}") + autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}", nil) } return autogenPath } @@ -105,12 +121,12 @@ func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, te if autogenPath != nil { templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp) if templatePath.Valid() { - autogenTemplate(ctx, autogenPath, templatePath.String()) + autogenTemplate(ctx, autogenPath, templatePath.String(), nil) } else { if ctx.Device() { - autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}") + autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}", nil) } else { - autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}") + autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}", nil) } } return autogenPath |