diff options
Diffstat (limited to 'na/include')
| -rw-r--r-- | na/include/lume/selftest.h | 69 |
1 files changed, 12 insertions, 57 deletions
diff --git a/na/include/lume/selftest.h b/na/include/lume/selftest.h index f5beffd..7040986 100644 --- a/na/include/lume/selftest.h +++ b/na/include/lume/selftest.h @@ -19,47 +19,14 @@ */ #include <lume/types.h> -#include <lume/panic.h> - -extern "C" void early_puts(const char* s); - -/* Print a decimal number (minimal, no printf available) */ -inline void st_print_num(uint64 n) -{ - if (n == 0) { early_puts("0"); return; } - char buf[21]; - int i = 20; - buf[i] = '\0'; - while (n > 0 && i > 0) { - buf[--i] = '0' + static_cast<char>(n % 10); - n /= 10; - } - early_puts(&buf[i]); -} - -inline void st_print_hex(uint64 n) -{ - early_puts("0x"); - char buf[17]; - int i = 16; - buf[i] = '\0'; - if (n == 0) { early_puts("0"); return; } - while (n > 0 && i > 0) { - int d = static_cast<int>(n & 0xF); - buf[--i] = (d < 10) ? ('0' + d) : ('a' + d - 10); - n >>= 4; - } - early_puts(&buf[i]); -} +#include <lume/klog.h> +#include <lume/kprintf.h> #define ST_ASSERT(cond) \ do { \ if (!(cond)) { \ - early_puts("[FAIL] "); \ - early_puts(__FILE__); \ - early_puts(":"); \ - st_print_num(__LINE__); \ - early_puts(": assertion failed: " #cond "\n"); \ + kprintf("[FAIL] %s:%d: assertion failed: %s\n", \ + __FILE__, __LINE__, #cond); \ kernel_panic("selftest failed", #cond); \ } \ } while (0) @@ -68,15 +35,9 @@ inline void st_print_hex(uint64 n) do { \ auto _a = (a); auto _b = (b); \ if (_a != _b) { \ - early_puts("[FAIL] "); \ - early_puts(__FILE__); \ - early_puts(":"); \ - st_print_num(__LINE__); \ - early_puts(": " #a " != " #b " ("); \ - st_print_hex((uint64)(uintptr)(_a)); \ - early_puts(" != "); \ - st_print_hex((uint64)(uintptr)(_b)); \ - early_puts(")\n"); \ + kprintf("[FAIL] %s:%d: %s != %s (0x%llx != 0x%llx)\n", \ + __FILE__, __LINE__, #a, #b, \ + (uint64)(uintptr)(_a), (uint64)(uintptr)(_b)); \ kernel_panic("selftest failed", #a " != " #b); \ } \ } while (0) @@ -85,13 +46,9 @@ inline void st_print_hex(uint64 n) do { \ auto _a = (a); auto _b = (b); \ if (_a == _b) { \ - early_puts("[FAIL] "); \ - early_puts(__FILE__); \ - early_puts(":"); \ - st_print_num(__LINE__); \ - early_puts(": " #a " == " #b " (both "); \ - st_print_hex((uint64)(uintptr)(_a)); \ - early_puts(")\n"); \ + kprintf("[FAIL] %s:%d: %s == %s (both 0x%llx)\n", \ + __FILE__, __LINE__, #a, #b, \ + (uint64)(uintptr)(_a)); \ kernel_panic("selftest failed", #a " == " #b); \ } \ } while (0) @@ -99,12 +56,10 @@ inline void st_print_hex(uint64 n) /* Announce a test suite beginning/end */ inline void st_begin(const char* name) { - early_puts("[test] "); - early_puts(name); - early_puts(" ... "); + kprintf("[test] %s ... ", name); } inline void st_pass() { - early_puts("PASS\n"); + kprintf("PASS\n"); } |
