From 627c5b3f824bdd309442f72ba9baa5bdbc6b4a6a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 9 Nov 2007 23:27:30 +0000 Subject: [PATCH] Patch by Vasilis Kaoutsis: Added posixtestsuite tests for sigrelse(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22866 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../conformance/interfaces/Jamfile | 1 + .../conformance/interfaces/sigrelse/1-1.c | 73 ++++++++++++ .../conformance/interfaces/sigrelse/2-1.c | 27 +++++ .../interfaces/sigrelse/3-core-buildonly.c | 105 ++++++++++++++++++ .../conformance/interfaces/sigrelse/Jamfile | 7 ++ 5 files changed, 213 insertions(+) create mode 100644 src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/1-1.c create mode 100644 src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/2-1.c create mode 100644 src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/3-core-buildonly.c create mode 100644 src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/Jamfile diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile index beb199ba79..45fd0b08c7 100644 --- a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile @@ -10,5 +10,6 @@ SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance i SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sighold ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigignore ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigprocmask ; +SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigrelse ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces signal ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigsuspend ; diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/1-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/1-1.c new file mode 100644 index 0000000000..0804c669a2 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/1-1.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2003, Intel Corporation. All rights reserved. + * Created by: salwan.searty REMOVE-THIS AT intel DOT com + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + + Steps: + 1. Set up a handler for signal SIGABRT, such that it is called if +signal is ever raised. + 2. Call sighold on that SIGABRT. + 3. Raise a SIGABRT and verify that the signal handler was not called. +Otherwise, the test exits with unresolved results. + 4. Call sigrelse on SIGABRT. + 5. Verify that the handler gets called this time. + +*/ + +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include "posixtest.h" + +int handler_called = 0; + +void handler(int signo) +{ + handler_called = 1; +} + +int main() +{ + struct sigaction act; + + act.sa_handler = 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"); + return PTS_UNRESOLVED; + } + + sighold(SIGABRT); + + if (raise(SIGABRT) == -1) { + perror("Unexpected error while attempting to setup test " + "pre-conditions"); + return PTS_UNRESOLVED; + } + + if (handler_called) { + printf("UNRESOLVED. possible problem in sigrelse\n"); + return PTS_UNRESOLVED; + } + + if (sigrelse(SIGABRT) == -1) { + printf("UNRESOLVED. possible problem in sigrelse\n"); + return PTS_UNRESOLVED; + } + + sleep(1); + + if (handler_called) { + printf("sigrelse(): Test PASSED: SIGABRT successfully removed from signal mask\n"); + return PTS_PASS; + } + printf("FAIL\n"); + return PTS_FAIL; +} + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/2-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/2-1.c new file mode 100644 index 0000000000..633699b280 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/2-1.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2003, Intel Corporation. All rights reserved. + * Created by: salwan.searty REMOVE-THIS AT intel DOT com + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + + Simply, if sigrelse returns a 0 here, test passes. + +*/ + +#define _XOPEN_SOURCE 600 + +#include +#include +#include "posixtest.h" + +int main() +{ + + if ((int)sigrelse(SIGABRT) != 0) { + perror("sigrelse failed -- returned -- test aborted"); + return PTS_UNRESOLVED; + } + printf("sigrelse(): Test PASSED\n"); + return PTS_PASS; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/3-core-buildonly.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/3-core-buildonly.c new file mode 100644 index 0000000000..faf7a7288b --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/3-core-buildonly.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2003, Intel Corporation. All rights reserved. + * Created by: salwan.searty REMOVE-THIS AT intel DOT com + * This file is licensed under the GPL license. For the full content + * of this license, see the COPYING file at the top level of this + * source tree. + + Testing passing an invalid signals to sigrelse(). + After sighold is called on an invalid signal, sigrelse() should +return -1 and set errno to EINVAL + + The invalid signal passed to sigrelse() depends on the argument +passed to this program. + There are currently 4 invalid signals. + */ + +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include +#include +#include "posixtest.h" + +jmp_buf sig11_recover; +void sig11_handler(int sig); + +int main(int argc, char *argv[]) +{ + int signo, TEST_RETURN; + struct sigaction sa, osa; + + if (argc < 2) { + printf("Usage: %s [1|2|3|4]\n", argv[0]); + return PTS_UNRESOLVED; + } + + /* + 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]); + return PTS_UNRESOLVED; + } + + /* special sig11 case */ + sa.sa_handler = &sig11_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + + sigaction(SIGSEGV, NULL, &osa); + sigaction(SIGSEGV, &sa, NULL); + + if (setjmp(sig11_recover)) { + errno = EINVAL; + TEST_RETURN=-2; + } else { + TEST_RETURN=sigrelse(signo); + } + sigaction(SIGSEGV, &osa, NULL); + + if (TEST_RETURN == -1) { + if (EINVAL == errno) { + printf ("errno set to EINVAL\n"); + printf("sigrelse(): Test PASSED\n"); + return PTS_PASS; + } else { + printf ("errno not set to EINVAL\n"); + return PTS_FAIL; + } + } + if (TEST_RETURN == -2) { + printf ("test received SIGSEGV\n"); + return PTS_UNRESOLVED; + } + + printf("sigrelse did not return -1\n"); + return PTS_FAIL; + +} + +/****************************************************************** + * sig11_handler() - our segfault recover hack + ******************************************************************/ +void +sig11_handler(int sig) +{ + longjmp(sig11_recover, 1); +} + + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/Jamfile new file mode 100644 index 0000000000..31ae8c5341 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/sigrelse/Jamfile @@ -0,0 +1,7 @@ +SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigrelse ; + +SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ; + +SimpleTest sigrelse_1-1 : 1-1.c ; +SimpleTest sigrelse_2-1 : 2-1.c ; +SimpleTest sigrelse_3-core-buildonly : 3-core-buildonly.c ;