universalservice/gen_tests.sh

66 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# The road to hell is paved with Makefile generators.
TEST_TARGETS=""
GENERATED_OBJS=""
gen_test() {
local NAME COLLECTOR TEST_IMPL DEPS OBJDEPS
NAME=$1
COLLECTOR=$2
TEST_IMPL="$NAME.c"
DEPS="$1.o uns.o $3"
OBJDEPS="include/uns.h $1.c $4"
printf '%s.o: %s\n' "$NAME" "$OBJDEPS"
printf '%s_%s.test: %s\n' "$NAME" "$COLLECTOR" "$DEPS"
printf '\t${CC} ${LDFLAGS} %s -o %s_%s.test\n' \
"$DEPS" "$NAME" "$COLLECTOR"
printf '\tvalgrind ./%s_%s.test\n' "$NAME" "$COLLECTOR"
TEST_TARGETS=$(printf "%s %s_%s.test" "$TEST_TARGETS" "$NAME" "$COLLECTOR")
GENERATED_OBJS="$GENERATED_OBJS $NAME.o"
}
gen_string_test() {
local COLLECTOR DEPS OBJDEPS
COLLECTOR=$1
DEPS="$2 examples/test_$COLLECTOR.o examples/string/uns_string.o"
OBJDEPS="examples/string/uns_string.h"
gen_test 'examples/string/test_small' "$COLLECTOR" \
"$DEPS" "$OBJDEPS"
gen_test 'examples/string/test_large' "$COLLECTOR" \
"$DEPS" "$OBJDEPS"
gen_test 'examples/string/test_inefficient' "$COLLECTOR" \
"$DEPS" "$OBJDEPS"
}
gen_hashtable_test() {
local COLLECTOR DEPS OBJDEPS
COLLECTOR=$1
DEPS="$2 examples/test_$COLLECTOR.o examples/hashtable/uns_hashtable.o"
OBJDEPS="examples/hashtable/uns_hashtable.h examples/hashtable/testnames.h"
gen_test 'examples/hashtable/test_insert' "$COLLECTOR" \
"$DEPS" "$OBJDEPS"
gen_test 'examples/hashtable/test_insert_delete' "$COLLECTOR" \
"$DEPS" "$OBJDEPS"
}
gen_tests() {
gen_string_test "$1" '${CHENEY_C89_OBJS}'
gen_hashtable_test "$1" '${CHENEY_C89_OBJS}'
}
gen_tests cheney_c89
printf "tests: %s\n" "$TEST_TARGETS"
printf 'clean_tests: %s\n\t${RM} -f %s %s\n' "$TEST_TARGETS" "$GENERATED_OBJS"