From 0a1d3a92f119071bb7deb6551bc9e696355ba4bd Mon Sep 17 00:00:00 2001 From: FlareCoding Date: Mon, 9 Sep 2024 23:51:09 -0400 Subject: [PATCH] added assertion macros and a way to parse unit test results and determine failure/success --- Makefile | 35 ++++++++-- efi/OVMF_VARS.fd | Bin 540672 -> 540672 bytes kernel/src/entry/tests/kernel_unit_tests.h | 8 ++- .../entry/tests/memory_allocation.test.cpp | 10 +-- parse_unit_test_results.sh | 63 ++++++++++++++++++ 5 files changed, 101 insertions(+), 15 deletions(-) create mode 100755 parse_unit_test_results.sh diff --git a/Makefile b/Makefile index a08d723..ddc220d 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,12 @@ else QEMU_FLAGS += -cpu qemu64 endif +# Unit test execution duration timeout (all tests) +UNIT_TESTS_RUN_TIMEOUT := 1m + +# Name of the unit test result output file +UNIT_TESTS_LOG_FILENAME := dev_os_output.log + # Targets .PHONY: all bootloader kernel buildimg run run-headless clean @@ -65,7 +71,7 @@ buildimg: $(DISK_IMG) $(DISK_IMG): bootloader kernel @mkdir -p $(@D) - dd if=/dev/zero of=$(DISK_IMG) bs=512 count=93750 + dd if=/dev/zero of=$(DISK_IMG) bs=512 count=93750 > /dev/null 2>&1 mkfs -t vfat $(DISK_IMG) mmd -i $(DISK_IMG) ::/EFI mmd -i $(DISK_IMG) ::/EFI/BOOT @@ -94,13 +100,32 @@ run-debug-headless: $(DISK_IMG) connect-gdb: gdb -ex "source ./gdb_setup.gdb" -ex "target remote localhost:4554" -ex "add-symbol-file kernel/bin/kernel.elf" -ex "b _kentry" -# Run tests target -run-unit-tests: $(DISK_IMG) - $(QEMU_EMULATOR) $(QEMU_FLAGS) -nographic | tee dev_os_output.log +# Builds and runs a clean image of the OS with appropriate unit test flags +execute-unit-tests: + @echo "[LOG] Preparing a clean build environment" + @$(MAKE) clean > /dev/null + + @echo "[LOG] Building the kernel with unit tests" + @$(MAKE) KRUN_UNIT_TESTS=1 > /dev/null + + @echo "[LOG] Launching the StelluxOS image in a VM" + @timeout $(UNIT_TESTS_RUN_TIMEOUT) setsid bash -c '$(QEMU_EMULATOR) $(QEMU_FLAGS) -nographic | tee $(UNIT_TESTS_LOG_FILENAME)' + + @echo "" + @echo "[LOG] Parsing unit test results" + + # Grouping commands in a single shell to preserve RESULT and handle cleanup + @bash -c '\ + bash parse_unit_test_results.sh; \ + RESULT=$$?; \ + echo "[LOG] Cleaning up"; \ + $(MAKE) clean > /dev/null; \ + exit $$RESULT \ + ' # Clean target clean: rm -rf $(BIN_DIR) $(MAKE) -C $(BOOTLOADER_DIR) clean $(MAKE) -C $(KERNEL_DIR) clean - rm -rf com1.serial com2.serial dev_os_output.log + rm -rf com1.serial com2.serial $(UNIT_TESTS_LOG_FILENAME) diff --git a/efi/OVMF_VARS.fd b/efi/OVMF_VARS.fd index 60d74578e23e60817ab83572171813646739f445..8bb5775b2053495592c03108beaa14a7e6498eae 100644 GIT binary patch delta 458 zcmZo@P;3CA7RK!f?2J=bwohSUisRZWb;*f^d6_7~=KIrBnI{WeVcG2PxP+T|Iflpz z43U)>BC9Y&R%3{)!4O%CA+iobWIcw+1`Lsn7$Tc6L^flHY{3xOiXpNMLu5OK$PNsV tofsm!Fhq7EiELN+$p{SkJ;*`_*qI(|Zxdi?6JTu