Merge "build device binary for java_test_host" am: af20c7cad1
am: a4a08a2bcb
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1957100 Change-Id: I1fe0c0b581272e2f2af213f2818acb954d321769
This commit is contained in:
commit
4a428735e9
4 changed files with 140 additions and 7 deletions
38
java/java.go
38
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}
|
||||
|
@ -831,6 +832,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 {
|
||||
|
@ -904,6 +908,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"})
|
||||
|
@ -918,14 +927,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)
|
||||
|
||||
|
@ -935,6 +965,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 {
|
||||
|
@ -967,7 +1001,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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue