diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile index c6d9ddff13..ddf039e790 100644 --- a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile @@ -9,4 +9,5 @@ SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance i SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_setspecific ; 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 signal ; SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigsuspend ; diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/1-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/1-1.c new file mode 100644 index 0000000000..b240d65f5c --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/1-1.c @@ -0,0 +1,53 @@ +/* + * 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. + + This program tests the assertion that the default handling of the + signal shall occur if the value of the func parameter is SIG_DFL. + + How this program tests this assertion by setting up a handler + "myhandler" for SIGCHLD. Then another call to signal() is made about + SIGCHLD, this time with SIG_DFL as the value of the func parameter. + The default action for SIGCHLD is to be ignored, so unless myhandler + gets called when SIGCHLD is raised, the test passess, otherwise + returns failure. + +*/ + +#include +#include +#include +#include "posixtest.h" + +int handler_called = 0; + +void myhandler(int signo) +{ + printf("SIGCHLD called. Inside handler\n"); + handler_called = 1; +} + +int main() +{ + if (signal(SIGCHLD, myhandler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + return PTS_UNRESOLVED; + } + + if (signal(SIGCHLD,SIG_DFL) != myhandler) { + perror("Unexpected error while using signal()"); + return PTS_UNRESOLVED; + } + + raise(SIGCHLD); + + if (handler_called == 1) { + printf("Test FAILED: handler was called even though default was expected\n"); + return PTS_FAIL; + } + printf("signal(): Test passed\n"); + return PTS_PASS; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/2-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/2-1.c new file mode 100644 index 0000000000..6b40e472f8 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/2-1.c @@ -0,0 +1,52 @@ +/* + * 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. + + This program tests the assertion that the signal shall be ignored + if the value of the func parameter is SIG_IGN. + + How this program tests this assertion is by setting up a handler + "myhandler" for SIGCHLD. Then another call to signal() is made about + SIGCHLD, this time with SIG_IGN as the value of the func parameter. + SIGCHLD should be ignored now, so unless myhandler gets called when + SIGCHLD is raised, the test passes, otherwise returns failure. + +*/ + +#include +#include +#include +#include "posixtest.h" + +int handler_called = 0; + +void myhandler(int signo) +{ + printf("SIGCHLD called. Inside handler\n"); + handler_called = 1; +} + +int main() +{ + if (signal(SIGCHLD, myhandler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + return PTS_UNRESOLVED; + } + + if (signal(SIGCHLD,SIG_IGN) != myhandler) { + perror("Unexpected error while using signal()"); + return PTS_UNRESOLVED; + } + + raise(SIGCHLD); + + if (handler_called == 1) { + printf("Test FAILED: handler was called even though default was expected\n"); + return PTS_FAIL; + } + printf("signal(): Test passed\n"); + return PTS_PASS; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/3-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/3-1.c new file mode 100644 index 0000000000..4fd4f34d0c --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/3-1.c @@ -0,0 +1,45 @@ +/* + * 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. + + This program tests the assertion that the signal shall be ignored + if the value of the func parameter is SIG_IGN. + + How this program tests this assertion is by setting up a handler + "myhandler" for SIGCHLD, and then raising that signal. If the + handler_called variable is anything but 1, then fail, otherwise pass. + +*/ + +#include +#include +#include +#include "posixtest.h" + +int handler_called = 0; + +void myhandler(int signo) +{ + printf("SIGCHLD called. Inside handler\n"); + handler_called = 1; +} + +int main() +{ + if (signal(SIGCHLD, myhandler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + return PTS_UNRESOLVED; + } + + raise(SIGCHLD); + + if (handler_called != 1) { + printf("Test FAILED: handler was called even though default was expected\n"); + return PTS_FAIL; + } + printf("signal(): Test passed\n"); + return PTS_PASS; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/5-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/5-1.c new file mode 100644 index 0000000000..6ee173daf8 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/5-1.c @@ -0,0 +1,53 @@ +/* + * 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. + + This program tests the assertion that the signal function shall return + the function name of the last signal handler that was associated with + sig. + + How this program tests this assertion is by setting up handlers + SIGUSR1_handler and SIGUSR2_handler for signals SIGUSR1 and SIGUSR2 + respectively. A third call to signal() is made regarding signal SIGUSR1. + If this call returns anything but SIGUSR1_handler, fail the test, + otherwise the test passes. + +*/ + +#include +#include +#include +#include "posixtest.h" + +void SIGUSR1_handler(int signo) +{ + printf("do nothing useful\n"); +} + +void SIGUSR2_handler(int signo) +{ + printf("do nothing useful\n"); +} + +int main() +{ + if (signal(SIGUSR1, SIGUSR1_handler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + return PTS_UNRESOLVED; + } + + if (signal(SIGUSR2, SIGUSR2_handler) == SIG_ERR) { + perror("Unexpected error while using signal()"); + return PTS_UNRESOLVED; + } + + if (signal(SIGUSR1,SIG_IGN) != SIGUSR1_handler) { + printf("signal did not return the last handler that was associated with SIGUSR1\n"); + return PTS_FAIL; + } + printf("signal(): Test passed\n"); + return PTS_PASS; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/6-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/6-1.c new file mode 100644 index 0000000000..ea9e0a9fd4 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/6-1.c @@ -0,0 +1,40 @@ +/* + * 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. + + This program tests the assertion that signal() shall return SIG_ERR + and set errno to a positive value if an invalid signal number was + passed to it. + +*/ + +#include +#include +#include +#include +#include "posixtest.h" + +void myhandler(int signo) +{ + printf("handler does nothing useful.\n"); +} + +int main() +{ + errno = -1; + + if (signal(-1, myhandler) != SIG_ERR) { + printf("Test FAILED: signal() didn't return SIG_ERR even though invalid signal number was passed to it\n"); + return PTS_FAIL; + } + + 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"); + return PTS_FAIL; + } + printf("signal(): Test passed\n"); + return PTS_PASS; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/7-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/7-1.c new file mode 100644 index 0000000000..d4a59427d7 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/7-1.c @@ -0,0 +1,40 @@ +/* + * 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. + + This program tests the assertion that signal() shall return SIG_ERR + and set errno to a positive value if an invalid signal number was + passed to it. + +*/ + +#include +#include +#include +#include +#include "posixtest.h" + +void myhandler(int signo) +{ + printf("handler does nothing useful.\n"); +} + +int main() +{ + errno = -1; + + if (signal(SIGKILL, myhandler) != SIG_ERR) { + printf("Test FAILED: signal() didn't return SIG_ERR even though a non-catchable signal was passed to it\n"); + return PTS_FAIL; + } + + 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"); + return PTS_FAIL; + } + printf("signal(): Test passed\n"); + return PTS_PASS; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/Jamfile new file mode 100644 index 0000000000..3711fd4bdc --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/signal/Jamfile @@ -0,0 +1,10 @@ +SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces signal ; + +SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ; + +SimpleTest signal_1-1 : 1-1.c ; +SimpleTest signal_2-1 : 2-1.c ; +SimpleTest signal_3-1 : 3-1.c ; +SimpleTest signal_5-1 : 5-1.c ; +SimpleTest signal_6-1 : 6-1.c ; +SimpleTest signal_7-1 : 7-1.c ;