test: Make the USDT "only enabled" test more stringent
PATCH 1/1 test: Make the USDT "only enabled" test more stringent
From: Eugene Loh <[email protected]>
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
--- 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
test/unittest/usdt/tst.onlyenabled.r new file +21 -0
@@ -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
test/unittest/usdt/tst.onlyenabled.sh +31 -1
@@ -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
Signature · 1 line
2.43.5
Quoted 5 lines · eugene loh
From: Eugene Loh <[email protected]>
What if a program has an is-enabled probe without the corresponding parent probe? It should at least compile, and we test that.
Quoted 8 lines
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!
Quoted 1 line
Signed-off-by Eugene Loh <[email protected]>