Merge "Migrate sh package to a per test build directory" am: a36d0dc2b7
am: dd7a42a321
am: 05a103c073
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1636432 Change-Id: I64dbecf93e17eb8ae34dba16aa4f964688864996
This commit is contained in:
commit
cdad455200
|
@ -1,44 +1,20 @@
|
|||
package sh
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"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) {
|
||||
run := func() int {
|
||||
setUp()
|
||||
defer tearDown()
|
||||
|
||||
return m.Run()
|
||||
}
|
||||
|
||||
os.Exit(run())
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
var shFixtureFactory = android.NewFixtureFactory(
|
||||
&buildDir,
|
||||
nil,
|
||||
cc.PrepareForTestWithCcBuildComponents,
|
||||
PrepareForTestWithShBuildComponents,
|
||||
android.FixtureMergeMockFs(android.MockFS{
|
||||
|
@ -66,7 +42,7 @@ func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config
|
|||
}
|
||||
|
||||
func TestShTestSubDir(t *testing.T) {
|
||||
ctx, _ := testShBinary(t, `
|
||||
ctx, config := testShBinary(t, `
|
||||
sh_test {
|
||||
name: "foo",
|
||||
src: "test.sh",
|
||||
|
@ -78,16 +54,13 @@ func TestShTestSubDir(t *testing.T) {
|
|||
|
||||
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
|
||||
|
||||
expectedPath := path.Join(buildDir,
|
||||
"../target/product/test_device/data/nativetest64/foo_test")
|
||||
expectedPath := "out/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)
|
||||
}
|
||||
android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", config, expectedPath, actualPath)
|
||||
}
|
||||
|
||||
func TestShTest(t *testing.T) {
|
||||
ctx, _ := testShBinary(t, `
|
||||
ctx, config := testShBinary(t, `
|
||||
sh_test {
|
||||
name: "foo",
|
||||
src: "test.sh",
|
||||
|
@ -103,22 +76,17 @@ func TestShTest(t *testing.T) {
|
|||
|
||||
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
|
||||
|
||||
expectedPath := path.Join(buildDir,
|
||||
"../target/product/test_device/data/nativetest64/foo")
|
||||
expectedPath := "out/target/product/test_device/data/nativetest64/foo"
|
||||
actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0]
|
||||
if expectedPath != actualPath {
|
||||
t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath)
|
||||
}
|
||||
android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", config, 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)
|
||||
}
|
||||
android.AssertDeepEquals(t, "LOCAL_TEST_DATA", expectedData, actualData)
|
||||
}
|
||||
|
||||
func TestShTest_dataModules(t *testing.T) {
|
||||
ctx, _ := testShBinary(t, `
|
||||
ctx, config := testShBinary(t, `
|
||||
sh_test {
|
||||
name: "foo",
|
||||
src: "test.sh",
|
||||
|
@ -157,22 +125,17 @@ func TestShTest_dataModules(t *testing.T) {
|
|||
libExt = ".dylib"
|
||||
}
|
||||
relocated := variant.Output("relocated/lib64/libbar" + libExt)
|
||||
expectedInput := filepath.Join(buildDir, ".intermediates/libbar/"+arch+"_shared/libbar"+libExt)
|
||||
if relocated.Input.String() != expectedInput {
|
||||
t.Errorf("Unexpected relocation input, expected: %q, actual: %q",
|
||||
expectedInput, relocated.Input.String())
|
||||
}
|
||||
expectedInput := "out/soong/.intermediates/libbar/" + arch + "_shared/libbar" + libExt
|
||||
android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
|
||||
|
||||
mod := variant.Module().(*ShTest)
|
||||
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
|
||||
expectedData := []string{
|
||||
filepath.Join(buildDir, ".intermediates/bar", arch, ":bar"),
|
||||
filepath.Join(buildDir, ".intermediates/foo", arch, "relocated/:lib64/libbar"+libExt),
|
||||
filepath.Join("out/soong/.intermediates/bar", arch, ":bar"),
|
||||
filepath.Join("out/soong/.intermediates/foo", arch, "relocated/:lib64/libbar"+libExt),
|
||||
}
|
||||
actualData := entries.EntryMap["LOCAL_TEST_DATA"]
|
||||
if !reflect.DeepEqual(expectedData, actualData) {
|
||||
t.Errorf("Unexpected test data, expected: %q, actual: %q", expectedData, actualData)
|
||||
}
|
||||
android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +160,7 @@ func TestShTestHost(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestShTestHost_dataDeviceModules(t *testing.T) {
|
||||
ctx, _ := testShBinary(t, `
|
||||
ctx, config := testShBinary(t, `
|
||||
sh_test_host {
|
||||
name: "foo",
|
||||
src: "test.sh",
|
||||
|
@ -227,21 +190,16 @@ func TestShTestHost_dataDeviceModules(t *testing.T) {
|
|||
variant := ctx.ModuleForTests("foo", buildOS+"_x86_64")
|
||||
|
||||
relocated := variant.Output("relocated/lib64/libbar.so")
|
||||
expectedInput := filepath.Join(buildDir, ".intermediates/libbar/android_arm64_armv8-a_shared/libbar.so")
|
||||
if relocated.Input.String() != expectedInput {
|
||||
t.Errorf("Unexpected relocation input, expected: %q, actual: %q",
|
||||
expectedInput, relocated.Input.String())
|
||||
}
|
||||
expectedInput := "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so"
|
||||
android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
|
||||
|
||||
mod := variant.Module().(*ShTest)
|
||||
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
|
||||
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.
|
||||
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"]
|
||||
if !reflect.DeepEqual(expectedData, actualData) {
|
||||
t.Errorf("Unexpected test data, expected: %q, actual: %q", expectedData, actualData)
|
||||
}
|
||||
android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue