Patch by Vasilis Kaoutsis: Added tests for signal().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22828 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
7154471870
commit
3ee9275573
@ -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 ;
|
||||
|
@ -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 <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
@ -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 <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
@ -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 <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
@ -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 <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
@ -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 <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#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;
|
||||
}
|
@ -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 <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#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;
|
||||
}
|
@ -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 ;
|
Loading…
Reference in New Issue
Block a user