Skip to content

Commit

Permalink
Merge pull request #515 from Tarsnap/import
Browse files Browse the repository at this point in the history
Merge changes from kivaloo and spiped.
  • Loading branch information
cperciva authored Apr 6, 2024
2 parents e8f139f + 606a676 commit 647084b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ toplevel: apisupport-config.h cflags-filter.sh \
# For "loop-back" building of a subdirectory
.PHONY: buildsubdir
buildsubdir: toplevel
export CFLAGS="$${CFLAGS:-${CFLAGS_DEFAULT}}"; \
. ./posix-flags.sh; \
. ./cpusupport-config.h; \
. ./cflags-filter.sh; \
Expand All @@ -75,6 +76,7 @@ buildsubdir: toplevel
# For "loop-back" building of libraries
.PHONY: libs
libs: apisupport-config.h cflags-filter.sh cpusupport-config.h posix-flags.sh
export CFLAGS="$${CFLAGS:-${CFLAGS_DEFAULT}}"; \
. ./posix-flags.sh; \
. ./cpusupport-config.h; \
. ./cflags-filter.sh; \
Expand Down
4 changes: 2 additions & 2 deletions tests/10-events-interrupt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ scenario_cmd() {
) &

# Wait for the binary to initialize its signal handler
wait_while test ! -e "${pidfile}"
wait_while 0 test ! -e "${pidfile}"
pid=$( cat "${pidfile}" )

# Signal and wait for the binary to finish writing the logfile
kill -s USR1 "${pid}"
wait_while test ! -e "${flag_1}"
wait_while 0 test ! -e "${flag_1}"

# Compare with good values
setup_check "test-empty-events"
Expand Down
20 changes: 16 additions & 4 deletions tests/shared_test_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
# Look for ${cmd} in the ${PATH}, and ensure that it supports ${args}.
# - has_pid(cmd):
# Look for a ${cmd} in $(ps).
# - wait_while(func):
# Wait until ${func} returns non-zero.
# - wait_while(timeout, func):
# Wait up to ${timeout} milliseconds, or until ${func} returns non-zero.
# - setup_check(description, check_prev):
# Set up the below variables.
# - expected_exitcode(expected, actual):
Expand Down Expand Up @@ -133,11 +133,14 @@ has_pid() {
return 1
}

## wait_while(func):
## wait_while(timeout, func):
# Wait while ${func} returns 0. If ${msleep} is defined, use that to wait
# 100ms; otherwise, wait in 1 second increments.
# 100ms; otherwise, wait in 1 second increments. If ${timeout} is non-zero,
# return 1 if ${timeout} milliseconds have passed.
wait_while() {
_wait_while_ms=0
_wait_while_timeout=$1
shift 1

# Check for the ending condition
while "$@"; do
Expand All @@ -147,6 +150,15 @@ wait_while() {
"${_wait_while_ms}" "$*" 1>&2
fi

# Bail if we've exceeded the timeout
if [ "${_wait_while_timeout}" -gt 0 ] && \
[ "${_wait_while_ms}" -gt "${_wait_while_timeout}" ]; then
if [ "${VERBOSE}" -ne 0 ]; then
printf "Bail; timeout exceeded\n" 1>&2
fi
return 1
fi

# Wait using the appropriate binary
if [ -n "${msleep:-}" ]; then
"${msleep}" 100
Expand Down

0 comments on commit 647084b

Please sign in to comment.