[DTrace-devel] [PATCH v2 6/6] test: Add USDT error tests for -w and -Z

Kris Van Hees kris.van.hees at oracle.com
Mon Oct 28 20:36:15 UTC 2024


On Fri, Oct 04, 2024 at 12:55:08AM -0400, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> Error checking for USDT probes can be different from other probes.
> So add specific USDT tests for -Z and -w.  Specifically:
> 
>     err.no-Z  No USDT process yet when dtrace is launched
>               and -Z is not specified.  Therefore, dtrace
>               will not start up.
> 
>     err.no-w  A USDT process is running when dtrace is
>               launched, so -Z is not needed.  However, the
>               action is destructive and -w is not specified.
>               Therefore, dtrace will not start up.
> 
>     err.Z_no-w  No USDT process yet when dtrace is launched,
>                 but -Z is specified.  So, dtrace starts
>                 successfully.  But the action is destructive
>                 and -w is not specified.  So when the USDT
>                 process starts, dtrace fails.
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>

Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>

> ---
>  test/unittest/usdt/err.Z_no-w.r  |  4 ++
>  test/unittest/usdt/err.Z_no-w.sh | 65 ++++++++++++++++++++++++++++++++
>  test/unittest/usdt/err.no-Z.r    | 13 +++++++
>  test/unittest/usdt/err.no-Z.sh   | 31 +++++++++++++++
>  test/unittest/usdt/err.no-w.r    |  3 ++
>  test/unittest/usdt/err.no-w.sh   | 31 +++++++++++++++
>  6 files changed, 147 insertions(+)
>  create mode 100644 test/unittest/usdt/err.Z_no-w.r
>  create mode 100755 test/unittest/usdt/err.Z_no-w.sh
>  create mode 100644 test/unittest/usdt/err.no-Z.r
>  create mode 100755 test/unittest/usdt/err.no-Z.sh
>  create mode 100644 test/unittest/usdt/err.no-w.r
>  create mode 100755 test/unittest/usdt/err.no-w.sh
> 
> diff --git a/test/unittest/usdt/err.Z_no-w.r b/test/unittest/usdt/err.Z_no-w.r
> new file mode 100644
> index 000000000..b81622481
> --- /dev/null
> +++ b/test/unittest/usdt/err.Z_no-w.r
> @@ -0,0 +1,4 @@
> +dtrace is running so start the trigger
> +dtrace died as expected after trigger started
> +-- @@stderr --
> +dtrace: processing aborted: Destructive actions not allowed
> diff --git a/test/unittest/usdt/err.Z_no-w.sh b/test/unittest/usdt/err.Z_no-w.sh
> new file mode 100755
> index 000000000..3833b4400
> --- /dev/null
> +++ b/test/unittest/usdt/err.Z_no-w.sh
> @@ -0,0 +1,65 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2024, 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.
> +#
> +# This test verifies that dtrace will not run a destructive script
> +# for USDT probes if -w is not specified.
> +#
> +# Specifically, the script is launched with -Z and no USDT processes are
> +# initially present.  Only once a USDT process is detected does dtrace
> +# fail due to the destructive action.
> +
> +dtrace=$1
> +trigger=`pwd`/test/triggers/usdt-tst-defer
> +
> +# Set up test directory.
> +
> +DIRNAME=$tmpdir/Z_no-w.$$.$RANDOM
> +mkdir -p $DIRNAME
> +cd $DIRNAME
> +
> +# Make a private copy of the trigger executable so that we get our
> +# own DOF stash.
> +
> +cp $trigger main
> +
> +# Run dtrace.
> +
> +$dtrace $dt_flags -Zq -o dtrace.out -n '
> +testprov*:::foo
> +{
> +	raise(SIGUSR1);
> +}' &
> +dtpid=$!
> +sleep 4
> +if [[ ! -d /proc/$dtpid ]]; then
> +	echo ERROR dtrace died prematurely
> +	exit 1
> +fi
> +
> +# Start a trigger process.
> +
> +echo dtrace is running so start the trigger
> +./main > main.out &
> +pid=$!
> +
> +# Check again if dtrace is still running.
> +
> +sleep 2
> +if [[ ! -d /proc/$dtpid ]]; then
> +	echo dtrace died as expected after trigger started
> +else
> +	echo dtrace is unexpectedly still running
> +	kill -9 $dtpid
> +	wait    $dtpid
> +fi
> +
> +# Tell the trigger to proceed to completion.
> +
> +kill -USR1 $pid
> +wait       $pid
> +
> +exit 1
> diff --git a/test/unittest/usdt/err.no-Z.r b/test/unittest/usdt/err.no-Z.r
> new file mode 100644
> index 000000000..52d9492ab
> --- /dev/null
> +++ b/test/unittest/usdt/err.no-Z.r
> @@ -0,0 +1,13 @@
> +expected failure
> +-- @@stderr --
> +dtrace: invalid probe specifier 
> +BEGIN
> +{
> +	exit(0);
> +}
> +
> +testprov*:::foo
> +{
> +	raise(SIGUSR1);
> +	exit(0);
> +}: probe description testprov*:::foo does not match any probes
> diff --git a/test/unittest/usdt/err.no-Z.sh b/test/unittest/usdt/err.no-Z.sh
> new file mode 100755
> index 000000000..29d63d9ce
> --- /dev/null
> +++ b/test/unittest/usdt/err.no-Z.sh
> @@ -0,0 +1,31 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2024, 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.
> +#
> +# This test verifies that dtrace will not wait for USDT processes to
> +# appear if -Z is not used.
> +
> +dtrace=$1
> +
> +$dtrace $dt_flags -qn '
> +BEGIN
> +{
> +	exit(0);
> +}
> +
> +testprov*:::foo
> +{
> +	raise(SIGUSR1);
> +	exit(0);
> +}'
> +if [ $? -ne 0 ]; then
> +	echo expected failure
> +	exit 1
> +fi
> +
> +echo unexpected success
> +
> +exit 0
> diff --git a/test/unittest/usdt/err.no-w.r b/test/unittest/usdt/err.no-w.r
> new file mode 100644
> index 000000000..7a4d60cd0
> --- /dev/null
> +++ b/test/unittest/usdt/err.no-w.r
> @@ -0,0 +1,3 @@
> +expected failure
> +-- @@stderr --
> +dtrace: could not enable tracing: Destructive actions not allowed
> diff --git a/test/unittest/usdt/err.no-w.sh b/test/unittest/usdt/err.no-w.sh
> new file mode 100755
> index 000000000..407654981
> --- /dev/null
> +++ b/test/unittest/usdt/err.no-w.sh
> @@ -0,0 +1,31 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2024, 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.
> +#
> +# This test verifies that dtrace will not run a destructive script
> +# for USDT probes if -w is not specified.
> +
> +dtrace=$1
> +
> +$dtrace $dt_flags -c test/triggers/usdt-tst-defer -qn '
> +BEGIN
> +{
> +	exit(0);
> +}
> +
> +testprov*:::foo
> +{
> +	raise(SIGUSR1);
> +	exit(0);
> +}'
> +if [ $? -ne 0 ]; then
> +	echo expected failure
> +	exit 1
> +fi
> +
> +echo unexpected success
> +
> +exit 0
> -- 
> 2.43.5
> 



More information about the DTrace-devel mailing list