提交 657191d0 编写于 作者: D dhy308

Fix review issues.

Issue: I6AEEI
Test: Build & Boot Devices
Signed-off-by: Ndhy308 <tony.gan@huawei.com>
上级 37bf72e3
......@@ -38,13 +38,16 @@
#define SIGCHIAN_TEST_SIGNAL_NUM_2 2
#define SIGCHIAN_TEST_SIGNAL_NUM_3 3
#define SIGCHIAN_TEST_SIGNAL_NUM_4 4
#define SIGCHIAN_TEST_SIGNAL_NUM_10 10
#define SIGCHIAN_TEST_SIGNAL_NUM_5 5
#define SIGCHIAN_TEST_SIGNAL_NUM_6 6
#define SIGCHIAN_TEST_SIGNAL_NUM_8 8
#define SIGCHIAN_TEST_SIGNAL_NUM_9 9
#define SIGCHIAN_TEST_SIGNAL_NUM_11 11
#define SIGCHIAN_TEST_SIGNAL_NUM_13 13
#define SIGCHIAN_TEST_SIGNAL_NUM_14 14
#define SIGCHAIN_SIGNAL_37 37
#define SIGCHAIN_SIGNAL_43 43
#define SIGCHAIN_SIGNAL_50 50
#define SIGCHAIN_SIGNAL_56 56
#define SIGCHAIN_SIGNAL_64 64
#define SIGCHAIN_SIGNAL_65 65
extern bool get_sigchain_mask_enable();
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_sigabrt_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_001", signo, SIGABRT);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_sigabrt_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_001", signo, SIGABRT);
return true;
}
/**
* @tc.name : sigchain_add_special_handler_001
* @tc.desc : The signal are not registered with the kernel, call add_special_signal_handler to add
* two special handlers
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_001()
{
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_sigabrt_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigabrt1 = {
.sca_sigaction = sigchain_special_sigabrt_handler2,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGABRT, &sigabrt1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGABRT};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_001", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGABRT);
EXPECT_EQ("sigchain_add_special_handler_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
/**
* @brief the special handler
*/
static bool sigchain_special_sighup_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_002", signo, SIGHUP);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_sighup_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_002", signo, SIGHUP);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sighup_handler(int signo)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_002", signo, SIGHUP);
}
/**
* @tc.name : sigchain_add_special_handler_002
* @tc.desc : The signal are registered with the kernel(Using signal), call
* add_special_signal_handler to add two special handlers
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_002()
{
signal(SIGHUP, signal_sighup_handler);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_sighup_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sighup1 = {
.sca_sigaction = sigchain_special_sighup_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGHUP);
EXPECT_EQ("sigchain_add_special_handler_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_5);
}
/**
* @brief the special handler
*/
static bool sigchain_special_sigsegv_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_003", signo, SIGSEGV);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_sigsegv_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_003", signo, SIGSEGV);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sigsegv_sigaction(int signo)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_003", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_add_special_handler_003
* @tc.desc : the signal that are registered with the kernel(Using sigaction), call
* add_special_signal_handler to add two special handlers
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_003()
{
struct sigaction sigac = {
.sa_handler = signal_sigsegv_sigaction,
};
sigaction(SIGSEGV, &sigac, NULL);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_sigsegv_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sigsegv2 = {
.sca_sigaction = sigchain_special_sigsegv_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv2);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_003", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGSEGV);
EXPECT_EQ("sigchain_add_special_handler_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_8);
}
/**
* @brief the special handler
*/
static bool sigchain_special_sigterm_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_004", signo, SIGTERM);
return true;
}
/**
* @tc.name : sigchain_add_special_handler_004
* @tc.desc : the signal is not registered with the kernel, call add_special_signal_handler to add
* a special handler.
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_004()
{
struct signal_chain_action sigterm = {
.sca_sigaction = sigchain_special_sigterm_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGTERM, &sigterm);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGTERM};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_004", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGTERM);
EXPECT_EQ("sigchain_add_special_handler_004", g_count, SIGCHIAN_TEST_SIGNAL_NUM_9);
}
/**
* @brief the special handler
*/
static bool sigchain_special_64_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_add_special_handler_005", signo, SIGCHAIN_SIGNAL_64);
g_count++;
return false;
}
/**
* @brief the signal handler
*/
static void signal_64_handler(int signo)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_005", signo, SIGCHAIN_SIGNAL_64);
}
/**
* @tc.name : sigchain_add_special_handler_005
* @tc.desc : the signal is registered with the kernel(Using signal), call add_special_signal_handler to add
* a special handler.
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_005()
{
signal(SIGCHAIN_SIGNAL_64, signal_64_handler);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_64_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_64, &sighup);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGCHAIN_SIGNAL_64};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_005", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGCHAIN_SIGNAL_64);
EXPECT_EQ("sigchain_add_special_handler_005", g_count, SIGCHIAN_TEST_SIGNAL_NUM_11);
}
/**
* @brief the special handler
*/
static bool sigchain_special_37_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_006", signo, SIGCHAIN_SIGNAL_37);
return false;
}
/**
* @brief the signal handler
*/
static void signal_37_sigaction(int signo)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_006", signo, SIGCHAIN_SIGNAL_37);
}
/**
* @tc.name : sigchain_add_special_handler_006
* @tc.desc : the signal is registered with the kernel(Using sigaction), call add_special_signal_handler
* to add a special handler.
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_006()
{
struct sigaction sigac = {
.sa_handler = signal_37_sigaction,
};
sigaction(SIGCHAIN_SIGNAL_37, &sigac, NULL);
struct signal_chain_action sig37 = {
.sca_sigaction = sigchain_special_37_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_37, &sig37);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGCHAIN_SIGNAL_37};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_006", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGCHAIN_SIGNAL_37);
EXPECT_EQ("sigchain_add_special_handler_006", g_count, SIGCHIAN_TEST_SIGNAL_NUM_13);
}
/**
* @brief the special handler
*/
static bool sigchain_special_43_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_007", signo, SIGCHAIN_SIGNAL_43);
return true;
}
/**
* @brief the signal handler
*/
static void signal_43_sigaction(int signo)
{
g_count++;
EXPECT_FALSE("sigchain_intercept_sigprocmask_003", true);
}
/**
* @tc.name : sigchain_add_special_handler_007
* @tc.desc : Multiple signal are registered with the kernel(Using sigaction), sigchain_special_43_handler return
* true.
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_007()
{
struct sigaction sigac = {
.sa_handler = signal_43_sigaction,
};
sigaction(SIGCHAIN_SIGNAL_43, &sigac, NULL);
struct signal_chain_action sig43 = {
.sca_sigaction = sigchain_special_43_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_43, &sig43);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGCHAIN_SIGNAL_43};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_007", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGCHAIN_SIGNAL_43);
EXPECT_EQ("sigchain_add_special_handler_007", g_count, SIGCHIAN_TEST_SIGNAL_NUM_14);
}
int main(void)
{
sigchain_add_special_handler_001();
sigchain_add_special_handler_002();
sigchain_add_special_handler_003();
sigchain_add_special_handler_004();
sigchain_add_special_handler_005();
sigchain_add_special_handler_006();
sigchain_add_special_handler_007();
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_add_special_handler_001", signo, SIGSEGV);
g_count++;
return true;
}
/**
* @tc.name : sigchain_add_special_handler_001
* @tc.desc : Call add_special_signal_handler when the signal that is not registered with the kernel
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_001()
{
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_001", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
}
int main(void)
{
sigchain_add_special_handler_001();
raise(SIGSEGV);
EXPECT_EQ("sigchain_add_special_handler_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_002", signo, SIGSEGV);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
EXPECT_EQ("sigchain_add_special_handler_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
g_count++;
EXPECT_EQ("sigchain_add_special_handler_002", signo, SIGSEGV);
return;
}
/**
* @tc.name : sigchain_add_special_handler_002
* @tc.desc : Call add_special_signal_handler after the signal that is registered with
* the kernel (using signal)
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_002()
{
signal(SIGSEGV, signal_handler);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
}
int main(void)
{
sigchain_add_special_handler_002();
raise(SIGSEGV);
EXPECT_EQ("sigchain_add_special_handler_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_003", signo, SIGSEGV);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sigaction(int signo)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_003", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_add_special_handler_003
* @tc.desc : Call add_special_signal_handler after the signal that is registered with
* the kernel (using sigaction)
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_003()
{
struct sigaction sigsegv1 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGSEGV, &sigsegv1, NULL);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_003", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
}
int main(void)
{
sigchain_add_special_handler_003();
raise(SIGSEGV);
EXPECT_EQ("sigchain_add_special_handler_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_004", signo, SIGABRT);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_004", signo, SIGABRT);
return true;
}
/**
* @tc.name : sigchain_add_special_handler_004
* @tc.desc : The signal are not registered with the kernel, call add_special_signal_handler to add
* two special handlers
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_004()
{
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigabrt1 = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGABRT, &sigabrt1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGABRT};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_004", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
}
int main(void)
{
sigchain_add_special_handler_004();
raise(SIGABRT);
EXPECT_EQ("sigchain_add_special_handler_004", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_005", signo, SIGABRT);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_005", signo, SIGABRT);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_005", signo, SIGABRT);
}
/**
* @tc.name : sigchain_add_special_handler_005
* @tc.desc : The signal are registered with the kernel(Using signal), call
* add_special_signal_handler to add two special handlers
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_005()
{
signal(SIGABRT, signal_handler);
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigabrt1 = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGABRT};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_005", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
}
int main(void)
{
sigchain_add_special_handler_005();
raise(SIGABRT);
EXPECT_EQ("sigchain_add_special_handler_005", g_count, SIGCHIAN_TEST_SIGNAL_NUM_3);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_006", signo, SIGABRT);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_006", signo, SIGABRT);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sigaction(int signo)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_006", signo, SIGABRT);
}
/**
* @tc.name : sigchain_add_special_handler_006
* @tc.desc : the signal that are registered with the kernel(Using sigaction), call
* add_special_signal_handler to add two special handlers
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_006()
{
struct sigaction sigac = {
.sa_handler = signal_sigaction,
};
sigaction(SIGABRT, &sigac, NULL);
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigabrt2 = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt2);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGABRT};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_006", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
}
int main(void)
{
sigchain_add_special_handler_006();
raise(SIGABRT);
EXPECT_EQ("sigchain_add_special_handler_006", g_count, SIGCHIAN_TEST_SIGNAL_NUM_3);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_007", signo, SIGSEGV);
return true;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_007", signo, SIGHUP);
return true;
}
/**
* @tc.name : sigchain_add_special_handler_007
* @tc.desc : Multiple signal are not registered with the kernel, call add_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_007()
{
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_007", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
}
int main(void)
{
sigchain_add_special_handler_007();
raise(SIGHUP);
EXPECT_EQ("sigchain_add_special_handler_007", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
raise(SIGSEGV);
EXPECT_EQ("sigchain_add_special_handler_007", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
#define SIGCHAIN_CALL_SPECIAL_HANDLER1 1
#define SIGCHAIN_CALL_SPECIAL_HANDLER2 2
#define SIGCHAIN_CALL_HANDLER_SIGSEGV 4
#define SIGCHAIN_CALL_HANDLER_SIGUP 8
#define SIGCHAIN_CALL_CHECK_NUM 7
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_add_special_handler_008", signo, SIGSEGV);
g_count += SIGCHAIN_CALL_SPECIAL_HANDLER1;
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_add_special_handler_008", signo, SIGHUP);
g_count += SIGCHAIN_CALL_SPECIAL_HANDLER2;
return true;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
if (signo == SIGHUP) {
g_count += SIGCHAIN_CALL_HANDLER_SIGUP;
EXPECT_EQ("sigchain_add_special_handler_008", signo, SIGHUP);
} else {
g_count += SIGCHAIN_CALL_HANDLER_SIGSEGV;
EXPECT_EQ("sigchain_add_special_handler_008", signo, SIGSEGV);
}
}
/**
* @tc.name : sigchain_add_special_handler_008
* @tc.desc : Multiple signal are registered with the kernel(Using signal), call add_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_008()
{
signal(SIGSEGV, signal_handler);
signal(SIGHUP, signal_handler);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_008", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
}
int main(void)
{
sigchain_add_special_handler_008();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_add_special_handler_008", g_count, SIGCHAIN_CALL_CHECK_NUM);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_009", signo, SIGSEGV);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_009", signo, SIGHUP);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sigaction(int signo)
{
g_count++;
if (signo == SIGHUP) {
EXPECT_EQ("sigchain_add_special_handler_009", signo, SIGHUP);
} else {
EXPECT_EQ("sigchain_add_special_handler_009", signo, SIGSEGV);
}
}
/**
* @tc.name : sigchain_add_special_handler_009
* @tc.desc : Multiple signal are registered with the kernel(Using sigaction), call add_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_009()
{
struct sigaction sigac = {
.sa_handler = signal_sigaction,
};
sigaction(SIGSEGV, &sigac, NULL);
struct sigaction sigac1 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGHUP, &sigac1, NULL);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_009", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
}
int main(void)
{
sigchain_add_special_handler_009();
raise(SIGHUP);
EXPECT_EQ("sigchain_add_special_handler_009", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
raise(SIGSEGV);
EXPECT_EQ("sigchain_add_special_handler_009", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGHUP);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGABRT);
return true;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler3(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGSEGV);
return true;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler4(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGURG);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler5(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGSYS);
return true;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler6(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGCHAIN_SIGNAL_37);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler7(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGCHAIN_SIGNAL_43);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler8(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGCHAIN_SIGNAL_50);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler9(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGCHAIN_SIGNAL_56);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler10(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_010", signo, SIGCHAIN_SIGNAL_64);
return false;
}
/**
* @tc.name : sigchain_add_special_handler_010
* @tc.desc : Multiple different signals((Coverage signal range)) are not registered with the kernel,
* call add_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_010()
{
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler3,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sigurg = {
.sca_sigaction = sigchain_special_handler4,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGURG, &sigurg);
struct signal_chain_action sigsys = {
.sca_sigaction = sigchain_special_handler5,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSYS, &sigsys);
struct signal_chain_action sig37 = {
.sca_sigaction = sigchain_special_handler6,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_37, &sig37);
struct signal_chain_action sig43 = {
.sca_sigaction = sigchain_special_handler7,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_43, &sig43);
struct signal_chain_action sig50 = {
.sca_sigaction = sigchain_special_handler8,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_50, &sig50);
struct signal_chain_action sig56 = {
.sca_sigaction = sigchain_special_handler9,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_56, &sig56);
struct signal_chain_action sig64 = {
.sca_sigaction = sigchain_special_handler10,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_64, &sig64);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_10] = {SIGHUP, SIGABRT,
SIGSEGV, SIGURG, SIGSYS,
SIGCHAIN_SIGNAL_37,
SIGCHAIN_SIGNAL_43,
SIGCHAIN_SIGNAL_50,
SIGCHAIN_SIGNAL_56,
SIGCHAIN_SIGNAL_64};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_010", signo, SIGCHIAN_TEST_SIGNAL_NUM_10);
}
}
int main(void)
{
sigchain_add_special_handler_010();
raise(SIGHUP);
raise(SIGABRT);
raise(SIGSEGV);
raise(SIGURG);
raise(SIGSYS);
raise(SIGCHAIN_SIGNAL_37);
raise(SIGCHAIN_SIGNAL_43);
raise(SIGCHAIN_SIGNAL_50);
raise(SIGCHAIN_SIGNAL_56);
raise(SIGCHAIN_SIGNAL_64);
EXPECT_EQ("sigchain_add_special_handler_010", g_count, SIGCHIAN_TEST_SIGNAL_NUM_10);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGHUP);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGABRT);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler3(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGSEGV);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler4(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGURG);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler5(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGSYS);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler6(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_37);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler7(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_43);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler8(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_50);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler9(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_56);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler10(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_64);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
if (signo == SIGHUP) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGHUP);
} else if (signo == SIGABRT) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGABRT);
} else if (signo == SIGSEGV) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGSEGV);
} else if (signo == SIGURG) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGURG);
} else if (signo == SIGSYS) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGSYS);
} else if (signo == SIGCHAIN_SIGNAL_37) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_37);
} else if (signo == SIGCHAIN_SIGNAL_43) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_43);
} else if (signo == SIGCHAIN_SIGNAL_50) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_50);
} else if (signo ==SIGCHAIN_SIGNAL_56) {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_56);
} else {
EXPECT_EQ("sigchain_add_special_handler_011", signo, SIGCHAIN_SIGNAL_64);
}
}
/**
* @tc.name : sigchain_add_special_handler_011
* @tc.desc : Multiple different signals(Coverage signal range) are registered with the kernel(using signal),
* call add_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_011()
{
signal(SIGHUP, signal_handler);
signal(SIGABRT, signal_handler);
signal(SIGSEGV, signal_handler);
signal(SIGURG, signal_handler);
signal(SIGSYS, signal_handler);
signal(SIGCHAIN_SIGNAL_37, signal_handler);
signal(SIGCHAIN_SIGNAL_43, signal_handler);
signal(SIGCHAIN_SIGNAL_50, signal_handler);
signal(SIGCHAIN_SIGNAL_56, signal_handler);
signal(SIGCHAIN_SIGNAL_64, signal_handler);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler3,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sigurg = {
.sca_sigaction = sigchain_special_handler4,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGURG, &sigurg);
struct signal_chain_action sigsys = {
.sca_sigaction = sigchain_special_handler5,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSYS, &sigsys);
struct signal_chain_action sig37 = {
.sca_sigaction = sigchain_special_handler6,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_37, &sig37);
struct signal_chain_action sig43 = {
.sca_sigaction = sigchain_special_handler7,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_43, &sig43);
struct signal_chain_action sig50 = {
.sca_sigaction = sigchain_special_handler8,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_50, &sig50);
struct signal_chain_action sig56= {
.sca_sigaction = sigchain_special_handler9,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_56, &sig56);
struct signal_chain_action sig64 = {
.sca_sigaction = sigchain_special_handler10,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_64, &sig64);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_10] = {SIGHUP, SIGABRT, SIGSEGV,
SIGURG, SIGSYS,
SIGCHAIN_SIGNAL_37,
SIGCHAIN_SIGNAL_43,
SIGCHAIN_SIGNAL_50,
SIGCHAIN_SIGNAL_56,
SIGCHAIN_SIGNAL_64};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_011", signo, SIGCHIAN_TEST_SIGNAL_NUM_10);
}
}
int main(void)
{
sigchain_add_special_handler_011();
raise(SIGHUP);
raise(SIGABRT);
raise(SIGSEGV);
raise(SIGURG);
raise(SIGSYS);
raise(SIGCHAIN_SIGNAL_37);
raise(SIGCHAIN_SIGNAL_43);
raise(SIGCHAIN_SIGNAL_50);
raise(SIGCHAIN_SIGNAL_56);
raise(SIGCHAIN_SIGNAL_64);
EXPECT_EQ("sigchain_add_special_handler_011", g_count, SIGCHIAN_TEST_SIGNAL_NUM_10);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <signal.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGHUP);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGABRT);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler3(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGSEGV);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler4(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGURG);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler5(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGSYS);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler6(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_37);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler7(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_43);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler8(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_50);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler9(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_56);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler10(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_64);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sigaction(int signo)
{
if (signo == SIGHUP) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGHUP);
} else if (signo == SIGABRT) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGABRT);
} else if (signo == SIGSEGV) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGSEGV);
} else if (signo == SIGURG) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGURG);
} else if (signo == SIGSYS) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGSYS);
} else if (signo == SIGCHAIN_SIGNAL_37) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_37);
} else if (signo == SIGCHAIN_SIGNAL_43) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_43);
} else if (signo == SIGCHAIN_SIGNAL_50) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_50);
} else if (signo ==SIGCHAIN_SIGNAL_56) {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_56);
} else {
EXPECT_EQ("sigchain_add_special_handler_012", signo, SIGCHAIN_SIGNAL_64);
}
}
/**
* @tc.name : sigchain_add_special_handler_012
* @tc.desc : Multiple different signals(Coverage signal range) are registered with the kernel(using signal),
* call add_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_add_special_handler_012()
{
struct sigaction sigaction0 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGHUP, &sigaction0, NULL);
struct sigaction sigaction1 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGABRT, &sigaction1, NULL);
struct sigaction sigaction2 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGSEGV, &sigaction2, NULL);
struct sigaction sigaction3 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGURG, &sigaction3, NULL);
struct sigaction sigaction4 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGSYS, &sigaction4, NULL);
struct sigaction sigaction5 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGCHAIN_SIGNAL_37, &sigaction5, NULL);
struct sigaction sigaction6 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGCHAIN_SIGNAL_43, &sigaction6, NULL);
struct sigaction sigaction7 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGCHAIN_SIGNAL_50, &sigaction7, NULL);
struct sigaction sigaction8 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGCHAIN_SIGNAL_56, &sigaction8, NULL);
struct sigaction sigaction9 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGCHAIN_SIGNAL_64, &sigaction9, NULL);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler3,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sigurg = {
.sca_sigaction = sigchain_special_handler4,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGURG, &sigurg);
struct signal_chain_action sigsys = {
.sca_sigaction = sigchain_special_handler5,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGSYS, &sigsys);
struct signal_chain_action sig37 = {
.sca_sigaction = sigchain_special_handler6,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_37, &sig37);
struct signal_chain_action sig43 = {
.sca_sigaction = sigchain_special_handler7,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_43, &sig43);
struct signal_chain_action sig50 = {
.sca_sigaction = sigchain_special_handler8,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_50, &sig50);
struct signal_chain_action sig56 = {
.sca_sigaction = sigchain_special_handler9,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_56, &sig56);
struct signal_chain_action sig64 = {
.sca_sigaction = sigchain_special_handler10,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_64, &sig64);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_10] = {SIGHUP, SIGABRT, SIGSEGV, SIGURG, SIGSYS,
SIGCHAIN_SIGNAL_37,
SIGCHAIN_SIGNAL_43,
SIGCHAIN_SIGNAL_50,
SIGCHAIN_SIGNAL_56,
SIGCHAIN_SIGNAL_64};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_012", signo, SIGCHIAN_TEST_SIGNAL_NUM_10);
}
}
int main(void)
{
sigchain_add_special_handler_012();
raise(SIGHUP);
raise(SIGABRT);
raise(SIGSEGV);
raise(SIGURG);
raise(SIGSYS);
raise(SIGCHAIN_SIGNAL_37);
raise(SIGCHAIN_SIGNAL_43);
raise(SIGCHAIN_SIGNAL_50);
raise(SIGCHAIN_SIGNAL_56);
raise(SIGCHAIN_SIGNAL_64);
EXPECT_EQ("sigchain_add_special_handler_012", g_count, SIGCHIAN_TEST_SIGNAL_NUM_10);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
#define SIGCHAIN_CALL_SPECIAL_HANDLER_TAG 1
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_call_special_handler_001", signo, SIGSEGV);
g_count++;
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
EXPECT_EQ("sigchain_call_special_handler_001", signo, SIGSEGV);
EXPECT_EQ("sigchain_call_special_handler_001", g_count, SIGCHAIN_CALL_SPECIAL_HANDLER_TAG);
g_count++;
return;
}
/**
* @tc.name : sigchain_call_special_handler_001
* @tc.desc : Test the call order of the special handler and user's handler.
* @tc.level : Level 0
*/
static void sigchain_call_special_handler_001()
{
signal(SIGSEGV, signal_handler);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_call_special_handler_001", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
}
int main(void)
{
sigchain_call_special_handler_001();
raise(SIGSEGV);
EXPECT_EQ("sigchain_call_special_handler_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
......@@ -27,15 +27,13 @@ static int g_count = 0;
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_intercept_sigprocmask_005", signo, SIGHUP);
if (g_count == 0) {
sigset_t set = {0};
int signal[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGHUP, SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_001", signal, SIGCHIAN_TEST_SIGNAL_NUM_2);
raise(SIGSEGV);
g_count++;
}
return true;
EXPECT_EQ("sigchain_handler_call_order_001", signo, SIGHUP);
sigset_t set = {0};
int signal[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGHUP, SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_001", signal, SIGCHIAN_TEST_SIGNAL_NUM_2);
raise(SIGSEGV);
g_count++;
return false;
}
/**
......@@ -43,39 +41,31 @@ static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *uconte
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_intercept_sigprocmask_005", signo, SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigprocmask_005", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
EXPECT_EQ("sigchain_handler_call_order_001", signo, SIGSEGV);
EXPECT_EQ("sigchain_handler_call_order_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
g_count++;
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
g_count++;
EXPECT_TRUE("sigchain_intercept_sigprocmask_005", true);
EXPECT_TRUE("sigchain_handler_call_order_001", true);
}
/**
* @tc.name : sigchain_intercept_sigprocmask_005
* @tc.name : sigchain_handler_call_order_001
* @tc.desc : The signals are registered with the special handler, and mask and rasie the signal
* at the special handler. Test the influence of sigchain on sigprocmask.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_005()
static void sigchain_handler_call_order_001()
{
struct sigaction siga1 = {
.sa_handler = signal_handler,
};
sigaction(SIGSEGV, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler,
};
sigaction(SIGHUP, &siga2, NULL);
signal(SIGHUP, signal_handler);
signal(SIGSEGV, signal_handler);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler,
......@@ -91,19 +81,55 @@ static void sigchain_intercept_sigprocmask_005()
};
add_special_signal_handler(SIGSEGV, &sigsegv);
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGHUP, SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_005", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
raise(SIGHUP);
EXPECT_EQ("sigchain_handler_call_order_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler3(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_handler_call_order_002", signo, SIGSYS);
g_count++;
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler3(int signo)
{
EXPECT_EQ("sigchain_handler_call_order_002", signo, SIGSYS);
EXPECT_EQ("sigchain_handler_call_order_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_5);
g_count++;
return;
}
/**
* @tc.name : sigchain_handler_call_order_002
* @tc.desc : Add a special handler for a signal that is registered with
* the kernel (Using signal interface) in sigchain.
* @tc.level : Level 0
*/
static void sigchain_handler_call_order_002()
{
signal(SIGSYS, signal_handler3);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler3,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSYS, &sigsegv);
raise(SIGSYS);
EXPECT_EQ("sigchain_handler_call_order_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_6);
}
int main(void)
{
sigchain_intercept_sigprocmask_005();
raise(SIGHUP);
if (get_sigchain_mask_enable()) {
EXPECT_EQ("sigchain_intercept_sigprocmask_005", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
} else {
EXPECT_EQ("sigchain_intercept_sigprocmask_005", g_count, 0);
}
sigchain_handler_call_order_001();
sigchain_handler_call_order_002();
return t_status;
}
\ No newline at end of file
......@@ -14,6 +14,7 @@
*/
#include <sigchain.h>
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
......@@ -24,30 +25,37 @@ static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
static void signal_handler1(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_002", signo, SIGHUP);
return false;
EXPECT_EQ("sigchain_intercept_sigaction_001", signo, SIGHUP);
}
/**
* @brief the special handler
* @tc.name : sigchain_intercept_sigaction_001
* @tc.desc : The signals are not registered with the special handler, test the influence of sigchain
* on sigaction.
* @tc.level : Level 0
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
static void sigchain_intercept_sigaction_001()
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_002", signo, SIGSEGV);
return false;
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
raise(SIGHUP);
EXPECT_EQ("sigchain_intercept_sigaction_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
/**
* @brief the signal handler
* @brief the special handler
*/
static void signal_handler1(int signo)
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_002", signo, SIGHUP);
EXPECT_EQ("sigchain_intercept_sigaction_002", signo, SIGSEGV);
return false;
}
/**
......@@ -59,6 +67,7 @@ static void signal_handler2(int signo)
EXPECT_EQ("sigchain_intercept_sigaction_002", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_intercept_sigaction_002
* @tc.desc : The signals are registered with the special handler, test the influence of sigchain on sigaction.
......@@ -66,25 +75,13 @@ static void signal_handler2(int signo)
*/
static void sigchain_intercept_sigaction_002()
{
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
......@@ -92,17 +89,67 @@ static void sigchain_intercept_sigaction_002()
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigaction_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_3);
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler3(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_003", signo, SIGURG);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler3(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_003", signo, SIGURG);
}
/**
* @tc.name : sigchain_intercept_sigaction_003
* @tc.desc : the signals are registered with the special handler, and remove the special handler. Test
* the influence of sigchain on sigaction.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigaction_003()
{
struct signal_chain_action sigurg = {
.sca_sigaction = sigchain_special_handler3,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGURG, &sigurg);
struct sigaction siga2 = {
.sa_handler = signal_handler3,
};
sigaction(SIGURG, &siga2, NULL);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGURG};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGURG, sigchain_special_handler3);
raise(SIGURG);
EXPECT_EQ("sigchain_intercept_sigaction_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
}
int main(void)
{
sigchain_intercept_sigaction_001();
sigchain_intercept_sigaction_002();
raise(SIGHUP);
EXPECT_EQ("sigchain_intercept_sigaction_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigaction_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
sigchain_intercept_sigaction_003();
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static void signal_handler1(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_001", signo, SIGHUP);
}
/**
* @brief the special handler
*/
static void signal_handler2(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_001", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_intercept_sigaction_001
* @tc.desc : The signals are not registered with the special handler, test the influence of sigchain
* on sigaction.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigaction_001()
{
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
sigaction(SIGSEGV, &siga2, NULL);
}
int main(void)
{
sigchain_intercept_sigaction_001();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigaction_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_003", signo, SIGHUP);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_003", signo, SIGSEGV);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler1(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_003", signo, SIGHUP);
}
/**
* @brief the signal handler
*/
static void signal_handler2(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_003", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_intercept_sigaction_003
* @tc.desc : the signals are registered with the special handler, and remove the special handler. Test
* the influence of sigchain on sigaction.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigaction_003()
{
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
sigaction(SIGSEGV, &siga2, NULL);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
remove_special_signal_handler(SIGHUP, sigchain_special_handler);
remove_special_signal_handler(SIGSEGV, sigchain_special_handler1);
}
int main(void)
{
sigchain_intercept_sigaction_003();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigaction_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static void signal_handler1(int signo)
{
EXPECT_EQ("sigchain_intercept_sigaction_004", signo, SIGHUP);
sigset_t set = {0};
int signal[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_004", signal, SIGCHIAN_TEST_SIGNAL_NUM_2);
g_count++;
raise(SIGSEGV);
}
/**
* @brief the special handler
*/
static void signal_handler2(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigaction_004", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_intercept_sigaction_004
* @tc.desc : The signals are not registered with the special handler, and mask and rasie the signal
* at the special handler. Test the influence of sigchain on sigaction.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigaction_004()
{
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
sigaction(SIGSEGV, &siga2, NULL);
}
int main(void)
{
sigchain_intercept_sigaction_004();
raise(SIGHUP);
EXPECT_EQ("sigchain_intercept_sigaction_004", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
......@@ -14,6 +14,7 @@
*/
#include <sigchain.h>
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
......@@ -22,32 +23,34 @@
static int g_count = 0;
/**
* @brief the special handler
* @brief the signal handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
static void signal_handler1(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_002", signo, SIGHUP);
return false;
EXPECT_EQ("sigchain_intercept_signal_001", signo, SIGHUP);
}
/**
* @brief the special handler
* @tc.name : sigchain_add_special_handler_025
* @tc.desc : The signals are not registered with the special handler, test the influence of sigchain on signal
* @tc.level : Level 0
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
static void sigchain_intercept_signal_001()
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_002", signo, SIGSEGV);
return false;
signal(SIGHUP, signal_handler1);
raise(SIGHUP);
EXPECT_EQ("sigchain_intercept_signal_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
/**
* @brief the signal handler
* @brief the special handler
*/
static void signal_handler1(int signo)
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_002", signo, SIGHUP);
EXPECT_EQ("sigchain_intercept_signal_002", signo, SIGSEGV);
return false;
}
/**
......@@ -66,13 +69,6 @@ static void signal_handler2(int signo)
*/
static void sigchain_intercept_signal_002()
{
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
......@@ -80,21 +76,68 @@ static void sigchain_intercept_signal_002()
};
add_special_signal_handler(SIGSEGV, &sigsegv);
signal(SIGHUP, signal_handler1);
signal(SIGSEGV, signal_handler2);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_signal_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_signal_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_signal_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_3);
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler3(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_003", signo, SIGURG);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler3(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_003", signo, SIGURG);
}
/**
* @tc.name : sigchain_intercept_signal_003
* @tc.desc : The signals are registered with the special handler, and remove the special handler.
* Test the influence of sigchain on signal
* @tc.level : Level 0
*/
static void sigchain_intercept_signal_003()
{
struct signal_chain_action sigurg = {
.sca_sigaction = sigchain_special_handler3,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGURG, &sigurg);
signal(SIGURG, signal_handler3);
remove_special_signal_handler(SIGURG, sigchain_special_handler3);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGURG};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
raise(SIGURG);
EXPECT_EQ("sigchain_intercept_signal_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
}
int main(void)
{
sigchain_intercept_signal_001();
sigchain_intercept_signal_002();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_signal_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
sigchain_intercept_signal_003();
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the signal handler
*/
static void signal_handler1(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_001", signo, SIGHUP);
}
/**
* @brief the signal handler
*/
static void signal_handler2(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_001", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_add_special_handler_025
* @tc.desc : The signals are not registered with the special handler, test the influence of sigchain on signal
* @tc.level : Level 0
*/
static void sigchain_intercept_signal_001()
{
signal(SIGHUP, signal_handler1);
signal(SIGSEGV, signal_handler2);
}
int main(void)
{
sigchain_intercept_signal_001();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigaction_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_003", signo, SIGHUP);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_003", signo, SIGSEGV);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler1(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_003", signo, SIGHUP);
}
/**
* @brief the signal handler
*/
static void signal_handler2(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_signal_003", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_intercept_signal_003
* @tc.desc : The signals are registered with the special handler, and remove the special handler.
* Test the influence of sigchain on signal
* @tc.level : Level 0
*/
static void sigchain_intercept_signal_003()
{
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
signal(SIGHUP, signal_handler1);
signal(SIGSEGV, signal_handler2);
remove_special_signal_handler(SIGHUP, sigchain_special_handler);
remove_special_signal_handler(SIGSEGV, sigchain_special_handler1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
}
int main(void)
{
sigchain_intercept_signal_003();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_signal_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
......@@ -14,6 +14,7 @@
*/
#include <sigchain.h>
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
......@@ -21,98 +22,161 @@
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_intercept_sigprocmask_003", true);
EXPECT_EQ("sigchain_intercept_sigprocmask_001", signo, SIGSEGV);
return false;
}
/**
* @brief the special handler
* @brief the signal handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
static void signal_handler2(int signo)
{
g_count++;
EXPECT_FALSE("sigchain_intercept_sigprocmask_003", true);
return false;
EXPECT_EQ("sigchain_intercept_sigprocmask_001", signo, SIGSEGV);
}
/**
* @brief the signal handler
* @tc.name : sigchain_intercept_sigprocmask_001
* @tc.desc : The signals are registered with the special handler, test the influence of sigchain
* on sigprocmask.
* @tc.level : Level 0
*/
static void signal_handler1(int signo)
static void sigchain_intercept_sigprocmask_001()
{
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
sigaction(SIGSEGV, &siga2, NULL);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_001", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
raise(SIGSEGV);
if (get_sigchain_mask_enable()) {
EXPECT_EQ("sigchain_intercept_sigprocmask_001", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
} else {
EXPECT_EQ("sigchain_intercept_sigprocmask_001", g_count, 0);
}
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler3(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigprocmask_003", signo, SIGHUP);
EXPECT_FALSE("sigchain_intercept_sigprocmask_002", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler2(int signo)
static void signal_handler3(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigprocmask_003", signo, SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigprocmask_002", signo, SIGSYS);
}
/**
* @tc.name : sigchain_intercept_sigprocmask_003
* @tc.name : sigchain_intercept_sigprocmask_002
* @tc.desc : The signals are registered with the special handler, and remove the special handler.
* Test the influence of sigchain on sigprocmask.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_003()
static void sigchain_intercept_sigprocmask_002()
{
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
sigaction(SIGSEGV, &siga2, NULL);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
.sa_handler = signal_handler3,
};
add_special_signal_handler(SIGHUP, &sighup);
sigaction(SIGSYS, &siga2, NULL);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_sigaction = sigchain_special_handler3,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
add_special_signal_handler(SIGSYS, &sigsegv);
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGHUP, SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_003", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSYS};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
remove_special_signal_handler(SIGHUP, sigchain_special_handler);
remove_special_signal_handler(SIGSEGV, sigchain_special_handler1);
remove_special_signal_handler(SIGSYS, sigchain_special_handler3);
raise(SIGSYS);
if (get_sigchain_mask_enable()) {
EXPECT_EQ("sigchain_intercept_sigprocmask_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_3);
} else {
EXPECT_EQ("sigchain_intercept_sigprocmask_002", g_count, 0);
}
}
int main(void)
/**
* @brief the signal handler
*/
static void signal_handler1(int signo)
{
sigchain_intercept_sigprocmask_003();
g_count++;
EXPECT_FALSE("sigchain_intercept_sigprocmask_001", true);
}
/**
* @tc.name : sigchain_intercept_sigprocmask_003
* @tc.desc : The signals are not registered with the special handler, test the influence of sigchain
* on sigprocmask.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_003()
{
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_003", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
raise(SIGHUP);
if (get_sigchain_mask_enable()) {
EXPECT_EQ("sigchain_intercept_sigprocmask_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
} else {
EXPECT_EQ("sigchain_intercept_sigprocmask_003", g_count, 0);
}
raise(SIGSEGV);
if (get_sigchain_mask_enable()) {
EXPECT_EQ("sigchain_intercept_sigprocmask_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
EXPECT_EQ("sigchain_intercept_sigprocmask_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_3);
} else {
EXPECT_EQ("sigchain_intercept_sigprocmask_003", g_count, 0);
}
}
/**
* @tc.name : sigchain_intercept_sigprocmask_004
* @tc.desc : The new set is null, call sigprocmask.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_004()
{
int result = sigprocmask(SIG_BLOCK, NULL, NULL);
if (result != 0) {
EXPECT_FALSE("sigchain_intercept_sigprocmask_004", true);
}
}
int main(void)
{
sigchain_intercept_sigprocmask_001();
sigchain_intercept_sigprocmask_002();
sigchain_intercept_sigprocmask_003();
sigchain_intercept_sigprocmask_004();
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the signal handler
*/
static void signal_handler1(int signo)
{
g_count++;
EXPECT_FALSE("sigchain_intercept_sigprocmask_001", true);
}
/**
* @brief the signal handler
*/
static void signal_handler2(int signo)
{
g_count++;
EXPECT_FALSE("sigchain_intercept_sigprocmask_001", true);
}
/**
* @tc.name : sigchain_intercept_sigprocmask_001
* @tc.desc : The signals are not registered with the special handler, test the influence of sigchain
* on sigprocmask.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_001()
{
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
sigaction(SIGSEGV, &siga2, NULL);
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGHUP, SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_001", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
int main(void)
{
sigchain_intercept_sigprocmask_001();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigprocmask_001", g_count, 0);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigprocmask_002", signo, SIGHUP);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigprocmask_002", signo, SIGSEGV);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler1(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigprocmask_002", signo, SIGHUP);
}
/**
* @brief the signal handler
*/
static void signal_handler2(int signo)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigprocmask_002", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_intercept_sigprocmask_002
* @tc.desc : The signals are registered with the special handler, test the influence of sigchain
* on sigprocmask.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_002()
{
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
sigaction(SIGSEGV, &siga2, NULL);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGHUP, SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
int main(void)
{
sigchain_intercept_sigprocmask_002();
raise(SIGHUP);
if (get_sigchain_mask_enable()) {
EXPECT_EQ("sigchain_intercept_sigprocmask_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
} else {
EXPECT_EQ("sigchain_intercept_sigprocmask_002", g_count, 0);
}
raise(SIGSEGV);
if (get_sigchain_mask_enable()) {
EXPECT_EQ("sigchain_intercept_sigprocmask_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
} else {
EXPECT_EQ("sigchain_intercept_sigprocmask_002", g_count, 0);
}
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include <threads.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
g_count++;
}
/**
* @tc.name : sigchain_intercept_sigprocmask_004
* @tc.desc : The signals are registered with the special handler.Test the multiple threads call
* sigprocmask and add_special_signal_handler.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_004(int signo)
{
struct sigaction siga = {
.sa_handler = signal_handler,
};
sigaction(signo, &siga, NULL);
struct signal_chain_action sig_ca = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(signo, &sig_ca);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signal[SIGCHIAN_TEST_SIGNAL_NUM_1] = {signo};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_004", signal, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
}
void thread_func1(void *data)
{
sigchain_intercept_sigprocmask_004(SIGHUP);
}
void thread_func2(void *data)
{
sigchain_intercept_sigprocmask_004(SIGSEGV);
}
int main(void)
{
thrd_t t1, t2;
thrd_create(&t1, (thrd_start_t)thread_func1, NULL);
thrd_create(&t2, (thrd_start_t)thread_func2, NULL);
thrd_join(t1, NULL);
thrd_join(t2, NULL);
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigprocmask_004", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
/**
* @tc.name : sigchain_intercept_sigprocmask_006
* @tc.desc : The new set is null, call sigprocmask.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_006()
{
int result = sigprocmask(SIG_BLOCK, NULL, NULL);
if (result != 0) {
EXPECT_FALSE("sigchain_intercept_sigprocmask_006", true);
}
}
int main(void)
{
sigchain_intercept_sigprocmask_006();
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_EQ("sigchain_intercept_sigprocmask_007", signo, SIGSEGV);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
EXPECT_EQ("sigchain_intercept_sigprocmask_007", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
g_count++;
EXPECT_EQ("sigchain_intercept_sigprocmask_007", signo, SIGSEGV);
return;
}
/**
* @tc.name : sigchain_intercept_sigprocmask_007
* @tc.desc : The 'musl.sigchain.procmask' is false, call the sigprocmask
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_007()
{
signal(SIGSEGV, signal_handler);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_007", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
int main(void)
{
sigchain_intercept_sigprocmask_007();
raise(SIGSEGV);
if (get_sigchain_mask_enable()) {
EXPECT_EQ("sigchain_intercept_sigprocmask_007", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
} else {
EXPECT_EQ("sigchain_intercept_sigprocmask_007", g_count, 0);
}
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_sigabrt_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_001", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_sigabrt_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_001", true);
return true;
}
/**
* @tc.name : sigchain_rm_special_handler_001
* @tc.desc : The signal are not registered with the kernel, call remove_special_signal_handler to remove
* two special handlers
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_001()
{
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_sigabrt_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigabrt1 = {
.sca_sigaction = sigchain_special_sigabrt_handler2,
.sca_mask = {},
.sca_flags = SIGCHAIN_ALLOW_NORETURN,
};
add_special_signal_handler(SIGABRT, &sigabrt1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGABRT};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_001", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGABRT, sigchain_special_sigabrt_handler1);
remove_special_signal_handler(SIGABRT, sigchain_special_sigabrt_handler2);
raise(SIGABRT);
EXPECT_EQ("sigchain_rm_special_handler_001", g_count, 0);
}
/**
* @brief the special handler
*/
static bool sigchain_special_sighup_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_002", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_sighup_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_002", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sighup_handler(int signo)
{
g_count++;
EXPECT_EQ("sigchain_rm_special_handler_002", signo, SIGHUP);
}
/**
* @tc.name : sigchain_rm_special_handler_002
* @tc.desc : The signal are registered with the kernel(Using signal), call
* remove_special_signal_handler to remove two special handlers
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_002()
{
signal(SIGHUP, signal_sighup_handler);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_sighup_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sighup1 = {
.sca_sigaction = sigchain_special_sighup_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGHUP, sigchain_special_sighup_handler1);
remove_special_signal_handler(SIGHUP, sigchain_special_sighup_handler2);
raise(SIGHUP);
EXPECT_EQ("sigchain_rm_special_handler_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
/**
* @brief the special handler
*/
static bool sigchain_special_sigsegv_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_003", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_sigsegv_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_003", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sigsegv_sigaction(int signo)
{
g_count++;
EXPECT_EQ("sigchain_rm_special_handler_003", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_rm_special_handler_003
* @tc.desc : the signal that are registered with the kernel(Using sigaction), call
* remove_special_signal_handler to remove two special handlers
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_003()
{
struct sigaction sigac = {
.sa_handler = signal_sigsegv_sigaction,
};
sigaction(SIGSEGV, &sigac, NULL);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_sigsegv_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sigsegv2 = {
.sca_sigaction = sigchain_special_sigsegv_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv2);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_003", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGSEGV, sigchain_special_sigsegv_handler1);
remove_special_signal_handler(SIGSEGV, sigchain_special_sigsegv_handler2);
raise(SIGSEGV);
EXPECT_EQ("sigchain_rm_special_handler_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
/**
* @brief the special handler
*/
static bool sigchain_special_sigterm_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_004", true);
return true;
}
/**
* @tc.name : sigchain_rm_special_handler_004
* @tc.desc : the signal is not registered with the kernel, call remove_special_signal_handler to remove
* a special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_004()
{
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_sigterm_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGTERM, &sigsegv);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGTERM};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_004", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGTERM, sigchain_special_sigterm_handler);
raise(SIGTERM);
EXPECT_EQ("sigchain_rm_special_handler_004", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
/**
* @brief the special handler
*/
static bool sigchain_special_64_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_FALSE("sigchain_rm_special_handler_005", true);
g_count++;
return false;
}
/**
* @brief the signal handler
*/
static void signal_64_handler(int signo)
{
g_count++;
EXPECT_EQ("sigchain_rm_special_handler_005", signo, SIGCHAIN_SIGNAL_64);
}
/**
* @tc.name : sigchain_rm_special_handler_005
* @tc.desc : the signal is registered with the kernel(Using signal), call remove_special_signal_handler to remove
* a special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_005()
{
signal(SIGCHAIN_SIGNAL_64, signal_64_handler);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_64_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_64, &sighup);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGCHAIN_SIGNAL_64};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_005", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGCHAIN_SIGNAL_64, sigchain_special_64_handler);
raise(SIGCHAIN_SIGNAL_64);
EXPECT_EQ("sigchain_rm_special_handler_005", g_count, SIGCHIAN_TEST_SIGNAL_NUM_3);
}
/**
* @brief the special handler
*/
static bool sigchain_special_37_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_006", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_37_sigaction(int signo)
{
g_count++;
EXPECT_EQ("sigchain_rm_special_handler_006", signo, SIGCHAIN_SIGNAL_37);
}
/**
* @tc.name : sigchain_rm_special_handler_006
* @tc.desc : the signal is registered with the kernel(Using sigaction), call remove_special_signal_handler
* to remove a special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_006()
{
struct sigaction sigac = {
.sa_handler = signal_37_sigaction,
};
sigaction(SIGCHAIN_SIGNAL_37, &sigac, NULL);
struct signal_chain_action sig37 = {
.sca_sigaction = sigchain_special_37_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_37, &sig37);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGCHAIN_SIGNAL_37};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_006", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGCHAIN_SIGNAL_37, sigchain_special_37_handler);
raise(SIGCHAIN_SIGNAL_37);
EXPECT_EQ("sigchain_rm_special_handler_006", g_count, SIGCHIAN_TEST_SIGNAL_NUM_4);
}
int main(void)
{
sigchain_rm_special_handler_001();
sigchain_rm_special_handler_002();
sigchain_rm_special_handler_003();
sigchain_rm_special_handler_004();
sigchain_rm_special_handler_005();
sigchain_rm_special_handler_006();
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_001", true);
return false;
}
/**
* @tc.name : sigchain_rm_special_handler_001
* @tc.desc : The signal is not registered with the kernel, and add the special handler.
* Call the remove_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_001()
{
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sigsegv);
remove_special_signal_handler(SIGHUP, sigchain_special_handler);
}
int main(void)
{
sigchain_rm_special_handler_001();
raise(SIGHUP);
EXPECT_EQ("sigchain_rm_special_handler_001", g_count, 0);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_002", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
g_count++;
EXPECT_EQ("sigchain_rm_special_handler_002", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_rm_special_handler_002
* @tc.desc : The signal is registered with the kernel(using signal), and add the special handler.
* Call the remove_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_002()
{
signal(SIGSEGV, signal_handler);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_add_special_handler_002", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGSEGV, sigchain_special_handler);
}
int main(void)
{
sigchain_rm_special_handler_002();
raise(SIGSEGV);
EXPECT_EQ("sigchain_rm_special_handler_002", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_003", true);
return true;
}
/**
* @brief the signal handler
*/
static void signal_sigaction(int signo)
{
g_count++;
EXPECT_EQ("sigchain_rm_special_handler_003", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_rm_special_handler_003
* @tc.desc : The signal is registered with the kernel(using sigaction), and add the special handler.
* Call the remove_special_signal_handler
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_003()
{
struct sigaction sigsegv1 = {
.sa_handler = signal_sigaction,
};
sigaction(SIGSEGV, &sigsegv1, NULL);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_003", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGSEGV, sigchain_special_handler);
}
int main(void)
{
sigchain_rm_special_handler_003();
raise(SIGSEGV);
EXPECT_EQ("sigchain_rm_special_handler_003", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_004", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_004", true);
return false;
}
/**
* @tc.name : sigchain_rm_special_handler_004
* @tc.desc : The signal is not registered with the kernel, and add two special handler.
* Call the remove_special_signal_handler to remove the two special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_004()
{
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigabrt1 = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGABRT};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_004", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGABRT, sigchain_special_handler2);
remove_special_signal_handler(SIGABRT, sigchain_special_handler1);
}
int main(void)
{
sigchain_rm_special_handler_004();
raise(SIGABRT);
EXPECT_EQ("sigchain_rm_special_handler_004", g_count, 0);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_005", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_005", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
g_count++;
EXPECT_EQ("sigchain_rm_special_handler_005", signo, SIGABRT);
}
/**
* @tc.name : sigchain_rm_special_handler_005
* @tc.desc : The signal is registered with the kernel(using signal), and add two special handler.
* Call the remove_special_signal_handler to remove the two special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_005()
{
signal(SIGABRT, signal_handler);
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigabrt1 = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt1);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGABRT};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_005", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGABRT, sigchain_special_handler2);
remove_special_signal_handler(SIGABRT, sigchain_special_handler1);
}
int main(void)
{
sigchain_rm_special_handler_005();
raise(SIGABRT);
EXPECT_EQ("sigchain_rm_special_handler_005", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_006", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_006", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sigaction(int signo)
{
g_count++;
EXPECT_EQ("sigchain_rm_special_handler_006", signo, SIGABRT);
}
/**
* @tc.name : sigchain_rm_special_handler_006
* @tc.desc : The signal is registered with the kernel(using sigaction), and add two special handler.
* Call the remove_special_signal_handler to remove the two special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_006()
{
struct sigaction sigac = {
.sa_handler = signal_sigaction,
};
sigaction(SIGABRT, &sigac, NULL);
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigabrt2 = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt2);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_1] = {SIGABRT};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_006", signo, SIGCHIAN_TEST_SIGNAL_NUM_1);
}
remove_special_signal_handler(SIGABRT, sigchain_special_handler2);
remove_special_signal_handler(SIGABRT, sigchain_special_handler1);
}
int main(void)
{
sigchain_rm_special_handler_006();
raise(SIGABRT);
EXPECT_EQ("sigchain_rm_special_handler_006", g_count, SIGCHIAN_TEST_SIGNAL_NUM_1);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_007", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_007", true);
return false;
}
/**
* @tc.name : sigchain_rm_special_handler_007
* @tc.desc : The two signals are not registered with the kernel, and add the special handler for the two signals.
* Call the remove_special_signal_handler to remove the two signal's special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_007()
{
struct signal_chain_action sig64 = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_64, &sig64);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGCHAIN_SIGNAL_64, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_007", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
remove_special_signal_handler(SIGHUP, sigchain_special_handler2);
remove_special_signal_handler(SIGCHAIN_SIGNAL_64, sigchain_special_handler1);
}
int main(void)
{
sigchain_rm_special_handler_007();
raise(SIGHUP);
raise(SIGCHAIN_SIGNAL_64);
EXPECT_EQ("sigchain_rm_special_handler_007", g_count, 0);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_008", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_008", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_handler(int signo)
{
g_count++;
if (signo == SIGHUP) {
EXPECT_EQ("sigchain_rm_special_handler_008", signo, SIGHUP);
} else {
EXPECT_EQ("sigchain_rm_special_handler_008", signo, SIGSEGV);
}
}
/**
* @tc.name : sigchain_rm_special_handler_008
* @tc.desc : The two signals are registered with the kernel(using signal), and add the special handler for
* the two signals. Call the remove_special_signal_handler to remove the two signal's special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_008()
{
signal(SIGSEGV, signal_handler);
signal(SIGHUP, signal_handler);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_008", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
remove_special_signal_handler(SIGHUP, sigchain_special_handler2);
remove_special_signal_handler(SIGSEGV, sigchain_special_handler1);
}
int main(void)
{
sigchain_rm_special_handler_008();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_rm_special_handler_008", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_009", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_009", true);
return false;
}
/**
* @brief the signal handler
*/
static void signal_sigaction(int signo)
{
g_count++;
if (signo == SIGHUP) {
EXPECT_EQ("sigchain_rm_special_handler_009", signo, SIGHUP);
} else {
EXPECT_EQ("sigchain_rm_special_handler_009", signo, SIGSEGV);
}
}
/**
* @tc.name : sigchain_rm_special_handler_008
* @tc.desc : The two signals are registered with the kernel(using sigaction), and add the special handler for
* the two signals. Call the remove_special_signal_handler to remove the two signal's special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_009()
{
struct sigaction sigac_segv = {
.sa_handler = signal_sigaction,
};
sigaction(SIGSEGV, &sigac_segv, NULL);
struct sigaction sigac_hup = {
.sa_handler = signal_sigaction,
};
sigaction(SIGHUP, &sigac_hup, NULL);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
if (get_sigchain_mask_enable()) {
sigset_t set = {0};
int signo[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_rm_special_handler_009", signo, SIGCHIAN_TEST_SIGNAL_NUM_2);
}
remove_special_signal_handler(SIGHUP, sigchain_special_handler2);
remove_special_signal_handler(SIGSEGV, sigchain_special_handler1);
}
int main(void)
{
sigchain_rm_special_handler_009();
raise(SIGHUP);
raise(SIGSEGV);
EXPECT_EQ("sigchain_rm_special_handler_009", g_count, SIGCHIAN_TEST_SIGNAL_NUM_2);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* 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.
*/
#include <sigchain.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
static int g_count = 0;
/**
* @brief the special handler
*/
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler2(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler3(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler4(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler5(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler6(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler7(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler8(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler9(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @brief the special handler
*/
static bool sigchain_special_handler10(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
g_count++;
EXPECT_FALSE("sigchain_rm_special_handler_010", true);
return false;
}
/**
* @tc.name : sigchain_rm_special_handler_010
* @tc.desc : The multiple signals(Coverage signal range) are not registered with the kernel,
* and add the special handler. Call the remove_special_signal_handler to remove
* the signals's special handler.
* @tc.level : Level 0
*/
static void sigchain_rm_special_handler_010()
{
struct signal_chain_action sighup = {
.sca_sigaction = sigchain_special_handler1,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGHUP, &sighup);
struct signal_chain_action sigabrt = {
.sca_sigaction = sigchain_special_handler2,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGABRT, &sigabrt);
struct signal_chain_action sigsegv = {
.sca_sigaction = sigchain_special_handler3,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSEGV, &sigsegv);
struct signal_chain_action sigurg = {
.sca_sigaction = sigchain_special_handler4,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGURG, &sigurg);
struct signal_chain_action sigsys = {
.sca_sigaction = sigchain_special_handler5,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGSYS, &sigsys);
struct signal_chain_action sig37 = {
.sca_sigaction = sigchain_special_handler6,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_37, &sig37);
struct signal_chain_action sig43 = {
.sca_sigaction = sigchain_special_handler7,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_43, &sig43);
struct signal_chain_action sig50 = {
.sca_sigaction = sigchain_special_handler8,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_50, &sig50);
struct signal_chain_action sig56 = {
.sca_sigaction = sigchain_special_handler9,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_56, &sig56);
struct signal_chain_action sig64 = {
.sca_sigaction = sigchain_special_handler10,
.sca_mask = {},
.sca_flags = 0,
};
add_special_signal_handler(SIGCHAIN_SIGNAL_64, &sig64);
remove_special_signal_handler(SIGHUP, sigchain_special_handler1);
remove_special_signal_handler(SIGABRT, sigchain_special_handler2);
remove_special_signal_handler(SIGSEGV, sigchain_special_handler3);
remove_special_signal_handler(SIGURG, sigchain_special_handler4);
remove_special_signal_handler(SIGSYS, sigchain_special_handler5);
remove_special_signal_handler(SIGCHAIN_SIGNAL_37, sigchain_special_handler6);
remove_special_signal_handler(SIGCHAIN_SIGNAL_43, sigchain_special_handler7);
remove_special_signal_handler(SIGCHAIN_SIGNAL_50, sigchain_special_handler8);
remove_special_signal_handler(SIGCHAIN_SIGNAL_56, sigchain_special_handler9);
remove_special_signal_handler(SIGCHAIN_SIGNAL_64, sigchain_special_handler10);
raise(SIGCHAIN_SIGNAL_37);
raise(SIGCHAIN_SIGNAL_43);
raise(SIGCHAIN_SIGNAL_50);
raise(SIGCHAIN_SIGNAL_56);
raise(SIGCHAIN_SIGNAL_64);
}
int main(void)
{
sigchain_rm_special_handler_010();
EXPECT_EQ("sigchain_rm_special_handler_010", g_count, 0);
return t_status;
}
\ No newline at end of file
......@@ -11,43 +11,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
functionalext_sigchain_list = [
"sigchain_add_special_handler_a",
"sigchain_add_special_handler_b",
"sigchain_add_special_handler_c",
"sigchain_add_special_handler_d",
"sigchain_add_special_handler_e",
"sigchain_add_special_handler_f",
"sigchain_add_special_handler_g",
"sigchain_add_special_handler_h",
"sigchain_add_special_handler_i",
"sigchain_add_special_handler_j",
"sigchain_add_special_handler_k",
"sigchain_add_special_handler_l",
"sigchain_rm_special_handler_a",
"sigchain_rm_special_handler_b",
"sigchain_rm_special_handler_c",
"sigchain_rm_special_handler_d",
"sigchain_rm_special_handler_e",
"sigchain_rm_special_handler_f",
"sigchain_rm_special_handler_g",
"sigchain_rm_special_handler_h",
"sigchain_rm_special_handler_i",
"sigchain_rm_special_handler_j",
"sigchain_rm_special_handler_k",
"sigchain_rm_special_handler_l",
"sigchain_intercept_sigaction_a",
"sigchain_intercept_sigaction_b",
"sigchain_intercept_sigaction_c",
"sigchain_intercept_sigaction_d",
"sigchain_intercept_signal_a",
"sigchain_intercept_signal_b",
"sigchain_intercept_signal_c",
"sigchain_intercept_sigprocmask_a",
"sigchain_intercept_sigprocmask_b",
"sigchain_intercept_sigprocmask_c",
"sigchain_intercept_sigprocmask_d",
"sigchain_intercept_sigprocmask_e",
"sigchain_intercept_sigprocmask_f",
"sigchain_intercept_sigprocmask_g",
"sigchain_call_special_handler_a",
"sigchain_add_special_handler",
"sigchain_rm_special_handler",
"sigchain_intercept_sigaction",
"sigchain_intercept_signal",
"sigchain_intercept_sigprocmask",
"sigchain_handler_call_order",
]
......@@ -236,8 +236,6 @@ template("test_unittest") {
if (target_dir == "functionalext/sigchain") {
include_dirs += [ "//${musl_base_dir}/include" ]
ldflags += [ "-Wl,-rpath=./" ]
}
}
}
......
......@@ -14,12 +14,11 @@ static const char *param_name = "musl.sigchain.procmask";
bool get_sigchain_mask_enable()
{
#ifdef OHOS_ENABLE_PARAMETER
static CachedHandle musl_log_Handle = NULL;
if (musl_log_Handle == NULL) {
musl_log_Handle = CachedParameterCreate(param_name, "false");
static CachedHandle sigchain_procmask_handle = NULL;
if (sigchain_procmask_handle == NULL) {
sigchain_procmask_handle = CachedParameterCreate(param_name, "false");
}
char *param_value = CachedParameterGet(musl_log_Handle);
char *param_value = CachedParameterGet(sigchain_procmask_handle);
if (param_value != NULL) {
if (strcmp(param_value, "true") == 0) {
return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册