blob: e58aab6add69ccce891b5cf928857fca26f06e3b [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 Howard74d2b8d2019-01-29 12:52:41 -070018 printf 'usage: %s [run_tests] [test_with_gcc]\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 Howardbffa6c92019-01-11 23:12:19 -070049 if [ "$CC" = "clang" ]; then
50 CFLAGS="$clang_flags $CFLAGS"
51 fi
52
Gavin Howard79f605c2019-01-08 13:08:21 -070053 header "Running \"./configure.sh $configure_flags\" with CC=\"$CC\" and CFLAGS=\"$CFLAGS\""
54 CFLAGS="$CFLAGS" CC="$CC" ./configure.sh $configure_flags > /dev/null
Gavin Howardb026ebd2019-01-05 19:44:49 -070055
56}
57
Gavin Howard4052e032018-10-23 17:22:57 -060058build() {
59
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070060 local CFLAGS="$1"
Gavin Howard4052e032018-10-23 17:22:57 -060061 shift
62
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070063 local CC="$1"
Gavin Howard4052e032018-10-23 17:22:57 -060064 shift
65
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070066 local configure_flags="$1"
Gavin Howard4052e032018-10-23 17:22:57 -060067 shift
68
Gavin Howardb026ebd2019-01-05 19:44:49 -070069 configure "$CFLAGS" "$CC" "$configure_flags"
Gavin Howard4052e032018-10-23 17:22:57 -060070
Gavin Howardb026ebd2019-01-05 19:44:49 -070071 header "Building with CC=\"$CC\" and CFLAGS=\"$CFLAGS\""
72
Gavin Howardecbee382019-02-01 12:46:26 -070073 do_make > /dev/null 2> "$scriptdir/.test.txt"
Gavin Howard4052e032018-10-23 17:22:57 -060074
75 if [ -s "$scriptdir/.test.txt" ]; then
Gavin Howard805cd412019-01-05 19:34:35 -070076 printf '%s generated warning(s):\n' "$CC"
77 printf '\n'
Gavin Howard4052e032018-10-23 17:22:57 -060078 cat "$scriptdir/.test.txt"
79 exit 1
80 fi
81}
82
Gavin Howard8c4780b2019-01-04 12:37:33 -070083runtest() {
84
85 header "Running tests"
86
Gavin Howard95358a92019-01-08 01:17:29 -070087 if [ "$#" -gt 0 ]; then
Gavin Howardecbee382019-02-01 12:46:26 -070088 do_make "$@"
Gavin Howard95358a92019-01-08 01:17:29 -070089 else
Gavin Howardecbee382019-02-01 12:46:26 -070090 do_make test
Gavin Howard95358a92019-01-08 01:17:29 -070091 fi
Gavin Howard8c4780b2019-01-04 12:37:33 -070092}
93
94runconfigtests() {
Gavin Howard4052e032018-10-23 17:22:57 -060095
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070096 local CFLAGS="$1"
Gavin Howard4052e032018-10-23 17:22:57 -060097 shift
98
Gavin Howard6f1aa5a2019-01-04 13:29:04 -070099 local CC="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600100 shift
101
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700102 local configure_flags="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600103 shift
104
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700105 local run_tests="$1"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700106 shift
107
Gavin Howard8c4780b2019-01-04 12:37:33 -0700108 if [ "$run_tests" -ne 0 ]; then
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700109 header "Running tests with configure flags \"$configure_flags\", CC=\"$CC\", and CFLAGS=\"$CFLAGS\""
Gavin Howard8c4780b2019-01-04 12:37:33 -0700110 else
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700111 header "Building with configure flags \"$configure_flags\", CC=\"$CC\", and CFLAGS=\"$CFLAGS\""
Gavin Howard8c4780b2019-01-04 12:37:33 -0700112 fi
113
Gavin Howardd4fece32019-01-08 02:06:22 -0700114 build "$CFLAGS" "$CC" "$configure_flags"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700115 if [ "$run_tests" -ne 0 ]; then
116 runtest
117 fi
118
Gavin Howardecbee382019-02-01 12:46:26 -0700119 do_make clean
Gavin Howard8c4780b2019-01-04 12:37:33 -0700120
Gavin Howardd4fece32019-01-08 02:06:22 -0700121 build "$CFLAGS" "$CC" "$configure_flags -b"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700122 if [ "$run_tests" -ne 0 ]; then
123 runtest
124 fi
125
Gavin Howardecbee382019-02-01 12:46:26 -0700126 do_make clean
Gavin Howard8c4780b2019-01-04 12:37:33 -0700127
Gavin Howardd4fece32019-01-08 02:06:22 -0700128 build "$CFLAGS" "$CC" "$configure_flags -d"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700129 if [ "$run_tests" -ne 0 ]; then
130 runtest
131 fi
132
Gavin Howardecbee382019-02-01 12:46:26 -0700133 do_make clean
Gavin Howard6e27dec2018-10-24 17:38:34 -0600134}
Gavin Howard4052e032018-10-23 17:22:57 -0600135
Gavin Howard8c4780b2019-01-04 12:37:33 -0700136runtestseries() {
Gavin Howard4052e032018-10-23 17:22:57 -0600137
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700138 local CFLAGS="$1"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700139 shift
Gavin Howard4052e032018-10-23 17:22:57 -0600140
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700141 local CC="$1"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700142 shift
143
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700144 local run_tests="$1"
Gavin Howard8c4780b2019-01-04 12:37:33 -0700145 shift
146
Gavin Howardd4fece32019-01-08 02:06:22 -0700147 runconfigtests "$CFLAGS" "$CC" "" "$run_tests"
148 runconfigtests "$CFLAGS" "$CC" "-E" "$run_tests"
149 runconfigtests "$CFLAGS" "$CC" "-H" "$run_tests"
150 runconfigtests "$CFLAGS" "$CC" "-R" "$run_tests"
151 runconfigtests "$CFLAGS" "$CC" "-S" "$run_tests"
152 runconfigtests "$CFLAGS" "$CC" "-EH" "$run_tests"
153 runconfigtests "$CFLAGS" "$CC" "-ER" "$run_tests"
154 runconfigtests "$CFLAGS" "$CC" "-ES" "$run_tests"
155 runconfigtests "$CFLAGS" "$CC" "-HR" "$run_tests"
156 runconfigtests "$CFLAGS" "$CC" "-HS" "$run_tests"
157 runconfigtests "$CFLAGS" "$CC" "-RS" "$run_tests"
158 runconfigtests "$CFLAGS" "$CC" "-EHR" "$run_tests"
159 runconfigtests "$CFLAGS" "$CC" "-EHS" "$run_tests"
160 runconfigtests "$CFLAGS" "$CC" "-ERS" "$run_tests"
161 runconfigtests "$CFLAGS" "$CC" "-HRS" "$run_tests"
162 runconfigtests "$CFLAGS" "$CC" "-EHRS" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600163}
164
165runtests() {
166
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700167 local CFLAGS="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600168 shift
169
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700170 local CC="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600171 shift
172
Gavin Howardd2143fb2019-01-04 22:00:30 -0700173 local run_tests="$1"
174 shift
175
Gavin Howardd4fece32019-01-08 02:06:22 -0700176 runtestseries "$CFLAGS" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600177}
178
Gavin Howard4052e032018-10-23 17:22:57 -0600179karatsuba() {
180
181 header "Running Karatsuba tests"
Gavin Howardecbee382019-02-01 12:46:26 -0700182 do_make karatsuba_test
Gavin Howard4052e032018-10-23 17:22:57 -0600183}
184
185vg() {
186
187 header "Running valgrind"
188
Gavin Howardd4fece32019-01-08 02:06:22 -0700189 build "$reldebug" "$CC" "-g"
Gavin Howardecbee382019-02-01 12:46:26 -0700190 runtest valgrind
Gavin Howard4052e032018-10-23 17:22:57 -0600191
Gavin Howardecbee382019-02-01 12:46:26 -0700192 do_make clean_config
Gavin Howard4052e032018-10-23 17:22:57 -0600193
Gavin Howardd4fece32019-01-08 02:06:22 -0700194 build "$reldebug" "$CC" "-gb"
Gavin Howardecbee382019-02-01 12:46:26 -0700195 runtest valgrind
Gavin Howard4052e032018-10-23 17:22:57 -0600196
Gavin Howardecbee382019-02-01 12:46:26 -0700197 do_make clean_config
Gavin Howard4052e032018-10-23 17:22:57 -0600198
Gavin Howardd4fece32019-01-08 02:06:22 -0700199 build "$reldebug" "$CC" "-gd"
Gavin Howardecbee382019-02-01 12:46:26 -0700200 runtest valgrind
Gavin Howard4052e032018-10-23 17:22:57 -0600201
Gavin Howardecbee382019-02-01 12:46:26 -0700202 do_make clean_config
Gavin Howard4052e032018-10-23 17:22:57 -0600203}
204
Gavin Howard4052e032018-10-23 17:22:57 -0600205debug() {
206
Gavin Howard6f1aa5a2019-01-04 13:29:04 -0700207 local CC="$1"
Gavin Howard4052e032018-10-23 17:22:57 -0600208 shift
209
Gavin Howardd2143fb2019-01-04 22:00:30 -0700210 local run_tests="$1"
211 shift
212
213 runtests "$debug" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600214
Gavin Howard1522c5a2019-01-05 20:17:40 -0700215 if [ "$CC" = "clang" -a "$run_tests" -ne 0 ]; then
Gavin Howardd2143fb2019-01-04 22:00:30 -0700216 runtests "$debug -fsanitize=address" "$CC" "$run_tests"
217 runtests "$debug -fsanitize=undefined" "$CC" "$run_tests"
218 runtests "$debug -fsanitize=memory" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600219 fi
220}
221
222release() {
Gavin Howardd2143fb2019-01-04 22:00:30 -0700223
224 local CC="$1"
225 shift
226
227 local run_tests="$1"
228 shift
229
230 runtests "$release" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600231}
232
233reldebug() {
Gavin Howardd2143fb2019-01-04 22:00:30 -0700234
235 local CC="$1"
236 shift
237
238 local run_tests="$1"
239 shift
240
241 runtests "$reldebug" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600242}
243
244minsize() {
Gavin Howardd2143fb2019-01-04 22:00:30 -0700245
246 local CC="$1"
247 shift
248
249 local run_tests="$1"
250 shift
251
252 runtests "$minsize" "$CC" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600253}
254
Gavin Howardbffa6c92019-01-11 23:12:19 -0700255clang_flags="-Weverything -Wno-padded -Wno-switch-enum -Wno-format-nonliteral"
256clang_flags="$clang_flags -Wno-cast-align -Wno-missing-noreturn -Wno-disabled-macro-expansion"
257clang_flags="$clang_flags -Wno-unreachable-code -Wno-unreachable-code-return"
258
Gavin Howard6fe912a2019-02-02 12:45:37 -0700259cflags="-Wall -Wextra -Werror -pedantic -std=c99"
Gavin Howarddb6b3fc2019-01-04 21:51:46 -0700260
261debug="$cflags -g -O0 -fno-omit-frame-pointer"
262release="$cflags -DNDEBUG -O3"
263reldebug="$cflags -O3 -g -fno-omit-frame-pointer"
264minsize="$cflags -DNDEBUG -Os"
Gavin Howard4052e032018-10-23 17:22:57 -0600265
266set -e
267
268script="$0"
269scriptdir=$(dirname "$script")
270
Gavin Howard30a203e2019-01-05 19:37:03 -0700271if [ "$#" -gt 0 ]; then
Gavin Howardd2143fb2019-01-04 22:00:30 -0700272 run_tests="$1"
273 shift
274else
275 run_tests=1
276fi
277
278if [ "$#" -gt 0 ]; then
Gavin Howardbbb5ec32019-01-05 19:45:30 -0700279 test_with_gcc="$1"
280 shift
281else
282 test_with_gcc=1
283fi
284
Gavin Howard4052e032018-10-23 17:22:57 -0600285cd "$scriptdir"
286
Gavin Howardb65f0f82019-01-24 16:22:08 -0700287build "$debug" "clang" ""
288
289header "Running math library under --standard"
290
291echo "quit" | bin/bc -ls
Gavin Howardb026ebd2019-01-05 19:44:49 -0700292
Gavin Howard4052e032018-10-23 17:22:57 -0600293version=$(make version)
294
Gavin Howardecbee382019-02-01 12:46:26 -0700295do_make clean_tests
Gavin Howard68f4a4e2019-01-07 17:50:15 -0700296
Gavin Howardd2143fb2019-01-04 22:00:30 -0700297debug "clang" "$run_tests"
298release "clang" "$run_tests"
299reldebug "clang" "$run_tests"
300minsize "clang" "$run_tests"
Gavin Howard4052e032018-10-23 17:22:57 -0600301
Gavin Howard91afc872019-01-05 20:22:37 -0700302if [ "$test_with_gcc" -ne 0 ]; then
Gavin Howardbbb5ec32019-01-05 19:45:30 -0700303 debug "gcc" "$run_tests"
304 release "gcc" "$run_tests"
305 reldebug "gcc" "$run_tests"
306 minsize "gcc" "$run_tests"
307fi
Gavin Howard4052e032018-10-23 17:22:57 -0600308
Gavin Howardd2143fb2019-01-04 22:00:30 -0700309if [ "$run_tests" -ne 0 ]; then
Gavin Howardc7ae8af2019-01-10 09:33:47 -0700310
Gavin Howardecbee382019-02-01 12:46:26 -0700311 build "$release" "clang" ""
Gavin Howardbc8cf8c2019-01-16 11:29:03 -0700312
Gavin Howardd2143fb2019-01-04 22:00:30 -0700313 karatsuba
314 vg
Gavin Howard16208122018-10-24 17:20:45 -0600315
Gavin Howardecbee382019-02-01 12:46:26 -0700316 build "$reldebug" "afl-gcc" ""
Gavin Howardcf614742019-01-05 20:27:16 -0700317
318 printf '\n'
319 printf 'Run %s/tests/randmath.py and the fuzzer.\n' "$scriptdir"
320 printf 'Then run the GitHub release script as follows:\n'
321 printf '\n'
Gavin Howard74d2b8d2019-01-29 12:52:41 -0700322 printf ' <github_release> %s <msg> release.sh RELEASE.md \\\n' "$version"
Gavin Howardc083fad2019-01-09 09:55:09 -0700323 printf ' tests/afl.py tests/randmath.py tests/bc/scripts/timeconst.bc\n'
Gavin Howardcf614742019-01-05 20:27:16 -0700324
325fi