blob: cd6ba6d22ccd0f6d3ebf0343319959f614001fa1 [file] [log] [blame]
Gavin Howard805cd412019-01-05 19:34:35 -07001#! /bin/sh
Gavin Howard4052e032018-10-23 17:22:57 -06002#
3# Copyright 2018 Gavin D. Howard
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted.
7#
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14# PERFORMANCE OF THIS SOFTWARE.
15#
16
17usage() {
Gavin Howard0b934b52019-02-15 15:06:35 -070018 printf 'usage: %s [run_tests] [generate_tests] [test_with_gcc] [run_sanitizers] [run_valgrind]\n' "$script"
Gavin Howard4052e032018-10-23 17:22:57 -060019 exit 1
20}
21
22header() {
23
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070024 local msg="$1"
25 shift
Gavin Howard4052e032018-10-23 17:22:57 -060026
Gavin Howard805cd412019-01-05 19:34:35 -070027 printf '\n'
Gavin Howard03e24672019-01-05 19:47:22 -070028 printf '*******************\n'
Gavin Howard805cd412019-01-05 19:34:35 -070029 printf '%s...\n' "$msg"
Gavin Howard03e24672019-01-05 19:47:22 -070030 printf '*******************\n'
Gavin Howard805cd412019-01-05 19:34:35 -070031 printf '\n'
Gavin Howard4052e032018-10-23 17:22:57 -060032}
33
Gavin Howardecbee382019-02-01 12:46:26 -070034do_make() {
35 make -j4 "$@"
36}
37
Gavin Howardb026ebd2019-01-05 19:44:49 -070038configure() {
39
40 local CFLAGS="$1"
41 shift
42
43 local CC="$1"
44 shift
45
46 local configure_flags="$1"
47 shift
48
Gavin Howardfd7513b2019-02-13 18:12:54 -070049 if [ "$gen_tests" -eq 0 ]; then
Gavin Howarda28acf82019-02-13 18:06:29 -070050 configure_flags="-G $configure_flags"
51 fi
52
Gavin Howardbffa6c92019-01-11 23:12:19 -070053 if [ "$CC" = "clang" ]; then
54 CFLAGS="$clang_flags $CFLAGS"
55 fi
56
Gavin Howard79f605c2019-01-08 13:08:21 -070057 header "Running \"./configure.sh $configure_flags\" with CC=\"$CC\" and CFLAGS=\"$CFLAGS\""
58 CFLAGS="$CFLAGS" CC="$CC" ./configure.sh $configure_flags > /dev/null
Gavin Howardb026ebd2019-01-05 19:44:49 -070059
60}
61
Gavin Howard4052e032018-10-23 17:22:57 -060062build() {
63
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070064 local CFLAGS="$1"
Gavin Howard4052e032018-10-23 17:22:57 -060065 shift
66
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070067 local CC="$1"
Gavin Howard4052e032018-10-23 17:22:57 -060068 shift
69
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070070 local configure_flags="$1"
Gavin Howard4052e032018-10-23 17:22:57 -060071 shift
72
Gavin Howardb026ebd2019-01-05 19:44:49 -070073 configure "$CFLAGS" "$CC" "$configure_flags"
Gavin Howard4052e032018-10-23 17:22:57 -060074
Gavin Howardb026ebd2019-01-05 19:44:49 -070075 header "Building with CC=\"$CC\" and CFLAGS=\"$CFLAGS\""
76
Gavin Howardecbee382019-02-01 12:46:26 -070077 do_make > /dev/null 2> "$scriptdir/.test.txt"
Gavin Howard4052e032018-10-23 17:22:57 -060078
79 if [ -s "$scriptdir/.test.txt" ]; then
Gavin Howard805cd412019-01-05 19:34:35 -070080 printf '%s generated warning(s):\n' "$CC"
81 printf '\n'
Gavin Howard4052e032018-10-23 17:22:57 -060082 cat "$scriptdir/.test.txt"
83 exit 1
84 fi
85}
86
Gavin Howard8c4780b2019-01-04 12:37:33 -070087runtest() {
88
89 header "Running tests"
90
Gavin Howard95358a92019-01-08 01:17:29 -070091 if [ "$#" -gt 0 ]; then
Gavin Howardecbee382019-02-01 12:46:26 -070092 do_make "$@"
Gavin Howard95358a92019-01-08 01:17:29 -070093 else
Gavin Howardecbee382019-02-01 12:46:26 -070094 do_make test
Gavin Howard95358a92019-01-08 01:17:29 -070095 fi
Gavin Howard8c4780b2019-01-04 12:37:33 -070096}
97
98runconfigtests() {
Gavin Howard4052e032018-10-23 17:22:57 -060099
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700100 local CFLAGS="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600101 shift
102
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700103 local CC="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600104 shift
105
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700106 local configure_flags="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600107 shift
108
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700109 local run_tests="$1"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700110 shift
111
Gavin Howard8c4780b2019-01-04 12:37:33 -0700112 if [ "$run_tests" -ne 0 ]; then
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700113 header "Running tests with configure flags \"$configure_flags\", CC=\"$CC\", and CFLAGS=\"$CFLAGS\""
Gavin Howard8c4780b2019-01-04 12:37:33 -0700114 else
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700115 header "Building with configure flags \"$configure_flags\", CC=\"$CC\", and CFLAGS=\"$CFLAGS\""
Gavin Howard8c4780b2019-01-04 12:37:33 -0700116 fi
117
Gavin Howardd4fece32019-01-08 02:06:22 -0700118 build "$CFLAGS" "$CC" "$configure_flags"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700119 if [ "$run_tests" -ne 0 ]; then
120 runtest
121 fi
122
Gavin Howardecbee382019-02-01 12:46:26 -0700123 do_make clean
Gavin Howard8c4780b2019-01-04 12:37:33 -0700124
Gavin Howardd4fece32019-01-08 02:06:22 -0700125 build "$CFLAGS" "$CC" "$configure_flags -b"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700126 if [ "$run_tests" -ne 0 ]; then
127 runtest
128 fi
129
Gavin Howardecbee382019-02-01 12:46:26 -0700130 do_make clean
Gavin Howard8c4780b2019-01-04 12:37:33 -0700131
Gavin Howardd4fece32019-01-08 02:06:22 -0700132 build "$CFLAGS" "$CC" "$configure_flags -d"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700133 if [ "$run_tests" -ne 0 ]; then
134 runtest
135 fi
136
Gavin Howardecbee382019-02-01 12:46:26 -0700137 do_make clean
Gavin Howard6e27dec2018-10-24 17:38:34 -0600138}
Gavin Howard4052e032018-10-23 17:22:57 -0600139
Gavin Howard8c4780b2019-01-04 12:37:33 -0700140runtestseries() {
Gavin Howard4052e032018-10-23 17:22:57 -0600141
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700142 local CFLAGS="$1"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700143 shift
Gavin Howard4052e032018-10-23 17:22:57 -0600144
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700145 local CC="$1"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700146 shift
147
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700148 local run_tests="$1"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700149 shift
150
Gavin Howardd4fece32019-01-08 02:06:22 -0700151 runconfigtests "$CFLAGS" "$CC" "" "$run_tests"
152 runconfigtests "$CFLAGS" "$CC" "-E" "$run_tests"
153 runconfigtests "$CFLAGS" "$CC" "-H" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700154 runconfigtests "$CFLAGS" "$CC" "-N" "$run_tests"
Gavin Howardd4fece32019-01-08 02:06:22 -0700155 runconfigtests "$CFLAGS" "$CC" "-R" "$run_tests"
156 runconfigtests "$CFLAGS" "$CC" "-S" "$run_tests"
157 runconfigtests "$CFLAGS" "$CC" "-EH" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700158 runconfigtests "$CFLAGS" "$CC" "-EN" "$run_tests"
Gavin Howardd4fece32019-01-08 02:06:22 -0700159 runconfigtests "$CFLAGS" "$CC" "-ER" "$run_tests"
160 runconfigtests "$CFLAGS" "$CC" "-ES" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700161 runconfigtests "$CFLAGS" "$CC" "-HN" "$run_tests"
Gavin Howardd4fece32019-01-08 02:06:22 -0700162 runconfigtests "$CFLAGS" "$CC" "-HR" "$run_tests"
163 runconfigtests "$CFLAGS" "$CC" "-HS" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700164 runconfigtests "$CFLAGS" "$CC" "-NR" "$run_tests"
165 runconfigtests "$CFLAGS" "$CC" "-NS" "$run_tests"
Gavin Howardd4fece32019-01-08 02:06:22 -0700166 runconfigtests "$CFLAGS" "$CC" "-RS" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700167 runconfigtests "$CFLAGS" "$CC" "-EHN" "$run_tests"
Gavin Howardd4fece32019-01-08 02:06:22 -0700168 runconfigtests "$CFLAGS" "$CC" "-EHR" "$run_tests"
169 runconfigtests "$CFLAGS" "$CC" "-EHS" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700170 runconfigtests "$CFLAGS" "$CC" "-ENR" "$run_tests"
171 runconfigtests "$CFLAGS" "$CC" "-ENS" "$run_tests"
Gavin Howardd4fece32019-01-08 02:06:22 -0700172 runconfigtests "$CFLAGS" "$CC" "-ERS" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700173 runconfigtests "$CFLAGS" "$CC" "-HNR" "$run_tests"
174 runconfigtests "$CFLAGS" "$CC" "-HNS" "$run_tests"
Gavin Howardd4fece32019-01-08 02:06:22 -0700175 runconfigtests "$CFLAGS" "$CC" "-HRS" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700176 runconfigtests "$CFLAGS" "$CC" "-NRS" "$run_tests"
177 runconfigtests "$CFLAGS" "$CC" "-EHNR" "$run_tests"
178 runconfigtests "$CFLAGS" "$CC" "-EHNS" "$run_tests"
Gavin Howardd4fece32019-01-08 02:06:22 -0700179 runconfigtests "$CFLAGS" "$CC" "-EHRS" "$run_tests"
Gavin Howard2be9b7d2019-02-20 16:27:02 -0700180 runconfigtests "$CFLAGS" "$CC" "-ENRS" "$run_tests"
181 runconfigtests "$CFLAGS" "$CC" "-HNRS" "$run_tests"
182 runconfigtests "$CFLAGS" "$CC" "-EHNRS" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600183}
184
185runtests() {
186
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700187 local CFLAGS="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600188 shift
189
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700190 local CC="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600191 shift
192
Gavin Howardd2143fb2019-01-04 22:00:30 -0700193 local run_tests="$1"
194 shift
195
Gavin Howardd4fece32019-01-08 02:06:22 -0700196 runtestseries "$CFLAGS" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600197}
198
Gavin Howard4052e032018-10-23 17:22:57 -0600199karatsuba() {
200
201 header "Running Karatsuba tests"
Gavin Howardecbee382019-02-01 12:46:26 -0700202 do_make karatsuba_test
Gavin Howard4052e032018-10-23 17:22:57 -0600203}
204
205vg() {
206
207 header "Running valgrind"
208
Gavin Howardd4fece32019-01-08 02:06:22 -0700209 build "$reldebug" "$CC" "-g"
Gavin Howardecbee382019-02-01 12:46:26 -0700210 runtest valgrind
Gavin Howard4052e032018-10-23 17:22:57 -0600211
Gavin Howardecbee382019-02-01 12:46:26 -0700212 do_make clean_config
Gavin Howard4052e032018-10-23 17:22:57 -0600213
Gavin Howardd4fece32019-01-08 02:06:22 -0700214 build "$reldebug" "$CC" "-gb"
Gavin Howardecbee382019-02-01 12:46:26 -0700215 runtest valgrind
Gavin Howard4052e032018-10-23 17:22:57 -0600216
Gavin Howardecbee382019-02-01 12:46:26 -0700217 do_make clean_config
Gavin Howard4052e032018-10-23 17:22:57 -0600218
Gavin Howardd4fece32019-01-08 02:06:22 -0700219 build "$reldebug" "$CC" "-gd"
Gavin Howardecbee382019-02-01 12:46:26 -0700220 runtest valgrind
Gavin Howard4052e032018-10-23 17:22:57 -0600221
Gavin Howardecbee382019-02-01 12:46:26 -0700222 do_make clean_config
Gavin Howard4052e032018-10-23 17:22:57 -0600223}
224
Gavin Howard4052e032018-10-23 17:22:57 -0600225debug() {
226
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700227 local CC="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600228 shift
229
Gavin Howardd2143fb2019-01-04 22:00:30 -0700230 local run_tests="$1"
231 shift
232
233 runtests "$debug" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600234
Gavin Howarddd9ecc22019-02-14 13:10:52 -0700235 if [ "$CC" = "clang" -a "$run_sanitizers" -ne 0 ]; then
Gavin Howardd2143fb2019-01-04 22:00:30 -0700236 runtests "$debug -fsanitize=address" "$CC" "$run_tests"
237 runtests "$debug -fsanitize=undefined" "$CC" "$run_tests"
238 runtests "$debug -fsanitize=memory" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600239 fi
240}
241
242release() {
Gavin Howardd2143fb2019-01-04 22:00:30 -0700243
244 local CC="$1"
245 shift
246
247 local run_tests="$1"
248 shift
249
250 runtests "$release" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600251}
252
253reldebug() {
Gavin Howardd2143fb2019-01-04 22:00:30 -0700254
255 local CC="$1"
256 shift
257
258 local run_tests="$1"
259 shift
260
261 runtests "$reldebug" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600262}
263
264minsize() {
Gavin Howardd2143fb2019-01-04 22:00:30 -0700265
266 local CC="$1"
267 shift
268
269 local run_tests="$1"
270 shift
271
272 runtests "$minsize" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600273}
274
Gavin Howardbffa6c92019-01-11 23:12:19 -0700275clang_flags="-Weverything -Wno-padded -Wno-switch-enum -Wno-format-nonliteral"
276clang_flags="$clang_flags -Wno-cast-align -Wno-missing-noreturn -Wno-disabled-macro-expansion"
277clang_flags="$clang_flags -Wno-unreachable-code -Wno-unreachable-code-return"
278
Gavin Howard6fe912a2019-02-02 12:45:37 -0700279cflags="-Wall -Wextra -Werror -pedantic -std=c99"
Gavin Howarddb6b3fc2019-01-04 21:51:46 -0700280
281debug="$cflags -g -O0 -fno-omit-frame-pointer"
282release="$cflags -DNDEBUG -O3"
283reldebug="$cflags -O3 -g -fno-omit-frame-pointer"
284minsize="$cflags -DNDEBUG -Os"
Gavin Howard4052e032018-10-23 17:22:57 -0600285
286set -e
287
288script="$0"
289scriptdir=$(dirname "$script")
290
Gavin Howard30a203e2019-01-05 19:37:03 -0700291if [ "$#" -gt 0 ]; then
Gavin Howardd2143fb2019-01-04 22:00:30 -0700292 run_tests="$1"
293 shift
294else
295 run_tests=1
296fi
297
298if [ "$#" -gt 0 ]; then
Gavin Howarda28acf82019-02-13 18:06:29 -0700299 gen_tests="$1"
300 shift
301else
302 gen_tests=1
303fi
304
305if [ "$#" -gt 0 ]; then
Gavin Howardbbb5ec32019-01-05 19:45:30 -0700306 test_with_gcc="$1"
307 shift
308else
309 test_with_gcc=1
310fi
311
Gavin Howarddd9ecc22019-02-14 13:10:52 -0700312if [ "$#" -gt 0 ]; then
313 run_sanitizers="$1"
314 shift
315else
316 run_sanitizers=1
317fi
318
Gavin Howard0b934b52019-02-15 15:06:35 -0700319if [ "$#" -gt 0 ]; then
320 run_valgrind="$1"
321 shift
322else
323 run_valgrind=1
324fi
325
Gavin Howard4052e032018-10-23 17:22:57 -0600326cd "$scriptdir"
327
Gavin Howardb65f0f82019-01-24 16:22:08 -0700328build "$debug" "clang" ""
329
330header "Running math library under --standard"
331
Gavin Howard50080252019-02-20 15:27:43 -0700332printf 'quit\n' | bin/bc -ls
Gavin Howardb026ebd2019-01-05 19:44:49 -0700333
Gavin Howard4052e032018-10-23 17:22:57 -0600334version=$(make version)
335
Gavin Howardecbee382019-02-01 12:46:26 -0700336do_make clean_tests
Gavin Howard68f4a4e2019-01-07 17:50:15 -0700337
Gavin Howardd2143fb2019-01-04 22:00:30 -0700338debug "clang" "$run_tests"
339release "clang" "$run_tests"
340reldebug "clang" "$run_tests"
341minsize "clang" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600342
Gavin Howard91afc872019-01-05 20:22:37 -0700343if [ "$test_with_gcc" -ne 0 ]; then
Gavin Howardbbb5ec32019-01-05 19:45:30 -0700344 debug "gcc" "$run_tests"
345 release "gcc" "$run_tests"
346 reldebug "gcc" "$run_tests"
347 minsize "gcc" "$run_tests"
348fi
Gavin Howard4052e032018-10-23 17:22:57 -0600349
Gavin Howardd2143fb2019-01-04 22:00:30 -0700350if [ "$run_tests" -ne 0 ]; then
Gavin Howardc7ae8af2019-01-10 09:33:47 -0700351
Gavin Howardecbee382019-02-01 12:46:26 -0700352 build "$release" "clang" ""
Gavin Howardbc8cf8c2019-01-16 11:29:03 -0700353
Gavin Howardd2143fb2019-01-04 22:00:30 -0700354 karatsuba
Gavin Howard0b934b52019-02-15 15:06:35 -0700355
356 if [ "$run_valgrind" -ne 0 ]; then
357 vg
358 fi
Gavin Howard16208122018-10-24 17:20:45 -0600359
Gavin Howard26863372019-02-15 18:36:27 -0700360 configure "$reldebug" "afl-gcc" ""
Gavin Howardcf614742019-01-05 20:27:16 -0700361
362 printf '\n'
Gavin Howard26863372019-02-15 18:36:27 -0700363 printf 'Run make\n'
364 printf '\n'
Gavin Howard1b5ea802019-02-19 21:24:04 -0700365 printf 'Then run %s/tests/randmath.py and the fuzzer.\n' "$scriptdir"
Gavin Howardcf614742019-01-05 20:27:16 -0700366 printf 'Then run the GitHub release script as follows:\n'
367 printf '\n'
Gavin Howard9c5840f2019-02-20 11:15:04 -0700368 printf ' <github_release> %s <msg> .travis.yml codecov.yml release.sh RELEASE.md \\\n' "$version"
Gavin Howardc083fad2019-01-09 09:55:09 -0700369 printf ' tests/afl.py tests/randmath.py tests/bc/scripts/timeconst.bc\n'
Gavin Howardcf614742019-01-05 20:27:16 -0700370
371fi