diff options
author | 2022-01-20 21:10:28 +0000 | |
---|---|---|
committer | 2022-01-26 19:57:27 +0000 | |
commit | b3342ce580c8211c5fd62b011711c4d149446d1b (patch) | |
tree | c13799af1166da07279e8ea96e3d6dbd92b80b01 | |
parent | 1e698865b5a0631af134eeefb65d93f9f5056523 (diff) |
build device binary for java_test_host
This commit adds support for a java_host_test that requires a target
binary to run. If the binary has host and target variants and is added
as a dependency in the `data` attribute, then the host variant is used.
Instead, we need a way to force the use of the target variant.
Bug: 182919153
Test: add code from aosp/1647282/1 && atest AuthFsHostTest
Change-Id: I68a6259b41a5e6809e1b82eec3122ffdf5067f56
-rw-r--r-- | java/java.go | 38 | ||||
-rw-r--r-- | java/java_test.go | 61 | ||||
-rw-r--r-- | sh/sh_binary_test.go | 38 | ||||
-rw-r--r-- | tradefed/autogen.go | 10 |
4 files changed, 140 insertions, 7 deletions
diff --git a/java/java.go b/java/java.go index bb7c32be8..bec440525 100644 --- a/java/java.go +++ b/java/java.go @@ -325,6 +325,7 @@ func IsJniDepTag(depTag blueprint.DependencyTag) bool { var ( dataNativeBinsTag = dependencyTag{name: "dataNativeBins"} + dataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} staticLibTag = dependencyTag{name: "staticlib"} libTag = dependencyTag{name: "javalib", runtimeLinked: true} java9LibTag = dependencyTag{name: "java9lib", runtimeLinked: true} @@ -837,6 +838,9 @@ type testProperties struct { type hostTestProperties struct { // list of native binary modules that should be installed alongside the test Data_native_bins []string `android:"arch_variant"` + + // list of device binary modules that should be installed alongside the test + Data_device_bins []string `android:"arch_variant"` } type testHelperLibraryProperties struct { @@ -910,6 +914,11 @@ func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) { } } + if len(j.testHostProperties.Data_device_bins) > 0 { + deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() + ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins...) + } + if len(j.testProperties.Jni_libs) > 0 { for _, target := range ctx.MultiTargets() { sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) @@ -924,14 +933,35 @@ func (j *TestHost) AddExtraResource(p android.Path) { j.extraResources = append(j.extraResources, p) } +func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) { + var configs []tradefed.Config + if len(j.testHostProperties.Data_device_bins) > 0 { + // add Tradefed configuration to push device bins to device for testing + remoteDir := filepath.Join("/data/local/tests/unrestricted/", j.Name()) + options := []tradefed.Option{{Name: "cleanup", Value: "true"}} + for _, bin := range j.testHostProperties.Data_device_bins { + fullPath := filepath.Join(remoteDir, bin) + options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: fullPath}) + } + configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options}) + } + + j.Test.generateAndroidBuildActionsWithConfig(ctx, configs) +} + func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { + j.generateAndroidBuildActionsWithConfig(ctx, nil) +} + +func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, configs []tradefed.Config) { if j.testProperties.Test_options.Unit_test == nil && ctx.Host() { // TODO(b/): Clean temporary heuristic to avoid unexpected onboarding. defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites) 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, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test) + j.testProperties.Test_suites, configs, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test) j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) @@ -941,6 +971,10 @@ func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) }) + ctx.VisitDirectDepsWithTag(dataDeviceBinsTag, func(dep android.Module) { + j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) + }) + ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) { sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo) if sharedLibInfo.SharedLibrary != nil { @@ -973,7 +1007,7 @@ 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) + j.prebuiltTestProperties.Test_suites, nil, nil, nil) j.Import.GenerateAndroidBuildActions(ctx) } diff --git a/java/java_test.go b/java/java_test.go index 3a51981e6..21c76b6c1 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1460,3 +1460,64 @@ func TestErrorproneEnabledOnlyByEnvironmentVariable(t *testing.T) { t.Errorf("expected errorprone to contain %q, got %q", expectedSubstring, javac.Args["javacFlags"]) } } + +func TestDataDeviceBinsBuildsDeviceBinary(t *testing.T) { + bp := ` + java_test_host { + name: "foo", + srcs: ["test.java"], + data_device_bins: ["bar"], + } + + cc_binary { + name: "bar", + } + ` + + ctx := android.GroupFixturePreparers( + PrepareForIntegrationTestWithJava, + ).RunTestWithBp(t, bp) + + buildOS := ctx.Config.BuildOS.String() + fooVariant := ctx.ModuleForTests("foo", buildOS+"_common") + barVariant := ctx.ModuleForTests("bar", "android_arm64_armv8-a") + fooMod := fooVariant.Module().(*TestHost) + + relocated := barVariant.Output("bar") + expectedInput := "out/soong/.intermediates/bar/android_arm64_armv8-a/unstripped/bar" + android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input) + + entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, fooMod)[0] + expectedData := []string{ + "out/soong/.intermediates/bar/android_arm64_armv8-a/bar:bar", + } + actualData := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"] + android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", ctx.Config, expectedData, actualData) +} + +func TestDataDeviceBinsAutogenTradefedConfig(t *testing.T) { + bp := ` + java_test_host { + name: "foo", + srcs: ["test.java"], + data_device_bins: ["bar"], + } + + cc_binary { + name: "bar", + } + ` + + ctx := android.GroupFixturePreparers( + PrepareForIntegrationTestWithJava, + ).RunTestWithBp(t, bp) + + buildOS := ctx.Config.BuildOS.String() + fooModule := ctx.ModuleForTests("foo", buildOS+"_common") + expectedAutogenConfig := `<option name="push-file" key="bar" value="/data/local/tests/unrestricted/foo/bar" />` + + autogen := fooModule.Rule("autogen") + if !strings.Contains(autogen.Args["extraConfigs"], expectedAutogenConfig) { + t.Errorf("foo extraConfigs %v does not contain %q", autogen.Args["extraConfigs"], expectedAutogenConfig) + } +} diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go index 28b6fb93a..7fe1d8538 100644 --- a/sh/sh_binary_test.go +++ b/sh/sh_binary_test.go @@ -4,6 +4,7 @@ import ( "os" "path/filepath" "strconv" + "strings" "testing" "android/soong/android" @@ -215,3 +216,40 @@ func TestShTestHost_dataDeviceModules(t *testing.T) { actualData := entries.EntryMap["LOCAL_TEST_DATA"] android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) } + +func TestShTestHost_dataDeviceModulesAutogenTradefedConfig(t *testing.T) { + ctx, config := testShBinary(t, ` + sh_test_host { + name: "foo", + src: "test.sh", + data_device_bins: ["bar"], + data_device_libs: ["libbar"], + } + + cc_binary { + name: "bar", + shared_libs: ["libbar"], + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + stl: "none", + } + + cc_library { + name: "libbar", + no_libcrt: true, + nocrt: true, + system_shared_libs: [], + stl: "none", + } + `) + + buildOS := config.BuildOS.String() + fooModule := ctx.ModuleForTests("foo", buildOS+"_x86_64") + + expectedBinAutogenConfig := `<option name="push-file" key="bar" value="/data/local/tests/unrestricted/foo/bar" />` + autogen := fooModule.Rule("autogen") + if !strings.Contains(autogen.Args["extraConfigs"], expectedBinAutogenConfig) { + t.Errorf("foo extraConfings %v does not contain %q", autogen.Args["extraConfigs"], expectedBinAutogenConfig) + } +} diff --git a/tradefed/autogen.go b/tradefed/autogen.go index da5582973..c2429ab7a 100644 --- a/tradefed/autogen.go +++ b/tradefed/autogen.go @@ -188,20 +188,20 @@ func AutoGenNativeBenchmarkTestConfig(ctx android.ModuleContext, testConfigProp } func AutoGenJavaTestConfig(ctx android.ModuleContext, testConfigProp *string, testConfigTemplateProp *string, - testSuites []string, autoGenConfig *bool, unitTest *bool) android.Path { + testSuites []string, config []Config, autoGenConfig *bool, unitTest *bool) 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(), nil, "") + autogenTemplate(ctx, autogenPath, templatePath.String(), config, "") } else { if ctx.Device() { - autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}", nil, "") + autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}", config, "") } else { if Bool(unitTest) { - autogenTemplate(ctx, autogenPath, "${JavaHostUnitTestConfigTemplate}", nil, "") + autogenTemplate(ctx, autogenPath, "${JavaHostUnitTestConfigTemplate}", config, "") } else { - autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}", nil, "") + autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}", config, "") } } } |