diff options
author | Mattias Andrée <maandree@kth.se> | 2018-08-29 00:35:12 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-08-29 00:35:12 +0200 |
commit | ac15d5da43275997dc871fc1128c6d01c3c5a4cc (patch) | |
tree | 0ff763e83f1541610329a825079eb78a8b3a9b87 /test.h | |
parent | Warn about unran tests under valgrind (diff) | |
download | libsimple-ac15d5da43275997dc871fc1128c6d01c3c5a4cc.tar.gz libsimple-ac15d5da43275997dc871fc1128c6d01c3c5a4cc.tar.bz2 libsimple-ac15d5da43275997dc871fc1128c6d01c3c5a4cc.tar.xz |
Add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | test.h | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -20,6 +20,40 @@ return 0;\ } while (0) +#define assert_unreached()\ + assert(*&(volatile int *){0}) + +#define assert_exit(EXPR)\ + do {\ + volatile int old_stderr_ok__ = stderr_ok;\ + exit_ok = 1;\ + stderr_ok = 1;\ + stderr_n = 0;\ + if (setjmp(exit_jmp)) {\ + exit_ok = 0;\ + stderr_ok = old_stderr_ok__;\ + break;\ + }\ + assert(EXPR);\ + assert_unreached();\ + } while (0) + +#define assert_exit_ptr(EXPR)\ + do {\ + void *volatile ptr__;\ + assert_exit((ptr__ = (EXPR)));\ + } while (0) + +#define assert_stderr(FMT, ...)\ + do {\ + char buf__[1024];\ + int len__;\ + len__ = sprintf(buf__, FMT, __VA_ARGS__);\ + assert(len__ >= 0);\ + assert((size_t)len__ == stderr_n);\ + assert(!memcmp(buf__, stderr_buf, stderr_n));\ + } while (0); + struct allocinfo { void *real_beginning; @@ -32,6 +66,8 @@ struct allocinfo { }; +extern char *argv0; + extern size_t alloc_fail_in; extern int exit_real; extern int exit_ok; @@ -40,6 +76,7 @@ extern jmp_buf exit_jmp; extern char stderr_buf[8 << 10]; extern size_t stderr_n; extern int stderr_real; +extern int stderr_ok; size_t get_pagesize(void); |