From ce82b05eb294f1f35cd95d476d05233404c3cf28 Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Thu, 29 Jun 2023 17:21:53 -0700 Subject: [PATCH] scripts: misc fixes - POSIX/posix-cflags.sh: replace ${NEED_STD_C99} with ${CFLAGS_C99} to better represent what this variable means. In particular, since it's going to be used to construct a command line, it should not be quoted. (At the moment, the only possible values of that variable are "" or "-std=c99", so it wouldn't matter if we double-quoted it. However, in theory there might be some compiler which required additional arguments in order to set it to c99 mode.) - tests/shared_test_functions.sh: add ${s_count_str} as a "global" variable. Add a list of "public API" functions. - tests/shared_valgrind_functions.sh: use ${s_count_str}. Also, import valgrind_incomplete() to support wait_while with servers. - tests/18-warnp.sh: don't use $(...), because we don't want to run the output of check_output. All we want is the exit code, so (...) is the correct construct. - apisupport/, cpusupport/, release-tools/: add newlines to separate code paragraphs. --- POSIX/posix-cflags.sh | 8 ++++---- apisupport/Build/apisupport.sh | 1 + cpusupport/Build/cpusupport.sh | 1 + release-tools/metabuild.sh | 1 + tests/18-warnp.sh | 2 +- tests/shared_test_functions.sh | 19 ++++++++++++++++--- tests/shared_valgrind_functions.sh | 16 +++++++++++++++- 7 files changed, 39 insertions(+), 9 deletions(-) diff --git a/POSIX/posix-cflags.sh b/POSIX/posix-cflags.sh index e039bcd8..5810da3a 100644 --- a/POSIX/posix-cflags.sh +++ b/POSIX/posix-cflags.sh @@ -78,19 +78,19 @@ if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 "$D/posix-sta printf %s "-DPOSIXFAIL_STAT_ST_MTIM" echo "WARNING: POSIX violation: struct stat does not contain st_mtim" 1>&2 fi -NEED_STD_C99="" +CFLAGS_C99="" if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "$D/posix-restrict.c" 2>/dev/null; then echo "WARNING: POSIX violation: ${CC} does not accept the 'restrict' keyword" 1>&2 if ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -std=c99 "$D/posix-restrict.c" 2>/dev/null; then [ ${FIRST} = "NO" ] && printf " "; FIRST=NO printf %s "-std=c99" - NEED_STD_C99="-std=c99" + CFLAGS_C99="-std=c99" fi fi -if ! ${CC} ${CFLAGS} ${NEED_STD_C99} -D_POSIX_C_SOURCE=200809L -DARGNAME="" "$D/posix-abstract-declarator.c" 2>/dev/null; then +if ! ${CC} ${CFLAGS} ${CFLAGS_C99} -D_POSIX_C_SOURCE=200809L -DARGNAME="" "$D/posix-abstract-declarator.c" 2>/dev/null; then echo "WARNING: POSIX violation: ${CC} does not accept qualifiers in an abstract declarator" 1>&2 # Test compile with -DPOSIXFAIL_ABSTRACT_DECLARATOR - if ${CC} ${CFLAGS} ${NEED_STD_C99} -D_POSIX_C_SOURCE=200809L -DPOSIXFAIL_ABSTRACT_DECLARATOR "$D/posix-abstract-declarator.c" 2>/dev/null; then + if ${CC} ${CFLAGS} ${CFLAGS_C99} -D_POSIX_C_SOURCE=200809L -DPOSIXFAIL_ABSTRACT_DECLARATOR "$D/posix-abstract-declarator.c" 2>/dev/null; then [ ${FIRST} = "NO" ] && printf " "; FIRST=NO printf %s "-DPOSIXFAIL_ABSTRACT_DECLARATOR" fi diff --git a/apisupport/Build/apisupport.sh b/apisupport/Build/apisupport.sh index 64607265..f696c1f8 100755 --- a/apisupport/Build/apisupport.sh +++ b/apisupport/Build/apisupport.sh @@ -4,6 +4,7 @@ if ! [ "${PATH}" = "$1" ]; then echo "WARNING: POSIX violation: $SHELL's command -p resets \$PATH" 1>&2 PATH=$1 fi + # Standard output should be written to apisupport-config.h, which is both a # C header file defining APISUPPORT_PLATFORM_FEATURE macros and sourceable sh # code which sets CFLAGS_PLATFORM_FEATURE environment variables. diff --git a/cpusupport/Build/cpusupport.sh b/cpusupport/Build/cpusupport.sh index eda64f32..c179178a 100755 --- a/cpusupport/Build/cpusupport.sh +++ b/cpusupport/Build/cpusupport.sh @@ -4,6 +4,7 @@ if ! [ "${PATH}" = "$1" ]; then echo "WARNING: POSIX violation: $SHELL's command -p resets \$PATH" 1>&2 PATH=$1 fi + # Standard output should be written to cpusupport-config.h, which is both a # C header file defining CPUSUPPORT_ARCH_FEATURE macros and sourceable sh # code which sets CFLAGS_ARCH_FEATURE environment variables. diff --git a/release-tools/metabuild.sh b/release-tools/metabuild.sh index 635b1b78..e1940145 100755 --- a/release-tools/metabuild.sh +++ b/release-tools/metabuild.sh @@ -144,6 +144,7 @@ else copyvar PROG fi copyvar MAN1 + # SRCS is trickier to handle, as we need to remove any -config.h from the list. if [ -n "$(${MAKEBSD} -v SRCS)" ]; then printf "SRCS=" >> $OUT diff --git a/tests/18-warnp.sh b/tests/18-warnp.sh index b26c3ea2..7d0f23ba 100644 --- a/tests/18-warnp.sh +++ b/tests/18-warnp.sh @@ -46,7 +46,7 @@ scenario_cmd() { # Check console output. setup_check_variables "test_warnp output console" - $(set -e ; check_output "${test_output}" "${nonce}") + (set -e ; check_output "${test_output}" "${nonce}") echo "$?" > "${c_exitfile}" # Run binary to check multithreaded output. diff --git a/tests/shared_test_functions.sh b/tests/shared_test_functions.sh index 5e627e50..887a1cd4 100644 --- a/tests/shared_test_functions.sh +++ b/tests/shared_test_functions.sh @@ -17,6 +17,18 @@ # scenario_cmd() # function which was defined in that file. # +# Functions which are available to other scripts as a "public API" are: +# - has_pid(cmd): +# Look for a ${cmd} in $(ps). +# - wait_while(func): +# Wait until ${func} returns non-zero. +# - setup_check_variables(description, check_prev): +# Set up the below variables. +# - expected_exitcode(expected, actual): +# Check if ${expected} matches ${actual}. +# - run_scenarios(): +# Run scenarios in the test directory. +# ### Variables # # Wherever possible, this suite uses local variables and @@ -27,6 +39,7 @@ # valgrind log files. # - s_count: this is the count of the scenario's checks (so that # each check can have distinct files). +# - s_count_str: ${s_count} expressed as a two-digit string. # - s_retval: this is the overall exit code of the scenario. # - c_exitfile: this contains the exit code of each check. # - c_valgrind_min: this is the minimum value of USE_VALGRIND @@ -161,12 +174,12 @@ setup_check_variables() { fi # Set up the "exit" file. - count_str=$(printf "%02d" "${s_count}") - c_exitfile="${s_basename}-${count_str}.exit" + s_count_str=$(printf "%02d" "${s_count}") + c_exitfile="${s_basename}-${s_count_str}.exit" # Write the "description" file. printf "%s\n" "${description}" > \ - "${s_basename}-${count_str}.desc" + "${s_basename}-${s_count_str}.desc" # Set up the valgrind command (or an empty string). c_valgrind_cmd="$(valgrind_setup_cmd)" diff --git a/tests/shared_valgrind_functions.sh b/tests/shared_valgrind_functions.sh index fb998e45..d24f6887 100644 --- a/tests/shared_valgrind_functions.sh +++ b/tests/shared_valgrind_functions.sh @@ -17,6 +17,8 @@ set -o noclobber -o nounset # Check for any memory leaks recorded in valgrind logfiles associated with a # test exitfile. Return the filename if there's a leak; otherwise return an # empty string. +# - valgrind_incomplete(): +# Check if any valgrind log files are incomplete. # A non-zero value unlikely to be used as an exit code by the programs being # tested. @@ -228,7 +230,7 @@ valgrind_setup_cmd() { return fi - val_logfilename="${s_val_basename}-${count_str}-%p.log" + val_logfilename="${s_val_basename}-${s_count_str}-%p.log" c_valgrind_cmd="valgrind \ --log-file=${val_logfilename} \ --track-fds=yes \ @@ -238,6 +240,18 @@ valgrind_setup_cmd() { echo "${c_valgrind_cmd}" } +## valgrind_incomplete: +# Return 0 if at least one valgrind log file is not complete. +valgrind_incomplete() { + # The exit code of `grep -L` is undesirable: if at least one file + # contains the pattern, it returns 0. To detect if at least one file + # does *not* contain the pattern, we need to check grep's output, + # rather than the exit code. + _valgrind_incomplete_logfiles=$(grep -L "ERROR SUMMARY" \ + "${out_valgrind}"/*.log) + test -n "${_valgrind_incomplete_logfiles}" +} + ## valgrind_get_basename (exitfile): # Return the filename without ".log" of the valgrind logfile corresponding to # ${exitfile}.