6 #include <ccan/tap/tap.h>
8 /* We don't actually want it to exit... */
10 #define exit(status) longjmp(exited, (status) + 1)
12 #define printf saved_printf
13 static int saved_printf(const char *fmt, ...);
15 #define fprintf saved_fprintf
16 static int saved_fprintf(FILE *ignored, const char *fmt, ...);
18 #define vfprintf saved_vfprintf
19 static int saved_vfprintf(FILE *ignored, const char *fmt, va_list ap);
21 /* Hack to avoid a memory leak which valgrind complains about. */
22 #define realloc set_realloc
23 static void *set_realloc(void *ptr, size_t size);
26 static void set_free(void *ptr);
28 /* Include the C files directly. */
29 #include <ccan/failtest/failtest.c>
35 static void *set_realloc(void *ptr, size_t size)
37 return buffer = realloc(ptr, size);
40 static void set_free(void *ptr)
47 static char *output = NULL;
49 static int saved_vprintf(const char *fmt, va_list ap)
56 ret = vsnprintf(NULL, 0, fmt, ap2);
62 output = realloc(output, len + ret + 1);
63 return vsprintf(output + len, fmt, ap);
66 static int saved_vfprintf(FILE *ignored, const char *fmt, va_list ap)
68 return saved_vprintf(fmt, ap);
71 static int saved_printf(const char *fmt, ...)
77 ret = saved_vprintf(fmt, ap);
82 static int saved_fprintf(FILE *ignored, const char *fmt, ...)
88 ret = saved_vprintf(fmt, ap);
99 status = setjmp(exited);
101 char *p = failtest_malloc(1, "run-malloc.c", 1);
102 /* If we just segv, valgrind counts that as a failure.
103 * So kill ourselves creatively. */
105 kill(getpid(), SIGSEGV);
106 fail("Expected child to crash!");
109 ok1(strstr(output, "Killed by signal"));
110 ok1(strstr(output, "--failpath=M\n"));
113 return exit_status();