blob: 137e77348c117ee13113a5fd67446f21d120d753 [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) {
Colin Cross98be1bb2019-12-13 20:41:13 -08009 fs := map[string][]byte{
Jaewoong Jung8eaeb092019-05-16 14:58:29 -070010 "test.sh": nil,
11 "testdata/data1": nil,
12 "testdata/sub/data2": nil,
13 }
Colin Cross98be1bb2019-12-13 20:41:13 -080014
15 config := TestArchConfig(buildDir, nil, bp, fs)
16
17 ctx := NewTestArchContext()
18 ctx.RegisterModuleType("sh_test", ShTestFactory)
19 ctx.RegisterModuleType("sh_test_host", ShTestHostFactory)
20 ctx.Register(config)
Jaewoong Jung8eaeb092019-05-16 14:58:29 -070021 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
22 FailIfErrored(t, errs)
23 _, errs = ctx.PrepareBuildActions(config)
24 FailIfErrored(t, errs)
25
26 return ctx, config
27}
28
29func TestShTestTestData(t *testing.T) {
30 ctx, config := testShBinary(t, `
31 sh_test {
32 name: "foo",
33 src: "test.sh",
34 filename: "test.sh",
35 data: [
36 "testdata/data1",
37 "testdata/sub/data2",
38 ],
39 }
40 `)
41
42 mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest)
43
Jiyong Park0b0e1b92019-12-03 13:24:29 +090044 entries := AndroidMkEntriesForTest(t, config, "", mod)[0]
Jaewoong Jung8eaeb092019-05-16 14:58:29 -070045 expected := []string{":testdata/data1", ":testdata/sub/data2"}
46 actual := entries.EntryMap["LOCAL_TEST_DATA"]
47 if !reflect.DeepEqual(expected, actual) {
48 t.Errorf("Unexpected test data expected: %q, actual: %q", expected, actual)
49 }
50}
Jaewoong Jung61a83682019-07-01 09:08:50 -070051
52func TestShTestHost(t *testing.T) {
53 ctx, _ := testShBinary(t, `
54 sh_test_host {
55 name: "foo",
56 src: "test.sh",
57 filename: "test.sh",
58 data: [
59 "testdata/data1",
60 "testdata/sub/data2",
61 ],
62 }
63 `)
64
65 buildOS := BuildOs.String()
66 mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest)
67 if !mod.Host() {
68 t.Errorf("host bit is not set for a sh_test_host module.")
69 }
70}