[DTrace-devel] [PATCH v2 02/12] Check correctly for status of DTrace job

Kris Van Hees kris.van.hees at oracle.com
Tue Jun 15 09:15:03 PDT 2021


On Thu, Jun 03, 2021 at 04:02:58PM -0400, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> A test launched a DTrace job in the background and was incorrectly
> checking its status.  Specifically, it was passing spuriously.  Fix,
> and for now mark XFAIL.
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>  .../tst.jstack_unprintable-bug26045010.sh     | 51 ++++++++++++++-----
>  1 file changed, 37 insertions(+), 14 deletions(-)
> 
> diff --git a/test/unittest/ustack/tst.jstack_unprintable-bug26045010.sh b/test/unittest/ustack/tst.jstack_unprintable-bug26045010.sh
> index 9f6f6812..232a24fe 100755
> --- a/test/unittest/ustack/tst.jstack_unprintable-bug26045010.sh
> +++ b/test/unittest/ustack/tst.jstack_unprintable-bug26045010.sh
> @@ -1,10 +1,11 @@
>  #!/bin/bash
>  #
>  # Oracle Linux DTrace.
> -# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
> +# Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
>  # Licensed under the Universal Permissive License v 1.0 as shown at
>  # http://oss.oracle.com/licenses/upl.
>  #
> +# @@xfail: dtv2
>  if [ $# != 1 ]; then
>  	echo expected one argument: '<'dtrace-path'>'
>  	exit 2
> @@ -44,20 +45,43 @@ EOF
>  
>  file=out.txt
>  rm -f $file
> -$dtrace -q $dt_flags -n 'profile-9 /execname == "java" && arg1/ { jstack(4); }' -o $file &
> -sleep 1
> +$dtrace -q $dt_flags -n '
> +BEGIN
> +{
> +	printf("hello world\n");
> +}
> +profile-9
> +/execname == "java" && arg1/
> +{
> +	jstack(4);
> +}' -o $file &
> +pid=$!
> +
> +# confirm that the DTrace job is running successfully
> +nsecs=0
> +while true; do
> +	sleep 1
> +	nsecs=$(($nsecs + 1))
> +	if grep -q "hello world" $file; then
> +		break
> +	fi
> +	if ! ps -p $pid >& /dev/null || [ $nsecs -ge 10 ] ; then
> +		echo error starting DTrace job
> +		cat $file
> +		rm -f $file
> +		exit 1
> +	fi
> +done

So, if the dtrace starts (pid exists) but does not output the marker string
within 10 xeconds, you exit.  But the dtrace will be left hanging?  It ought
to get killed, right.

I think you want two conditions here:

	if ! ps -p $pid >& /dev/null; then
		echo DTrace died
		cat $file
		rm -f $file
		exit 1
	elif [ $nsecs -ge 10 ] ; then
		echo error starting DTrace job
		kill %1
		cat $file
		rm -f $file
		exit 1
	fi


> +
> +# run the Java job
>  /usr/bin/java bug26045010
> +
> +# kill the DTrace job
>  sleep 1
>  kill %1
> -sleep 1
> -
> -status=$?
> -if [ "$status" -ne 0 ]; then
> -        echo $tst: dtrace failed
> -        rm -f $file
> -        exit $status
> -fi
> +wait
>  
> +# check results
>  n=`sed 's/[[:print:]]//g' $file | awk 'BEGIN {x = 0}; NF>0 {x += 1}; END {print x}'`
>  if [ $n -gt 0 ]; then
>          echo $tst: $n lines have unprintable characters
> @@ -65,10 +89,9 @@ if [ $n -gt 0 ]; then
>          echo "==================== file start"
>          cat $file
>          echo "==================== file end"
> -        status=1
> +        n=1
>  fi
>  
>  rm -f $file
>  
> -exit $status
> -
> +exit $n
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list