Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # |
| 4 | # Create an ASN.1 source code project for each line in each of the |
| 5 | # bundles/*.txt files, compile and run that it can be encoded, decoded, |
| 6 | # and fuzzed (if fuzzing is available). |
| 7 | # |
| 8 | |
| 9 | set -e |
| 10 | |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 11 | usage() { |
| 12 | echo "Usage:" |
| 13 | echo " $0 -h" |
Lev Walkin | 93f372b | 2017-10-03 16:39:38 -0700 | [diff] [blame] | 14 | echo " $0 [--dirty] -t \"<ASN.1 text defining type T, in string form>\"" |
| 15 | echo " $0 [--dirty] bundles/<bundle-name.txt> [<line>]" |
Lev Walkin | 8cec523 | 2017-10-03 15:05:54 -0700 | [diff] [blame] | 16 | echo "Where options are:" |
Lev Walkin | 4329272 | 2017-10-05 00:33:32 -0700 | [diff] [blame] | 17 | echo " -h Show this help screen" |
| 18 | echo " -e <syntax> Verify a given encoding explicitly (default is ALL)" |
| 19 | echo " --asn1c <flag> Add this flag to asn1c" |
| 20 | echo " --dirty Reuse compile results from the previous run(s)" |
| 21 | echo " -t <ASN.1> Run this particular typel" |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 22 | echo "Examples:" |
| 23 | echo " $0 -t UTF8String" |
| 24 | echo " $0 -t \"T ::= INTEGER (0..1)\"" |
| 25 | echo " $0 bundles/01-INTEGER-bundle.txt 3" |
| 26 | exit 1 |
| 27 | } |
| 28 | |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 29 | RNDTEMP=.tmp.random |
| 30 | |
| 31 | srcdir="${srcdir:-.}" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 32 | abs_top_srcdir="${abs_top_srcdir:-`pwd`/../../}" |
| 33 | abs_top_builddir="${abs_top_builddir:-`pwd`/../../}" |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 34 | |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 35 | tests_succeeded=0 |
| 36 | tests_failed=0 |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 37 | stop_after_failed=1 # We stop after 3 failures. |
Lev Walkin | 8cec523 | 2017-10-03 15:05:54 -0700 | [diff] [blame] | 38 | need_clean_before_bundle=1 # Clean before testing a bundle file |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 39 | need_clean_before_test=0 # Before each line in a bundle file |
Lev Walkin | 68619bf | 2017-10-03 18:40:36 -0700 | [diff] [blame] | 40 | encodings="" # Default is to verify all supported ASN.1 transfer syntaxes |
| 41 | parallelism=4 |
Lev Walkin | 4329272 | 2017-10-05 00:33:32 -0700 | [diff] [blame] | 42 | asn1c_flags="" |
Lev Walkin | 8cec523 | 2017-10-03 15:05:54 -0700 | [diff] [blame] | 43 | |
| 44 | make_clean_before_bundle() { |
Lev Walkin | ab25f19 | 2017-10-08 12:50:43 -0700 | [diff] [blame] | 45 | if [ "${need_clean_before_bundle}" = "1" ] ; then |
Lev Walkin | 226d107 | 2017-10-08 17:37:11 -0700 | [diff] [blame] | 46 | (cd ${RNDTEMP} && Make clean) || : |
Lev Walkin | ab25f19 | 2017-10-08 12:50:43 -0700 | [diff] [blame] | 47 | fi |
Lev Walkin | 8cec523 | 2017-10-03 15:05:54 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | make_clean_before_test() { |
Lev Walkin | 60d6267 | 2017-10-08 03:16:10 -0700 | [diff] [blame] | 51 | if [ "${need_clean_before_test}" = "1" ] ; then |
| 52 | Make clean |
| 53 | fi |
Lev Walkin | 8cec523 | 2017-10-03 15:05:54 -0700 | [diff] [blame] | 54 | } |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 55 | |
| 56 | # Get all the type-bearding lines in file and process them individually |
| 57 | verify_asn_types_in_file() { |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 58 | filename="$1" |
| 59 | need_line="$2" |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 60 | test "x$filename" != "x" || usage |
Lev Walkin | 8cec523 | 2017-10-03 15:05:54 -0700 | [diff] [blame] | 61 | |
| 62 | make_clean_before_bundle |
| 63 | |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 64 | echo "Open [$filename]" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 65 | line=0 |
| 66 | asn="" |
| 67 | while read asn; do |
| 68 | line=`echo "$line+1" | bc` |
| 69 | if echo "$asn" | sed -e 's/--.*//;' | grep -vi "[A-Z]" > /dev/null; then |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 70 | # Ignore lines consisting of just comments. |
| 71 | continue; |
| 72 | fi |
Lev Walkin | d28b45f | 2017-10-05 22:09:19 -0700 | [diff] [blame] | 73 | if [ "x$need_line" != "x" ] && [ "$need_line" != "$line" ]; then |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 74 | # We need a different line. |
| 75 | continue; |
| 76 | fi |
| 77 | verify_asn_type "$asn" "in $filename $line" |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 78 | if [ "${tests_failed}" = "${stop_after_failed}" ]; then |
| 79 | echo "STOP after ${tests_failed} failures, OK ${tests_succeeded}" |
| 80 | exit 1 |
| 81 | fi |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 82 | done < "$filename" |
| 83 | } |
| 84 | |
| 85 | verify_asn_type() { |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 86 | asn="$1" |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 87 | where="$2" |
| 88 | shift 2 |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 89 | test "x$asn" != "x" || usage |
Lev Walkin | 8cec523 | 2017-10-03 15:05:54 -0700 | [diff] [blame] | 90 | |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 91 | if echo "$asn" | grep -v "::=" > /dev/null; then |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 92 | asn="T ::= $asn" |
| 93 | fi |
| 94 | echo "Testing [$asn] ${where}" |
| 95 | |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 96 | mkdir -p ${RNDTEMP} |
Lev Walkin | 791d3b7 | 2017-10-02 16:24:28 -0700 | [diff] [blame] | 97 | if (set -e && cd ${RNDTEMP} && compile_and_test "$asn" "${where}"); then |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 98 | echo "OK [$asn] ${where}" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 99 | tests_succeeded=`echo "$tests_succeeded + 1" | bc` |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 100 | else |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 101 | tests_failed=`echo "$tests_failed + 1" | bc` |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 102 | echo "FAIL [$asn] ${where}" |
| 103 | fi |
| 104 | } |
| 105 | |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 106 | Make() { |
| 107 | ${MAKE:-make} -j "${parallelism}" "$@" || return $? |
| 108 | } |
| 109 | |
| 110 | get_param() { |
| 111 | param="$1" |
| 112 | default="$2" |
| 113 | text="$3" |
| 114 | |
| 115 | |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 116 | echo "$asn" | awk "/$param=/{for(i=1;i<=NF;i++)if(substr(\$i,0,length(\"${param}=\"))==\"${param}=\")PARAM=substr(\$i,length(\"${param}=\")+1)}END{if(PARAM)print PARAM;else print \"${default}\";}" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 119 | # compile_and_test "<text>" "<where found>" |
| 120 | compile_and_test() { |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 121 | asn="$1" |
| 122 | where="$2" |
Lev Walkin | 4329272 | 2017-10-05 00:33:32 -0700 | [diff] [blame] | 123 | |
| 124 | make_clean_before_test |
| 125 | |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 126 | asn_compile "$asn" "$where" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 127 | if [ $? -ne 0 ]; then |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 128 | echo "Cannot compile ASN.1 $asn" |
| 129 | return 1 |
| 130 | fi |
| 131 | |
| 132 | rm -f random-test-driver.o |
| 133 | rm -f random-test-driver |
Lev Walkin | 60d6267 | 2017-10-08 03:16:10 -0700 | [diff] [blame] | 134 | CFLAGS="${CFLAGS}" Make |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 135 | if [ $? -ne 0 ] ; then |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 136 | echo "Cannot compile C for $asn in ${RNDTEMP}" |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 137 | return 2 |
| 138 | fi |
| 139 | |
Lev Walkin | 791d3b7 | 2017-10-02 16:24:28 -0700 | [diff] [blame] | 140 | # Maximum size of the random data |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 141 | rmax=`get_param RMAX 128 "$asn"` |
Lev Walkin | 791d3b7 | 2017-10-02 16:24:28 -0700 | [diff] [blame] | 142 | if [ "0${rmax}" -lt 1 ]; then rmax=128; fi |
| 143 | |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 144 | echo "Checking random data encode-decode" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 145 | round_trip_check_cmd="${ASAN_ENV_FLAGS} ./random-test-driver -s ${rmax} ${encodings} -c" |
| 146 | if eval "$round_trip_check_cmd"; then |
| 147 | echo "Random test OK" |
| 148 | else |
Lev Walkin | cec390d | 2017-10-03 16:36:17 -0700 | [diff] [blame] | 149 | if [ "x$CC" = "x" ]; then CCSTR=""; else CCSTR="CC=${CC} "; fi |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 150 | echo "RETRY:" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 151 | echo "(cd ${RNDTEMP} && ${CCSTR}CFLAGS=\"${LIBFUZZER_CFLAGS} ${CFLAGS}\" ${MAKE:-make} && ${ASAN_ENV_FLAGS} ./random-test-driver -s ${rmax} ${encodings} -c)" |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 152 | return 3 |
| 153 | fi |
| 154 | |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 155 | echo "Generating new random data" |
| 156 | rm -rf random-data |
| 157 | cmd="${ASAN_ENV_FLAGS} UBSAN_OPTIONS=print_stacktrace=1" |
Lev Walkin | d28b45f | 2017-10-05 22:09:19 -0700 | [diff] [blame] | 158 | cmd="${cmd} ./random-test-driver -s ${rmax} ${encodings} -g random-data" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 159 | if eval "$cmd" ; then |
| 160 | echo "Random data generated OK" |
| 161 | else |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 162 | echo "RETRY:" |
| 163 | echo "(cd ${RNDTEMP} && $cmd)" |
| 164 | return 4 |
| 165 | fi |
| 166 | |
Lev Walkin | 233d14d | 2017-10-02 01:09:01 -0700 | [diff] [blame] | 167 | # Do a LibFuzzer based testing |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 168 | fuzz_time=10 |
| 169 | fuzz_cmd="${ASAN_ENV_FLAGS} UBSAN_OPTIONS=print_stacktrace=1" |
Lev Walkin | d28b45f | 2017-10-05 22:09:19 -0700 | [diff] [blame] | 170 | fuzz_cmd="${fuzz_cmd} ./random-test-driver" |
| 171 | fuzz_cmd="${fuzz_cmd} -timeout=3 -max_total_time=${fuzz_time} -max_len=128" |
Lev Walkin | 233d14d | 2017-10-02 01:09:01 -0700 | [diff] [blame] | 172 | |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 173 | if grep "^fuzz:" Makefile >/dev/null ; then |
| 174 | echo "No fuzzer defined, skipping fuzzing" |
| 175 | else |
| 176 | fuzz_targets=`echo random-data/* | sed -e 's/random-data./fuzz-/g'` |
Lev Walkin | d28b45f | 2017-10-05 22:09:19 -0700 | [diff] [blame] | 177 | { |
| 178 | echo "fuzz: $fuzz_targets" |
| 179 | echo "fuzz-%: random-data/% random-test-driver" |
| 180 | echo " ASN1_DATA_DIR=\$< ${fuzz_cmd} \$<" |
| 181 | } >> Makefile |
Lev Walkin | 233d14d | 2017-10-02 01:09:01 -0700 | [diff] [blame] | 182 | fi |
| 183 | |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 184 | # If LIBFUZZER_CFLAGS are properly defined, do the fuzz test as well |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 185 | if echo "${LIBFUZZER_CFLAGS}" | grep -i "[a-z]" > /dev/null; then |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 186 | |
| 187 | echo "Recompiling for fuzzing..." |
| 188 | rm -f random-test-driver.o |
| 189 | rm -f random-test-driver |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 190 | CFLAGS="${LIBFUZZER_CFLAGS} ${CFLAGS}" Make |
| 191 | if [ $? -ne 0 ]; then |
| 192 | echo "Recompile failed" |
| 193 | return 4 |
| 194 | fi |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 195 | |
Lev Walkin | d28b45f | 2017-10-05 22:09:19 -0700 | [diff] [blame] | 196 | echo "Fuzzing will take a multiple of $fuzz_time seconds..." |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 197 | Make fuzz |
| 198 | if [ $? -ne 0 ]; then |
Lev Walkin | 233d14d | 2017-10-02 01:09:01 -0700 | [diff] [blame] | 199 | echo "RETRY:" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 200 | echo "(cd ${RNDTEMP} && CC=${CC} CFLAGS=\"${LIBFUZZER_CFLAGS} ${CFLAGS}\" ${MAKE:-make} fuzz)" |
Lev Walkin | 233d14d | 2017-10-02 01:09:01 -0700 | [diff] [blame] | 201 | return 5 |
| 202 | fi |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 203 | fi |
| 204 | |
Lev Walkin | a5b0288 | 2017-10-01 22:48:44 -0700 | [diff] [blame] | 205 | return 0 |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 208 | asn_compile() { |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 209 | asn="$1" |
| 210 | where="$2" |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 211 | |
Lev Walkin | 5d947a8 | 2017-10-03 01:04:03 -0700 | [diff] [blame] | 212 | # Create "INTEGER (1..2)" from "T ::= INTEGER (1..2) -- RMAX=5" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 213 | short_asn=`echo "$asn" | sed -e 's/ *--.*//;s/RMAX=[^ ]* //;'` |
| 214 | if [ `echo "$short_asn" | grep -c "::="` = 1 ]; then |
| 215 | short_asn=`echo "$short_asn" | sed -e 's/.*::= *//'` |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 216 | fi |
| 217 | |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 218 | test ! -f Makefile.am # Protection from accidental clobbering |
| 219 | echo "Test DEFINITIONS ::= BEGIN $asn" > test.asn1 |
Lev Walkin | 4329272 | 2017-10-05 00:33:32 -0700 | [diff] [blame] | 220 | echo "-- ${where}" >> test.asn1 |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 221 | echo "END" >> test.asn1 |
Lev Walkin | 60d6267 | 2017-10-08 03:16:10 -0700 | [diff] [blame] | 222 | echo "${abs_top_builddir}/asn1c/asn1c" -S "${abs_top_srcdir}/skeletons" |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 223 | if "${abs_top_builddir}/asn1c/asn1c" -S "${abs_top_srcdir}/skeletons" \ |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 224 | -gen-OER -gen-PER ${asn1c_flags} test.asn1 |
Lev Walkin | a5b0288 | 2017-10-01 22:48:44 -0700 | [diff] [blame] | 225 | then |
Lev Walkin | 39936ce | 2017-10-05 23:56:39 -0700 | [diff] [blame] | 226 | echo "ASN.1 compiled OK" |
| 227 | else |
Lev Walkin | a5b0288 | 2017-10-01 22:48:44 -0700 | [diff] [blame] | 228 | return 1 |
| 229 | fi |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 230 | rm -f converter-example.c |
Lev Walkin | 09be69c | 2017-10-08 16:28:11 -0700 | [diff] [blame] | 231 | ln -sf "../${srcdir}/random-test-driver.c" || cp "../${srcdir}/random-test-driver.c" . |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 232 | echo "CFLAGS+= -DASN1_TEXT='$short_asn'" > Makefile |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 233 | sed -e 's/converter-example/random-test-driver/' \ |
Lev Walkin | d3cce46 | 2017-10-01 13:43:36 -0700 | [diff] [blame] | 234 | < Makefile.am.example >> Makefile |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 235 | echo "Makefile.am.example -> Makefile" |
| 236 | } |
| 237 | |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 238 | # Make up to four different passes: |
| 239 | # CFLAGS: | asn1c_flags: |
| 240 | # -m64 | -fnative-types |
| 241 | # -m32 | -fnative-types |
| 242 | # -m64 | -fwide-types |
| 243 | # -m32 | -fwide-types |
| 244 | # *) Of course, -m64 and -fnative-types are just implied. |
| 245 | test_drive() { |
| 246 | func="$1" |
| 247 | shift |
| 248 | |
| 249 | if [ "x${asn1c_flags}" = "x" ] ; then |
| 250 | # Test for native types and wide types |
| 251 | asn1c_flags=" " test_drive "${func}" "$@" |
| 252 | asn1c_flags="-fnative-types" test_drive "${func}" "$@" |
| 253 | return 0 |
| 254 | fi |
| 255 | |
| 256 | echo "MODE: default" |
| 257 | # Default (likely 64-bit) mode |
| 258 | ${func} "$@" |
| 259 | |
| 260 | # 32-bit mode, if available |
| 261 | if echo "${CFLAGS_M32}" | grep -i '[a-z]' > /dev/null ; then |
| 262 | echo "MODE: 32-bit" |
| 263 | # Unconditional clean, can't reuse object code. |
| 264 | (cd ${RNDTEMP} && Make clean) |
| 265 | # -m32 doesn't support fuzzing (no such library), so we remove fuzzer. |
| 266 | # -m32 doesn't support leak sanitizing (it hangs), so we remove |
| 267 | # ASAN_ENV_FLAGS which enable leak check. |
| 268 | CFLAGS="${CFLAGS} ${CFLAGS_M32}" CFLAGS_M32="" \ |
| 269 | LIBFUZZER_CFLAGS="" ASAN_ENV_FLAGS="" \ |
| 270 | ${func} "$@" |
| 271 | fi |
| 272 | } |
| 273 | |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 274 | # Command line parsing |
Lev Walkin | 68619bf | 2017-10-03 18:40:36 -0700 | [diff] [blame] | 275 | while :; do |
| 276 | case "$1" in |
| 277 | -h) usage ;; |
Lev Walkin | d28b45f | 2017-10-05 22:09:19 -0700 | [diff] [blame] | 278 | --asn1c) asn1c_flags="${asn1c_flags} $2"; shift 2; continue ;; |
Lev Walkin | 68619bf | 2017-10-03 18:40:36 -0700 | [diff] [blame] | 279 | --dirty) |
| 280 | need_clean_before_bundle=0 |
| 281 | need_clean_before_test=0 |
| 282 | shift |
| 283 | continue |
| 284 | ;; |
Lev Walkin | d28b45f | 2017-10-05 22:09:19 -0700 | [diff] [blame] | 285 | -e) encodings="${encodings} -e $2"; shift 2; continue;; |
Lev Walkin | 68619bf | 2017-10-03 18:40:36 -0700 | [diff] [blame] | 286 | -j) parallelism="$1"; shift 2; continue;; |
| 287 | -t) |
| 288 | parallelism=1 # Better for debuggability |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 289 | test_drive verify_asn_type "$2" "(command line)" || exit 1 ;; |
Lev Walkin | 68619bf | 2017-10-03 18:40:36 -0700 | [diff] [blame] | 290 | "") |
Lev Walkin | 09be69c | 2017-10-08 16:28:11 -0700 | [diff] [blame] | 291 | for bundle in `ls -1 ${srcdir}/bundles/*.txt | sort -nr`; do |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 292 | test_drive verify_asn_types_in_file "$bundle" |
Lev Walkin | 68619bf | 2017-10-03 18:40:36 -0700 | [diff] [blame] | 293 | done |
| 294 | ;; |
| 295 | *) |
Lev Walkin | 7c470c7 | 2017-10-08 04:01:45 -0700 | [diff] [blame] | 296 | test_drive verify_asn_types_in_file "$@" |
Lev Walkin | 68619bf | 2017-10-03 18:40:36 -0700 | [diff] [blame] | 297 | ;; |
| 298 | esac |
| 299 | break |
| 300 | done |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 301 | |
Lev Walkin | d28b45f | 2017-10-05 22:09:19 -0700 | [diff] [blame] | 302 | if [ "$tests_succeeded" != "0" ] && [ "$tests_failed" = "0" ]; then |
Lev Walkin | cb52391 | 2017-09-30 19:33:23 -0700 | [diff] [blame] | 303 | echo "OK $tests_succeeded tests" |
| 304 | else |
| 305 | echo "FAILED $tests_failed tests, OK $tests_succeeded tests" |
| 306 | exit 1 |
| 307 | fi |