Skip to contentSkip to conversation

ndctl/test: make inject-smart.sh more tolerant of decimal fields

PATCH New Vishal Verma 1 participant 1 message Feb 18, 2022 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

PATCH 1/1 ndctl/test: make inject-smart.sh more tolerant of decimal fields

Some combinations of json-c/jq/other libraries seem to produce differing outputs for the final jq-filtered smart fields, in that some have a decimal "42.0" numeric field, where as in other combinations it is a simple "42" (still a numeric field, not string).

This shouldn't matter in practice, but for this contrived test case, we need to make sure that "42" is treated the same as "42.0"

Normalize all fields before comparing them to "%0.0f" so that the comparison doesn't result in superfluous failures.

---
 test/inject-smart.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/inject-smart.sh +2 -2
index 8b91360..046322b 100755
@@ -105,13 +105,13 @@ get_field()
 	json="$($NDCTL list -b $bus -d $dimm -H)"
 	val="$(jq -r ".[].dimms[].health.$smart_listing" <<< $json)"
 	val="$(translate_val $val)"
-	echo $val
+	printf "%0.0f\n" "$val"
 }
 
 verify()
 {
 	local field="$1"
-	local val="$2"
+	local val="$(printf "%0.0f\n" "$2")"
 
 	[[ "$val" == "$(get_field $field)" ]]
 }
Signature · 1 line
2.34.1