diff options
author | Joel Sherrill <joel@rtems.org> | 2019-09-10 12:53:31 -0500 |
---|---|---|
committer | Joel Sherrill <joel@rtems.org> | 2019-09-24 16:27:57 -0500 |
commit | 8798372261ed1df999bc9f4f3f0be0a230480041 (patch) | |
tree | 0762d89609e1bb4717335838f56b254fdaaba2e9 /testsuites/psxtests/psxsignal07 | |
parent | rtems: Add rtems_interrupt_server_entry_move() (diff) | |
download | rtems-8798372261ed1df999bc9f4f3f0be0a230480041.tar.bz2 |
Correct initial POSIX signals mask
+ Modify POSIX thread create extension to ensure expected
initial signal mask is provided to system threads, initial
tasks and threads, and inheritied by tasks and threads.
+ Adds psxsignal07 to verify functionality when using a POSIX
Initialization thread and POSIX threads.
+ Adds psxsignal08 to verify functionality when using a Classic API
Initialization task and Classic API tasks.
Closes #3794.
Diffstat (limited to 'testsuites/psxtests/psxsignal07')
-rw-r--r-- | testsuites/psxtests/psxsignal07/main.c | 136 | ||||
-rw-r--r-- | testsuites/psxtests/psxsignal07/psxsignal07.doc | 23 | ||||
-rw-r--r-- | testsuites/psxtests/psxsignal07/psxsignal07.scn | 7 | ||||
-rw-r--r-- | testsuites/psxtests/psxsignal07/rtems_config.c | 44 |
4 files changed, 210 insertions, 0 deletions
diff --git a/testsuites/psxtests/psxsignal07/main.c b/testsuites/psxtests/psxsignal07/main.c new file mode 100644 index 0000000000..52b21751c8 --- /dev/null +++ b/testsuites/psxtests/psxsignal07/main.c @@ -0,0 +1,136 @@ +/* + * @brief psxsignal07 - Ensure initial signal mask and thread inheritance + */ + +/* + * COPYRIGHT (c) 2019. + * On-Line Applications Research Corporation (OAR). + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <tmacros.h> +#include "test_support.h" +#include <errno.h> +#include <pthread.h> +#include <signal.h> + +const char rtems_test_name[] = "PSXSIGNAL 7"; + +static sigset_t main_sigmask; + +#define SIGSET_NBYTES (sizeof(sigset_t)) + +/* #define DEBUG_TEST */ + +static void fetch_sigmask(const char *name, sigset_t *sigset_p) +{ + int rc; + + rc = sigemptyset(sigset_p); + rtems_test_assert(rc == 0); + + rc = sigprocmask(SIG_SETMASK, NULL, sigset_p); + rtems_test_assert(rc == 0); + +#ifdef DEBUG_TEST + /* + * There is no assurance that sigset_t is a primitive type so + * we have to print it a long at a time. + */ + int i; + unsigned char *p = (unsigned char *) sigset_p; + + printf("%s signal mask (in hex):\n ", name); + for (i=0 ; i < SIGSET_NBYTES ; i++) { + printf("%02x%s", *p++, (i % 16 == 15) ? "\n " : " "); + } + printf("\n"); +#endif +} + +static void block_sigmask(int signo, sigset_t *sigset_p) +{ + sigset_t sigset; + int rc; + + /* + * Block the requested signal + */ + rc = sigemptyset(&sigset); + rtems_test_assert(rc == 0); + rc = sigaddset(&sigset, signo); + rtems_test_assert(rc == 0); + + rc = sigprocmask(SIG_BLOCK, &sigset, NULL); + rtems_test_assert(rc == 0); + + /* + * Fetch the current signal mask reflecting the requested update + */ + sigemptyset(sigset_p); + rc = sigprocmask(SIG_SETMASK, NULL, sigset_p); + rtems_test_assert(rc == 0); +} + +static void *thread_body(void *arg) +{ + sigset_t mask; + + /* + * There is no assurance that sigset_t is a primitive type so + * we have to use memcmp(). + */ + fetch_sigmask("main", &main_sigmask); + fetch_sigmask(arg, &mask); + rtems_test_assert(main_sigmask == mask); + + return NULL; +} + +int main(int argc, char **argv) +{ + int rc; + pthread_t id; + sigset_t empty; + + TEST_BEGIN(); + + /* + * Verify first thread has empty signal mask + */ + fetch_sigmask("main", &main_sigmask); + + sigemptyset(&empty); + fetch_sigmask("empty", &empty); + + puts("Ensure main thread's mask equals sigemptyset"); + rtems_test_assert(main_sigmask == empty); + + /* + * Verify first thread has empty signal mask + */ + puts("Ensure parent's empty mask is inherited by thread"); + rc = pthread_create(&id, NULL, thread_body, "thread1"); + rtems_test_assert(rc == 0); + sleep(1); + + /* + * Create a thread and see if it inherits non-empty signal mask. + */ + puts("Ensure parent's mask with SIGUSR1 mask is inherited by thread"); + block_sigmask(SIGUSR1, &main_sigmask); + rc = pthread_create(&id, NULL, thread_body, "thread2"); + rtems_test_assert(rc == 0); + sleep(1); + + TEST_END(); + + rtems_test_exit(0); + return 0; +} + diff --git a/testsuites/psxtests/psxsignal07/psxsignal07.doc b/testsuites/psxtests/psxsignal07/psxsignal07.doc new file mode 100644 index 0000000000..78425471f7 --- /dev/null +++ b/testsuites/psxtests/psxsignal07/psxsignal07.doc @@ -0,0 +1,23 @@ +# COPYRIGHT (c) 2019. +# On-Line Applications Research Corporation (OAR). +# +# SPDX-License-Identifier: BSD-2-Clause +# + +This file describes the directives and concepts tested by this test set. + +test set name: psxsignal07 + +directives: + + sigprocmask + sigemptyset + sigaddset + +concepts: + ++ Ensure that the initial signal mask is empty (all unmasked). + ++ Ensure that a POSIX thread inherits an empty signal mask. + ++ Ensure that a POSIX thread inherits an non-empty signal mask. diff --git a/testsuites/psxtests/psxsignal07/psxsignal07.scn b/testsuites/psxtests/psxsignal07/psxsignal07.scn new file mode 100644 index 0000000000..ad7a12deda --- /dev/null +++ b/testsuites/psxtests/psxsignal07/psxsignal07.scn @@ -0,0 +1,7 @@ +*** BEGIN OF TEST PSXSIGNAL 7 *** +Ensure main thread's mask equals sigemptyset +Ensure parent's empty mask is inherited by thread +Ensure parent's mask with SIGUSR1 mask is inherited by thread + +*** END OF TEST PSXSIGNAL 7 *** + diff --git a/testsuites/psxtests/psxsignal07/rtems_config.c b/testsuites/psxtests/psxsignal07/rtems_config.c new file mode 100644 index 0000000000..e3f3349640 --- /dev/null +++ b/testsuites/psxtests/psxsignal07/rtems_config.c @@ -0,0 +1,44 @@ +/* + * COPYRIGHT (c) 2019. + * On-Line Applications Research Corporation (OAR). + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <stdlib.h> + +int main(int argc, char **argv); + +static char *argv_list[] = { + "psxsignal07", + "" +}; +static void *POSIX_Init(void *arg) +{ + (void) arg; /* deliberately ignored */ + + /* + * Initialize optional services + */ + + /* + * Could get arguments from command line or have a static set. + */ + (void) main(1, argv_list); + + return NULL; +} + +#include <bsp.h> /* for device driver prototypes */ + +/* NOTICE: the clock driver is explicitly disabled */ +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_UNIFIED_WORK_AREAS + +#define CONFIGURE_INIT +#include <rtems/confdefs.h> |