Skip to content

Commit

Permalink
test: Add support for interpreter files
Browse files Browse the repository at this point in the history
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@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed May 24, 2023
1 parent 3472de7 commit fb7db6f
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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()
Expand Down Expand Up @@ -884,7 +901,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
Expand Down Expand Up @@ -1136,7 +1153,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
Expand All @@ -1157,7 +1182,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=
Expand Down Expand Up @@ -1275,6 +1300,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
Expand Down

0 comments on commit fb7db6f

Please sign in to comment.