Skip to content

Commit

Permalink
scripts: misc fixes
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
gperciva committed Jun 30, 2023
1 parent 2475780 commit ce82b05
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
8 changes: 4 additions & 4 deletions POSIX/posix-cflags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions apisupport/Build/apisupport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cpusupport/Build/cpusupport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions release-tools/metabuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/18-warnp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 16 additions & 3 deletions tests/shared_test_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)"
Expand Down
16 changes: 15 additions & 1 deletion tests/shared_valgrind_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 \
Expand All @@ -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}.
Expand Down

0 comments on commit ce82b05

Please sign in to comment.