diff options
author | Marvin Borner | 2020-08-30 18:56:05 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-30 18:56:05 +0200 |
commit | 30932492e9f8a98e1f98461c9d28547f23d82e7e (patch) | |
tree | ffc7acb099a81e09d73df2e4a8290d4a8dc8bfc2 | |
parent | ffa367193078ba32012494cfa7be50e6b3b18e2d (diff) |
Even more tests
-rw-r--r-- | .github/workflows/build.yml | 4 | ||||
-rw-r--r-- | kernel/Makefile | 8 | ||||
-rw-r--r-- | kernel/inc/boot.h | 5 | ||||
-rw-r--r-- | kernel/inc/test.h | 42 | ||||
-rw-r--r-- | kernel/main.c | 5 | ||||
-rw-r--r-- | kernel/test.c | 52 |
6 files changed, 73 insertions, 43 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b37bd87..f608fdd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,5 +23,5 @@ jobs: run: sh run cross -y - name: Build run: sh run build -y - - name: Test install - run: sh run image -y + - name: Test everything + run: sh run test -y diff --git a/kernel/Makefile b/kernel/Makefile index da6a26c..bdf89ff 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,6 +1,7 @@ # MIT License, Copyright (c) 2020 Marvin Borner COBJS = main.o \ + test.o \ drivers/interrupts.o \ drivers/interrupts_asm.o \ drivers/keyboard.o \ @@ -43,10 +44,7 @@ compile: $(COBJS) @$(LD) -N -ekernel_main -Ttext 0x00050000 -o ../build/kernel.bin -L../build/ $+ -lk --oformat binary @$(CC) $(CFLAGS) -o ../build/debug.o -L../build/ $+ -lk -compile_test: CFLAGS += -Dtest -Wl,-etest_all -compile_test: $(COBJS:main.o=test.o) - @mkdir -p ../build/ - @$(LD) -N -etest_all -Ttext 0x00050000 -o ../build/kernel.bin -L../build/ $+ -lk --oformat binary - @$(CC) $(CFLAGS) -o ../build/debug.o -L../build/ $+ -lk +compile_test: CFLAGS += -Dtest +compile_test: compile .PHONY: test compile_test diff --git a/kernel/inc/boot.h b/kernel/inc/boot.h index c1d9288..98e964d 100644 --- a/kernel/inc/boot.h +++ b/kernel/inc/boot.h @@ -1,6 +1,9 @@ // MIT License, Copyright (c) 2020 Marvin Borner // This file specifies the structs passed by the bootloader +#ifndef BOOT_H +#define BOOT_H + #include <def.h> struct vid_info *boot_passed; @@ -8,3 +11,5 @@ struct vid_info { u32 mode; u32 *vbe; }; + +#endif diff --git a/kernel/inc/test.h b/kernel/inc/test.h new file mode 100644 index 0000000..6f2cdbb --- /dev/null +++ b/kernel/inc/test.h @@ -0,0 +1,42 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#ifndef TEST_H +#define TEST_H + +#include <boot.h> +#include <print.h> +#include <str.h> + +#define a_mag 0x55 +#define b_mag 0x42 + +#define check(exp) \ + if ((exp)) { \ + printf("\x1B[32m[PASS]\x1B[0m %s:%d: %s: Test '%s'\n", __FILE__, __LINE__, \ + __func__, #exp); \ + } else { \ + printf("\x1B[31m[FAIL]\x1B[0m %s:%d: %s: Test '%s'\n", __FILE__, __LINE__, \ + __func__, #exp); \ + } + +#define equals(first, second) \ + if ((first) == (second)) { \ + printf("\x1B[32m[PASS]\x1B[0m %s:%d: %s: Test equality '%s'(%d) == '%s'(%d)\n", \ + __FILE__, __LINE__, __func__, #first, (first), #second, (second)); \ + } else { \ + printf("\x1B[31m[FAIL]\x1B[0m %s:%d: %s: Test equality '%s'(%d) == '%s'(%d)\n", \ + __FILE__, __LINE__, __func__, #first, (first), #second, (second)); \ + } + +#define equals_str(first, second) \ + if (strcmp((first), (second)) == 0) { \ + printf("\x1B[32m[PASS]\x1B[0m %s:%d: %s: Test equality %s(%s) '%s'(%s)\n", \ + __FILE__, __LINE__, __func__, #first, (first), #second, (second)); \ + } else { \ + printf("\x1B[31m[FAIL]\x1B[0m %s:%d: %s: Test equality %s(%s) '%s'(%s)\n", \ + __FILE__, __LINE__, __func__, #first, (first), #second, (second)); \ + } + +void test_all(struct vid_info *vid_info); + +#endif diff --git a/kernel/main.c b/kernel/main.c index 7d87be5..93e8806 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -13,6 +13,11 @@ void kernel_main(struct vid_info *vid_info) { +#ifdef test +#include <test.h> + test_all(vid_info); +#endif + heap_init(0x00f00000); boot_passed = vid_info; diff --git a/kernel/test.c b/kernel/test.c index 93fcbb1..f1a49a6 100644 --- a/kernel/test.c +++ b/kernel/test.c @@ -1,30 +1,13 @@ // MIT License, Copyright (c) 2020 Marvin Borner -#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); \ - } +#include <test.h> void test_all(struct vid_info *vid_info) { @@ -39,28 +22,25 @@ void test_all(struct vid_info *vid_info) 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); + equals(a[-1], a_mag); + equals(a[a_mag], b_mag); + equals(b[-1], b_mag); // Test math - check(pow(2, 3) == 8); - check(pow(0, 3) == 0); - check(pow(0, 0) == 1); + equals(pow(2, 3), 8); + equals(pow(0, 3), 0); + equals(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(); - timer_install(); - keyboard_install(); - mouse_install(); + char buf[10] = { 0 }; + strcpy(buf, "42"); + equals(atoi(buf), 42); + equals_str(htoa(0x42), "42"); + equals(htoi(buf), 0x42); + equals_str(itoa(42), "42"); + equals_str(conv_base(42, buf, 0, 0), ""); + equals_str(conv_base(42, buf, 2, 0), "101010"); + /* equals_str(conv_base(424242, buf, 36, 0), "93ci"); // TODO: THIS */ idle(); } |