Skip to content

Commit 3264022

Browse files
ejohnstownphilljj
authored andcommitted
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
1 parent 79456c2 commit 3264022

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

apps/wolfsshd/test/sshd_sftp_idle_cpu_test.sh

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,26 @@ if [ ! -r /proc/self/stat ]; then
5151
exit 77
5252
fi
5353

54-
PIDS_BEFORE=$(pgrep wolfsshd | sort)
54+
PIDS_BEFORE=$(pgrep wolfsshd | tr '\n' ' ')
5555
if [ -z "$PIDS_BEFORE" ]; then
5656
echo "no local wolfsshd to measure, skipping"
5757
exit 77
5858
fi
5959

60+
# Echoes the first wolfsshd that did not exist before this connection. The
61+
# difference has to be one-way: a pid that LEFT during the window is not a
62+
# candidate, and a symmetric difference offers it as readily as the child
63+
# that arrived, leaving an unreadable /proc entry to measure.
64+
new_wolfsshd_pid() {
65+
for P in $(pgrep wolfsshd); do
66+
case " $PIDS_BEFORE " in
67+
*" $P "*) ;;
68+
*) echo "$P"; return 0 ;;
69+
esac
70+
done
71+
return 1
72+
}
73+
6074
# Hold a session open without sending a single request. The client takes its
6175
# commands from this pipe, and nothing ever writes one; the sleep bounds how
6276
# long the pipe stays open so no part of this outlives the test.
@@ -66,12 +80,31 @@ HOLDER=$!
6680
"$TEST_SFTP_CLIENT" -u "$3" -i "$PRIVATE_KEY" -j "$PUBLIC_KEY" \
6781
-h "$1" -p "$2" < "$FIFO" > /dev/null 2>&1 &
6882
CLIENT=$!
69-
sleep 5
7083

71-
PIDS_AFTER=$(pgrep wolfsshd | sort)
72-
CHILD=$(printf '%s\n%s\n' "$PIDS_BEFORE" "$PIDS_AFTER" | sort | uniq -u | head -1)
73-
if [ -z "$CHILD" ] || [ ! -r "/proc/$CHILD/stat" ]; then
84+
# Poll for the child rather than sampling a fixed second in. NewConnection()
85+
# forks right after accept(), so it appears long before the five seconds the
86+
# old sample waited.
87+
WAITED=0
88+
CHILD=$(new_wolfsshd_pid)
89+
while [ -z "$CHILD" ] && [ "$WAITED" -lt 50 ]; do
90+
sleep 0.1
91+
WAITED=$((WAITED + 1))
92+
CHILD=$(new_wolfsshd_pid)
93+
done
94+
95+
if [ -z "$CHILD" ]; then
7496
echo "Expecting another wolfSSHd pid after connection"
97+
echo " before: $PIDS_BEFORE"
98+
echo " after: $(pgrep wolfsshd | tr '\n' ' ')"
99+
exit 1
100+
fi
101+
102+
# Let the handshake, authentication and SFTP setup finish, so the ticks they
103+
# cost land before the baseline rather than inside the measurement.
104+
sleep 5
105+
106+
if [ ! -r "/proc/$CHILD/stat" ]; then
107+
echo "Connection process $CHILD exited before the measurement"
75108
exit 1
76109
fi
77110

0 commit comments

Comments
 (0)