Add module name to sh_test install path.
This relands Ibb1d774709ea421e18d5350009c203f83c5b2d60 after fixing a backward compatibility issue where some test configs rely on sh_tests not having a module name in their paths when sub_dir is specified. Bug: 156980228 Test: m ziptool-tests Test: sh_binary_test.go Change-Id: If0521a008e7170d94b601f3df9dd0c12d1c96d21
This commit is contained in:
@@ -107,6 +107,8 @@ type ShTest struct {
|
|||||||
|
|
||||||
testProperties TestProperties
|
testProperties TestProperties
|
||||||
|
|
||||||
|
installDir android.InstallPath
|
||||||
|
|
||||||
data android.Paths
|
data android.Paths
|
||||||
testConfig android.Path
|
testConfig android.Path
|
||||||
}
|
}
|
||||||
@@ -176,13 +178,13 @@ func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
||||||
func(entries *android.AndroidMkEntries) {
|
func(entries *android.AndroidMkEntries) {
|
||||||
s.customAndroidMkEntries(entries)
|
s.customAndroidMkEntries(entries)
|
||||||
|
entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
|
func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) {
|
||||||
entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir))
|
|
||||||
entries.SetString("LOCAL_MODULE_SUFFIX", "")
|
entries.SetString("LOCAL_MODULE_SUFFIX", "")
|
||||||
entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
|
entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel())
|
||||||
if len(s.properties.Symlinks) > 0 {
|
if len(s.properties.Symlinks) > 0 {
|
||||||
@@ -201,8 +203,14 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
} else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
|
} else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
|
||||||
testDir = filepath.Join(testDir, ctx.Arch().ArchType.String())
|
testDir = filepath.Join(testDir, ctx.Arch().ArchType.String())
|
||||||
}
|
}
|
||||||
installDir := android.PathForModuleInstall(ctx, testDir, proptools.String(s.properties.Sub_dir))
|
if s.SubDir() != "" {
|
||||||
s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath)
|
// Don't add the module name to the installation path if sub_dir is specified for backward
|
||||||
|
// compatibility.
|
||||||
|
s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir())
|
||||||
|
} else {
|
||||||
|
s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name())
|
||||||
|
}
|
||||||
|
s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath)
|
||||||
|
|
||||||
s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
|
s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data)
|
||||||
|
|
||||||
@@ -229,7 +237,7 @@ func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
||||||
func(entries *android.AndroidMkEntries) {
|
func(entries *android.AndroidMkEntries) {
|
||||||
s.customAndroidMkEntries(entries)
|
s.customAndroidMkEntries(entries)
|
||||||
|
entries.SetPath("LOCAL_MODULE_PATH", s.installDir.ToMakePath())
|
||||||
entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
|
entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
|
||||||
if s.testConfig != nil {
|
if s.testConfig != nil {
|
||||||
entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
|
entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig)
|
||||||
|
@@ -55,7 +55,27 @@ func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config
|
|||||||
return ctx, config
|
return ctx, config
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShTestTestData(t *testing.T) {
|
func TestShTestSubDir(t *testing.T) {
|
||||||
|
ctx, config := testShBinary(t, `
|
||||||
|
sh_test {
|
||||||
|
name: "foo",
|
||||||
|
src: "test.sh",
|
||||||
|
sub_dir: "foo_test"
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest)
|
||||||
|
|
||||||
|
entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0]
|
||||||
|
|
||||||
|
expectedPath := "/tmp/target/product/test_device/data/nativetest64/foo_test"
|
||||||
|
actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0]
|
||||||
|
if expectedPath != actualPath {
|
||||||
|
t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestShTest(t *testing.T) {
|
||||||
ctx, config := testShBinary(t, `
|
ctx, config := testShBinary(t, `
|
||||||
sh_test {
|
sh_test {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
@@ -71,10 +91,17 @@ func TestShTestTestData(t *testing.T) {
|
|||||||
mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest)
|
mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest)
|
||||||
|
|
||||||
entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0]
|
entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0]
|
||||||
expected := []string{":testdata/data1", ":testdata/sub/data2"}
|
|
||||||
actual := entries.EntryMap["LOCAL_TEST_DATA"]
|
expectedPath := "/tmp/target/product/test_device/data/nativetest64/foo"
|
||||||
if !reflect.DeepEqual(expected, actual) {
|
actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0]
|
||||||
t.Errorf("Unexpected test data expected: %q, actual: %q", expected, actual)
|
if expectedPath != actualPath {
|
||||||
|
t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedData := []string{":testdata/data1", ":testdata/sub/data2"}
|
||||||
|
actualData := entries.EntryMap["LOCAL_TEST_DATA"]
|
||||||
|
if !reflect.DeepEqual(expectedData, actualData) {
|
||||||
|
t.Errorf("Unexpected test data expected: %q, actual: %q", expectedData, actualData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user