/[ascend]/trunk/ascend/utilities/test/test_ascSignal.c
ViewVC logotype

Diff of /trunk/ascend/utilities/test/test_ascSignal.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2272 by jpye, Wed Apr 29 03:38:10 2009 UTC revision 2273 by jpye, Mon Aug 9 04:42:16 2010 UTC
# Line 117  static void test_ascSignal(void) Line 117  static void test_ascSignal(void)
117    /* no point in testing if the functionality is disabled */    /* no point in testing if the functionality is disabled */
118    CU_FAIL("Signal handler manager not enabled.");    CU_FAIL("Signal handler manager not enabled.");
119  #else  #else
120    
121      CONSOLE_DEBUG("Assigning signals");
122        
123    old_fpe_handler = signal(SIGFPE, my_handler1);        /* save any pre-existing handlers */    old_fpe_handler = signal(SIGFPE, my_handler1);        /* save any pre-existing handlers */
124    old_int_handler = signal(SIGINT, my_handler1);    old_int_handler = signal(SIGINT, my_handler1);
# Line 128  static void test_ascSignal(void) Line 130  static void test_ascSignal(void)
130    
131    /* Asc_SignalInit(), Asc_SignalDestroy() - not much to test */    /* Asc_SignalInit(), Asc_SignalDestroy() - not much to test */
132    
133      CONSOLE_DEBUG("Start signal manager");
134    
135    CU_TEST(0 == Asc_SignalInit());                       /* initialize the signal manager */    CU_TEST(0 == Asc_SignalInit());                       /* initialize the signal manager */
136    
137    old_handler = signal(SIGFPE, SIG_DFL);                /* previously-installed handlers should still be active */    old_handler = signal(SIGFPE, SIG_DFL);                /* previously-installed handlers should still be active */
# Line 137  static void test_ascSignal(void) Line 141  static void test_ascSignal(void)
141    old_handler = signal(SIGSEGV, SIG_DFL);    old_handler = signal(SIGSEGV, SIG_DFL);
142    CU_TEST(my_handler2 == old_handler);    CU_TEST(my_handler2 == old_handler);
143    
144      CONSOLE_DEBUG("Recover installed signals");
145    Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
146    
147    old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should have been reinstalled */    old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should have been reinstalled */
# Line 146  static void test_ascSignal(void) Line 151  static void test_ascSignal(void)
151    old_handler = signal(SIGSEGV, SIG_DFL);    old_handler = signal(SIGSEGV, SIG_DFL);
152    CU_TEST(my_handler2 == old_handler);    CU_TEST(my_handler2 == old_handler);
153    
154      CONSOLE_DEBUG("Recover installed signals again");
155    Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
156    
157      CONSOLE_DEBUG("Test push/pop of handlers");
158    
159    /* test Asc_SignalPush(), Asc_SignalPop() */    /* test Asc_SignalPush(), Asc_SignalPop() */
160    
161    CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, Asc_SignalTrap));  /* ok - supported signal, ok func */    CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, Asc_SignalTrap));  /* ok - supported signal, ok func */
# Line 158  static void test_ascSignal(void) Line 166  static void test_ascSignal(void)
166    old_handler = signal(SIGINT, SIG_DFL);    old_handler = signal(SIGINT, SIG_DFL);
167    CU_TEST(my_handler1 == old_handler);    CU_TEST(my_handler1 == old_handler);
168    
169    CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, NULL));           /* NULL func - should have no effect */    CU_TEST(-2 == Asc_SignalHandlerPush(SIGSEGV, NULL));           /* NULL func - should have no effect */
170    old_handler = signal(SIGSEGV, SIG_DFL);    old_handler = signal(SIGSEGV, SIG_DFL);
171    CU_TEST(my_handler2 == old_handler);                          /* old handler should still be installed */    CU_TEST(my_handler2 == old_handler);                          /* old handler should still be installed */
172    
# Line 191  static void test_ascSignal(void) Line 199  static void test_ascSignal(void)
199    CU_TEST(NULL == old_handler);    CU_TEST(NULL == old_handler);
200    old_handler = signal(SIGSEGV, SIG_DFL);    old_handler = signal(SIGSEGV, SIG_DFL);
201    CU_TEST(my_handler2 == old_handler);    CU_TEST(my_handler2 == old_handler);
   Asc_SignalRecover(TRUE);  
