diff options
author | Jason Evans <jasone@canonware.com> | 2013-12-09 04:52:21 (GMT) |
---|---|---|
committer | Jason Evans <jasone@canonware.com> | 2013-12-09 04:52:21 (GMT) |
commit | 2a83ed0284e92c7ba4bd4efe9df149ac724b2f26 (patch) | |
tree | 915b5dbaa91c4a8dd3fdffedb98ce8abb48535b6 /test/src | |
parent | 9f35a71a81adcfd6c0ea6461ecd2b84ac384e34f (diff) | |
download | jemalloc-2a83ed0284e92c7ba4bd4efe9df149ac724b2f26.zip jemalloc-2a83ed0284e92c7ba4bd4efe9df149ac724b2f26.tar.gz jemalloc-2a83ed0284e92c7ba4bd4efe9df149ac724b2f26.tar.bz2 |
Refactor tests.
Refactor tests to use explicit testing assertions, rather than diff'ing
test output. This makes the test code a bit shorter, more explicitly
encodes testing intent, and makes test failure diagnosis more
straightforward.
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/test.c | 80 |
1 files changed, 74 insertions, 6 deletions
diff --git a/test/src/test.c b/test/src/test.c index 1bc34b4..eb1f5ef 100644 --- a/test/src/test.c +++ b/test/src/test.c @@ -1,28 +1,96 @@ #include "test/jemalloc_test.h" -#define JEMALLOC_TEST_EXIT_FAIL 1 -#define JEMALLOC_TEST_EXIT_SKIP 2 +static unsigned test_count = 0; +static test_status_t test_counts[test_status_count] = {0, 0, 0}; +static test_status_t test_status = test_status_pass; +static const char * test_name = ""; JEMALLOC_ATTR(format(printf, 1, 2)) void -test_fail(const char *format, ...) +test_skip(const char *format, ...) { va_list ap; va_start(ap, format); malloc_vcprintf(NULL, NULL, format, ap); va_end(ap); - exit(JEMALLOC_TEST_EXIT_FAIL); + test_status = test_status_skip; } JEMALLOC_ATTR(format(printf, 1, 2)) void -test_skip(const char *format, ...) +test_fail(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + malloc_vcprintf(NULL, NULL, format, ap); + va_end(ap); + test_status = test_status_fail; +} + +static const char * +test_status_string(test_status_t test_status) +{ + + switch (test_status) { + case test_status_pass: return "pass"; + case test_status_skip: return "skip"; + case test_status_fail: return "fail"; + default: not_reached(); + } +} + +void +p_test_init(const char *name) +{ + + test_count++; + test_status = test_status_pass; + test_name = name; +} + +void +p_test_fini(void) +{ + + test_counts[test_status]++; + malloc_printf("%s: %s\n", test_name, test_status_string(test_status)); +} + +test_status_t +p_test(test_t* t, ...) +{ + test_status_t ret = test_status_pass; + va_list ap; + + va_start(ap, t); + for (; t != NULL; t = va_arg(ap, test_t*)) { + t(); + if (test_status > ret) + ret = test_status; + } + va_end(ap); + + malloc_printf("tests: %u, pass: %u, skip: %u, fail: %u\n", + test_count, + test_counts[test_status_pass], + test_counts[test_status_skip], + test_counts[test_status_fail]); + + return (ret); +} + +void +p_test_fail(const char *format, ...) { va_list ap; va_start(ap, format); malloc_vcprintf(NULL, NULL, format, ap); + format = va_arg(ap, const char *); + malloc_vcprintf(NULL, NULL, format, ap); va_end(ap); - exit(JEMALLOC_TEST_EXIT_SKIP); + malloc_printf("\n"); + test_status = test_status_fail; } |