diff options
author | Marvin Borner | 2020-08-30 09:59:03 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-30 09:59:03 +0200 |
commit | f73592503981eaacf1836f0d0049bed2f989212e (patch) | |
tree | b10ec58e932a94022c36fe6e1de2b7bbc20fc838 | |
parent | e15051fd2d1d65af315ac4004256d5bc56a6dc67 (diff) |
Added kernel testing suit
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | kernel/Makefile | 9 | ||||
-rw-r--r-- | kernel/features/event.c | 8 | ||||
-rw-r--r-- | kernel/test.c | 34 | ||||
-rwxr-xr-x | run | 20 |
5 files changed, 76 insertions, 9 deletions
@@ -16,5 +16,19 @@ compile: @$(MAKE) --no-print-directory -C apps/ @echo "Compiled apps" +test: + @$(MAKE) clean --no-print-directory -C libc/ + @$(MAKE) libc --no-print-directory -C libc/ + @echo "Compiled libc" + @$(MAKE) clean --no-print-directory -C libc/ + @$(MAKE) libk --no-print-directory -C libc/ + @echo "Compiled libk" + @$(MAKE) --no-print-directory -C libgui/ + @echo "Compiled libgui" + @$(MAKE) test --no-print-directory -C kernel/ + @echo "Compiled kernel" + @$(MAKE) --no-print-directory -C apps/ + @echo "Compiled apps" + clean: @find kernel/ apps/ libc/ \( -name "*.o" -or -name "*.a" -or -name "*.elf" -or -name "*.bin" \) -type f -delete diff --git a/kernel/Makefile b/kernel/Makefile index 07f985a..da6a26c 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -26,6 +26,7 @@ CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builti ASFLAGS = -f elf32 all: compile bootloader +test: compile_test bootloader %.o: %.c @$(CC) -c $(CFLAGS) $< -o $@ @@ -41,3 +42,11 @@ compile: $(COBJS) @mkdir -p ../build/ @$(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 + +.PHONY: test compile_test diff --git a/kernel/features/event.c b/kernel/features/event.c index 5436ef5..71c0ad9 100644 --- a/kernel/features/event.c +++ b/kernel/features/event.c @@ -29,14 +29,14 @@ void event_unregister(enum message_type id, struct proc *proc) { assert(id < sizeof(event_table) / sizeof(*event_table)); - struct event_descriptor *desc = malloc(sizeof(*desc)); - desc->id = id; - desc->proc = proc; + struct event_descriptor desc; + desc.id = id; + desc.proc = proc; struct node *iterator = event_table[id]->head; do { struct event_descriptor *desc_comp = iterator->data; - if (desc_comp->id == desc->id && desc_comp->proc == desc->proc) + if (desc_comp->id == desc.id && desc_comp->proc == desc.proc) list_remove(event_table[id], iterator); } while ((iterator = iterator->next) != NULL); } diff --git a/kernel/test.c b/kernel/test.c new file mode 100644 index 0000000..b328a2c --- /dev/null +++ b/kernel/test.c @@ -0,0 +1,34 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include <assert.h> +#include <boot.h> +#include <cpu.h> +#include <fs.h> +#include <keyboard.h> +#include <load.h> +#include <mem.h> +#include <mouse.h> +#include <serial.h> +#include <syscall.h> +#include <timer.h> + +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); + + // Install drivers + interrupts_install(); + timer_install(); + keyboard_install(); + mouse_install(); + + ls_root(); + + idle(); +} @@ -10,7 +10,7 @@ no_ask="${2}" network="rtl8139" qemu_with_flags() { - SDL_VIDEO_X11_DGAMOUSE=0 qemu-system-i386 -no-reboot -vga std -serial stdio -rtc base=localtime -m 256M -net nic,model=${network},macaddr=42:42:42:42:42:42 -net user "$@" + SDL_VIDEO_X11_DGAMOUSE=0 qemu-system-i386 -no-reboot -vga std -rtc base=localtime -m 256M -net nic,model=${network},macaddr=42:42:42:42:42:42 -net user "$@" } make_cross() { @@ -89,7 +89,11 @@ make_build() { rm -rf build/* printf "\nBuilding...\n" - make + if [ "$mode" = "test" ]; then + make test + else + make + fi # Create disk image dd if=/dev/zero of=build/disk.img bs=1k count=32k status=none @@ -110,7 +114,13 @@ make_build() { } make_test() { - qemu_with_flags -drive file=build/disk.img,format=raw,index=1,media=disk + if [ "$mode" = "test" ]; then + qemu_with_flags -nographic -drive file=build/disk.img,format=raw,index=1,media=disk & + sleep 3 + killall -9 qemu-system-i386 + else + qemu_with_flags -drive -serial stdio file=build/disk.img,format=raw,index=1,media=disk + fi } make_debug() { @@ -191,12 +201,12 @@ else printf "cross\t\tBuilds the cross compiler\n" printf "clean\t\tRemoves the compiled files\n" printf "build\t\tBuilds the whole project (cross+clean)\n" - printf "test\t\tEmulates Melvix with QEMU (cross+clean+build)\n" + printf "test\t\tRuns the Melvix unit tests with QEMU (cross+clean+build)\n" printf "debug\t\tEmulates Melvix with QEMU and debug options (cross+clean+build)\n" printf "again\t\tOpens QEMU again using the previous build\n" printf "disasm\t\tDisassembles the main kernel binary\n" printf "sync\t\tSyncs the 'tags' and 'compile_commands.json' file\n" printf "disk\t\tPrepares the userspace disk (e.g. fonts)\n" + printf "nothing\t\tWhen no option is set, Melvix gets built and emulated using QEMU (cross+clean+build)\n" printf "*\t\tAnything else prints this help\n\n" - echo "The default option is 'test'" fi |