7 #include <ccan/tap/tap.h>
9 /* We don't actually want it to exit... */
10 static jmp_buf exited
;
11 #define exit(status) longjmp(exited, (status) + 1)
13 #define printf saved_printf
14 static int saved_printf(const char *fmt
, ...);
16 #define fprintf saved_fprintf
17 static int saved_fprintf(FILE *ignored
, const char *fmt
, ...);
19 #define vfprintf saved_vfprintf
20 static int saved_vfprintf(FILE *ignored
, const char *fmt
, va_list ap
);
22 /* Hack to avoid a memory leak which valgrind complains about. */
23 #define realloc set_realloc
24 static void *set_realloc(void *ptr
, size_t size
);
27 static void set_free(void *ptr
);
29 /* Include the C files directly. */
30 #include <ccan/failtest/failtest.c>
36 static void *set_realloc(void *ptr
, size_t size
)
38 return buffer
= realloc(ptr
, size
);
41 static void set_free(void *ptr
)
48 static char *output
= NULL
;
50 static int saved_vprintf(const char *fmt
, va_list ap
)
57 ret
= vsnprintf(NULL
, 0, fmt
, ap2
);
63 output
= realloc(output
, len
+ ret
+ 1);
64 return vsprintf(output
+ len
, fmt
, ap
);
67 static int saved_vfprintf(FILE *ignored
, const char *fmt
, va_list ap
)
69 return saved_vprintf(fmt
, ap
);
72 static int saved_printf(const char *fmt
, ...)
78 ret
= saved_vprintf(fmt
, ap
);
83 static int saved_fprintf(FILE *ignored
, const char *fmt
, ...)
89 ret
= saved_vprintf(fmt
, ap
);
99 failtest_init(0, NULL
);
101 status
= setjmp(exited
);
103 char *p
= failtest_malloc(1, "run-malloc.c", 1);
104 /* If we just segv, valgrind counts that as a failure.
105 * So kill ourselves creatively. */
107 kill(getpid(), SIGSEGV
);
108 fail("Expected child to crash!");
111 ok1(strstr(output
, "Killed by signal"));
112 ok1(strstr(output
, "--failpath=M\n"));
115 return exit_status();