• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  */
22 
23 /*********************************************************************
24  *  @CaseName: dlclose_02
25  *  @Brief: 测试dlclose关闭一对多so的动态库
26 *********************************************************************/
27 
28 #include "common.h" /* PLEASE DON'T MODIFY THIS LINE */
29 
30 // Func:本用例执行测试前进行环境初始化
31 // Args:同用例参数
tc_pre_test(int argc,char ** argv)32 int tc_pre_test(int argc, char **argv)
33 {
34 	// @PRE-1: 测试so存在
35 	char *files[] = {
36 		"/data/tests/libc-test/ola_test/liba.so",
37 		"/data/tests/libc-test/ola_test/libb.so",
38         "/data/tests/libc-test/ola_test/libcc.so"
39 	};
40 	int num_files = sizeof(files) /sizeof(files[0]);
41 	if (check_so_exist(num_files, files) != 0) {
42 		rt_err("check so failed\n");
43 	}
44 	return RT_EOK;
45 }
46 
47 // Func: 用例执行测试活动,重要:本函数必须定义且函数名不可修改
48 // Args: 同用例参数
tc_do_test(int argc,char ** argv)49 int tc_do_test(int argc, char **argv)
50 {
51 	// @STEP-1: dlopen加载libcc.so
52 	// @EXPECT-1: 3个so都加载成功
53 	int ret = 0;
54 	char *direct_libs = "/data/tests/libc-test/ola_test/libcc.so";
55 	void *direct_hdls[] = { NULL, NULL };
56 	char *depend_libs[] = {
57 		"/data/tests/libc-test/ola_test/liba.so",
58 		"/data/tests/libc-test/ola_test/libb.so"
59 	};
60 
61 	direct_hdls[0] = dlopen(direct_libs, RTLD_NOW | RTLD_GLOBAL);
62 	if (!direct_hdls[0]) {
63 		rt_err("dlopen %c failed: %s \n", direct_libs[0], dlerror());
64 	}
65     if (!check_loaded(direct_libs)) {
66         rt_err("dso %c exist in /proc/self/maps\n", direct_libs[0]);
67     }
68     if (!check_loaded(depend_libs[0]) || !check_loaded(depend_libs[1])) {
69         rt_err("dso %s or %s should exist in /proc/self/maps\n", depend_libs[0], depend_libs[1]);
70     }
71 
72 	// @STEP-2: dlclose卸载libcc.so
73 	// @EXPECT-2: 2个so均被卸载
74 	ret = dlclose(direct_hdls[0]);
75 	if (ret != 0) {
76 		rt_err("dlclose %c failed: %s \n", direct_libs[0], dlerror());
77 	}
78 
79     if (check_loaded(depend_libs[0]) || check_loaded(depend_libs[1])) {
80         rt_err("dso %c or %c shouldn't exist in /proc/self/maps\n", direct_libs[0], direct_libs[1]);
81     }
82 
83 	return RT_EOK;
84 }
85 
86 // Func: 本用例执行完测试活动后进行用例清理操作
87 // Args: 同用例参数
tc_post_test(int argc,char ** argv)88 int tc_post_test(int argc, char **argv)
89 {
90 	return RT_EOK;
91 }
92 
93 // Func: 本用例执行失败后需要进行的日志收集动作
tc_get_debuginfo(int argc,char ** argv)94 int tc_get_debuginfo(int argc, char **argv)
95 {
96 	return RT_EOK;
97 }
98 
main()99 int main() {
100 	if(tc_pre_test(0, NULL)) {
101 		rt_err("tc_pre_test failed:\n");
102 		return -1;
103 	}
104 	if(tc_do_test(0, NULL)) {
105 		rt_err("tc_do_test failed:\n");
106 		return -1;
107 	}
108 	if(tc_post_test(0, NULL)) {
109 		rt_err("tc_post_test failed:\n");
110 		return -1;
111 	}
112 	if(tc_get_debuginfo(0, NULL)) {
113 		rt_err("tc_get_debuginfo failed:\n");
114 		return -1;
115 	}
116 	return 0;
117 }