1 /*
2 * Copyright (C) 2025 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 #include <stdlib.h>
16 #include <stdio.h>
17
18 #include "bt-test.h"
19 #include "functionalext.h"
20
backtrace2_TestGetVer()21 static void backtrace2_TestGetVer() {
22 std::string verA("");
23 std::string verB("");
24
25 testbt::TestVer test_1(verA, verB);
26 test_1.symbolNameA = "clibGetVerA";
27 test_1.fileNameA = "libadlt_base_backtrace2_lib_a.so";
28 test_1.symbolNameB = "clibGetVerB";
29 test_1.fileNameB = "libadlt_base_backtrace2_lib_b.so";
30
31 std::string resVer = test_1.test();
32
33 EXPECT_STREQ(__func__, "1.0.a", verA.c_str());
34 EXPECT_STREQ(__func__, "1.0.b", verB.c_str());
35
36 std::string btA("");
37 std::string btB("");
38 testbt::TestVerBT test_2(btA, btB);
39 test_2.symbolNameA = "clibGetVerA";
40 test_2.fileNameA = "libadlt_base_backtrace2_lib_a.so";
41 test_2.symbolNameB = "clibGetVerB";
42 test_2.fileNameB = "libadlt_base_backtrace2_lib_b.so";
43
44 std::string resBT = test_2.test();
45
46 bool okA = (btA.find("clibGetVerA") != std::string::npos) &&
47 (btA.find("backtrace2_lib_a.so") != std::string::npos);
48 bool okB = (btB.find("clibGetVerB") != std::string::npos) &&
49 (btB.find("backtrace2_lib_b.so") != std::string::npos);
50
51 EXPECT_TRUE(__func__, okA && okB);
52 }
53
backtrace2_TestMaxMin()54 static void backtrace2_TestMaxMin() {
55 int max = 0;
56 int min = 0;
57
58 testbt::TestMaxMin test_1(max, min);
59 test_1.symbolNameA = "clibMaxA";
60 test_1.fileNameA = "libadlt_base_backtrace2_lib_a.so";
61 test_1.aa = 1;
62 test_1.ab = 55;
63 test_1.symbolNameB = "clibMinB";
64 test_1.fileNameB = "libadlt_base_backtrace2_lib_b.so";
65 test_1.ba = 2;
66 test_1.bb = 11;
67
68 std::string resMaxMin = test_1.test();
69
70 EXPECT_EQ(__func__, 55, max);
71 EXPECT_EQ(__func__, 2, min);
72
73 std::string btA("");
74 std::string btB("");
75 testbt::TestVerBT test_2(btA, btB);
76 test_2.symbolNameA = "clibMaxA";
77 test_2.fileNameA = "libadlt_base_backtrace2_lib_a.so";
78 test_2.symbolNameB = "clibMinB";
79 test_2.fileNameB = "libadlt_base_backtrace2_lib_b.so";
80
81 std::string resBT = test_2.test();
82
83 bool okA = (btA.find("clibMaxA") != std::string::npos) &&
84 (btA.find("backtrace2_lib_a.so") != std::string::npos);
85 bool okB = (btB.find("clibMinB") != std::string::npos) &&
86 (btB.find("backtrace2_lib_b.so") != std::string::npos);
87
88 EXPECT_TRUE(__func__, okA && okB);
89 }
90
main(int argc,char ** argv)91 int main(int argc, char **argv) {
92 backtrace2_TestGetVer();
93 backtrace2_TestMaxMin();
94 return t_status;
95 }