diff options
Diffstat (limited to 'tests/scripts')
| -rwxr-xr-x | tests/scripts/gen-prog | 34 | ||||
| -rwxr-xr-x | tests/scripts/gen-simple | 31 | ||||
| -rw-r--r-- | tests/scripts/makefile | 42 |
3 files changed, 107 insertions, 0 deletions
diff --git a/tests/scripts/gen-prog b/tests/scripts/gen-prog new file mode 100755 index 0000000..e56ecc3 --- /dev/null +++ b/tests/scripts/gen-prog @@ -0,0 +1,34 @@ +#!/bin/sh + +NAME= +PROG= +while getopts "n:p:" opt; do + case "$opt" in + n) NAME="$OPTARG";; + p) PROG="$OPTARG";; + *) echo "unrecognised options -$OPTARG" >&2; exit 1; + esac +done + +shift $((OPTIND - 1)) + +# create all subdirectories +mkdir -p $(echo "${@}" | tr ' ' '\n' | sed "s|[^/]*$||;s|^|build/$NAME|" | uniq) + +for s in ${@} +do + obj="build/${NAME}/${s%.*}.o" + dep="${obj}.d" + + echo "${NAME}_OBJS += ${obj}" >> tests.mk + echo "${dep}:" >> tests.mk + echo "-include ${dep}" >> tests.mk + echo "${obj}: $NAME/${s}" >> tests.mk + echo " \$(COMPILE_TEST) -c $NAME/${s} -o ${obj}" >> tests.mk +done + +echo "build/${NAME}/$PROG: \$(${NAME}_OBJS) \$(COMMON)" >> tests.mk +echo " \$(COMPILE_TEST) \$(${NAME}_OBJS) \$(COMMON) \ + -o build/${NAME}/$PROG" >> tests.mk + +echo "include ${NAME}/check.mk" >> tests.mk diff --git a/tests/scripts/gen-simple b/tests/scripts/gen-simple new file mode 100755 index 0000000..ddec9a4 --- /dev/null +++ b/tests/scripts/gen-simple @@ -0,0 +1,31 @@ +#!/bin/sh + +NAME= +PROGS= +while getopts "n:p:" opt; do + case "$opt" in + n) NAME="$OPTARG";; + p) PROGS="$PROGS $OPTARG";; + *) echo "unrecognised option -$OPTARG" >&2; exit 1;; + esac +done + +if [ -z "$NAME" ]; then + echo "No name given for tests" >&2; exit 2; +fi + +if [ -z "$PROGS" ]; then + echo "No programs to add to initrd" >&2; exit 3; +fi + +echo "build/$NAME/initrd: build/$NAME/init \$(COMMON) \$(KMI)" >> tests.mk +echo " echo build/$NAME/init | \$(GEN_INITRD) build/$NAME/initrd" >> tests.mk +echo "reports/$NAME/log: build/$NAME/initrd" >> tests.mk +echo " mkdir -p reports/$NAME" >> tests.mk +echo " rm -f reports/$NAME/*" >> tests.mk +echo " timeout --foreground 30s \$(QEMU) \ + build/$NAME/initrd > reports/$NAME/log" >> tests.mk + +echo "TESTS += $NAME" >> tests.mk +echo ".PHONY: do-$NAME" >> tests.mk +echo "do-$NAME: reports/$NAME/log" >> tests.mk diff --git a/tests/scripts/makefile b/tests/scripts/makefile new file mode 100644 index 0000000..8ea802f --- /dev/null +++ b/tests/scripts/makefile @@ -0,0 +1,42 @@ +.PHONY: all +all: check + +ARCH ?= riscv64 +CROSS_COMPILE ?= $(ARCH)-unknown-elf- + +LLVM ?= 0 +COMPILER != [ "$(LLVM)" != "0" ] \ + && echo clang --target="$(CROSS_COMPILE)" \ + || echo $(CROSS_COMPILE)gcc + +OBFLAGS := -ffreestanding -nostdlib -std=c17 -g +INCLUDEFLAGS := -I ../include -I. +WARNFLAGS := -Wall -Wextra +COMPILE_TEST := $(COMPILER) $(WARNFLAGS) $(INCLUDEFLAGS) $(OBFLAGS) + +GEN_INITRD := cpio -H newc -o > +QEMU := qemu-system-$(ARCH) -machine virt -kernel ../kmi.bin \ + -serial stdio \ + -monitor none \ + -nographic \ + -no-reboot \ + -initrd + +KMI := ../kmi.bin +COMMON := build/printf.o + +build/printf.o: common/printf.c + $(COMPILE_TEST) -c common/printf.c -o build/printf.o + +include tests.mk + +.PHONY: check +check: $(TESTS) + @for d in reports/* ; do \ + if [ ! -f "$$d/OK" ]; then \ + echo "BROKEN: $$d" ; \ + elif [ "$$(tail -n1 $$d/OK)" != "OK" ]; then \ + echo "FAIL: $$d" ; \ + fi \ + done + @echo "Done." |
