From fc3b96be9b97586bbd7ed917121d000df4483205 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 2 Sep 2026 14:40:11 -0700 Subject: [PATCH] tests: pick the sshd child that arrived sshd_sftp_idle_cpu_test.sh measures the connection process it forked, so it takes the wolfsshd present after the connection and not before. The old symmetric difference offered a pid that left during the window just as readily, and the smallest one wins, so an earlier test's departing child was measured through a /proc entry that no longer existed. - compare the pid sets one way, and poll for the fork rather than sampling a fixed five seconds in - let the handshake and SFTP setup finish before the baseline, so their ticks land outside the measurement rather than inside it - print both pid sets when no child is found, since the failure says nothing about which pids were considered --- apps/wolfsshd/test/sshd_sftp_idle_cpu_test.sh | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/apps/wolfsshd/test/sshd_sftp_idle_cpu_test.sh b/apps/wolfsshd/test/sshd_sftp_idle_cpu_test.sh index 722c24a4a..8161a5f35 100755 --- a/apps/wolfsshd/test/sshd_sftp_idle_cpu_test.sh +++ b/apps/wolfsshd/test/sshd_sftp_idle_cpu_test.sh @@ -51,12 +51,26 @@ if [ ! -r /proc/self/stat ]; then exit 77 fi -PIDS_BEFORE=$(pgrep wolfsshd | sort) +PIDS_BEFORE=$(pgrep wolfsshd | tr '\n' ' ') if [ -z "$PIDS_BEFORE" ]; then echo "no local wolfsshd to measure, skipping" exit 77 fi +# Echoes the first wolfsshd that did not exist before this connection. The +# difference has to be one-way: a pid that LEFT during the window is not a +# candidate, and a symmetric difference offers it as readily as the child +# that arrived, leaving an unreadable /proc entry to measure. +new_wolfsshd_pid() { + for P in $(pgrep wolfsshd); do + case " $PIDS_BEFORE " in + *" $P "*) ;; + *) echo "$P"; return 0 ;; + esac + done + return 1 +} + # Hold a session open without sending a single request. The client takes its # commands from this pipe, and nothing ever writes one; the sleep bounds how # long the pipe stays open so no part of this outlives the test. @@ -66,12 +80,31 @@ HOLDER=$! "$TEST_SFTP_CLIENT" -u "$3" -i "$PRIVATE_KEY" -j "$PUBLIC_KEY" \ -h "$1" -p "$2" < "$FIFO" > /dev/null 2>&1 & CLIENT=$! -sleep 5 -PIDS_AFTER=$(pgrep wolfsshd | sort) -CHILD=$(printf '%s\n%s\n' "$PIDS_BEFORE" "$PIDS_AFTER" | sort | uniq -u | head -1) -if [ -z "$CHILD" ] || [ ! -r "/proc/$CHILD/stat" ]; then +# Poll for the child rather than sampling a fixed second in. NewConnection() +# forks right after accept(), so it appears long before the five seconds the +# old sample waited. +WAITED=0 +CHILD=$(new_wolfsshd_pid) +while [ -z "$CHILD" ] && [ "$WAITED" -lt 50 ]; do + sleep 0.1 + WAITED=$((WAITED + 1)) + CHILD=$(new_wolfsshd_pid) +done + +if [ -z "$CHILD" ]; then echo "Expecting another wolfSSHd pid after connection" + echo " before: $PIDS_BEFORE" + echo " after: $(pgrep wolfsshd | tr '\n' ' ')" + exit 1 +fi + +# Let the handshake, authentication and SFTP setup finish, so the ticks they +# cost land before the baseline rather than inside the measurement. +sleep 5 + +if [ ! -r "/proc/$CHILD/stat" ]; then + echo "Connection process $CHILD exited before the measurement" exit 1 fi