diff mbox series

[v2,2/3] zram/zram_lib.sh: Skip test if zram module can not be removed

Message ID 1639136448-2148-2-git-send-email-xuyang2018.jy@fujitsu.com
State Changes Requested
Headers show
Series [v2,1/3] swapping01: skip test if zram-swap is being used | expand

Commit Message

Yang Xu \(Fujitsu\) Dec. 10, 2021, 11:40 a.m. UTC
If zram-generator package is installed and works, then we can not
remove zram module because zram swap is being used. We can also use zramstart
command or similar shell script(use zramctl,mkswap,swapon) to do this.

Since zram01.sh and zram02.sh needs to rmmod and modprobe, they can't work well
if zram module can't be removed. So skip it.

Fixes: #888
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/device-drivers/zram/zram_lib.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Cyril Hrubis Dec. 10, 2021, 12:25 p.m. UTC | #1
Hi!
> +	lsmod | grep -q '^zram'
> +	if [ $? -eq 0 ]; then

Why not just:
	if grep -q '^zram' /proc/modules; then
		...

Here as well what the lsmod does it to open /proc/modules and for each
entry it also looks at /sys/module/$name/refcnt and
/sys/module/$name/hodlers. But we are not interested in the second part
at all...

> +		 rmmod zram > /dev/null 2>&1 || tst_brk TCONF "zram module is being used"
> +	fi
> +
>  	tst_set_timeout $((dev_num*450))
>  
>  	tst_res TINFO "create '$dev_num' zram device(s)"
> @@ -54,10 +64,12 @@ zram_load()
>  	modprobe zram num_devices=$dev_num || \
>  		tst_brk TBROK "failed to insert zram module"
>  
> +	dev_zram_load=1
>  	dev_num_created=$(ls /dev/zram* | wc -w)
>  
>  	if [ "$dev_num_created" -ne "$dev_num" ]; then
> -		tst_brk TFAIL "unexpected num of devices: $dev_num_created"
> +		tst_brk TFAIL "expected num of devices $dev_num, but created"\
> +				"$dev_num_created"
>  	fi
>  
>  	tst_res TPASS "all zram devices successfully created"
> -- 
> 2.23.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp
diff mbox series

Patch

diff --git a/testcases/kernel/device-drivers/zram/zram_lib.sh b/testcases/kernel/device-drivers/zram/zram_lib.sh
index fe9c915c3..4fed1f17c 100755
--- a/testcases/kernel/device-drivers/zram/zram_lib.sh
+++ b/testcases/kernel/device-drivers/zram/zram_lib.sh
@@ -5,6 +5,7 @@ 
 
 dev_makeswap=-1
 dev_mounted=-1
+dev_zram_load=-1
 
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
@@ -17,6 +18,10 @@  zram_cleanup()
 {
 	local i
 
+	if [ $dev_zram_load -le 0 ]; then
+		return
+	fi
+
 	for i in $(seq 0 $dev_makeswap); do
 		swapoff /dev/zram$i
 	done
@@ -47,6 +52,11 @@  zram_load()
 		tst_brk TBROK "dev_num must be > 0"
 	fi
 
+	lsmod | grep -q '^zram'
+	if [ $? -eq 0 ]; then
+		 rmmod zram > /dev/null 2>&1 || tst_brk TCONF "zram module is being used"
+	fi
+
 	tst_set_timeout $((dev_num*450))
 
 	tst_res TINFO "create '$dev_num' zram device(s)"
@@ -54,10 +64,12 @@  zram_load()
 	modprobe zram num_devices=$dev_num || \
 		tst_brk TBROK "failed to insert zram module"
 
+	dev_zram_load=1
 	dev_num_created=$(ls /dev/zram* | wc -w)
 
 	if [ "$dev_num_created" -ne "$dev_num" ]; then
-		tst_brk TFAIL "unexpected num of devices: $dev_num_created"
+		tst_brk TFAIL "expected num of devices $dev_num, but created"\
+				"$dev_num_created"
 	fi
 
 	tst_res TPASS "all zram devices successfully created"