• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "bbox_detector_unit_test.h"
16 
17 #include "bbox_detector_plugin.h"
18 #include "sys_event.h"
19 #include "sys_event_dao.h"
20 #include "smart_parser.h"
21 #include "tbox.h"
22 using namespace std;
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 using namespace testing::ext;
SetUpTestCase(void)27 void BBoxDetectorUnitTest::SetUpTestCase(void) {}
28 
TearDownTestCase(void)29 void BBoxDetectorUnitTest::TearDownTestCase(void) {}
30 
SetUp(void)31 void BBoxDetectorUnitTest::SetUp(void) {}
32 
TearDown(void)33 void BBoxDetectorUnitTest::TearDown(void) {}
34 
35 /**
36  * @tc.name: BBoxDetectorUnitTest001
37  * @tc.desc: check bbox config parser whether it is passed.
38  *           1.parse bbox config;
39  *           2.check result;
40  * @tc.type: FUNC
41  * @tc.require:
42  * @tc.author: liuwei
43  */
44 HWTEST_F(BBoxDetectorUnitTest, BBoxDetectorUnitTest001, TestSize.Level1)
45 {
46     /**
47      * @tc.steps: step1. init bboxDetector and parse hisysevent.
48      */
49 
50     /**
51      * @tc.steps: step2. check func.
52      * @tc.expect: get right result for checking
53      */
54     SysEventCreator sysEventCreator("KERNEL_VENDOR", "PANIC", SysEventCreator::FAULT);
55     auto sysEvent = make_shared<SysEvent>("test", nullptr, sysEventCreator);
56     auto testPlugin = make_shared<BBoxDetectorPlugin>();
57     shared_ptr<Event> event = dynamic_pointer_cast<Event>(sysEvent);
58     EXPECT_EQ(testPlugin->CanProcessEvent(event), true);
59 }
60 
61 /**
62  * @tc.name: BBoxDetectorUnitTest002
63  * @tc.desc: check whether fault is processed,and check whether fault file is pasered
64  *           1. check whether fault file is pasered;
65  * @tc.type: FUNC
66  * @tc.require:
67  * @tc.author: liuwei
68  */
69 HWTEST_F(BBoxDetectorUnitTest, BBoxDetectorUnitTest002, TestSize.Level1)
70 {
71     /**
72      * @tc.steps: step1. construct panic file path
73      * @tc.steps: step2. Analysis panic event
74      * @tc.steps: step3. check result
75      */
76     string stack = R"("dump_backtrace+0x0/0x184"
77                      "show_stack+0x2c/0x3c",
78                      "dump_stack+0xc0/0x11c",
79                      "panic+0x1cc/0x3dc",
80                      "sysrq_handle_term+0x0/0x94",
81                      "__handle_sysrq+0x15c/0x184",
82                      "write_sysrq_trigger+0xb0/0xf4",
83                      "proc_reg_write+0x94/0x120",
84                      "vfs_write+0x184/0x380",
85                      "ksys_write+0x74/0xc8",
86                      "__arm64_sys_write+0x24/0x34",
87                      "el0_svc_common+0x104/0x180",
88                      "do_el0_svc+0x2c/0x3c",
89                      "el0_svc+0x10/0x1c",
90                      "vks_write+0x123/0xa6",
91                      "el0_sync+0x180/0x1c0"
92                     )";
93 
94     std::map<std::string, std::string> eventInfos;
95     eventInfos.insert(std::pair("END_STACK", stack));
96     eventInfos.insert(std::pair("PNAME", "PANIC"));
97     eventInfos.insert(std::pair("Eventid", "901000002"));
98     Tbox::FilterTrace(eventInfos);
99 
100     EXPECT_STREQ(eventInfos["FIRST_FRAME"].c_str(), "sysrq_handle_term+0x0/0x94");
101     EXPECT_STREQ(eventInfos["SECOND_FRAME"].c_str(), "__handle_sysrq+0x15c/0x184");
102 }
103 }  // namespace HiviewDFX
104 }  // namespace OHOS
105