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;
30 ctx.SetApexModules({CreateTestVndkApex()});
31 auto base_config = CreateBaseConfiguration(ctx);
32 ConfigWriter config_writer;
33
34 base_config.WriteConfig(config_writer);
35
36 VerifyConfiguration(config_writer.ToString());
37 }
38
TEST(linkerconfig_configuration_fulltest,baseconfig_vndk_using_core_variant_test)39 TEST(linkerconfig_configuration_fulltest,
40 baseconfig_vndk_using_core_variant_test) {
41 MockGenericVariables();
42 MockVndkUsingCoreVariant();
43 Context ctx;
44 ctx.SetApexModules({CreateTestVndkApex()});
45 auto base_config = CreateBaseConfiguration(ctx);
46 ConfigWriter config_writer;
47
48 base_config.WriteConfig(config_writer);
49
50 VerifyConfiguration(config_writer.ToString());
51 }
52
TEST(linkerconfig_configuration_fulltest,baseconfig_vndk_27_test)53 TEST(linkerconfig_configuration_fulltest, baseconfig_vndk_27_test) {
54 MockGenericVariables();
55 MockVndkVersion("27");
56 Context ctx;
57 ctx.SetApexModules({CreateTestVndkApex()});
58 auto base_config = CreateBaseConfiguration(ctx);
59 ConfigWriter config_writer;
60
61 base_config.WriteConfig(config_writer);
62
63 VerifyConfiguration(config_writer.ToString());
64 }
65
TEST(linkerconfig_configuration_fulltest,apexes_with_jni_are_visible_to_system_section)66 TEST(linkerconfig_configuration_fulltest,
67 apexes_with_jni_are_visible_to_system_section) {
68 MockGenericVariables();
69 Context ctx;
70 ctx.SetApexModules(
71 {CreateTestVndkApex(),
72 ApexInfo(
73 "foo", "", {}, {}, {"libjni.so"}, {}, false, true, false, false)});
74 auto config = CreateBaseConfiguration(ctx);
75
76 auto* section = config.GetSection("system");
77 ASSERT_TRUE(section);
78 auto* ns = section->GetNamespace("foo");
79 ASSERT_TRUE(ns);
80 ASSERT_TRUE(ns->IsVisible());
81
82 ConfigWriter config_writer;
83 config.WriteConfig(config_writer);
84 VerifyConfiguration(config_writer.ToString());
85 }
86
TEST(linkerconfig_configuration_fulltest,vendor_apex_configured_to_use_vndk_can_load_vndk)87 TEST(linkerconfig_configuration_fulltest,
88 vendor_apex_configured_to_use_vndk_can_load_vndk) {
89 MockGenericVariables();
90 Context ctx;
91
92 android::linkerconfig::proto::LinkerConfig vendor_config;
93 vendor_config.add_requirelibs("libapexprovide.so");
94 vendor_config.add_providelibs("libvendorprovide.so");
95 ctx.SetVendorConfig(vendor_config);
96
97 // Vendor apex requires :vndk
98 auto vendor_apex = ApexInfo("vendor_apex",
99 "/apex/vendor_apex",
100 {"libapexprovide.so"},
101 {":vndk", "libvendorprovide.so"},
102 {},
103 {},
104 false,
105 true,
106 true,
107 false);
108 vendor_apex.partition = "VENDOR";
109 ctx.SetApexModules({vendor_apex,
110 // To generate vendor section
111 ApexInfo("com.android.vndk.v",
112 "/apex/com.android.vndk.v",
113 {},
114 {},
115 {},
116 {},
117 false,
118 true,
119 true,
120 false)});
121
122 auto config = CreateBaseConfiguration(ctx);
123
124 auto* section = config.GetSection("vendor");
125 ASSERT_TRUE(section);
126
127 // vendor apex should be able to load vndk libraries
128 auto shared_libs =
129 section->GetNamespace("vendor_apex")->GetLink("vndk").GetSharedLibs();
130 ASSERT_TRUE(std::find(shared_libs.begin(),
131 shared_libs.end(),
132 "vndk_core_libraries") != shared_libs.end());
133
134 ConfigWriter config_writer;
135 config.WriteConfig(config_writer);
136 VerifyConfiguration(config_writer.ToString());
137 }
138