diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2001-11-08 21:04:05 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2001-11-08 21:04:05 +0000 |
commit | 461903013c0abb6e88f39b5aa1ca0f68ac03fcb3 (patch) | |
tree | 83869b4f681b042a44e38f67d7575d1c6020d0f7 | |
parent | 80a429d20a345f222a4151d8f162fd8542244bb5 (diff) | |
download | newlib-461903013c0abb6e88f39b5aa1ca0f68ac03fcb3.zip newlib-461903013c0abb6e88f39b5aa1ca0f68ac03fcb3.tar.gz newlib-461903013c0abb6e88f39b5aa1ca0f68ac03fcb3.tar.bz2 |
* checksignal.c: New testcase.
-rw-r--r-- | winsup/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | winsup/testsuite/winsup.api/checksignal.c | 79 |
2 files changed, 83 insertions, 0 deletions
diff --git a/winsup/testsuite/ChangeLog b/winsup/testsuite/ChangeLog index bba5781..849af81 100644 --- a/winsup/testsuite/ChangeLog +++ b/winsup/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-11-08 Corinna Vinschen <corinna@vinschen.de> + + * checksignal.c: New testcase. + 2001-11-04 Christopher Faylor <cgf@redhat.com> * Makefile.in: Oops. Revert previous change. Add Makefile/Makefile.in diff --git a/winsup/testsuite/winsup.api/checksignal.c b/winsup/testsuite/winsup.api/checksignal.c new file mode 100644 index 0000000..a8b5d39 --- /dev/null +++ b/winsup/testsuite/winsup.api/checksignal.c @@ -0,0 +1,79 @@ +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> + +#include "test.h" +#include "usctest.h" + +char *TCID = "checksignal"; /* Test program identifier. */ +int TST_TOTAL = 3; /* Total number of test cases. */ +extern int Tst_count; /* Test Case counter for tst_* routines */ + +void +sig_handler (int signo) +{ + errno = EINVAL; +} + +int +main () +{ + int n, ret; + int fds[2]; + char buf[10]; + struct sigaction act; + + Tst_count = 0; + + if (pipe (fds) < 0) + tst_brk (TBROK, NULL, NULL, "Create pipe"); + + /* Reset SA_RESTART flag. */ + while ((ret = sigaction (SIGALRM, NULL, &act)) == EINTR) + ; + if (ret) + tst_brk (TBROK, NULL, NULL, "Get signal action structure"); + act.sa_flags &= ~SA_RESTART; + while ((ret = sigaction (SIGALRM, &act, NULL)) == EINTR) + ; + if (ret) + tst_brk (TBROK, NULL, NULL, "Reset SA_RESTART"); + + /* Set signal handler using signal(2) call... */ + if (signal (SIGALRM, sig_handler) < 0) + tst_brk (TBROK, NULL, NULL, "Call signal() to install signal handler"); + /* ...and check if signal(2) sets SA_RESTART again. */ + while ((ret = sigaction (SIGALRM, NULL, &act)) == EINTR) + ; + if (ret) + tst_brk (TBROK, NULL, NULL, "Get signal action structure"); + tst_resm (act.sa_flags & SA_RESTART ? TPASS : TFAIL, + "signal() sets SA_RESTART"); + + /* Reset SA_RESTART flag again. */ + act.sa_handler = sig_handler; + act.sa_flags &= ~SA_RESTART; + while ((ret = sigaction (SIGALRM, &act, NULL)) == EINTR) + ; + if (ret) + tst_brk (TBROK, NULL, NULL, "Reset SA_RESTART"); + + /* Start timer to force a SIGALRM. */ + alarm (1); + + /* Call read(2) to check if the EINTR errno is correctly preserved, + even if the signal handler routine changes errno. */ + n = read(fds[0], buf, 10); + tst_resm (n < 0 && errno == EINTR ? TPASS : TFAIL, + "Set EINTR on interrupted read() call"); + + /* Check if another errno is correctly returned (here EBADF). */ + close (fds[0]); + n = read(fds[0], buf, 10); + tst_resm (n < 0 && errno == EBADF ? TPASS : TFAIL, + "Set EBADF on closed file descriptor"); + + tst_exit (); +} |