blob: 939e4bbb143595e0caa29afe3d1ae307aad2ecf9 [file] [log] [blame]
Kiyoung Kim62abd122020-10-06 17:16:44 +09001// 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
15package linkerconfig
16
17import (
Kiyoung Kim62abd122020-10-06 17:16:44 +090018 "os"
19 "reflect"
20 "testing"
Paul Duffin2a2fb662021-03-29 01:14:55 +010021
22 "android/soong/android"
Kiyoung Kim62abd122020-10-06 17:16:44 +090023)
24
Kiyoung Kim62abd122020-10-06 17:16:44 +090025func TestMain(m *testing.M) {
Paul Duffin2a2fb662021-03-29 01:14:55 +010026 os.Exit(m.Run())
Kiyoung Kim62abd122020-10-06 17:16:44 +090027}
28
Paul Duffin2a2fb662021-03-29 01:14:55 +010029var prepareForLinkerConfigTest = android.GroupFixturePreparers(
30 android.PrepareForTestWithAndroidBuildComponents,
31 android.FixtureRegisterWithContext(registerLinkerConfigBuildComponent),
32 android.FixtureAddFile("linker.config.json", nil),
33)
Kiyoung Kim62abd122020-10-06 17:16:44 +090034
35func TestBaseLinkerConfig(t *testing.T) {
Paul Duffin2a2fb662021-03-29 01:14:55 +010036 result := prepareForLinkerConfigTest.RunTestWithBp(t, `
37 linker_config {
38 name: "linker-config-base",
39 src: "linker.config.json",
40 }
Kiyoung Kim62abd122020-10-06 17:16:44 +090041 `)
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 Duffin2a2fb662021-03-29 01:14:55 +010049 p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig)
Kiyoung Kim62abd122020-10-06 17:16:44 +090050
51 if p.outputFilePath.Base() != "linker.config.pb" {
52 t.Errorf("expected linker.config.pb, got %q", p.outputFilePath.Base())
53 }
54
Paul Duffin2a2fb662021-03-29 01:14:55 +010055 entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0]
Kiyoung Kim62abd122020-10-06 17:16:44 +090056 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
71func TestUninstallableLinkerConfig(t *testing.T) {
Paul Duffin2a2fb662021-03-29 01:14:55 +010072 result := prepareForLinkerConfigTest.RunTestWithBp(t, `
73 linker_config {
74 name: "linker-config-base",
75 src: "linker.config.json",
76 installable: false,
77 }
Kiyoung Kim62abd122020-10-06 17:16:44 +090078 `)
79
80 expected := []string{"true"}
81
Paul Duffin2a2fb662021-03-29 01:14:55 +010082 p := result.ModuleForTests("linker-config-base", "android_arm64_armv8-a").Module().(*linkerConfig)
83 entries := android.AndroidMkEntriesForTest(t, result.TestContext, p)[0]
Kiyoung Kim62abd122020-10-06 17:16:44 +090084 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}