aboutgitcodebugslistschat
path: root/test/lib
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-09-02 12:04:34 +1000
committerStefano Brivio <sbrivio@redhat.com>2022-09-07 11:01:22 +0200
commite5e10aff8179b5f410b4e2fe7923303fd183fc75 (patch)
tree5012fa7c298cafe7658728ea37482a8d947c7423 /test/lib
parent29247d0db6953d7a3d45c4da763b487ef695ac1e (diff)
downloadpasst-e5e10aff8179b5f410b4e2fe7923303fd183fc75.tar
passt-e5e10aff8179b5f410b4e2fe7923303fd183fc75.tar.gz
passt-e5e10aff8179b5f410b4e2fe7923303fd183fc75.tar.bz2
passt-e5e10aff8179b5f410b4e2fe7923303fd183fc75.tar.lz
passt-e5e10aff8179b5f410b4e2fe7923303fd183fc75.tar.xz
passt-e5e10aff8179b5f410b4e2fe7923303fd183fc75.tar.zst
passt-e5e10aff8179b5f410b4e2fe7923303fd183fc75.zip
test: Rewrite test_iperf3
test_iperf3() is a pretty inscrutable mess of nested background processes. It has a number of ugly sleeps needed to wait for things to complete. Rewrite it to be cleaner: * Use the construct (a & b & wait) to run 'a' and 'b' in parallel, but then wait for them both to complete before continuing * This allows us to wait for both the server and client to finish, rather than sleeping * Use jq to do all the math we need to get the final result, rather than jq followed by some complicated 'bc' mangling Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'test/lib')
-rwxr-xr-xtest/lib/test68
1 files changed, 27 insertions, 41 deletions
diff --git a/test/lib/test b/test/lib/test
index b293b34..5a6c01c 100755
--- a/test/lib/test
+++ b/test/lib/test
@@ -31,54 +31,40 @@ test_iperf3() {
__procs="$((${1} - 1))"; shift
__time="${1}"; shift
- pane_run "${__spane}" 'for i in $(seq 0 '${__procs}'); do' \
- ':> s${i}.bw; done'
+ pane_run "${__spane}" \
+ '(' \
+ ' for i in $(seq 0 '${__procs}'); do' \
+ ' iperf3 -s1J -p'${__port}' -i'${__time} \
+ ' > s${i}.json &' \
+ ' done;' \
+ ' wait' \
+ ')'
+
+ pane_run "${__cpane}" \
+ '(' \
+ ' for i in $(seq 0 '${__procs}'); do' \
+ ' iperf3 -c '${__dest}' -p '${__port} \
+ ' -t'${__time}' -T s${i} '"${@}"' &' \
+ ' done;' \
+ ' wait' \
+ ')'
+
+ pane_status "${__cpane}"
pane_status "${__spane}"
- __udp=0
+ __jval=".end.sum_received.bits_per_second"
for __opt in ${@}; do
- [ "${__opt}" = "-u" ] && __udp=1
+ # UDP test
+ [ "${__opt}" = "-u" ] && __jval=".intervals[0].sum.bits_per_second"
done
- (
- sleep 2
- pane_run "${__cpane}" 'for i in $(seq 0 '${__procs}');' \
- 'do ( iperf3 -c '"${__dest}"' -p '"${__port}" \
- '-t'${__time} "${@}" ' -T s${i} & echo $! > c${i}.pid & ); done'
- sleep $(echo ${__time} + 10 | bc -l)
- pane_run "${__cpane}" 'for i in $(seq 0 '${__procs}'); do'\
- 'kill -INT $(cat c${i}.pid) 2>/dev/null; done'
- ) &
-
- if [ ${__udp} -eq 0 ]; then
- pane_run "${__spane}" 'for i in $(seq 0 '${__procs}');' \
- 'do ( ( iperf3 -s1J -p '"${__port}" \
- '& echo $! > s${i}.pid ) 2>/dev/null' \
- '| jq -rM ".end.sum_received.bits_per_second"' \
- '> s${i}.bw & );' \
- 'done'
- else
- pane_run "${__spane}" 'for i in $(seq 0 '${__procs}');' \
- 'do ( ( iperf3 -s1J -i '${__time}' -p '"${__port}" \
- '& echo $! > s${i}.pid ) 2>/dev/null' \
- '| jq -rM ".intervals[0].sum.bits_per_second"' \
- '> s${i}.bw & );' \
- 'done'
- fi
-
- pane_status "${__spane}"
- sleep $(echo ${__time} + 15 | bc -l)
- pane_run "${__spane}" 'for i in $(seq 0 '${__procs}'); do' \
- 'kill -INT $(cat s${i}.pid) 2>/dev/null; done'
- sleep 4
- pane_wait "${__spane}"
- pane_run "${__spane}" '(cat s*.bw |' \
- 'sed '"'"'s/\(.*\)/\1\+/g'"'"' |' \
- 'tr -d "\n"; echo 0) | bc -l'
+ pane_run "${__spane}" \
+ 'cat s*.json | jq -rMs "map('${__jval}') | add"'
pane_wait "${__spane}"
__bw="$(pane_parse "${__spane}")"
- pane_run "${__spane}" 'for i in $(seq 0 '${__procs}'); do' \
- 'rm -f [cs]${i}.bw [cs]${i}.pid; done'
+
+ pane_run "${__spane}" \
+ 'for i in $(seq 0 '${__procs}'); do rm s${i}.json; done'
pane_status "${__spane}"
TEST_ONE_subs="$(list_add_pair "${TEST_ONE_subs}" "__${__var}__" "${__bw}" )"