* [PATCH] selftests/zram: avoid subshells and bc for ratio calculations
@ 2023-06-28 10:53 David Disseldorp
2023-06-28 11:03 ` David Disseldorp
0 siblings, 1 reply; 2+ messages in thread
From: David Disseldorp @ 2023-06-28 10:53 UTC (permalink / raw)
To: Shuah Khan; +Cc: linux-kselftest, Michal Koutný, David Disseldorp
Awk is already called for /sys/block/zram#/mm_stat parsing, so use it
to also perform the floating point capacity vs consumption ratio
calculations. The test output is unchanged.
This allows bc to be dropped as a dependency for the zram selftests.
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
tools/testing/selftests/zram/zram01.sh | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/zram/zram01.sh b/tools/testing/selftests/zram/zram01.sh
index 8f4affe34f3e4..df1b1d4158989 100755
--- a/tools/testing/selftests/zram/zram01.sh
+++ b/tools/testing/selftests/zram/zram01.sh
@@ -33,7 +33,7 @@ zram_algs="lzo"
zram_fill_fs()
{
- for i in $(seq $dev_start $dev_end); do
+ for ((i = $dev_start; i <= $dev_end && !ERR_CODE; i++)); do
echo "fill zram$i..."
local b=0
while [ true ]; do
@@ -44,15 +44,13 @@ zram_fill_fs()
done
echo "zram$i can be filled with '$b' KB"
- local mem_used_total=`awk '{print $3}' "/sys/block/zram$i/mm_stat"`
- local v=$((100 * 1024 * $b / $mem_used_total))
- if [ "$v" -lt 100 ]; then
- echo "FAIL compression ratio: 0.$v:1"
- ERR_CODE=-1
- return
- fi
-
- echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK"
+ awk -v b="$b" '{ v = (100 * 1024 * b / $3) } END {
+ if (v < 100) {
+ printf "FAIL compression ratio: 0.%u:1\n", v
+ exit 1
+ }
+ printf "zram compression ratio: %.2f:1: OK\n", v / 100
+ }' "/sys/block/zram$i/mm_stat" || ERR_CODE=-1
done
}
--
2.35.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/zram: avoid subshells and bc for ratio calculations
2023-06-28 10:53 [PATCH] selftests/zram: avoid subshells and bc for ratio calculations David Disseldorp
@ 2023-06-28 11:03 ` David Disseldorp
0 siblings, 0 replies; 2+ messages in thread
From: David Disseldorp @ 2023-06-28 11:03 UTC (permalink / raw)
To: Shuah Khan; +Cc: linux-kselftest, Michal Koutný
One minor follow up...
On Wed, 28 Jun 2023 12:53:45 +0200, David Disseldorp wrote:
> Awk is already called for /sys/block/zram#/mm_stat parsing, so use it
> to also perform the floating point capacity vs consumption ratio
> calculations. The test output is unchanged.
> This allows bc to be dropped as a dependency for the zram selftests.
It looks as though the following hunk should also be squashed in. free
usage was dropped with d18da7ec3719559d6e74937266d0416e6c7e0b31:
--- a/tools/testing/selftests/zram/README
+++ b/tools/testing/selftests/zram/README
@@ -27,9 +27,7 @@ zram01.sh: creates general purpose ram disks with ext4 filesystems
zram02.sh: creates block device for swap
Commands required for testing:
- - bc
- dd
- - free
- awk
- mkswap
- swapon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-28 11:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-28 10:53 [PATCH] selftests/zram: avoid subshells and bc for ratio calculations David Disseldorp
2023-06-28 11:03 ` David Disseldorp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox