mirror of
https://github.com/cryb-to/cryb-to.git
synced 2025-01-02 18:01:11 +00:00
When running a test, make sure it didn't leave allocation failure enabled.
Add predicates for null and non-null pointers. Staticize some internal allocator state.
This commit is contained in:
parent
4fa82f7c7b
commit
0a9f2c21fe
4 changed files with 41 additions and 1 deletions
|
@ -82,6 +82,8 @@ void t_fcloseall(void);
|
||||||
/*
|
/*
|
||||||
* Various utilities
|
* 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_mem(const void *, const void *, size_t);
|
||||||
int t_compare_str(const char *, const char *);
|
int t_compare_str(const char *, const char *);
|
||||||
#define t_compare_num(n, t) int t_compare_##n(t, t);
|
#define t_compare_num(n, t) int t_compare_##n(t, t);
|
||||||
|
|
|
@ -170,6 +170,16 @@ t_run_test(struct t_test *t, int n)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if ((signo = setjmp(sigjmp)) == 0)
|
if ((signo = setjmp(sigjmp)) == 0)
|
||||||
ret = (*t->func)(&desc, t->arg);
|
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)
|
if (ret > 0)
|
||||||
printf("ok %d - %s\n", n, desc ? desc : "no description");
|
printf("ok %d - %s\n", n, desc ? desc : "no description");
|
||||||
else if (ret < 0)
|
else if (ret < 0)
|
||||||
|
|
|
@ -126,7 +126,7 @@ static struct bucket buckets[BUCKET_MAX_SHIFT + 1];
|
||||||
|
|
||||||
/* mapping metadata */
|
/* mapping metadata */
|
||||||
static struct mapping *mappings;
|
static struct mapping *mappings;
|
||||||
unsigned long nmapalloc, nmapfree;
|
static unsigned long nmapalloc, nmapfree;
|
||||||
|
|
||||||
/* if non-zero, all allocations fail */
|
/* if non-zero, all allocations fail */
|
||||||
int t_malloc_fail;
|
int t_malloc_fail;
|
||||||
|
|
|
@ -40,6 +40,34 @@
|
||||||
|
|
||||||
#include <cryb/test.h>
|
#include <cryb/test.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
* Compare two buffers, and print a verbose message if they differ.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue