From 901b8099a28f94855a37df2582993ca64586c82e Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Thu, 5 Dec 2024 17:00:10 -0800 Subject: [PATCH 01/20] 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 From 9116eaa66dd77047772f0f52ea7d0450511fdce9 Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Mon, 23 Dec 2024 23:16:06 -0800 Subject: [PATCH 02/20] clean up a bunch of tests --- tests/signals/kill-group.c | 51 ++++++++++++++++++ tests/signals/kill-invalid.c | 19 ++----- tests/signals/kill-permission.c | 25 +++------ tests/signals/kill-self.c | 6 +-- tests/signals/killpg-esrch.c | 15 ++---- tests/signals/killpg-invalid.c | 23 +++----- tests/signals/killpg-self.c | 27 ++++------ tests/signals/killpg0-self.c | 16 +++--- tests/signals/pthread_kill-invalid.c | 11 ++-- tests/signals/pthread_kill0-self.c | 10 ++-- tests/signals/sigaddset-add.c | 15 +++--- tests/signals/sigdelset-delete.c | 15 +++--- tests/signals/sigismember-invalid.c | 14 ++--- tests/signals/sigismember-valid.c | 22 +++++--- tests/signals/sigpause-pause.c | 22 +++----- tests/signals/sigpause-suspend.c | 27 +++------- tests/signals/sigprocmask-11.c | 8 ++- tests/signals/sigprocmask-3.c | 70 ++++++++----------------- tests/signals/sigprocmask-4.c | 2 - tests/signals/sigprocmask-5.c | 1 - tests/signals/sigprocmask-6.c | 1 - tests/signals/sigprocmask-7.c | 1 - tests/signals/sigprocmask-8.c | 36 +++++-------- tests/signals/sigprocmask-9.c | 5 +- tests/signals/sigprocmask-blocksingle.c | 43 ++++++--------- tests/signals/sigrelse-2.c | 9 ++-- tests/signals/sigrelse-3.c | 23 ++++---- 27 files changed, 221 insertions(+), 296 deletions(-) create mode 100644 tests/signals/kill-group.c diff --git a/tests/signals/kill-group.c b/tests/signals/kill-group.c new file mode 100644 index 0000000000..cde477390e --- /dev/null +++ b/tests/signals/kill-group.c @@ -0,0 +1,51 @@ +#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 kill_group(int signum) +{ + int pgrp; + struct sigaction act; + int status; + + act.sa_handler=sig_handler; + act.sa_flags=0; + status = sigemptyset(&act.sa_mask); + ERROR_IF(sigemptyset, status, == -1); + + status = sigaction(signum, &act, 0); + ERROR_IF(sigaction, staus, == -1); + + staus = getpgrp(); + ERROR_IF(getpgrp, status, == -1); + + status = kill(-pgrp, signum); + ERROR_IF(kill, staus, != 0); + + return EXIT_SUCCESS; +} + +// If pid is negative, but not -1, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the absolute value of pid, and for which the process has permission to send a signal. +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; + } + kill_group(sig); + } + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/tests/signals/kill-invalid.c b/tests/signals/kill-invalid.c index e3e478e01c..5a6ea5f5cf 100644 --- a/tests/signals/kill-invalid.c +++ b/tests/signals/kill-invalid.c @@ -12,18 +12,9 @@ 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"); + int status; + status = kill(999999, 0); + ERROR_IF(kill, status, != -1); + ERROR_IF(kill, errno, != ESRCH); + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/kill-permission.c b/tests/signals/kill-permission.c index 57346df06f..bad0a625f8 100644 --- a/tests/signals/kill-permission.c +++ b/tests/signals/kill-permission.c @@ -6,22 +6,13 @@ #include #include "../test_helpers.h" -int main() +int main(void) { - 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; + int status; + // This is added incase user is root. If user is normal user, then it has no effect on the tests + setuid(1000); + status = kill(1, 0); + ERROR_IF(kill, status, != -1); + ERROR_IF(kill, errno, !=EPERM); + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/kill-self.c b/tests/signals/kill-self.c index f208c2f91b..b72d50170d 100644 --- a/tests/signals/kill-self.c +++ b/tests/signals/kill-self.c @@ -34,11 +34,7 @@ int kill_self(int sig) status = kill(getpid(), sig); ERROR_IF(kill, status, != 0); - if (handler_called == 0) - { - printf("Handler was not called\n"); - exit(EXIT_FAILURE); - } + ERROR_IF(kill, handler_called, == 0); return EXIT_SUCCESS; } diff --git a/tests/signals/killpg-esrch.c b/tests/signals/killpg-esrch.c index 32b8cea409..a8a40caa67 100644 --- a/tests/signals/killpg-esrch.c +++ b/tests/signals/killpg-esrch.c @@ -10,16 +10,11 @@ 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); - } + int status; + status = killpg(999999, 0); + ERROR_IF(killpg, status, !=-1); - if (errno != ESRCH) { - printf("killpg did not set errno to ESRCH even though it was passed an invalid signal number."); - exit(EXIT_FAILURE); - } + ERROR_IF(killpg, errno, != ESRCH); - printf("Test PASSED\n"); - return 0; + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/killpg-invalid.c b/tests/signals/killpg-invalid.c index 243b140415..e349269174 100644 --- a/tests/signals/killpg-invalid.c +++ b/tests/signals/killpg-invalid.c @@ -11,21 +11,14 @@ int main() { int pgrp; - if ((pgrp = getpgrp()) == -1) { - printf("Could not get process group number\n"); - exit(EXIT_FAILURE); - } + pgrp = getpgrp(); + ERROR_IF(getpgrp, pgrp, == -1); + + int status; + status = killpg(pgrp, -1); + ERROR_IF(killpg, status, != -1); - if (killpg(pgrp, -1) != -1) { - printf("killpg did not return -1 even though it was passed an invalid signal number."); - exit(EXIT_FAILURE); - } + ERROR_IF(killpg, errno, != EINVAL); - 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; + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/killpg-self.c b/tests/signals/killpg-self.c index e8ce85fa2b..b12c8a8e16 100644 --- a/tests/signals/killpg-self.c +++ b/tests/signals/killpg-self.c @@ -19,26 +19,19 @@ int killpg_test1(int signum) 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); - } + int status = sigemptyset(&act.sa_mask); + ERROR_IF(sigemptyset, status, == -1); - if ((pgrp = getpgrp()) == -1) { - printf("Could not get process group number\n"); - exit(EXIT_FAILURE); - } + status = sigaction(signum, &act, 0); + ERROR_IF(sigaction, status, == -1); - if (killpg(pgrp, signum) != 0) { - printf("Could not raise signal being tested\n"); - exit(EXIT_FAILURE); - } + pgrp = getpgrp() + ERROR_IF(getpgrp, pgrp, == -1); - return 0; + status = killpg(pgrp, signum); + ERROR_IF(killpg, status, != 0); + + return EXIT_SUCCESS; } int main(){ diff --git a/tests/signals/killpg0-self.c b/tests/signals/killpg0-self.c index 2279c144e5..634011677f 100644 --- a/tests/signals/killpg0-self.c +++ b/tests/signals/killpg0-self.c @@ -9,16 +9,14 @@ int main() { int pgrp; - if ((pgrp = getpgrp()) == -1) { - printf("Could not get process group number\n"); - exit(EXIT_FAILURE); - } + pgrp = getpgrp(); + ERROR_IF(getpgrp, pgrp, == -1); + + int status; + status = killpg(pgrp, 0); + ERROR_IF(killpg, status, != 0); - if (killpg(pgrp, 0) != 0) { - printf("killpg did not return success.\n"); - exit(EXIT_FAILURE); - } printf("Test PASSED\n"); - return 0; + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/pthread_kill-invalid.c b/tests/signals/pthread_kill-invalid.c index 48a57e986b..71fe887e81 100644 --- a/tests/signals/pthread_kill-invalid.c +++ b/tests/signals/pthread_kill-invalid.c @@ -12,10 +12,9 @@ int main() 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; + int status; + status = pthread_kill(main_thread, -1); + ERROR_IF(pthread_kill, status, != EINVAL); + + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/pthread_kill0-self.c b/tests/signals/pthread_kill0-self.c index 45d1ab067a..3fdca12fe1 100644 --- a/tests/signals/pthread_kill0-self.c +++ b/tests/signals/pthread_kill0-self.c @@ -10,11 +10,9 @@ int main() main_thread=pthread_self(); - if (pthread_kill(main_thread, 0) != 0) { - printf("Could not call pthread_kill with sig = 0\n"); - exit(EXIT_FAILURE); - } + int status; + status = pthread_kill(main_thread, 0); + ERROR_IF(pthread_kill, status, != 0); - printf("Test PASSED\n"); - return 0; + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/sigaddset-add.c b/tests/signals/sigaddset-add.c index c5c4044ba0..419cb507f1 100644 --- a/tests/signals/sigaddset-add.c +++ b/tests/signals/sigaddset-add.c @@ -14,16 +14,13 @@ void addset_test(sigset_t *sigset, int signal){ - if (sigismember(sigset, signal) !=0){ - printf("the signal is already in the set, %d\n", signal); - } + int status; + status = sigismember(sigset, signal); + ERROR_IF(sigismember, status, != 0); 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"); - } + + status = sigismember(sigset, signal); + ERROR_IF(sigismember, status, != 1); } diff --git a/tests/signals/sigdelset-delete.c b/tests/signals/sigdelset-delete.c index 72dc04f2a6..6d72896df1 100644 --- a/tests/signals/sigdelset-delete.c +++ b/tests/signals/sigdelset-delete.c @@ -15,16 +15,13 @@ 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); - } + int status; + status = sigismember(sigset, signal); + ERROR_IF(sigismember, status, != 1); + 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"); - } + status = sigismember(sigset, signal); + ERROR_IF(sigismember, status, != 0); } diff --git a/tests/signals/sigismember-invalid.c b/tests/signals/sigismember-invalid.c index 86432bd727..ce26321caa 100644 --- a/tests/signals/sigismember-invalid.c +++ b/tests/signals/sigismember-invalid.c @@ -9,17 +9,13 @@ int main() { sigset_t sigset; + int status; 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); - } + status = sigismember(&sigset, -1); + ERROR_IF(sigismember, status, != -1); + ERROR_IF(sigismember, errno, != EINVAL); - printf ("errno set to EINVAL and sigismember returned -1\n"); - return 0; + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/sigismember-valid.c b/tests/signals/sigismember-valid.c index daf39d7b9c..3f81ee50f7 100644 --- a/tests/signals/sigismember-valid.c +++ b/tests/signals/sigismember-valid.c @@ -10,11 +10,21 @@ #include "signals_list.h" #include "../test_helpers.h" -void check(sigset_t set, int signum) { +void check_full(sigset_t set, int signum) { + if (!sigismember(&set, signum)) { + printf("%d was not added to the set", signum); + exit(EXIT_FAILURE); + } + +} + +void check_empty(sigset_t set, int signum) { printf("%d is ", signum); - if (!sigismember(&set, signum)) - printf("not "); - puts("in the set"); + if (sigismember(&set, signum)) { + printf("%d was not removed from the set", signum); + exit(EXIT_FAILURE); + } + } @@ -24,12 +34,12 @@ int main() { sigfillset(&sigset); for (int i=1; i #include #include +#include "../test_helpers.h" int handler_called = 0; int sigprocmask_return_val = 1; /* some value that's not a 1 or 0 */ @@ -26,35 +27,22 @@ int main() 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); - } + int status; - if (sigprocmask(SIG_SETMASK, &blocked_set1, NULL) == -1) { - perror("Unexpected error while attempting to use sigprocmask.\n"); - exit(EXIT_FAILURE); - } + status = sigaction(SIGABRT, &act, 0); + ERROR_IF(sigaction, status, == -1); - if ((raise(SIGABRT) == -1)) { - perror("Unexpected error while attempting to setup test " - "pre-conditions"); - exit(EXIT_FAILURE); - } + status = sigprocmask(SIG_SETMASK, &blocked_set1, NULL); + ERROR_IF(sigprocmask, status, == -1); + + status = raise(SIGABRT); + ERROR_IF(raise, status, == -1); 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); - } + ERROR_IF(sigprocmask, sigprocmask_return_val, != 0); + + ERROR_IF(raise, handler_called, != 1); - 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 index e34c652d42..7f5cb44956 100644 --- a/tests/signals/sigprocmask-9.c +++ b/tests/signals/sigprocmask-9.c @@ -14,19 +14,16 @@ int main() { 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-blocksingle.c b/tests/signals/sigprocmask-blocksingle.c index 0ddd466715..8e8d54f7af 100644 --- a/tests/signals/sigprocmask-blocksingle.c +++ b/tests/signals/sigprocmask-blocksingle.c @@ -28,39 +28,28 @@ int sigprocmask_block(int signum) 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); - } + int status; + status = sigaction(signum, &act, 0); + ERROR_IF(sigaction, status, == -1); - if (sigprocmask(SIG_SETMASK, &blocked_set, NULL) == -1) { - perror("Unexpected error while attempting to use sigprocmask.\n"); - exit(EXIT_FAILURE); - } + status = sigprocmask(SIG_SETMASK, &blocked_set, NULL); + ERROR_IF(sigprocmask, status, == -1); - if (raise(signum) == -1) { - perror("Unexpected error while attempting to setup test " - "pre-conditions"); - exit(EXIT_FAILURE); - } + status = raise(signum); + ERROR_IF(raise, status, == -1); - if (handler_called) { - printf("FAIL: Signal was not blocked\n"); - exit(EXIT_FAILURE); - } + ERROR_IF(raise, handler_called, == 1); + // 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); - } + status = sigpending(&pending_set); + ERROR_IF(sigpending, status, == -1); - if (sigismember(&pending_set, signum) != 1) { - perror("FAIL: sigismember did not return 1\n"); - exit(EXIT_FAILURE); - } + status = sigismember(&pending_set, signum); + ERROR_IF(sigismember, status, != 1); - printf("Test PASSED: signal was added to the process's signal mask\n"); act.sa_handler = SIG_IGN; sigaction(signum, &act, 0); diff --git a/tests/signals/sigrelse-2.c b/tests/signals/sigrelse-2.c index e7a6922a0f..cfe927836d 100644 --- a/tests/signals/sigrelse-2.c +++ b/tests/signals/sigrelse-2.c @@ -6,11 +6,8 @@ int main() { - - if ((int)sigrelse(SIGABRT) != 0) { - perror("sigrelse failed -- returned -- test aborted"); - exit(EXIT_FAILURE); - } - printf("sigrelse passed\n"); + int status; + status = (int)sigrelse(SIGABRT); + ERROR_IF(sigrelse, status, != 0); return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/sigrelse-3.c b/tests/signals/sigrelse-3.c index a0572e259d..863d592ffe 100644 --- a/tests/signals/sigrelse-3.c +++ b/tests/signals/sigrelse-3.c @@ -7,14 +7,19 @@ int main() { - if ((int)sigrelse(100000) == -1) { + int status; + status = (int)sigrelse(100000); + ERROR_IF(sigrelse, status, != -1); + ERROR_IF(sigrelse, errno, != EINVAL); + return EXIT_SUCCESS; + // 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); - } - } + // 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 From 6f787d20e558128e3a7da464667cbf6372f35a4a Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Wed, 15 Jan 2025 16:44:16 -0800 Subject: [PATCH 03/20] clean up some tests --- tests/signals/kill-child.c | 15 +++----- tests/signals/kill-invalid.c | 2 + tests/signals/killpg-child.c | 25 +++++-------- tests/signals/killpg-esrch.c | 3 +- tests/signals/killpg-invalid.c | 3 +- tests/signals/killpg-self.c | 9 +++-- tests/signals/killpg0-self.c | 7 ++-- tests/signals/pthread_kill-child.c | 32 ++++++---------- tests/signals/pthread_kill-invalid.c | 3 ++ tests/signals/pthread_kill-self.c | 35 +++++++---------- tests/signals/pthread_kill0-self.c | 5 ++- tests/signals/raise-compliance.c | 9 ++--- tests/signals/sigaddset-add.c | 18 +++++---- tests/signals/sigdelset-delete.c | 17 ++++----- tests/signals/sigismember-invalid.c | 4 +- tests/signals/sigismember-valid.c | 19 ++++------ tests/signals/sigpause-error.c | 25 +++++++------ tests/signals/sigpause-invalid.c | 5 +++ tests/signals/sigpause-pause.c | 30 +++++++++------ tests/signals/sigpause-revert.c | 3 ++ tests/signals/sigpause-suspend.c | 18 +++++---- tests/signals/sigprocmask-10.c | 18 ++++----- tests/signals/sigprocmask-11.c | 4 +- tests/signals/sigprocmask-12.c | 27 ++++++++----- tests/signals/sigprocmask-3.c | 9 +++-- tests/signals/sigprocmask-4.c | 2 + tests/signals/sigprocmask-5.c | 3 ++ tests/signals/sigprocmask-8.c | 3 ++ tests/signals/sigprocmask-9.c | 5 +++ tests/signals/sigprocmask-block.c | 50 +++++++++---------------- tests/signals/sigprocmask-blocksingle.c | 19 ++++------ tests/signals/sigrelse-1.c | 50 ++++++++++++------------- tests/signals/sigrelse-2.c | 3 +- 33 files changed, 237 insertions(+), 243 deletions(-) diff --git a/tests/signals/kill-child.c b/tests/signals/kill-child.c index 3e593ef1b1..809564789c 100644 --- a/tests/signals/kill-child.c +++ b/tests/signals/kill-child.c @@ -19,8 +19,6 @@ void sig_handler(int signo) void child_proc(int signum) { - int sig; - (void) sig; sigset_t sig_set; int status; @@ -41,11 +39,7 @@ void child_proc(int signum) status = sleep(10); ERROR_IF(sleep, status, == 0); - if (sig_handled == 0) - { - printf("signal handler was not called"); - exit(EXIT_FAILURE); - } + ERROR_IF(kill, sig_handled, == 0 ); exit(EXIT_SUCCESS); } @@ -88,13 +82,14 @@ void kill_child(int signum) int main() { - for (int i = 1; i < N_SIGNALS; i++) + for (int i = 1; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) { - if (i == SIGKILL || i == SIGSTOP) + int sig = signals_list[i].signal; + if (sig == SIGKILL || i == SIGSTOP) { continue; } - kill_child(i); + kill_child(sig); } return EXIT_SUCCESS; } diff --git a/tests/signals/kill-invalid.c b/tests/signals/kill-invalid.c index 5a6ea5f5cf..8cf8e7d3e6 100644 --- a/tests/signals/kill-invalid.c +++ b/tests/signals/kill-invalid.c @@ -6,6 +6,8 @@ #include #include "../test_helpers.h" +//this test ensures that sending an invalid signal will set errno to esrch + int main() { diff --git a/tests/signals/killpg-child.c b/tests/signals/killpg-child.c index d1edddcb96..1cec7b8607 100644 --- a/tests/signals/killpg-child.c +++ b/tests/signals/killpg-child.c @@ -6,6 +6,8 @@ #include "signals_list.h" #include "../test_helpers.h" +// test killing a child process + void sig_handler (int signo) { (void) signo; exit(1); @@ -36,21 +38,16 @@ int killpg_test2(int signum) sigignore(signum); sleep(1); - if ((child_pgid = getpgid(child_pid)) == -1) { - printf("Could not get pgid of child\n"); - exit(EXIT_FAILURE); - } + + child_pgid = getpgid(child_pid); + ERROR_IF(getpgid, child_pgid, == -1); + int status; + status = killpg(child_pgid, signum); + ERROR_IF(killpg, status, != 0); - 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); - } + status = wait(&i); + ERROR_IF(wait, status, == -1); if (WEXITSTATUS(i)) { printf("Child exited normally\n"); @@ -63,8 +60,6 @@ int killpg_test2(int signum) } } - printf("Should have exited from parent\n"); - printf("Test FAILED\n"); return EXIT_FAILURE; } diff --git a/tests/signals/killpg-esrch.c b/tests/signals/killpg-esrch.c index a8a40caa67..ab1e62cd96 100644 --- a/tests/signals/killpg-esrch.c +++ b/tests/signals/killpg-esrch.c @@ -1,5 +1,3 @@ -#define _XOPEN_SOURCE 600 - #include #include #include @@ -7,6 +5,7 @@ #include #include "../test_helpers.h" +// if a user tries to kill a process that does not exist the esrch error will be returned int main() { diff --git a/tests/signals/killpg-invalid.c b/tests/signals/killpg-invalid.c index e349269174..b1f89dc023 100644 --- a/tests/signals/killpg-invalid.c +++ b/tests/signals/killpg-invalid.c @@ -1,5 +1,3 @@ -#define _XOPEN_SOURCE 600 - #include #include #include @@ -7,6 +5,7 @@ #include #include "../test_helpers.h" +// the test makes sure that if an invalid signal is passed it will return the EINVAL error int main() { int pgrp; diff --git a/tests/signals/killpg-self.c b/tests/signals/killpg-self.c index b12c8a8e16..41186f0573 100644 --- a/tests/signals/killpg-self.c +++ b/tests/signals/killpg-self.c @@ -5,10 +5,13 @@ #include "signals_list.h" #include "../test_helpers.h" +// Test that the killpg() function shall send signal sig to the process +// group specified by prgp. + void sig_handler(int signo) { - printf("Caught signal %d being tested!\n", signo); - printf("Test PASSED\n"); + // printf("Caught signal %d being tested!\n", signo); + // printf("Test PASSED\n"); return; } @@ -25,7 +28,7 @@ int killpg_test1(int signum) status = sigaction(signum, &act, 0); ERROR_IF(sigaction, status, == -1); - pgrp = getpgrp() + pgrp = getpgrp(); ERROR_IF(getpgrp, pgrp, == -1); status = killpg(pgrp, signum); diff --git a/tests/signals/killpg0-self.c b/tests/signals/killpg0-self.c index 634011677f..444e02939f 100644 --- a/tests/signals/killpg0-self.c +++ b/tests/signals/killpg0-self.c @@ -1,9 +1,10 @@ -#define _XOPEN_SOURCE 600 - #include #include #include #include +#include "../test_helpers.h" + +// test sending signal 0 to self will killpg int main() { @@ -16,7 +17,5 @@ int main() status = killpg(pgrp, 0); ERROR_IF(killpg, status, != 0); - - printf("Test PASSED\n"); return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/pthread_kill-child.c b/tests/signals/pthread_kill-child.c index f3df951a16..842bd68e73 100644 --- a/tests/signals/pthread_kill-child.c +++ b/tests/signals/pthread_kill-child.c @@ -5,6 +5,9 @@ #include #include #include +#include "../test_helpers.h" + +//test with pthread_kill to kill a child process void * thread_function(void *arg) { @@ -25,32 +28,19 @@ int main() rc = pthread_create(&child_thread, NULL, thread_function, NULL); - if (rc != 0) - { - printf("Error at pthread_create()\n"); - exit(EXIT_FAILURE); - } + ERROR_IF(pthread_create, rc, != 0); rc = pthread_join(child_thread, NULL); - if (rc != 0) - { - printf("Error at pthread_join()\n"); - exit(EXIT_FAILURE); - } + ERROR_IF(pthread_join, rc, != 0); - /* Now the child_thread exited, it is an invalid tid */ + // 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); + int status; + status = pthread_kill(invalid_tid, 0); + ERROR_IF(pthread_kill, status, != ESRCH); + + exit(EXIT_SUCCESS); } \ No newline at end of file diff --git a/tests/signals/pthread_kill-invalid.c b/tests/signals/pthread_kill-invalid.c index 71fe887e81..053f817557 100644 --- a/tests/signals/pthread_kill-invalid.c +++ b/tests/signals/pthread_kill-invalid.c @@ -5,6 +5,9 @@ #include #include #include +#include "../test_helpers.h" + +//test with pthread_kill making sure sending an invalid signal returns einval int main() { diff --git a/tests/signals/pthread_kill-self.c b/tests/signals/pthread_kill-self.c index 6bd9f01bd7..8ea87658c1 100644 --- a/tests/signals/pthread_kill-self.c +++ b/tests/signals/pthread_kill-self.c @@ -7,6 +7,8 @@ #include "signals_list.h" #include "../test_helpers.h" +//test pthread_kill on self + # define INTHREAD 0 # define INMAIN 1 # define SIGTOTEST SIGABRT @@ -20,7 +22,6 @@ struct signal { }; void handler() { - printf("signal was called\n"); handler_called = 1; return; } @@ -55,37 +56,27 @@ int pthread_kill_test1(int signum) 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); - } + int status; + status = pthread_create(&new_th, NULL, a_thread_func, &arg); + ERROR_IF(pthread_create, status, != 0); 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); - } + status = pthread_kill(new_th, signum); + ERROR_IF(pthread_kill, status, != 0); + 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; + ERROR_IF(pthread_kill, handler_called, == -1); + ERROR_IF(pthread_kill, handler_called, == 0); + + handler_called = 0; + return EXIT_SUCCESS; } int main(){ diff --git a/tests/signals/pthread_kill0-self.c b/tests/signals/pthread_kill0-self.c index 3fdca12fe1..a4723a9e94 100644 --- a/tests/signals/pthread_kill0-self.c +++ b/tests/signals/pthread_kill0-self.c @@ -3,12 +3,15 @@ #include #include #include +#include "../test_helpers.h" + +// test sending 0 with pthread_kill to self int main() { pthread_t main_thread; - main_thread=pthread_self(); + main_thread = pthread_self(); int status; status = pthread_kill(main_thread, 0); diff --git a/tests/signals/raise-compliance.c b/tests/signals/raise-compliance.c index 20e7e9629b..6722729398 100644 --- a/tests/signals/raise-compliance.c +++ b/tests/signals/raise-compliance.c @@ -1,14 +1,13 @@ -// 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" +// 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); + void sig_hand(int i) { diff --git a/tests/signals/sigaddset-add.c b/tests/signals/sigaddset-add.c index 419cb507f1..556d7781c6 100644 --- a/tests/signals/sigaddset-add.c +++ b/tests/signals/sigaddset-add.c @@ -1,9 +1,4 @@ - - // 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 @@ -11,13 +6,18 @@ #include "signals_list.h" #include "../test_helpers.h" + // 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. void addset_test(sigset_t *sigset, int signal){ - int status; + int status; + status = sigismember(sigset, signal); ERROR_IF(sigismember, status, != 0); - sigaddset(sigset, signal); + + status = sigaddset(sigset, signal); + ERROR_IF(sigaddset, status, != 0); status = sigismember(sigset, signal); ERROR_IF(sigismember, status, != 1); @@ -30,7 +30,9 @@ int main() { sigemptyset(&sigset); for (int i = 1; i < N_SIGNALS; i++){ - addset_test(&sigset, i); + int sig = signals_list[i-1].signal; + + addset_test(&sigset, sig); } diff --git a/tests/signals/sigdelset-delete.c b/tests/signals/sigdelset-delete.c index 6d72896df1..224d74a301 100644 --- a/tests/signals/sigdelset-delete.c +++ b/tests/signals/sigdelset-delete.c @@ -1,10 +1,3 @@ - - - // 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 @@ -12,6 +5,9 @@ #include "signals_list.h" #include "../test_helpers.h" +// 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. void delset_test(sigset_t *sigset, int signal){ @@ -19,7 +15,9 @@ void delset_test(sigset_t *sigset, int signal){ status = sigismember(sigset, signal); ERROR_IF(sigismember, status, != 1); - sigdelset(sigset, signal); + status = sigdelset(sigset, signal); + ERROR_IF(sigdelset, status, != 0); + status = sigismember(sigset, signal); ERROR_IF(sigismember, status, != 0); @@ -31,7 +29,8 @@ int main() { sigfillset(&sigset); for (int i = 1; i < N_SIGNALS; i++){ - delset_test(&sigset, i); + int sig = signals_list[i-1].signal; + delset_test(&sigset, sig); } } diff --git a/tests/signals/sigismember-invalid.c b/tests/signals/sigismember-invalid.c index ce26321caa..80c45fa236 100644 --- a/tests/signals/sigismember-invalid.c +++ b/tests/signals/sigismember-invalid.c @@ -3,9 +3,9 @@ #include #include #include +#include "../test_helpers.h" - - +// test to make sure that if you pass an invalid signal to sigismember it will return EINVAL int main() { sigset_t sigset; diff --git a/tests/signals/sigismember-valid.c b/tests/signals/sigismember-valid.c index 3f81ee50f7..e6c54f5894 100644 --- a/tests/signals/sigismember-valid.c +++ b/tests/signals/sigismember-valid.c @@ -1,27 +1,22 @@ - // 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" +// 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. + void check_full(sigset_t set, int signum) { if (!sigismember(&set, signum)) { - printf("%d was not added to the set", signum); exit(EXIT_FAILURE); } } void check_empty(sigset_t set, int signum) { - printf("%d is ", signum); if (sigismember(&set, signum)) { - printf("%d was not removed from the set", signum); exit(EXIT_FAILURE); } @@ -34,12 +29,14 @@ int main() { sigfillset(&sigset); for (int i=1; i #include +// This program verifies that sigpause() returns -1 and sets errno to EINVAL +// if passed an invalid signal number. + #define INMAIN 0 #define INTHREAD 1 @@ -26,6 +29,8 @@ int sigpause_invalid(){ int return_value = 0; return_value = sigpause(-1); + ERROR_IF(sigpause, return_value, != -1); + ERROR_IF(sigpause, errno, != EINVAL); if (return_value == -1) { if (errno == EINVAL) { printf ("Test PASSED: sigpause returned -1 and set errno to EINVAL\n"); diff --git a/tests/signals/sigpause-pause.c b/tests/signals/sigpause-pause.c index 751f0c0cda..4caf0e62c8 100644 --- a/tests/signals/sigpause-pause.c +++ b/tests/signals/sigpause-pause.c @@ -1,5 +1,3 @@ -#define _XOPEN_SOURCE 700 - #include #include #include @@ -9,25 +7,31 @@ #include "signals_list.h" #include "../test_helpers.h" +// This program verifies that sigpause() removes sig from the signal mask. + int handler_called = 0; void handler() { - // printf("signal was called\n"); handler_called = 1; return; } void *a_thread_func(void *sig) { + int status; int signum = *(int *)sig; - printf("%d !!!\n", signum); + printf("Pausing signal %s\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); + status = sigemptyset(&act.sa_mask); + ERROR_IF(sigemptyset, status, != 0); + status = sigaction(signum, &act, 0); + ERROR_IF(sigaction, status, != 0); + status = sighold(signum); + ERROR_IF(sighold, status, != 0); + status = sigpause(signum); + ERROR_IF(sigpause, status, != 0); return NULL; } @@ -48,7 +52,10 @@ int sigpause_basic(int signum) sleep(1); - ERROR_IF(pthread_kill, handler_called,, != 1); + if (handler_called != 1){ + prinft("handler wasn't called\n"); + exit(EXIT_FAILURE); + } handler_called = 0; return EXIT_SUCCESS; @@ -58,10 +65,11 @@ int sigpause_basic(int signum) int main(){ for (int i=1; i #include #include @@ -9,6 +7,9 @@ #include "signals_list.h" #include "../test_helpers.h" +// This program verifies that sigpause() suspends the calling process +// until it receives a signal. + #define INMAIN 0 #define INTHREAD 1 @@ -19,14 +20,13 @@ 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); + printf("Pausing signal %s\n", signum); struct sigaction act; act.sa_flags = 0; act.sa_handler = handler; @@ -50,7 +50,6 @@ int sigpause_suspend(int signum) for (j=0; j<10; j++) { sleep(1); - ERROR_IF(sigpuase, returned, == 1); } status = pthread_kill(new_th, signum); @@ -59,6 +58,10 @@ int sigpause_suspend(int signum) sleep(1); ERROR_IF(sigpuase, returned, != 1); + if (returned != 1){ + printf("returned != 1 \n"); + exit(EXIT_FAILURE); + } returned = 0; @@ -68,10 +71,11 @@ int sigpause_suspend(int signum) int main(){ for (int i=1; i #include #include +#include "../test_helpers.h" + +// The thread's signal mask shall not be changed, if sigprocmask( ) fails. #define NUMSIGNALS 24 @@ -43,23 +46,18 @@ int main() { sigprocmask(SIG_SETMASK, &actl, NULL); sigaddset(&actl, SIGALRM); - if (sigprocmask(r, &actl, NULL) != -1) { - perror("sigprocmask() did not fail even though invalid how parameter was passed to it.\n"); - exit(EXIT_FAILURE); - } + int status; + status = sigprocmask(r, &actl, NULL); + ERROR_IF(sigprocmask, status, != -1); sigprocmask(SIG_SETMASK, NULL, &oactl); - if (sigismember(&oactl, SIGABRT) != 1) { - printf("FAIL: signal mask was changed. \n"); - exit(EXIT_FAILURE); - } + status = sigismember(&oactl, SIGABRT); + ERROR_IF(sigismember, status, != -1); if (is_changed(oactl)) { - printf("FAIL: signal mask was changed. \n"); exit(EXIT_FAILURE); } - printf("PASS: signal mask was not changed.\n"); return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/sigprocmask-11.c b/tests/signals/sigprocmask-11.c index fa819d06e1..07f1c4a367 100644 --- a/tests/signals/sigprocmask-11.c +++ b/tests/signals/sigprocmask-11.c @@ -4,8 +4,10 @@ #include #include #include +#include "../test_helpers.h" -// I don't understand this test +// sigprocmask( ) shall return 0, Upon successful completion; otherwise, it shall return -1 +// and errno shall be set to indicate the error, and the process' signal mask shall be unchanged. int main() { diff --git a/tests/signals/sigprocmask-12.c b/tests/signals/sigprocmask-12.c index 590adcd948..fe01df4aa4 100644 --- a/tests/signals/sigprocmask-12.c +++ b/tests/signals/sigprocmask-12.c @@ -5,6 +5,10 @@ #include #include #include +#include "../test_helpers.h" + +// An errno value of [EINVAL] shall be returned and the sigprocmask() function shall fail, if the value of +// the how argument is not equal to one of the defined values. int main(int argc, char *argv[]) { @@ -41,16 +45,19 @@ int main(int argc, char *argv[]) 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); - } - } + int status; + status = sigprocmask(r, &set, NULL); + ERROR_IF(sigprocmask, status, != -1); + ERROR_IF(sigprocmask, errno, != EINVAL); + // 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 index a1fc2e06e3..9bb7e1359e 100644 --- a/tests/signals/sigprocmask-3.c +++ b/tests/signals/sigprocmask-3.c @@ -4,6 +4,9 @@ #include "signals_list.h" #include "../test_helpers.h" +// The resulting set shall be the union of the current set and the signal +// set pointed to by set, if the value of the argument how is SIG_BLOCK. + int handler_called = 0; void sig_handler(int signo) @@ -34,7 +37,7 @@ int sigprocmask_block(int signum) ERROR_IF(sigaction, status, == -1); status = sigaction(defaultsig, &act, 0); - ERROR_IF(sigaction, status, == -1); + ERROR_IF(sigaction, status, == -1); status = sigprocmask(SIG_SETMASK, &set1, NULL); ERROR_IF(sigprocmask, status, == -1); @@ -49,7 +52,7 @@ int sigprocmask_block(int signum) handler_called = 0; status = raise(defaultsig); - ERROR_IF(raise, defualtsig, == -1); + ERROR_IF(raise, defaultsig, == -1); ERROR_IF(raise, handler_called, == 1); @@ -62,7 +65,7 @@ int sigprocmask_block(int signum) status = sigismember(&pending_set, signum); ERROR_IF(sigismemeber, status, != 0); - printf("Test PASSED: signal was added to the process's signal mask\n"); + // 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); diff --git a/tests/signals/sigprocmask-4.c b/tests/signals/sigprocmask-4.c index be816a8ff8..e539ec4ba9 100644 --- a/tests/signals/sigprocmask-4.c +++ b/tests/signals/sigprocmask-4.c @@ -3,6 +3,8 @@ #include #include +// The previous mask shall be stored in the location pointed to by oset, if the argument oset is not a null pointer. + #define NUMSIGNALS 26 diff --git a/tests/signals/sigprocmask-5.c b/tests/signals/sigprocmask-5.c index b58105434c..a7cc8560ac 100644 --- a/tests/signals/sigprocmask-5.c +++ b/tests/signals/sigprocmask-5.c @@ -2,6 +2,9 @@ #include #include +// The value of the argument how is not significant and the process's signal mask shall be unchanged, and +// thus the call can be used to enquire about currently blocked signals, if the argument set is a null +// pointer. #define NUMSIGNALS 25 diff --git a/tests/signals/sigprocmask-8.c b/tests/signals/sigprocmask-8.c index 28a329a64a..ba7284eb1d 100644 --- a/tests/signals/sigprocmask-8.c +++ b/tests/signals/sigprocmask-8.c @@ -3,6 +3,9 @@ #include #include "../test_helpers.h" +// After the call to sigprocmask(), if there are any pending unblocked signals, at least one of those +// signals shall be delivered before the call to sigprocmask() returns. + int handler_called = 0; int sigprocmask_return_val = 1; /* some value that's not a 1 or 0 */ diff --git a/tests/signals/sigprocmask-9.c b/tests/signals/sigprocmask-9.c index 7f5cb44956..2c46e98163 100644 --- a/tests/signals/sigprocmask-9.c +++ b/tests/signals/sigprocmask-9.c @@ -2,6 +2,11 @@ #include #include +// Attempt to add SIGKILL and SIGSTOP to the process's signal mask and +// verify that: +// - They do not get added. +// - sigprocmask() does not return -1. + int main() { sigset_t set1, set2; diff --git a/tests/signals/sigprocmask-block.c b/tests/signals/sigprocmask-block.c index 3d7174ccb3..b1736bfa91 100644 --- a/tests/signals/sigprocmask-block.c +++ b/tests/signals/sigprocmask-block.c @@ -29,51 +29,35 @@ int sigprocmask_block(int signum) 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); - } + int status; + status = sigaction(signum, &act, 0); + ERROR_IF(sigaction, status, == -1); + status = sigaction(defaultsig, &act, 0); + ERROR_IF(sigaction, status, == -1); - if (sigaction(defaultsig, &act, 0) == -1) { - perror("Unexpected error while attempting to setup test " - "pre-conditions"); - exit(EXIT_FAILURE); - } + status = sigprocmask(SIG_SETMASK, &blocked_set1, NULL); + ERROR_IF(sigprocmask, status, == -1); - if (sigprocmask(SIG_SETMASK, &blocked_set1, NULL) == -1) { - perror("Unexpected error while attempting to use sigprocmask.\n"); - exit(EXIT_FAILURE); - } + status = sigprocmask(SIG_BLOCK, &blocked_set2, NULL); + ERROR_IF(sigprocmask, status, == -1); - 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); - } + ERROR_IF(raise, signum, == -1); + ERROR_IF(raise, defaultsig, == -1); 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); - } + status = sigpending(&pending_set); + ERROR_IF(sigpending, status, == -1); - if ((sigismember(&pending_set, signum) != 1) | (sigismember(&pending_set, defaultsig) != 1)) { - perror("FAIL: sigismember did not return 1\n"); - exit(EXIT_FAILURE); - } + status = sigismember(&pending_set, signum); + ERROR_IF(sigismember, status, != 1); + status = sigismember(&pending_set, defaultsig); + ERROR_IF(sigismember, status, != 1); - 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); diff --git a/tests/signals/sigprocmask-blocksingle.c b/tests/signals/sigprocmask-blocksingle.c index 8e8d54f7af..2f8ffbe837 100644 --- a/tests/signals/sigprocmask-blocksingle.c +++ b/tests/signals/sigprocmask-blocksingle.c @@ -14,11 +14,6 @@ void sig_handler(int signo) 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); @@ -38,11 +33,10 @@ int sigprocmask_block(int signum) status = raise(signum); ERROR_IF(raise, status, == -1); - ERROR_IF(raise, handler_called, == 1); - // if (handler_called) { - // printf("FAIL: Signal was not blocked\n"); - // exit(EXIT_FAILURE); - // } + if (handler_called) { + printf("FAIL: Signal was not blocked\n"); + exit(EXIT_FAILURE); + } status = sigpending(&pending_set); ERROR_IF(sigpending, status, == -1); @@ -58,10 +52,11 @@ int sigprocmask_block(int signum) int main(){ for (int i=1; i #include #include +#include "../test_helpers.h" int main() { From a7e9135bc9838ac5a60fa53a2d2801d165e1f6fa Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Thu, 23 Jan 2025 19:34:51 -0800 Subject: [PATCH 04/20] clean up more tests --- tests/signals/kill-child.c | 2 +- tests/signals/kill-group.c | 16 ++++++++++------ tests/signals/kill-permission.c | 6 ++++-- tests/signals/killpg-child.c | 2 +- tests/signals/sigrelse-3.c | 13 +------------ 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tests/signals/kill-child.c b/tests/signals/kill-child.c index 809564789c..deefb271ed 100644 --- a/tests/signals/kill-child.c +++ b/tests/signals/kill-child.c @@ -85,7 +85,7 @@ int main() for (int i = 1; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) { int sig = signals_list[i].signal; - if (sig == SIGKILL || i == SIGSTOP) + if (sig == SIGKILL || sig == SIGSTOP) { continue; } diff --git a/tests/signals/kill-group.c b/tests/signals/kill-group.c index cde477390e..17ae2fb895 100644 --- a/tests/signals/kill-group.c +++ b/tests/signals/kill-group.c @@ -5,10 +5,12 @@ #include "signals_list.h" #include "../test_helpers.h" +// this test is to make sure that when a negative pid is supplied to kill, all the processes in that group will be killed + +int handler_called = 0; void sig_handler(int signo) { - printf("Caught signal %d being tested!\n", signo); - printf("Test PASSED\n"); + handler_called = 1; return; } @@ -24,18 +26,20 @@ int kill_group(int signum) ERROR_IF(sigemptyset, status, == -1); status = sigaction(signum, &act, 0); - ERROR_IF(sigaction, staus, == -1); + ERROR_IF(sigaction, status, == -1); - staus = getpgrp(); + status = getpgrp(); ERROR_IF(getpgrp, status, == -1); status = kill(-pgrp, signum); - ERROR_IF(kill, staus, != 0); + ERROR_IF(kill, status, != 0); + + ERROR_IF(kill, handler_called, !=1); + handler_called = 0; return EXIT_SUCCESS; } -// If pid is negative, but not -1, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the absolute value of pid, and for which the process has permission to send a signal. int main() { for (unsigned int i = 0; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) diff --git a/tests/signals/kill-permission.c b/tests/signals/kill-permission.c index bad0a625f8..eab0aef545 100644 --- a/tests/signals/kill-permission.c +++ b/tests/signals/kill-permission.c @@ -6,13 +6,15 @@ #include #include "../test_helpers.h" +// makes sure that a process is not killed if the user doesn't have permission to kill the process + int main(void) { int status; - // This is added incase user is root. If user is normal user, then it has no effect on the tests + // This is added in case user is root. If user is normal user, then it has no effect on the tests setuid(1000); status = kill(1, 0); ERROR_IF(kill, status, != -1); - ERROR_IF(kill, errno, !=EPERM); + ERROR_IF(kill, errno, != EPERM); return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/killpg-child.c b/tests/signals/killpg-child.c index 1cec7b8607..4cad327632 100644 --- a/tests/signals/killpg-child.c +++ b/tests/signals/killpg-child.c @@ -68,7 +68,7 @@ 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 || sig == SIGCHLD) + if (sig == SIGKILL || sig == SIGSTOP || sig == SIGCHLD || sig == SIGINT || sig == SIGQUIT) { continue; } diff --git a/tests/signals/sigrelse-3.c b/tests/signals/sigrelse-3.c index 863d592ffe..980bca35bd 100644 --- a/tests/signals/sigrelse-3.c +++ b/tests/signals/sigrelse-3.c @@ -1,9 +1,8 @@ -#define _XOPEN_SOURCE 700 - #include #include #include #include +#include "../test_helpers.h" int main() { @@ -12,14 +11,4 @@ int main() ERROR_IF(sigrelse, status, != -1); ERROR_IF(sigrelse, errno, != EINVAL); return EXIT_SUCCESS; - // 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 From a2e19224a4004827615872455e707c37482d429b Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Thu, 23 Jan 2025 19:50:09 -0800 Subject: [PATCH 05/20] add signals-tests to makefile and run_tests --- tests/Makefile | 28 ++++++++++++++++++++++++++++ tests/run_tests.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/tests/Makefile b/tests/Makefile index 38412a55ce..a91e9d4770 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -183,6 +183,34 @@ NAMES=\ pwd \ sa_restart \ sigchld \ + signals/kill-self \ + signals/kill0-self \ + signals/kill-child \ + signals/kill-group \ + signals/kill-invalid \ + signals/kill-permission \ + signals/killpg-child \ + signals/killpg-esrch \ + signals/killpg-invalid \ + signals/killpg-self \ + signals/killpg0-self \ + signals/pthread_kill-invalid \ + signals/pthread_kill-self \ + signals/pthread_kill0-self \ + signals/raise-compliance \ + signals/sigaddset-add \ + signals/sigdelset-delete \ + signals/sigismember-invalid \ + signals/sigismember-valid \ + signals/sigpause-revert \ + signals/sigrpocmask-6 \ + signals/sigrpocmask-7 \ + signals/sigrpocmask-8 \ + signals/sigrpocmask-9 \ + signals/sigrpocmask-11 \ + signals/sigrpocmask-blocksingle \ + signals/sigrelse-2 \ + signals/sigrelse-3 \ stdio/ctermid \ stdio/tempnam \ stdio/tmpnam \ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index af32abdc75..a58315e509 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -168,6 +168,34 @@ STATUS_NAMES=(\ sigchld \ stdio/ctermid \ sigqueue \ + signals/kill-self \ + signals/kill0-self \ + signals/kill-child \ + signals/kill-group \ + signals/kill-invalid \ + signals/kill-permission \ + signals/killpg-child \ + signals/killpg-esrch \ + signals/killpg-invalid \ + signals/killpg-self \ + signals/killpg0-self \ + signals/pthread_kill-invalid \ + signals/pthread_kill-self \ + signals/pthread_kill0-self \ + signals/raise-compliance \ + signals/sigaddset-add \ + signals/sigdelset-delete \ + signals/sigismember-invalid \ + signals/sigismember-valid \ + signals/sigpause-revert \ + signals/sigrpocmask-6 \ + signals/sigrpocmask-7 \ + signals/sigrpocmask-8 \ + signals/sigrpocmask-9 \ + signals/sigrpocmask-11 \ + signals/sigrpocmask-blocksingle \ + signals/sigrelse-2 \ + signals/sigrelse-3 \ stdio/tempnam \ stdio/tmpnam \ stdlib/bsearch \ From 2bc44dba9d3b50a7364a17317d14b71a90bbc9c1 Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Fri, 24 Jan 2025 17:57:44 -0800 Subject: [PATCH 06/20] modify makefile and run_tests fix compiler warnings --- tests/Makefile | 20 ++++++-------------- tests/run_tests.sh | 20 ++++++-------------- tests/signals/kill-child.c | 2 +- tests/signals/kill-group.c | 2 ++ tests/signals/killpg-self.c | 1 + 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index a91e9d4770..0ec8b764e9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -185,30 +185,22 @@ NAMES=\ sigchld \ signals/kill-self \ signals/kill0-self \ - signals/kill-child \ - signals/kill-group \ signals/kill-invalid \ signals/kill-permission \ - signals/killpg-child \ signals/killpg-esrch \ signals/killpg-invalid \ - signals/killpg-self \ signals/killpg0-self \ signals/pthread_kill-invalid \ - signals/pthread_kill-self \ signals/pthread_kill0-self \ signals/raise-compliance \ - signals/sigaddset-add \ - signals/sigdelset-delete \ signals/sigismember-invalid \ signals/sigismember-valid \ - signals/sigpause-revert \ - signals/sigrpocmask-6 \ - signals/sigrpocmask-7 \ - signals/sigrpocmask-8 \ - signals/sigrpocmask-9 \ - signals/sigrpocmask-11 \ - signals/sigrpocmask-blocksingle \ + signals/sigprocmask-6 \ + signals/sigprocmask-7 \ + signals/sigprocmask-8 \ + signals/sigprocmask-9 \ + signals/sigprocmask-11 \ + signals/sigprocmask-blocksingle \ signals/sigrelse-2 \ signals/sigrelse-3 \ stdio/ctermid \ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index a58315e509..8df7b62e81 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -170,30 +170,22 @@ STATUS_NAMES=(\ sigqueue \ signals/kill-self \ signals/kill0-self \ - signals/kill-child \ - signals/kill-group \ signals/kill-invalid \ signals/kill-permission \ - signals/killpg-child \ signals/killpg-esrch \ signals/killpg-invalid \ - signals/killpg-self \ signals/killpg0-self \ signals/pthread_kill-invalid \ - signals/pthread_kill-self \ signals/pthread_kill0-self \ signals/raise-compliance \ - signals/sigaddset-add \ - signals/sigdelset-delete \ signals/sigismember-invalid \ signals/sigismember-valid \ - signals/sigpause-revert \ - signals/sigrpocmask-6 \ - signals/sigrpocmask-7 \ - signals/sigrpocmask-8 \ - signals/sigrpocmask-9 \ - signals/sigrpocmask-11 \ - signals/sigrpocmask-blocksingle \ + signals/sigprocmask-6 \ + signals/sigprocmask-7 \ + signals/sigprocmask-8 \ + signals/sigprocmask-9 \ + signals/sigprocmask-11 \ + signals/sigprocmask-blocksingle \ signals/sigrelse-2 \ signals/sigrelse-3 \ stdio/tempnam \ diff --git a/tests/signals/kill-child.c b/tests/signals/kill-child.c index deefb271ed..c8f66ddaf5 100644 --- a/tests/signals/kill-child.c +++ b/tests/signals/kill-child.c @@ -82,7 +82,7 @@ void kill_child(int signum) int main() { - for (int i = 1; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) + for (long unsigned int i = 1; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) { int sig = signals_list[i].signal; if (sig == SIGKILL || sig == SIGSTOP) diff --git a/tests/signals/kill-group.c b/tests/signals/kill-group.c index 17ae2fb895..dd8243c71b 100644 --- a/tests/signals/kill-group.c +++ b/tests/signals/kill-group.c @@ -10,6 +10,7 @@ int handler_called = 0; void sig_handler(int signo) { + (void) signo; handler_called = 1; return; } @@ -29,6 +30,7 @@ int kill_group(int signum) ERROR_IF(sigaction, status, == -1); status = getpgrp(); + pgrp = status; ERROR_IF(getpgrp, status, == -1); status = kill(-pgrp, signum); diff --git a/tests/signals/killpg-self.c b/tests/signals/killpg-self.c index 41186f0573..130506aacc 100644 --- a/tests/signals/killpg-self.c +++ b/tests/signals/killpg-self.c @@ -12,6 +12,7 @@ void sig_handler(int signo) { // printf("Caught signal %d being tested!\n", signo); // printf("Test PASSED\n"); + (void) signo; return; } From 2d3374f176db07f2c5aa32bfe7fa34edefabf15f Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Fri, 24 Jan 2025 20:25:40 -0800 Subject: [PATCH 07/20] add tests to makefile and run_tests --- tests/Makefile | 6 ++++++ tests/run_tests.sh | 6 ++++++ tests/signals/signal-handle_return.c | 26 +++++++++++----------- tests/signals/signal-handler.c | 24 ++++++++++----------- tests/signals/signal-handler2.c | 29 +++++++++++-------------- tests/signals/signal-ignore.c | 32 +++++++++++++--------------- tests/signals/signal-invalid.c | 16 ++++++-------- tests/signals/signal-uncatchable.c | 16 ++++++-------- 8 files changed, 77 insertions(+), 78 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 0ec8b764e9..3c5beb00ce 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -195,6 +195,12 @@ NAMES=\ signals/raise-compliance \ signals/sigismember-invalid \ signals/sigismember-valid \ + signals/signal-handle_return \ + signals/signal-handler \ + signals/signal-handler2 \ + signals/signal-ignore \ + signals/signal-invalid \ + signals/signal-uncatchable \ signals/sigprocmask-6 \ signals/sigprocmask-7 \ signals/sigprocmask-8 \ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 8df7b62e81..1af7468a9c 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -180,6 +180,12 @@ STATUS_NAMES=(\ signals/raise-compliance \ signals/sigismember-invalid \ signals/sigismember-valid \ + signals/signal-handle_return \ + signals/signal-handler \ + signals/signal-handler2 \ + signals/signal-ignore \ + signals/signal-invalid \ + signals/signal-uncatchable \ signals/sigprocmask-6 \ signals/sigprocmask-7 \ signals/sigprocmask-8 \ diff --git a/tests/signals/signal-handle_return.c b/tests/signals/signal-handle_return.c index d52ac6c750..933f992078 100644 --- a/tests/signals/signal-handle_return.c +++ b/tests/signals/signal-handle_return.c @@ -1,6 +1,7 @@ #include #include #include +#include "../test_helpers.h" void SIGUSR1_handler(int signo) { @@ -16,20 +17,19 @@ void SIGUSR2_handler(int signo) int main() { - if (signal(SIGUSR1, SIGUSR1_handler) == SIG_ERR) { - perror("Unexpected error while using signal()"); - exit(EXIT_FAILURE); - } + void (*status) (int); + status = signal(SIGUSR1, SIGUSR1_handler); + ERROR_IF(signal, status, == SIG_ERR); - if (signal(SIGUSR2, SIGUSR2_handler) == SIG_ERR) { - perror("Unexpected error while using signal()"); - exit(EXIT_FAILURE); - } + status = signal(SIGUSR2, SIGUSR2_handler); + ERROR_IF(signal, status, == SIG_ERR); + + status = signal(SIGUSR1,SIG_IGN); + // printf("status is %d\n", status); + // printf("SIGUSR1_handler is %d\n", SIGUSR1_handler); + ERROR_IF(signal, status, != SIGUSR1_handler); + + //this seems to be a weird comparison error - 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 index 0cd2b78145..f6eba8e168 100644 --- a/tests/signals/signal-handler.c +++ b/tests/signals/signal-handler.c @@ -1,6 +1,7 @@ #include #include #include +#include "../test_helpers.h" int handler_called = 0; @@ -13,23 +14,20 @@ void sig_handler(int signo) int main() { - if (signal(SIGCHLD, sig_handler) == SIG_ERR) { - perror("Unexpected error while using signal()"); - exit(1); - } + void (*status) (int); + status = signal(SIGCHLD, sig_handler); + ERROR_IF(signal, status, == SIG_ERR); - if (signal(SIGCHLD,SIG_DFL) != sig_handler) { - perror("Unexpected error while using signal()"); - exit(1); - } + status = signal(SIGCHLD,SIG_DFL); + ERROR_IF(signal, status, != sig_handler); + //same comparison error from handle_return + raise(SIGCHLD); if (handler_called == 1) { - printf("Test FAILED: handler was called even though default was expected\n"); - exit(1); - } - printf("test passed \n"); + return EXIT_FAILURE; + } handler_called = 0; - return 0; + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tests/signals/signal-handler2.c b/tests/signals/signal-handler2.c index 29b856c952..7cc8394bdd 100644 --- a/tests/signals/signal-handler2.c +++ b/tests/signals/signal-handler2.c @@ -8,35 +8,30 @@ int handler_called = 0; void sig_handler(int signo) { - printf("%d called. Inside handler\n", signo); + (void) 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); - } - + void (*status) (int); + status = signal(signum, sig_handler); + ERROR_IF(signal, status, == SIG_ERR); + 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); + ERROR_IF(raise, handler_called, != 1); return EXIT_SUCCESS; } int main(){ - for (int i=1; i #include #include +#include "../test_helpers.h" + +// test to make sure sending an invalid signal sets errno void sig_handler(int signo) { @@ -13,15 +16,10 @@ 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); - } + void (*status) (int); + status = signal(-1, sig_handler); + ERROR_IF(signal, status, != SIG_ERR); + ERROR_IF(signal, errno, <= 0); - 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 index 5ef87c381e..1bf85db82c 100644 --- a/tests/signals/signal-uncatchable.c +++ b/tests/signals/signal-uncatchable.c @@ -2,6 +2,9 @@ #include #include #include +#include "../test_helpers.h" + +//make sure you can't catch uncatchable signals void sig_handler(int signo) { @@ -12,16 +15,11 @@ void sig_handler(int signo) int main() { errno = -1; + void (*status) (int); + status = signal(SIGKILL, sig_handler); + ERROR_IF(signal, status, != SIG_ERR); - 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); - } + ERROR_IF(signal, errno, <= 0); - 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 From 70b997b249456307dd09c8a90b349de1f0aad5f0 Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Fri, 21 Feb 2025 19:35:10 -0800 Subject: [PATCH 08/20] switched to master makefile, run_tests and test_helpers --- tests/Makefile | 26 -------------------------- tests/run_tests.sh | 26 -------------------------- tests/test_helpers.h | 1 - 3 files changed, 53 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 3c5beb00ce..38412a55ce 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -183,32 +183,6 @@ NAMES=\ pwd \ sa_restart \ sigchld \ - signals/kill-self \ - signals/kill0-self \ - signals/kill-invalid \ - signals/kill-permission \ - signals/killpg-esrch \ - signals/killpg-invalid \ - signals/killpg0-self \ - signals/pthread_kill-invalid \ - signals/pthread_kill0-self \ - signals/raise-compliance \ - signals/sigismember-invalid \ - signals/sigismember-valid \ - signals/signal-handle_return \ - signals/signal-handler \ - signals/signal-handler2 \ - signals/signal-ignore \ - signals/signal-invalid \ - signals/signal-uncatchable \ - signals/sigprocmask-6 \ - signals/sigprocmask-7 \ - signals/sigprocmask-8 \ - signals/sigprocmask-9 \ - signals/sigprocmask-11 \ - signals/sigprocmask-blocksingle \ - signals/sigrelse-2 \ - signals/sigrelse-3 \ stdio/ctermid \ stdio/tempnam \ stdio/tmpnam \ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 1af7468a9c..af32abdc75 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -168,32 +168,6 @@ STATUS_NAMES=(\ sigchld \ stdio/ctermid \ sigqueue \ - signals/kill-self \ - signals/kill0-self \ - signals/kill-invalid \ - signals/kill-permission \ - signals/killpg-esrch \ - signals/killpg-invalid \ - signals/killpg0-self \ - signals/pthread_kill-invalid \ - signals/pthread_kill0-self \ - signals/raise-compliance \ - signals/sigismember-invalid \ - signals/sigismember-valid \ - signals/signal-handle_return \ - signals/signal-handler \ - signals/signal-handler2 \ - signals/signal-ignore \ - signals/signal-invalid \ - signals/signal-uncatchable \ - signals/sigprocmask-6 \ - signals/sigprocmask-7 \ - signals/sigprocmask-8 \ - signals/sigprocmask-9 \ - signals/sigprocmask-11 \ - signals/sigprocmask-blocksingle \ - signals/sigrelse-2 \ - signals/sigrelse-3 \ stdio/tempnam \ stdio/tmpnam \ stdlib/bsearch \ diff --git a/tests/test_helpers.h b/tests/test_helpers.h index 571617fe68..35c1eb465e 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include From a017dd19094da7e3d33205a7d10c5bfcf82bbd46 Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Tue, 25 Feb 2025 00:55:36 -0800 Subject: [PATCH 09/20] most recent updates to sigset-5 and 10 --- tests/signals/sigset-10.c | 25 +++++++++++++++---------- tests/signals/sigset-5.c | 25 +++++++++++++++---------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/tests/signals/sigset-10.c b/tests/signals/sigset-10.c index e6b8d478c8..9762881ce3 100644 --- a/tests/signals/sigset-10.c +++ b/tests/signals/sigset-10.c @@ -4,18 +4,23 @@ #include #include #include +#include "../test_helpers.h" 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"); + void (*status) (int); + status = sigset(SIGKILL,SIG_IGN); + ERROR_IF(sigset, status, == SIG_ERR); + ERROR_IF(sigset, errno, != EINVAL); + // 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-5.c b/tests/signals/sigset-5.c index 80ec9d6514..b0ad6763da 100644 --- a/tests/signals/sigset-5.c +++ b/tests/signals/sigset-5.c @@ -36,20 +36,25 @@ int sigset_test5(int signum) sigemptyset(&mask); sigprocmask(SIG_SETMASK, &mask, NULL); + void (*status) (int); - if (sigset(signum, sig_handler) == SIG_ERR) { - perror("Unexpected error while using sigset()"); - exit(EXIT_FAILURE); - } + status = sigset(signum, sig_handler); + ERROR_IF(sigset, status, == SIG_ERR); + // if (sigset(signum, sig_handler) == SIG_ERR) { + // perror("Unexpected error while using sigset()"); + // exit(EXIT_FAILURE); + // } raise(signum); sigprocmask(SIG_SETMASK, NULL, &mask); - - if (is_empty(&mask) != 1) { - printf("Test FAILED: signal mask should be empty\n"); - exit(EXIT_FAILURE); - } - printf("sig %d was successfully removed from the mask when handler returned\n", signum); + int status1; + status1 = is_empty(&mask); + ERROR_IF(is_empty, status1, != 1); + // if (is_empty(&mask) != 1) { + // printf("Test FAILED: signal mask should be empty\n"); + // exit(EXIT_FAILURE); + // } + // printf("sig %d was successfully removed from the mask when handler returned\n", signum); return EXIT_SUCCESS; } From 493839baf5a75e4c3484a32f28e7fdcf924a1199 Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Tue, 25 Feb 2025 01:39:00 -0800 Subject: [PATCH 10/20] fixed killpg-child on linux --- tests/signals/killpg-child.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/signals/killpg-child.c b/tests/signals/killpg-child.c index 4cad327632..1291f13959 100644 --- a/tests/signals/killpg-child.c +++ b/tests/signals/killpg-child.c @@ -10,7 +10,7 @@ void sig_handler (int signo) { (void) signo; - exit(1); + exit(EXIT_SUCCESS); } int killpg_test2(int signum) @@ -31,7 +31,7 @@ int killpg_test2(int signum) sigpause(SIGABRT); - return 0; + return EXIT_FAILURE; } else { /* parent here */ int i; @@ -49,10 +49,10 @@ int killpg_test2(int signum) status = wait(&i); ERROR_IF(wait, status, == -1); - if (WEXITSTATUS(i)) { + if (WEXITSTATUS(i) == EXIT_SUCCESS) { printf("Child exited normally\n"); printf("Test PASSED\n"); - return 0; + return EXIT_SUCCESS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); @@ -73,11 +73,10 @@ int main(){ continue; } x = killpg_test2(sig); - } - if (x == EXIT_FAILURE){ - return EXIT_FAILURE; - } else { - return EXIT_SUCCESS; - } + if (x == EXIT_FAILURE){ + return EXIT_FAILURE; + } + } + return EXIT_SUCCESS; } From 38e3320fb0e5d96b62123ac337a7daad41ecb172 Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Tue, 25 Feb 2025 02:05:16 -0800 Subject: [PATCH 11/20] fixed sigprocmask-10 on linux --- tests/signals/sigprocmask-10.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/signals/sigprocmask-10.c b/tests/signals/sigprocmask-10.c index b85034e061..f14c593bdf 100644 --- a/tests/signals/sigprocmask-10.c +++ b/tests/signals/sigprocmask-10.c @@ -38,22 +38,27 @@ int main() { int r=get_rand(); sigset_t actl, oactl; + int status; sigemptyset(&actl); sigemptyset(&oactl); - sigaddset(&actl, SIGABRT); + status = sigaddset(&actl, SIGABRT); + ERROR_IF(sigaddset, status, != 0); - sigprocmask(SIG_SETMASK, &actl, NULL); + status = sigprocmask(SIG_SETMASK, &actl, NULL); + ERROR_IF(sigprocmask, status, != 0); - sigaddset(&actl, SIGALRM); - int status; + status = sigaddset(&actl, SIGALRM); + ERROR_IF(sigaddset, status, != 0); + status = sigprocmask(r, &actl, NULL); ERROR_IF(sigprocmask, status, != -1); - sigprocmask(SIG_SETMASK, NULL, &oactl); + status = sigprocmask(SIG_SETMASK, NULL, &oactl); + ERROR_IF(sigprocmask, status, != 0); status = sigismember(&oactl, SIGABRT); - ERROR_IF(sigismember, status, != -1); + ERROR_IF(sigismember, status, != 1); if (is_changed(oactl)) { exit(EXIT_FAILURE); From 77cf9fc2a1840c23d0500fb932f3509f62e52cd0 Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Thu, 20 Mar 2025 23:53:40 -0700 Subject: [PATCH 12/20] added tests to makefile and run_tests --- tests/Makefile | 26 ++++++++++++++++++++++++++ tests/run_tests.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tests/Makefile b/tests/Makefile index 38412a55ce..3c5beb00ce 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -183,6 +183,32 @@ NAMES=\ pwd \ sa_restart \ sigchld \ + signals/kill-self \ + signals/kill0-self \ + signals/kill-invalid \ + signals/kill-permission \ + signals/killpg-esrch \ + signals/killpg-invalid \ + signals/killpg0-self \ + signals/pthread_kill-invalid \ + signals/pthread_kill0-self \ + signals/raise-compliance \ + signals/sigismember-invalid \ + signals/sigismember-valid \ + signals/signal-handle_return \ + signals/signal-handler \ + signals/signal-handler2 \ + signals/signal-ignore \ + signals/signal-invalid \ + signals/signal-uncatchable \ + signals/sigprocmask-6 \ + signals/sigprocmask-7 \ + signals/sigprocmask-8 \ + signals/sigprocmask-9 \ + signals/sigprocmask-11 \ + signals/sigprocmask-blocksingle \ + signals/sigrelse-2 \ + signals/sigrelse-3 \ stdio/ctermid \ stdio/tempnam \ stdio/tmpnam \ diff --git a/tests/run_tests.sh b/tests/run_tests.sh index af32abdc75..1af7468a9c 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -168,6 +168,32 @@ STATUS_NAMES=(\ sigchld \ stdio/ctermid \ sigqueue \ + signals/kill-self \ + signals/kill0-self \ + signals/kill-invalid \ + signals/kill-permission \ + signals/killpg-esrch \ + signals/killpg-invalid \ + signals/killpg0-self \ + signals/pthread_kill-invalid \ + signals/pthread_kill0-self \ + signals/raise-compliance \ + signals/sigismember-invalid \ + signals/sigismember-valid \ + signals/signal-handle_return \ + signals/signal-handler \ + signals/signal-handler2 \ + signals/signal-ignore \ + signals/signal-invalid \ + signals/signal-uncatchable \ + signals/sigprocmask-6 \ + signals/sigprocmask-7 \ + signals/sigprocmask-8 \ + signals/sigprocmask-9 \ + signals/sigprocmask-11 \ + signals/sigprocmask-blocksingle \ + signals/sigrelse-2 \ + signals/sigrelse-3 \ stdio/tempnam \ stdio/tmpnam \ stdlib/bsearch \ From 240a41861c2591621db7cc5277a54a43707d30e9 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Apr 2025 01:01:33 +0200 Subject: [PATCH 13/20] Rebase, misc fixes for test suite. --- tests/Makefile | 10 +++++++--- tests/signals/kill-child.c | 7 ++++--- tests/signals/kill-group.c | 6 +++++- tests/signals/kill-self.c | 5 +++-- tests/signals/pthread_kill-self.c | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 3c5beb00ce..9e8033af71 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -29,14 +29,12 @@ EXPECT_NAMES=\ locale \ math \ netdb/getaddrinfo \ - ptrace \ regex \ select \ setjmp \ sigaction \ sigaltstack \ signal \ - sigsetjmp \ stdio/all \ stdio/buffer \ stdio/dprintf \ @@ -122,7 +120,6 @@ EXPECT_NAMES=\ unistd/fsync \ unistd/ftruncate \ unistd/getopt \ - unistd/getopt_long \ unistd/pipe \ unistd/rmdir \ waitpid \ @@ -130,6 +127,7 @@ EXPECT_NAMES=\ kill-waitpid \ # unistd/sleep \ unistd/swab \ + unistd/getopt_long \ unistd/write \ wchar/fgetwc \ wchar/fwide \ @@ -190,7 +188,13 @@ NAMES=\ signals/killpg-esrch \ signals/killpg-invalid \ signals/killpg0-self \ + signals/kill-group \ + signals/kill-child \ + signals/killpg-child \ + signals/killpg-self \ signals/pthread_kill-invalid \ + signals/pthread_kill-child \ + signals/pthread_kill-self \ signals/pthread_kill0-self \ signals/raise-compliance \ signals/sigismember-invalid \ diff --git a/tests/signals/kill-child.c b/tests/signals/kill-child.c index c8f66ddaf5..10e332374e 100644 --- a/tests/signals/kill-child.c +++ b/tests/signals/kill-child.c @@ -1,3 +1,4 @@ +#include #include #include #include "signals_list.h" @@ -8,7 +9,7 @@ * Skip SIGKILL and SIGSTOP as these are not catchable. */ -int sig_handled = 0; +volatile sig_atomic_t sig_handled = 0; void sig_handler(int signo) { @@ -18,7 +19,6 @@ void sig_handler(int signo) void child_proc(int signum) { - sigset_t sig_set; int status; @@ -39,7 +39,7 @@ void child_proc(int signum) status = sleep(10); ERROR_IF(sleep, status, == 0); - ERROR_IF(kill, sig_handled, == 0 ); + assert(sig_handled != 0); exit(EXIT_SUCCESS); } @@ -89,6 +89,7 @@ int main() { continue; } + printf("Testing for signal %s (%d)\n", strsignal(sig), sig); kill_child(sig); } return EXIT_SUCCESS; diff --git a/tests/signals/kill-group.c b/tests/signals/kill-group.c index dd8243c71b..80059ef874 100644 --- a/tests/signals/kill-group.c +++ b/tests/signals/kill-group.c @@ -44,6 +44,10 @@ int kill_group(int signum) int main() { + // Ensure we don't kill what was already in the process group. + int status = setpgid(0, 0); + ERROR_IF(setpgid, status, == -1); + for (unsigned int i = 0; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) { int sig = signals_list[i].signal; @@ -54,4 +58,4 @@ int main() kill_group(sig); } return EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/tests/signals/kill-self.c b/tests/signals/kill-self.c index b72d50170d..f05ec12a9f 100644 --- a/tests/signals/kill-self.c +++ b/tests/signals/kill-self.c @@ -1,3 +1,4 @@ +#include #include #include "signals_list.h" #include "../test_helpers.h" @@ -7,7 +8,7 @@ * Ensure all signals can be caught (other than SIGKILL and SIGSTOP). */ -int handler_called = 0; +volatile sig_atomic_t handler_called = 0; void sig_handler(int sig) { @@ -34,7 +35,7 @@ int kill_self(int sig) status = kill(getpid(), sig); ERROR_IF(kill, status, != 0); - ERROR_IF(kill, handler_called, == 0); + assert(handler_called == 1); return EXIT_SUCCESS; } diff --git a/tests/signals/pthread_kill-self.c b/tests/signals/pthread_kill-self.c index 8ea87658c1..3e70746141 100644 --- a/tests/signals/pthread_kill-self.c +++ b/tests/signals/pthread_kill-self.c @@ -14,7 +14,7 @@ # define SIGTOTEST SIGABRT int sem1; /* Manual semaphore */ -int handler_called = 0; +volatile sig_atomic_t handler_called = 0; int count = 1; struct signal { From df228ddd79a425e4f569e4c26b4618d7a61fb632 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Apr 2025 01:58:41 +0200 Subject: [PATCH 14/20] Add remaining tests. --- tests/Makefile | 21 +++++++++++++++++++++ tests/signals/killpg-self.c | 4 ++++ tests/signals/killpg0-self.c | 6 +++++- tests/signals/sigpause-invalid.c | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 9e8033af71..32f2725fe2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -199,20 +199,41 @@ NAMES=\ signals/raise-compliance \ signals/sigismember-invalid \ signals/sigismember-valid \ + signals/sigaddset-add \ + signals/sigdelset-delete \ + signals/signal-h \ + signals/signal-h-2 \ signals/signal-handle_return \ signals/signal-handler \ signals/signal-handler2 \ signals/signal-ignore \ signals/signal-invalid \ signals/signal-uncatchable \ + signals/sigprocmask-3 \ + signals/sigprocmask-4 \ + signals/sigprocmask-5 \ signals/sigprocmask-6 \ signals/sigprocmask-7 \ signals/sigprocmask-8 \ signals/sigprocmask-9 \ + signals/sigprocmask-10 \ signals/sigprocmask-11 \ + signals/sigprocmask-12 \ + signals/sigpause-invalid \ + signals/sigpause-revert \ + signals/sigpause-suspend \ signals/sigprocmask-blocksingle \ + signals/sigprocmask-block \ + signals/sigrelse-1 \ signals/sigrelse-2 \ signals/sigrelse-3 \ + signals/sigset-1 \ + signals/sigset-10 \ + signals/sigset-2 \ + signals/sigset-3 \ + signals/sigset-4 \ + signals/sigset-5 \ + signals/sigset-9 \ stdio/ctermid \ stdio/tempnam \ stdio/tmpnam \ diff --git a/tests/signals/killpg-self.c b/tests/signals/killpg-self.c index 130506aacc..afd4865112 100644 --- a/tests/signals/killpg-self.c +++ b/tests/signals/killpg-self.c @@ -39,6 +39,10 @@ int killpg_test1(int signum) } int main(){ + // UB if pg == 1, so set it here first + int status = setpgid(0, 0); + ERROR_IF(setpgid, status, == -1); + for (unsigned int i = 0; i < sizeof(signals_list)/sizeof(signals_list[0]); i++) { int sig = signals_list[i].signal; diff --git a/tests/signals/killpg0-self.c b/tests/signals/killpg0-self.c index 444e02939f..e319660eca 100644 --- a/tests/signals/killpg0-self.c +++ b/tests/signals/killpg0-self.c @@ -8,6 +8,10 @@ int main() { + // UB if pg == 1, so set it here first + int err = setpgid(0, 0); + ERROR_IF(setpgid, err, == -1); + int pgrp; pgrp = getpgrp(); @@ -18,4 +22,4 @@ int main() ERROR_IF(killpg, status, != 0); return EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/tests/signals/sigpause-invalid.c b/tests/signals/sigpause-invalid.c index 714ef40f07..60b18c5f11 100644 --- a/tests/signals/sigpause-invalid.c +++ b/tests/signals/sigpause-invalid.c @@ -1,5 +1,6 @@ #define _XOPEN_SOURCE 700 +#include "../test_helpers.h" #include #include #include From cb23a518c05fb4737aab8a2e4bcb5e0a146665c8 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Apr 2025 11:40:12 +0200 Subject: [PATCH 15/20] Improve sigprocmask-9 test. --- tests/signals/sigprocmask-9.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/signals/sigprocmask-9.c b/tests/signals/sigprocmask-9.c index 2c46e98163..168eed88c4 100644 --- a/tests/signals/sigprocmask-9.c +++ b/tests/signals/sigprocmask-9.c @@ -1,3 +1,5 @@ +#include "../test_helpers.h" +#include #include #include #include @@ -8,27 +10,19 @@ // - sigprocmask() does not return -1. int main() { - sigset_t set1, set2; - int sigprocmask_return_val = 1; + int ret; sigemptyset(&set1); sigemptyset(&set2); sigaddset(&set1, SIGKILL); sigaddset(&set1, SIGSTOP); - sigprocmask_return_val = sigprocmask(SIG_SETMASK, &set1, NULL); - sigprocmask(SIG_SETMASK, NULL, &set2); + ret = sigprocmask(SIG_SETMASK, &set1, NULL); + ERROR_IF(sigprocmask, ret, == -1); + ret = sigprocmask(SIG_SETMASK, NULL, &set2); + ERROR_IF(sigprocmask, ret, == -1); - if (sigismember(&set2, SIGKILL)) { - exit(EXIT_FAILURE); - } - if (sigismember(&set2, SIGSTOP)) { - exit(EXIT_FAILURE); - } - if (sigprocmask_return_val == -1) { - exit(EXIT_FAILURE); - } - - return EXIT_SUCCESS; -} \ No newline at end of file + assert(!sigismember(&set2, SIGKILL)); + assert(!sigismember(&set2, SIGSTOP)); +} From d1081b278cfd8a1492936b71b81981a4626c08b4 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Apr 2025 12:04:35 +0200 Subject: [PATCH 16/20] Fix sigset-5 and sigset-10. --- tests/signals/sigset-10.c | 7 ++++--- tests/signals/sigset-5.c | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/signals/sigset-10.c b/tests/signals/sigset-10.c index 9762881ce3..04986b739e 100644 --- a/tests/signals/sigset-10.c +++ b/tests/signals/sigset-10.c @@ -1,5 +1,6 @@ #define _XOPEN_SOURCE 600 +#include #include #include #include @@ -10,8 +11,8 @@ int main() { void (*status) (int); status = sigset(SIGKILL,SIG_IGN); - ERROR_IF(sigset, status, == SIG_ERR); - ERROR_IF(sigset, errno, != EINVAL); + assert(status == SIG_ERR); + assert(errno == EINVAL); // 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"); @@ -23,4 +24,4 @@ int main() // } // printf("test passed: error was set successfully\n"); return EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/tests/signals/sigset-5.c b/tests/signals/sigset-5.c index b0ad6763da..dc34f2848b 100644 --- a/tests/signals/sigset-5.c +++ b/tests/signals/sigset-5.c @@ -1,6 +1,8 @@ #define _XOPEN_SOURCE 600 +#include #include +#include #include #include #include "signals_list.h" @@ -8,21 +10,21 @@ #define NUMSIGNALS 26 -int is_empty(sigset_t *set) { +bool is_empty(sigset_t *set) { int i; - int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, + int siglist[25] = {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 Date: Thu, 17 Apr 2025 12:49:31 +0200 Subject: [PATCH 17/20] Misc improvements. --- tests/signals/sigprocmask-3.c | 5 ++++- tests/signals/sigprocmask-blocksingle.c | 1 + tests/signals/sigrelse-1.c | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/signals/sigprocmask-3.c b/tests/signals/sigprocmask-3.c index 9bb7e1359e..aee43032ca 100644 --- a/tests/signals/sigprocmask-3.c +++ b/tests/signals/sigprocmask-3.c @@ -7,7 +7,7 @@ // The resulting set shall be the union of the current set and the signal // set pointed to by set, if the value of the argument how is SIG_BLOCK. -int handler_called = 0; +volatile sig_atomic_t handler_called = 0; void sig_handler(int signo) { @@ -45,12 +45,14 @@ int sigprocmask_block(int signum) status = sigprocmask(SIG_UNBLOCK, &set2, NULL); ERROR_IF(sigprocmask, status, == -1); + printf("Raising %s\n", strsignal(signum)); status = raise(signum); ERROR_IF(raise, status, == -1); ERROR_IF(raise, handler_called, != 1); handler_called = 0; + printf("Raising %s\n", strsignal(defaultsig)); status = raise(defaultsig); ERROR_IF(raise, defaultsig, == -1); @@ -78,6 +80,7 @@ int main(){ if (i == SIGKILL || i == SIGSTOP){ continue; } + printf("Testing signal %s (%d)\n", strsignal(i), i); sigprocmask_block(i); } return 0; diff --git a/tests/signals/sigprocmask-blocksingle.c b/tests/signals/sigprocmask-blocksingle.c index 2f8ffbe837..5dd3d5a3c0 100644 --- a/tests/signals/sigprocmask-blocksingle.c +++ b/tests/signals/sigprocmask-blocksingle.c @@ -56,6 +56,7 @@ int main(){ if (sig == SIGKILL || sig == SIGSTOP){ continue; } + printf("Testing signal %s (%d)\n", strsignal(i), i); sigprocmask_block(sig); } return EXIT_SUCCESS; diff --git a/tests/signals/sigrelse-1.c b/tests/signals/sigrelse-1.c index 5dca66c529..9d1cc402fe 100644 --- a/tests/signals/sigrelse-1.c +++ b/tests/signals/sigrelse-1.c @@ -1,5 +1,6 @@ // The sigrelse() function shall remove sig from the signal mask of the calling process. +#include #include #include #include @@ -10,7 +11,7 @@ #define _XOPEN_SOURCE 700 -int handler_called = 0; +volatile sig_atomic_t handler_called = 0; void sig_handler(int signo) { @@ -35,7 +36,7 @@ int sigrelse_test(int signum) status = raise(signum); ERROR_IF(raise, status, == -1); - ERROR_IF(raise, handler_called, == 1); + assert(handler_called == 0); // if (handler_called) { // printf("UNRESOLVED. possible problem in sigrelse\n"); // exit(EXIT_FAILURE); @@ -62,6 +63,7 @@ int main(){ if (i == SIGKILL || i == SIGSTOP){ continue; } + printf("For signal %s\n", strsignal(i)); sigrelse_test(i); } return 0; From 95d2b5912055227940c1c4081029e01a9092c890 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Apr 2025 13:44:23 +0200 Subject: [PATCH 18/20] Improvements to sigpause and sigrelse tests. --- tests/signals/sigpause-invalid.c | 6 +++--- tests/signals/sigpause-revert.c | 3 ++- tests/signals/sigpause-suspend.c | 2 +- tests/signals/sigrelse-1.c | 18 +++++++++--------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/signals/sigpause-invalid.c b/tests/signals/sigpause-invalid.c index 60b18c5f11..79e80add58 100644 --- a/tests/signals/sigpause-invalid.c +++ b/tests/signals/sigpause-invalid.c @@ -1,6 +1,7 @@ #define _XOPEN_SOURCE 700 #include "../test_helpers.h" +#include #include #include #include @@ -14,7 +15,7 @@ #define INMAIN 0 #define INTHREAD 1 -int handler_called = 0; +volatile sig_atomic_t handler_called = 0; int returned = 0; int return_value = 2; int result = 2; @@ -30,8 +31,7 @@ int sigpause_invalid(){ int return_value = 0; return_value = sigpause(-1); - ERROR_IF(sigpause, return_value, != -1); - ERROR_IF(sigpause, errno, != EINVAL); + if (return_value == -1) { if (errno == EINVAL) { printf ("Test PASSED: sigpause returned -1 and set errno to EINVAL\n"); diff --git a/tests/signals/sigpause-revert.c b/tests/signals/sigpause-revert.c index 8d01e0bc12..48fa9eb33d 100644 --- a/tests/signals/sigpause-revert.c +++ b/tests/signals/sigpause-revert.c @@ -15,7 +15,7 @@ #define INMAIN 0 #define INTHREAD 1 -int handler_called = 0; +volatile sig_atomic_t handler_called = 0; int returned = 0; int return_value = 2; int result = 2; @@ -102,6 +102,7 @@ int main(){ if (i == SIGKILL || i == SIGSTOP){ continue; } + printf("Testing signal %s\n", strsignal(i)); sigpause_revert(i); } return EXIT_SUCCESS; diff --git a/tests/signals/sigpause-suspend.c b/tests/signals/sigpause-suspend.c index 5575031a6a..1512537089 100644 --- a/tests/signals/sigpause-suspend.c +++ b/tests/signals/sigpause-suspend.c @@ -13,7 +13,7 @@ #define INMAIN 0 #define INTHREAD 1 -int handler_called = 0; +volatile sig_atomic_t handler_called = 0; int returned = 0; int return_value = 2; int result = 2; diff --git a/tests/signals/sigrelse-1.c b/tests/signals/sigrelse-1.c index 9d1cc402fe..49b53f82a6 100644 --- a/tests/signals/sigrelse-1.c +++ b/tests/signals/sigrelse-1.c @@ -21,6 +21,9 @@ void sig_handler(int signo) int sigrelse_test(int signum) { + // needs to be reset + handler_called = 0; + struct sigaction act; act.sa_handler = sig_handler; @@ -28,26 +31,23 @@ int sigrelse_test(int signum) sigemptyset(&act.sa_mask); int status; - status = sigaction(signum, &act, 0); + status = sigaction(signum, &act, NULL); ERROR_IF(sigaction, status, == -1); - sighold(signum); + status = sighold(signum); + ERROR_IF(sighold, status, == -1); + + assert(handler_called == 0); status = raise(signum); ERROR_IF(raise, status, == -1); assert(handler_called == 0); - // if (handler_called) { - // printf("UNRESOLVED. possible problem in sigrelse\n"); - // exit(EXIT_FAILURE); - // } status = sigrelse(signum); ERROR_IF(sigrelse, status, == -1); - sleep(1); - - ERROR_IF(sigrelse, handler_called, != 1); + assert(handler_called == 1); // if (handler_called) { // printf("PASS: %d successfully removed from signal mask\n", signum); // handler_called = 0; From 3947cda43a6b0e63dc2892625fc537a00b7dec81 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Apr 2025 15:02:36 +0200 Subject: [PATCH 19/20] Fix sigpause-revert test. --- tests/signals/sigpause-revert.c | 88 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/tests/signals/sigpause-revert.c b/tests/signals/sigpause-revert.c index 48fa9eb33d..fcb26ab89d 100644 --- a/tests/signals/sigpause-revert.c +++ b/tests/signals/sigpause-revert.c @@ -1,10 +1,12 @@ #define _XOPEN_SOURCE 700 +#include #include #include #include #include #include +#include #include #include "signals_list.h" #include "../test_helpers.h" @@ -12,18 +14,10 @@ // This program verifies that sigpause() restores sig to the signal mask before // returning. -#define INMAIN 0 -#define INTHREAD 1 - -volatile sig_atomic_t handler_called = 0; -int returned = 0; -int return_value = 2; -int result = 2; -int sem = INMAIN; +volatile sig_atomic_t handler_called = false; void handler() { - // printf("signal was called\n"); - handler_called = 1; + handler_called = true; return; } @@ -31,67 +25,73 @@ 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"); + puts("before sigpause"); + + assert(!handler_called); if ((sigpause(signum) != -1) || (errno != EINTR)) { - printf ("Test UNRESOLVED: sigpause didn't return -1 and/or didn't set errno correctly."); - return_value = 2; + puts("Test UNRESOLVED: sigpause didn't return -1 and/or didn't set errno correctly."); + exit(2); return NULL; } + assert(handler_called); + handler_called = false; - sleep(1); + int status = raise(signum); + ERROR_IF(raise, status, == -1); + + assert(!handler_called); - raise (signum); sigpending(&pendingset); if (sigismember(&pendingset, signum) == 1) { - printf("Test PASSED: signal mask was restored when sigpause returned."); - return_value = 0; + puts("Test PASSED: signal mask was restored when sigpause returned."); } - sem = INMAIN; return NULL; } -int sigpause_revert(int signum){ +int sigpause_revert(int signum) { pthread_t new_th; + int status; + struct sigaction act; - if(pthread_create(&new_th, NULL, c_thread_func, (void *)&signum) != 0) + // Ensure thread inherits mask with signum blocked. + status = sighold(signum); + ERROR_IF(sighold, status, == -1); + + act.sa_flags = 0; + act.sa_handler = handler; + status = sigemptyset(&act.sa_mask); + ERROR_IF(sigemptyset, status, == -1); + status = sigaction(signum, &act, NULL); + ERROR_IF(sigaction, status, == -1); + + if((status = pthread_create(&new_th, NULL, c_thread_func, (void *)&signum)) != 0) { - perror("Error creating thread\n"); + errno = status; + perror("Error creating thread"); exit(EXIT_FAILURE); } sleep(1); - - if(pthread_kill(new_th, signum) != 0) + + if((status = pthread_kill(new_th, signum)) != 0) { - printf("Test UNRESOLVED: Couldn't send signal to thread\n"); + errno = status; + perror("Test UNRESOLVED: Couldn't send signal to thread"); exit(EXIT_FAILURE); } + if ((status = pthread_join(new_th, NULL)) != 0) { + errno = status; + perror("failed to join thread"); + return 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"); + puts("Test PASSED"); return EXIT_SUCCESS; } From 8863a8967fefe7800abb31f1ad21213d4501218b Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Apr 2025 15:33:46 +0200 Subject: [PATCH 20/20] Fix sigpause-suspend. --- tests/signals/signals_list.h | 2 +- tests/signals/sigpause-suspend.c | 76 ++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/tests/signals/signals_list.h b/tests/signals/signals_list.h index 52d5847c2d..75bf3cd847 100644 --- a/tests/signals/signals_list.h +++ b/tests/signals/signals_list.h @@ -76,4 +76,4 @@ const struct signalAction signals_list[] = { #endif }; -#endif /* _SIGNALS_LIST */ \ No newline at end of file +#endif /* _SIGNALS_LIST */ diff --git a/tests/signals/sigpause-suspend.c b/tests/signals/sigpause-suspend.c index 1512537089..8a7583fde1 100644 --- a/tests/signals/sigpause-suspend.c +++ b/tests/signals/sigpause-suspend.c @@ -1,4 +1,7 @@ +#include #include +#include +#include #include #include #include @@ -14,26 +17,19 @@ #define INTHREAD 1 volatile sig_atomic_t handler_called = 0; -int returned = 0; -int return_value = 2; -int result = 2; -int sem = INMAIN; +volatile atomic_bool completed = false; void handler() { handler_called = 1; return; } -void *b_thread_func(void *sig) -{ - int signum = *(int *)sig; - printf("Pausing signal %s\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; +void *b_thread_func(void *code_raw) { + int *code = code_raw; + printf("Pausing signal %s\n", strsignal(*code)); + sigpause(*code); + assert(handler_called != 0); + *code = 0; + atomic_store(&completed, true); return NULL; } @@ -41,40 +37,54 @@ void *b_thread_func(void *sig) int sigpause_suspend(int signum) { - pthread_t new_th; - int j; - + atomic_store(&completed, false); int status; - status = pthread_create(&new_th, NULL, b_thread_func, (void *)&signum); - ERROR_IF(pthread_create, status, != 0); - for (j=0; j<10; j++) { - sleep(1); - } + struct sigaction act; + act.sa_flags = 0; + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + status = sigaction(signum, &act, 0); + ERROR_IF(sigaction, status, == -1); - status = pthread_kill(new_th, signum); - ERROR_IF(pthread_kill, status, != 0); + pthread_t new_th; - sleep(1); + int code = signum; + if ((status = pthread_create(&new_th, NULL, b_thread_func, (void *)&code)) != 0) { + errno = status; + perror("failed to create thread"); + return EXIT_FAILURE; + } + sleep(1); + assert(!atomic_load(&completed)); - ERROR_IF(sigpuase, returned, != 1); - if (returned != 1){ - printf("returned != 1 \n"); - exit(EXIT_FAILURE); - } + if ((status = pthread_kill(new_th, signum)) != 0) { + errno = status; + perror("failed to kill thread"); + return EXIT_FAILURE; + } - returned = 0; + if ((status = pthread_join(new_th, NULL)) != 0) { + errno = status; + perror("failed to join thread"); + return EXIT_FAILURE; + } + + assert(code == 0); + assert(atomic_load(&completed)); return EXIT_SUCCESS; } int main(){ - for (int i=1; i