/[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 2534 by jpye, Sun Oct 9 04:12:47 2011 UTC revision 2535 by jpye, Thu Jan 26 00:19:50 2012 UTC
# Line 21  Line 21 
21   *  COPYING.   *  COPYING.
22   */   */
23    
24  #include <stdio.h>  #include <ascend/utilities/ascSignal.h>
25  #include <ascend/general/platform.h>  #include <ascend/general/platform.h>
 #ifdef __WIN32__  
 #include <io.h>  
 #endif  
26  #include <ascend/general/ascMalloc.h>  #include <ascend/general/ascMalloc.h>
 #include <ascend/utilities/ascSignal.h>  
   
27  #include <test/common.h>  #include <test/common.h>
28    #include <stdio.h>
 // #define ASCSIGNAL_DEBUG  
29    
30  static jmp_buf my_jmp_buf1;  static jmp_buf my_jmp_buf1;
   
31  static int f_handler1_called;  static int f_handler1_called;
32  static int f_handler1_sigval;  static int f_handler1_sigval;
33  /*  /*
# Line 44  static int f_handler1_sigval; Line 37  static int f_handler1_sigval;
37   *  an unsupported sigval).  Then longjmp's using   *  an unsupported sigval).  Then longjmp's using
38   *  my_jmp_buf1 and the sigval.   *  my_jmp_buf1 and the sigval.
39   */   */
40  void my_handler1(int sigval)  void my_handler1(int sigval){
 {  
41    f_handler1_called = TRUE;    f_handler1_called = TRUE;
42    Asc_SignalRecover(FALSE);    Asc_SignalRecover(FALSE);
43    switch (sigval)    switch (sigval){
   {  
44      case SIGFPE:      case SIGFPE:
       f_handler1_sigval = SIGFPE;  
45        FPRESET;        FPRESET;
       break;  
46      case SIGINT:      case SIGINT:
       f_handler1_sigval = SIGINT;  
       break;  
47      case SIGSEGV:      case SIGSEGV:
48        f_handler1_sigval = SIGSEGV;        f_handler1_sigval = sigval;
49        break;        break;
50      default:      default:
51        f_handler1_sigval = -1;        f_handler1_sigval = -1;
# Line 68  void my_handler1(int sigval) Line 55  void my_handler1(int sigval)
55  }  }
56    
57  static jmp_buf my_jmp_buf2;  static jmp_buf my_jmp_buf2;
   
58  static int f_handler2_called;  static int f_handler2_called;
59  static int f_handler2_sigval;  static int f_handler2_sigval;
60  /*  /* identical to my_handler1 */
61   *  Signal handler for unit tests.  void my_handler2(int sigval){
  *  Resets the signal handlers and sets f_handler1_called to  
  *  TRUE and f_handler1_sigval to the signal type code (-1 if  
  *  an unsupported sigval).  Then longjmp's using  
  *  my_jmp_buf1 and the sigval.  
  */  
 void my_handler2(int sigval)  
 {  
62    f_handler2_called = TRUE;    f_handler2_called = TRUE;
63    Asc_SignalRecover(FALSE);    Asc_SignalRecover(FALSE);
64    switch (sigval)    switch (sigval){
   {  
65      case SIGFPE:      case SIGFPE:
       f_handler2_sigval = SIGFPE;  
66        FPRESET;        FPRESET;
       break;  
67      case SIGINT:      case SIGINT:
       f_handler2_sigval = SIGINT;  
       break;  
68      case SIGSEGV:      case SIGSEGV:
69        f_handler2_sigval = SIGSEGV;        f_handler2_sigval = sigval;
70        break;        break;
71      default:      default:
72        f_handler2_sigval = -1;        f_handler2_sigval = -1;
# Line 101  void my_handler2(int sigval) Line 75  void my_handler2(int sigval)
75    longjmp(my_jmp_buf2, sigval);    longjmp(my_jmp_buf2, sigval);
76  }  }
77    
78    static jmp_buf my_jmp_buf3;
79    static int f_handler3_called;
80    static int f_handler3_sigval;
81    /* identical to my_handler1 */
82    void my_handler3(int sigval){
83      f_handler3_called = TRUE;
84      Asc_SignalRecover(FALSE);
85      switch (sigval){
86        case SIGFPE:
87          FPRESET;
88        case SIGINT:
89        case SIGSEGV:
90          f_handler3_sigval = sigval;
91          break;
92        default:
93          f_handler3_sigval = -1;
94          break;
95      }
96      longjmp(my_jmp_buf3, sigval);
97    }
98    
99  static void test_ascSignal(void)  /*----------------------------------------------------------------------------*/
100  {  
101    static void test_ascSignal(void){
102    SigHandlerFn* old_fpe_handler = NULL;    SigHandlerFn* old_fpe_handler = NULL;
103    SigHandlerFn* old_int_handler = NULL;    SigHandlerFn* old_int_handler = NULL;
104    SigHandlerFn* old_seg_handler = NULL;    SigHandlerFn* old_seg_handler = NULL;
# Line 120  static void test_ascSignal(void) Line 115  static void test_ascSignal(void)
115    CU_FAIL("Signal handler manager not enabled.");    CU_FAIL("Signal handler manager not enabled.");
116  #else  #else
117    
   //CONSOLE_DEBUG("Assigning signals");  
     
118    old_fpe_handler = signal(SIGFPE, my_handler1);        /* save any pre-existing handlers */    old_fpe_handler = signal(SIGFPE, my_handler1);        /* save any pre-existing handlers */
119    old_int_handler = signal(SIGINT, my_handler1);    old_int_handler = signal(SIGINT, my_handler1);
120    old_seg_handler = signal(SIGSEGV, my_handler1);    old_seg_handler = signal(SIGSEGV, my_handler1);
# Line 132  static void test_ascSignal(void) Line 125  static void test_ascSignal(void)
125    
126    /* Asc_SignalInit(), Asc_SignalDestroy() - not much to test */    /* Asc_SignalInit(), Asc_SignalDestroy() - not much to test */
127    
   //CONSOLE_DEBUG("Start signal manager");  
   
128    CU_TEST(0 == Asc_SignalInit());                       /* initialize the signal manager */    CU_TEST(0 == Asc_SignalInit());                       /* initialize the signal manager */
129    
130    old_handler = signal(SIGFPE, SIG_DFL);                /* previously-installed handlers should still be active */    /* previously-installed handlers should still be active */
131    CU_TEST(my_handler1 == old_handler);    CU_TEST(signal(SIGFPE, SIG_DFL) == my_handler1);
132    old_handler = signal(SIGINT, SIG_DFL);    CU_TEST(signal(SIGINT, SIG_DFL) == SIG_DFL);
133    CU_TEST(NULL == old_handler);    CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);
   old_handler = signal(SIGSEGV, SIG_DFL);  
   CU_TEST(my_handler2 == old_handler);  
   
   //CONSOLE_DEBUG("Recover installed signals");  
   Asc_SignalRecover(TRUE);  
   
   old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should have been reinstalled */  
   CU_TEST(my_handler1 == old_handler);  
   old_handler = signal(SIGINT, SIG_DFL);  
   CU_TEST(NULL == old_handler);  
   old_handler = signal(SIGSEGV, SIG_DFL);  
   CU_TEST(my_handler2 == old_handler);  
134    
   //CONSOLE_DEBUG("Recover installed signals again");  
135    Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
136    
137    //CONSOLE_DEBUG("Test push/pop of handlers");    /* handlers should have been reinstalled */
138      CU_TEST(signal(SIGFPE, SIG_DFL) == my_handler1);
139      CU_TEST(signal(SIGINT, SIG_DFL) == SIG_DFL);
140      CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);
141    
142      Asc_SignalRecover(TRUE); /* back to h1, 0, h2 again */
143    
144      /*
145      In the following, take
146      H1 = my_handler1
147      H2 = my_handler2
148      AS = Asc_SignalTrap
149      DF = SIG_DFL
150      00 = NULL
151      so the initial state of the stacks is
152      FPE:H1, INT:00, SEG: H2.
153      */
154    
155      CONSOLE_DEBUG("INITIAL STACKS...");
156      Asc_SignalPrintStack(SIGFPE);
157      Asc_SignalPrintStack(SIGINT);
158      Asc_SignalPrintStack(SIGSEGV);
159    
160    /* test Asc_SignalPush(), Asc_SignalPop() */    /* test Asc_SignalPush(), Asc_SignalPop() */
161      CU_TEST(Asc_SignalStackLength(SIGFPE) == 1);
162    
163    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 */
164    old_handler = signal(SIGFPE, SIG_DFL);    CU_TEST(signal(SIGFPE, SIG_DFL) == Asc_SignalTrap);
   CU_TEST(Asc_SignalTrap == old_handler);  
165    
166    CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, my_handler1));     /* ok - supported signal, ok func */    CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, my_handler1));    /* ok - supported signal, ok func */
167    old_handler = signal(SIGINT, SIG_DFL);    CU_TEST(signal(SIGINT, SIG_DFL) == my_handler1);
   CU_TEST(my_handler1 == old_handler);  
168    
169    CU_TEST(-2 == 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);    CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);             /* old handler should still be installed */
   CU_TEST(my_handler2 == old_handler);                          /* old handler should still be installed */  
