Added primitive unit testing in tests/

This commit is contained in:
2016-03-27 12:07:53 -07:00
parent 6642358073
commit 25e3b5c517
6 changed files with 62 additions and 1 deletions

View File

@@ -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

11
tests/stdlib_atoi.c Normal file
View File

@@ -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;
}

1
tests/stdlib_atoi.deps Normal file
View File

@@ -0,0 +1 @@
stdlib

20
tests/stdlib_dtoa.c Normal file
View File

@@ -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;
}

1
tests/stdlib_dtoa.deps Normal file
View File

@@ -0,0 +1 @@
stdlib

20
tests/test.sh Normal file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
for file in *.c
do
filebase=$(basename $file | sed 's/\.c$//')
compile_def=$(cat <<EOF
function shunittest_compile_${filebase} {
set -e ; make ${filebase}.elf >&2 ; test -e ${filebase}.elf ; set +e
}
EOF
)
eval "$compile_def"
run_def=$(cat <<EOF
function shunittest_run_${filebase} {
set -e ; ./${filebase}.elf >&2 ; set +e
}
EOF
)
eval "$run_def"
done