The first ok() line was actually failing, because sigaction returns 0
on success, but because the program exit(0) out the abort handler,
that wasn't being seen.
So remove tap and just abort and assert our way through the test,
which I think is clearer.
We use macros to mug the talloc entry points, since talloc_set_allocator()
is not in mainline talloc.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-#include <ccan/tap/tap.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <signal.h>
#include <errno.h>
#include <ccan/rfc822/rfc822.h>
#include <ccan/rfc822/rfc822.h>
-#include <ccan/rfc822/rfc822.c>
+#include <ccan/talloc/talloc.h>
+static bool should_fail = false;
-static void *failing_malloc(size_t size)
+static void *mayfail_alloc(const void *ctx, size_t size)
+ if (should_fail)
+ return NULL;
+ return talloc_zero_size(ctx, size);
+/* Override various tallocation functions. */
+#undef talloc
+#undef talloc_zero
+#undef talloc_array
+#define talloc(ctx, type) mayfail_alloc((ctx), sizeof(type))
+#define talloc_zero(ctx, type) mayfail_alloc((ctx), sizeof(type))
+#define talloc_array(ctx, type, num) mayfail_alloc((ctx), sizeof(type)*(num))
+
+#include <ccan/rfc822/rfc822.c>
+
+#include "testdata.h"
+
static void abort_handler(int signum)
{
static void abort_handler(int signum)
{
ret = sigaction(SIGABRT, &sa, NULL);
ret = sigaction(SIGABRT, &sa, NULL);
- ok(ret, "Couldn't install signal handler: %s", strerror(errno));
buf = assemble_msg(&test_msg_1, &len, 0);
msg = rfc822_start(NULL, buf, len);
buf = assemble_msg(&test_msg_1, &len, 0);
msg = rfc822_start(NULL, buf, len);
-
- talloc_set_allocator(failing_malloc, free, realloc);
-
(void) rfc822_next_header(msg, NULL);
(void) rfc822_next_header(msg, NULL);
- ok(0, "Didn't get SIGABRT");
-
- rfc822_free(msg);
- talloc_free(buf);
-
- exit(exit_status());
+ /* We should never get here! */
+ abort();