All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org,
	"Michal Koutný" <mkoutny@suse.com>,
	"David Disseldorp" <ddiss@suse.de>
Subject: [PATCH v2] selftests/zram: avoid subshells and bc for ratio calculations
Date: Wed, 12 Jul 2023 13:10:11 +0200	[thread overview]
Message-ID: <20230712111009.31150-1-ddiss@suse.de> (raw)

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.
The documented free dependency can also be removed following
d18da7ec37195 ("selftests/zram01.sh: Fix compression ratio calculation")

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 tools/testing/selftests/zram/README    |  2 --
 tools/testing/selftests/zram/zram01.sh | 18 ++++++++----------
 2 files changed, 8 insertions(+), 12 deletions(-)

v2: drop unused dependencies from selftests/zram/README

diff --git a/tools/testing/selftests/zram/README b/tools/testing/selftests/zram/README
index 110b34834a6fa..510ca5a1087f5 100644
--- 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
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


                 reply	other threads:[~2023-07-12 11:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230712111009.31150-1-ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.