4 # This script is designed to quickly create lots of files in underlying
5 # test-* directories, do lots of other magic stuff and exit cleanly.
10 if [ "x$1" = "x" ]; then
11 echo "Usage: $0 check-src/<check-NN.c>"
16 abs_top_srcdir="${abs_top_srcdir:-$(pwd)/../../}"
17 abs_top_builddir="${abs_top_builddir:-$(pwd)/../../}"
19 if echo "$*" | grep -q -- -- ; then
20 TEST_DRIVER=$(echo "$*" | sed -e 's/ -- .*/ -- /g')
21 source_full=$(echo "$*" | sed -e 's/.* //g')
27 # Compute the .asn1 spec name by the given file name.
28 source_short=$(echo "$source_full" | sed -e 's/.*\///')
29 testno=$(echo "$source_short" | cut -f2 -d'-' | cut -f1 -d'.')
31 args=$(echo "$source_short" | sed -E -e 's/\.c+$//')
32 source_obj=$(echo "$source_short" | sed -E -e 's/\.c+$/.o/')
33 ext=$(echo "$source_short" | sed -E -e 's/.*\.(c+)$/\1/')
38 data_dir=$(echo "$1" | sed -e s/check-/data-/)
43 if [ -d ${data_dir} ]; then
44 OPT_DATA_DIR="../${data_dir}"
49 if test "${LIBFUZZER_CFLAGS}" && grep LLVMFuzzer ${source_full} > /dev/null;
56 # Assume the test fails. Will be removed when it passes well.
58 if [ -f "${testdir}-FAILED" ]; then
61 touch "${testdir}-FAILED"
64 ln -fns "../${source_full}" "${testdir}"
66 asn_module=$(echo "${abs_top_srcdir}/tests/tests-asn1c-compiler/${testno}"-*.asn1)
68 AUTOGENERATED="# This file is autogenerated by $0 ${source_full} ${AFLAGS}"
70 # Create a common Makefile for the project
71 cat <<END_MAKEFILE > "${testdir}/Makefile"
74 CFLAGS = \${COMMON_FLAGS} ${CFLAGS:-} -g -O1
75 CFLAGS += -DSRCDIR=../${srcdir}
76 CXXFLAGS = \${CFLAGS} ${CXXFLAGS}
77 LIBFUZZER_CFLAGS = ${LIBFUZZER_CFLAGS}
78 LDFLAGS = ${LDFLAGS:-}
79 ASAN_ENV_FLAGS = ${ASAN_ENV_FLAGS:-}
81 ASN_PROGRAM = check-program
82 ASN_PROGRAM_SRCS = ${source_short}
87 -include converter-example.mk
90 \$(MAKE) check-program
92 # Compile the corresponding .asn1 spec.
93 compiled-module: ${asn_module} ${abs_top_builddir}/asn1c/asn1c
94 ${abs_top_builddir}/asn1c/asn1c \\
95 -S ${abs_top_srcdir}/skeletons \\
98 ${AFLAGS} ${asn_module}
99 rm -f converter-example.c
100 @touch compiled-module
105 if [ "${MAKE_FUZZER}" != "yes" ]; then
106 CHECK_FUZZER="@echo \"No fuzzer defined, skipping.\""
107 cat <<END_MAKEFILE >> "${testdir}/Makefile"
112 CHECK_FUZZER="ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 ./check-fuzzer -timeout=3 -max_total_time=60 -max_len=512 ${OPT_DATA_DIR}"
113 cat <<END_MAKEFILE >> "${testdir}/Makefile"
114 check-fuzzer: ${source_short} \$(ASN_LIBRARY)
115 ${CC} \$(CFLAGS) \$(LIBFUZZER_CFLAGS) \$(LDFLAGS) -o check-fuzzer \$^
119 cat <<END_MAKEFILE >> "${testdir}/Makefile"
121 check-succeeded: compiled-module \$(ASN_LIBRARY) ${source_short}
122 \$(MAKE) check-program
123 \$(MAKE) check-fuzzer
124 @rm -f check-succeeded
125 \${ASAN_ENV_FLAGS} ./check-program
127 @touch check-succeeded
128 @echo "OK: ${source_full}"
134 check: check-succeeded
138 # Perform building and checking
139 ${TEST_DRIVER} ${MAKE:-make} -C "${testdir}" check
141 # Make sure the test is not marked as failed any longer.
142 rm -f "${testdir}-FAILED"