diff options
Diffstat (limited to 'scripts/release.sh')
-rwxr-xr-x | scripts/release.sh | 242 |
1 files changed, 186 insertions, 56 deletions
diff --git a/scripts/release.sh b/scripts/release.sh index 638161f8..d383896f 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: BSD-2-Clause # -# Copyright (c) 2018-2021 Gavin D. Howard and contributors. +# Copyright (c) 2018-2023 Gavin D. Howard and contributors. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -29,28 +29,23 @@ # For OpenBSD, run using the following: # -# scripts/release.sh 1 0 1 0 0 0 0 1 0 0 0 0 +# scripts/release.sh 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 # # For FreeBSD, run using the following: # -# scripts/release.sh 1 0 1 0 0 0 0 1 0 1 0 0 -# -# There is one problem with running this script on FreeBSD: it takes overcommit -# to the extreme. This means that some tests that try to create allocation -# failures instead make bc and dc crash. So running this script on FreeBSD does -# not work right now. +# scripts/release.sh 1 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 1 # # For Linux, run two separate ones (in different checkouts), like so: # -# scripts/release.sh 1 1 1 0 1 0 0 1 0 1 0 1 -# scripts/release.sh 1 1 0 1 0 1 0 1 0 1 0 0 -# -# Yes, I usually do sanitizers with Clang and Valgrind with GCC. +# scripts/release.sh 1 1 1 1 0 1 0 0 1 0 1 0 1 0 0 1 1 +# cd build; ../scripts/release.sh 1 1 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 # -# To run sanitizers or Valgrind with generated tests, use the following: +# Yes, I usually do sanitizers with Clang and Valgrind with GCC, and I also do +# out-of-source builds with GCC. # -# scripts/release.sh 1 1 1 0 1 0 0 1 0 1 0 1 -# scripts/release.sh 1 1 0 1 0 1 0 1 0 1 0 0 +# The reason I run history tests with GCC and not with Clang is because Clang +# already runs slower as a result of running with sanitizers, and the history +# tests are a little sensitive to load on a system. # # If this script fails on any platform when starting the Karatsuba test, check # that Python is installed, especially if the error says something like: @@ -58,10 +53,16 @@ # Print the usage and exit with an error. Each parameter should be an integer. # Non-zero activates, and zero deactivates. +# @param 1 A message to print. usage() { - printf 'usage: %s [run_tests] [generate_tests] [test_with_clang] [test_with_gcc] \n' "$script" - printf ' [run_sanitizers] [run_valgrind] [test_settings] [run_64_bit] \n' - printf ' [run_gen_script] [test_c11] [test_128_bit] [test_computed_goto]\n' + if [ $# -eq 1 ]; then + printf '%s\n\n' "$1" + fi + printf 'usage: %s [run_tests] [generate_tests] [run_problematic_tests] \n' "$script" + printf ' [test_with_clang] [test_with_gcc] [run_sanitizers] [run_valgrind] \n' + printf ' [test_settings] [run_64_bit] [run_gen_script] [test_c11] \n' + printf ' [test_128_bit] [test_computed_goto] [test_karatsuba] [test_history] \n' + printf ' [test_editline] [test_readline]\n' exit 1 } @@ -116,15 +117,38 @@ configure() { _configure_configure_flags="-G $_configure_configure_flags" fi + # Make sure to skip problematic tests if necessary. + if [ "$problematic_tests" -eq 0 ]; then + _configure_configure_flags="-P $_configure_configure_flags" + fi + # Choose the right extra flags. if [ "$_configure_CC" = "clang" ]; then + _configure_CFLAGS="$clang_flags $_configure_CFLAGS" + + # We need to quiet this warning from Clang because the configure.sh docs + # have this warning, so people should know. Also, I want this script to + # work. + if [ "$_configure_GEN_HOST" -eq 0 ]; then + _configure_CFLAGS="$_configure_CFLAGS -Wno-overlength-strings" + fi + elif [ "$_configure_CC" = "gcc" ]; then + _configure_CFLAGS="$gcc_flags $_configure_CFLAGS" + + # We need to quiet this warning from GCC because the configure.sh docs + # have this warning, so people should know. Also, I want this script to + # work. + if [ "$_configure_GEN_HOST" -eq 0 ]; then + _configure_CFLAGS="$_configure_CFLAGS -Wno-overlength-strings" + fi + fi # Print the header and do the job. - _configure_header=$(printf 'Running ./configure.sh %s ...' "$_configure_configure_flags") + _configure_header=$(printf 'Running configure.sh %s ...' "$_configure_configure_flags") _configure_header=$(printf "$_configure_header\n CC=\"%s\"\n" "$_configure_CC") _configure_header=$(printf "$_configure_header\n CFLAGS=\"%s\"\n" "$_configure_CFLAGS") _configure_header=$(printf "$_configure_header\n LONG_BIT=%s" "$_configure_LONG_BIT") @@ -132,7 +156,7 @@ configure() { header "$_configure_header" CFLAGS="$_configure_CFLAGS" CC="$_configure_CC" GEN_HOST="$_configure_GEN_HOST" \ - LONG_BIT="$_configure_LONG_BIT" ./configure.sh $_configure_configure_flags > /dev/null + LONG_BIT="$_configure_LONG_BIT" "$real/configure.sh" $_configure_configure_flags > /dev/null } # Build with make. This function also captures and outputs any warnings if they @@ -169,15 +193,24 @@ build() { header "$_build_header" + set +e + # Capture and print warnings. - do_make > /dev/null 2> "$scriptdir/../.test.txt" + do_make > /dev/null 2> "./.test.txt" + err=$? + + set -e - if [ -s "$scriptdir/../.test.txt" ]; then + if [ -s "./.test.txt" ]; then printf '%s generated warning(s):\n' "$_build_CC" printf '\n' - cat "$scriptdir/../.test.txt" + cat "./.test.txt" exit 1 fi + + if [ "$err" -ne 0 ]; then + exit "$err" + fi } # Run tests with make. @@ -188,7 +221,12 @@ runtest() { if [ "$#" -gt 0 ]; then do_make "$@" else + do_make test + + if [ "$test_history" -ne 0 ]; then + do_make test_history + fi fi } @@ -301,6 +339,21 @@ runconfigseries() { runconfigtests "$_runconfigseries_CFLAGS -DBC_RAND_BUILTIN=0" "$_runconfigseries_CC" \ "$_runconfigseries_configure_flags" 1 64 "$_runconfigseries_run_tests" + # Test Editline and Readline if history is not turned off. + if [ "${_runconfigseries_configure_flags#*H}" = "${_runconfigseries_configure_flags}" ]; then + + if [ "$test_editline" -ne 0 ]; then + runconfigtests "$_runconfigseries_CFLAGS -DBC_RAND_BUILTIN=0" "$_runconfigseries_CC" \ + "$_runconfigseries_configure_flags -e" 1 64 "$_runconfigseries_run_tests" + fi + + if [ "$test_readline" -ne 0 ]; then + runconfigtests "$_runconfigseries_CFLAGS -DBC_RAND_BUILTIN=0" "$_runconfigseries_CC" \ + "$_runconfigseries_configure_flags -r" 1 64 "$_runconfigseries_run_tests" + fi + + fi + fi runconfigtests "$_runconfigseries_CFLAGS" "$_runconfigseries_CC" \ @@ -402,13 +455,13 @@ runlibtests() { build "$_runlibtests_CFLAGS" "$_runlibtests_CC" "$_runlibtests_configure_flags" 1 64 if [ "$_runlibtests_run_tests" -ne 0 ]; then - runtest + runtest test fi build "$_runlibtests_CFLAGS" "$_runlibtests_CC" "$_runlibtests_configure_flags" 1 32 if [ "$_runlibtests_run_tests" -ne 0 ]; then - runtest + runtest test fi } @@ -497,7 +550,6 @@ debug() { runtests "$debug" "$_debug_CC" "-g" "$_debug_run_tests" fi - if [ "$_debug_CC" = "clang" -a "$run_sanitizers" -ne 0 ]; then runlibtests "$debug -fsanitize=undefined" "$_debug_CC" "-gm" "$_debug_run_tests" else @@ -584,32 +636,54 @@ build_set() { minsize "$_build_set_CC" "$_build_set_run_tests" } +set -e + +script="$0" +scriptdir=$(dirname "$script") + +. "$scriptdir/functions.sh" + +# Unset all bc and dc environment variables. This is intended to allow this +# script to run in a clean environment. +unset POSIXLY_CORRECT +unset BC_BANNER +unset BC_ENV_ARGS +unset DC_ENV_ARGS +unset BC_LINE_LENGTH +unset DC_LINE_LENGTH +unset BC_SIGINT_RESET +unset DC_SIGINT_RESET +unset BC_TTY_MODE +unset DC_TTY_MODE +unset BC_PROMPT +unset DC_PROMPT +unset BC_EXPR_EXIT +unset DC_EXPR_EXIT +unset BC_DIGIT_CLAMP +unset DC_DIGIT_CLAMP + # Set some strict warning flags. Clang's -Weverything can be way too strict, so # we actually have to turn off some things. -clang_flags="-Weverything -Wno-padded -Wno-switch-enum -Wno-format-nonliteral" -clang_flags="$clang_flags -Wno-cast-align -Wno-missing-noreturn -Wno-disabled-macro-expansion" -clang_flags="$clang_flags -Wno-unreachable-code -Wno-unreachable-code-return" -clang_flags="$clang_flags -Wno-implicit-fallthrough -Wno-unused-macros -Wno-gnu-label-as-value" -gcc_flags="-Wno-maybe-uninitialized -Wno-clobbered" +clang_flags="-Weverything -Wno-padded" +gcc_flags="-Wno-clobbered" # Common CFLAGS. -cflags="-Wall -Wextra -Werror -pedantic -Wno-conditional-uninitialized" +cflags="-Wall -Wextra -Werror -pedantic" # Common debug and release flags. debug="$cflags -fno-omit-frame-pointer" release="$cflags -DNDEBUG" -set -e - -script="$0" -scriptdir=$(dirname "$script") +real=$(realpath "$scriptdir/../") # Whether to run tests. if [ "$#" -gt 0 ]; then run_tests="$1" shift + check_bool_arg "$run_tests" else run_tests=1 + check_bool_arg "$run_tests" fi # Whether to generate tests. On platforms like OpenBSD, there is no GNU bc to @@ -617,88 +691,160 @@ fi if [ "$#" -gt 0 ]; then gen_tests="$1" shift + check_bool_arg "$gen_tests" else gen_tests=1 + check_bool_arg "$gen_tests" +fi + +# Whether to run problematic tests. This needs to be off on FreeBSD. +if [ "$#" -gt 0 ]; then + problematic_tests="$1" + shift + check_bool_arg "$problematic_tests" +else + problematic_tests=1 + check_bool_arg "$problematic_tests" fi # Whether to test with clang. if [ "$#" -gt 0 ]; then test_with_clang="$1" shift + check_bool_arg "$test_with_clang" else test_with_clang=1 + check_bool_arg "$test_with_clang" fi # Whether to test with gcc. if [ "$#" -gt 0 ]; then test_with_gcc="$1" shift + check_bool_arg "$test_with_gcc" else test_with_gcc=1 + check_bool_arg "$test_with_clang" fi # Whether to test with sanitizers. if [ "$#" -gt 0 ]; then run_sanitizers="$1" + check_bool_arg "$run_sanitizers" shift else run_sanitizers=1 + check_bool_arg "$run_sanitizers" fi # Whether to test with valgrind. if [ "$#" -gt 0 ]; then run_valgrind="$1" shift + check_bool_arg "$run_valgrind" else run_valgrind=1 + check_bool_arg "$run_valgrind" fi # Whether to test all settings combos. if [ "$#" -gt 0 ]; then test_settings="$1" shift + check_bool_arg "$test_settings" else test_settings=1 + check_bool_arg "$test_settings" fi # Whether to test 64-bit in addition to 32-bit. if [ "$#" -gt 0 ]; then run_64_bit="$1" shift + check_bool_arg "$run_64_bit" else run_64_bit=1 + check_bool_arg "$run_64_bit" fi # Whether to test with strgen.sh in addition to strgen.c. if [ "$#" -gt 0 ]; then run_gen_script="$1" shift + check_bool_arg "$run_gen_script" else run_gen_script=0 + check_bool_arg "$run_gen_script" fi # Whether to test on C11 in addition to C99. if [ "$#" -gt 0 ]; then test_c11="$1" shift + check_bool_arg "$test_c11" else test_c11=0 + check_bool_arg "$test_c11" fi # Whether to test 128-bit integers in addition to no 128-bit integers. if [ "$#" -gt 0 ]; then test_128_bit="$1" shift + check_bool_arg "$test_128_bit" else test_128_bit=0 + check_bool_arg "$test_128_bit" fi # Whether to test with computed goto or not. if [ "$#" -gt 0 ]; then test_computed_goto="$1" shift + check_bool_arg "$test_computed_goto" else test_computed_goto=0 + check_bool_arg "$test_computed_goto" +fi + +# Whether to test history or not. +if [ "$#" -gt 0 ]; then + test_karatsuba="$1" + shift + check_bool_arg "$test_karatsuba" +else + test_karatsuba=1 + check_bool_arg "$test_karatsuba" +fi + +# Whether to test history or not. +if [ "$#" -gt 0 ]; then + test_history="$1" + shift + check_bool_arg "$test_history" +else + test_history=0 + check_bool_arg "$test_history" +fi + +# Whether to test editline or not. +if [ "$#" -gt 0 ]; then + test_editline="$1" + shift + check_bool_arg "$test_editline" +else + test_editline=0 + check_bool_arg "$test_editline" +fi + +# Whether to test editline or not. +if [ "$#" -gt 0 ]; then + test_readline="$1" + shift + check_bool_arg "$test_readline" +else + test_readline=0 + check_bool_arg "$test_readline" fi if [ "$run_64_bit" -ne 0 ]; then @@ -712,8 +858,6 @@ if [ "$test_computed_goto" -eq 0 ]; then gcc_flags="-DBC_NO_COMPUTED_GOTO $gcc_flags" fi -cd "$scriptdir/.." - # Setup a default compiler. if [ "$test_with_clang" -ne 0 ]; then defcc="clang" @@ -723,7 +867,7 @@ else defcc="c99" fi -export ASAN_OPTIONS="abort_on_error=1,allocator_may_return_null=1" +export ASAN_OPTIONS="abort_on_error=1,allocator_may_return_null=1:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:detect_invalid_pointer_pairs=2" export UBSAN_OPTIONS="print_stack_trace=1,silence_unsigned_overflow=1" build "$debug -std=c99" "$defcc" "-g" "1" "$bits" @@ -750,7 +894,9 @@ if [ "$run_tests" -ne 0 ]; then build "$release" "$defcc" "-O3" "1" "$bits" # Run karatsuba. - karatsuba + if [ "$test_karatsuba" -ne 0 ]; then + karatsuba + fi # Valgrind. if [ "$run_valgrind" -ne 0 -a "$test_with_gcc" -ne 0 ]; then @@ -760,20 +906,4 @@ if [ "$run_tests" -ne 0 ]; then printf '\n' printf 'Tests successful.\n' - # I just assume that I am going to be fuzzing when I am done. - header "Building for AFL++..." - - "$scriptdir/fuzz_prep.sh" - - printf '\n' - printf 'Ready for scripts/randmath.py and for fuzzing.\n' - printf '\n' - printf 'Run scripts/randmath.py if you changed any math code.\n' - printf '\n' - printf 'Then if there are no problems, run the fuzzer.\n' - printf '\n' - printf 'Then run `scripts/fuzz_prep.sh -a`.\n' - printf '\n' - printf 'Then run `scripts/afl.py --asan`.\n' - fi |