Migrate sh package to a per test build directory

Bug: 182885307
Test: m nothing
Change-Id: I8e379c555e48ab482c56a19630d83a3a54126fc5
This commit is contained in:
Paul Duffin 2021-03-16 07:50:37 +00:00
parent 5f9f771dab
commit 32b06c2ae6
1 changed files with 21 additions and 63 deletions

View File

@ -1,44 +1,20 @@
package sh package sh
import ( import (
"io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"reflect"
"testing" "testing"
"android/soong/android" "android/soong/android"
"android/soong/cc" "android/soong/cc"
) )
var buildDir string
func setUp() {
var err error
buildDir, err = ioutil.TempDir("", "soong_sh_test")
if err != nil {
panic(err)
}
}
func tearDown() {
os.RemoveAll(buildDir)
}
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
run := func() int { os.Exit(m.Run())
setUp()
defer tearDown()
return m.Run()
}
os.Exit(run())
} }
var shFixtureFactory = android.NewFixtureFactory( var shFixtureFactory = android.NewFixtureFactory(
&buildDir, nil,
cc.PrepareForTestWithCcBuildComponents, cc.PrepareForTestWithCcBuildComponents,
PrepareForTestWithShBuildComponents, PrepareForTestWithShBuildComponents,
android.FixtureMergeMockFs(android.MockFS{ android.FixtureMergeMockFs(android.MockFS{
@ -66,7 +42,7 @@ func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config
} }
func TestShTestSubDir(t *testing.T) { func TestShTestSubDir(t *testing.T) {
ctx, _ := testShBinary(t, ` ctx, config := testShBinary(t, `
sh_test { sh_test {
name: "foo", name: "foo",
src: "test.sh", src: "test.sh",
@ -78,16 +54,13 @@ func TestShTestSubDir(t *testing.T) {
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
expectedPath := path.Join(buildDir, expectedPath := "out/target/product/test_device/data/nativetest64/foo_test"
"../target/product/test_device/data/nativetest64/foo_test")
actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0] actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0]
if expectedPath != actualPath { android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", config, expectedPath, actualPath)
t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath)
}
} }
func TestShTest(t *testing.T) { func TestShTest(t *testing.T) {
ctx, _ := testShBinary(t, ` ctx, config := testShBinary(t, `
sh_test { sh_test {
name: "foo", name: "foo",
src: "test.sh", src: "test.sh",
@ -103,22 +76,17 @@ func TestShTest(t *testing.T) {
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
expectedPath := path.Join(buildDir, expectedPath := "out/target/product/test_device/data/nativetest64/foo"
"../target/product/test_device/data/nativetest64/foo")
actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0] actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0]
if expectedPath != actualPath { android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", config, expectedPath, actualPath)
t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath)
}
expectedData := []string{":testdata/data1", ":testdata/sub/data2"} expectedData := []string{":testdata/data1", ":testdata/sub/data2"}
actualData := entries.EntryMap["LOCAL_TEST_DATA"] actualData := entries.EntryMap["LOCAL_TEST_DATA"]
if !reflect.DeepEqual(expectedData, actualData) { android.AssertDeepEquals(t, "LOCAL_TEST_DATA", expectedData, actualData)
t.Errorf("Unexpected test data expected: %q, actual: %q", expectedData, actualData)
}
} }
func TestShTest_dataModules(t *testing.T) { func TestShTest_dataModules(t *testing.T) {
ctx, _ := testShBinary(t, ` ctx, config := testShBinary(t, `
sh_test { sh_test {
name: "foo", name: "foo",
src: "test.sh", src: "test.sh",
@ -157,22 +125,17 @@ func TestShTest_dataModules(t *testing.T) {
libExt = ".dylib" libExt = ".dylib"
} }
relocated := variant.Output("relocated/lib64/libbar" + libExt) relocated := variant.Output("relocated/lib64/libbar" + libExt)
expectedInput := filepath.Join(buildDir, ".intermediates/libbar/"+arch+"_shared/libbar"+libExt) expectedInput := "out/soong/.intermediates/libbar/" + arch + "_shared/libbar" + libExt
if relocated.Input.String() != expectedInput { android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
t.Errorf("Unexpected relocation input, expected: %q, actual: %q",
expectedInput, relocated.Input.String())
}
mod := variant.Module().(*ShTest) mod := variant.Module().(*ShTest)
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
expectedData := []string{ expectedData := []string{
filepath.Join(buildDir, ".intermediates/bar", arch, ":bar"), filepath.Join("out/soong/.intermediates/bar", arch, ":bar"),
filepath.Join(buildDir, ".intermediates/foo", arch, "relocated/:lib64/libbar"+libExt), filepath.Join("out/soong/.intermediates/foo", arch, "relocated/:lib64/libbar"+libExt),
} }
actualData := entries.EntryMap["LOCAL_TEST_DATA"] actualData := entries.EntryMap["LOCAL_TEST_DATA"]
if !reflect.DeepEqual(expectedData, actualData) { android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData)
t.Errorf("Unexpected test data, expected: %q, actual: %q", expectedData, actualData)
}
} }
} }
@ -197,7 +160,7 @@ func TestShTestHost(t *testing.T) {
} }
func TestShTestHost_dataDeviceModules(t *testing.T) { func TestShTestHost_dataDeviceModules(t *testing.T) {
ctx, _ := testShBinary(t, ` ctx, config := testShBinary(t, `
sh_test_host { sh_test_host {
name: "foo", name: "foo",
src: "test.sh", src: "test.sh",
@ -227,21 +190,16 @@ func TestShTestHost_dataDeviceModules(t *testing.T) {
variant := ctx.ModuleForTests("foo", buildOS+"_x86_64") variant := ctx.ModuleForTests("foo", buildOS+"_x86_64")
relocated := variant.Output("relocated/lib64/libbar.so") relocated := variant.Output("relocated/lib64/libbar.so")
expectedInput := filepath.Join(buildDir, ".intermediates/libbar/android_arm64_armv8-a_shared/libbar.so") expectedInput := "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so"
if relocated.Input.String() != expectedInput { android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
t.Errorf("Unexpected relocation input, expected: %q, actual: %q",
expectedInput, relocated.Input.String())
}
mod := variant.Module().(*ShTest) mod := variant.Module().(*ShTest)
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
expectedData := []string{ expectedData := []string{
filepath.Join(buildDir, ".intermediates/bar/android_arm64_armv8-a/:bar"), "out/soong/.intermediates/bar/android_arm64_armv8-a/:bar",
// libbar has been relocated, and so has a variant that matches the host arch. // libbar has been relocated, and so has a variant that matches the host arch.
filepath.Join(buildDir, ".intermediates/foo/"+buildOS+"_x86_64/relocated/:lib64/libbar.so"), "out/soong/.intermediates/foo/" + buildOS + "_x86_64/relocated/:lib64/libbar.so",
} }
actualData := entries.EntryMap["LOCAL_TEST_DATA"] actualData := entries.EntryMap["LOCAL_TEST_DATA"]
if !reflect.DeepEqual(expectedData, actualData) { android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData)
t.Errorf("Unexpected test data, expected: %q, actual: %q", expectedData, actualData)
}
} }