1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
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 */
15
16 #include <dlfcn.h>
17 #include <errno.h>
18 #include <stdio.h>
19 #include <string.h>
20
21 #include "dlns_test.h"
22 #include "functionalext.h"
23
24 /**
25 * @tc.name : dlopen_ns_special_0100
26 * @tc.desc : Loading the same library multiple times from the same namespace.
27 * @tc.level : Level 2
28 */
dlopen_ns_special_0100(void)29 void dlopen_ns_special_0100(void)
30 {
31 Dl_namespace dlns;
32 dlns_init(&dlns, "ns_no_allowed_libs");
33
34 void* handle1 = dlopen_ns(&dlns, dllName, RTLD_LAZY);
35 EXPECT_TRUE("dlopen_ns_special_0100", handle1);
36
37 void* handle2 = dlopen_ns(&dlns, dllName, RTLD_LAZY);
38 EXPECT_TRUE("dlopen_ns_special_0100", handle2);
39
40 void* handle3 = dlopen_ns(&dlns, dllName, RTLD_LAZY);
41 EXPECT_TRUE("dlopen_ns_special_0100", handle3);
42
43 dlclose(handle1);
44 dlclose(handle2);
45 dlclose(handle3);
46 }
47
48 /**
49 * @tc.name : dlopen_ns_special_0200
50 * @tc.desc : Loading the same library multiple times in different namespaces.
51 * @tc.level : Level 2
52 */
dlopen_ns_special_0200(void)53 void dlopen_ns_special_0200(void)
54 {
55 Dl_namespace dlns_no_allowed_libs, dlns_normal, dlns_wrong_lib_path;
56 dlns_init(&dlns_no_allowed_libs, "ns_no_allowed_libs");
57 dlns_init(&dlns_normal, "ns_normal");
58 dlns_init(&dlns_wrong_lib_path, "inherited_class");
59
60 void* handle1 = dlopen_ns(&dlns_no_allowed_libs, dllName, RTLD_LAZY);
61 EXPECT_TRUE("dlopen_ns_special_0200", handle1);
62
63 void* handle2 = dlopen_ns(&dlns_normal, dllName, RTLD_LAZY);
64 EXPECT_TRUE("dlopen_ns_special_0200", handle2);
65
66 void* handle3 = dlopen_ns(&dlns_wrong_lib_path, dllName, RTLD_LAZY);
67 EXPECT_TRUE("dlopen_ns_special_0200", handle3);
68
69 dlclose(handle1);
70 dlclose(handle2);
71 dlclose(handle3);
72 }
73
74 /**
75 * @tc.name : dlopen_ns_sys_path_0100
76 * @tc.desc : arm platform, lib_paths in the default namespace is the system path
77 * read in the ld-musl-namespace-arm.ini file
78 * @tc.level : Level 2
79 */
dlopen_ns_sys_path_0100(void)80 void dlopen_ns_sys_path_0100(void)
81 {
82 Dl_namespace dlns;
83 dlns_init(&dlns, "default");
84 void* handle = dlopen_ns(&dlns, dllName, RTLD_LAZY);
85 EXPECT_TRUE("dlopen_ns_sys_path_0100", handle);
86 dlclose(handle);
87 }
88
89
main(void)90 int main(void)
91 {
92 dlopen_ns_special_0100();
93 dlopen_ns_special_0200();
94 dlopen_ns_sys_path_0100();
95
96 return t_status;
97 }