ReactOS 0.4.16-dev-1457-g02ea0aa
setjmp.c File Reference
#include <apitest.h>
#include <pseh/pseh2.h>
#include <setjmp.h>
#include <assert.h>
#include <rtlfuncs.h>
Include dependency graph for setjmp.c:

Go to the source code of this file.

Macros

#define CHECK_POINT(number)
 
#define DO_COME(number)    ok(s_check_points[number], "CheckPoint #%d: Didn't reach\n", number)
 
#define NEVER_COME(number)
 

Functions

static void TEST_setjmp_normal (void)
 
static void TEST_setjmp_return_check (void)
 
static void TEST_longjmp (int value)
 
static void TEST_setjmp_longjmp_integration (void)
 
static void TEST_setjmp_zero_longjmp_check (void)
 
 START_TEST (setjmp)
 

Variables

static jmp_buf g_jmp_buf
 
static INT s_check_points [16] = { 0 }
 

Macro Definition Documentation

◆ CHECK_POINT

#define CHECK_POINT (   number)
Value:
do { \
s_check_points[number] = __LINE__; \
} while (0)
static unsigned int number
Definition: dsound.c:1479
static INT s_check_points[16]
Definition: setjmp.c:96
#define _countof(array)
Definition: sndvol32.h:70

Definition at line 98 of file setjmp.c.

◆ DO_COME

#define DO_COME (   number)     ok(s_check_points[number], "CheckPoint #%d: Didn't reach\n", number)

◆ NEVER_COME

