[DTrace-devel] [PATCH 1/2] test: Add support for interpreter files

Kris Van Hees kris.van.hees at oracle.com
Fri Apr 28 05:16:52 UTC 2023


On Sat, Mar 04, 2023 at 05:36:37PM -0500, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> A D script foo.d can be run with "dtrace -s foo.d".
> 
> Alternatively, it can be made an executable interpreter file by adding
> a "#!dtrace -s" initial line (using the correct path to dtrace) and then
> "chmod +x foo.d".  At that point, it can be run "./foo.d".
> 
> A few tests have the #! initial line and therefore seem to intend to use
> the second, interpreter invocation style.  In particular, this is how some
> scripting tests are implemented.
> 
> But if a test has a .d extension, runtest.sh invokes it using "dtrace -s foo.d".
> This means we ignore the initial #! line:  both the specific path to dtrace
> as well as any dtrace options that are specified on the initial #! line.
> 
> There are some *.sh tests that get around this problem by setting up their
> own .d files and invoking them, but this means that some minor infrastructure
> is being replicated from file to file.
> 
> Add support in runtest.sh for *.d executable interpreter files.  In such
> a file, the initial #! line should start #!dtrace, since runtest.sh will
> replace the "dtrace" with the absolute path to the dtrace being tested.
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>

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

> ---
>  runtest.sh | 37 ++++++++++++++++++++++++++++++++++---
>  1 file changed, 34 insertions(+), 3 deletions(-)
> 
> diff --git a/runtest.sh b/runtest.sh
> index 261db3b8..bc7e6c1a 100755
> --- a/runtest.sh
> +++ b/runtest.sh
> @@ -195,6 +195,23 @@ extract_options()
>      done
>  }
>  
> +# is_interpreter_file FILE
> +
> +is_interpreter_file()
> +{
> +    if [[ ! -e $1 ]]; then
> +        return 1
> +    fi
> +    if [[ $(awk '{print $1; exit}' $1) != "#!dtrace" ]]; then
> +        return 1
> +    fi
> +
> +    # At this point, perhaps we can also check that the file is executable.
> +    # But we will copy it anyhow.  So do not bother.
> +
> +    return 0
> +}
> +
>  DEFAULT_TIMEOUT=41
>  
>  usage()
> @@ -874,7 +891,7 @@ for dt in $dtrace; do
>          #
>          # The full list of suffxes is as follows:
>          #
> -        # .d: The D program itself. Either this, or .sh, are mandatory.
> +        # .d: The D program itself.
>          #
>          # .sh: If executable, a shell script that is run instead of dtrace with
>          #      a single argument, the path to dtrace.  All other features are still
> @@ -1126,7 +1143,15 @@ for dt in $dtrace; do
>  
>          progtype=d
>          run=$dt
> -        if [[ -x $base.sh ]]; then
> +        interpreter_file=""
> +        if is_interpreter_file $base.d; then
> +            interpreter_file=$tmpdir/test.interpreter.$RANDOM.d
> +            rm -f $interpreter_file
> +            sed 's:^#!dtrace :#!'$dt' :' $base.d > $interpreter_file
> +            chmod +x $interpreter_file
> +            progtype=shell
> +            run="$interpreter_file $raw_dt_flags"
> +        elif [[ -x $base.sh ]]; then
>              progtype=shell
>              run="$base.sh $dt"
>              if [[ -z $trigger ]]; then
> @@ -1147,7 +1172,7 @@ for dt in $dtrace; do
>          # even in the presence of a hanging test. stdout and stderr go into
>          # different files, and any debugging output is split into a third.)
>  
> -	rm -f core
> +        rm -f core
>          fail=
>          this_noexec=$NOEXEC
>          testmsg=
> @@ -1265,6 +1290,12 @@ for dt in $dtrace; do
>                  unset _pid
>              fi
>  
> +            # Translate $interpreter_file back into name of test file.
> +            if [[ -n $interpreter_file ]]; then
> +                sed -i 's:'$interpreter_file':'$base.d':' $testout
> +                sed -i 's:'$interpreter_file':'$base.d':' $testerr
> +            fi
> +
>              # Split debugging info out of the test output.
>              grep -E '^[a-z_]+ DEBUG [0-9]+: ' $testerr > $testdebug
>              grep -vE '^[a-z_]+ DEBUG [0-9]+: ' $testerr > $testerr.tmp
> -- 
> 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