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