selftests: mptcp: lib: dump nstat for the right test

In case of errors, mptcp_lib_pr_nstat is called to dump the nstat
counters, but for some tests, it was dumping the counters for all
subtests, not just the current one.

That's an issue for tests that don't recreate the netns for each
subtest, e.g. mptcp_connect.sh. In this case, 'nstat -a' will look at
the absolute counters since the creation of the netns, making
debugging harder.

Instead, it should dump the counters for the current test, by using the
history recorded in /tmp/<ns>.nstat if available, and not using '-a'
which was dumping the absolute values instead of calculating increments.

While at it, rename the previous 'hist' variable to 'cache' as it was
used to look at the cache, not the nstat history.

Fixes: 658e531417 ("selftests: mptcp: join: dump stats from history")
Cc: stable@vger.kernel.org
Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20260908-net-mptcp-misc-fixes-7-3-rc1-v2-11-df1de70348b6@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Matthieu Baerts (NGI0) 2026-09-08 16:07:16 +02:00 committed by Jakub Kicinski
parent caa4a79f74
commit e1a56368ea

View File

@ -108,12 +108,14 @@ mptcp_lib_pr_info() {
mptcp_lib_pr_nstat() {
local ns="${1}"
local hist="/tmp/${ns}.out"
local cache="/tmp/${ns}.out"
local hist="/tmp/${ns}.nstat"
if [ -f "${hist}" ]; then
awk '$2 != 0 { print " "$0 }' "${hist}"
if [ -f "${cache}" ]; then
awk '$2 != 0 { print " "$0 }' "${cache}"
else
ip netns exec "${ns}" nstat -as | grep Tcp
NSTAT_HISTORY="${hist}" ip netns exec "${ns}" nstat -s |
grep Tcp
fi
}