Add python template for mobly tests.
Mobly is a Python-based test framework that specializes in supporting
test cases that require multiple devices. There are some Mobly based
Android tests, but these tests cannot be added to xTS since they are
not using TF. Currently TF provides a 2-device Mobly test runner.
This change is a short-term solution to help teams (eg. bluetooth) to
add their multi-device Mobly tests to xTS without writing TF configs.
For long-term, device infra team and xTS infra team will provide a
solution for more complex multi-device tests in xTS and deprecate this
TF template.
Test: manually check the generated mobly xml config
Bug: 272239365
Change-Id: I252cc774094eebbd9264243d30023ace4839c2cd
diff --git a/python/test.go b/python/test.go
index fb8e918..31da17e 100644
--- a/python/test.go
+++ b/python/test.go
@@ -15,6 +15,8 @@
package python
import (
+ "fmt"
+
"github.com/google/blueprint/proptools"
"android/soong/android"
@@ -63,7 +65,22 @@
Java_data []string
// Test options.
- Test_options android.CommonTestOptions
+ Test_options TestOptions
+}
+
+type TestOptions struct {
+ android.CommonTestOptions
+
+ // Runner for the test. Supports "tradefed" and "mobly" (for multi-device tests). Default is "tradefed".
+ Runner *string
+
+ // Metadata to describe the test configuration.
+ Metadata []Metadata
+}
+
+type Metadata struct {
+ Name string
+ Value string
}
type PythonTestModule struct {
@@ -94,14 +111,41 @@
p.PythonLibraryModule.GenerateAndroidBuildActions(ctx)
p.buildBinary(ctx)
- p.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
- TestConfigProp: p.testProperties.Test_config,
- TestConfigTemplateProp: p.testProperties.Test_config_template,
- TestSuites: p.binaryProperties.Test_suites,
- AutoGenConfig: p.binaryProperties.Auto_gen_config,
- DeviceTemplate: "${PythonBinaryHostTestConfigTemplate}",
- HostTemplate: "${PythonBinaryHostTestConfigTemplate}",
- })
+ var configs []tradefed.Option
+ for _, metadata := range p.testProperties.Test_options.Metadata {
+ configs = append(configs, tradefed.Option{Name: "config-descriptor:metadata", Key: metadata.Name, Value: metadata.Value})
+ }
+
+ runner := proptools.StringDefault(p.testProperties.Test_options.Runner, "tradefed")
+ if runner == "tradefed" {
+ p.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
+ TestConfigProp: p.testProperties.Test_config,
+ TestConfigTemplateProp: p.testProperties.Test_config_template,
+ TestSuites: p.binaryProperties.Test_suites,
+ OptionsForAutogenerated: configs,
+ AutoGenConfig: p.binaryProperties.Auto_gen_config,
+ DeviceTemplate: "${PythonBinaryHostTestConfigTemplate}",
+ HostTemplate: "${PythonBinaryHostTestConfigTemplate}",
+ })
+ } else if runner == "mobly" {
+ if p.testProperties.Test_config != nil || p.testProperties.Test_config_template != nil || p.binaryProperties.Auto_gen_config != nil {
+ panic(fmt.Errorf("cannot set test_config, test_config_template or auto_gen_config for mobly test"))
+ }
+
+ for _, testSuite := range p.binaryProperties.Test_suites {
+ if testSuite == "cts" {
+ configs = append(configs, tradefed.Option{Name: "test-suite-tag", Value: "cts"})
+ break
+ }
+ }
+ p.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{
+ OptionsForAutogenerated: configs,
+ DeviceTemplate: "${PythonBinaryHostMoblyTestConfigTemplate}",
+ HostTemplate: "${PythonBinaryHostMoblyTestConfigTemplate}",
+ })
+ } else {
+ panic(fmt.Errorf("unknown python test runner '%s', should be 'tradefed' or 'mobly'", runner))
+ }
p.installedDest = ctx.InstallFile(installDir(ctx, "nativetest", "nativetest64", ctx.ModuleName()), p.installSource.Base(), p.installSource)