aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorfrankfeng <frankfeng@google.com>2020-06-03 10:28:47 -0700
committerfrankfeng <frankfeng@google.com>2020-06-04 10:37:14 -0700
commitc5b8749853890d973ca56f87262dc277b06bc984 (patch)
tree00ab228d325db4aafab3974cb9e0f5af7803bd0c /sh
parent264700345dfe8a29abb41954bdf027099203a14e (diff)
downloadsoong-c5b8749853890d973ca56f87262dc277b06bc984.tar.gz
Implement test config auto-gen for sh_test.
Supports the following properties: - Require_root - Test_config_template - Auto_gen_config Test config template is in a separate CL. Bug: 148805488 Bug: 151761373 Test: make Test: unit tests Test: verified with bc_test & toybox-tests Change-Id: I63d60a153a6abda4ce30b74d3eb915fbf6389cb8
Diffstat (limited to 'sh')
-rw-r--r--sh/Android.bp1
-rw-r--r--sh/sh_binary.go37
2 files changed, 36 insertions, 2 deletions
diff --git a/sh/Android.bp b/sh/Android.bp
index 0b04e7dea..0f40c5f68 100644
--- a/sh/Android.bp
+++ b/sh/Android.bp
@@ -5,6 +5,7 @@ bootstrap_go_package {
"blueprint",
"soong",
"soong-android",
+ "soong-tradefed",
],
srcs: [
"sh_binary.go",
diff --git a/sh/sh_binary.go b/sh/sh_binary.go
index 2dcd7162c..9276a62e9 100644
--- a/sh/sh_binary.go
+++ b/sh/sh_binary.go
@@ -22,6 +22,7 @@ import (
"github.com/google/blueprint/proptools"
"android/soong/android"
+ "android/soong/tradefed"
)
// sh_binary is for shell scripts (and batch files) that are installed as
@@ -74,6 +75,19 @@ type TestProperties struct {
// list of files or filegroup modules that provide data that should be installed alongside
// the test.
Data []string `android:"path,arch_variant"`
+
+ // Add RootTargetPreparer to auto generated test config. This guarantees the test to run
+ // with root permission.
+ Require_root *bool
+
+ // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
+ // should be installed with the module.
+ Test_config_template *string `android:"path,arch_variant"`
+
+ // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
+ // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
+ // explicitly.
+ Auto_gen_config *bool
}
type ShBinary struct {
@@ -93,7 +107,8 @@ type ShTest struct {
testProperties TestProperties
- data android.Paths
+ data android.Paths
+ testConfig android.Path
}
func (s *ShBinary) HostToolPath() android.OptionalPath {
@@ -190,6 +205,16 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
+
+ var configs []tradefed.Config
+ if Bool(s.testProperties.Require_root) {
+ configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
+ } else {
+ options := []tradefed.Option{{Name: "force-root", Value: "false"}}
+ configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
+ }
+ s.testConfig = tradefed.AutoGenShellTestConfig(ctx, s.testProperties.Test_config,
+ s.testProperties.Test_config_template, s.testProperties.Test_suites, configs, s.testProperties.Auto_gen_config, s.outputFilePath.Base())
}
func (s *ShTest) InstallInData() bool {
@@ -206,7 +231,13 @@ func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
s.customAndroidMkEntries(entries)
entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
- entries.SetString("LOCAL_TEST_CONFIG", proptools.String(s.testProperties.Test_config))
+ if s.testProperties.Test_config != nil {
+ entries.SetString("LOCAL_TEST_CONFIG", proptools.String(s.testProperties.Test_config))
+ } else {
+ if s.testConfig != nil {
+ entries.SetString("LOCAL_FULL_TEST_CONFIG", s.testConfig.String())
+ }
+ }
for _, d := range s.data {
rel := d.Rel()
path := d.String()
@@ -265,3 +296,5 @@ func ShTestHostFactory() android.Module {
android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
return module
}
+
+var Bool = proptools.Bool