202    
203      CONSOLE_DEBUG("Recover installed signals after a f");
204      Asc_SignalRecover(TRUE);
205    old_handler = signal(SIGFPE, SIG_DFL);                /* but Asc_SignalRecover should reset it */    old_handler = signal(SIGFPE, SIG_DFL);                /* but Asc_SignalRecover should reset it */
206    CU_TEST(my_handler1 == old_handler);    CU_TEST(my_handler1 == old_handler);
207    old_handler = signal(SIGINT, SIG_DFL);    old_handler = signal(SIGINT, SIG_DFL);
# Line 214  static void test_ascSignal(void) Line 223  static void test_ascSignal(void)
223    
224    /* test Asc_SignalTrap() */    /* test Asc_SignalTrap() */
225    
226      CONSOLE_DEBUG("Testing trapping of signals");
227    
228    CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, Asc_SignalTrap));
229    CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, Asc_SignalTrap));
230    CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, Asc_SignalTrap));
# Line 254  Asc_SignalRecover(TRUE); Line 265  Asc_SignalRecover(TRUE);
265    CU_TEST(0 == Asc_SignalHandlerPop(SIGINT, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPop(SIGINT, Asc_SignalTrap));
266    CU_TEST(0 == Asc_SignalHandlerPop(SIGSEGV, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPop(SIGSEGV, Asc_SignalTrap));
267    
268      CONSOLE_DEBUG("Check handler settings after pop");
269    
270    old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should be restored at this point */    old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should be restored at this point */
271    CU_TEST(my_handler1 == old_handler);    CU_TEST(my_handler1 == old_handler);
272    old_handler = signal(SIGINT, SIG_DFL);    old_handler = signal(SIGINT, SIG_DFL);
# Line 263  Asc_SignalRecover(TRUE); Line 276  Asc_SignalRecover(TRUE);
276    Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
277    
278    /* test typical use with nesting of handlers */    /* test typical use with nesting of handlers */
279      CONSOLE_DEBUG("Testing typical use of nested handlers");
280    
281    f_handler1_called = FALSE;                              /* initialize flags for detecting flow */    f_handler1_called = FALSE;                              /* initialize flags for detecting flow */
282    f_handler1_sigval = 0;    f_handler1_sigval = 0;
# Line 468  Asc_SignalRecover(TRUE); Line 482  Asc_SignalRecover(TRUE);
482    CU_TEST(FALSE == signal3_caught);    CU_TEST(FALSE == signal3_caught);
483    CU_TEST(0 == Asc_SignalHandlerPop(SIGSEGV, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPop(SIGSEGV, Asc_SignalTrap));
484    
485      CONSOLE_DEBUG("Check recovered signals");
486    
487    old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should be restored at this point */    old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should be restored at this point */
488    CU_TEST(my_handler1 == old_handler);    CU_TEST(my_handler1 == old_handler);
489    old_handler = signal(SIGINT, SIG_DFL);    old_handler = signal(SIGINT, SIG_DFL);
# Line 496  Asc_SignalRecover(TRUE); Line 512  Asc_SignalRecover(TRUE);
512      signal(SIGSEGV, old_seg_handler);      signal(SIGSEGV, old_seg_handler);
513    
514    CU_TEST(prior_meminuse == ascmeminuse());   /* make sure we cleaned up after ourselves */    CU_TEST(prior_meminuse == ascmeminuse());   /* make sure we cleaned up after ourselves */
515    
516      CONSOLE_DEBUG("Finished");
517  }  }
518    
519  /*===========================================================================*/  /*===========================================================================*/

Legend:
Removed from v.2272  
changed lines
  Added in v.2273

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22