Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libcperciva import #296

Merged
merged 3 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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 @@ -83,6 +84,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 libcperciva/netbuf/netbuf_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ netbuf_read_init(int s)

/**
* netbuf_read_init2(s, ssl):
* Behave like netbuf_read_init if ${ssl} is NULL. If the SSL context ${ssl}
* is not NULL, use it and ignore ${s}.
* Behave like netbuf_read_init() if ${ssl} is NULL. If the SSL context
* ${ssl} is not NULL, use it and ignore ${s}.
*/
struct netbuf_read *
netbuf_read_init2(int s, struct network_ssl_ctx * ssl)
Expand Down
8 changes: 4 additions & 4 deletions libcperciva/netbuf/netbuf_ssl_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ extern void (* netbuf_write_ssl_cancel_func)(void *);

/**
* netbuf_read_init2(s, ssl):
* Behave like netbuf_read_init if ${ssl} is NULL. If the SSL context ${ssl}
* is not NULL, use it and ignore ${s}.
* Behave like netbuf_read_init() if ${ssl} is NULL. If the SSL context
* ${ssl} is not NULL, use it and ignore ${s}.
*/
struct netbuf_read * netbuf_read_init2(int, struct network_ssl_ctx *);

/**
* netbuf_write_init2(s, ssl, fail_callback, fail_cookie):
* Behave like netbuf_write_init if ${ssl} is NULL. If the SSL context ${ssl}
* is not NULL, use it and ignore ${s}.
* Behave like netbuf_write_init() if ${ssl} is NULL. If the SSL context
* ${ssl} is not NULL, use it and ignore ${s}.
*/
struct netbuf_write * netbuf_write_init2(int, struct network_ssl_ctx *,
int (*)(void *), void *);
Expand Down
4 changes: 2 additions & 2 deletions libcperciva/netbuf/netbuf_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ netbuf_write_init(int s, int (* fail_callback)(void *), void * fail_cookie)

/**
* netbuf_write_init2(s, ssl, fail_callback, fail_cookie):
* Behave like netbuf_write_init() if ${ssl} is NULL. If the SSL context ${ssl}
* is not NULL, use it and ignore ${s}.
* Behave like netbuf_write_init() if ${ssl} is NULL. If the SSL context
* ${ssl} is not NULL, use it and ignore ${s}.
*/
struct netbuf_write *
netbuf_write_init2(int s, struct network_ssl_ctx * ssl,
Expand Down
2 changes: 1 addition & 1 deletion tests/shared_test_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ wait_while() {
fi

# Wait using the appropriate binary
if [ -n "${msleep:-}" ]; then
if [ -n "${msleep:-}" ]; then
"${msleep}" 100
_wait_while_ms=$((_wait_while_ms + 100))
else
Expand Down
104 changes: 73 additions & 31 deletions tests/shared_valgrind_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,44 @@ _val_checkl() {
fi
}

## _get_pids (logfiles):
# Extract a list of pids in the format %08d from ${logfiles}.
_get_pids() {
_get_pids_logfiles=$1

_get_pids_pids=""
for _get_pids_logfile in ${_valgrind_check_logfiles} ; do
# Get the pid.
_get_pids_pid=$(printf "%s" "${_get_pids_logfile%%.log}" | \
rev | cut -d "-" -f 1 | rev)
# Zero-pad it and add it to the new list.
_get_pids_pids=$(printf "%s %08d" \
"${_get_pids_pids}" "${_get_pids_pid}")
done

echo "${_get_pids_pids}"
}

## _is_parent (logfile, pids):
# If the parent pid of ${logfile} is in ${pids}, return 0; otherwise, return 1.
_is_parent () {
_is_parent_logfile=$1
_is_parent_pids=$2

# Get the parent pid from the valgrind logfile
ppid=$(grep "Parent PID:" "${_is_parent_logfile}" | \
awk '{ print $4 }')
ppid=$(printf "%08d" "${ppid}")

# If the parent is in the list of pids, this isn't the parent process.
if [ "${_is_parent_pids#*"${ppid}"}" != "${_is_parent_pids}" ] ; then
return 1
fi

# Yes, this is the parent process.
return 0
}

## valgrind_check (exitfile):
# 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
Expand All @@ -368,41 +406,45 @@ valgrind_check() {
return
fi

# Get a normalized list of pids.
_valgrind_check_pids=$(_get_pids "${_valgrind_check_logfiles}")

# If the valgrind logfiles contain "-valgrind-parent-", then we only
# want to check the parent (the lowest pid).
for _valgrind_check_logfile in ${_valgrind_check_logfiles} ; do
if [ "${_valgrind_check_logfile#*-valgrind-parent-}" != "${_valgrind_check_logfile}" ]; then
# Only check the parent
_val_checkl "${_valgrind_check_logfile}"
return "$?"
fi
done
# want to check the parent. The parent is the logfile whose "parent
# pid" is not in the list of pids. (If one logfile contains
# "-valgrind-parent-" then all of them should have it, so we can
# simply check if that string occurs in the list of logfiles.)
if [ "${_valgrind_check_logfiles#*-valgrind-parent-}" != \
"${_valgrind_check_logfiles}" ]; then
_valgrind_check_parent=1
else
_valgrind_check_parent=0
fi

# If there's two files, there's a fork() -- likely within
# daemonize() -- so only pay attention to the child.
if [ "${_valgrind_check_num}" -eq "2" ]; then
# Find both pids.
_valgrind_check_val_pids=""
for _valgrind_check_logfile in ${_valgrind_check_logfiles} ; do
_valgrind_check_val_pid=$(head -n 1 "${_valgrind_check_logfile}" | cut -d "=" -f 3)
_valgrind_check_val_pids="${_valgrind_check_val_pids} ${_valgrind_check_val_pid}"
done

# Find the logfile which has a parent in the list of pids.
for _valgrind_check_logfile in ${_valgrind_check_logfiles} ; do
_valgrind_check_val_parent_pid=$(grep "Parent PID:" "${_valgrind_check_logfile}" | \
awk '{ print $4 }')
if [ "${_valgrind_check_val_pids#*"${_valgrind_check_val_parent_pid}"}" != \
"${_valgrind_check_val_pids}" ]; then
# Check the logfiles depending on whether it's the parent or not,
# and whether we want to check the parent or children.
for _valgrind_check_logfile in ${_valgrind_check_logfiles} ; do
if _is_parent "${_valgrind_check_logfile}" \
"${_valgrind_check_pids}" ; then
# This is the parent.
if [ "${_valgrind_check_parent}" -eq 1 ] ; then
_val_checkl "${_valgrind_check_logfile}"
return "$?"
# Bail if there's a problem.
if [ "$?" -ne 0 ]; then
return
fi
fi
done
fi

# Programmer error; hard bail.
echo "Programmer error: wrong number of valgrind logfiles!" 1>&2
exit 1
else
# This is a child.
if [ "${_valgrind_check_parent}" -eq 0 ] ; then
_val_checkl "${_valgrind_check_logfile}"
# Bail if there's a problem.
if [ "$?" -ne 0 ]; then
return
fi
fi
fi
done
}

## valgrind_init():
Expand Down
Loading