171    
172    CU_TEST(0 != Asc_SignalHandlerPush(SIGILL, Asc_SignalTrap));  /* unsupported signal type */    CU_TEST(0 != Asc_SignalHandlerPush(SIGILL, Asc_SignalTrap));  /* unsupported signal type */
173    CU_TEST(0 != Asc_SignalHandlerPush(SIGABRT, my_handler2));    /* unsupported signal type */    CU_TEST(0 != Asc_SignalHandlerPush(SIGABRT, my_handler2));    /* unsupported signal type */
174    
175    Asc_SignalRecover(TRUE);    /* expect FPE:H1:AS, INT:00,H1, SEG:H2 */
176      CU_TEST(Asc_SignalStackLength(SIGFPE) == 2);
177    
   old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should have been reinstalled */  
   CU_TEST(Asc_SignalTrap == old_handler);  
   old_handler = signal(SIGINT, SIG_DFL);  
   CU_TEST(my_handler1 == old_handler);  
   old_handler = signal(SIGSEGV, SIG_DFL);  
   CU_TEST(my_handler2 == old_handler);  
178    Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
179    
180    CU_TEST(0 == Asc_SignalHandlerPop(SIGINT, my_handler1));    CONSOLE_DEBUG("UPDATED STACKS...");
181    old_handler = signal(SIGFPE, SIG_DFL);                /* SIGINT should be reset to no handler */    Asc_SignalPrintStack(SIGFPE);
182    CU_TEST(Asc_SignalTrap == old_handler);    Asc_SignalPrintStack(SIGINT);
183    old_handler = signal(SIGINT, SIG_DFL);    Asc_SignalPrintStack(SIGSEGV);
   CU_TEST(NULL == old_handler);  
   old_handler = signal(SIGSEGV, SIG_DFL);  
   CU_TEST(my_handler2 == old_handler);  
   Asc_SignalRecover(TRUE);  
