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) { |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 9 | config := TestArchConfig(buildDir, nil) |
| 10 | |
| 11 | ctx := NewTestArchContext() |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 12 | ctx.RegisterModuleType("sh_test", ShTestFactory) |
| 13 | ctx.RegisterModuleType("sh_test_host", ShTestHostFactory) |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 14 | 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 | |
| 30 | func 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 Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame^] | 45 | entries := AndroidMkEntriesForTest(t, config, "", mod)[0] |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 46 | 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 Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 52 | |
| 53 | func 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 | } |