// S : tags libc c todo // S : expect --result valid // S : cc -o test.bc -D_PDCLIB_BUILD -DTEST $file // S : verify -o nofail:malloc test.bc #include #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 ) { /* 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; }