[DTrace-devel] [PATCH] test: Update -xmodpath test

eugene.loh at oracle.com eugene.loh at oracle.com
Mon Dec 18 21:43:38 UTC 2023


From: Eugene Loh <eugene.loh at oracle.com>

We test -xmodpath by checking that pointing modpath to:
- an empty directory produces "bad" results
- an appropriate symlink reproduces good (default) results

With the addition of a BTF-to-CTF convertor, however, DTrace basically
functions even in the absence of CTF info.

One signature of the convertor, though, is that rawtp-provider args[]
type information will be (void*) regardless of what the actual type is.
Use this signature to verify that -xmodpath is working.

One complication is that a trial-and-error method of getting rawtp args[]
info is used if there is no HAVE_LIBCTF.  In this case, rawtp args[]
types will be uint64_t, even when no -xmodpath is specified.  Skip the
test in this case.

To review:

- If no HAVE_LIBCTF, rawtp args[] type will always be uint64_t.
  Skip the test in this case.

- If HAVE_LIBCTF but -xmodpath points at an empty directory, many
  DTrace features should still work, but rawtp args[] types will
  all be (void*).  Check that -xmodpath=empty produces (void*).

- Under "normal" circumstances, many rawtp args[] types will be
  neither uint64_t nor (void*).  Check such results in the default
  case and when -xmodpath points at a valid CTF archive.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 test/unittest/options/tst.modpath.r  | 18 ++-----
 test/unittest/options/tst.modpath.sh | 74 ++++++++++++++++++++++------
 test/unittest/options/tst.modpath.x  | 19 ++++++-
 3 files changed, 80 insertions(+), 31 deletions(-)
 mode change 120000 => 100755 test/unittest/options/tst.modpath.x

diff --git a/test/unittest/options/tst.modpath.r b/test/unittest/options/tst.modpath.r
index 464a19be..0fc2bb61 100644
--- a/test/unittest/options/tst.modpath.r
+++ b/test/unittest/options/tst.modpath.r
@@ -1,14 +1,4 @@
-                   FUNCTION:NAME
-                          :BEGIN 
-
-sanity check on DTrace passed
-DTrace correctly fails when modpath is an empty directory
-                   FUNCTION:NAME
-                          :BEGIN 
-
-DTrace works with modpath and a linked CTF archive
--- @@stderr --
-dtrace: description 'BEGIN ' matched 1 probe
-dtrace: description 'BEGIN ' matched 1 probe
-dtrace: could not enable tracing: Module does not contain any CTF data
-dtrace: description 'BEGIN ' matched 1 probe
+basic check on DTrace passed
+empty check on DTrace passed
+final check on DTrace passed
+all checks pass
diff --git a/test/unittest/options/tst.modpath.sh b/test/unittest/options/tst.modpath.sh
index cd26114f..0f269123 100755
--- a/test/unittest/options/tst.modpath.sh
+++ b/test/unittest/options/tst.modpath.sh
@@ -12,36 +12,78 @@ DIRNAME="$tmpdir/modpath.$$.$RANDOM"
 mkdir -p $DIRNAME
 cd $DIRNAME
 
-# create the directory where the CTF archive will end up
+# Create the directory where the CTF archive will end up.
 mkdir -p mydirectory/kernel
 
-# sanity check that DTrace works
-$dtrace $dt_flags -n 'BEGIN {exit(0)}'
+# Basic check that DTrace works.
+$dtrace $dt_flags                       -lvP rawtp > basic.out
 if [ $? -ne 0 ]; then
-	echo ERROR: sanity check on DTrace failed
+	echo ERROR: basic check on DTrace failed
+	cat basic.out
 	exit 1
 else
-	echo sanity check on DTrace passed
+	echo basic check on DTrace passed
 fi
 
-# verify that modpath directs us to the (empty) directory
-$dtrace $dt_flags -xmodpath=mydirectory -n 'BEGIN {exit(0)}'
+# Verify that modpath directs us to the (empty) directory, with no CTF info.
+$dtrace $dt_flags -xmodpath=mydirectory -lvP rawtp > empty.out
 if [ $? -ne 0 ]; then
