1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "linkerconfig/baseconfig.h"
18 #include "configurationtest.h"
19 #include "linkerconfig/configwriter.h"
20 #include "mockenv.h"
21
22 using android::linkerconfig::contents::Context;
23 using android::linkerconfig::contents::CreateBaseConfiguration;
24 using android::linkerconfig::modules::ApexInfo;
25 using android::linkerconfig::modules::ConfigWriter;
26
TEST(linkerconfig_configuration_fulltest,baseconfig_test)27 TEST(linkerconfig_configuration_fulltest, baseconfig_test) {
28 MockGenericVariables();
29 Context ctx = GenerateContextWithVndk();
30 auto base_config = CreateBaseConfiguration(ctx);
31 ConfigWriter config_writer;
32
33 base_config.WriteConfig(config_writer);
34
35 VerifyConfiguration(config_writer.ToString());
36 }
37
TEST(linkerconfig_configuration_fulltest,baseconfig_vndk_using_core_variant_test)38 TEST(linkerconfig_configuration_fulltest,
39 baseconfig_vndk_using_core_variant_test) {
40 MockGenericVariables();
41 MockVndkUsingCoreVariant();
42 Context ctx = GenerateContextWithVndk();
43 auto base_config = CreateBaseConfiguration(ctx);
44 ConfigWriter config_writer;
45
46 base_config.WriteConfig(config_writer);
47
48 VerifyConfiguration(config_writer.ToString());
49 }
50
TEST(linkerconfig_configuration_fulltest,baseconfig_vndk_27_test)51 TEST(linkerconfig_configuration_fulltest, baseconfig_vndk_27_test) {
52 MockGenericVariables();
53 MockVndkVersion("27");
54 Context ctx = GenerateContextWithVndk();
55 auto base_config = CreateBaseConfiguration(ctx);
56 ConfigWriter config_writer;
57
58 base_config.WriteConfig(config_writer);
59
60 VerifyConfiguration(config_writer.ToString());
61 }
62
TEST(linkerconfig_configuration_fulltest,apexes_with_jni_are_visible_to_system_section)63 TEST(linkerconfig_configuration_fulltest,
64 apexes_with_jni_are_visible_to_system_section) {
65 MockGenericVariables();
66 Context ctx;
67 ctx.AddApexModule(ApexInfo(
68 "foo", "", {}, {}, {"libjni.so"}, {}, {}, false, true, false, false));
69 auto config = CreateBaseConfiguration(ctx);
70
71 auto* section = config.GetSection("system");
72 ASSERT_TRUE(section);
73 auto* ns = section->GetNamespace("foo");
74 ASSERT_TRUE(ns);
75 ASSERT_TRUE(ns->IsVisible());
76
77 ConfigWriter config_writer;
78 config.WriteConfig(config_writer);
79 VerifyConfiguration(config_writer.ToString());
80 }
81
TEST(linkerconfig_configuration_fulltest,vendor_apex_configured_to_use_vndk_can_load_vndk)82 TEST(linkerconfig_configuration_fulltest,
83 vendor_apex_configured_to_use_vndk_can_load_vndk) {
84 MockGenericVariables();
85 Context ctx;
86
87 android::linkerconfig::proto::LinkerConfig vendor_config;
88 vendor_config.add_requirelibs("libapexprovide.so");
89 vendor_config.add_providelibs("libvendorprovide.so");
90 ctx.SetVendorConfig(vendor_config);
91
92 // Vendor apex requires :vndk
93 auto vendor_apex = ApexInfo("vendor_apex",
94 "/apex/vendor_apex",
95 {"libapexprovide.so"},
96 {":vndk", "libvendorprovide.so"},
97 {},
98 {},
99 {},
100 false,
101 true,
102 true,
103 false);
104 vendor_apex.original_path = "/vendor/apex/com.android.vendor";
105 ctx.AddApexModule(vendor_apex);
106
107 // To generate vendor section
108 ctx.AddApexModule(ApexInfo("com.android.vndk.v",
109 "/apex/com.android.vndk.v",
110 {},
111 {},
112 {},
113 {},
114 {},
115 false,
116 true,
117 true,
118 false));
119
120 auto config = CreateBaseConfiguration(ctx);
121
122 auto* section = config.GetSection("vendor");
123 ASSERT_TRUE(section);
124
125 // vendor apex should be able to load vndk libraries
126 auto shared_libs =
127 section->GetNamespace("vendor_apex")->GetLink("vndk").GetSharedLibs();
128 ASSERT_TRUE(std::find(shared_libs.begin(),
129 shared_libs.end(),
130 "vndk_core_libraries") != shared_libs.end());
131
132 ConfigWriter config_writer;
133 config.WriteConfig(config_writer);
134 VerifyConfiguration(config_writer.ToString());
135 }
136