All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Jozsef Kadlecsik <kadlec@netfilter.org>, Florian Westphal <fw@strlen.de>
Subject: [PATCH ipset] tests: runtest.sh: do kmemleak scan if available
Date: Fri, 14 Aug 2026 01:04:01 +0200	[thread overview]
Message-ID: <20260813230404.19951-1-fw@strlen.de> (raw)

If we find that the kernel has kmemleak support, run a scan
at the end of the test and report an error in case there are new
reports.  It won't report any leaks that existed before in order
to not indicate errors in case of earlier memory leaks triggered
by other, non-ipset related tests.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 tests/runtest.sh | 52 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 8 deletions(-)

diff --git a/tests/runtest.sh b/tests/runtest.sh
index 1b00b7bc55d5..3571c310095e 100755
--- a/tests/runtest.sh
+++ b/tests/runtest.sh
@@ -36,6 +36,45 @@ cleanup() {
 	ip link del eth0
 }
 trap cleanup EXIT
+
+kmemleak_found=0
+test -f /sys/kernel/debug/kmemleak && kmemleak_found=$(grep "unreferenced object" /sys/kernel/debug/kmemleak | wc -l)
+
+check_kmemleak_force()
+{
+	echo scan > /sys/kernel/debug/kmemleak
+
+	local lines=$(grep "unreferenced object" /sys/kernel/debug/kmemleak | wc -l)
+	if [ $lines -ne $kmemleak_found ];then
+		echo "FAILED"
+		cat /sys/kernel/debug/kmemleak
+		failcount=$((failcount+1))
+	else
+		echo "OK"
+	fi
+}
+
+check_failcount() {
+	local ret=0
+
+	if [ -f /sys/kernel/debug/kmemleak ]; then
+		echo -n  "Waiting 30 seconds, then doing kmemleak scan "
+		sleep 30
+		check_kmemleak_force
+	fi
+
+	rmmod ip_set >/dev/null 2>&1
+
+	if [ "$failcount" -eq 0 ]; then
+		echo "All tests are passed"
+	else
+		echo "$failcount tests have failed"
+		ret=1
+	fi
+
+	exit $ret
+}
+
 tmpdir=$(mktemp -t -d ip-set-XXXXXXXX)
 
 ip link set lo up
@@ -111,7 +150,9 @@ else
 fi
 
 # Make sure the scripts are executable
-chmod a+x check_* *.sh
+for f in check_* *.sh; do
+	test -x "$f" || chmod a+x "$f"
+done
 
 failcount=0
 for types in $tests; do
@@ -181,10 +222,5 @@ for x in $tests; do
 		;;
 	esac
 done
-rmmod ip_set >/dev/null 2>&1
-if [ "$failcount" -eq 0 ]; then
-	echo "All tests are passed"
-else
-	echo "$failcount tests have failed"
-	exit 1
-fi
+
+check_failcount
-- 
2.54.0


                 reply	other threads:[~2026-08-13 23:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260813230404.19951-1-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=kadlec@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.