Introduce a convert_to_mb() helper which converts the size argument
to MBytes and use in test device require function. This makes it
possible to use user input strings in future.
Reviewed-by: Hannes Reinecke <[email protected]>
Signed-off-by: Daniel Wagner <[email protected]>
---
common/rc | 30 +++++++++++++++++++++++++++---
tests/nvme/035 | 2 +-
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/common/rc b/common/rc
index af4c0b1cab22..0b15d1fe4c6b 100644
--- a/common/rc
+++ b/common/rc
@@ -324,9 +324,12 @@ _get_pci_parent_from_blkdev() {
tail -2 | head -1
}
-_require_test_dev_size_mb() {
- local require_sz_mb=$1
- local test_dev_sz_mb=$(($(blockdev --getsize64 "$TEST_DEV")/1024/1024))
+_require_test_dev_size() {
+ local require_sz_mb
+ local test_dev_sz_mb
+
+ require_sz_mb="$(convert_to_mb "$1")"
+ test_dev_sz_mb="$(($(blockdev --getsize64 "$TEST_DEV")/1024/1024))"
if (( "$test_dev_sz_mb" < "$require_sz_mb" )); then
SKIP_REASONS+=("${TEST_DEV} required at least ${require_sz_mb}m")
@@ -422,3 +425,24 @@ _have_writeable_kmsg() {
_run_user() {
su "$NORMAL_USER" -c "$1"
}
+
+convert_to_mb()
+{
+ local str=$1
+ local res
+
+ res=$(echo "${str}" | sed -n 's/^\([0-9]\+\)$/\1/p')
+ if [[ -n "${res}" ]]; then
+ echo "$((res / 1024 / 1024))"
+ fi
+
+ res=$(echo "${str}" | sed -n 's/^\([0-9]\+\)[mM]$/\1/p')
+ if [[ -n "${res}" ]]; then
+ echo "$((res))"
+ fi
+
+ res=$(echo "${str}" | sed -n 's/^\([0-9]\+\)[gG]$/\1/p')
+ if [[ -n "${res}" ]]; then
+ echo "$((res * 1024))"
+ fi
+}
diff --git a/tests/nvme/035 b/tests/nvme/035
index d169e351e3d0..eb1024edddbf 100755
--- a/tests/nvme/035
+++ b/tests/nvme/035
@@ -17,7 +17,7 @@ requires() {
}
device_requires() {
- _require_test_dev_size_mb 1024
+ _require_test_dev_size 1024m
}
test_device() {
--
2.40.0
On 5/3/23 01:02, Daniel Wagner wrote:
> Introduce a convert_to_mb() helper which converts the size argument
> to MBytes and use in test device require function. This makes it
> possible to use user input strings in future.
>
> Reviewed-by: Hannes Reinecke <[email protected]>
> Signed-off-by: Daniel Wagner <[email protected]>
> ---
>
Much needed mb helper, looks good.
Reviewed-by: Chaitanya Kulkarni <[email protected]>
-ck
On Wed, May 03, 2023 at 09:22:07AM +0000, Chaitanya Kulkarni wrote:
> On 5/3/23 01:02, Daniel Wagner wrote:
> > Introduce a convert_to_mb() helper which converts the size argument
> > to MBytes and use in test device require function. This makes it
> > possible to use user input strings in future.
> >
> > Reviewed-by: Hannes Reinecke <[email protected]>
> > Signed-off-by: Daniel Wagner <[email protected]>
> > ---
> >
>
> Much needed mb helper, looks good.
I am sure the helper can be written way smarter but my shell-foo
skills are a bit limitted. Still a starting point :)
On May 03, 2023 / 10:02, Daniel Wagner wrote:
[...]
> +convert_to_mb()
> +{
> + local str=$1
> + local res
> +
> + res=$(echo "${str}" | sed -n 's/^\([0-9]\+\)$/\1/p')
> + if [[ -n "${res}" ]]; then
> + echo "$((res / 1024 / 1024))"
> + fi
> +
> + res=$(echo "${str}" | sed -n 's/^\([0-9]\+\)[mM]$/\1/p')
> + if [[ -n "${res}" ]]; then
> + echo "$((res))"
> + fi
> +
> + res=$(echo "${str}" | sed -n 's/^\([0-9]\+\)[gG]$/\1/p')
> + if [[ -n "${res}" ]]; then
> + echo "$((res * 1024))"
Here are some spaces still left.
> + fi
> +}