From 5db71f0309465c591107f243876909fa42470dcd Mon Sep 17 00:00:00 2001 From: dhy308 Date: Mon, 13 Feb 2023 10:16:45 +0800 Subject: [PATCH] Fix review issues. Issue: I6AEEI Test: Build & Boot Devices Signed-off-by: dhy308 --- .../src/functionalext/common/sigchain_util.h | 6 +- .../sigchain/sigchain_intercept_sigaction_d.c | 68 +++++++++++++++++++ .../sigchain_intercept_sigprocmask_e.c | 6 +- .../sigchain_intercept_sigprocmask_f.c | 40 +++++++++++ .../test_src_functionalext_sigchain.gni | 2 + porting/linux/user/src/signal/sigprocmask.c | 13 ++-- 6 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 libc-test/src/functionalext/sigchain/sigchain_intercept_sigaction_d.c create mode 100644 libc-test/src/functionalext/sigchain/sigchain_intercept_sigprocmask_f.c diff --git a/libc-test/src/functionalext/common/sigchain_util.h b/libc-test/src/functionalext/common/sigchain_util.h index 5516b97f..21235afc 100644 --- a/libc-test/src/functionalext/common/sigchain_util.h +++ b/libc-test/src/functionalext/common/sigchain_util.h @@ -16,17 +16,17 @@ #define SIGCHAIN_TEST_SET_MASK(set, fun, signo, num) do{ \ int result = sigemptyset(&set); \ if (result != 0) { \ - EXPECT_FALSE(fun, (result == 0)); \ + EXPECT_FALSE(fun, true); \ } \ for (int i = 0; i < num; i++) { \ result = sigaddset(&set, signo[i]); \ if (result != 0) { \ - EXPECT_FALSE(fun, (result == 0)); \ + EXPECT_FALSE(fun, true); \ } \ } \ result = sigprocmask(SIG_BLOCK, &set, NULL); \ if (result != 0) { \ - EXPECT_FALSE(fun, (result == 0)); \ + EXPECT_FALSE(fun, true); \ } \ } while (0) diff --git a/libc-test/src/functionalext/sigchain/sigchain_intercept_sigaction_d.c b/libc-test/src/functionalext/sigchain/sigchain_intercept_sigaction_d.c new file mode 100644 index 00000000..441c615b --- /dev/null +++ b/libc-test/src/functionalext/sigchain/sigchain_intercept_sigaction_d.c @@ -0,0 +1,68 @@ +/* + * 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 +#include +#include +#include "test.h" +#include "functionalext.h" +#include "sigchain_util.h" + +/** + * @brief the special handler + */ +static void signal_handler1(int signo) +{ + EXPECT_EQ("sigchain_intercept_sigaction_001", signo, SIGHUP); + sigset_t set = {0}; + int signal[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP}; + SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_002", signal, SIGCHIAN_TEST_SIGNAL_NUM_2); + + raise(SIGSEGV); +} + +/** + * @brief the special handler + */ +static void signal_handler2(int signo) +{ + EXPECT_EQ("sigchain_intercept_sigaction_001", signo, SIGSEGV); +} + +/** + * @tc.name : sigchain_intercept_sigaction_004 + * @tc.desc : Test the influence of sigchain on sigaction, the signals are not registered with + * the special handler, and mask and rasie the signal at the special handler + * @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); + return t_status; +} \ No newline at end of file diff --git a/libc-test/src/functionalext/sigchain/sigchain_intercept_sigprocmask_e.c b/libc-test/src/functionalext/sigchain/sigchain_intercept_sigprocmask_e.c index 5300e825..b9f9b5e9 100644 --- a/libc-test/src/functionalext/sigchain/sigchain_intercept_sigprocmask_e.c +++ b/libc-test/src/functionalext/sigchain/sigchain_intercept_sigprocmask_e.c @@ -32,6 +32,7 @@ static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *uconte 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,6 +44,7 @@ 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, 1); return false; } @@ -59,7 +61,7 @@ static void signal_handler(int signo) /** * @tc.name : sigchain_intercept_sigprocmask_005 * @tc.desc : Test the influence of sigchain on sigprocmask, the signals are registered with - * the special handler + * the special handler, and mask and rasie the signal at the special handler * @tc.level : Level 0 */ static void sigchain_intercept_sigprocmask_005() @@ -97,7 +99,5 @@ int main(void) { sigchain_intercept_sigprocmask_005(); raise(SIGHUP); - raise(SIGSEGV); - raise(SIGHUP); return t_status; } \ No newline at end of file diff --git a/libc-test/src/functionalext/sigchain/sigchain_intercept_sigprocmask_f.c b/libc-test/src/functionalext/sigchain/sigchain_intercept_sigprocmask_f.c new file mode 100644 index 00000000..bbdea2e8 --- /dev/null +++ b/libc-test/src/functionalext/sigchain/sigchain_intercept_sigprocmask_f.c @@ -0,0 +1,40 @@ +/* + * 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 +#include +#include +#include "test.h" +#include "functionalext.h" +#include "sigchain_util.h" + +/** + * @tc.name : sigchain_intercept_sigprocmask_006 + * @tc.desc : Test the influence of sigchain on sigprocmask, the new set is null. + * @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 diff --git a/libc-test/src/functionalext/sigchain/test_src_functionalext_sigchain.gni b/libc-test/src/functionalext/sigchain/test_src_functionalext_sigchain.gni index f67179f1..1e81d0cc 100644 --- a/libc-test/src/functionalext/sigchain/test_src_functionalext_sigchain.gni +++ b/libc-test/src/functionalext/sigchain/test_src_functionalext_sigchain.gni @@ -38,6 +38,7 @@ functionalext_sigchain_list = [ "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", @@ -46,5 +47,6 @@ functionalext_sigchain_list = [ "sigchain_intercept_sigprocmask_c", "sigchain_intercept_sigprocmask_d", "sigchain_intercept_sigprocmask_e", + "sigchain_intercept_sigprocmask_f", "sigchain_call_special_handler_a", ] diff --git a/porting/linux/user/src/signal/sigprocmask.c b/porting/linux/user/src/signal/sigprocmask.c index b018058a..b83dc403 100644 --- a/porting/linux/user/src/signal/sigprocmask.c +++ b/porting/linux/user/src/signal/sigprocmask.c @@ -6,10 +6,15 @@ extern void intercept_sigprocmask(int how, sigset_t *restrict set); int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old) { - sigset_t tmpset = *set; - intercept_sigprocmask(how, &tmpset); - const sigset_t *new_set_ptr = &tmpset; - int r = pthread_sigmask(how, new_set_ptr, old); + int r = 0; + if (set) { + sigset_t tmpset = *set; + intercept_sigprocmask(how, &tmpset); + const sigset_t *new_set_ptr = &tmpset; + r = pthread_sigmask(how, new_set_ptr, old); + } else { + r = pthread_sigmask(how, set, old); + } if (!r) return r; errno = r; return -1; -- GitLab