[DTrace-devel] [PATCH v2 2/4] test: fix check_result.sh

Kris Van Hees kris.van.hees at oracle.com
Wed Nov 8 05:36:04 UTC 2023


On Wed, Nov 01, 2023 at 03:31:04PM +0000, Nick Alcock wrote:
> This checker (used in a number of tests) has a syntax error that
> causes it to spit things like
> 
> test/utils/check_result.sh: line 14: 4 - : syntax error: operand expected (error token is "- ")
> test/utils/check_result.sh: line 15: 4 + : syntax error: operand expected (error token is "+ ")
> 
> instead of actually checking for minima/maxima.
> 
> The problem is that shell variables inside $((...)) shuold not be
> $-prepended: they undergo variable expansion anyway, and $-prepending them
> just causes them to undergo *another* round, which fails and expands to
> nothing, yielding the errors above.

This is not true though.  The bash manpage clearly states that $-prepending is
not needed - not that it is not allowed or that it should not be used.  And
in fact, various other shell scripts in DTrace use a variety of $-prepended
and regular tokens.  I suggest we do not adopt this patch.  The failure seen
seems to more likely a fluke or temporary bug in bash.

> Fixed, fixing a number of tests (that is, causing them to emit errors
> appropriately, i.e. possibly fail where they weren't before).
> 
> Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
> ---
>  test/utils/check_result.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/test/utils/check_result.sh b/test/utils/check_result.sh
> index 9509512a5750b..25a877a44c89a 100755
> --- a/test/utils/check_result.sh
> +++ b/test/utils/check_result.sh
> @@ -11,11 +11,11 @@ margin=$3
>  
>  printf " check %10s;  against %10s;  margin %10s:  " $actual $expect $margin
>  
> -if [ $actual -lt $(($expect - $margin)) ]; then
> +if [ $actual -lt $((expect - margin)) ]; then
>  	echo ERROR too small
>  	exit 1
>  fi
> -if [ $actual -gt $(($expect + $margin)) ]; then
> +if [ $actual -gt $((expect + margin)) ]; then
>  	echo ERROR too large
>  	exit 1
>  fi
> -- 
> 2.42.0.271.g85384428f1
> 
> 



More information about the DTrace-devel mailing list