diff --git a/include/cryb/test.h b/include/cryb/test.h index b784014..1b92eb5 100644 --- a/include/cryb/test.h +++ b/include/cryb/test.h @@ -82,6 +82,8 @@ void t_fcloseall(void); /* * Various utilities */ +int t_is_null(const void *); +int t_is_not_null(const void *); int t_compare_mem(const void *, const void *, size_t); int t_compare_str(const char *, const char *); #define t_compare_num(n, t) int t_compare_##n(t, t); diff --git a/lib/test/t_main.c b/lib/test/t_main.c index 9c501b0..ba293fe 100644 --- a/lib/test/t_main.c +++ b/lib/test/t_main.c @@ -170,6 +170,16 @@ t_run_test(struct t_test *t, int n) ret = 0; if ((signo = setjmp(sigjmp)) == 0) ret = (*t->func)(&desc, t->arg); + if (t_malloc_fail != 0) { + t_verbose("WARNING: test case left t_malloc_fail = %d\n", + t_malloc_fail); + t_malloc_fail = 0; + } + if (t_malloc_fail_after != 0) { + t_verbose("WARNING: test case left t_malloc_fail_after = %d\n", + t_malloc_fail_after); + t_malloc_fail_after = 0; + } if (ret > 0) printf("ok %d - %s\n", n, desc ? desc : "no description"); else if (ret < 0) diff --git a/lib/test/t_malloc.c b/lib/test/t_malloc.c index 50fd06b..d4f75c8 100644 --- a/lib/test/t_malloc.c +++ b/lib/test/t_malloc.c @@ -126,7 +126,7 @@ static struct bucket buckets[BUCKET_MAX_SHIFT + 1]; /* mapping metadata */ static struct mapping *mappings; -unsigned long nmapalloc, nmapfree; +static unsigned long nmapalloc, nmapfree; /* if non-zero, all allocations fail */ int t_malloc_fail; diff --git a/lib/test/t_util.c b/lib/test/t_util.c index ed4260b..025cdeb 100644 --- a/lib/test/t_util.c +++ b/lib/test/t_util.c @@ -40,6 +40,34 @@ #include +/* + * Print a verbose message if a pointer is not null. + */ +int +t_is_null(const void *ptr) +{ + + if (ptr != NULL) { + t_verbose("expected null pointer, got non-null pointer\n"); + return (0); + } + return (1); +} + +/* + * Print a verbose message if a pointer is null. + */ +int +t_is_not_null(const void *ptr) +{ + + if (ptr == NULL) { + t_verbose("expected non-null pointer, got null pointer\n"); + return (0); + } + return (1); +} + /* * Compare two buffers, and print a verbose message if they differ. */