zram/zram_lib.sh: fix zram_compress_alg() test for zram01
cover zram/zram_lib.sh: fix zram_compress_alg() test for zram01
The zram_compress_alg() test in zram01 is not working properly, this patchset will address the following issues:
1. One-liner local variable assignment with space-separated value does not work for DASH, which is symbolically linked to /bin/sh on some OS like Ubuntu.
2. Inconsistent variable name for compression algorithms, and the algorithm name needs to be sanitized.
3. Hard-coded block device numbers to iterate with. If the number of the available zram compression algorithms is larger than the number of block devices, the test will fail.
Po-Hsu Lin (3):
zram/zram_lib.sh: fix local variable assignment for DASH zram/zram_lib.sh: fix variable name and algorithm retrieval zram/zram_lib.sh: iterate through all available compression algorithms
for all zram block devices
.../kernel/device-drivers/zram/zram_lib.sh | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 zram/zram_lib.sh: fix local variable assignment for DASH
The /bin/sh was symbolically link to dash in Ubuntu.
This is making the one-liner local variable assignment not working [1]:
/opt/ltp/testcases/bin/zram01.sh: 102: local: 842: bad variable name
This is because there are more then one string in the return value:
$ cat /sys/block/zram0/comp_algorithm
[lzo] lz4 lz4hc 842 zstdUse a pair of quotes to enclose to solve this issue.
[1] https://wiki.ubuntu.com/DashAsBinSh#local
--- testcases/kernel/device-drivers/zram/zram_lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/device-drivers/zram/zram_lib.sh +1 -1
@@ -98,7 +98,7 @@ zram_compress_alg() tst_resm TINFO "test that we can set compression algorithm" - local algs=$(cat /sys/block/zram0/comp_algorithm) + local algs="$(cat /sys/block/zram0/comp_algorithm)" tst_resm TINFO "supported algs: $algs" local i=0 for alg in $zram_algs; do
Signature · 1 line
2.17.1
PATCH 1/3 zram/zram_lib.sh: fix local variable assignment for DASH
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/3 zram/zram_lib.sh: fix variable name and algorithm retrieval
In reply to Po-Hsu LinThe compression algorithm was stored into a local variable algs, however the variable name zram_algs was used in the for loop later.
Unify them with zram_algs, and use sed to get rid of the square brackets that indicates the compression algorithm currently in use.
$ cat /sys/block/zram0/comp_algorithm
[lzo] lz4 lz4hc 842 zstd--- testcases/kernel/device-drivers/zram/zram_lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/device-drivers/zram/zram_lib.sh +2 -2
@@ -98,8 +98,8 @@ zram_compress_alg() tst_resm TINFO "test that we can set compression algorithm" - local algs="$(cat /sys/block/zram0/comp_algorithm)" - tst_resm TINFO "supported algs: $algs" + local zram_algs="$(sed 's/[][]//g' /sys/block/zram0/comp_algorithm)" + tst_resm TINFO "supported algs: $zram_algs" local i=0 for alg in $zram_algs; do local sys_path="/sys/block/zram${i}/comp_algorithm"
Signature · 1 line
2.17.1
PATCH 2/3 zram/zram_lib.sh: fix variable name and algorithm retrieval
Hi!
testcases/kernel/device-drivers/zram/zram_lib.sh zram_compress_alg() · line 101
Quoted 5 lines
testcases/kernel/device-drivers/zram/zram_lib.sh +1
-2tst_resm TINFO "test that we can set compression algorithm" - local algs="$(cat /sys/block/zram0/comp_algorithm)" - tst_resm TINFO "supported algs: $algs" + local zram_algs="$(sed 's/[][]//g' /sys/block/zram0/comp_algorithm)"
This has still the same name as the variable set in the zram01.sh.
There are two options what to do here, either we remove zram_algs from the zram01.sh or set the algorithms to the ones defined in the zram01.sh test at the end of this function.
Quoted 10 lines
testcases/kernel/device-drivers/zram/zram_lib.sh +1
-0+ tst_resm TINFO "supported algs: $zram_algs" local i=0 for alg in $zram_algs; do local sys_path="/sys/block/zram${i}/comp_algorithm"Signature · 5 lines
2.17.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/3 zram/zram_lib.sh: fix variable name and algorithm retrieval
Quoted 8 lines · Cyril Hrubis
Hi!
testcases/kernel/device-drivers/zram/zram_lib.sh zram_compress_alg() · line 101
Quoted 5 lines
tst_resmTINFO "test that we can set compression algorithm"testcases/kernel/device-drivers/zram/zram_lib.sh +1
-2- local algs="$(cat /sys/block/zram0/comp_algorithm)" - tst_resm TINFO "supported algs: $algs" + local zram_algs="$(sed 's/[][]//g' /sys/block/zram0/comp_algorithm)"
Quoted 6 lines
This has still the same name as the variable set in the
zram01.sh.There are two options what to do here, either we remove
zram_algsfrom thezram01.shor set the algorithms to the ones defined in thezram01.shtest at the end of this function.
OK thanks,
I think maybe it's better to keep zram_algs in zram01.sh, make the mapped zram property structure intact.
That's probably the original purpose for the local variable "algs".
I will re-send a version with variable name unified with the local algs here, so we don't need to restore the zram_algs in the end of this function.
Quoted 14 lines
Quoted 10 lines
+
tst_resmTINFO "supported algs: $zram_algs"
local i=0
for alg in $zram_algs; do
local sys_path="/sys/block/zram${i}/comp_algorithm"
--
2.17.1--
Mailing list info: https://lists.linux.it/listinfo/ltp--
Cyril Hrubis
[email protected]
PATCH 3/3 zram/zram_lib.sh: iterate through all available compression algorithms for all zram block devices
In reply to Po-Hsu LinThe test was designed to switch up to 4 zram compression algorithms, one of them on a zram block device at a time through 4 devices as defined in zram01.sh.
As the number of zram block devices are hard-coded in zram01.sh, the test will fail if your system supports more than 4 compression algorithms because it will try to access a non-existing block device:
zram01.sh: cannot create /sys/block/zram4/comp_algorithm: Directory nonexistent zram01 2 TFAIL: can't set 'zstd' to /sys/block/zram4/comp_algorithm
Fix this by checking how many available zram block devices we can use first. And iterate all the available compression algorithms on each one of block devices. This ensures all the algorithm can be assigned on all of the zram block devices and thus improves the test coverage.
--- .../kernel/device-drivers/zram/zram_lib.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
testcases/kernel/device-drivers/zram/zram_lib.sh +12 -6
@@ -101,12 +101,18 @@ zram_compress_alg() local zram_algs="$(sed 's/[][]//g' /sys/block/zram0/comp_algorithm)" tst_resm TINFO "supported algs: $zram_algs" local i=0 - for alg in $zram_algs; do - local sys_path="/sys/block/zram${i}/comp_algorithm" - echo "$alg" > $sys_path || \ - tst_brkm TFAIL "can't set '$alg' to $sys_path" - i=$(($i + 1)) - tst_resm TINFO "$sys_path = '$alg' ($i/$dev_num)" + local dev_max=0 + while [ -d /sys/block/zram$(($dev_max + 1)) ]; do + dev_max=$(($dev_max + 1)) + done + + for i in $(seq 0 $dev_max); do + for alg in $zram_algs; do + local sys_path="/sys/block/zram${i}/comp_algorithm" + echo "$alg" > $sys_path || \ + tst_brkm TFAIL "can't set '$alg' to $sys_path" + tst_resm TINFO "$sys_path = '$alg' ($i/$dev_max)" + done done tst_resm TPASS "test succeeded"
Signature · 1 line
2.17.1
PATCH 3/3 zram/zram_lib.sh: iterate through all available compression algorithms for all zram block devices
Hi!
Quoted 13 lines
Signed-off-by Po-Hsu Lin <[email protected]>--- .../kernel/device-drivers/zram/zram_lib.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)testcases/kernel/device-drivers/zram/zram_lib.sh +0
-0@@ -101,12 +101,18 @@ zram_compress_alg() local zram_algs="$(sed 's/[][]//g' /sys/block/zram0/comp_algorithm)" tst_resm TINFO "supported algs: $zram_algs" local i=0
testcases/kernel/device-drivers/zram/zram_lib.sh zram_compress_alg() · line 107
Quoted 10 lines
testcases/kernel/device-drivers/zram/zram_lib.sh +4
-6- for alg in $zram_algs; do - local sys_path="/sys/block/zram${i}/comp_algorithm" - echo "$alg" > $sys_path || \ - tst_brkm TFAIL "can't set '$alg' to $sys_path" - i=$(($i + 1)) - tst_resm TINFO "$sys_path = '$alg' ($i/$dev_num)" + local dev_max=0 + while [ -d /sys/block/zram$(($dev_max + 1)) ]; do + dev_max=$(($dev_max + 1)) + done
The zram01.sh test defines dev_num that is passed to the modprobe zram as num_devices, there is no point in counting the block devices like this.
testcases/kernel/device-drivers/zram/zram_lib.sh zram_compress_alg() · line 116
Quoted 8 lines
testcases/kernel/device-drivers/zram/zram_lib.sh +7
-0+ for i in $(seq 0 $dev_max); do + for alg in $zram_algs; do + local sys_path="/sys/block/zram${i}/comp_algorithm" + echo "$alg" > $sys_path || \ + tst_brkm TFAIL "can't set '$alg' to $sys_path" + tst_resm TINFO "$sys_path = '$alg' ($i/$dev_max)" + done done
This is OK, but we should make sure we end up with expected compression method for subsequent tests.
Maybe we should just set the alg to the zram_algs="" as defined in the zram01.sh after this loop.
Quoted 7 lines
testcases/kernel/device-drivers/zram/zram_lib.sh +0
-0tst_resm TPASS "test succeeded"Signature · 5 lines
2.17.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]