• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
2#
3# SPDX-License-Identifier: BSD-2-Clause
4#
5# Copyright (c) 2018-2021 Gavin D. Howard and contributors.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9#
10# * Redistributions of source code must retain the above copyright notice, this
11#   list of conditions and the following disclaimer.
12#
13# * Redistributions in binary form must reproduce the above copyright notice,
14#   this list of conditions and the following disclaimer in the documentation
15#   and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28#
29
30# For OpenBSD, run using the following:
31#
32# scripts/release.sh 1 0 1 0 0 0 0 1 0 0 0 0
33#
34# For FreeBSD, run using the following:
35#
36# scripts/release.sh 1 0 1 0 0 0 0 1 0 1 0 0
37#
38# There is one problem with running this script on FreeBSD: it takes overcommit
39# to the extreme. This means that some tests that try to create allocation
40# failures instead make bc and dc crash. So running this script on FreeBSD does
41# not work right now.
42#
43# For Linux, run two separate ones (in different checkouts), like so:
44#
45# scripts/release.sh 1 1 1 0 1 0 0 1 0 1 0 1
46# scripts/release.sh 1 1 0 1 0 1 0 1 0 1 0 0
47#
48# Yes, I usually do sanitizers with Clang and Valgrind with GCC.
49#
50# To run sanitizers or Valgrind with generated tests, use the following:
51#
52# scripts/release.sh 1 1 1 0 1 0 0 1 0 1 0 1
53# scripts/release.sh 1 1 0 1 0 1 0 1 0 1 0 0
54#
55# If this script fails on any platform when starting the Karatsuba test, check
56# that Python is installed, especially if the error says something like:
57# "karatsuba.py: not found".
58
59# Print the usage and exit with an error. Each parameter should be an integer.
60# Non-zero activates, and zero deactivates.
61usage() {
62	printf 'usage: %s [run_tests] [generate_tests] [test_with_clang] [test_with_gcc] \n' "$script"
63	printf '          [run_sanitizers] [run_valgrind] [test_settings] [run_64_bit] \n'
64	printf '          [run_gen_script] [test_c11] [test_128_bit] [test_computed_goto]\n'
65	exit 1
66}
67
68# Print a header with a message. This is just to make it easy to track progress.
69# @param msg  The message to print in the header.
70header() {
71
72	_header_msg="$1"
73	shift
74
75	printf '\n'
76	printf '*******************\n'
77	printf "$_header_msg"
78	printf '\n'
79	printf '*******************\n'
80	printf '\n'
81}
82
83# Easy way to call make.
84do_make() {
85	# No reason to do 64 except to see if I actually can overload my system. :)
86	# Well, also that it might actually improve throughput as other jobs can run
87	# while some are waiting.
88	make -j64 "$@"
89}
90
91# Run configure.sh.
92# @param CFLAGS           The CFLAGS.
93# @param CC               The C compiler.
94# @param configure_flags  The flags for configure.sh itself.
95# @param GEN_HOST         The setting for GEN_HOST.
96# @param LONG_BIT         The setting for LONG_BIT.
97configure() {
98
99	_configure_CFLAGS="$1"
100	shift
101
102	_configure_CC="$1"
103	shift
104
105	_configure_configure_flags="$1"
106	shift
107
108	_configure_GEN_HOST="$1"
109	shift
110
111	_configure_LONG_BIT="$1"
112	shift
113
114	# Make sure to not generate tests if necessary.
115	if [ "$gen_tests" -eq 0 ]; then
116		_configure_configure_flags="-G $_configure_configure_flags"
117	fi
118
119	# Choose the right extra flags.
120	if [ "$_configure_CC" = "clang" ]; then
121		_configure_CFLAGS="$clang_flags $_configure_CFLAGS"
122	elif [ "$_configure_CC" = "gcc" ]; then
123		_configure_CFLAGS="$gcc_flags $_configure_CFLAGS"
124	fi
125
126	# Print the header and do the job.
127	_configure_header=$(printf 'Running ./configure.sh %s ...' "$_configure_configure_flags")
128	_configure_header=$(printf "$_configure_header\n    CC=\"%s\"\n" "$_configure_CC")
129	_configure_header=$(printf "$_configure_header\n    CFLAGS=\"%s\"\n" "$_configure_CFLAGS")
130	_configure_header=$(printf "$_configure_header\n    LONG_BIT=%s" "$_configure_LONG_BIT")
131	_configure_header=$(printf "$_configure_header\n    GEN_HOST=%s" "$_configure_GEN_HOST")
132
133	header "$_configure_header"
134	CFLAGS="$_configure_CFLAGS" CC="$_configure_CC" GEN_HOST="$_configure_GEN_HOST" \
135		LONG_BIT="$_configure_LONG_BIT" ./configure.sh $_configure_configure_flags > /dev/null
136}
137
138# Build with make. This function also captures and outputs any warnings if they
139# exists because as far as I am concerned, warnings are not acceptable for
140# release.
141# @param CFLAGS           The CFLAGS.
142# @param CC               The C compiler.
143# @param configure_flags  The flags for configure.sh itself.
144# @param GEN_HOST         The setting for GEN_HOST.
145# @param LONG_BIT         The setting for LONG_BIT.
146build() {
147
148	_build_CFLAGS="$1"
149	shift
150
151	_build_CC="$1"
152	shift
153
154	_build_configure_flags="$1"
155	shift
156
157	_build_GEN_HOST="$1"
158	shift
159
160	_build_LONG_BIT="$1"
161	shift
162
163	configure "$_build_CFLAGS" "$_build_CC" "$_build_configure_flags" "$_build_GEN_HOST" "$_build_LONG_BIT"
164
165	_build_header=$(printf 'Building...\n    CC=%s' "$_build_CC")
166	_build_header=$(printf "$_build_header\n    CFLAGS=\"%s\"" "$_build_CFLAGS")
167	_build_header=$(printf "$_build_header\n    LONG_BIT=%s" "$_build_LONG_BIT")
168	_build_header=$(printf "$_build_header\n    GEN_HOST=%s" "$_build_GEN_HOST")
169
170	header "$_build_header"
171
172	# Capture and print warnings.
173	do_make > /dev/null 2> "$scriptdir/../.test.txt"
174
175	if [ -s "$scriptdir/../.test.txt" ]; then
176		printf '%s generated warning(s):\n' "$_build_CC"
177		printf '\n'
178		cat "$scriptdir/../.test.txt"
179		exit 1
180	fi
181}
182
183# Run tests with make.
184runtest() {
185
186	header "Running tests"
187
188	if [ "$#" -gt 0 ]; then
189		do_make "$@"
190	else
191		do_make test
192	fi
193}
194
195# Builds and runs tests with both calculators, then bc only, then dc only. If
196# run_tests is false, then it just does the builds.
197# @param CFLAGS           The CFLAGS.
198# @param CC               The C compiler.
199# @param configure_flags  The flags for configure.sh itself.
200# @param GEN_HOST         The setting for GEN_HOST.
201# @param LONG_BIT         The setting for LONG_BIT.
202# @param run_tests        Whether to run tests or not.
203runconfigtests() {
204
205	_runconfigtests_CFLAGS="$1"
206	shift
207
208	_runconfigtests_CC="$1"
209	shift
210
211	_runconfigtests_configure_flags="$1"
212	shift
213
214	_runconfigtests_GEN_HOST="$1"
215	shift
216
217	_runconfigtests_LONG_BIT="$1"
218	shift
219
220	_runconfigtests_run_tests="$1"
221	shift
222
223	if [ "$_runconfigtests_run_tests" -ne 0 ]; then
224		_runconfigtests_header=$(printf 'Running tests with configure flags')
225	else
226		_runconfigtests_header=$(printf 'Building with configure flags')
227	fi
228
229	_runconfigtests_header=$(printf "$_runconfigtests_header \"%s\" ...\n" "$_runconfigtests_configure_flags")
230	_runconfigtests_header=$(printf "$_runconfigtests_header\n    CC=%s\n" "$_runconfigseries_CC")
231	_runconfigtests_header=$(printf "$_runconfigtests_header\n    CFLAGS=\"%s\"" "$_runconfigseries_CFLAGS")
232	_runconfigtests_header=$(printf "$_runconfigtests_header\n    LONG_BIT=%s" "$_runconfigtests_LONG_BIT")
233	_runconfigtests_header=$(printf "$_runconfigtests_header\n    GEN_HOST=%s" "$_runconfigtests_GEN_HOST")
234
235	header "$_runconfigtests_header"
236
237	build "$_runconfigtests_CFLAGS" "$_runconfigtests_CC" \
238		"$_runconfigtests_configure_flags" "$_runconfigtests_GEN_HOST" \
239		"$_runconfigtests_LONG_BIT"
240
241	if [ "$_runconfigtests_run_tests" -ne 0 ]; then
242		runtest
243	fi
244
245	do_make clean
246
247	build "$_runconfigtests_CFLAGS" "$_runconfigtests_CC" \
248		"$_runconfigtests_configure_flags -b" "$_runconfigtests_GEN_HOST" \
249		"$_runconfigtests_LONG_BIT"
250
251	if [ "$_runconfigtests_run_tests" -ne 0 ]; then
252		runtest
253	fi
254
255	do_make clean
256
257	build "$_runconfigtests_CFLAGS" "$_runconfigtests_CC" \
258		"$_runconfigtests_configure_flags -d" "$_runconfigtests_GEN_HOST" \
259		"$_runconfigtests_LONG_BIT"
260
261	if [ "$_runconfigtests_run_tests" -ne 0 ]; then
262		runtest
263	fi
264
265	do_make clean
266}
267
268# Builds and runs tests with runconfigtests(), but also does 64-bit, 32-bit, and
269# 128-bit rand, if requested. It also does it with the gen script (strgen.sh) if
270# requested. If run_tests is false, it just does the builds.
271# @param CFLAGS           The CFLAGS.
272# @param CC               The C compiler.
273# @param configure_flags  The flags for configure.sh itself.
274# @param run_tests        Whether to run tests or not.
275runconfigseries() {
276
277	_runconfigseries_CFLAGS="$1"
278	shift
279
280	_runconfigseries_CC="$1"
281	shift
282
283	_runconfigseries_configure_flags="$1"
284	shift
285
286	_runconfigseries_run_tests="$1"
287	shift
288
289	if [ "$run_64_bit" -ne 0 ]; then
290
291		if [ "$test_128_bit" -ne 0 ]; then
292			runconfigtests "$_runconfigseries_CFLAGS" "$_runconfigseries_CC" \
293				"$_runconfigseries_configure_flags" 1 64 "$_runconfigseries_run_tests"
294		fi
295
296		if [ "$run_gen_script" -ne 0 ]; then
297			runconfigtests "$_runconfigseries_CFLAGS" "$_runconfigseries_CC" \
298				"$_runconfigseries_configure_flags" 0 64 "$_runconfigseries_run_tests"
299		fi
300
301		runconfigtests "$_runconfigseries_CFLAGS -DBC_RAND_BUILTIN=0" "$_runconfigseries_CC" \
302			"$_runconfigseries_configure_flags" 1 64 "$_runconfigseries_run_tests"
303
304	fi
305
306	runconfigtests "$_runconfigseries_CFLAGS" "$_runconfigseries_CC" \
307		"$_runconfigseries_configure_flags" 1 32 "$_runconfigseries_run_tests"
308
309	if [ "$run_gen_script" -ne 0 ]; then
310		runconfigtests "$_runconfigseries_CFLAGS" "$_runconfigseries_CC" \
311			"$_runconfigseries_configure_flags" 0 32 "$_runconfigseries_run_tests"
312	fi
313}
314
315# Builds and runs tests with each setting combo running runconfigseries(). If
316# run_tests is false, it just does the builds.
317# @param CFLAGS           The CFLAGS.
318# @param CC               The C compiler.
319# @param configure_flags  The flags for configure.sh itself.
320# @param run_tests        Whether to run tests or not.
321runsettingsseries() {
322
323	_runsettingsseries_CFLAGS="$1"
324	shift
325
326	_runsettingsseries_CC="$1"
327	shift
328
329	_runsettingsseries_configure_flags="$1"
330	shift
331
332	_runsettingsseries_run_tests="$1"
333	shift
334
335	if [ "$test_settings" -ne 0 ]; then
336
337		while read _runsettingsseries_s; do
338			runconfigseries "$_runsettingsseries_CFLAGS" "$_runsettingsseries_CC" \
339				"$_runsettingsseries_configure_flags $_runsettingsseries_s" \
340				"$_runsettingsseries_run_tests"
341		done < "$scriptdir/release_settings.txt"
342
343	else
344		runconfigseries "$_runsettingsseries_CFLAGS" "$_runsettingsseries_CC" \
345			"$_runsettingsseries_configure_flags" "$_runsettingsseries_run_tests"
346	fi
347}
348
349# Builds and runs tests with each build type running runsettingsseries(). If
350# run_tests is false, it just does the builds.
351# @param CFLAGS           The CFLAGS.
352# @param CC               The C compiler.
353# @param configure_flags  The flags for configure.sh itself.
354# @param run_tests        Whether to run tests or not.
355runtestseries() {
356
357	_runtestseries_CFLAGS="$1"
358	shift
359
360	_runtestseries_CC="$1"
361	shift
362
363	_runtestseries_configure_flags="$1"
364	shift
365
366	_runtestseries_run_tests="$1"
367	shift
368
369	_runtestseries_flags="E H N EH EN HN EHN"
370
371	runsettingsseries "$_runtestseries_CFLAGS" "$_runtestseries_CC" \
372		"$_runtestseries_configure_flags" "$_runtestseries_run_tests"
373
374	for _runtestseries_f in $_runtestseries_flags; do
375		runsettingsseries "$_runtestseries_CFLAGS" "$_runtestseries_CC" \
376			"$_runtestseries_configure_flags -$_runtestseries_f" "$_runtestseries_run_tests"
377	done
378}
379
380# Builds and runs the tests for bcl. If run_tests is false, it just does the
381# builds.
382# @param CFLAGS           The CFLAGS.
383# @param CC               The C compiler.
384# @param configure_flags  The flags for configure.sh itself.
385# @param run_tests        Whether to run tests or not.
386runlibtests() {
387
388	_runlibtests_CFLAGS="$1"
389	shift
390
391	_runlibtests_CC="$1"
392	shift
393
394	_runlibtests_configure_flags="$1"
395	shift
396
397	_runlibtests_run_tests="$1"
398	shift
399
400	_runlibtests_configure_flags="$_runlibtests_configure_flags -a"
401
402	build "$_runlibtests_CFLAGS" "$_runlibtests_CC" "$_runlibtests_configure_flags" 1 64
403
404	if [ "$_runlibtests_run_tests" -ne 0 ]; then
405		runtest
406	fi
407
408	build "$_runlibtests_CFLAGS" "$_runlibtests_CC" "$_runlibtests_configure_flags" 1 32
409
410	if [ "$_runlibtests_run_tests" -ne 0 ]; then
411		runtest
412	fi
413}
414
415# Builds and runs tests under C99, then C11, if requested, using
416# runtestseries(). If run_tests is false, it just does the builds.
417# @param CFLAGS           The CFLAGS.
418# @param CC               The C compiler.
419# @param configure_flags  The flags for configure.sh itself.
420# @param run_tests        Whether to run tests or not.
421runtests() {
422
423	_runtests_CFLAGS="$1"
424	shift
425
426	_runtests_CC="$1"
427	shift
428
429	_runtests_configure_flags="$1"
430	shift
431
432	_runtests_run_tests="$1"
433	shift
434
435	runtestseries "-std=c99 $_runtests_CFLAGS" "$_runtests_CC" "$_runtests_configure_flags" "$_runtests_run_tests"
436
437	if [ "$test_c11" -ne 0 ]; then
438		runtestseries "-std=c11 $_runtests_CFLAGS" "$_runtests_CC" "$_runtests_configure_flags" "$_runtests_run_tests"
439	fi
440}
441
442# Runs the karatsuba tests.
443karatsuba() {
444
445	header "Running Karatsuba tests"
446	do_make karatsuba_test
447}
448
449# Builds and runs under valgrind. It runs both, bc only, then dc only.
450vg() {
451
452	header "Running valgrind"
453
454	if [ "$run_64_bit" -ne 0 ]; then
455		_vg_bits=64
456	else
457		_vg_bits=32
458	fi
459
460	build "$debug -std=c99" "gcc" "-O3 -gv" "1" "$_vg_bits"
461	runtest test
462
463	do_make clean_config
464
465	build "$debug -std=c99" "gcc" "-O3 -gvb" "1" "$_vg_bits"
466	runtest test
467
468	do_make clean_config
469
470	build "$debug -std=c99" "gcc" "-O3 -gvd" "1" "$_vg_bits"
471	runtest test
472
473	do_make clean_config
474
475	build "$debug -std=c99" "gcc" "-O3 -gva" "1" "$_vg_bits"
476	runtest test
477
478	do_make clean_config
479}
480
481# Builds the debug series and runs the tests if run_tests allows. If sanitizers
482# are enabled, it also does UBSan.
483# @param CC         The C compiler.
484# @param run_tests  Whether to run tests or not.
485debug() {
486
487	_debug_CC="$1"
488	shift
489
490	_debug_run_tests="$1"
491	shift
492
493
494	if [ "$_debug_CC" = "clang" -a "$run_sanitizers" -ne 0 ]; then
495		runtests "$debug -fsanitize=undefined" "$_debug_CC" "-gm" "$_debug_run_tests"
496	else
497		runtests "$debug" "$_debug_CC" "-g" "$_debug_run_tests"
498	fi
499
500
501	if [ "$_debug_CC" = "clang" -a "$run_sanitizers" -ne 0 ]; then
502		runlibtests "$debug -fsanitize=undefined" "$_debug_CC" "-gm" "$_debug_run_tests"
503	else
504		runlibtests "$debug" "$_debug_CC" "-g" "$_debug_run_tests"
505	fi
506}
507
508# Builds the release series and runs the test if run_tests allows.
509# @param CC         The C compiler.
510# @param run_tests  Whether to run tests or not.
511release() {
512
513	_release_CC="$1"
514	shift
515
516	_release_run_tests="$1"
517	shift
518
519	runtests "$release" "$_release_CC" "-O3" "$_release_run_tests"
520
521	runlibtests "$release" "$_release_CC" "-O3" "$_release_run_tests"
522}
523
524# Builds the release debug series and runs the test if run_tests allows. If
525# sanitizers are enabled, it also does ASan and MSan.
526# @param CC         The C compiler.
527# @param run_tests  Whether to run tests or not.
528reldebug() {
529
530	_reldebug_CC="$1"
531	shift
532
533	_reldebug_run_tests="$1"
534	shift
535
536
537	if [ "$_reldebug_CC" = "clang" -a "$run_sanitizers" -ne 0 ]; then
538		runtests "$debug -fsanitize=address" "$_reldebug_CC" "-mgO3" "$_reldebug_run_tests"
539		runtests "$debug -fsanitize=memory" "$_reldebug_CC" "-mgO3" "$_reldebug_run_tests"
540	else
541		runtests "$debug" "$_reldebug_CC" "-gO3" "$_reldebug_run_tests"
542	fi
543
544
545	if [ "$_reldebug_CC" = "clang" -a "$run_sanitizers" -ne 0 ]; then
546		runlibtests "$debug -fsanitize=address" "$_reldebug_CC" "-mgO3" "$_reldebug_run_tests"
547		runlibtests "$debug -fsanitize=memory" "$_reldebug_CC" "-mgO3" "$_reldebug_run_tests"
548	else
549		runlibtests "$debug" "$_reldebug_CC" "-gO3" "$_reldebug_run_tests"
550	fi
551}
552
553# Builds the min size release series and runs the test if run_tests allows.
554# @param CC         The C compiler.
555# @param run_tests  Whether to run tests or not.
556minsize() {
557
558	_minsize_CC="$1"
559	shift
560
561	_minsize_run_tests="$1"
562	shift
563
564	runtests "$release" "$_minsize_CC" "-Os" "$_minsize_run_tests"
565
566	runlibtests "$release" "$_minsize_CC" "-Os" "$_minsize_run_tests"
567}
568
569# Builds all sets: debug, release, release debug, and min size, and runs the
570# tests if run_tests allows.
571# @param CC         The C compiler.
572# @param run_tests  Whether to run tests or not.
573build_set() {
574
575	_build_set_CC="$1"
576	shift
577
578	_build_set_run_tests="$1"
579	shift
580
581	debug "$_build_set_CC" "$_build_set_run_tests"
582	release "$_build_set_CC" "$_build_set_run_tests"
583	reldebug "$_build_set_CC" "$_build_set_run_tests"
584	minsize "$_build_set_CC" "$_build_set_run_tests"
585}
586
587# Set some strict warning flags. Clang's -Weverything can be way too strict, so
588# we actually have to turn off some things.
589clang_flags="-Weverything -Wno-padded -Wno-switch-enum -Wno-format-nonliteral"
590clang_flags="$clang_flags -Wno-cast-align -Wno-missing-noreturn -Wno-disabled-macro-expansion"
591clang_flags="$clang_flags -Wno-unreachable-code -Wno-unreachable-code-return"
592clang_flags="$clang_flags -Wno-implicit-fallthrough -Wno-unused-macros -Wno-gnu-label-as-value"
593gcc_flags="-Wno-maybe-uninitialized -Wno-clobbered"
594
595# Common CFLAGS.
596cflags="-Wall -Wextra -Werror -pedantic -Wno-conditional-uninitialized"
597
598# Common debug and release flags.
599debug="$cflags -fno-omit-frame-pointer"
600release="$cflags -DNDEBUG"
601
602set -e
603
604script="$0"
605scriptdir=$(dirname "$script")
606
607# Whether to run tests.
608if [ "$#" -gt 0 ]; then
609	run_tests="$1"
610	shift
611else
612	run_tests=1
613fi
614
615# Whether to generate tests. On platforms like OpenBSD, there is no GNU bc to
616# generate tests, so this must be off.
617if [ "$#" -gt 0 ]; then
618	gen_tests="$1"
619	shift
620else
621	gen_tests=1
622fi
623
624# Whether to test with clang.
625if [ "$#" -gt 0 ]; then
626	test_with_clang="$1"
627	shift
628else
629	test_with_clang=1
630fi
631
632# Whether to test with gcc.
633if [ "$#" -gt 0 ]; then
634	test_with_gcc="$1"
635	shift
636else
637	test_with_gcc=1
638fi
639
640# Whether to test with sanitizers.
641if [ "$#" -gt 0 ]; then
642	run_sanitizers="$1"
643	shift
644else
645	run_sanitizers=1
646fi
647
648# Whether to test with valgrind.
649if [ "$#" -gt 0 ]; then
650	run_valgrind="$1"
651	shift
652else
653	run_valgrind=1
654fi
655
656# Whether to test all settings combos.
657if [ "$#" -gt 0 ]; then
658	test_settings="$1"
659	shift
660else
661	test_settings=1
662fi
663
664# Whether to test 64-bit in addition to 32-bit.
665if [ "$#" -gt 0 ]; then
666	run_64_bit="$1"
667	shift
668else
669	run_64_bit=1
670fi
671
672# Whether to test with strgen.sh in addition to strgen.c.
673if [ "$#" -gt 0 ]; then
674	run_gen_script="$1"
675	shift
676else
677	run_gen_script=0
678fi
679
680# Whether to test on C11 in addition to C99.
681if [ "$#" -gt 0 ]; then
682	test_c11="$1"
683	shift
684else
685	test_c11=0
686fi
687
688# Whether to test 128-bit integers in addition to no 128-bit integers.
689if [ "$#" -gt 0 ]; then
690	test_128_bit="$1"
691	shift
692else
693	test_128_bit=0
694fi
695
696# Whether to test with computed goto or not.
697if [ "$#" -gt 0 ]; then
698	test_computed_goto="$1"
699	shift
700else
701	test_computed_goto=0
702fi
703
704if [ "$run_64_bit" -ne 0 ]; then
705	bits=64
706else
707	bits=32
708fi
709
710if [ "$test_computed_goto" -eq 0 ]; then
711	clang_flags="-DBC_NO_COMPUTED_GOTO $clang_flags"
712	gcc_flags="-DBC_NO_COMPUTED_GOTO $gcc_flags"
713fi
714
715cd "$scriptdir/.."
716
717# Setup a default compiler.
718if [ "$test_with_clang" -ne 0 ]; then
719	defcc="clang"
720elif [ "$test_with_gcc" -ne 0 ]; then
721	defcc="gcc"
722else
723	defcc="c99"
724fi
725
726export ASAN_OPTIONS="abort_on_error=1,allocator_may_return_null=1"
727export UBSAN_OPTIONS="print_stack_trace=1,silence_unsigned_overflow=1"
728
729build "$debug -std=c99" "$defcc" "-g" "1" "$bits"
730
731header "Running math library under --standard"
732
733# Make sure the math library is POSIX compliant.
734printf 'quit\n' | bin/bc -ls
735
736do_make clean_tests
737
738# Run the clang build sets.
739if [ "$test_with_clang" -ne 0 ]; then
740	build_set "clang" "$run_tests"
741fi
742
743# Run the gcc build sets.
744if [ "$test_with_gcc" -ne 0 ]; then
745	build_set "gcc" "$run_tests"
746fi
747
748if [ "$run_tests" -ne 0 ]; then
749
750	build "$release" "$defcc" "-O3" "1" "$bits"
751
752	# Run karatsuba.
753	karatsuba
754
755	# Valgrind.
756	if [ "$run_valgrind" -ne 0 -a "$test_with_gcc" -ne 0 ]; then
757		vg
758	fi
759
760	printf '\n'
761	printf 'Tests successful.\n'
762
763	# I just assume that I am going to be fuzzing when I am done.
764	header "Building for AFL++..."
765
766	"$scriptdir/fuzz_prep.sh"
767
768	printf '\n'
769	printf 'Ready for scripts/randmath.py and for fuzzing.\n'
770	printf '\n'
771	printf 'Run scripts/randmath.py if you changed any math code.\n'
772	printf '\n'
773	printf 'Then if there are no problems, run the fuzzer.\n'
774	printf '\n'
775	printf 'Then run `scripts/fuzz_prep.sh -a`.\n'
776	printf '\n'
777	printf 'Then run `scripts/afl.py --asan`.\n'
778
779fi
780