diff options
Diffstat (limited to 'include/test_util.h')
-rw-r--r-- | include/test_util.h | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/include/test_util.h b/include/test_util.h index 7ee2fed284..6134897fa1 100644 --- a/include/test_util.h +++ b/include/test_util.h @@ -19,12 +19,14 @@ do { \ ccprintf("Running %s...", #n); \ cflush(); \ + before_test(); \ if (n() == EC_SUCCESS) { \ ccputs("OK\n"); \ } else { \ ccputs("Fail\n"); \ __test_error_count++; \ } \ + after_test(); \ } while (0) #define TEST_ASSERT(n) \ @@ -36,18 +38,27 @@ } \ } while (0) -#define __ABS(n) ((n) > 0 ? (n) : -(n)) - -#define TEST_ASSERT_ABS_LESS(n, t) \ +#define TEST_OPERATOR(a, b, op, fmt) \ do { \ - if (__ABS(n) >= t) { \ - ccprintf("%d: ASSERT_ABS_LESS failed: abs(%d) is " \ - "not less than %d\n", __LINE__, n, t); \ + if (!((a) op (b))) { \ + ccprintf("%d: ASSERSION failed: %s " #op " %s\n", \ + __LINE__, #a, #b); \ + ccprintf("\t\tEVAL: " #fmt " " #op " " #fmt "\n", \ + (a), (b)); \ task_dump_trace(); \ return EC_ERROR_UNKNOWN; \ } \ } while (0) +#define TEST_EQ(a, b, fmt) TEST_OPERATOR(a, b, ==, fmt) +#define TEST_NE(a, b, fmt) TEST_OPERATOR(a, b, !=, fmt) +#define TEST_BITS_SET(a, bits) TEST_OPERATOR(a & bits, bits, ==, %u) +#define TEST_BITS_CLEARED(a, bits) TEST_OPERATOR(a & bits, 0, ==, %u) + +#define __ABS(n) ((n) > 0 ? (n) : -(n)) + +#define TEST_ASSERT_ABS_LESS(n, t) TEST_OPERATOR(__ABS(n), t, <, %d) + #define TEST_ASSERT_ARRAY_EQ(s, d, n) \ do { \ int __i; \ @@ -107,6 +118,12 @@ void register_test_end_hook(void); */ void test_init(void); +/** Called before each test. Used for initialization. */ +void before_test(void); + +/** Called after each test. Used to clean up. */ +void after_test(void); + /* Test entry point */ void run_test(void); |