Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 1 | // Copyright (C) 2020 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package linkerconfig |
| 16 | |
| 17 | import ( |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 18 | "os" |
| 19 | "reflect" |
| 20 | "testing" |
Paul Duffin | 2a2fb66 | 2021-03-29 01:14:55 +0100 | [diff] [blame] | 21 | |
| 22 | "android/soong/android" |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 23 | ) |
| 24 | |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 25 | func TestMain(m *testing.M) { |
Paul Duffin | 2a2fb66 | 2021-03-29 01:14:55 +0100 | [diff] [blame] | 26 | os.Exit(m.Run()) |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 27 | } |
| 28 | |
Paul Duffin | 2a2fb66 | 2021-03-29 01:14:55 +0100 | [diff] [blame] | 29 | var prepareForLinkerConfigTest = android.GroupFixturePreparers( |
| 30 | android.PrepareForTestWithAndroidBuildComponents, |
| 31 | android.FixtureRegisterWithContext(registerLinkerConfigBuildComponent), |
| 32 | android.FixtureAddFile("linker.config.json", nil), |
| 33 | ) |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 34 | |
| 35 | func TestBaseLinkerConfig(t *testing.T) { |
Paul Duffin | 2a2fb66 | 2021-03-29 01:14:55 +0100 | [diff] [blame] | 36 | result := prepareForLinkerConfigTest.RunTestWithBp(t, ` |
| 37 | linker_config { |
| 38 | name: "linker-config-base", |
| 39 | src: "linker.config.json", |
| 40 | } |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 41 | `) |
| 42 | |
| 43 | expected := map[string][]string{ |
| 44 | "LOCAL_MODULE": {"linker-config-base"}, |
| 45 | "LOCAL_MODULE_CLASS": {"ETC"}, |
| 46 | "LOCAL_INSTALLED_MODULE_STEM": {"linker.config.pb"}, |
| 47 | } |
| 48 | |
Paul Duffin | 2a2fb66 | 2021-03-29 01:14:55 +0100 | [diff] [blame] | 49 | p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 50 | |
| 51 | if p.outputFilePath.Base() != "linker.config.pb" { |
| 52 | t.Errorf("expected linker.config.pb, got %q", p.outputFilePath.Base()) |
| 53 | } |
| 54 | |
Paul Duffin | 2a2fb66 | 2021-03-29 01:14:55 +0100 | [diff] [blame] | 55 | entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0] |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 56 | for k, expectedValue := range expected { |
| 57 | if value, ok := entries.EntryMap[k]; ok { |
| 58 | if !reflect.DeepEqual(value, expectedValue) { |
| 59 | t.Errorf("Value of %s is '%s', but expected as '%s'", k, value, expectedValue) |
| 60 | } |
| 61 | } else { |
| 62 | t.Errorf("%s is not defined", k) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if value, ok := entries.EntryMap["LOCAL_UNINSTALLABLE_MODULE"]; ok { |
| 67 | t.Errorf("Value of LOCAL_UNINSTALLABLE_MODULE is %s, but expected as empty", value) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | func TestUninstallableLinkerConfig(t *testing.T) { |
Paul Duffin | 2a2fb66 | 2021-03-29 01:14:55 +0100 | [diff] [blame] | 72 | result := prepareForLinkerConfigTest.RunTestWithBp(t, ` |
| 73 | linker_config { |
| 74 | name: "linker-config-base", |
| 75 | src: "linker.config.json", |
| 76 | installable: false, |
| 77 | } |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 78 | `) |
| 79 | |
| 80 | expected := []string{"true"} |
| 81 | |
Paul Duffin | 2a2fb66 | 2021-03-29 01:14:55 +0100 | [diff] [blame] | 82 | p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig) |
| 83 | entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0] |
Kiyoung Kim | 62abd12 | 2020-10-06 17:16:44 +0900 | [diff] [blame] | 84 | if value, ok := entries.EntryMap["LOCAL_UNINSTALLABLE_MODULE"]; ok { |
| 85 | if !reflect.DeepEqual(value, expected) { |
| 86 | t.Errorf("LOCAL_UNINSTALLABLE_MODULE is expected to be true but %s", value) |
| 87 | } |
| 88 | } else { |
| 89 | t.Errorf("LOCAL_UNINSTALLABLE_MODULE is not defined") |
| 90 | } |
| 91 | } |