summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-05-13 16:29:04 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-05-13 16:29:04 +0800
commit25fa7f331d6772f5b2cfee50c581db1c5aa71a1e (patch)
tree848108d0b9a8e6524dd66c804a53058a43303ac6
parent67cc7598da3a1cd02f06f9c0fd3f60ae2e7dc02f (diff)
downloadlume-25fa7f331d6772f5b2cfee50c581db1c5aa71a1e.tar.gz
lume-25fa7f331d6772f5b2cfee50c581db1c5aa71a1e.tar.xz
feat: replace early_puts with kprintf in selftest for improved logging
-rw-r--r--na/include/lume/selftest.h69
-rw-r--r--na/test/selftest.cc28
2 files changed, 34 insertions, 63 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");
}
diff --git a/na/test/selftest.cc b/na/test/selftest.cc
index a992ae2..96962e2 100644
--- a/na/test/selftest.cc
+++ b/na/test/selftest.cc
@@ -19,12 +19,20 @@ void selftest_vmm();
void selftest_fdt();
void selftest_vma();
void selftest_atomic();
+void selftest_trap();
+void selftest_sched();
+void selftest_klog();
+void selftest_random();
+void selftest_reloc();
+void selftest_waitqueue();
+void selftest_uaccess();
+void selftest_sys_mm();
void selftest_run_all()
{
- early_puts("\n========================================\n");
- early_puts(" Boot Self-Test Suite\n");
- early_puts("========================================\n");
+ kprintf("\n========================================\n");
+ kprintf(" Boot Self-Test Suite\n");
+ kprintf("========================================\n");
selftest_spinlock();
selftest_pmm();
@@ -34,8 +42,16 @@ void selftest_run_all()
selftest_vma();
selftest_atomic();
selftest_fdt();
+ selftest_trap();
+ selftest_sched();
+ selftest_klog();
+ selftest_random();
+ selftest_reloc();
+ selftest_waitqueue();
+ selftest_uaccess();
+ selftest_sys_mm();
- early_puts("========================================\n");
- early_puts(" All self-tests PASSED\n");
- early_puts("========================================\n\n");
+ kprintf("========================================\n");
+ kprintf(" All self-tests PASSED\n");
+ kprintf("========================================\n\n");
}