Skip to content

Commit 9e983c5

Browse files
committed
Merge branch 'selftests-pmtu-Add-test-choice-and-captures'
Stefano Brivio says: ==================== selftests: pmtu: Add test choice and captures This series adds a couple of features useful for debugging: 1/2 allows selecting single tests and 2/2 adds optional traffic captures. Semantics for current invocation of test script are preserved. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 2527e40 + bb059fb commit 9e983c5

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

tools/testing/selftests/net/pmtu.sh

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ dummy6_mask="64"
142142

143143
cleanup_done=1
144144
err_buf=
145+
tcpdump_pids=
145146

146147
err() {
147148
err_buf="${err_buf}${1}
@@ -284,7 +285,24 @@ setup() {
284285
done
285286
}
286287

288+
trace() {
289+
[ $tracing -eq 0 ] && return
290+
291+
for arg do
292+
[ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue
293+
${ns_cmd} tcpdump -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null &
294+
tcpdump_pids="${tcpdump_pids} $!"
295+
ns_cmd=
296+
done
297+
sleep 1
298+
}
299+
287300
cleanup() {
301+
for pid in ${tcpdump_pids}; do
302+
kill ${pid}
303+
done
304+
tcpdump_pids=
305+
288306
[ ${cleanup_done} -eq 1 ] && return
289307
for n in ${NS_A} ${NS_B} ${NS_R1} ${NS_R2}; do
290308
ip netns del ${n} 2> /dev/null
@@ -357,6 +375,10 @@ test_pmtu_ipvX() {
357375
family=${1}
358376

359377
setup namespaces routing || return 2
378+
trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
379+
"${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
380+
"${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
381+
"${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
360382

361383
if [ ${family} -eq 4 ]; then
362384
ping=ping
@@ -445,6 +467,8 @@ test_pmtu_ipv6_exception() {
445467

446468
test_pmtu_vti4_exception() {
447469
setup namespaces veth vti4 xfrm4 || return 2
470+
trace "${ns_a}" veth_a "${ns_b}" veth_b \
471+
"${ns_a}" vti4_a "${ns_b}" vti4_b
448472

449473
veth_mtu=1500
450474
vti_mtu=$((veth_mtu - 20))
@@ -473,6 +497,8 @@ test_pmtu_vti4_exception() {
473497

474498
test_pmtu_vti6_exception() {
475499
setup namespaces veth vti6 xfrm6 || return 2
500+
trace "${ns_a}" veth_a "${ns_b}" veth_b \
501+
"${ns_a}" vti6_a "${ns_b}" vti6_b
476502
fail=0
477503

478504
# Create route exception by exceeding link layer MTU
@@ -641,15 +667,56 @@ test_pmtu_vti6_link_change_mtu() {
641667
return ${fail}
642668
}
643669

644-
trap cleanup EXIT
670+
usage() {
671+
echo
672+
echo "$0 [OPTIONS] [TEST]..."
673+
echo "If no TEST argument is given, all tests will be run."
674+
echo
675+
echo "Options"
676+
echo " --trace: capture traffic to TEST_INTERFACE.pcap"
677+
echo
678+
echo "Available tests${tests}"
679+
exit 1
680+
}
645681

646682
exitcode=0
647683
desc=0
648684
IFS="
649685
"
686+
687+
tracing=0
688+
for arg do
689+
if [ "${arg}" != "${arg#--*}" ]; then
690+
opt="${arg#--}"
691+
if [ "${opt}" = "trace" ]; then
692+
if which tcpdump > /dev/null 2>&1; then
693+
tracing=1
694+
else
695+
echo "=== tcpdump not available, tracing disabled"
696+
fi
697+
else
698+
usage
699+
fi
700+
else
701+
# Check first that all requested tests are available before
702+
# running any
703+
command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; }
704+
fi
705+
done
706+
707+
trap cleanup EXIT
708+
650709
for t in ${tests}; do
651710
[ $desc -eq 0 ] && name="${t}" && desc=1 && continue || desc=0
652711

712+
run_this=1
713+
for arg do
714+
[ "${arg}" != "${arg#--*}" ] && continue
715+
[ "${arg}" = "${name}" ] && run_this=1 && break
716+
run_this=0
717+
done
718+
[ $run_this -eq 0 ] && continue
719+
653720
(
654721
unset IFS
655722
eval test_${name}

0 commit comments

Comments
 (0)