2024-07-08 19:58:22 -04:00
|
|
|
#!/bin/sh
|
|
|
|
# The road to hell is paved with Makefile generators.
|
2024-07-10 10:47:55 -04:00
|
|
|
#
|
|
|
|
# Each test is compiled statically linked with a single collector.
|
|
|
|
#
|
|
|
|
# OBJDEPS: Dependencies for an object file.
|
|
|
|
# DEPS: Dependencies for an executable file.
|
2024-07-08 19:58:22 -04:00
|
|
|
|
|
|
|
TEST_TARGETS=""
|
|
|
|
GENERATED_OBJS=""
|
|
|
|
|
2024-07-10 10:47:55 -04:00
|
|
|
gen_test() { # test_name, collector_name, exec_deps, obj_file_deps
|
|
|
|
local NAME COLLECTOR TARGET TEST_IMPL DEPS OBJDEPS
|
2024-07-08 19:58:22 -04:00
|
|
|
|
|
|
|
NAME=$1
|
|
|
|
COLLECTOR=$2
|
2024-07-10 10:47:55 -04:00
|
|
|
TARGET="$NAME"_"$COLLECTOR".test
|
2024-07-08 19:58:22 -04:00
|
|
|
TEST_IMPL="$NAME.c"
|
|
|
|
DEPS="$1.o uns.o $3"
|
|
|
|
OBJDEPS="include/uns.h $1.c $4"
|
|
|
|
|
2024-07-10 10:47:55 -04:00
|
|
|
echo "
|
|
|
|
$TARGET: $DEPS
|
2024-07-14 01:20:50 -04:00
|
|
|
\${CC} \${TEST_LDFLAGS} $DEPS -o $TARGET
|
|
|
|
\${TEST_WRAPPER} ./$TARGET
|
2024-07-10 10:47:55 -04:00
|
|
|
"
|
2024-07-08 19:58:22 -04:00
|
|
|
|
2024-07-10 10:47:55 -04:00
|
|
|
TEST_TARGETS="$TEST_TARGETS $TARGET"
|
2024-07-08 19:58:22 -04:00
|
|
|
GENERATED_OBJS="$GENERATED_OBJS $NAME.o"
|
|
|
|
}
|
|
|
|
|
2024-07-10 10:47:55 -04:00
|
|
|
gen_string_test() { # collector_name, exec_deps
|
2024-07-08 19:58:22 -04:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2024-07-10 10:47:55 -04:00
|
|
|
gen_hashtable_test() { # collector_name, exec_deps
|
2024-07-08 19:58:22 -04:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2024-07-10 10:47:55 -04:00
|
|
|
gen_lisp_test() { #collector_name, exec_deps
|
|
|
|
local COLLECTOR SHIM_OBJ TARGET DEPS OBJDEPS
|
|
|
|
COLLECTOR=$1
|
|
|
|
TARGET="examples/lisp/uns_lisp_$COLLECTOR"
|
|
|
|
SHIM_OBJ="$TARGET.o"
|
|
|
|
OBJDEPS="examples/lisp/uns_lisp_$COLLECTOR.c include/uns.h include/$COLLECTOR.h"
|
|
|
|
DEPS="$2 $SHIM_OBJ uns.o "'${UNS_LISP_OBJS}'
|
|
|
|
|
|
|
|
echo "
|
|
|
|
$SHIM_OBJ: $OBJDEPS
|
|
|
|
|
|
|
|
$TARGET: $DEPS
|
2024-07-14 01:20:50 -04:00
|
|
|
\${CC} \${TEST_LDFLAGS} $DEPS -o $TARGET
|
2024-07-10 10:47:55 -04:00
|
|
|
"
|
|
|
|
|
|
|
|
TEST_TARGETS="$TEST_TARGETS $TARGET"
|
|
|
|
GENERTATED_OBJS="$GENERATED_OBJS $SHIM_OBJ"
|
|
|
|
}
|
|
|
|
|
2024-07-08 19:58:22 -04:00
|
|
|
gen_tests() {
|
2024-07-08 20:06:01 -04:00
|
|
|
echo "examples/test_$1.o: include/uns.h $2"
|
|
|
|
GENERATED_OBJS="$GENERATED_OBJS examples/test_$1.o"
|
2024-07-10 10:47:55 -04:00
|
|
|
|
2024-07-08 19:58:22 -04:00
|
|
|
gen_string_test "$1" '${CHENEY_C89_OBJS}'
|
|
|
|
gen_hashtable_test "$1" '${CHENEY_C89_OBJS}'
|
2024-07-10 10:47:55 -04:00
|
|
|
gen_lisp_test "$1" '${CHENEY_C89_OBJS}'
|
2024-07-08 19:58:22 -04:00
|
|
|
}
|
|
|
|
|
2024-07-08 20:06:01 -04:00
|
|
|
gen_tests cheney_c89 "include/cheney_c89.h"
|
2024-07-08 19:58:22 -04:00
|
|
|
|
2024-07-10 10:47:55 -04:00
|
|
|
echo
|
2024-07-08 19:58:22 -04:00
|
|
|
printf "tests: %s\n" "$TEST_TARGETS"
|
2024-07-08 20:06:01 -04:00
|
|
|
printf 'clean_tests:\n\t${RM} -f %s %s\n' "$TEST_TARGETS" "$GENERATED_OBJS"
|