[DTrace-devel] [PATCH] test: Make the USDT "only enabled" test more stringent

eugene.loh at oracle.com eugene.loh at oracle.com
Tue Jun 3 20:35:32 UTC 2025


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

What if a program has an is-enabled probe without the corresponding
parent probe?  It should at least compile, and we test that.

Add more checks to the test:
- the is-enabled branch is not taken when run without dtrace
- the parent USDT probe is listed with "dtrace -l"
- the is-enabled branch is not taken even when run with dtrace
    if the parent probe is not enabled
- the is-enabled branch is taken when run with dtrace
    and the parent probe is enabled;  however, the parent probe
    does not fire since it is not in the test trigger

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 test/unittest/usdt/tst.onlyenabled.r  | 21 ++++++++++++++++++
 test/unittest/usdt/tst.onlyenabled.sh | 32 ++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 test/unittest/usdt/tst.onlyenabled.r

diff --git a/test/unittest/usdt/tst.onlyenabled.r b/test/unittest/usdt/tst.onlyenabled.r
new file mode 100644
index 00000000..93cb402c
--- /dev/null
+++ b/test/unittest/usdt/tst.onlyenabled.r
@@ -0,0 +1,21 @@
+run without dtrace
+USDT probe is not enabled
+
+USDT probes found:
+NNN test_provNNN test main go
+
+run with dtrace but not the USDT probe
+USDT probe is not enabled
+                   FUNCTION:NAME
+                          :BEGIN BEGIN probe fired
+
+
+
+run with dtrace and with the USDT probe
+USDT probe is enabled
+
+-- @@stderr --
+dtrace: description 'BEGIN
+                                ' matched 1 probe
+dtrace: description 'test_prov$target:::go
+                                ' matched 1 probe
diff --git a/test/unittest/usdt/tst.onlyenabled.sh b/test/unittest/usdt/tst.onlyenabled.sh
index d3487834..d1859bbc 100755
--- a/test/unittest/usdt/tst.onlyenabled.sh
+++ b/test/unittest/usdt/tst.onlyenabled.sh
@@ -5,6 +5,7 @@
 # Licensed under the Universal Permissive License v 1.0 as shown at
 # http://oss.oracle.com/licenses/upl.
 #
+# @@nosort
 if [ $# != 1 ]; then
 	echo expected one argument: '<'dtrace-path'>'
 	exit 2
@@ -32,6 +33,7 @@ if [ $? -ne 0 ]; then
 fi
 
 cat > test.c <<EOF
+#include <stdio.h>
 #include <sys/types.h>
 #include "prov.h"
 
@@ -39,7 +41,9 @@ int
 main(int argc, char **argv)
 {
 	if (TEST_PROV_GO_ENABLED())
-		return 2;
+		printf("USDT probe is enabled\n");
+	else
+		printf("USDT probe is not enabled\n");
 
 	return 0;
 }
@@ -61,4 +65,30 @@ if [ $? -ne 0 ]; then
 	exit 1
 fi
 
+# Test compiled, but does it run correctly?
+echo run without dtrace
+./test
+
+echo
+echo USDT probes found:
+$dtrace $dt_flags -c ./test -lP 'test_prov$target' \
+|& awk '/test_prov/ { gsub(/[0-9]+/, "NNN"); print $1, $2, $3, $4, $5; }'
+
+echo
+echo run with dtrace but not the USDT probe
+$dtrace $dt_flags -c ./test -n 'BEGIN
+                                {
+                                    printf("BEGIN probe fired\n");
+                                    exit(0);
+                                }' -o dt.out
+cat dt.out     # report dtrace output after trigger output
+
+echo
+echo run with dtrace and with the USDT probe
+$dtrace $dt_flags -c ./test -n 'test_prov$target:::go
+                                {
+                                    printf("ERROR: USDT probe fired!\n");
+                                    exit(1);
+                                }'
+
 exit 0
-- 
2.43.5




More information about the DTrace-devel mailing list