diff mbox series

[3/3] zram/zram_lib.sh: set the compression algorithms back to default after test

Message ID 20190710072305.25806-4-po-hsu.lin@canonical.com
State Rejected
Headers show
Series zram/zram_lib.sh: fix zram_compress_alg() test for zram01 | expand

Commit Message

Po-Hsu Lin July 10, 2019, 7:23 a.m. UTC
Set the compression algorithm back to the default one in the end of the
zram_compress_alg() test.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 testcases/kernel/device-drivers/zram/zram_lib.sh | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Petr Vorel March 17, 2020, 6:21 p.m. UTC | #1
Hi Po-Hsu,

> Set the compression algorithm back to the default one in the end of the
> zram_compress_alg() test.

Why is this needed? We remove zram in zram_cleanup() anyway.
This would make sense if we detect whether zram was loaded before testing and
try to restore the setup of originally loaded module instead of always removing it.

Kind regards,
Petr
Po-Hsu Lin March 19, 2020, 2:39 p.m. UTC | #2
Hello Petr,

Yes you're right, the zram_cleanup() will kick in after zram01.sh finishes,
so this can be dropped for the moment I think.

Thanks for the review!


On Wed, Mar 18, 2020 at 2:21 AM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Po-Hsu,
>
> > Set the compression algorithm back to the default one in the end of the
> > zram_compress_alg() test.
>
> Why is this needed? We remove zram in zram_cleanup() anyway.
> This would make sense if we detect whether zram was loaded before testing and
> try to restore the setup of originally loaded module instead of always removing it.
>
> Kind regards,
> Petr
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 7773f4338..e2b6eb8ec 100755
--- a/testcases/kernel/device-drivers/zram/zram_lib.sh
+++ b/testcases/kernel/device-drivers/zram/zram_lib.sh
@@ -99,6 +99,7 @@  zram_compress_alg()
 	tst_resm TINFO "test that we can set compression algorithm"
 
 	local algs="$(sed 's/[][]//g' /sys/block/zram0/comp_algorithm)"
+	local alg_default="$(grep -oP '(?<=\[).*(?=\])' /sys/block/zram0/comp_algorithm)"
 	tst_resm TINFO "supported algs: $algs"
 	local i=0
 	local dev_max=$(($dev_num - 1))
@@ -110,6 +111,12 @@  zram_compress_alg()
 				tst_brkm TFAIL "can't set '$alg' to $sys_path"
 			tst_resm TINFO "$sys_path = '$alg' ($i/$dev_max)"
 		done
+		# Restore the compression algorithm to the default one
+		if [ -n "$alg_default" ]; then
+			echo "$alg_default" >  $sys_path || \
+				tst_brkm TFAIL "can't restore '$alg_default' to $sys_path"
+			tst_resm TINFO "Set $sys_path back to $alg_default"
+		fi
 	done
 
 	tst_resm TPASS "test succeeded"