linux: Introduce INTERNAL_VSYSCALL
[glibc.git] / assert / test-assert.c
blob25e264543ba01beb794c8cf974ff6901a1016a88
1 /* Test assert().
3 * This is hairier than you'd think, involving games with
4 * stdio and signals.
6 */
8 #include <signal.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <setjmp.h>
14 #include <support/xstdio.h>
16 jmp_buf rec;
17 char buf[160];
19 static void
20 sigabrt (int unused)
22 longjmp (rec, 1); /* recover control */
25 #undef NDEBUG
26 #include <assert.h>
27 static void
28 assert1 (void)
30 assert (1 == 2);
33 static void
34 assert2 (void)
36 assert (1 == 1);
40 #define NDEBUG
41 #include <assert.h>
42 static void
43 assert3 (void)
45 assert (2 == 3);
48 int
49 main (void)
52 volatile int failed = 1;
54 fclose (stderr);
55 stderr = tmpfile ();
56 if(!stderr)
57 abort ();
59 signal (SIGABRT, sigabrt);
61 if (!setjmp (rec))
62 assert1 ();
63 else
64 failed = 0; /* should happen */
66 if (!setjmp (rec))
67 assert2 ();
68 else
69 failed = 1; /* should not happen */
71 if (!setjmp (rec))
72 assert3 ();
73 else
74 failed = 1; /* should not happen */
76 rewind (stderr);
77 xfgets (buf, 160, stderr);
78 if (!strstr (buf, "1 == 2"))
79 failed = 1;
81 xfgets (buf, 160, stderr);
82 if (strstr (buf, "1 == 1"))
83 failed = 1;
85 xfgets (buf, 160, stderr);
86 if (strstr (buf, "2 == 3"))
87 failed = 1;
89 return failed;