#define NEVER_COME (   number)
Value:
ok(!s_check_points[number], "CheckPoint #%d: Wrongly reached Line %d\n", \
#define ok(value,...)
Definition: atltest.h:57

Function Documentation

◆ START_TEST()

START_TEST ( setjmp  )

Definition at line 196 of file setjmp.c.

197{
199
200 /* FIXME: These tests are insufficient */
205
206#define DO_COME(number) \
207 ok(s_check_points[number], "CheckPoint #%d: Didn't reach\n", number)
208#define NEVER_COME(number) \
209 ok(!s_check_points[number], "CheckPoint #%d: Wrongly reached Line %d\n", \
210 number, s_check_points[number])
211
212 DO_COME(0);
213 NEVER_COME(1);
214
215 DO_COME(0);
216 NEVER_COME(1);
217 DO_COME(2);
218 NEVER_COME(3);
219 DO_COME(4);
220 NEVER_COME(5);
221 DO_COME(6);
222 NEVER_COME(7);
223 DO_COME(8);
224 NEVER_COME(9);
225 NEVER_COME(10);
226 DO_COME(11);
227 NEVER_COME(12);
228 DO_COME(13);
229 NEVER_COME(14);
230 NEVER_COME(15);
231}
static void TEST_setjmp_normal(void)
Definition: setjmp.c:18
#define NEVER_COME(number)
static void TEST_setjmp_return_check(void)
Definition: setjmp.c:103
#define DO_COME(number)
static void TEST_setjmp_zero_longjmp_check(void)
Definition: setjmp.c:156
static void TEST_setjmp_longjmp_integration(void)
Definition: setjmp.c:133
#define ZeroMemory
Definition: winbase.h:1753

◆ TEST_longjmp()

static void TEST_longjmp ( int  value)
static

Definition at line 126 of file setjmp.c.

127{
128 CHECK_POINT(4);
129 longjmp(g_jmp_buf, value);
130 CHECK_POINT(5);
131}
#define CHECK_POINT(number)
Definition: setjmp.c:98
static jmp_buf g_jmp_buf
Definition: setjmp.c:16
Definition: pdh_main.c:96

Referenced by TEST_setjmp_longjmp_integration(), and TEST_setjmp_zero_longjmp_check().

◆ TEST_setjmp_longjmp_integration()

static void TEST_setjmp_longjmp_integration ( void  )
static

Definition at line 133 of file setjmp.c.

134{
135 volatile int value;
136
137 memset(&g_jmp_buf, 0xCC, sizeof(g_jmp_buf));
139
140 if (value == 0)
141 {
142 CHECK_POINT(6);
143 TEST_longjmp(0xBEEFCAFE);
144 CHECK_POINT(7);
145 }
146 else if (value == 0xBEEFCAFE)
147 {
148 CHECK_POINT(8);
149 }
150 else
151 {
152 CHECK_POINT(9);
153 }
154}
#define memset(x, y, z)
Definition: compat.h:39
static void TEST_longjmp(int value)
Definition: setjmp.c:126
#define setjmp
Definition: setjmp.h:209

Referenced by START_TEST().

◆ TEST_setjmp_normal()

static void TEST_setjmp_normal ( void  )
static

Definition at line 18 of file setjmp.c.

19{
20 volatile int stage = 0;
21 volatile DWORD exception = 0;
22 volatile BOOL abnormal = FALSE, finally_called = FALSE;
23 int value;
24
26 switch (stage)
27 {
28 case 0:
29 ok_int(value, 0);
30 stage = 1;
31 longjmp(g_jmp_buf, 999);
33 break;
34 case 1:
35 ok_int(value, 999);
36 stage = 2;
37 longjmp(g_jmp_buf, 0);
39 break;
40 case 2:
41 ok_int(value, 1);
42 stage = 3;
43#ifdef __clang__ /* avoiding clang build hung up */
44 skip("avoiding clang build crash\n");
45#else /* ndef __clang__ */
47 {
48 longjmp(g_jmp_buf, 333);
49 }
51 {
52 finally_called = TRUE;
53 abnormal = AbnormalTermination();
54 }
57 break;
58#endif /* ndef __clang__ */
59 case 3:
60 ok_int(value, 333);
61#ifdef _M_AMD64 // This is broken on Windows 2003 x64
62 if (NtCurrentPeb()->OSMajorVersion >= 6)
63#endif
64 {
65 ok_int(finally_called, TRUE);
66 ok_int(abnormal, TRUE);
67 }
68 stage = 4;
69#ifdef __clang__ /* avoiding clang build hung up */
70 skip("avoiding clang build crash\n");
71#else /* ndef __clang__ */
73 {
74 longjmp(g_jmp_buf, 444);
75 }
77 {
78 exception = -1;
79 }
82 break;
83#endif /* ndef __clang__ */
84 case 4:
85 ok_int(value, 444);
86 ok_int(exception, 0);
87 break;
88 default:
90 break;
91 }
92
93 ok_int(stage, 4);
94}
#define NtCurrentPeb()
Definition: FLS.c:22
#define skip(...)
Definition: atltest.h:64
#define ok_int(expression, result)
Definition: atltest.h:134
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_FINALLY
Definition: pseh2_64.h:130
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define AbnormalTermination()
Definition: exception.h:76
#define GetExceptionCode()
Definition: exception.h:68

Referenced by START_TEST().

◆ TEST_setjmp_return_check()

static void TEST_setjmp_return_check ( void  )
static

Definition at line 103 of file setjmp.c.

104{
105 volatile int x = 1001, value;
106 memset(&g_jmp_buf, 0xCC, sizeof(g_jmp_buf));
108
109 if (value == 0)
110 {
111 CHECK_POINT(0);
112 longjmp(g_jmp_buf, 999);
113 CHECK_POINT(1);
114 }
115 else if (value == 999)
116 {
117 CHECK_POINT(2);
118 ok_int(x, 1001);
119 }
120 else
121 {
122 CHECK_POINT(3);
123 }
124}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Referenced by START_TEST().

◆ TEST_setjmp_zero_longjmp_check()

static void TEST_setjmp_zero_longjmp_check ( void  )
static

Definition at line 156 of file setjmp.c.

157{
158 volatile int value;
159 volatile BOOL went_zero = FALSE;
160
161 memset(&g_jmp_buf, 0xCC, sizeof(g_jmp_buf));
163
164 if (value == 0)
165 {
166 if (went_zero)
167 {
168 CHECK_POINT(10);
169 return;
170 }
171 went_zero = TRUE;
172
173 CHECK_POINT(11);
174
175 TEST_longjmp(0); /* giving zero should go to one */
176
177 CHECK_POINT(12);
178 }
179 else if (value == 1)
180 {
181 if (went_zero)
182 {
183 CHECK_POINT(13);
184 }
185 else
186 {
187 CHECK_POINT(14);
188 }
189 }
190 else
191 {
192 CHECK_POINT(15);
193 }
194}

Referenced by START_TEST().

Variable Documentation

◆ g_jmp_buf

◆ s_check_points

INT s_check_points[16] = { 0 }
static

Definition at line 96 of file setjmp.c.

Referenced by START_TEST().