-	echo DTrace correctly fails when modpath is an empty directory
-else
-	echo ERROR: DTrace unexpectedly passes with modpath set to empty directory
+	echo ERROR: empty check on DTrace failed
+	cat empty.out
 	exit 1
+else
+	echo empty check on DTrace passed
 fi
 
-# link a CTF archive to our directory
+# Link a CTF archive to our directory.
 ln -s /lib/modules/$(uname -r)/kernel/vmlinux.ctfa mydirectory/kernel/vmlinux.ctfa
 
-# verify that modpath now works
-$dtrace $dt_flags -xmodpath=mydirectory -n 'BEGIN {exit(0)}'
+# Verify that modpath now works.
+$dtrace $dt_flags -xmodpath=mydirectory -lvP rawtp > final.out
 if [ $? -ne 0 ]; then
-	echo ERROR: DTrace somehow fails
+	echo ERROR: final check on DTrace failed
+	cat final.out
 	exit 1
 else
-	echo DTrace works with modpath and a linked CTF archive
-	exit 0
+	echo final check on DTrace passed
+fi
+
+# Check the amount of CTF info we got from each run by seeing how many
+# rawtp args have non-trivial type info.  While nempty should be 0,
+# nbasic and nfinal should be substantial and likely identical (but
+# we allow a generous tolerance).
+
+nbasic=`awk '/^[	 ]*args\[/ && !/uint64_t/ && !/void \*/' basic.out | wc -l`
+nempty=`awk '/^[	 ]*args\[/ && !/uint64_t/ && !/void \*/' empty.out | wc -l`
+nfinal=`awk '/^[	 ]*args\[/ && !/uint64_t/ && !/void \*/' final.out | wc -l`
+
+if [ $nempty -ne 0 ]; then
+	echo ERROR: empty check turned up some CTF info
+	cat empty.out
+	echo got nbasic $nbasic nempty $nempty nfinal $nfinal
+	exit 1
 fi
+if [ $nbasic -lt 1000 ]; then
+	echo ERROR: basic check turned up little CTF info
+	cat basic.out
+	echo got nbasic $nbasic nempty $nempty nfinal $nfinal
+	exit 1
+fi
+if [ $nfinal -lt 1000 ]; then
+	echo ERROR: final check turned up little CTF info
+	cat final.out
+	echo got nbasic $nbasic nempty $nempty nfinal $nfinal
+	exit 1
+fi
+if [ $nbasic -gt $(($nfinal + 200)) -o $nfinal -gt $((nbasic + 200)) ]; then
+	echo $nbasic $nfinal out of range
+	echo ==== basic.out:
+	cat basic.out
+	echo ==== final.out:
+	cat final.out
+	echo got nbasic $nbasic nempty $nempty nfinal $nfinal
+	exit 1
+fi
+
+echo all checks pass
+exit 0
diff --git a/test/unittest/options/tst.modpath.x b/test/unittest/options/tst.modpath.x
deleted file mode 120000
index df5695cd..00000000
--- a/test/unittest/options/tst.modpath.x
+++ /dev/null
@@ -1 +0,0 @@
-tst.ctfpath.x
\ No newline at end of file
diff --git a/test/unittest/options/tst.modpath.x b/test/unittest/options/tst.modpath.x
new file mode 100755
index 00000000..6d483535
--- /dev/null
+++ b/test/unittest/options/tst.modpath.x
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# Skip test if there is no CTF archive.
+if [ ! -r /lib/modules/$(uname -r)/kernel/vmlinux.ctfa ]; then
+	echo "No CTF archive found for the kernel."
+	exit 2
+fi
+
+# Skip test if CTF info is not used for rawtp args[] types.  (If all rawtp
+# args[] types are "uint64_t", this is a symptom of our using the back-up
+# trial-and-error method.)
+types=`$dtrace -lvP rawtp | awk '/^[ 	]*args/ { $1 = ""; print }' | sort -u`
+if [ "$types" == " uint64_t" ]; then
+	echo "not using CTF for rawtp args types"
+	exit 2
+fi
+
+exit 0
-- 
2.18.4




More information about the DTrace-devel mailing list