184    
185    CU_TEST(0 != Asc_SignalHandlerPop(SIGFPE, my_handler1));  /* wrong handler indicated */    /* handlers should have been reinstalled */
186    old_handler = signal(SIGFPE, SIG_DFL);                /* so SIGFPE should be not be reset */    CU_TEST(signal(SIGFPE, SIG_DFL) == Asc_SignalTrap);
187    CU_TEST(Asc_SignalTrap == old_handler);    CU_TEST(signal(SIGINT, SIG_DFL) == my_handler1);
188    old_handler = signal(SIGINT, SIG_DFL);    CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);
189    CU_TEST(NULL == old_handler);    Asc_SignalRecover(TRUE); /* still at asc, h1, 0 */
   old_handler = signal(SIGSEGV, SIG_DFL);  
   CU_TEST(my_handler2 == old_handler);  
190    
191    //CONSOLE_DEBUG("Recover installed signals after a f");    CU_TEST(0 == Asc_SignalHandlerPop(SIGINT, my_handler1));
192    Asc_SignalRecover(TRUE);    /* SIGINT should be reset to no handler */
193    old_handler = signal(SIGFPE, SIG_DFL);                /* but Asc_SignalRecover should reset it */    /* expect FPE:H1:AS, INT:00, SEG:H2 */
194    CU_TEST(my_handler1 == old_handler);    CU_TEST(signal(SIGFPE, SIG_DFL) == Asc_SignalTrap);
195    old_handler = signal(SIGINT, SIG_DFL);    CU_TEST(signal(SIGINT, SIG_DFL) == NULL);
196    CU_TEST(NULL == old_handler);    CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);
197    old_handler = signal(SIGSEGV, SIG_DFL);    Asc_SignalRecover(TRUE);
198    CU_TEST(my_handler2 == old_handler);  
199      CONSOLE_DEBUG("Testing pop of incorrect handler...");
200      CU_TEST(0 != Asc_SignalHandlerPop(SIGFPE, my_handler2));  /* wrong handler indicated */
201      /* expect FPE:H1, INT:00, SEG:H2, but SIGFPE shoule still be AS. */
202      CU_TEST(signal(SIGFPE, SIG_DFL) == Asc_SignalTrap);
203      CU_TEST(signal(SIGINT, SIG_DFL) == NULL);
204      CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);
205    
206      Asc_SignalRecover(TRUE);
207      /* but Asc_SignalRecover should fix up SIGFPE to H1 */
208      /* expect FPE:H1, INT:00, SEG:H2 */
209      CU_TEST(signal(SIGFPE, SIG_DFL) == my_handler1);
210      CU_TEST(signal(SIGINT, SIG_DFL) == NULL);
211      CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);
212    Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
213    
214    CU_TEST(0 != Asc_SignalHandlerPop(SIGILL, my_handler1));     /* unsupported signal type */    CU_TEST(0 != Asc_SignalHandlerPop(SIGILL, my_handler1));     /* unsupported signal type */
215    CU_TEST(0 != Asc_SignalHandlerPop(SIGABRT, Asc_SignalTrap)); /* unsupported signal type */    CU_TEST(0 != Asc_SignalHandlerPop(SIGABRT, Asc_SignalTrap)); /* unsupported signal type */
216    
217    old_handler = signal(SIGFPE, SIG_DFL);                /* should be no change in handlers */    /* should be no change in handlers */
218    CU_TEST(my_handler1 == old_handler);    CU_TEST(signal(SIGFPE, SIG_DFL) == my_handler1);
219    old_handler = signal(SIGINT, SIG_DFL);    CU_TEST(signal(SIGINT, SIG_DFL) == NULL);
220    CU_TEST(NULL == old_handler);    CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);
   old_handler = signal(SIGSEGV, SIG_DFL);  
   CU_TEST(my_handler2 == old_handler);  
