Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 1 | package android |
| 2 | |
| 3 | import ( |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func testShBinary(t *testing.T, bp string) (*TestContext, Config) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame^] | 9 | fs := map[string][]byte{ |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 10 | "test.sh": nil, |
| 11 | "testdata/data1": nil, |
| 12 | "testdata/sub/data2": nil, |
| 13 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame^] | 14 | |
| 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 Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 21 | _, 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 | |
| 29 | func 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 Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 44 | entries := AndroidMkEntriesForTest(t, config, "", mod)[0] |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 45 | 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 Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 51 | |
| 52 | func 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 | } |