summaryrefslogtreecommitdiffstats
path: root/tests/shell/run-tests.sh
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2023-07-20 14:33:34 +0200
committerFlorian Westphal <fw@strlen.de>2023-07-20 18:26:12 +0200
commit11bc7d9b9ee310ce5829fc149f43d73d4f443abe (patch)
treee897acb8132e64f76317a02585cbab73cd197530 /tests/shell/run-tests.sh
parentc2b28dcebd058b978692b8e1899e79b96c025396 (diff)
tests: shell: auto-run kmemleak if its available
On my test vm a full scan takes almost 5s. As this would slowdown the test runs too much, only run them every couple of tests. This allows to detect when there is a leak reported at the end of the script, and it allows to narrow down the test case/group that triggers the issue. Add new -K flag to force kmemleak runs after each test if its available, this can then be used to find the exact test case. Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'tests/shell/run-tests.sh')
-rwxr-xr-xtests/shell/run-tests.sh56
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index 1a699875..b66ef4fa 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -74,6 +74,11 @@ if [ "$1" == "-V" ] ; then
shift
fi
+if [ "$1" == "-K" ]; then
+ KMEMLEAK=y
+ shift
+fi
+
for arg in "$@"; do
SINGLE+=" $arg"
VERBOSE=y
@@ -163,7 +168,46 @@ check_taint()
read taint_now < /proc/sys/kernel/tainted
if [ $taint -ne $taint_now ] ; then
msg_warn "[FAILED] kernel is tainted: $taint -> $taint_now"
- ((failed++))
+ fi
+}
+
+kmem_runs=0
+kmemleak_found=0
+
+check_kmemleak_force()
+{
+ test -f /sys/kernel/debug/kmemleak || return 0
+
+ echo scan > /sys/kernel/debug/kmemleak
+
+ lines=$(grep "unreferenced object" /sys/kernel/debug/kmemleak | wc -l)
+ if [ $lines -ne $kmemleak_found ];then
+ msg_warn "[FAILED] kmemleak detected $lines memory leaks"
+ kmemleak_found=$lines
+ fi
+
+ if [ $lines -ne 0 ];then
+ return 1
+ fi
+
+ return 0
+}
+
+check_kmemleak()
+{
+ test -f /sys/kernel/debug/kmemleak || return
+
+ if [ "$KMEMLEAK" == "y" ] ; then
+ check_kmemleak_force
+ return
+ fi
+
+ kmem_runs=$((kmem_runs + 1))
+ if [ $((kmem_runs % 30)) -eq 0 ]; then
+ # scan slows tests down quite a bit, hence
+ # do this only for every 30th test file by
+ # default.
+ check_kmemleak_force
fi
}
@@ -218,9 +262,19 @@ do
fi
check_taint
+ check_kmemleak
done
echo ""
+
+# kmemleak may report suspected leaks
+# that get free'd after all, so always do
+# a check after all test cases
+# have completed and reset the counter
+# so another warning gets emitted.
+kmemleak_found=0
+check_kmemleak_force
+
msg_info "results: [OK] $ok [FAILED] $failed [TOTAL] $((ok+failed))"
kernel_cleanup