• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
16 #include <string>
17 #include <vector>
18 
19 #include "smart_parser.h"
20 #include "tbox.h"
21 #include "log_util.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::HiviewDFX;
25 namespace OHOS {
26 namespace HiviewDFX {
27 
28 /**
29  * @tc.name: SmartParserPanicTest001
30  * @tc.desc: Smart parser non-encrypted panic log.
31  * @tc.type: FUNC
32  */
33 HWTEST(SmartParserPanicTest, SmartParserPanicTest001, testing::ext::TestSize.Level3)
34 {
35     /**
36      * @tc.steps: step1. parser log
37      */
38     const std::string logPath = std::string{LogUtil::SMART_PARSER_TEST_DIR}  +
39         "/SmartParserPanicTest001/19700101000000-00000007/ap_log/dmesg-ramoops-0";
40     const std::string eventType = "PANIC";
41     auto eventInfos = SmartParser::Analysis(logPath, SMART_PARSER_PATH, eventType);
42 
43     /**
44      * @tc.steps: step2. check result
45      */
46     std::string endStack = "<dump_backtrace+0x0/0x8>\n";
47     endStack += "<show_stack+0x24/0x30>\n";
48     endStack += "<dump_stack+0xc0/0x11c>\n";
49     endStack += "<panic+0x178/0x3f0>\n";
50     endStack += "<sysrq_handle_term+0x0/0x38>\n";
51     endStack += "<__handle_sysrq+0x170/0x1b8>\n";
52     endStack += "<write_sysrq_trigger+0xb4/0xe0>\n";
53     endStack += "<proc_reg_write+0x90/0x1a0>\n";
54     endStack += "<vfs_write+0x14c/0x410>\n";
55     endStack += "<ksys_write+0x84/0xf4>\n";
56     endStack += "<__arm64_sys_write+0x28/0x34>\n";
57     endStack += "<el0_svc_common+0x134/0x22c>\n";
58     endStack += "<el0_svc_compat+0x1c/0x28>\n";
59     endStack += "<el0_sync_compat_handler+0xc0/0xf0>\n";
60     endStack += "<el0_sync_compat+0x184/0x1c0>\n";
61 
62     ASSERT_EQ(eventInfos["END_STACK"], endStack);
63 
64     Tbox::FilterTrace(eventInfos, eventType);
65     ASSERT_EQ(eventInfos["FIRST_FRAME"], "sysrq_handle_term+0x0/0x38");
66     ASSERT_EQ(eventInfos["SECOND_FRAME"], "__handle_sysrq+0x170/0x1b8");
67     ASSERT_EQ(eventInfos["LAST_FRAME"], "el0_sync_compat+0x184/0x1c0");
68 }
69 
70 /**
71  * @tc.name: SmartParserPanicTest002
72  * @tc.desc: Smart parser encrypted panic log.
73  * @tc.type: FUNC
74  */
75 HWTEST(SmartParserPanicTest, SmartParserPanicTest002, testing::ext::TestSize.Level3)
76 {
77     /**
78      * @tc.steps: step1. parser log
79      */
80     const std::string logPath = std::string{LogUtil::SMART_PARSER_TEST_DIR}  +
81         "/SmartParserPanicTest002/19700101000000-00000007/ap_log/dmesg-ramoops-0";
82     const std::string eventType = "PANIC";
83     auto eventInfos = SmartParser::Analysis(logPath, SMART_PARSER_PATH, eventType);
84 
85     /**
86      * @tc.steps: step2. check result
87      */
88     std::string endStack = "<dump_backtrace+0x0/0x0>\n";
89     endStack += "<show_stack+0x0/0x0>\n";
90     endStack += "<dump_stack+0x0/0x0>\n";
91     endStack += "<panic+0x0/0x0>\n";
92     endStack += "<sysrq_handle_term+0x0/0x0>\n";
93     endStack += "<__handle_sysrq+0x0/0x0>\n";
94     endStack += "<write_sysrq_trigger+0x0/0x0>\n";
95     endStack += "<proc_reg_write+0x0/0x0>\n";
96     endStack += "<vfs_write+0x0/0x0>\n";
97     endStack += "<ksys_write+0x0/0x0>\n";
98     endStack += "<__arm64_sys_write+0x0/0x0>\n";
99     endStack += "<el0_svc_common+0x0/0x0>\n";
100     endStack += "<el0_svc_compat+0x0/0x0>\n";
101     endStack += "<el0_sync_compat_handler+0x0/0x0>\n";
102     endStack += "<el0_sync_compat+0x0/0x0>\n";
103 
104     ASSERT_EQ(eventInfos["END_STACK"], endStack);
105 
106     Tbox::FilterTrace(eventInfos, eventType);
107     ASSERT_EQ(eventInfos["FIRST_FRAME"], "sysrq_handle_term+0x0/0x0");
108     ASSERT_EQ(eventInfos["SECOND_FRAME"], "__handle_sysrq+0x0/0x0");
109     ASSERT_EQ(eventInfos["LAST_FRAME"], "el0_sync_compat+0x0/0x0");
110 }
111 
112 /**
113  * @tc.name: SmartParserPanicTest003
114  * @tc.desc: Smart parser hguard abnormal panic log.
115  * @tc.type: FUNC
116  */
117 HWTEST(SmartParserPanicTest, SmartParserPanicTest003, testing::ext::TestSize.Level3)
118 {
119     /**
120      * @tc.steps: step1. parser log
121      */
122     const std::string logPath = std::string{LogUtil::SMART_PARSER_TEST_DIR}  +
123         "/SmartParserPanicTest003/19700101000000-00000007/ap_log/dmesg-ramoops-0";
124     const std::string eventType = "PANIC";
125     auto eventInfos = SmartParser::Analysis(logPath, SMART_PARSER_PATH, eventType);
126 
127     /**
128      * @tc.steps: step2. check result
129      */
130     std::string endStack = "<dump_backtrace+0x0/0x0>\n";
131     endStack += "<show_stack+0x0/0x0>\n";
132     endStack += "<dump_stack+0x0/0x0>\n";
133     endStack += "<panic+0x0/0x0>\n";
134     endStack += "<sysrq_handle_term+0x0/0x0>\n";
135     endStack += "<__handle_sysrq+0x0/0x0>\n";
136     endStack += "<write_sysrq_trigger+0x0/0x0>\n";
137     endStack += "<proc_reg_write+0x0/0x0>\n";
138     endStack += "<vfs_write+0x0/0x0>\n";
139     endStack += "<ksys_write+0x0/0x0>\n";
140     endStack += "<__arm64_sys_write+0x0/0x0>\n";
141     endStack += "<el0_svc_common+0x0/0x0>\n";
142     endStack += "<el0_svc_compat+0x0/0x0>\n";
143     endStack += "<el0_sync_compat_handler+0x0/0x0>\n";
144     endStack += "<el0_sync_compat+0x0/0x0>\n";
145 
146     ASSERT_EQ(eventInfos["END_STACK"], endStack);
147 
148     Tbox::FilterTrace(eventInfos, eventType);
149     ASSERT_EQ(eventInfos["FIRST_FRAME"], "sysrq_handle_term+0x0/0x0");
150     ASSERT_EQ(eventInfos["SECOND_FRAME"], "__handle_sysrq+0x0/0x0");
151     ASSERT_EQ(eventInfos["LAST_FRAME"], "el0_sync_compat+0x0/0x0");
152 }
153 } // namespace HiviewDFX
154 } // namespace OHOS
155