• 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: SmartParserCppCrashTest001
30  * @tc.desc: Smart paerser cpp crash log.
31  * @tc.type: FUNC
32  */
33 HWTEST(SmartParserCppCrashTest, SmartParserCppCrashTest001, testing::ext::TestSize.Level0)
34 {
35     /**
36      * @tc.steps: step1. parser log
37      */
38     const std::string logPath = std::string{LogUtil::SMART_PARSER_TEST_DIR}  +
39         "/SmartParserCppCrashTest001/cppcrash-com.ohos.launcher-20010025-19700324235211000.log";
40     const std::string eventType = "CPP_CRASH";
41     auto eventInfos = SmartParser::Analysis(logPath, SMART_PARSER_PATH, eventType);
42 
43     /**
44      * @tc.steps: step2. check result
45      */
46     std::string endStack = "#00 pc 00000000000bb328 /system/lib64/libc.so(__epoll_pwait+8)\n";
47     endStack += "#01 pc 000000000000d370 /system/lib64/libeventhandler.z.so";
48     endStack += "(OHOS::AppExecFwk::EpollIoWaiter::WaitFor(std::__1::unique_lock<std::__1::mutex>&, long)+192)\n";
49     endStack += "#02 pc 0000000000011db4 /system/lib64/libeventhandler.z.so";
50     endStack += "(OHOS::AppExecFwk::EventQueue::WaitUntilLocked(std::__1::chrono::time_point<";
51     endStack += "std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, ";
52     endStack += "std::__1::ratio<1l, 1000000000l> > > const&, std::__1::unique_lock<std::__1::mutex>&)+96)\n";
53     endStack +=
54         R"(#03 pc 0000000000011cf8 /system/lib64/libeventhandler.z.so(OHOS::AppExecFwk::EventQueue::GetEvent()+112)
55 #04 pc 0000000000017728 /system/lib64/libeventhandler.z.so
56 #05 pc 000000000001608c /system/lib64/libeventhandler.z.so(OHOS::AppExecFwk::EventRunner::Run()+96)
57 #06 pc 000000000009380c /system/lib64/libappkit_native.z.so(OHOS::AppExecFwk::MainThread::Start()+372)
58 #07 pc 00000000000144b8 /system/bin/appspawn
59 #08 pc 00000000000139ec /system/bin/appspawn
60 #09 pc 000000000001fd90 /system/lib64/libbegetutil.z.so
61 #10 pc 000000000001f980 /system/lib64/libbegetutil.z.so
62 #11 pc 000000000001ccd0 /system/lib64/libbegetutil.z.so(ProcessEvent+108)
63 #12 pc 000000000001c6cc /system/lib64/libbegetutil.z.so
64 #13 pc 00000000000128b4 /system/bin/appspawn
65 #14 pc 000000000001053c /system/bin/appspawn
66 #15 pc 000000000006afa4 /system/lib64/libc.so(__libc_init+112)
67 )";
68 
69     ASSERT_EQ(eventInfos["END_STACK"], endStack);
70 
71     Tbox::FilterTrace(eventInfos, eventType);
72     std::string firstFrame = "/system/lib64/libeventhandler.z.so";
73     firstFrame += "(OHOS::AppExecFwk::EpollIoWaiter::WaitFor(std::__1::unique_lock<std::__1::mutex>&, long)+192";
74     ASSERT_EQ(eventInfos["FIRST_FRAME"], firstFrame);
75     std::string secondFrame = "/system/lib64/libeventhandler.z.so";
76     secondFrame += "(OHOS::AppExecFwk::EventQueue::WaitUntilLocked";
77     secondFrame += "(std::__1::chrono::time_point<std::__1::chrono::steady_clock, ";
78     secondFrame += "std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > const&, ";
79     secondFrame += "std::__1::unique_lock<std::__1::mutex>&)+96";
80     ASSERT_EQ(eventInfos["SECOND_FRAME"], secondFrame);
81     ASSERT_EQ(eventInfos["LAST_FRAME"], "/system/bin/appspawn");
82 }
83 } // namespace HiviewDFX
84 } // namespace OHOS
85