1 /*
2 * Copyright (C) 2020 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/apexconfig.h"
18
19 #include <android-base/file.h>
20 #include <apex_manifest.pb.h>
21 #include <gtest/gtest.h>
22 #include <vector>
23
24 #include "configurationtest.h"
25 #include "linkerconfig/apex.h"
26 #include "linkerconfig/configwriter.h"
27 #include "mockenv.h"
28
29 using android::linkerconfig::modules::ApexInfo;
30
31 namespace {
32 struct ApexConfigTest : ::testing::Test {
SetUp__anon19652efa0111::ApexConfigTest33 void SetUp() override {
34 MockGenericVariables();
35 }
36
PrepareApex__anon19652efa0111::ApexConfigTest37 ApexInfo PrepareApex(const std::string& apex_name,
38 const std::vector<std::string>& provide_libs,
39 const std::vector<std::string>& require_libs) {
40 return ApexInfo(apex_name,
41 "/apex/" + apex_name,
42 provide_libs,
43 require_libs,
44 /*jni_libs=*/{},
45 /*permitted_paths=*/{},
46 /*has_bin=*/true,
47 /*has_lib=*/true,
48 /*visible=*/false,
49 /*has_shared_lib=*/false);
50 }
51 };
52 } // namespace
53
TEST_F(ApexConfigTest,apex_no_dependency)54 TEST_F(ApexConfigTest, apex_no_dependency) {
55 android::linkerconfig::contents::Context ctx;
56 auto target_apex = PrepareApex("target", {}, {});
57 auto config = android::linkerconfig::contents::CreateApexConfiguration(
58 ctx, target_apex);
59
60 android::linkerconfig::modules::ConfigWriter config_writer;
61 config.WriteConfig(config_writer);
62
63 VerifyConfiguration(config_writer.ToString());
64 }
65
TEST_F(ApexConfigTest,apex_with_required)66 TEST_F(ApexConfigTest, apex_with_required) {
67 android::linkerconfig::contents::Context ctx;
68 ctx.AddApexModule(PrepareApex("foo", {"a.so"}, {"b.so"}));
69 ctx.AddApexModule(PrepareApex("bar", {"b.so"}, {}));
70 ctx.AddApexModule(PrepareApex("baz", {"c.so"}, {"a.so"}));
71 auto target_apex = PrepareApex("target", {}, {"a.so", "b.so"});
72 auto config = android::linkerconfig::contents::CreateApexConfiguration(
73 ctx, target_apex);
74
75 android::linkerconfig::modules::ConfigWriter config_writer;
76 config.WriteConfig(config_writer);
77
78 VerifyConfiguration(config_writer.ToString());
79 }