From 901b8099a28f94855a37df2582993ca64586c82e Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Thu, 5 Dec 2024 17:00:10 -0800 Subject: [PATCH] add stdint.h to test_helpers add tests for signals --- tests/signals/kill-child.c | 100 ++++++++++ tests/signals/kill-invalid.c | 29 +++ tests/signals/kill-permission.c | 27 +++ tests/signals/kill-self.c | 59 ++++++ tests/signals/kill0-self.c | 16 ++ tests/signals/killpg-child.c | 88 +++++++++ tests/signals/killpg-esrch.c | 25 +++ tests/signals/killpg-invalid.c | 31 ++++ tests/signals/killpg-self.c | 56 ++++++ tests/signals/killpg0-self.c | 24 +++ tests/signals/pthread_kill-child.c | 56 ++++++ tests/signals/pthread_kill-invalid.c | 21 +++ tests/signals/pthread_kill-self.c | 103 +++++++++++ tests/signals/pthread_kill0-self.c | 20 ++ tests/signals/raise-compliance.c | 49 +++++ tests/signals/sigaddset-add.c | 40 ++++ tests/signals/sigdelset-delete.c | 40 ++++ tests/signals/sigismember-invalid.c | 25 +++ tests/signals/sigismember-valid.c | 35 ++++ tests/signals/signal-h-2.c | 32 ++++ tests/signals/signal-h.c | 232 ++++++++++++++++++++++++ tests/signals/signal-handle_return.c | 35 ++++ tests/signals/signal-handler.c | 35 ++++ tests/signals/signal-handler2.c | 42 +++++ tests/signals/signal-ignore.c | 47 +++++ tests/signals/signal-invalid.c | 27 +++ tests/signals/signal-uncatchable.c | 27 +++ tests/signals/signals_list.h | 79 ++++++++ tests/signals/sigpause-error.c | 102 +++++++++++ tests/signals/sigpause-invalid.c | 52 ++++++ tests/signals/sigpause-pause.c | 77 ++++++++ tests/signals/sigpause-revert.c | 106 +++++++++++ tests/signals/sigpause-suspend.c | 91 ++++++++++ tests/signals/sigprocmask-10.c | 65 +++++++ tests/signals/sigprocmask-11.c | 22 +++ tests/signals/sigprocmask-12.c | 56 ++++++ tests/signals/sigprocmask-3.c | 110 +++++++++++ tests/signals/sigprocmask-4.c | 42 +++++ tests/signals/sigprocmask-5.c | 47 +++++ tests/signals/sigprocmask-6.c | 47 +++++ tests/signals/sigprocmask-7.c | 46 +++++ tests/signals/sigprocmask-8.c | 60 ++++++ tests/signals/sigprocmask-9.c | 32 ++++ tests/signals/sigprocmask-block.c | 93 ++++++++++ tests/signals/sigprocmask-blocksingle.c | 79 ++++++++ tests/signals/sigrelse-1.c | 73 ++++++++ tests/signals/sigrelse-2.c | 16 ++ tests/signals/sigrelse-3.c | 20 ++ tests/signals/sigset-1.c | 48 +++++ tests/signals/sigset-10.c | 21 +++ tests/signals/sigset-2.c | 54 ++++++ tests/signals/sigset-3.c | 45 +++++ tests/signals/sigset-4.c | 56 ++++++ tests/signals/sigset-5.c | 65 +++++++ tests/signals/sigset-9.c | 45 +++++ tests/test_helpers.h | 1 + 56 files changed, 2971 insertions(+) create mode 100644 tests/signals/kill-child.c create mode 100644 tests/signals/kill-invalid.c create mode 100644 tests/signals/kill-permission.c create mode 100644 tests/signals/kill-self.c create mode 100644 tests/signals/kill0-self.c create mode 100644 tests/signals/killpg-child.c create mode 100644 tests/signals/killpg-esrch.c create mode 100644 tests/signals/killpg-invalid.c create mode 100644 tests/signals/killpg-self.c create mode 100644 tests/signals/killpg0-self.c create mode 100644 tests/signals/pthread_kill-child.c create mode 100644 tests/signals/pthread_kill-invalid.c create mode 100644 tests/signals/pthread_kill-self.c create mode 100644 tests/signals/pthread_kill0-self.c create mode 100644 tests/signals/raise-compliance.c create mode 100644 tests/signals/sigaddset-add.c create mode 100644 tests/signals/sigdelset-delete.c create mode 100644 tests/signals/sigismember-invalid.c create mode 100644 tests/signals/sigismember-valid.c create mode 100644 tests/signals/signal-h-2.c create mode 100644 tests/signals/signal-h.c create mode 100644 tests/signals/signal-handle_return.c create mode 100644 tests/signals/signal-handler.c create mode 100644 tests/signals/signal-handler2.c create mode 100644 tests/signals/signal-ignore.c create mode 100644 tests/signals/signal-invalid.c create mode 100644 tests/signals/signal-uncatchable.c create mode 100644 tests/signals/signals_list.h create mode 100644 tests/signals/sigpause-error.c create mode 100644 tests/signals/sigpause-invalid.c create mode 100644 tests/signals/sigpause-pause.c create mode 100644 tests/signals/sigpause-revert.c create mode 100644 tests/signals/sigpause-suspend.c create mode 100644 tests/signals/sigprocmask-10.c create mode 100644 tests/signals/sigprocmask-11.c create mode 100644 tests/signals/sigprocmask-12.c create mode 100644 tests/signals/sigprocmask-3.c create mode 100644 tests/signals/sigprocmask-4.c create mode 100644 tests/signals/sigprocmask-5.c create mode 100644 tests/signals/sigprocmask-6.c create mode 100644 tests/signals/sigprocmask-7.c create mode 100644 tests/signals/sigprocmask-8.c create mode 100644 tests/signals/sigprocmask-9.c create mode 100644 tests/signals/sigprocmask-block.c create mode 100644 tests/signals/sigprocmask-blocksingle.c create mode 100644 tests/signals/sigrelse-1.c create mode 100644 tests/signals/sigrelse-2.c create mode 100644 tests/signals/sigrelse-3.c create mode 100644 tests/signals/sigset-1.c create mode 100644 tests/signals/sigset-10.c create mode 100644 tests/signals/sigset-2.c create mode 100644 tests/signals/sigset-3.c create mode 100644 tests/signals/sigset-4.c create mode 100644 tests/signals/sigset-5.c create mode 100644 tests/signals/sigset-9.c diff --git a/tests/signals/kill-child.c b/tests/signals/kill-child.c new file mode 100644 index 0000000000..3e593ef1b1 --- /dev/null +++ b/tests/signals/kill-child.c @@ -0,0 +1,100 @@ +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +/* + * Test signal catching when being signalled from parent. + * Skip SIGKILL and SIGSTOP as these are not catchable. + */ + +int sig_handled = 0; + +void sig_handler(int signo) +{ + (void) signo; + sig_handled = 1; +} + +void child_proc(int signum) +{ + + int sig; + (void) sig; + sigset_t sig_set; + int status; + + sig_handled = 0; + + status = sigemptyset(&sig_set); + ERROR_IF(sigemptyset, status, == -1); + + status = sigaddset(&sig_set, signum); + ERROR_IF(sigaddset, status, == -1); + + struct sigaction act; + act.sa_handler = sig_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(signum, &act, NULL); + + status = sleep(10); + ERROR_IF(sleep, status, == 0); + + if (sig_handled == 0) + { + printf("signal handler was not called"); + exit(EXIT_FAILURE); + } + + exit(EXIT_SUCCESS); +} + +void parent(int signum, pid_t pid) +{ + int status; + + sleep(1); + status = kill(pid, signum); + ERROR_IF(kill, status, != 0); + + pid = wait(&status); + ERROR_IF(wait, pid, == (pid_t)-1); + + if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS) + { + printf("Child did not exit normally.\n"); + exit(EXIT_FAILURE); + } + else + { + return; + } +} + +void kill_child(int signum) +{ + int pid; + + if ((pid = fork()) == 0) + { + child_proc(signum); + } + else + { + parent(signum, pid); + } +} + +int main() +{ + for (int i = 1; i < N_SIGNALS; i++) + { + if (i == SIGKILL || i == SIGSTOP) + { + continue; + } + kill_child(i); + } + return EXIT_SUCCESS; +} diff --git a/tests/signals/kill-invalid.c b/tests/signals/kill-invalid.c new file mode 100644 index 0000000000..e3e478e01c --- /dev/null +++ b/tests/signals/kill-invalid.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include +#include "../test_helpers.h" + +int main() +{ + + /* + * ESRCH + */ + if (-1 == kill(999999, 0)) { + if (ESRCH == errno) { + printf("ESRCH error received\n"); + } else { + printf("kill() failed on ESRCH errno not set correctly\n"); + exit(EXIT_FAILURE); + } + } else { + printf("kill() did not fail on ESRCH\n"); + exit(EXIT_FAILURE); + } + + + printf("test passed\n"); +} \ No newline at end of file diff --git a/tests/signals/kill-permission.c b/tests/signals/kill-permission.c new file mode 100644 index 0000000000..57346df06f --- /dev/null +++ b/tests/signals/kill-permission.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include +#include "../test_helpers.h" + +int main() +{ + setuid(1); /* this is added incase user is root. If user is normal user, then it has no effect on the tests*/ + + if (kill(1, 0) == -1) { + if (EPERM == errno) { + printf("EPERM error received\n"); + } else { + printf("kill() failed on EPERM errno not set correctly\n"); + exit(EXIT_FAILURE); + } + } else { + printf("kill() did not fail on EPERM\n"); + exit(EXIT_FAILURE); + } + + printf("test passed\n"); + return 0; +} \ No newline at end of file diff --git a/tests/signals/kill-self.c b/tests/signals/kill-self.c new file mode 100644 index 0000000000..f208c2f91b --- /dev/null +++ b/tests/signals/kill-self.c @@ -0,0 +1,59 @@ +#include +#include "signals_list.h" +#include "../test_helpers.h" + +/* + * Test signal catching when signalling self. + * Ensure all signals can be caught (other than SIGKILL and SIGSTOP). + */ + +int handler_called = 0; + +void sig_handler(int sig) +{ + (void) sig; + handler_called = 1; +} + +int kill_self(int sig) +{ + struct sigaction act; + int status; + + handler_called = 0; + + act.sa_handler = sig_handler; + act.sa_flags = 0; + + status = sigemptyset(&act.sa_mask); + ERROR_IF(sigemptyset, status, == -1); + + status = sigaction(sig, &act, NULL); + ERROR_IF(sigaction, status, == -1); + + status = kill(getpid(), sig); + ERROR_IF(kill, status, != 0); + + if (handler_called == 0) + { + printf("Handler was not called\n"); + exit(EXIT_FAILURE); + } + + return EXIT_SUCCESS; +} + +int main() +{ + + for (unsigned int i = 1; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) + { + int sig = signals_list[i].signal; + if (sig == SIGKILL || sig == SIGSTOP) + { + continue; + } + kill_self(sig); + } + return EXIT_SUCCESS; +} diff --git a/tests/signals/kill0-self.c b/tests/signals/kill0-self.c new file mode 100644 index 0000000000..ad76980233 --- /dev/null +++ b/tests/signals/kill0-self.c @@ -0,0 +1,16 @@ +#include +#include "../test_helpers.h" + +/* + * Send signal 0 to self. This just reports whether a signal can be sent. + */ + +int main() +{ + int status = 0; + + status = kill(getpid(), 0); + ERROR_IF(kill, status, != 0); + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/killpg-child.c b/tests/signals/killpg-child.c new file mode 100644 index 0000000000..d1edddcb96 --- /dev/null +++ b/tests/signals/killpg-child.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +void sig_handler (int signo) { + (void) signo; + exit(1); +} + +int killpg_test2(int signum) +{ + int child_pid, child_pgid; + printf("we are on signal %d\n ", signum); + + if ((child_pid = fork()) == 0) { + /* child here */ + struct sigaction act; + act.sa_handler=sig_handler; + act.sa_flags=0; + sigemptyset(&act.sa_mask); + sigaction(signum, &act, 0); + + /* change child's process group id */ + setpgrp(); + + sigpause(SIGABRT); + + return 0; + } else { + /* parent here */ + int i; + sigignore(signum); + + sleep(1); + if ((child_pgid = getpgid(child_pid)) == -1) { + printf("Could not get pgid of child\n"); + exit(EXIT_FAILURE); + } + + + if (killpg(child_pgid, signum) != 0) { + printf("Could not raise signal being tested\n"); + exit(EXIT_FAILURE); + } + + if (wait(&i) == -1) { + perror("Error waiting for child to exit\n"); + exit(EXIT_FAILURE); + } + + if (WEXITSTATUS(i)) { + printf("Child exited normally\n"); + printf("Test PASSED\n"); + return 0; + } else { + printf("Child did not exit normally.\n"); + printf("Test FAILED\n"); + exit(EXIT_FAILURE); + } + } + + printf("Should have exited from parent\n"); + printf("Test FAILED\n"); + return EXIT_FAILURE; +} + +int main(){ + int x; + for (unsigned int i = 1; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) + { + int sig = signals_list[i].signal; + if (sig == SIGKILL || sig == SIGSTOP || sig == SIGCHLD) + { + continue; + } + x = killpg_test2(sig); + } + if (x == EXIT_FAILURE){ + return EXIT_FAILURE; + } else { + return EXIT_SUCCESS; + } +} + diff --git a/tests/signals/killpg-esrch.c b/tests/signals/killpg-esrch.c new file mode 100644 index 0000000000..32b8cea409 --- /dev/null +++ b/tests/signals/killpg-esrch.c @@ -0,0 +1,25 @@ +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include +#include +#include "../test_helpers.h" + +int main() +{ + + if (killpg(999999, 0) != -1) { + printf("killpg did not return -1 even though it was passed an invalid process group id."); + exit(EXIT_FAILURE); + } + + if (errno != ESRCH) { + printf("killpg did not set errno to ESRCH even though it was passed an invalid signal number."); + exit(EXIT_FAILURE); + } + + printf("Test PASSED\n"); + return 0; +} \ No newline at end of file diff --git a/tests/signals/killpg-invalid.c b/tests/signals/killpg-invalid.c new file mode 100644 index 0000000000..243b140415 --- /dev/null +++ b/tests/signals/killpg-invalid.c @@ -0,0 +1,31 @@ +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include +#include +#include "../test_helpers.h" + +int main() +{ + int pgrp; + + if ((pgrp = getpgrp()) == -1) { + printf("Could not get process group number\n"); + exit(EXIT_FAILURE); + } + + if (killpg(pgrp, -1) != -1) { + printf("killpg did not return -1 even though it was passed an invalid signal number."); + exit(EXIT_FAILURE); + } + + if (errno != EINVAL) { + printf("killpg did not set errno to EINVAL even though it was passed an invalid signal number."); + exit(EXIT_FAILURE); + } + + printf("Test PASSED\n"); + return 0; +} \ No newline at end of file diff --git a/tests/signals/killpg-self.c b/tests/signals/killpg-self.c new file mode 100644 index 0000000000..e8ce85fa2b --- /dev/null +++ b/tests/signals/killpg-self.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +void sig_handler(int signo) +{ + printf("Caught signal %d being tested!\n", signo); + printf("Test PASSED\n"); + return; +} + +int killpg_test1(int signum) +{ + int pgrp; + struct sigaction act; + + act.sa_handler=sig_handler; + act.sa_flags=0; + if (sigemptyset(&act.sa_mask) == -1) { + perror("Error calling sigemptyset\n"); + exit(EXIT_FAILURE); + } + if (sigaction(signum, &act, 0) == -1) { + perror("Error calling sigaction\n"); + exit(EXIT_FAILURE); + } + + if ((pgrp = getpgrp()) == -1) { + printf("Could not get process group number\n"); + exit(EXIT_FAILURE); + } + + if (killpg(pgrp, signum) != 0) { + printf("Could not raise signal being tested\n"); + exit(EXIT_FAILURE); + } + + return 0; +} + +int main(){ + for (unsigned int i = 0; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) + { + int sig = signals_list[i].signal; + if (sig == SIGKILL || sig == SIGSTOP) + { + continue; + } + killpg_test1(sig); + } + return EXIT_SUCCESS; +} + diff --git a/tests/signals/killpg0-self.c b/tests/signals/killpg0-self.c new file mode 100644 index 0000000000..2279c144e5 --- /dev/null +++ b/tests/signals/killpg0-self.c @@ -0,0 +1,24 @@ +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include + +int main() +{ + int pgrp; + + if ((pgrp = getpgrp()) == -1) { + printf("Could not get process group number\n"); + exit(EXIT_FAILURE); + } + + if (killpg(pgrp, 0) != 0) { + printf("killpg did not return success.\n"); + exit(EXIT_FAILURE); + } + + printf("Test PASSED\n"); + return 0; +} \ No newline at end of file diff --git a/tests/signals/pthread_kill-child.c b/tests/signals/pthread_kill-child.c new file mode 100644 index 0000000000..f3df951a16 --- /dev/null +++ b/tests/signals/pthread_kill-child.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include + +void * thread_function(void *arg) +{ + /* Does nothing */ + (void) arg; + pthread_exit((void*)0); + + /* To please some compilers */ + return NULL; +} + +int main() +{ + pthread_t child_thread; + pthread_t invalid_tid; + + int rc; + + rc = pthread_create(&child_thread, NULL, + thread_function, NULL); + if (rc != 0) + { + printf("Error at pthread_create()\n"); + exit(EXIT_FAILURE); + } + + rc = pthread_join(child_thread, NULL); + if (rc != 0) + { + printf("Error at pthread_join()\n"); + exit(EXIT_FAILURE); + } + + /* Now the child_thread exited, it is an invalid tid */ + memcpy(&invalid_tid, &child_thread, + sizeof(pthread_t)); + // int i = pthread_kill(invalid_tid, 0); + sleep(3); + // printf("%d\n", i); + // printf("esrch is %d\n", ESRCH); + + if (pthread_kill(invalid_tid, 0) == ESRCH) { + printf("pthread_kill() returns ESRCH.\n"); + return 0; + } + + printf("Test Fail\n"); + exit(1); +} \ No newline at end of file diff --git a/tests/signals/pthread_kill-invalid.c b/tests/signals/pthread_kill-invalid.c new file mode 100644 index 0000000000..48a57e986b --- /dev/null +++ b/tests/signals/pthread_kill-invalid.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + pthread_t main_thread; + + main_thread = pthread_self(); + + if (EINVAL != pthread_kill(main_thread, -1)) { + printf("pthread_kill() did not fail on EINVAL\n"); + exit(EXIT_FAILURE); + } + printf("test pass\n"); + return 0; +} \ No newline at end of file diff --git a/tests/signals/pthread_kill-self.c b/tests/signals/pthread_kill-self.c new file mode 100644 index 0000000000..6bd9f01bd7 --- /dev/null +++ b/tests/signals/pthread_kill-self.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +# define INTHREAD 0 +# define INMAIN 1 +# define SIGTOTEST SIGABRT + +int sem1; /* Manual semaphore */ +int handler_called = 0; +int count = 1; + +struct signal { + int signum; +}; + +void handler() { + printf("signal was called\n"); + handler_called = 1; + return; +} + +void *a_thread_func( void *arg) +{ + + struct sigaction act; + act.sa_flags = 0; + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + sigaction(((struct signal *)arg)->signum, &act, 0); + + sem1=INMAIN; + + while(sem1==INMAIN) + sleep(1); + + // sleep(50); + + handler_called=-1; + pthread_exit(0); + return NULL; +} + +int pthread_kill_test1(int signum) +{ + pthread_t new_th; + + sem1=INTHREAD; + + struct signal arg; + arg.signum = signum; + + if(pthread_create(&new_th, NULL, a_thread_func, &arg) != 0) + { + perror("Error creating thread\n"); + exit(EXIT_FAILURE); + } + + while(sem1==INTHREAD) + sleep(1); + + if(pthread_kill(new_th, signum) != 0) + { + printf("Test FAILED: Couldn't send signal to thread\n"); + exit(EXIT_FAILURE); + } + sleep(2); + sem1=INTHREAD; + + while(handler_called==0) + sleep(1); + + if(handler_called == -1) { + printf("Test FAILED: Kill request timed out\n"); + exit(EXIT_FAILURE); + } else if (handler_called == 0) { + printf("Test FAILED: Thread did not recieve or handle\n"); + exit(EXIT_FAILURE); + } + + printf("Test PASSED for signal %d\n", signum); + handler_called = 0; + return 0; +} + +int main(){ + for (unsigned int i = 0; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) + { + int sig = signals_list[i].signal; + if (sig == SIGKILL || sig == SIGSTOP) + { + continue; + } + pthread_kill_test1(sig); + } + return EXIT_SUCCESS; +} + diff --git a/tests/signals/pthread_kill0-self.c b/tests/signals/pthread_kill0-self.c new file mode 100644 index 0000000000..45d1ab067a --- /dev/null +++ b/tests/signals/pthread_kill0-self.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include + +int main() +{ + pthread_t main_thread; + + main_thread=pthread_self(); + + if (pthread_kill(main_thread, 0) != 0) { + printf("Could not call pthread_kill with sig = 0\n"); + exit(EXIT_FAILURE); + } + + printf("Test PASSED\n"); + return 0; +} \ No newline at end of file diff --git a/tests/signals/raise-compliance.c b/tests/signals/raise-compliance.c new file mode 100644 index 0000000000..20e7e9629b --- /dev/null +++ b/tests/signals/raise-compliance.c @@ -0,0 +1,49 @@ +// The raise() function shall send the signal sig to the executing [CX] [Option Start] thread or process. [Option End] If a signal handler is called, the raise() function shall not return until after the signal handler does. + +// [CX] [Option Start] The effect of the raise() function shall be equivalent to calling: pthread_kill(pthread_self(), sig); + + +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +void sig_hand(int i) + +{ + if (i < 1 || i > 32){ + printf("an invalid signal was given: %d", i); + } + static int count = 1; + + count++; + printf("%d \n", count); + if (count == 32) { + printf("reached 32nd signal\n"); + return; + } + else{ + printf("count is %d\n", count); + } +} + +void raise_test(int sig){ + signal(sig, sig_hand); + raise(sig); +} + +int main(void) +{ + for (int i = 0; i < N_SIGNALS; i++) + { + int sig = signals_list[i].signal; + if (sig == SIGKILL || sig == SIGSTOP) + { + continue; + } + raise_test(sig); + } + return EXIT_SUCCESS; +} + diff --git a/tests/signals/sigaddset-add.c b/tests/signals/sigaddset-add.c new file mode 100644 index 0000000000..c5c4044ba0 --- /dev/null +++ b/tests/signals/sigaddset-add.c @@ -0,0 +1,40 @@ + + + // The sigaddset() function adds the individual signal specified by the signo to the signal set pointed to by set. + + // Applications shall call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined. + +#define _OPEN_SYS +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + + + +void addset_test(sigset_t *sigset, int signal){ + if (sigismember(sigset, signal) !=0){ + printf("the signal is already in the set, %d\n", signal); + } + sigaddset(sigset, signal); + if (sigismember(sigset, signal) ==1){ + printf("the signal was added successfully\n"); + } + if (sigismember(sigset, signal) !=1){ + printf("the signal add failed\n"); + } + +} + +int main() { + sigset_t sigset; + + sigemptyset(&sigset); + +for (int i = 1; i < N_SIGNALS; i++){ + addset_test(&sigset, i); + } + + +} diff --git a/tests/signals/sigdelset-delete.c b/tests/signals/sigdelset-delete.c new file mode 100644 index 0000000000..72dc04f2a6 --- /dev/null +++ b/tests/signals/sigdelset-delete.c @@ -0,0 +1,40 @@ + + + // The sigdelset() function deletes the individual signal specified by signo from the signal set pointed to by set. + + // Applications should call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined. + + +#define _OPEN_SYS +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + + + +void delset_test(sigset_t *sigset, int signal){ + if (sigismember(sigset, signal) !=1){ + printf("the signal is already out of the set, %d\n", signal); + } + sigdelset(sigset, signal); + if (sigismember(sigset, signal) ==0){ + printf("the signal was deleted successfully\n"); + } + if (sigismember(sigset, signal) !=0){ + printf("the signal remove failed\n"); + } + +} + +int main() { + sigset_t sigset; + + sigfillset(&sigset); + + for (int i = 1; i < N_SIGNALS; i++){ + delset_test(&sigset, i); + } + +} diff --git a/tests/signals/sigismember-invalid.c b/tests/signals/sigismember-invalid.c new file mode 100644 index 0000000000..86432bd727 --- /dev/null +++ b/tests/signals/sigismember-invalid.c @@ -0,0 +1,25 @@ +#define _OPEN_SYS +#include +#include +#include +#include + + + + +int main() { + sigset_t sigset; + + sigfillset(&sigset); + if (sigismember(&sigset, -1)!=-1){ + printf("sigismember didn't return -1"); + exit(EXIT_FAILURE); + } else if (EINVAL != errno) { + printf("errno was not set to EINVAL\n"); + exit(EXIT_FAILURE); + } + + printf ("errno set to EINVAL and sigismember returned -1\n"); + return 0; + +} \ No newline at end of file diff --git a/tests/signals/sigismember-valid.c b/tests/signals/sigismember-valid.c new file mode 100644 index 0000000000..daf39d7b9c --- /dev/null +++ b/tests/signals/sigismember-valid.c @@ -0,0 +1,35 @@ + // The sigismember() function shall test whether the signal specified by signo is a member of the set pointed to by set. + + // Applications should call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined. + + + +#define _OPEN_SYS +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +void check(sigset_t set, int signum) { + printf("%d is ", signum); + if (!sigismember(&set, signum)) + printf("not "); + puts("in the set"); +} + + + +int main() { + sigset_t sigset; + + sigfillset(&sigset); + for (int i=1; i + +/* + * This is a test to ensure all required items for signal.h are defined. + * The definitions follow the order described in + * + */ + +void handler(int sig_num) +{ + (void)sig_num; +} + +void action(int sig_num, siginfo_t *info, void *context) +{ + (void)sig_num; + (void)info; + (void)context; +} + +int main() +{ + int (*sh)(int) __attribute__((unused)) = sighold; + int (*sigig)(int) __attribute__((unused)) = sigignore; + int (*sigintr)(int, int) __attribute__((unused)) = siginterrupt; + int (*paws)(int) __attribute__((unused)) = sigpause; + int (*srls)(int) __attribute__((unused)) = sigrelse; + void (*(*sset)(int, void (*)(int)))(int) __attribute__((unused)) = sigset; + + return EXIT_SUCCESS; +} diff --git a/tests/signals/signal-h.c b/tests/signals/signal-h.c new file mode 100644 index 0000000000..8ec09b374d --- /dev/null +++ b/tests/signals/signal-h.c @@ -0,0 +1,232 @@ +#include "../test_helpers.h" +#include + +/* + * This is a test to ensure all required items for signal.h are defined. + * The definitions follow the order described in + * + */ + +void handler(int sig_num) +{ + (void)sig_num; +} + +void action(int sig_num, siginfo_t *info, void *context) +{ + (void)sig_num; + (void)info; + (void)context; +} + +int main() +{ + void (*sig_dfl)(int) __attribute__((unused)) = SIG_DFL; + void (*sig_err)(int) __attribute__((unused)) = SIG_ERR; + void (*sig_ign)(int) __attribute__((unused)) = SIG_IGN; + + pthread_t pthread_num __attribute__((unused)) = 0; + size_t size __attribute__((unused)) = 0; + uid_t uid __attribute__((unused)) = 0; + + sig_atomic_t atomic __attribute__((unused)) = 0; + sigset_t sig_set __attribute__((unused)) ; + pid_t pid __attribute__((unused)) = 0; + + pthread_attr_t *attr __attribute__((unused)) = NULL; + + // struct sigevent sev; + union sigval sv; + + sv.sival_int = (int)0; + sv.sival_ptr = (void *)0; + + // sev.sigev_notify = (int)0; + // sev.sigev_notify = SIGEV_NONE; + // sev.sigev_notify = SIGEV_SIGNAL; + // sev.sigev_notify = SIGEV_THREAD; + + // sev.sigev_signo = (int)0; + // sev.sigev_value = sv; + // sev.sigev_value.sival_int = (int)0; + // sev.sigev_value.sival_ptr = (void *)0; + // sev.sigev_notify_function = (void (*)(union sigval))0; + // sev.sigev_notify_attributes = (pthread_attr_t *)0; + + int rt_sig_num __attribute__((unused)) = SIGRTMIN; + rt_sig_num = SIGRTMAX; + + // rt_sig_num = SIG2STR_MAX; + + // sev.sigev_signo = SIGABRT; + // sev.sigev_signo = SIGALRM; + // sev.sigev_signo = SIGBUS; + // sev.sigev_signo = SIGCHLD; + // sev.sigev_signo = SIGCONT; + // sev.sigev_signo = SIGFPE; + // sev.sigev_signo = SIGHUP; + // sev.sigev_signo = SIGILL; + // sev.sigev_signo = SIGINT; + // sev.sigev_signo = SIGKILL; + // sev.sigev_signo = SIGPIPE; + // sev.sigev_signo = SIGQUIT; + // sev.sigev_signo = SIGSEGV; + // sev.sigev_signo = SIGSTOP; + // sev.sigev_signo = SIGTERM; + // sev.sigev_signo = SIGTSTP; + // sev.sigev_signo = SIGTTIN; + // sev.sigev_signo = SIGTTOU; + // sev.sigev_signo = SIGUSR1; + // sev.sigev_signo = SIGUSR2; + // sev.sigev_signo = SIGWINCH; + // sev.sigev_signo = SIGPOLL; + // sev.sigev_signo = SIGPROF; + // sev.sigev_signo = SIGSYS; + // sev.sigev_signo = SIGTRAP; + // sev.sigev_signo = SIGURG; + // sev.sigev_signo = SIGVTALRM; + // sev.sigev_signo = SIGXCPU; + // sev.sigev_signo = SIGXFSZ; + + struct sigaction sa; + + sa.sa_handler = SIG_IGN; + sa.sa_handler = SIG_DFL; + sa.sa_handler = handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = (int)0; + sa.sa_sigaction = action; + +#ifndef SA_NOCLDSTOP +#error "Required constant not defined SA_NOCLDSTOP" +#endif +#ifndef SIG_BLOCK +#error "Required constant not defined SIG_BLOCK" +#endif +#ifndef SIG_UNBLOCK +#error "Required constant not defined SIG_UNBLOCK" +#endif +#ifndef SIG_SETMASK +#error "Required constant not defined SIG_SETMASK" +#endif +#ifndef SA_ONSTACK +#error "Required constant not defined SA_ONSTACK" +#endif +#ifndef SA_RESETHAND +#error "Required constant not defined SA_RESETHAND" +#endif +#ifndef SA_RESTART +#error "Required constant not defined SA_RESTART" +#endif +#ifndef SA_SIGINFO +#error "Required constant not defined SA_SIGINFO" +#endif +#ifndef SA_NOCLDWAIT +#error "Required constant not defined SA_NOCLDWAIT" +#endif +#ifndef SA_NODEFER +#error "Required constant not defined SA_NODEFER" +#endif +#ifndef SS_ONSTACK +#error "Required constant not defined SS_ONSTACK" +#endif +#ifndef SS_DISABLE +#error "Required constant not defined SS_DISABLE" +#endif +#ifndef MINSIGSTKSZ +#error "Required constant not defined MINSIGSTKSZ" +#endif +#ifndef SIGSTKSZ +#error "Required constant not defined SIGSTKSZ" +#endif + + // struct ucontext_t uc; + mcontext_t mc __attribute__((unused)); + + // add parts to ucontext_t + // uc.uc_link = NULL; + // uc.uc_sigmask = 0; + // uc.uc_stack = NULL; + // uc.uc_mcontext = NULL; + + + stack_t st __attribute__((unused)); + st.ss_sp = NULL; + st.ss_size = (size_t)0; + st.ss_flags = (int)0; + + siginfo_t si __attribute__((unused)); + si.si_signo = SIGHUP; + si.si_code = (int)0; + si.si_errno = (int)0; + si.si_pid = (pid_t)0; + si.si_uid = (uid_t)0; + si.si_addr = NULL; + si.si_status = (int)0; + si.si_value = sv; + + // si.si_code = ILL_ILLOPC; + // si.si_code = ILL_ILLOPN; + // si.si_code = ILL_ILLADR; + // si.si_code = ILL_ILLTRP; + // si.si_code = ILL_PRVOPC; + // si.si_code = ILL_PRVREG; + // si.si_code = ILL_COPROC; + // si.si_code = ILL_BADSTK; + // si.si_code = FPE_INTDIV; + // si.si_code = FPE_INTOVF; + // si.si_code = FPE_FLTDIV; + // si.si_code = FPE_FLTOVF; + // si.si_code = FPE_FLTUND; + // si.si_code = FPE_FLTRES; + // si.si_code = FPE_FLTINV; + // si.si_code = FPE_FLTSUB; + // si.si_code = SEGV_MAPERR; + // si.si_code = SEGV_ACCERR; + // si.si_code = BUS_ADRALN; + // si.si_code = BUS_ADRERR; + // si.si_code = BUS_OBJERR; + // si.si_code = TRAP_BRKPT; + // si.si_code = TRAP_TRACE; + // si.si_code = CLD_EXITED; + // si.si_code = CLD_KILLED; + // si.si_code = CLD_DUMPED; + // si.si_code = CLD_TRAPPED; + // si.si_code = CLD_STOPPED; + // si.si_code = CLD_CONTINUED; + // si.si_code = SI_USER; + // si.si_code = SI_QUEUE; + // si.si_code = SI_TIMER; + // si.si_code = SI_ASYNCIO; + // si.si_code = SI_MESGQ; + + // void (*(*bs)(int, void (*)(int)))(int) = bsd_signal; + int (*k)(pid_t, int) __attribute__((unused))= kill; + int (*kpg)(pid_t, int) __attribute__((unused))= killpg; + void (*psig)(const siginfo_t *, const char *) __attribute__((unused))= psiginfo; + void (*ps)(int, const char *) __attribute__((unused))= psignal; + int (*ptk)(pthread_t, int) __attribute__((unused))= pthread_kill; + int (*ptsm)(int, const sigset_t *, sigset_t *) __attribute__((unused))= pthread_sigmask; + int (*r)(int) __attribute__((unused))= raise; + // int (*s2s)(int, char*) = sig2str; + int (*sact)(int, const struct sigaction *restrict, + struct sigaction *restrict) __attribute__((unused)) = sigaction; + int (*sas)(sigset_t *, int) __attribute__((unused))= sigaddset; + int (*sastk)(const stack_t *restrict, stack_t *restrict) __attribute__((unused))= sigaltstack; + int (*sds)(sigset_t *, int) __attribute__((unused))= sigdelset; + int (*ses)(sigset_t *) __attribute__((unused))= sigemptyset; + int (*sfs)(sigset_t *) __attribute__((unused))= sigfillset; + int (*ismem)(const sigset_t *, int) __attribute__((unused))= sigismember; + void ( *(*sgnl)(int, void (*)(int)))(int) __attribute__((unused))= signal; + int (*pend)(sigset_t *) __attribute__((unused))= sigpending; + int (*spmsk)(int, const sigset_t *restrict, sigset_t *restrict) __attribute__((unused))= sigprocmask; + int (*sigq)(pid_t, int, const union sigval) __attribute__((unused))= sigqueue; + int (*susp)(const sigset_t *) __attribute__((unused))= sigsuspend; + int (*stmwt)(const sigset_t *restrict, siginfo_t *restrict, + const struct timespec *restrict) __attribute__((unused))= sigtimedwait; + int (*swt)(const sigset_t *restrict, int *restrict) __attribute__((unused))= sigwait; + int (*swtinfo)(const sigset_t *restrict, siginfo_t *restrict) __attribute__((unused))= sigwaitinfo; + // int (*str2s)(const char *restrict, int *restrict) = str2sig; + + return EXIT_SUCCESS; +} diff --git a/tests/signals/signal-handle_return.c b/tests/signals/signal-handle_return.c new file mode 100644 index 0000000000..d52ac6c750 --- /dev/null +++ b/tests/signals/signal-handle_return.c @@ -0,0 +1,35 @@ +#include +#include +#include + +void SIGUSR1_handler(int signo) +{ + (void) signo; + printf("do nothing useful\n"); +} + +void SIGUSR2_handler(int signo) +{ + (void) signo; + printf("do nothing useful\n"); +} + +int main() +{ + if (signal(SIGUSR1, SIGUSR1_handler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + exit(EXIT_FAILURE); + } + + if (signal(SIGUSR2, SIGUSR2_handler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + exit(EXIT_FAILURE); + } + + if (signal(SIGUSR1,SIG_IGN) != SIGUSR1_handler) { + printf("signal did not return the last handler that was associated with SIGUSR1\n"); + exit(EXIT_FAILURE); + } + printf("test passed\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/signal-handler.c b/tests/signals/signal-handler.c new file mode 100644 index 0000000000..0cd2b78145 --- /dev/null +++ b/tests/signals/signal-handler.c @@ -0,0 +1,35 @@ +#include +#include +#include + +int handler_called = 0; + +void sig_handler(int signo) +{ + (void) signo; + printf("SIGCHLD called. Inside handler\n"); + handler_called = 1; +} + +int main() +{ + if (signal(SIGCHLD, sig_handler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + exit(1); + } + + if (signal(SIGCHLD,SIG_DFL) != sig_handler) { + perror("Unexpected error while using signal()"); + exit(1); + } + + raise(SIGCHLD); + + if (handler_called == 1) { + printf("Test FAILED: handler was called even though default was expected\n"); + exit(1); + } + printf("test passed \n"); + handler_called = 0; + return 0; +} \ No newline at end of file diff --git a/tests/signals/signal-handler2.c b/tests/signals/signal-handler2.c new file mode 100644 index 0000000000..29b856c952 --- /dev/null +++ b/tests/signals/signal-handler2.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int handler_called = 0; + +void sig_handler(int signo) +{ + printf("%d called. Inside handler\n", signo); + handler_called = 1; +} + +int signal_test3(int signum) +{ + if (signal(signum, sig_handler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + exit(EXIT_FAILURE); + } + + raise(signum); + + if (handler_called != 1) { + printf("Test FAILED: handler wasn't called even though it should have been\n"); + exit(1); + } + printf("test %d passed\n", signum); + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int handler_called = 0; + +void sig_handler(int signo) +{ + printf("%d called. Inside handler\n", signo); + handler_called = 1; +} + +int signal_test2(int signum) +{ + if (signal(signum, sig_handler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + exit(EXIT_FAILURE); + } + + if (signal(signum,SIG_IGN) != sig_handler) { + perror("Unexpected error while using signal()"); + exit(EXIT_FAILURE); + } + + raise(signum); + + if (handler_called == 1) { + printf("Test FAILED: handler was called even though ingore was expected\n"); + exit(EXIT_FAILURE); + } + printf("test %d passed\n", signum); + handler_called = 0; + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include +#include + +void sig_handler(int signo) +{ + (void) signo; + printf("handler does nothing useful.\n"); +} + +int main() +{ + errno = -1; + + if (signal(-1, sig_handler) != SIG_ERR) { + printf("Test FAILED: signal() didn't return SIG_ERR even though invalid signal number was passed to it\n"); + exit(EXIT_FAILURE); + } + + if (errno <= 0) { + printf("Test FAILED: errno wasn't set to a positive number even though invalid signal number was passed to the signal() function\n"); + exit(EXIT_FAILURE); + } + printf("test passed\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/signal-uncatchable.c b/tests/signals/signal-uncatchable.c new file mode 100644 index 0000000000..5ef87c381e --- /dev/null +++ b/tests/signals/signal-uncatchable.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +void sig_handler(int signo) +{ + (void) signo; + printf("handler does nothing useful.\n"); +} + +int main() +{ + errno = -1; + + if (signal(SIGKILL, sig_handler) != SIG_ERR) { + printf("Test FAILED: signal() didn't return SIG_ERR even though a non-catchable signal was passed to it\n"); + exit(EXIT_FAILURE); + } + + if (errno <= 0) { + printf("Test FAILED: errno wasn't set to a positive number even though a non-catchable signal was passed to the signal() function\n"); + exit(EXIT_FAILURE); + } + printf("test passed\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/signals_list.h b/tests/signals/signals_list.h new file mode 100644 index 0000000000..52d5847c2d --- /dev/null +++ b/tests/signals/signals_list.h @@ -0,0 +1,79 @@ +#ifndef _SIGNALS_LIST +#define _SIGNALS_LIST 1 + +#include + +#ifdef SIGSTKFLT +#endif + +const int N_SIGNALS = (28 +#ifdef SIGSTKFLT + + 1 +#endif +#ifdef SIGWINCH + + 1 +#endif +#ifdef SIGIO + + 1 +#endif +#ifdef SIGPWR + + 1 +#endif +#ifdef SIGUNUSED + + 1 +#endif +); + +struct signalAction +{ + int signal; + char action; +}; + +const struct signalAction signals_list[] = { + {SIGABRT, 'A'}, + {SIGALRM, 'T'}, + {SIGBUS, 'A'}, + {SIGCHLD, 'I'}, + {SIGCONT, 'C'}, + {SIGFPE, 'A'}, + {SIGHUP, 'T'}, + {SIGILL, 'A'}, + {SIGINT, 'T'}, + {SIGKILL, 'T'}, + {SIGPIPE, 'T'}, + {SIGQUIT, 'A'}, + {SIGSEGV, 'A'}, + {SIGSTOP, 'S'}, + {SIGTERM, 'T'}, + {SIGTSTP, 'S'}, + {SIGTTIN, 'S'}, + {SIGTTOU, 'S'}, + {SIGUSR1, 'T'}, + {SIGUSR2, 'T'}, + // {SIGPOLL, 'T'}, + {SIGPROF, 'T'}, + {SIGSYS, 'A'}, + {SIGTRAP, 'A'}, + {SIGURG, 'I'}, + {SIGVTALRM, 'T'}, + {SIGXCPU, 'A'}, + {SIGXFSZ, 'A'}, +#ifdef SIGSTKFLT + {SIGSTKFLT, 'T'}, +#endif +#ifdef SIGWINCH + {SIGWINCH, 'I'}, +#endif +#ifdef SIGIO + {SIGIO, 'T'}, +#endif +#ifdef SIGPWR + {SIGPWR, 'T'}, +#endif +#ifdef SIGUNUSED + {SIGUNUSED, 'A'}, +#endif +}; + +#endif /* _SIGNALS_LIST */ \ No newline at end of file diff --git a/tests/signals/sigpause-error.c b/tests/signals/sigpause-error.c new file mode 100644 index 0000000000..19d6088e5c --- /dev/null +++ b/tests/signals/sigpause-error.c @@ -0,0 +1,102 @@ +#define _XOPEN_SOURCE 700 + +#include +#include +#include +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +#define INMAIN 0 +#define INTHREAD 1 + +int handler_called = 0; +int returned = 0; +int return_value = 2; +int result = 2; +int sem = INMAIN; + +void handler() { + // printf("signal was called\n"); + handler_called = 1; + return; +} + +void *d_thread_func(void *sig) +{ + + int signum = *(int *)sig; + printf("%d !!!\n", signum); + int return_value = 0; + struct sigaction act; + act.sa_flags = 0; + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + sigaction(signum, &act, 0); + return_value = sigpause(signum); + if (return_value == -1) { + if (errno == EINTR) { + printf ("Test PASSED: sigpause returned -1 and set errno to EINTR\n"); + result = 0; + } else { + printf ("Test FAILED: sigpause did not set errno to EINTR\n"); + result = 1; + } + } else { + if (errno == EINTR) { + printf ("Test FAILED: sigpause did not return -1\n"); + } + printf ("Test FAILED: sigpause did not set errno to EINTR\n"); + printf ("Test FAILED: sigpause did not return -1\n"); + result = 1; + + } + sem = INMAIN; + return NULL; +} + + +int sigpause_error(int signum){ + pthread_t new_th; + + if ((pthread_create(&new_th, NULL, d_thread_func, (void *)&signum)) != 0) + { + perror("Error creating thread\n"); + exit(EXIT_FAILURE); + } + + sleep(1); + + if(pthread_kill(new_th, signum) != 0) + { + printf("Test UNRESOLVED: Couldn't send signal to thread\n"); + exit(EXIT_FAILURE); + } + + sem = INTHREAD; + while (sem == INTHREAD) + sleep(1); + + if(result == 2) { + exit(EXIT_FAILURE); + } + if(result == 1) { + exit(EXIT_FAILURE); + } + + printf("Test PASSED\n"); + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include +#include +#include +#include + +#define INMAIN 0 +#define INTHREAD 1 + +int handler_called = 0; +int returned = 0; +int return_value = 2; +int result = 2; +int sem = INMAIN; + +void handler() { + // printf("signal was called\n"); + handler_called = 1; + return; +} + +int sigpause_invalid(){ + int return_value = 0; + + return_value = sigpause(-1); + if (return_value == -1) { + if (errno == EINVAL) { + printf ("Test PASSED: sigpause returned -1 and set errno to EINVAL\n"); + return EXIT_SUCCESS; + } else { + printf ("Test FAILED: sigpause did not set errno to EINVAL\n"); + exit(EXIT_FAILURE); + } + } else { + printf ("Test FAILED: sigpause did not return -1\n"); + if (errno == EINVAL) { + printf ("Test FAILED: sigpause did not set errno to EINVAL\n"); + } + exit(EXIT_FAILURE); + } + return EXIT_SUCCESS; + +} + +int main(){ + sigpause_invalid(); + return EXIT_SUCCESS; +} + diff --git a/tests/signals/sigpause-pause.c b/tests/signals/sigpause-pause.c new file mode 100644 index 0000000000..99121c418f --- /dev/null +++ b/tests/signals/sigpause-pause.c @@ -0,0 +1,77 @@ +#define _XOPEN_SOURCE 700 + +#include +#include +#include +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int handler_called = 0; + +void handler() { + // printf("signal was called\n"); + handler_called = 1; + return; +} + +void *a_thread_func(void *sig) +{ + int signum = *(int *)sig; + printf("%d !!!\n", signum); + struct sigaction act; + act.sa_flags = 0; + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + sigaction(signum, &act, 0); + sighold(signum); + sigpause(signum); + + return NULL; +} + + + +int sigpause_basic(int signum) +{ + pthread_t new_th; + + if(pthread_create(&new_th, NULL, a_thread_func, (void *)&signum) != 0) + { + perror("Error creating thread\n"); + exit(EXIT_FAILURE); + } + + sleep(1); + + if(pthread_kill(new_th, signum) != 0) + { + printf("Test UNRESOLVED: Couldn't send signal to thread\n"); + exit(EXIT_FAILURE); + } + + sleep(1); + + if(handler_called != 1) { + printf("Test FAILED: signal wasn't removed from signal mask\n"); + exit(EXIT_FAILURE); + } + handler_called = 0; + + printf("Test PASSED\n"); + return EXIT_SUCCESS; +} + + + +int main(){ + for (int i=1; i +#include +#include +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +#define INMAIN 0 +#define INTHREAD 1 + +int handler_called = 0; +int returned = 0; +int return_value = 2; +int result = 2; +int sem = INMAIN; + +void handler() { + // printf("signal was called\n"); + handler_called = 1; + return; +} + +void *c_thread_func(void *sig) +{ + int signum = *(int *)sig; + printf("%d !!!\n", signum); + struct sigaction act; + sigset_t pendingset; + + act.sa_flags = 0; + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + sigaction(signum, &act, 0); + sighold(signum); + printf("after sigpause\n"); + + if ((sigpause(signum) != -1) || (errno != EINTR)) { + printf ("Test UNRESOLVED: sigpause didn't return -1 and/or didn't set errno correctly."); + return_value = 2; + return NULL; + } + + sleep(1); + + raise (signum); + sigpending(&pendingset); + if (sigismember(&pendingset, signum) == 1) { + printf("Test PASSED: signal mask was restored when sigpause returned."); + return_value = 0; + } + + sem = INMAIN; + return NULL; + +} + +int sigpause_revert(int signum){ + pthread_t new_th; + + if(pthread_create(&new_th, NULL, c_thread_func, (void *)&signum) != 0) + { + perror("Error creating thread\n"); + exit(EXIT_FAILURE); + } + + sleep(1); + + if(pthread_kill(new_th, signum) != 0) + { + printf("Test UNRESOLVED: Couldn't send signal to thread\n"); + exit(EXIT_FAILURE); + } + + sem = INTHREAD; + while (sem == INTHREAD) + sleep(1); + + if(handler_called != 1) { + printf("Test UNRESOLVED: signal wasn't removed from signal mask\n"); + exit(EXIT_FAILURE); + } + + if (return_value != 0) { + exit(EXIT_FAILURE); + } + + printf("Test PASSED\n"); + return EXIT_SUCCESS; +} + + + +int main(){ + for (int i=1; i +#include +#include +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +#define INMAIN 0 +#define INTHREAD 1 + +int handler_called = 0; +int returned = 0; +int return_value = 2; +int result = 2; +int sem = INMAIN; + +void handler() { + // printf("signal was called\n"); + handler_called = 1; + return; +} +void *b_thread_func(void *sig) +{ + int signum = *(int *)sig; + printf("%d !!!\n", signum); + struct sigaction act; + act.sa_flags = 0; + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + sigaction(signum, &act, 0); + sigpause(signum); + returned = 1; + + return NULL; +} + + +int sigpause_suspend(int signum) +{ + pthread_t new_th; + int j; + + if(pthread_create(&new_th, NULL, b_thread_func, (void *)&signum) != 0) + { + perror("Error creating thread\n"); + exit(EXIT_FAILURE); + } + + for (j=0; j<10; j++) { + sleep(1); + if (returned == 1) { + printf ("Test FAILED: sigpause returned before it received a signal\n"); + exit(EXIT_FAILURE); + } + } + + if(pthread_kill(new_th, signum) != 0) + { + printf("Test UNRESOLVED: Couldn't send signal to thread\n"); + exit(EXIT_FAILURE); + } + sleep(1); + + if(returned != 1) { + printf("Test FAILED: signal was sent, but sigpause never returned.\n"); + exit(EXIT_FAILURE); + } + + returned = 0; + + printf("test passed\n"); + return EXIT_SUCCESS; +} + + +int main(){ + for (int i=1; i +#include +#include + +#define NUMSIGNALS 24 + +int is_changed(sigset_t set) { + + int i; + int siglist[] = {SIGALRM, SIGBUS, SIGCHLD, + SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, + SIGPIPE, SIGQUIT, SIGSEGV, + SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, + SIGUSR1, SIGUSR2, SIGPROF, SIGSYS, + SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; + + for (i=0; i +#include +#include + +// I don't understand this test + +int main() +{ + + sigset_t set; + sigaddset (&set, SIGABRT); + + if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) { + perror("sigprocmask failed -- returned -- test aborted"); + exit(EXIT_FAILURE); + } + printf("sigignore passed\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/sigprocmask-12.c b/tests/signals/sigprocmask-12.c new file mode 100644 index 0000000000..590adcd948 --- /dev/null +++ b/tests/signals/sigprocmask-12.c @@ -0,0 +1,56 @@ +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int signo; + (void) signo; + int r=rand(); + sigset_t set; + + if (argc < 2) { + printf("Usage: %s [1|2|3|4]\n", argv[0]); + exit(EXIT_FAILURE); + } + + /* + Various error conditions + */ + switch (argv[1][0]) { + case '1': + signo=-1; + break; + case '2': + signo=-10000; + break; + case '3': + signo=INT32_MIN+1; + break; + case '4': + signo=INT32_MIN; + break; + default: + printf("Usage: %s [1|2|3|4]\n", argv[0]); + exit(EXIT_FAILURE); + } + + sigaddset(&set, SIGABRT); + + if (sigprocmask(r, &set, NULL) == -1) { + if (EINVAL == errno) { + printf ("errno set to EINVAL\n"); + return EXIT_SUCCESS; + } else { + printf ("errno not set to EINVAL\n"); + exit(EXIT_FAILURE); + } + } + + printf("sighold did not return -1\n"); + exit(EXIT_FAILURE); +} \ No newline at end of file diff --git a/tests/signals/sigprocmask-3.c b/tests/signals/sigprocmask-3.c new file mode 100644 index 0000000000..58fd9f5296 --- /dev/null +++ b/tests/signals/sigprocmask-3.c @@ -0,0 +1,110 @@ +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int handler_called = 0; + +void sig_handler(int signo) +{ + (void) signo; + handler_called = 1; +} + +int sigprocmask_block(int signum) +{ + int defaultsig = SIGALRM; + if (signum == SIGALRM) { + defaultsig = SIGHUP; + } + struct sigaction act; + sigset_t set1, set2, pending_set; + sigemptyset(&set1); + sigemptyset(&set2); + sigaddset(&set1, defaultsig); + sigaddset(&set2, signum); + + act.sa_handler = sig_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + + if (sigaction(signum, &act, 0) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + + if (sigaction(defaultsig, &act, 0) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (sigprocmask(SIG_SETMASK, &set1, NULL) == -1) { + perror("Unexpected error while attempting to use sigprocmask.\n"); + exit(EXIT_FAILURE); + } + + if (sigprocmask(SIG_UNBLOCK, &set2, NULL) == -1) { + perror("Unexpected error while attempting to use sigprocmask.\n"); + exit(EXIT_FAILURE); + } + + if (raise(signum) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (!handler_called) { + printf("FAIL: Handler was not called while it should have been\n"); + exit(EXIT_FAILURE); + } + handler_called = 0; + + if (raise(defaultsig) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (handler_called) { + printf("FAIL: signal was not blocked\n"); + exit(EXIT_FAILURE); + } + + if (sigpending(&pending_set) == -1) { + perror("Unexpected error while attempting to use sigpending\n"); + exit(EXIT_FAILURE); + } + + if (sigismember(&pending_set, defaultsig) != 1) { + perror("FAIL: sigismember did not return 1\n"); + exit(EXIT_FAILURE); + } + + if (sigismember(&pending_set, signum) != 0) { + perror("FAIL: sigismember did not return 0\n"); + exit(EXIT_FAILURE); + } + + printf("Test PASSED: signal was added to the process's signal mask\n"); + act.sa_handler = SIG_IGN; + sigaction(signum, &act, 0); + sigaction(defaultsig, &act, 0); + + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include + + +#define NUMSIGNALS 26 + +int main() +{ + sigset_t oactl, tempset; + int i, j, test_failed=0; + + int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, + SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, + SIGPIPE, SIGQUIT, SIGSEGV, + SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, + SIGUSR1, SIGUSR2, SIGPROF, SIGSYS, + SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; + + for (i=0; i 0) { + for (j=0; j +#include +#include + + +#define NUMSIGNALS 25 + +int is_changed(sigset_t set, int sig) { + + int i; + int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, + SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, + SIGPIPE, SIGQUIT, SIGSEGV, + SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, + SIGUSR1, SIGUSR2, SIGPROF, SIGSYS, + SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; + + if (sigismember(&set, sig) != 1) { + return 1; + } + for (i=0; i +#include +#include + + +#define NUMSIGNALS 25 + +int is_changed(sigset_t set, int sig) { + + int i; + int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, + SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, + SIGPIPE, SIGQUIT, SIGSEGV, + SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, + SIGUSR1, SIGUSR2, SIGPROF, SIGSYS, + SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; + + if (sigismember(&set, sig) != 1) { + return 1; + } + for (i=0; i +#include +#include + +#define NUMSIGNALS 25 + +int is_changed(sigset_t set, int sig) { + + int i; + int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, + SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, + SIGPIPE, SIGQUIT, SIGSEGV, + SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, + SIGUSR1, SIGUSR2, SIGPROF, SIGSYS, + SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; + + if (sigismember(&set, sig) != 1) { + return 1; + } + for (i=0; i +#include +#include + +int handler_called = 0; +int sigprocmask_return_val = 1; /* some value that's not a 1 or 0 */ + +void sig_handler(int signo) +{ + (void) signo; + handler_called = 1; + if (sigprocmask_return_val != 1) { + printf("FAIL: sigprocmask() returned before signal was delivered.\n"); + exit(EXIT_FAILURE); + } +} + +int main() +{ + struct sigaction act; + sigset_t blocked_set1; + sigemptyset(&blocked_set1); + sigaddset(&blocked_set1, SIGABRT); + + act.sa_handler = sig_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + + if (sigaction(SIGABRT, &act, 0) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (sigprocmask(SIG_SETMASK, &blocked_set1, NULL) == -1) { + perror("Unexpected error while attempting to use sigprocmask.\n"); + exit(EXIT_FAILURE); + } + + if ((raise(SIGABRT) == -1)) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + sigprocmask_return_val = sigprocmask(SIG_UNBLOCK, &blocked_set1, NULL); + + if (sigprocmask_return_val != 0) { + perror("Unexpected error while attempting to use sigprocmask.\n"); + exit(EXIT_FAILURE); + } + + if (handler_called != 1) { + perror("Handler wasn't called, implying signal was not delivered.\n"); + exit(EXIT_FAILURE); + } + + printf("Test PASSED: signal was delivered before the call to sigprocmask returned.\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/sigprocmask-9.c b/tests/signals/sigprocmask-9.c new file mode 100644 index 0000000000..e34c652d42 --- /dev/null +++ b/tests/signals/sigprocmask-9.c @@ -0,0 +1,32 @@ +#include +#include +#include + +int main() { + + sigset_t set1, set2; + int sigprocmask_return_val = 1; + + sigemptyset(&set1); + sigemptyset(&set2); + sigaddset(&set1, SIGKILL); + sigaddset(&set1, SIGSTOP); + sigprocmask_return_val = sigprocmask(SIG_SETMASK, &set1, NULL); + sigprocmask(SIG_SETMASK, NULL, &set2); + + if (sigismember(&set2, SIGKILL)) { + printf("FAIL: SIGKILL was added to the signal mask\n"); + exit(EXIT_FAILURE); + } + if (sigismember(&set2, SIGSTOP)) { + printf("FAIL: SIGSTOP was added to the signal mask\n"); + exit(EXIT_FAILURE); + } + if (sigprocmask_return_val == -1) { + printf("FAIL: sigprocmask returned -1. System should be able to enforce blocking un-ignorable signals without causing sigprocmask() to return -1.\n"); + exit(EXIT_FAILURE); + } + + printf("Test PASSED\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/sigprocmask-block.c b/tests/signals/sigprocmask-block.c new file mode 100644 index 0000000000..3d7174ccb3 --- /dev/null +++ b/tests/signals/sigprocmask-block.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int handler_called = 0; + +void sig_handler(int signo) +{ + (void) signo; + handler_called = 1; +} + +int sigprocmask_block(int signum) +{ + int defaultsig = SIGALRM; + if (signum == SIGALRM) { + defaultsig = SIGHUP; + } + struct sigaction act; + sigset_t blocked_set1, blocked_set2, pending_set; + sigemptyset(&blocked_set1); + sigemptyset(&blocked_set2); + sigaddset(&blocked_set1, signum); + sigaddset(&blocked_set2, defaultsig); + + act.sa_handler = sig_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + + if (sigaction(signum, &act, 0) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + + if (sigaction(defaultsig, &act, 0) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (sigprocmask(SIG_SETMASK, &blocked_set1, NULL) == -1) { + perror("Unexpected error while attempting to use sigprocmask.\n"); + exit(EXIT_FAILURE); + } + + if (sigprocmask(SIG_BLOCK, &blocked_set2, NULL) == -1) { + perror("Unexpected error while attempting to use sigprocmask.\n"); + exit(EXIT_FAILURE); + } + + if ((raise(signum) == -1) | (raise(defaultsig) == -1)) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (handler_called) { + printf("FAIL: Signal was not blocked\n"); + exit(EXIT_FAILURE); + } + + if (sigpending(&pending_set) == -1) { + perror("Unexpected error while attempting to use sigpending\n"); + exit(EXIT_FAILURE); + } + + if ((sigismember(&pending_set, signum) != 1) | (sigismember(&pending_set, defaultsig) != 1)) { + perror("FAIL: sigismember did not return 1\n"); + exit(EXIT_FAILURE); + } + + printf("Test PASSED: signal was added to the process's signal mask\n"); + act.sa_handler = SIG_IGN; + sigaction(signum, &act, 0); + sigaction(defaultsig, &act, 0); + + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int handler_called = 0; + +void sig_handler(int signo) +{ + (void) signo; + handler_called = 1; +} + +int sigprocmask_block(int signum) +{ + int defaultsig = SIGALRM; + (void) defaultsig; + if (signum == SIGALRM) { + defaultsig = SIGHUP; + } + struct sigaction act; + sigset_t blocked_set, pending_set; + sigemptyset(&blocked_set); + sigaddset(&blocked_set, signum); + + act.sa_handler = sig_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + + if (sigaction(signum, &act, 0) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (sigprocmask(SIG_SETMASK, &blocked_set, NULL) == -1) { + perror("Unexpected error while attempting to use sigprocmask.\n"); + exit(EXIT_FAILURE); + } + + if (raise(signum) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (handler_called) { + printf("FAIL: Signal was not blocked\n"); + exit(EXIT_FAILURE); + } + + if (sigpending(&pending_set) == -1) { + perror("Unexpected error while attempting to use sigpending\n"); + exit(EXIT_FAILURE); + } + + if (sigismember(&pending_set, signum) != 1) { + perror("FAIL: sigismember did not return 1\n"); + exit(EXIT_FAILURE); + } + + printf("Test PASSED: signal was added to the process's signal mask\n"); + act.sa_handler = SIG_IGN; + sigaction(signum, &act, 0); + + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +#define _XOPEN_SOURCE 700 + +int handler_called = 0; + +void sig_handler(int signo) +{ + (void) signo; + handler_called = 1; +} + +int sigrelse_test(int signum) +{ + struct sigaction act; + + act.sa_handler = sig_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + if (sigaction(signum, &act, 0) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + sighold(signum); + + if (raise(signum) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + exit(EXIT_FAILURE); + } + + if (handler_called) { + printf("UNRESOLVED. possible problem in sigrelse\n"); + exit(EXIT_FAILURE); + } + + if (sigrelse(signum) == -1) { + printf("UNRESOLVED. possible problem in sigrelse\n"); + exit(EXIT_FAILURE); + } + + sleep(1); + + if (handler_called) { + printf("PASS: %d successfully removed from signal mask\n", signum); + handler_called = 0; + return EXIT_SUCCESS; + } + printf("FAIL\n"); + exit(EXIT_FAILURE); + return EXIT_FAILURE; +} + +int main(){ + for (int i=1; i +#include +#include + +int main() +{ + + if ((int)sigrelse(SIGABRT) != 0) { + perror("sigrelse failed -- returned -- test aborted"); + exit(EXIT_FAILURE); + } + printf("sigrelse passed\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/sigrelse-3.c b/tests/signals/sigrelse-3.c new file mode 100644 index 0000000000..a0572e259d --- /dev/null +++ b/tests/signals/sigrelse-3.c @@ -0,0 +1,20 @@ +#define _XOPEN_SOURCE 700 + +#include +#include +#include +#include + +int main() +{ + if ((int)sigrelse(100000) == -1) { + + if (EINVAL == errno) { + printf ("errno set to EINVAL\n"); + return EXIT_SUCCESS; + } else { + printf ("errno not set to EINVAL\n"); + exit(EXIT_FAILURE); + } + } +} \ No newline at end of file diff --git a/tests/signals/sigset-1.c b/tests/signals/sigset-1.c new file mode 100644 index 0000000000..17f261d482 --- /dev/null +++ b/tests/signals/sigset-1.c @@ -0,0 +1,48 @@ +#define _XOPEN_SOURCE 600 + +#include +#include +#include + +int handler_called = 0; + +void sig_handler(int signo) +{ + (void) signo; + printf("SIGURG called. Inside handler\n"); + handler_called = 1; +} + +int sigset_test(int signum) +{ + + struct sigaction act; + act.sa_handler = sig_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + + if (sigaction(signum, &act, 0) != 0) { + perror("Unexpected error while using sigaction()"); + exit(EXIT_FAILURE); + } + + if (sigset(signum,SIG_DFL) != sig_handler) { + perror("Unexpected error while using signal()"); + exit(EXIT_FAILURE); + } + + raise(signum); + + if (handler_called == 1) { + printf("Test FAILED: handler was called even though default was expected\n"); + exit(EXIT_FAILURE); + } + printf("test passed, the signal was ignored\n"); + return EXIT_SUCCESS; +} + +int main(){ + sigset_test(SIGURG); + return EXIT_SUCCESS; +} + diff --git a/tests/signals/sigset-10.c b/tests/signals/sigset-10.c new file mode 100644 index 0000000000..e6b8d478c8 --- /dev/null +++ b/tests/signals/sigset-10.c @@ -0,0 +1,21 @@ +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include + +int main() +{ + if (sigset(SIGKILL,SIG_IGN) == SIG_ERR) { + if (errno != EINVAL) { + printf("Test FAILED: sigset() returned SIG_ERR but didn't set errno to EINVAL\n"); + exit(EXIT_FAILURE); + } + } else { + printf("Test FAILED: sigset() didn't return SIG_ERROR even though SIGKILL was passed to it\n"); + exit(EXIT_FAILURE); + } + printf("test passed: error was set successfully\n"); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/sigset-2.c b/tests/signals/sigset-2.c new file mode 100644 index 0000000000..35aacbcb13 --- /dev/null +++ b/tests/signals/sigset-2.c @@ -0,0 +1,54 @@ +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int handler_called = 0; + +void sig_handler(int signo) +{ + (void) signo; + printf("SIGUSR1 called. Inside handler\n"); + handler_called = 1; +} + +int sigset_test2(int signum) +{ + struct sigaction act; + act.sa_flags = 0; + act.sa_handler = sig_handler; + sigemptyset(&act.sa_mask); + + if (sigaction(signum, &act, 0) != 0) { + perror("Unexpected error while using sigaction()"); + exit(EXIT_FAILURE); + } + + if (sigset(signum,SIG_IGN) != sig_handler) { + perror("Unexpected error while using signal()"); + exit(EXIT_FAILURE); + } + + raise(signum); + + if (handler_called == 1) { + printf("Test FAILED: handler was called even though ignore was expected\n"); + exit(EXIT_FAILURE); + } + printf("test %d passed, the signal was ignored\n", signum); + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int handler_called = 0; + +void sig_handler(int signo) +{ + (void) signo; + // printf("SIGCHLD called. Inside handler\n"); + handler_called = 1; +} + +int sigset_test3(int signum) +{ + if (sigset(signum, sig_handler) == SIG_ERR) { + perror("Unexpected error while using sigset()"); + exit(EXIT_FAILURE); + } + + raise(signum); + + if (handler_called != 1) { + printf("Test FAILED: handler wasn't called even though it was expected\n"); + exit(EXIT_FAILURE); + } + printf("test %d passed, handler was called\n", signum); + handler_called = 0; + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +int signal_blocked = 0; +int count = 1; + +void sig_handler(int signo) +{ + (void) signo; + // printf("SIGCHLD called. Inside handler\n"); + sigset_t mask; + sigprocmask(SIG_SETMASK, NULL, &mask); + if (count == SIGKILL || count == SIGSTOP){ + count++; + } + if(sigismember(&mask, count)) { + signal_blocked = 1; + } + count++; +} + +int sigset_test4(int signum) +{ + if (sigset(signum, sig_handler) == SIG_ERR) { + perror("Unexpected error while using sigset()"); + exit(EXIT_FAILURE); + } + + raise(signum); + + if (signal_blocked != 1) { + printf("Test FAILED: signal was not added to the mask before the handler was executed\n"); + exit(EXIT_FAILURE); + } + signal_blocked = 0; + printf("test %d passed: the singal was added to the mask before the handler was executed\n", signum); + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +#define NUMSIGNALS 26 + +int is_empty(sigset_t *set) { + + int i; + int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, + SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, + SIGPIPE, SIGQUIT, SIGSEGV, + SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, + SIGUSR1, SIGUSR2, SIGPROF, SIGSYS, + SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; + + for (i=0; i +#include +#include +#include "signals_list.h" +#include "../test_helpers.h" + +void sig_handler(int signo) +{ + (void) signo; + printf("SIGUSR1 called. Inside handler\n"); +} + +int sigset_test9(int signum) +{ + struct sigaction act; + act.sa_flags = 0; + act.sa_handler = sig_handler; + sigemptyset(&act.sa_mask); + + if (sigaction(signum, &act, 0) != 0) { + perror("Unexpected error while using sigaction()"); + exit(EXIT_FAILURE); + } + + if (sigset(signum,SIG_DFL) != sig_handler) { + printf("Test FAILED: sigset didn't return myhandler even though it was SIGUSR1's original disposition\n"); + exit(EXIT_FAILURE); + } + printf("test %d passed \n", signum); + return EXIT_SUCCESS; +} + +int main(){ + for (int i=1; i #include #include +#include #include #include