221    Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
222    
223    /* test Asc_SignalTrap() */    /* test Asc_SignalTrap() */
224    
225    //CONSOLE_DEBUG("Testing trapping of signals");    //CONSOLE_DEBUG("Testing trapping of signals");
   
226    CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, Asc_SignalTrap));
227    CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, Asc_SignalTrap));
228    CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, Asc_SignalTrap));
# Line 261  static void test_ascSignal(void) Line 257  static void test_ascSignal(void)
257    }    }
258    CU_TEST(TRUE == signal1_caught);    CU_TEST(TRUE == signal1_caught);
259    
260  Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
261    
262    CU_TEST(0 == Asc_SignalHandlerPop(SIGFPE, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPop(SIGFPE, Asc_SignalTrap));
263    CU_TEST(0 == Asc_SignalHandlerPop(SIGINT, Asc_SignalTrap));    CU_TEST(0 == Asc_SignalHandlerPop(SIGINT, Asc_SignalTrap));
# Line 269  Asc_SignalRecover(TRUE); Line 265  Asc_SignalRecover(TRUE);
265    
266    //CONSOLE_DEBUG("Check handler settings after pop");    //CONSOLE_DEBUG("Check handler settings after pop");
267    
268    old_handler = signal(SIGFPE, SIG_DFL);                /* handlers should be restored at this point */    /* handlers should be restored at this point */
269    CU_TEST(my_handler1 == old_handler);    CU_TEST(signal(SIGFPE, SIG_DFL) == my_handler1);
270    old_handler = signal(SIGINT, SIG_DFL);    CU_TEST(signal(SIGINT, SIG_DFL) == NULL);
271    CU_TEST(NULL == old_handler);    CU_TEST(signal(SIGSEGV, SIG_DFL) == my_handler2);
   old_handler = signal(SIGSEGV, SIG_DFL);  
   CU_TEST(my_handler2 == old_handler);  
272    Asc_SignalRecover(TRUE);    Asc_SignalRecover(TRUE);
273    
274      CONSOLE_DEBUG("CURRENT STACKS...");
275      Asc_SignalPrintStack(SIGFPE);
276      Asc_SignalPrintStack(SIGINT);
277      Asc_SignalPrintStack(SIGSEGV);
278    
279    
280    /* test typical use with nesting of handlers */    /* test typical use with nesting of handlers */
281    //CONSOLE_DEBUG("Testing typical use of nested handlers");    //CONSOLE_DEBUG("Testing typical use of nested handlers");
282    
# Line 284  Asc_SignalRecover(TRUE); Line 284  Asc_SignalRecover(TRUE);
284    f_handler1_sigval = 0;    f_handler1_sigval = 0;
285    f_handler2_called = FALSE;    f_handler2_called = FALSE;
286    f_handler2_sigval = 0;    f_handler2_sigval = 0;
287      f_handler3_called = FALSE;
288      f_handler3_sigval = 0;
289    signal1_caught = FALSE;    signal1_caught = FALSE;
290    signal2_caught = FALSE;    signal2_caught = FALSE;
291    signal3_caught = FALSE;    signal3_caught = FALSE;
292    
293    CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, my_handler1));   /* test for SIGFPE */    CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, my_handler1));   /* test for SIGFPE */
294    if (0 == setjmp(my_jmp_buf1)) {    if(0 == setjmp(my_jmp_buf1)){
295      CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, my_handler2));      CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, my_handler2));
296      if (0 == setjmp(my_jmp_buf2)) {      if(0 == setjmp(my_jmp_buf2)){
297        CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, Asc_SignalTrap));        CU_TEST(0 == Asc_SignalHandlerPush(SIGFPE, my_handler3));
298        if (0 == setjmp(g_fpe_env)) {  
299           raise(SIGFPE);        Asc_SignalRecover(TRUE);
300        }        CONSOLE_DEBUG("CURRENT STACKS...");
301        else {        Asc_SignalPrintStack(SIGFPE);
302          Asc_SignalPrintStack(SIGINT);
303          Asc_SignalPrintStack(SIGSEGV);
304    
305          if(0 == setjmp(my_jmp_buf3)){
306             /* make sure the expected handler is in place... */
307             CU_TEST(my_handler3 == signal(SIGFPE, my_handler3));
308    
309             /* raise our first SIGFPE... */
310             CONSOLE_DEBUG("Raising SIGFPE exception...");
311             CU_TEST(0 == raise(SIGSEGV));
312    
313             CU_FAIL("should'nt be here!");
314             CONSOLE_DEBUG("got here (didn't want to)");
315             //Asc_SignalTrap(SIGFPE);
316             //CONSOLE_DEBUG("and here");
317          }else{
318            /* catching our first SIGFPE, labelled 'signal 3' */
319            CONSOLE_DEBUG("got here");
320          CU_TEST(f_handler1_called == FALSE);          CU_TEST(f_handler1_called == FALSE);
321          CU_TEST(f_handler1_sigval == 0);          CU_TEST(f_handler1_sigval == 0);
322          CU_TEST(f_handler2_called == FALSE);          CU_TEST(f_handler2_called == FALSE);
323          CU_TEST(f_handler2_sigval == 0);          CU_TEST(f_handler2_sigval == 0);
324          signal3_caught = TRUE;          signal3_caught = TRUE;
325        }        }
326          /* fall through: we should have caught 'signal 3' before this */
327          CONSOLE_DEBUG("down here");
328        CU_TEST(FALSE == signal1_caught);        CU_TEST(FALSE == signal1_caught);
329        CU_TEST(FALSE == signal2_caught);        CU_TEST(FALSE == signal2_caught);
330        CU_TEST(TRUE == signal3_caught);        CU_TEST(TRUE == signal3_caught);
331    
332        CU_TEST(0 == Asc_SignalHandlerPop(SIGFPE, Asc_SignalTrap));        CU_TEST(0 == Asc_SignalHandlerPop(SIGFPE, Asc_SignalTrap));
333    
334        f_handler1_called = FALSE;        f_handler1_called = FALSE;
335        f_handler1_sigval = 0;        f_handler1_sigval = 0;
336        f_handler2_called = FALSE;        f_handler2_called = FALSE;
# Line 315  Asc_SignalRecover(TRUE); Line 339  Asc_SignalRecover(TRUE);
339        signal2_caught = FALSE;        signal2_caught = FALSE;
340        signal3_caught = FALSE;        signal3_caught = FALSE;
341        raise(SIGFPE);        raise(SIGFPE);
342      }      }else{
     else {  
343        CU_TEST(f_handler1_called == FALSE);        CU_TEST(f_handler1_called == FALSE);
344        CU_TEST(f_handler1_sigval == 0);        CU_TEST(f_handler1_sigval == 0);
345        CU_TEST(f_handler2_called == TRUE);        CU_TEST(f_handler2_called == TRUE);
# Line 326  Asc_SignalRecover(TRUE); Line 349  Asc_SignalRecover(TRUE);
349      CU_TEST(FALSE == signal1_caught);      CU_TEST(FALSE == signal1_caught);
350      CU_TEST(TRUE == signal2_caught);      CU_TEST(TRUE == signal2_caught);
351      CU_TEST(FALSE == signal3_caught);      CU_TEST(FALSE == signal3_caught);
352        
353      CU_TEST(0 == Asc_SignalHandlerPop(SIGFPE, my_handler2));      CU_TEST(0 == Asc_SignalHandlerPop(SIGFPE, my_handler2));
354        
355      f_handler1_called = FALSE;      f_handler1_called = FALSE;
356      f_handler1_sigval = 0;      f_handler1_sigval = 0;
357      f_handler2_called = FALSE;      f_handler2_called = FALSE;
# Line 335  Asc_SignalRecover(TRUE); Line 360  Asc_SignalRecover(TRUE);
360      signal2_caught = FALSE;      signal2_caught = FALSE;
361      signal3_caught = FALSE;      signal3_caught = FALSE;
362      raise(SIGFPE);      raise(SIGFPE);
363    }    }else{
   else {  
364      CU_TEST(f_handler1_called == TRUE);      CU_TEST(f_handler1_called == TRUE);
365      CU_TEST(f_handler1_sigval == SIGFPE);      CU_TEST(f_handler1_sigval == SIGFPE);
366      CU_TEST(f_handler2_called == FALSE);      CU_TEST(f_handler2_called == FALSE);
# Line 346  Asc_SignalRecover(TRUE); Line 370  Asc_SignalRecover(TRUE);
370    CU_TEST(TRUE == signal1_caught);    CU_TEST(TRUE == signal1_caught);
371    CU_TEST(FALSE == signal2_caught);    CU_TEST(FALSE == signal2_caught);
372    CU_TEST(FALSE == signal3_caught);    CU_TEST(FALSE == signal3_caught);
373      
374    CU_TEST(0 == Asc_SignalHandlerPop(SIGFPE, my_handler1));    CU_TEST(0 == Asc_SignalHandlerPop(SIGFPE, my_handler1));
375      
376    f_handler1_called = FALSE;                              /* initialize flags for detecting flow */    f_handler1_called = FALSE;                              /* initialize flags for detecting flow */
377    f_handler1_sigval = 0;    f_handler1_sigval = 0;
378    f_handler2_called = FALSE;    f_handler2_called = FALSE;
# Line 357  Asc_SignalRecover(TRUE); Line 382  Asc_SignalRecover(TRUE);
382    signal3_caught = FALSE;    signal3_caught = FALSE;
383    
384    CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, my_handler2));   /* test for SIGINT */    CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, my_handler2));   /* test for SIGINT */
385    if (0 == setjmp(my_jmp_buf2)) {    if(0 == setjmp(my_jmp_buf2)) {
386      CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, Asc_SignalTrap));      CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, Asc_SignalTrap));
387      if (0 == setjmp(g_int_env)) {      if(0 == setjmp(g_int_env)) {
388        CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, my_handler1));        CU_TEST(0 == Asc_SignalHandlerPush(SIGINT, my_handler1));
389        if (0 == setjmp(my_jmp_buf1)) {        if(0 == setjmp(my_jmp_buf1)) {
390           raise(SIGINT);           raise(SIGINT);
391        }           CU_FAIL("shouldn't be here!");
392        else {        }else{
393          CU_TEST(f_handler1_called == TRUE);          CU_TEST(f_handler1_called == TRUE);
394          CU_TEST(f_handler1_sigval == SIGINT);          CU_TEST(f_handler1_sigval == SIGINT);
395          CU_TEST(f_handler2_called == FALSE);          CU_TEST(f_handler2_called == FALSE);
# Line 383  Asc_SignalRecover(TRUE); Line 408  Asc_SignalRecover(TRUE);
408        signal2_caught = FALSE;        signal2_caught = FALSE;
409        signal3_caught = FALSE;        signal3_caught = FALSE;
410        raise(SIGINT);        raise(SIGINT);
411      }      }else{
     else {  
412        CU_TEST(f_handler1_called == FALSE);        CU_TEST(f_handler1_called == FALSE);
413        CU_TEST(f_handler1_sigval == 0);        CU_TEST(f_handler1_sigval == 0);
414        CU_TEST(f_handler2_called == FALSE);        CU_TEST(f_handler2_called == FALSE);
# Line 403  Asc_SignalRecover(TRUE); Line 427  Asc_SignalRecover(TRUE);
427      signal2_caught = FALSE;      signal2_caught = FALSE;
428      signal3_caught = FALSE;      signal3_caught = FALSE;
429      raise(SIGINT);      raise(SIGINT);
430    }    }else{
   else {  
431      CU_TEST(f_handler1_called == FALSE);      CU_TEST(f_handler1_called == FALSE);
432      CU_TEST(f_handler1_sigval == 0);      CU_TEST(f_handler1_sigval == 0);
433      CU_TEST(f_handler2_called == TRUE);      CU_TEST(f_handler2_called == TRUE);
# Line 425  Asc_SignalRecover(TRUE); Line 448  Asc_SignalRecover(TRUE);
448    signal3_caught = FALSE;    signal3_caught = FALSE;
449    
450    CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, Asc_SignalTrap));   /* test for SIGSEGV */    CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, Asc_SignalTrap));   /* test for SIGSEGV */
451    if (0 == setjmp(g_seg_env)) {    if(0 == setjmp(g_seg_env)) {
452      CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, my_handler2));      CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, my_handler2));
453      if (0 == setjmp(my_jmp_buf2)) {      if(0 == setjmp(my_jmp_buf2)) {
454        CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, my_handler1));        CU_TEST(0 == Asc_SignalHandlerPush(SIGSEGV, my_handler1));
455        if (0 == setjmp(my_jmp_buf1)) {        if(0 == setjmp(my_jmp_buf1)) {
456           raise(SIGSEGV);           raise(SIGSEGV);
457        }           CU_FAIL("shouldn't be here!");
458        else {        }else{
459          CU_TEST(f_handler1_called == TRUE);          CU_TEST(f_handler1_called == TRUE);
460          CU_TEST(f_handler1_sigval == SIGSEGV);          CU_TEST(f_handler1_sigval == SIGSEGV);
461          CU_TEST(f_handler2_called == FALSE);          CU_TEST(f_handler2_called == FALSE);
# Line 451  Asc_SignalRecover(TRUE); Line 474  Asc_SignalRecover(TRUE);
474        signal2_caught = FALSE;        signal2_caught = FALSE;
475        signal3_caught = FALSE;        signal3_caught = FALSE;
476        raise(SIGSEGV);        raise(SIGSEGV);
477      }      }else{
     else {  
478        CU_TEST(f_handler1_called == FALSE);        CU_TEST(f_handler1_called == FALSE);
479        CU_TEST(f_handler1_sigval == 0);        CU_TEST(f_handler1_sigval == 0);
480        CU_TEST(f_handler2_called == TRUE);        CU_TEST(f_handler2_called == TRUE);
# Line 471  Asc_SignalRecover(TRUE); Line 493  Asc_SignalRecover(TRUE);
493      signal2_caught = FALSE;      signal2_caught = FALSE;
494      signal3_caught = FALSE;      signal3_caught = FALSE;
495      raise(SIGSEGV);      raise(SIGSEGV);
496    }    }else{
   else {  
497      CU_TEST(f_handler1_called == FALSE);      CU_TEST(f_handler1_called == FALSE);
498      CU_TEST(f_handler1_sigval == 0);      CU_TEST(f_handler1_sigval == 0);
499      CU_TEST(f_handler2_called == FALSE);      CU_TEST(f_handler2_called == FALSE);
# Line 513  Asc_SignalRecover(TRUE); Line 534  Asc_SignalRecover(TRUE);
534    if (NULL != old_seg_handler)    if (NULL != old_seg_handler)
535      signal(SIGSEGV, old_seg_handler);      signal(SIGSEGV, old_seg_handler);
536    
537    CU_TEST(prior_meminuse == ascmeminuse());   /* make sure we cleaned up after ourselves */    /* TODO what if they WERE null... has something changed now in that case?? */
538    
539    //CONSOLE_DEBUG("Finished");    CU_TEST(prior_meminuse == ascmeminuse());   /* make sure we cleaned up after ourselves */
540  }  }
541    
542  /*===========================================================================*/  /*===========================================================================*/

Legend:
Removed from v.2534  
changed lines
  Added in v.2535

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