Overwrite test-file-name in test config.
If the install apk name is different than the module name, use
test_config_fixer to update the test-file-name value in the config.
Test: app_test.go
Fixes: 147375216
Change-Id: I2141eeebbb3552995400b45634712306673fd812
diff --git a/java/app.go b/java/app.go
index 7828a80..e9941f2 100755
--- a/java/app.go
+++ b/java/app.go
@@ -644,22 +644,40 @@
}
a.generateAndroidBuildActions(ctx)
- a.testConfig = tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config,
+ testConfig := tradefed.AutoGenInstrumentationTestConfig(ctx, a.testProperties.Test_config,
a.testProperties.Test_config_template, a.manifestPath, a.testProperties.Test_suites, a.testProperties.Auto_gen_config)
- if a.overridableAppProperties.Package_name != nil {
- fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", "AndroidTest.xml")
- rule := android.NewRuleBuilder()
- rule.Command().BuiltTool(ctx, "test_config_fixer").
- FlagWithInput("--manifest ", a.manifestPath).
- FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name).
- Input(a.testConfig).
- Output(fixedConfig)
- rule.Build(pctx, ctx, "fix_test_config", "fix test config")
- a.testConfig = fixedConfig
- }
+ a.testConfig = a.FixTestConfig(ctx, testConfig)
a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
}
+func (a *AndroidTest) FixTestConfig(ctx android.ModuleContext, testConfig android.Path) android.Path {
+ if testConfig == nil {
+ return nil
+ }
+
+ fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", "AndroidTest.xml")
+ rule := android.NewRuleBuilder()
+ command := rule.Command().BuiltTool(ctx, "test_config_fixer").Input(testConfig).Output(fixedConfig)
+ fixNeeded := false
+
+ if ctx.ModuleName() != a.installApkName {
+ fixNeeded = true
+ command.FlagWithArg("--test-file-name ", a.installApkName+".apk")
+ }
+
+ if a.overridableAppProperties.Package_name != nil {
+ fixNeeded = true
+ command.FlagWithInput("--manifest ", a.manifestPath).
+ FlagWithArg("--package-name ", *a.overridableAppProperties.Package_name)
+ }
+
+ if fixNeeded {
+ rule.Build(pctx, ctx, "fix_test_config", "fix test config")
+ return fixedConfig
+ }
+ return testConfig
+}
+
func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
a.AndroidApp.DepsMutator(ctx)
}