Added primitive unit testing in tests/
This commit is contained in:
10
Makefile
10
Makefile
@@ -1,3 +1,7 @@
|
|||||||
|
ifeq ($(TEST_FORMAT),)
|
||||||
|
TEST_FORMAT:=tunit
|
||||||
|
endif
|
||||||
|
|
||||||
all: boot.img kernel.bin
|
all: boot.img kernel.bin
|
||||||
|
|
||||||
src/%.o: src/%.c
|
src/%.o: src/%.c
|
||||||
@@ -23,9 +27,13 @@ boot.img: boot.bin kernel.bin
|
|||||||
dd if=boot.tmp of=boot.img conv=notrunc
|
dd if=boot.tmp of=boot.img conv=notrunc
|
||||||
rm -f boot.tmp
|
rm -f boot.tmp
|
||||||
|
|
||||||
test: boot.img
|
run: boot.img
|
||||||
bochs -f bochsrc -q
|
bochs -f bochsrc -q
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
cd tests && make clean && shunit.sh -f $(TEST_FORMAT) -t test.sh
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f boot.bin asm/*o src/*o
|
rm -f boot.bin asm/*o src/*o
|
||||||
|
|||||||
11
tests/stdlib_atoi.c
Normal file
11
tests/stdlib_atoi.c
Normal 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
1
tests/stdlib_atoi.deps
Normal file
@@ -0,0 +1 @@
|
|||||||
|
stdlib
|
||||||
20
tests/stdlib_dtoa.c
Normal file
20
tests/stdlib_dtoa.c
Normal 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
1
tests/stdlib_dtoa.deps
Normal file
@@ -0,0 +1 @@
|
|||||||
|
stdlib
|
||||||
20
tests/test.sh
Normal file
20
tests/test.sh
Normal 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
|
||||||
Reference in New Issue
Block a user