Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / setjmp.c
1 /** setjmp/longjmp tests.
2 */
3 #include <testfwk.h>
4 #include <setjmp.h>
5
6 unsigned int global_int = 0;
7 unsigned int *gpInt;
8
9 #if defined(SDCC_mcs51)
10 #include <8052.h>
11
12 void T2_isr (void) interrupt 5 //no using
13 {
14   //do not clear flag TF2 so it keeps interrupting !
15   (*gpInt)++;
16 }
17 #endif
18
19 #if defined(SDCC_mcs51) || defined(PORT_HOST)
20
21 void try_fun(jmp_buf catch, int except)
22 {
23   longjmp(catch, except);
24 }
25
26 #endif
27
28 void
29 testJmp(void)
30 {
31 #if defined(SDCC_mcs51) || defined(PORT_HOST)
32
33   jmp_buf catch;
34   int exception;
35
36 #if defined(SDCC_mcs51)
37   gpInt = &global_int;
38   //enable the interrupt and set it's flag to generate some heavy stack usage
39   ET2 = 1;
40   EA = 1;
41   TF2 = 1;
42 #endif
43
44   exception = setjmp(catch);
45   if (exception == 0)
46   {
47         try_fun(catch, 1);
48         //should not get here!
49         ASSERT(0);
50   }
51   ASSERT(exception == 1);
52
53 #endif
54 }