Merge "Revert "ATest: GTest auto gen config support run_test_as in Android.bp .""
am: 1e30905f65
Change-Id: I23b1f23dde966742daff46f613c33eea4c2eea88
This commit is contained in:
19
cc/test.go
19
cc/test.go
@@ -31,12 +31,6 @@ type TestProperties struct {
|
|||||||
Isolated *bool
|
Isolated *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test option struct.
|
|
||||||
type TestOptions struct {
|
|
||||||
// the UID that you want to run in device.
|
|
||||||
Run_test_as string `android:"arch_variant"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TestBinaryProperties struct {
|
type TestBinaryProperties struct {
|
||||||
// Create a separate binary for each source file. Useful when there is
|
// Create a separate binary for each source file. Useful when there is
|
||||||
// global state that can not be torn down and reset between each test suite.
|
// global state that can not be torn down and reset between each test suite.
|
||||||
@@ -62,9 +56,6 @@ type TestBinaryProperties struct {
|
|||||||
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
// the name of the test configuration template (for example "AndroidTestTemplate.xml") that
|
||||||
// should be installed with the module.
|
// should be installed with the module.
|
||||||
Test_config_template *string `android:"arch_variant"`
|
Test_config_template *string `android:"arch_variant"`
|
||||||
|
|
||||||
// Test options.
|
|
||||||
Test_options *TestOptions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -253,16 +244,8 @@ func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
|
|
||||||
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
||||||
test.data = ctx.ExpandSources(test.Properties.Data, nil)
|
test.data = ctx.ExpandSources(test.Properties.Data, nil)
|
||||||
|
|
||||||
// Append new line in template like below
|
|
||||||
// <option name="run-test-as" value="1234" />
|
|
||||||
optionsMap := map[string]string{}
|
|
||||||
if test.Properties.Test_options != nil {
|
|
||||||
optionsMap["run-test-as"] = string(test.Properties.Test_options.Run_test_as)
|
|
||||||
}
|
|
||||||
|
|
||||||
test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
|
test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
|
||||||
test.Properties.Test_config_template, optionsMap)
|
test.Properties.Test_config_template)
|
||||||
|
|
||||||
test.binaryDecorator.baseInstaller.dir = "nativetest"
|
test.binaryDecorator.baseInstaller.dir = "nativetest"
|
||||||
test.binaryDecorator.baseInstaller.dir64 = "nativetest64"
|
test.binaryDecorator.baseInstaller.dir64 = "nativetest64"
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
package tradefed
|
package tradefed
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
@@ -37,10 +36,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' $template > $out &&" +
|
Command: "sed 's&{MODULE}&${name}&g' $template > $out",
|
||||||
"${optionCmd} $out",
|
|
||||||
CommandDeps: []string{"$template"},
|
CommandDeps: []string{"$template"},
|
||||||
}, "name", "template", "optionCmd")
|
}, "name", "template")
|
||||||
|
|
||||||
func testConfigPath(ctx android.ModuleContext, prop *string) (path android.Path, autogenPath android.WritablePath) {
|
func testConfigPath(ctx android.ModuleContext, prop *string) (path android.Path, autogenPath android.WritablePath) {
|
||||||
if p := getTestConfig(ctx, prop); p != nil {
|
if p := getTestConfig(ctx, prop); p != nil {
|
||||||
@@ -56,44 +54,30 @@ func testConfigPath(ctx android.ModuleContext, prop *string) (path android.Path,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, optionsMap map[string]string) {
|
func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template 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{
|
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": ctx.ModuleName(),
|
"name": ctx.ModuleName(),
|
||||||
"template": template,
|
"template": template,
|
||||||
"optionCmd": optionCmd,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string,
|
||||||
testConfigTemplateProp *string, optionsMap map[string]string) android.Path {
|
testConfigTemplateProp *string) android.Path {
|
||||||
path, autogenPath := testConfigPath(ctx, testConfigProp)
|
path, autogenPath := testConfigPath(ctx, testConfigProp)
|
||||||
if autogenPath != nil {
|
if autogenPath != nil {
|
||||||
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
||||||
if templatePath.Valid() {
|
if templatePath.Valid() {
|
||||||
autogenTemplate(ctx, autogenPath, templatePath.String(), optionsMap)
|
autogenTemplate(ctx, autogenPath, templatePath.String())
|
||||||
} else {
|
} else {
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}", optionsMap)
|
autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}")
|
||||||
} else {
|
} else {
|
||||||
autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}", optionsMap)
|
autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return autogenPath
|
return autogenPath
|
||||||
@@ -107,9 +91,9 @@ func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp
|
|||||||
if autogenPath != nil {
|
if autogenPath != nil {
|
||||||
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
||||||
if templatePath.Valid() {
|
if templatePath.Valid() {
|
||||||
autogenTemplate(ctx, autogenPath, templatePath.String(), nil)
|
autogenTemplate(ctx, autogenPath, templatePath.String())
|
||||||
} else {
|
} else {
|
||||||
autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}", nil)
|
autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}")
|
||||||
}
|
}
|
||||||
return autogenPath
|
return autogenPath
|
||||||
}
|
}
|
||||||
@@ -121,12 +105,12 @@ func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, te
|
|||||||
if autogenPath != nil {
|
if autogenPath != nil {
|
||||||
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
|
||||||
if templatePath.Valid() {
|
if templatePath.Valid() {
|
||||||
autogenTemplate(ctx, autogenPath, templatePath.String(), nil)
|
autogenTemplate(ctx, autogenPath, templatePath.String())
|
||||||
} else {
|
} else {
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}", nil)
|
autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}")
|
||||||
} else {
|
} else {
|
||||||
autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}", nil)
|
autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return autogenPath
|
return autogenPath
|
||||||
|
Reference in New Issue
Block a user