public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH blktests] check: check kmemleak before test run start
@ 2026-03-13 12:18 Shin'ichiro Kawasaki
  2026-03-20  6:47 ` Shinichiro Kawasaki
  0 siblings, 1 reply; 2+ messages in thread
From: Shin'ichiro Kawasaki @ 2026-03-13 12:18 UTC (permalink / raw)
  To: linux-block; +Cc: Shin'ichiro Kawasaki

When the kernel enables kmemleak, the check script scans for memory
leaks at the end of every test case run. However, if memory has already
leaked before the blktests test run starts, the leak is detected at the
end of the first test case. This makes it look as if the leak happend
during the firest test case, which is confusing.

To avoid this, check for memory leaks once before staring blktests. If
any leaks are found, report them separately.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 check | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/check b/check
index 3b5738f..f170458 100755
--- a/check
+++ b/check
@@ -229,6 +229,7 @@ _setup_kmemleak() {
 
 _check_kmemleak() {
 	local kmemleak
+	local out=$1
 
 	((KMEMLEAK)) || return 0
 
@@ -240,7 +241,7 @@ _check_kmemleak() {
 		return 0
 	fi
 
-	printf '%s\n' "$kmemleak" > "${seqres}.kmemleak"
+	printf '%s\n' "$kmemleak" > "$out"
 	return 1
 }
 
@@ -477,7 +478,7 @@ __call_test() {
 		elif ! _check_dmesg "$dmesg_marker"; then
 			TEST_RUN["status"]=fail
 			TEST_RUN["reason"]=dmesg
-		elif ! _check_kmemleak; then
+		elif ! _check_kmemleak "${seqres}.kmemleak"; then
 			TEST_RUN["status"]=fail
 			TEST_RUN["reason"]=kmemleak
 		else
@@ -1022,6 +1023,7 @@ _check() {
 
 	local test_dev test_name
 	local -a all_test_devs_in_array
+	local km_log="${OUTPUT}/start.kmemleak"
 
 	for test_name in "${!TEST_CASE_DEV_ARRAY[@]}"; do
 		IFS=" " read -r -a all_test_devs_in_array <<< \
@@ -1050,6 +1052,14 @@ _check() {
 		done
 	done
 
+	if ((KMEMLEAK)); then
+		# check if memory is already leaked before blktests run
+		_setup_kmemleak
+		if ! _check_kmemleak "$km_log"; then
+			echo "Memory leak detected before test run start. See '${km_log}'."
+		fi
+	fi
+
 	local test_name group prev_group
 	local tests=()
 	local ret=0
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-20  6:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 12:18 [PATCH blktests] check: check kmemleak before test run start Shin'ichiro Kawasaki
2026-03-20  6:47 ` Shinichiro Kawasaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox