X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Frfc822%2Ftest%2Frun-default-alloc-failure.c;fp=ccan%2Frfc822%2Ftest%2Frun-default-alloc-failure.c;h=c208154281106b18a2371dfcabd62bd49a21d384;hb=d3cbb4cbbc38c96c3a20a7e4e602be7327f25202;hp=7fc0393e2079eaae1507d8d18a915c304ca868e0;hpb=49ac066464e0127e4b9924b150bf47473ab733ae;p=ccan diff --git a/ccan/rfc822/test/run-default-alloc-failure.c b/ccan/rfc822/test/run-default-alloc-failure.c index 7fc0393e..c2081542 100644 --- a/ccan/rfc822/test/run-default-alloc-failure.c +++ b/ccan/rfc822/test/run-default-alloc-failure.c @@ -1,6 +1,7 @@ -#include +#include "config.h" #include #include +#include #include #include @@ -9,18 +10,32 @@ #include -#include +#include -#include "testdata.h" +static bool should_fail = false; -static void *failing_malloc(size_t size) +static void *mayfail_alloc(const void *ctx, size_t size) { - return NULL; + 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 + +#include "testdata.h" + static void abort_handler(int signum) { - ok(1, "Aborted"); + printf("Aborted"); exit(0); } @@ -34,23 +49,15 @@ int main(int argc, char *argv[]) }; int ret; - plan_tests(2); - ret = sigaction(SIGABRT, &sa, NULL); - ok(ret, "Couldn't install signal handler: %s", strerror(errno)); + assert(ret == 0); buf = assemble_msg(&test_msg_1, &len, 0); msg = rfc822_start(NULL, buf, len); - - talloc_set_allocator(failing_malloc, free, realloc); - + should_fail = true; (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(); }