diff mbox series

[ndctl,1/3] test/cxl-region-sysfs.sh: covert size and resource to hex before test

Message ID 20231123023058.2963551-1-lizhijian@fujitsu.com (mailing list archive)
State New, archived
Delegated to: Vishal Verma
Headers show
Series [ndctl,1/3] test/cxl-region-sysfs.sh: covert size and resource to hex before test | expand

Commit Message

Zhijian Li (Fujitsu) Nov. 23, 2023, 2:30 a.m. UTC
size and resource are both decimal

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
 test/cxl-region-sysfs.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Dan Williams Dec. 6, 2023, 9:31 p.m. UTC | #1
I would summarize this as "Fix hex vs decimal confusion"

Li Zhijian wrote:
> size and resource are both decimal

Please always describe the "why" in the changelog including the
motivation for the change and the effect of not applying the patch. I.e.
how would someone know that they are hitting the problem that this patch
fixes. Sample output usually helps here.

> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
>  test/cxl-region-sysfs.sh | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/test/cxl-region-sysfs.sh b/test/cxl-region-sysfs.sh
> index 8636392..ded7aa1 100644
> --- a/test/cxl-region-sysfs.sh
> +++ b/test/cxl-region-sysfs.sh
> @@ -123,6 +123,11 @@ readarray -t switch_decoders < <(echo $json | jq -r ".[].decoder")
>  [ ${#switch_decoders[@]} -ne $nr_switch_decoders ] && err \
>  "$LINENO: expected $nr_switch_decoders got ${#switch_decoders[@]} switch decoders"
>  
> +decimal_to_hex()
> +{
> +	printf "0x%x" $1
> +}
> +
>  for i in ${switch_decoders[@]}
>  do
>  	decoder=$(echo $json | jq -r ".[] | select(.decoder == \"$i\")")
> @@ -136,8 +141,8 @@ do
>  	[ $ig -ne $((r_ig << depth)) ] && err \
>  	"$LINENO: decoder: $i ig: $ig switch_ig: $((r_ig << depth))"
>  
> -	res=$(echo $decoder | jq -r ".resource")
> -	sz=$(echo $decoder | jq -r ".size")
> +	res=$(decimal_to_hex $(echo $decoder | jq -r ".resource"))
> +	sz=$(decimal_to_hex $(echo $decoder | jq -r ".size"))

This feels like overkill, I think bash arithmentic operations can handle
hex conversion and decimal comparison...

>  	[ $sz -ne $region_size ] && err \
>  	"$LINENO: decoder: $i sz: $sz region_size: $region_size"
>  	[ $res -ne $region_base ] && err \

...i.e. does this solve the issue?

@@ -138,9 +138,9 @@ do
 
        res=$(echo $decoder | jq -r ".resource")
        sz=$(echo $decoder | jq -r ".size")
-       [ $sz -ne $region_size ] && err \
+       (( sz != $region_size )) && err \
        "$LINENO: decoder: $i sz: $sz region_size: $region_size"
-       [ $res -ne $region_base ] && err \
+       (( $res != $region_base )) && err \
        "$LINENO: decoder: $i base: $res region_base: $region_base"
 done
diff mbox series

Patch

diff --git a/test/cxl-region-sysfs.sh b/test/cxl-region-sysfs.sh
index 8636392..ded7aa1 100644
--- a/test/cxl-region-sysfs.sh
+++ b/test/cxl-region-sysfs.sh
@@ -123,6 +123,11 @@  readarray -t switch_decoders < <(echo $json | jq -r ".[].decoder")
 [ ${#switch_decoders[@]} -ne $nr_switch_decoders ] && err \
 "$LINENO: expected $nr_switch_decoders got ${#switch_decoders[@]} switch decoders"
 
+decimal_to_hex()
+{
+	printf "0x%x" $1
+}
+
 for i in ${switch_decoders[@]}
 do
 	decoder=$(echo $json | jq -r ".[] | select(.decoder == \"$i\")")
@@ -136,8 +141,8 @@  do
 	[ $ig -ne $((r_ig << depth)) ] && err \
 	"$LINENO: decoder: $i ig: $ig switch_ig: $((r_ig << depth))"
 
-	res=$(echo $decoder | jq -r ".resource")
-	sz=$(echo $decoder | jq -r ".size")
+	res=$(decimal_to_hex $(echo $decoder | jq -r ".resource"))
+	sz=$(decimal_to_hex $(echo $decoder | jq -r ".size"))
 	[ $sz -ne $region_size ] && err \
 	"$LINENO: decoder: $i sz: $sz region_size: $region_size"
 	[ $res -ne $region_base ] && err \