Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ec823cb authored by Cole Faust's avatar Cole Faust
Browse files

Allow adding extra tradefed options in the Android.bp file

Some tests need to add custom tradefed options, but still want to
keep most of the soong autogenerated tradefed xml file.

Expose a test_options: { tradefed_options: [...] } property that
will allow tests to add more options to the autogenerated xml file.

Fixes: 184895128
Test: go test, and verified that the ninja files did not change for aosp_arm64
Change-Id: I75f7eb002c8325ce7cdc76e12e76e16195320620
parent 3784d144
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import (
	"text/scanner"

	"android/soong/bazel"

	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
)
+19 −4
Original line number Diff line number Diff line
@@ -459,8 +459,16 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
		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.testDecorator.InstallerProperties.Test_suites, configs, test.Properties.Auto_gen_config, testInstallBase)
	test.testConfig = tradefed.NewMaybeAutoGenTestConfigBuilder(ctx).
		SetTestConfigProp(test.Properties.Test_config).
		SetTestTemplateConfigProp(test.Properties.Test_config_template).
		SetTestSuites(test.testDecorator.InstallerProperties.Test_suites).
		SetConfig(configs).
		SetAutoGenConfig(test.Properties.Auto_gen_config).
		SetTestInstallBase(testInstallBase).
		SetDeviceTemplate("${NativeTestConfigTemplate}").
		SetHostTemplate("${NativeHostTestConfigTemplate}").
		Build()

	test.extraTestConfigs = android.PathsForModuleSrc(ctx, test.Properties.Test_options.Extra_test_configs)

@@ -616,8 +624,15 @@ func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Pat
	if Bool(benchmark.Properties.Require_root) {
		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, benchmark.Properties.Auto_gen_config)
	benchmark.testConfig = tradefed.NewMaybeAutoGenTestConfigBuilder(ctx).
		SetTestConfigProp(benchmark.Properties.Test_config).
		SetTestTemplateConfigProp(benchmark.Properties.Test_config_template).
		SetTestSuites(benchmark.Properties.Test_suites).
		SetConfig(configs).
		SetAutoGenConfig(benchmark.Properties.Auto_gen_config).
		SetDeviceTemplate("${NativeBenchmarkTestConfigTemplate}").
		SetHostTemplate("${NativeBenchmarkTestConfigTemplate}").
		Build()

	benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName())
	benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName())
+23 −4
Original line number Diff line number Diff line
@@ -888,6 +888,10 @@ type TestOptions struct {

	// a list of extra test configuration files that should be installed with the module.
	Extra_test_configs []string `android:"path,arch_variant"`

	// Extra <option> tags to add to the auto generated test xml file. The "key"
	// is optional in each of these.
	Tradefed_options []tradefed.Option
}

type testProperties struct {
@@ -1166,8 +1170,18 @@ func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext,
		j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest)
	}

	j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
		j.testProperties.Test_suites, configs, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test)
	j.testConfig = tradefed.NewMaybeAutoGenTestConfigBuilder(ctx).
		SetTestConfigProp(j.testProperties.Test_config).
		SetTestTemplateConfigProp(j.testProperties.Test_config_template).
		SetTestSuites(j.testProperties.Test_suites).
		SetConfig(configs).
		SetOptionsForAutogenerated(j.testProperties.Test_options.Tradefed_options).
		SetAutoGenConfig(j.testProperties.Auto_gen_config).
		SetUnitTest(j.testProperties.Test_options.Unit_test).
		SetDeviceTemplate("${JavaTestConfigTemplate}").
		SetHostTemplate("${JavaHostTestConfigTemplate}").
		SetHostUnitTestTemplate("${JavaHostUnitTestConfigTemplate}").
		Build()

	j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)

@@ -1212,8 +1226,13 @@ func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContex
}

func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
		j.prebuiltTestProperties.Test_suites, nil, nil, nil)
	j.testConfig = tradefed.NewMaybeAutoGenTestConfigBuilder(ctx).
		SetTestConfigProp(j.prebuiltTestProperties.Test_config).
		SetTestSuites(j.prebuiltTestProperties.Test_suites).
		SetDeviceTemplate("${JavaTestConfigTemplate}").
		SetHostTemplate("${JavaHostTestConfigTemplate}").
		SetHostUnitTestTemplate("${JavaHostUnitTestConfigTemplate}").
		Build()

	j.Import.GenerateAndroidBuildActions(ctx)
}
+22 −0
Original line number Diff line number Diff line
@@ -1945,3 +1945,25 @@ func TestJavaApiLibraryJarGeneration(t *testing.T) {
		}
	}
}

func TestTradefedOptions(t *testing.T) {
	result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, `
java_test_host {
	name: "foo",
	test_options: {
		tradefed_options: [
			{
				name: "exclude-path",
				value: "org/apache"
			}
		]
	}
}
`)
	args := result.ModuleForTests("foo", "linux_glibc_common").
		Output("out/soong/.intermediates/foo/linux_glibc_common/foo.config").Args
	expected := proptools.NinjaAndShellEscape("<option name=\"exclude-path\" value=\"org/apache\" />")
	if args["extraConfigs"] != expected {
		t.Errorf("Expected args[\"extraConfigs\"] to equal %q, was %q", expected, args["extraConfigs"])
	}
}
+8 −3
Original line number Diff line number Diff line
@@ -131,9 +131,14 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext)
	r.forceOSType = ctx.Config().BuildOS
	r.forceArchType = ctx.Config().BuildArch

	r.testConfig = tradefed.AutoGenRobolectricTestConfig(ctx, r.testProperties.Test_config,
		r.testProperties.Test_config_template, r.testProperties.Test_suites,
		r.testProperties.Auto_gen_config)
	r.testConfig = tradefed.NewMaybeAutoGenTestConfigBuilder(ctx).
		SetTestConfigProp(r.testProperties.Test_config).
		SetTestTemplateConfigProp(r.testProperties.Test_config_template).
		SetTestSuites(r.testProperties.Test_suites).
		SetAutoGenConfig(r.testProperties.Auto_gen_config).
		SetDeviceTemplate("${RobolectricTestConfigTemplate}").
		SetHostTemplate("${RobolectricTestConfigTemplate}").
		Build()
	r.data = android.PathsForModuleSrc(ctx, r.testProperties.Data)

	roboTestConfig := android.PathForModuleGen(ctx, "robolectric").
Loading