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 }