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() {