Merge "Add option test_min_api_level and test_min_sdk_version for auto-generated test config"
This commit is contained in:
commit
de8b140bf6
2 changed files with 44 additions and 10 deletions
34
cc/test.go
34
cc/test.go
|
@ -16,6 +16,7 @@ package cc
|
|||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
|
@ -71,6 +72,14 @@ type TestBinaryProperties struct {
|
|||
|
||||
// Add RunCommandTargetPreparer to stop framework before the test and start it after the test.
|
||||
Disable_framework *bool
|
||||
|
||||
// Add MinApiLevelModuleController to auto generated test config. If the device property of
|
||||
// "ro.product.first_api_level" < Test_min_api_level, then skip this module.
|
||||
Test_min_api_level *int64
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -314,19 +323,21 @@ func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|||
|
||||
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
||||
test.data = android.PathsForModuleSrc(ctx, test.Properties.Data)
|
||||
var api_level_prop string
|
||||
var configs []tradefed.Config
|
||||
var min_level string
|
||||
if Bool(test.Properties.Require_root) {
|
||||
configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
||||
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
||||
} else {
|
||||
var options []tradefed.Option
|
||||
options = append(options, tradefed.Option{"force-root", "false"})
|
||||
configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer", options})
|
||||
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
|
||||
}
|
||||
if Bool(test.Properties.Disable_framework) {
|
||||
var options []tradefed.Option
|
||||
options = append(options, tradefed.Option{"run-command", "stop"})
|
||||
options = append(options, tradefed.Option{"teardown-command", "start"})
|
||||
configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RunCommandTargetPreparer", options})
|
||||
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RunCommandTargetPreparer", options})
|
||||
}
|
||||
if Bool(test.testDecorator.Properties.Isolated) {
|
||||
configs = append(configs, tradefed.Option{"not-shardable", "true"})
|
||||
|
@ -334,6 +345,21 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
|
|||
if test.Properties.Test_options.Run_test_as != nil {
|
||||
configs = append(configs, tradefed.Option{"run-test-as", String(test.Properties.Test_options.Run_test_as)})
|
||||
}
|
||||
if test.Properties.Test_min_api_level != nil && test.Properties.Test_min_sdk_version != nil {
|
||||
ctx.PropertyErrorf("test_min_api_level", "'test_min_api_level' and 'test_min_sdk_version' should not be set at the same time.")
|
||||
} else if test.Properties.Test_min_api_level != nil {
|
||||
api_level_prop = "ro.product.first_api_level"
|
||||
min_level = strconv.FormatInt(int64(*test.Properties.Test_min_api_level), 10)
|
||||
} else if test.Properties.Test_min_sdk_version != nil {
|
||||
api_level_prop = "ro.build.version.sdk"
|
||||
min_level = strconv.FormatInt(int64(*test.Properties.Test_min_sdk_version), 10)
|
||||
}
|
||||
if api_level_prop != "" {
|
||||
var options []tradefed.Option
|
||||
options = append(options, tradefed.Option{"min-api-level", min_level})
|
||||
options = append(options, tradefed.Option{"api-level-prop", api_level_prop})
|
||||
configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.MinApiLevelModuleController", options})
|
||||
}
|
||||
|
||||
test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
|
||||
test.Properties.Test_config_template, test.Properties.Test_suites, configs)
|
||||
|
@ -461,7 +487,7 @@ func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Pat
|
|||
benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data)
|
||||
var configs []tradefed.Config
|
||||
if Bool(benchmark.Properties.Require_root) {
|
||||
configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer", nil})
|
||||
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)
|
||||
|
|
|
@ -73,26 +73,34 @@ func (o Option) Config() string {
|
|||
return fmt.Sprintf(`<option name="%s" value="%s" />`, o.Name, o.Value)
|
||||
}
|
||||
|
||||
type Preparer struct {
|
||||
// It can be a template of object or target_preparer.
|
||||
type Object struct {
|
||||
// Set it as a target_preparer if object type == "target_preparer".
|
||||
Type string
|
||||
Class string
|
||||
Options []Option
|
||||
}
|
||||
|
||||
var _ Config = Preparer{}
|
||||
var _ Config = Object{}
|
||||
|
||||
func (p Preparer) Config() string {
|
||||
func (ob Object) Config() string {
|
||||
var optionStrings []string
|
||||
for _, option := range p.Options {
|
||||
for _, option := range ob.Options {
|
||||
optionStrings = append(optionStrings, option.Config())
|
||||
}
|
||||
var options string
|
||||
if len(p.Options) == 0 {
|
||||
if len(ob.Options) == 0 {
|
||||
options = ""
|
||||
} else {
|
||||
optionDelimiter := fmt.Sprintf("\\n%s%s", test_xml_indent, test_xml_indent)
|
||||
options = optionDelimiter + strings.Join(optionStrings, optionDelimiter)
|
||||
}
|
||||
return fmt.Sprintf(`<target_preparer class="%s">%s\n%s</target_preparer>`, p.Class, options, test_xml_indent)
|
||||
if ob.Type == "target_preparer" {
|
||||
return fmt.Sprintf(`<target_preparer class="%s">%s\n%s</target_preparer>`, ob.Class, options, test_xml_indent)
|
||||
} else {
|
||||
return fmt.Sprintf(`<object type="%s" class="%s">%s\n%s</object>`, ob.Type, ob.Class, options, test_xml_indent)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, configs []Config) {
|
||||
|
|
Loading…
Reference in a new issue