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 := `