SignalTest.h 2.3 KB
Newer Older
W
wenjun 已提交
1
/*
M
mamingshuai 已提交
2
 * Copyright (c) 2021 Huawei Device Co., Ltd.
W
wenjun 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SIGNAL_TEST
#define SIGNAL_TEST

#include <gtest/gtest.h>
#include <signal.h>

M
mamingshuai 已提交
22 23
const int MAX_SIGNAL = 31;
const int MAX_DESCRP_LEN = 32;
W
wenjun 已提交
24 25 26
enum SignalAction {TERMINATE, COREDUMP, IGNORE, STOP, CONTINUE};
struct SignalNameAction {
    char signame[12];
M
mamingshuai 已提交
27
    char description[MAX_DESCRP_LEN];
W
wenjun 已提交
28 29
    SignalAction action;
};
M
mamingshuai 已提交
30
extern SignalNameAction const ALL_SIGNALS[MAX_SIGNAL];
W
wenjun 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

using handler_type = void (*) (int);

class IpcSignalTest : public::testing::TestWithParam<int> {
public:
    void SetUp()
    {
        mReceivedSignal = 0;
    };
    // fail test util-func for sig api
    void SignalFailTest(int signum, handler_type h, int expectErrno = EINVAL);
    void SigpendingFailTest(sigset_t* pset);
    void SigtimedwaitFailTest(const sigset_t *set, siginfo_t* info,
        const struct timespec* timeout, int expectErrno = EINVAL);

    // utils for all signal test
    void DefaultActionTest(int signum, bool expectStop, bool coredump = false);
    void SendAndRecvTest(int signum);
M
mamingshuai 已提交
49
    int CheckSigString(const char* outfile, const char* expectStr);
W
wenjun 已提交
50 51 52 53 54 55 56 57

    // general signal handler
    static void SignalHandler(int signum);
    // special signal handler for function 'abort'
    static void SigAbortHandler(int signum);
    // special signal handler for function 'sigaction'
    static void SigactionHandler(int signum, siginfo_t* si, void* ucontext);

M
mamingshuai 已提交
58 59 60 61 62
    static void* ThreadFunc1(void* arg);
    static void* ThreadFunc2(void* arg);
    static void* ThreadFuncForSigmask1(void* arg);
    static void* ThreadFuncForSigmask2(void* arg);

W
wenjun 已提交
63 64
protected:
    static int mReceivedSignal;
M
mamingshuai 已提交
65
    static int mShmid;
W
wenjun 已提交
66 67 68 69 70
    static siginfo_t mSiginfo;
};


#endif