* [PATCH] test: Make the USDT "only enabled" test more stringent
@ 2025-06-03 20:35 eugene.loh
2025-06-13 14:19 ` Nick Alcock
0 siblings, 1 reply; 2+ messages in thread
From: eugene.loh @ 2025-06-03 20:35 UTC (permalink / raw)
To: dtrace, dtrace-devel
From: Eugene Loh <eugene.loh@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@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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] test: Make the USDT "only enabled" test more stringent
2025-06-03 20:35 [PATCH] test: Make the USDT "only enabled" test more stringent eugene.loh
@ 2025-06-13 14:19 ` Nick Alcock
0 siblings, 0 replies; 2+ messages in thread
From: Nick Alcock @ 2025-06-13 14:19 UTC (permalink / raw)
To: eugene.loh; +Cc: dtrace, dtrace-devel
On 3 Jun 2025, eugene loh said:
> From: Eugene Loh <eugene.loh@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
Nice!
> Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Nick Alcock <nick.alcock@oracle.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-13 14:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-03 20:35 [PATCH] test: Make the USDT "only enabled" test more stringent eugene.loh
2025-06-13 14:19 ` Nick Alcock
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox