blob: 8488fe493a1f4fd7778bf174f2a4137674da3973 [file] [log] [blame]
Jaewoong Jung8eaeb092019-05-16 14:58:29 -07001package android
2
3import (
Jaewoong Jung8eaeb092019-05-16 14:58:29 -07004 "reflect"
5 "testing"
6)
7
8func testShBinary(t *testing.T, bp string) (*TestContext, Config) {
Jaewoong Jung8eaeb092019-05-16 14:58:29 -07009 config := TestArchConfig(buildDir, nil)
10
11 ctx := NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -080012 ctx.RegisterModuleType("sh_test", ShTestFactory)
13 ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -070014 ctx.Register()
15 mockFiles := map[string][]byte{
16 "Android.bp": []byte(bp),
17 "test.sh": nil,
18 "testdata/data1": nil,
19 "testdata/sub/data2": nil,
20 }
21 ctx.MockFileSystem(mockFiles)
22 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
23 FailIfErrored(t, errs)
24 _, errs = ctx.PrepareBuildActions(config)
25 FailIfErrored(t, errs)
26
27 return ctx, config
28}
29
30func TestShTestTestData(t *testing.T) {
31 ctx, config := testShBinary(t, `
32 sh_test {
33 name: "foo",
34 src: "test.sh",
35 filename: "test.sh",
36 data: [
37 "testdata/data1",
38 "testdata/sub/data2",
39 ],
40 }
41 `)
42
43 mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest)
44
Jiyong Park0b0e1b92019-12-03 13:24:29 +090045 entries := AndroidMkEntriesForTest(t, config, "", mod)[0]
Jaewoong Jung8eaeb092019-05-16 14:58:29 -070046 expected := []string{":testdata/data1", ":testdata/sub/data2"}
47 actual := entries.EntryMap["LOCAL_TEST_DATA"]
48 if !reflect.DeepEqual(expected, actual) {
49 t.Errorf("Unexpected test data expected: %q, actual: %q", expected, actual)
50 }
51}
Jaewoong Jung61a83682019-07-01 09:08:50 -070052
53func TestShTestHost(t *testing.T) {
54 ctx, _ := testShBinary(t, `
55 sh_test_host {
56 name: "foo",
57 src: "test.sh",
58 filename: "test.sh",
59 data: [
60 "testdata/data1",
61 "testdata/sub/data2",
62 ],
63 }
64 `)
65
66 buildOS := BuildOs.String()
67 mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest)
68 if !mod.Host() {
69 t.Errorf("host bit is not set for a sh_test_host module.")
70 }
71}