• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 
16 #ifndef DFX_CRASHER_H
17 #define DFX_CRASHER_H
18 
19 #include <cinttypes>
20 #include <string>
21 #include "dfx_test_func.h"
22 
23 class DfxCrasher {
24 public:
25 
26     static DfxCrasher &GetInstance();
27     ~DfxCrasher();
28 
29     static int RaiseAbort();
30     static int RaiseBusError();
31     static int RaiseFloatingPointException();
32     static int RaiseIllegalInstructionException();
33     static int RaiseSegmentFaultException();
34     static int RaiseTrapException();
35     static int IllegalInstructionException();
36     static int SegmentFaultException();
37     static int SetLastFatalMessage();
38     static int Abort();
39     static int Loop();
40 
41     void PrintUsage() const;
42 
43     static void* DoCrashInThread(void* inputArg);
44     uint64_t DoActionOnSubThread(const char* arg) const;
45     uint64_t ParseAndDoCrash(const char* arg) const;
46     static int MaxStackDepth();
47     static int MultiThreadCrash();
48     static int ProgramCounterZero();
49     static int StackOver64();
50     static int StackTop();
51     //           1         2         3         4         5         6         7
52     //  1234567890123456789012345678901234567890123456789012345678901234567890
53     static int MaxMethodNameTest12345678901234567890123456789012345678901234567890ABC();
54     static int TriggerSegmentFaultException();
55     static int StackOverflow();
56     static int Oom();
57     static int TriggerTrapException();
58     static int CrashInLambda();
59     static int DoDumpCrash();
60     static int TestExitHook();
61     static int TestSigHook();
62     static int StackCorruption();
63     static int StackCorruption2();
64 
65     static int RecursiveFunc(int curLevel, int targetLevel, int midLevel);
66     static int PrintFatalMessageInLibc();
67     static int TestGetCrashObj();
68     static int TestGetCrashObjMemory();
69 #ifndef is_ohos_lite
70     static int AsyncStacktrace();
71     static int CrashInFFRT(const std::string &debug);
72     static int CrashInLibuvWork(const std::string &debug);
73     static int CrashInLibuvTimer(const std::string &debug);
74     static int CrashInLibuvWorkDone(const std::string &debug);
75 #endif
76     static int TestDeadlock();
77 
78 private:
79     DfxCrasher();
80     DfxCrasher(const DfxCrasher &) = delete;
81     DfxCrasher &operator=(const DfxCrasher &) = delete;
82 };
83 int SleepThread(int threadID);
84 #endif // DFX_CRASHER_H
85