From 25e3b5c5173d3cf746956d65facef30742a869fa Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sun, 27 Mar 2016 12:07:53 -0700 Subject: [PATCH] Added primitive unit testing in tests/ --- Makefile | 10 +++++++++- tests/stdlib_atoi.c | 11 +++++++++++ tests/stdlib_atoi.deps | 1 + tests/stdlib_dtoa.c | 20 ++++++++++++++++++++ tests/stdlib_dtoa.deps | 1 + tests/test.sh | 20 ++++++++++++++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/stdlib_atoi.c create mode 100644 tests/stdlib_atoi.deps create mode 100644 tests/stdlib_dtoa.c create mode 100644 tests/stdlib_dtoa.deps create mode 100644 tests/test.sh diff --git a/Makefile b/Makefile index f1792a4..2608ebc 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +ifeq ($(TEST_FORMAT),) + TEST_FORMAT:=tunit +endif + all: boot.img kernel.bin src/%.o: src/%.c @@ -23,9 +27,13 @@ boot.img: boot.bin kernel.bin dd if=boot.tmp of=boot.img conv=notrunc rm -f boot.tmp -test: boot.img +run: boot.img bochs -f bochsrc -q +.PHONY: test +test: + cd tests && make clean && shunit.sh -f $(TEST_FORMAT) -t test.sh + .PHONY: clean clean: rm -f boot.bin asm/*o src/*o diff --git a/tests/stdlib_atoi.c b/tests/stdlib_atoi.c new file mode 100644 index 0000000..0aecf16 --- /dev/null +++ b/tests/stdlib_atoi.c @@ -0,0 +1,11 @@ +#include "stdlib.h" + +#define NULL 0x00 + +int main(void) +{ + if ( atoi("1234\0") != 1234 ) return 1; + if ( atoi("65536\0") != 65536 ) return 2; + if ( atoi("-32767\0") != -32767 ) return 3; + return 0; +} diff --git a/tests/stdlib_atoi.deps b/tests/stdlib_atoi.deps new file mode 100644 index 0000000..3b89510 --- /dev/null +++ b/tests/stdlib_atoi.deps @@ -0,0 +1 @@ +stdlib diff --git a/tests/stdlib_dtoa.c b/tests/stdlib_dtoa.c new file mode 100644 index 0000000..1dc8ffe --- /dev/null +++ b/tests/stdlib_dtoa.c @@ -0,0 +1,20 @@ +#include "stdlib.h" + +#define NULL 0x00 + +int main(void) +{ + if ( dtoa(0) != '0' ) return 1; + if ( dtoa(1) != '1' ) return 2; + if ( dtoa(2) != '2' ) return 3; + if ( dtoa(3) != '3' ) return 4; + if ( dtoa(4) != '4' ) return 5; + if ( dtoa(5) != '5' ) return 6; + if ( dtoa(6) != '6' ) return 7; + if ( dtoa(7) != '7' ) return 8; + if ( dtoa(8) != '8' ) return 9; + if ( dtoa(9) != '9' ) return 10; + if ( dtoa(11) != NULL ) return 11; + if ( dtoa(-1) != NULL ) return 12; + return 0; +} diff --git a/tests/stdlib_dtoa.deps b/tests/stdlib_dtoa.deps new file mode 100644 index 0000000..3b89510 --- /dev/null +++ b/tests/stdlib_dtoa.deps @@ -0,0 +1 @@ +stdlib diff --git a/tests/test.sh b/tests/test.sh new file mode 100644 index 0000000..aa03562 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +for file in *.c +do + filebase=$(basename $file | sed 's/\.c$//') + compile_def=$(cat <&2 ; test -e ${filebase}.elf ; set +e +} +EOF +) + eval "$compile_def" + run_def=$(cat <&2 ; set +e +} +EOF +) + eval "$run_def" +done