From 82c77b22605d691884be4c4e1e6bae8d66598d02 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 10 Aug 2025 21:37:15 +0300 Subject: make tests actually useful + Apparently quite a few components are currently broken, didn't even remember --- scripts/gen-deps | 54 +++++++++++++++++---------------- scripts/gen-report | 18 +++++++++++ scripts/gen-rv64-fw | 23 ++++++++++++++ scripts/makefile | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/makefile.tests | 6 ++++ 5 files changed, 156 insertions(+), 26 deletions(-) create mode 100755 scripts/gen-report create mode 100755 scripts/gen-rv64-fw create mode 100644 scripts/makefile create mode 100644 scripts/makefile.tests (limited to 'scripts') diff --git a/scripts/gen-deps b/scripts/gen-deps index 0feed7e..1238a94 100755 --- a/scripts/gen-deps +++ b/scripts/gen-deps @@ -1,35 +1,37 @@ #!/bin/sh -gencommon () { - lint="build/${s%.*}${1}.l" - dep="build/${s%.*}${1}.d" - obj="build/${s%.*}${1}" +PREFIX= +COMPILE=COMPILE +LINT=LINT +BUILD=build - echo "${dep}:" >> deps.mk - echo "include ${dep}" >> deps.mk - echo "${obj}: ${s}" >> deps.mk -} - -genobjs () { - gencommon ".o" - echo "${obj}: ${s}" >> deps.mk - echo " \$(COMPILE) -c $< -o \$@" >> deps.mk - - echo "${lint}: ${s}" >> deps.mk - echo " \$(LINT) -c ${s} -o /dev/null" >> deps.mk -} +while getopts "p:c:b:l:" opt; do + case "$opt" in + p) PREFIX="$OPTARG"_;; + c) COMPILE="$OPTARG";; + l) LINT="$OPTARG";; + b) BUILD=build/"$OPTARG";; + *) echo "unrecognised option -$OPTARG" >&2; exit 1;; + esac +done -case "${1}" in - --sources) - func=genobjs - ;; -esac +shift $((OPTIND - 1)) # create all subdirectories -mkdir -p $(echo "${2}" | xargs dirname | uniq | sed 's|^|build/|g') +mkdir -p $(echo "${@}" | tr ' ' '\n' | sed "s|[^/]*$||;s|^|${BUILD}/|" | uniq) -for s in ${2} +for s in ${@} do - ${func} ${suffix} - echo ${obj} + obj="${BUILD}/${s%.*}.o" + lint="${obj}.l" + dep="${obj}.d" + + echo "${PREFIX}OBJS += ${obj}" >> deps.mk + echo "${PREFIX}LINTS += ${lint}" >> deps.mk + echo "${dep}:" >> deps.mk + echo "-include ${dep}" >> deps.mk + echo "${obj}: ${s}" >> deps.mk + echo " \$(${COMPILE}) -c ${s} -o ${obj}" >> deps.mk + echo "${lint}: ${s}" >> deps.mk + echo " \$(${LINT}) -c ${s} -o /dev/null" >> deps.mk done diff --git a/scripts/gen-report b/scripts/gen-report new file mode 100755 index 0000000..38e4a47 --- /dev/null +++ b/scripts/gen-report @@ -0,0 +1,18 @@ +#!/bin/sh + +BUILD=build + +while getopts "d:" opt; do + case "$opt" in + d) BUILD="$OPTARG";; + *) echo "unregonised option -$OPTARG" >&2; exit 1;; + esac +done + +shift $((OPTIND - 1)) + +for p in "$@"; do + mkdir -p "reports/${p}" + timeout --foreground 30s valgrind -q --error-exitcode=1 \ + "./${BUILD}/${p}" > "reports/${p}/log" +done diff --git a/scripts/gen-rv64-fw b/scripts/gen-rv64-fw new file mode 100755 index 0000000..831071d --- /dev/null +++ b/scripts/gen-rv64-fw @@ -0,0 +1,23 @@ +#!/bin/sh + +BUILD=build +NAME= + +while getopts "d:o:" opt; do + case "$opt" in + d) BUILD="$OPTARG";; + o) NAME="$OPTARG";; + *) echo "unrecognised option -$OPTARG" >&2; exit 1; + esac +done + +shift $((OPTIND - 1)) + +# might try to figure out how to support llvm as well in tests, but good enough +# for now +riscv64-unknown-elf-gcc -O2 -Wall -Wextra -ffreestanding -nostdlib \ + -march=rv64i -mabi=lp64 -fno-delete-null-pointer-checks \ + -o "${BUILD}/${NAME}.elf" "${@}" + +riscv64-unknown-elf-objcopy -Obinary "${BUILD}/${NAME}.elf" "${BUILD}/${NAME}.bin" +xxd -i "${BUILD}/${NAME}.bin" > "${BUILD}/${NAME}" diff --git a/scripts/makefile b/scripts/makefile new file mode 100644 index 0000000..dc094fa --- /dev/null +++ b/scripts/makefile @@ -0,0 +1,81 @@ +# this could be done better +RELEASE ?= 0 +OPTFLAGS != [ "$(RELEASE)" != "0" ] \ + && echo "-O2 -flto=auto" \ + || echo "-O0" + +DEBUG ?= 1 +DEBUGFLAGS != [ "$(DEBUG)" != "0" ] \ + && echo "-DDEBUG=1" \ + || echo "-DNDEBUG=1" + +ASSERT ?= 1 +ASSERTFLAGS != [ "$(ASSERT)" != "0" ] \ + && echo "-DASSERT=1" \ + || echo + +DEP_FLAGS = -MT $@ -MMD -MP -MF $@.d +LINT_FLAGS := -fsyntax-only +PREPROCESS := -E + +LLVM ?= 0 +BUILD := build + +all: libgran.a + +# default values, overwrite if/when needed +CROSS_COMPILE := + +OBJCOPY != [ "$(LLVM)" != "0" ] \ + && echo llvm-objcopy \ + || echo $(CROSS_COMPILE)objcopy + +COMPILER != [ -n "$(CROSS_COMPILE)" ] \ + && { \ + [ "$(LLVM)" != "0" ] \ + && echo clang --target="$(CROSS_COMPILE)" \ + || echo $(CROSS_COMPILE)gcc \ + ; \ + } \ + || echo $(CC) + + +OBFLAGS := -g +WARNFLAGS := -Wall -Wextra + +COMPILE_FLAGS := $(CFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(OBFLAGS) $(ASSERTFLAGS) \ + $(DEBUGFLAGS) + +INCLUDE_FLAGS := -I include -I deps/conts/include + +LINT = $(COMPILER) \ + $(COMPILE_FLAGS) $(LIN_TFLAGS) $(INCLUDE_FLAGS) + +UBSAN ?= 0 +SANITIZE_FLAGS != [ "$(UBSAN)" != "0" ] \ + && echo -fsanitize=undefined \ + || echo + +# don't use dep trick for tests +COMPILE_TEST := $(COMPILER) $(COMPILE_FLAGS) \ + $(INCLUDE_FLAGS) $(SANITIZE_FLAGS) + +# dep flags use delayed expansion trick so we can't use := here +COMPILE_GRAN = $(COMPILER) $(COMPILE_FLAGS) \ + $(DEP_FLAGS) $(INCLUDE_FLAGS) $(SANITIZE_FLAGS) + +TESTS != [ -n "$(CHECK)" ] && echo "$(CHECK)" || echo check + +-include deps.mk + +libgran.a: $(GRAN_OBJS) + $(AR) rcs $@ $(GRAN_OBJS) + + +# might lint some common things twice +.PHONY: +lint: $(GRAN_LINTS) + +.PHONY: check +check: + $(MAKE) -f scripts/makefile.tests -k $(TESTS) COMPILE_TEST="$(COMPILE_TEST)" diff --git a/scripts/makefile.tests b/scripts/makefile.tests new file mode 100644 index 0000000..600a819 --- /dev/null +++ b/scripts/makefile.tests @@ -0,0 +1,6 @@ +TESTS := + +include tests/*/source.mk + +.PHONY: check +check: $(TESTS) -- cgit v1.3