Merge "rust: Add require_root and vendor install base" am: eabde18653

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1832614

Change-Id: Iaac35523cc871995c525f066f4601ee3b7e2cd0f
This commit is contained in:
Ivan Lozano
2021-09-24 18:54:06 +00:00
committed by Automerger Merge Worker
2 changed files with 25 additions and 6 deletions

View File

@@ -59,6 +59,10 @@ type TestProperties struct {
// Test options.
Test_options TestOptions
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
// with root permission.
Require_root *bool
}
// A test module is a binary module with extra --test compiler flag
@@ -109,12 +113,27 @@ func (test *testDecorator) compilerProps() []interface{} {
}
func (test *testDecorator) install(ctx ModuleContext) {
testInstallBase := "/data/local/tests/unrestricted"
if ctx.RustModule().InVendor() || ctx.RustModule().UseVndk() {
testInstallBase = "/data/local/tests/vendor"
}
var configs []tradefed.Config
if Bool(test.Properties.Require_root) {
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil})
} else {
var options []tradefed.Option
options = append(options, tradefed.Option{Name: "force-root", Value: "false"})
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options})
}
test.testConfig = tradefed.AutoGenRustTestConfig(ctx,
test.Properties.Test_config,
test.Properties.Test_config_template,
test.Properties.Test_suites,
nil,
test.Properties.Auto_gen_config)
configs,
test.Properties.Auto_gen_config,
testInstallBase)
dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data)

View File

@@ -227,17 +227,17 @@ func AutoGenPythonBinaryHostTestConfig(ctx android.ModuleContext, testConfigProp
}
func AutoGenRustTestConfig(ctx android.ModuleContext, testConfigProp *string,
testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool) android.Path {
testConfigTemplateProp *string, testSuites []string, config []Config, autoGenConfig *bool, testInstallBase string) android.Path {
path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites, autoGenConfig, testConfigTemplateProp)
if autogenPath != nil {
templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
if templatePath.Valid() {
autogenTemplate(ctx, autogenPath, templatePath.String(), config, "")
autogenTemplate(ctx, autogenPath, templatePath.String(), config, testInstallBase)
} else {
if ctx.Device() {
autogenTemplate(ctx, autogenPath, "${RustDeviceTestConfigTemplate}", config, "")
autogenTemplate(ctx, autogenPath, "${RustDeviceTestConfigTemplate}", config, testInstallBase)
} else {
autogenTemplate(ctx, autogenPath, "${RustHostTestConfigTemplate}", config, "")
autogenTemplate(ctx, autogenPath, "${RustHostTestConfigTemplate}", config, testInstallBase)
}
}
return autogenPath