Add log tests
This commit is contained in:
parent
526d1cee93
commit
36aeced2c3
3 changed files with 26 additions and 2 deletions
|
@ -36,7 +36,11 @@ export fn kmain(mb_info: *multiboot.multiboot_info_t, mb_magic: u32) void {
|
|||
var buffer = mem_profile.vaddr_end[0..mem_profile.fixed_alloc_size];
|
||||
var fixed_allocator = std.heap.FixedBufferAllocator.init(buffer);
|
||||
|
||||
serial.init(serial.DEFAULT_BAUDRATE, serial.Port.COM1) catch unreachable;
|
||||
serial.init(serial.DEFAULT_BAUDRATE, serial.Port.COM1) catch |e| {
|
||||
panic_root(@errorReturnTrace(), "Failed to initialise serial: {}", e);
|
||||
};
|
||||
if (build_options.rt_test)
|
||||
log.runtimeTests();
|
||||
|
||||
log.logInfo("Init arch " ++ @tagName(builtin.arch) ++ "\n");
|
||||
arch.init(&mem_profile, &fixed_allocator.allocator, build_options);
|
||||
|
|
|
@ -31,3 +31,19 @@ pub fn logWarning(comptime format: []const u8, args: ...) void {
|
|||
pub fn logError(comptime format: []const u8, args: ...) void {
|
||||
log(Level.ERROR, format, args);
|
||||
}
|
||||
|
||||
pub fn runtimeTests() void {
|
||||
inline for (@typeInfo(Level).Enum.fields) |field| {
|
||||
const level = @field(Level, field.name);
|
||||
log(level, "Test " ++ field.name ++ " level\n");
|
||||
log(level, "Test " ++ field.name ++ " level with args {}, {}\n", "a", u32(1));
|
||||
const logFn = switch (level) {
|
||||
.INFO => logInfo,
|
||||
.DEBUG => logDebug,
|
||||
.WARNING => logWarning,
|
||||
.ERROR => logError,
|
||||
};
|
||||
logFn("Test " ++ field.name ++ " function\n");
|
||||
logFn("Test " ++ field.name ++ " function with args {}, {}\n", "a", u32(1));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue