2019-05-16 23:58:29 +02:00
|
|
|
package android
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testShBinary(t *testing.T, bp string) (*TestContext, Config) {
|
2019-12-14 05:41:13 +01:00
|
|
|
fs := map[string][]byte{
|
2019-05-16 23:58:29 +02:00
|
|
|
"test.sh": nil,
|
|
|
|
"testdata/data1": nil,
|
|
|
|
"testdata/sub/data2": nil,
|
|
|
|
}
|
2019-12-14 05:41:13 +01:00
|
|
|
|
|
|
|
config := TestArchConfig(buildDir, nil, bp, fs)
|
|
|
|
|
|
|
|
ctx := NewTestArchContext()
|
|
|
|
ctx.RegisterModuleType("sh_test", ShTestFactory)
|
|
|
|
ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
|
|
|
|
ctx.Register(config)
|
2019-05-16 23:58:29 +02:00
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
|
|
FailIfErrored(t, errs)
|
|
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
|
|
FailIfErrored(t, errs)
|
|
|
|
|
|
|
|
return ctx, config
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShTestTestData(t *testing.T) {
|
|
|
|
ctx, config := testShBinary(t, `
|
|
|
|
sh_test {
|
|
|
|
name: "foo",
|
|
|
|
src: "test.sh",
|
|
|
|
filename: "test.sh",
|
|
|
|
data: [
|
|
|
|
"testdata/data1",
|
|
|
|
"testdata/sub/data2",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest)
|
|
|
|
|
2019-12-03 05:24:29 +01:00
|
|
|
entries := AndroidMkEntriesForTest(t, config, "", mod)[0]
|
2019-05-16 23:58:29 +02:00
|
|
|
expected := []string{":testdata/data1", ":testdata/sub/data2"}
|
|
|
|
actual := entries.EntryMap["LOCAL_TEST_DATA"]
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
|
|
|
t.Errorf("Unexpected test data expected: %q, actual: %q", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
2019-07-01 18:08:50 +02:00
|
|
|
|
|
|
|
func TestShTestHost(t *testing.T) {
|
|
|
|
ctx, _ := testShBinary(t, `
|
|
|
|
sh_test_host {
|
|
|
|
name: "foo",
|
|
|
|
src: "test.sh",
|
|
|
|
filename: "test.sh",
|
|
|
|
data: [
|
|
|
|
"testdata/data1",
|
|
|
|
"testdata/sub/data2",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
buildOS := BuildOs.String()
|
|
|
|
mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest)
|
|
|
|
if !mod.Host() {
|
|
|
|
t.Errorf("host bit is not set for a sh_test_host module.")
|
|
|
|
}
|
|
|
|
}
|