diff options
author | Marvin Borner | 2020-08-30 12:01:33 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-30 12:01:33 +0200 |
commit | ffa367193078ba32012494cfa7be50e6b3b18e2d (patch) | |
tree | 92b337d03c75f59739f39fffa789c57d69c1477d | |
parent | f73592503981eaacf1836f0d0049bed2f989212e (diff) |
Added some tests
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | kernel/test.c | 44 | ||||
-rwxr-xr-x | run | 4 |
3 files changed, 42 insertions, 9 deletions
@@ -1,6 +1,7 @@ # MIT License, Copyright (c) 2020 Marvin Borner all: compile clean +test: compile_test clean compile: @$(MAKE) clean --no-print-directory -C libc/ @@ -16,7 +17,7 @@ compile: @$(MAKE) --no-print-directory -C apps/ @echo "Compiled apps" -test: +compile_test: @$(MAKE) clean --no-print-directory -C libc/ @$(MAKE) libc --no-print-directory -C libc/ @echo "Compiled libc" diff --git a/kernel/test.c b/kernel/test.c index b328a2c..93fcbb1 100644 --- a/kernel/test.c +++ b/kernel/test.c @@ -2,25 +2,59 @@ #include <assert.h> #include <boot.h> +#include <conv.h> #include <cpu.h> #include <fs.h> #include <keyboard.h> #include <load.h> +#include <math.h> #include <mem.h> #include <mouse.h> #include <serial.h> +#include <str.h> #include <syscall.h> #include <timer.h> +#define a_mag 0x55 +#define b_mag 0x42 +#define check(exp) \ + if (!(exp)) { \ + printf("\x1B[31m[FAIL]\x1B[0m %s:%d: %s: Test '%s'\n", __FILE__, __LINE__, \ + __func__, #exp); \ + } else { \ + printf("\x1B[32m[PASS]\x1B[0m %s:%d: %s: Test '%s'\n", __FILE__, __LINE__, \ + __func__, #exp); \ + } + void test_all(struct vid_info *vid_info) { - heap_init(0x00f00000); - boot_passed = vid_info; - // Serial connection serial_install(); serial_print("\nConnected testing.\n"); - assert(vid_info && vid_info->mode && vid_info->vbe); + + // Boot passed + check(vid_info && vid_info->mode && vid_info->vbe); + + // Test malloc + heap_init(0x00f00000); + u32 *a = malloc(a_mag); + u32 *b = malloc(b_mag); + check(a[-1] == a_mag); + check(a[a_mag] == b_mag); + check(b[-1] == b_mag); + + // Test math + check(pow(2, 3) == 8); + check(pow(0, 3) == 0); + check(pow(0, 0) == 1); + + // Test conv + check(atoi("42") == 42); + check(strcmp(htoa(0x42), "42") == 0); + check(htoi("42") == 0x42); + check(strcmp(itoa(42), "42") == 0); + + boot_passed = vid_info; // Install drivers interrupts_install(); @@ -28,7 +62,5 @@ void test_all(struct vid_info *vid_info) keyboard_install(); mouse_install(); - ls_root(); - idle(); } @@ -116,10 +116,10 @@ make_build() { make_test() { if [ "$mode" = "test" ]; then qemu_with_flags -nographic -drive file=build/disk.img,format=raw,index=1,media=disk & - sleep 3 + sleep 2 killall -9 qemu-system-i386 else - qemu_with_flags -drive -serial stdio file=build/disk.img,format=raw,index=1,media=disk + qemu_with_flags -serial stdio -drive file=build/disk.img,format=raw,index=1,media=disk fi } |