anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

Blame 0124-ndctl-test-make-inject-smart.sh-more-tolerant-of-dec.patch

Jeff Moyer 2c91dc
From 4921c0c2040ffbe10facd320f6a718a3d42ad815 Mon Sep 17 00:00:00 2001
Jeff Moyer 2c91dc
From: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
Date: Thu, 17 Feb 2022 22:42:29 -0700
Jeff Moyer 2c91dc
Subject: [PATCH 124/217] ndctl/test: make inject-smart.sh more tolerant of
Jeff Moyer 2c91dc
 decimal fields
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Some combinations of json-c/jq/other libraries seem to produce differing
Jeff Moyer 2c91dc
outputs for the final jq-filtered smart fields, in that some have a
Jeff Moyer 2c91dc
decimal "42.0" numeric field, where as in other combinations it is a
Jeff Moyer 2c91dc
simple "42" (still a numeric field, not string).
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
This shouldn't matter in practice, but for this contrived test case, we
Jeff Moyer 2c91dc
need to make sure that "42" is treated the same as "42.0"
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Normalize all fields before comparing them to "%0.0f" so that the
Jeff Moyer 2c91dc
comparison doesn't result in superfluous failures.
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Reported-by: Dan Williams <dan.j.williams@intel.com>
Jeff Moyer 2c91dc
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
---
Jeff Moyer 2c91dc
 test/inject-smart.sh | 4 ++--
Jeff Moyer 2c91dc
 1 file changed, 2 insertions(+), 2 deletions(-)
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
diff --git a/test/inject-smart.sh b/test/inject-smart.sh
Jeff Moyer 2c91dc
index 8b91360..046322b 100755
Jeff Moyer 2c91dc
--- a/test/inject-smart.sh
Jeff Moyer 2c91dc
+++ b/test/inject-smart.sh
Jeff Moyer 2c91dc
@@ -105,13 +105,13 @@ get_field()
Jeff Moyer 2c91dc
 	json="$($NDCTL list -b $bus -d $dimm -H)"
Jeff Moyer 2c91dc
 	val="$(jq -r ".[].dimms[].health.$smart_listing" <<< $json)"
Jeff Moyer 2c91dc
 	val="$(translate_val $val)"
Jeff Moyer 2c91dc
-	echo $val
Jeff Moyer 2c91dc
+	printf "%0.0f\n" "$val"
Jeff Moyer 2c91dc
 }
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
 verify()
Jeff Moyer 2c91dc
 {
Jeff Moyer 2c91dc
 	local field="$1"
Jeff Moyer 2c91dc
-	local val="$2"
Jeff Moyer 2c91dc
+	local val="$(printf "%0.0f\n" "$2")"
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
 	[[ "$val" == "$(get_field $field)" ]]
Jeff Moyer 2c91dc
 }
Jeff Moyer 2c91dc
-- 
Jeff Moyer 2c91dc
2.27.0
Jeff Moyer 2c91dc