From 5ccf82b7feaec1c1fdb5e4cbf1db8a537d8c4419 Mon Sep 17 00:00:00 2001 From: solar Date: Fri, 10 Dec 2010 07:41:09 +0000 Subject: [PATCH] Added testdriver for signals, make links now including signal.h --- Makefile | 2 +- platform/example/functions/signal/raise.c | 45 +++++++++++++++++++++- platform/example/functions/signal/signal.c | 6 ++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 266558f..89bd2a0 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ find: links: @echo "Linking platform/$(PLATFORM)..." @cd internals && ln -s ../platform/$(PLATFORM)/internals/_PDCLIB_config.h - @cd includes && ln -s ../platform/$(PLATFORM)/includes/float.h + @cd includes && ln -s ../platform/$(PLATFORM)/includes/float.h && ln -s ../platform/$(PLATFORM)/includes/signal.h @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done @cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done diff --git a/platform/example/functions/signal/raise.c b/platform/example/functions/signal/raise.c index b16249c..307c876 100644 --- a/platform/example/functions/signal/raise.c +++ b/platform/example/functions/signal/raise.c @@ -10,6 +10,7 @@ #ifndef REGTEST +#include #include extern void (*_PDCLIB_sigabrt)( int ); @@ -22,25 +23,32 @@ extern void (*_PDCLIB_sigterm)( int ); int raise( int sig ) { void (*sighandler)( int ); + char const * message; switch ( sig ) { case SIGABRT: sighandler = _PDCLIB_sigabrt; + message = "Abnormal termination (SIGABRT)"; break; case SIGFPE: sighandler = _PDCLIB_sigfpe; + message = "Arithmetic exception (SIGFPE)"; break; case SIGILL: sighandler = _PDCLIB_sigill; + message = "Illegal instruction (SIGILL)"; break; case SIGINT: sighandler = _PDCLIB_sigint; + message = "Interactive attention signal (SIGINT)"; break; case SIGSEGV: sighandler = _PDCLIB_sigsegv; + message = "Invalid memory access (SIGSEGV)"; break; case SIGTERM: sighandler = _PDCLIB_sigterm; + message = "Termination request (SIGTERM)"; break; default: /* TODO: Implement. */ @@ -48,6 +56,7 @@ int raise( int sig ) } if ( sighandler == SIG_DFL ) { + fputs( message, stderr ); _Exit( EXIT_FAILURE ); } else if ( sighandler != SIG_IGN ) @@ -63,9 +72,43 @@ int raise( int sig ) #ifdef TEST #include <_PDCLIB_test.h> +#include + +static volatile sig_atomic_t flag = 0; + +static int expected_signal = 0; + +static void test_handler( int sig ) +{ + TESTCASE( sig == expected_signal ); + flag = 1; +} + int main( void ) { - TESTCASE( NO_TESTDRIVER ); + /* Could be other than SIG_DFL if you changed the implementation. */ + TESTCASE( signal( SIGABRT, SIG_IGN ) == SIG_DFL ); + /* Should be ignored. */ + TESTCASE( raise( SIGABRT ) == 0 ); + /* Installing test handler, old handler should be returned */ + TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN ); + /* Raising and checking SIGABRT */ + expected_signal = SIGABRT; + TESTCASE( raise( SIGABRT ) == 0 ); + TESTCASE( flag == 1 ); + /* Re-installing test handler, should have been reset to default */ + /* Could be other than SIG_DFL if you changed the implementation. */ + TESTCASE( signal( SIGABRT, test_handler ) == SIG_DFL ); + /* Raising and checking SIGABRT */ + flag = 0; + TESTCASE( raise( SIGABRT ) == 0 ); + TESTCASE( flag == 1 ); + /* Installing test handler for different signal... */ + TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL ); + /* Raising and checking SIGTERM */ + expected_signal = SIGTERM; + TESTCASE( raise( SIGTERM ) == 0 ); + TESTCASE( flag == 1 ); return TEST_RESULTS; } #endif diff --git a/platform/example/functions/signal/signal.c b/platform/example/functions/signal/signal.c index 33722ac..e07877d 100644 --- a/platform/example/functions/signal/signal.c +++ b/platform/example/functions/signal/signal.c @@ -22,6 +22,10 @@ void (*_PDCLIB_sigterm)( int ) = SIG_DFL; void (*signal( int sig, void (*func)( int ) ) )( int ) { void (*oldhandler)( int ); + if ( sig <= 0 || func == SIG_ERR ) + { + return SIG_ERR; + } switch ( sig ) { case SIGABRT: @@ -65,7 +69,7 @@ void (*signal( int sig, void (*func)( int ) ) )( int ) int main( void ) { - TESTCASE( NO_TESTDRIVER ); + /* Testing covered by raise.c */ return TEST_RESULTS; } #endif -- 2.40.0