• 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_module_test.h"
16 
17 #include "bbox_detector_plugin.h"
18 #include "common_defines.h"
19 #include "event.h"
20 #include "log_util.h"
21 #include "sys_event.h"
22 #include "string_util.h"
23 #include "time_util.h"
24 
25 using namespace std;
26 namespace OHOS {
27 namespace HiviewDFX {
28 using namespace testing::ext;
SetUpTestCase(void)29 void BBoxDetectorModuleTest::SetUpTestCase(void) {}
30 
TearDownTestCase(void)31 void BBoxDetectorModuleTest::TearDownTestCase(void) {}
32 
SetUp(void)33 void BBoxDetectorModuleTest::SetUp(void) {}
34 
TearDown(void)35 void BBoxDetectorModuleTest::TearDown(void) {}
36 
37 /**
38  * @tc.name: BBoxDetectorModuleTest001
39  * @tc.desc: check whether fault is processed.
40  *           1. check whether event is valid;
41  *           2. check whether category and reason is ignored;
42  * @tc.type: FUNC
43  * @tc.require:
44  * @tc.author: liuwei
45  */
46 HWTEST_F(BBoxDetectorModuleTest, BBoxDetectorModuleTest001, TestSize.Level1)
47 {
48     /**
49      * @tc.steps: step1. construct PANIC SysEvent
50      * @tc.steps: step2. construct BBOXDetectorPlugin
51      * @tc.steps: step3. OnEvent
52      * @tc.steps: step4. check result
53      */
54     SysEventCreator sysEventCreator("KERNEL_VENDOR", "PANIC", SysEventCreator::FAULT);
55     sysEventCreator.SetKeyValue("SUMMARY", "bootup_keypoint:97");
56     sysEventCreator.SetKeyValue("name_", "PANIC");
57     sysEventCreator.SetKeyValue("HAPPEN_TIME", "443990995");
58     sysEventCreator.SetKeyValue("LOG_PATH", "/data/hisi_logs/");
59     sysEventCreator.SetKeyValue("SUB_LOG_PATH", "19700106031950-00001111");
60     sysEventCreator.SetKeyValue("MODULE", "AP");
61     sysEventCreator.SetKeyValue("REASON", "AP_S_PANIC");
62     auto sysEvent = make_shared<SysEvent>("test", nullptr, sysEventCreator);
63     auto testPlugin = make_shared<BBoxDetectorPlugin>();
64     shared_ptr<Event> event = dynamic_pointer_cast<Event>(sysEvent);
65     testPlugin->OnLoad();
66     testPlugin->OnEvent(event);
67     ASSERT_EQ(sysEvent->GetEventValue("MODULE"), "AP");
68     ASSERT_EQ(sysEvent->GetEventValue("REASON"), "AP_S_PANIC");
69     ASSERT_EQ(sysEvent->GetEventValue("LOG_PATH"), "/data/hisi_logs/19700106031950-00001111");
70 }
71 
72 /**
73  * @tc.name: BBoxDetectorModuleTest002
74  * @tc.desc: check whether fault is processed.
75  *           1. check whether event is valid;
76  *           2. check whether category and reason is ignored;
77  * @tc.type: FUNC
78  * @tc.require:
79  * @tc.author: liuwei
80  */
81 HWTEST_F(BBoxDetectorModuleTest, BBoxDetectorModuleTest002, TestSize.Level1)
82 {
83     /**
84      * @tc.steps: step1. construct HWWATCHDOG SysEvent
85      * @tc.steps: step2. construct BBOXDetectorPlugin
86      * @tc.steps: step3. OnEvent
87      * @tc.steps: step4. check result
88      */
89     SysEventCreator sysEventCreator("KERNEL_VENDOR", "HWWATCHDOG", SysEventCreator::FAULT);
90     sysEventCreator.SetKeyValue("SUMMARY", "bootup_keypoint:97");
91     sysEventCreator.SetKeyValue("name_", "HWWATCHDOG");
92     sysEventCreator.SetKeyValue("HAPPEN_TIME", "443990995");
93     sysEventCreator.SetKeyValue("LOG_PATH", "/data/hisi_logs/");
94     sysEventCreator.SetKeyValue("SUB_LOG_PATH", "19700106031950-00001111");
95     sysEventCreator.SetKeyValue("MODULE", "AP");
96     sysEventCreator.SetKeyValue("REASON", "AP_S_HWWATCHDOG");
97     auto sysEvent = make_shared<SysEvent>("test", nullptr, sysEventCreator);
98     auto testPlugin = make_shared<BBoxDetectorPlugin>();
99     shared_ptr<Event> event = dynamic_pointer_cast<Event>(sysEvent);
100     testPlugin->OnLoad();
101     testPlugin->OnEvent(event);
102     ASSERT_EQ(sysEvent->GetEventValue("MODULE"), "AP");
103     ASSERT_EQ(sysEvent->GetEventValue("REASON"), "AP_S_HWWATCHDOG");
104     ASSERT_EQ(sysEvent->GetEventValue("LOG_PATH"), "/data/hisi_logs/19700106031950-00001111");
105 }
106 
107 /**
108  * @tc.name: BBoxDetectorModuleTest003
109  * @tc.desc: check whether fault is processed.
110  *           1. check whether event is valid;
111  *           2. check whether category and reason is ignored;
112  * @tc.type: FUNC
113  * @tc.require:
114  * @tc.author: liuwei
115  */
116 HWTEST_F(BBoxDetectorModuleTest, BBoxDetectorModuleTest003, TestSize.Level1)
117 {
118     /**
119      * @tc.steps: step1. construct HWWATCHDOG SysEvent
120      * @tc.steps: step2. construct BBOXDetectorPlugin
121      * @tc.steps: step3. OnEvent
122      * @tc.steps: step4. check result
123      */
124     SysEventCreator sysEventCreator("KERNEL_VENDOR", "MODEMCRASH", SysEventCreator::FAULT);
125     sysEventCreator.SetKeyValue("SUMMARY", "bootup_keypoint:97");
126     sysEventCreator.SetKeyValue("name_", "MODEMCRASH");
127     sysEventCreator.SetKeyValue("HAPPEN_TIME", "443990995");
128     sysEventCreator.SetKeyValue("LOG_PATH", "/data/hisi_logs/");
129     sysEventCreator.SetKeyValue("SUB_LOG_PATH", "19700106031950-00001111");
130     sysEventCreator.SetKeyValue("MODULE", "AP");
131     sysEventCreator.SetKeyValue("REASON", "MODEMCRASH");
132     auto sysEvent = make_shared<SysEvent>("test", nullptr, sysEventCreator);
133     auto testPlugin = make_shared<BBoxDetectorPlugin>();
134     shared_ptr<Event> event = dynamic_pointer_cast<Event>(sysEvent);
135     testPlugin->OnLoad();
136     testPlugin->OnEvent(event);
137     ASSERT_EQ(sysEvent->GetEventValue("MODULE"), "AP");
138     ASSERT_EQ(sysEvent->GetEventValue("REASON"), "MODEMCRASH");
139     ASSERT_EQ(sysEvent->GetEventValue("LOG_PATH"), "/data/hisi_logs/19700106031950-00001111");
140 }
141 
142 /**
143  * @tc.name: BBoxDetectorModuleTest004
144  * @tc.desc: check whether fault is processed.
145  *           1. check whether event is invalid;
146  * @tc.type: FUNC
147  * @tc.require:
148  * @tc.author: liuwei
149  */
150 HWTEST_F(BBoxDetectorModuleTest, BBoxDetectorModuleTest004, TestSize.Level1)
151 {
152     /**
153      * @tc.steps: step1. construct CPP_CRASH SysEvent
154      * @tc.steps: step2. construct BBOXDetectorPlugin
155      * @tc.steps: step3. OnEvent
156      * @tc.steps: step4. check result should return false
157      */
158     SysEventCreator sysEventCreator("KERNEL_VENDOR", "CPP_CRASH", SysEventCreator::FAULT);
159     sysEventCreator.SetKeyValue("SUMMARY", "bootup_keypoint:97");
160     sysEventCreator.SetKeyValue("name_", "CPP_CRASH");
161     sysEventCreator.SetKeyValue("HAPPEN_TIME", "443990995");
162     sysEventCreator.SetKeyValue("LOG_PATH", "/data/hisi_logs/");
163     sysEventCreator.SetKeyValue("SUB_LOG_PATH", "19700106031950-00001111");
164     sysEventCreator.SetKeyValue("MODULE", "AP");
165     sysEventCreator.SetKeyValue("REASON", "MODEMCRASH");
166     auto sysEvent = make_shared<SysEvent>("test", nullptr, sysEventCreator);
167     auto testPlugin = make_shared<BBoxDetectorPlugin>();
168     shared_ptr<Event> event = dynamic_pointer_cast<Event>(sysEvent);
169     testPlugin->OnLoad();
170     ASSERT_EQ(testPlugin->OnEvent(event), false);
171 }
172 }  // namespace HiviewDFX
173 }  // namespace OHOS
174