[PATCH] test: add -l and -lv tests for stapsdt probes

Kris Van Hees <[email protected]>
Newsgroups dev.linux.lists.dtrace
Message-ID <SJ0PR10MB56723A5B7174C2DF77C01DC2C22DA@SJ0PR10MB5672.namprd10.prod.outlook.com>
The stapsdt support in DTrace provides limited support for argument data
for probes.  The number of arguments passed to a probe and their native
type (signed or unsigned int of size 1, 2, 4, or 8 bytes) is discoverable.

Signed-off-by: Kris Van Hees
<[email protected]>
---
 test/unittest/usdt/tst.stapsdt-notes-l.sh  | 46 ++++++++++++++++++++++
 test/unittest/usdt/tst.stapsdt-notes-lv.sh | 46 ++++++++++++++++++++++
 2 files changed, 92 insertions(+)
 create mode 100755 test/unittest/usdt/tst.stapsdt-notes-l.sh
 create mode 100755 test/unittest/usdt/tst.stapsdt-notes-lv.sh

diff --git a/test/unittest/usdt/tst.stapsdt-notes-l.sh b/test/unittest/usdt/tst.stapsdt-notes-l.sh
new file mode 100755
index 000000000..663ba07b1
--- /dev/null
+++ b/test/unittest/usdt/tst.stapsdt-notes-l.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+
+# This test covers stapsdt probes fired by the STAP_PROBEn macros,
+# testing listing probes.
+
+if [ $# != 1 ]; then
+	echo expected one argument: '<'dtrace-path'>'
+	exit 2
+fi
+
+dtrace=$1
+CC=/usr/bin/gcc
+CFLAGS="-I${PWD}/test/unittest/usdt"
+
+DIRNAME="$tmpdir/usdt-notes.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+cat > test.c <<EOF
+#include <sdt_notes.h>
+
+int
+main(int argc, char **argv)
+{
+	STAP_PROBE(test_prov, zero);
+	STAP_PROBE1(test_prov, one, argc);
+	STAP_PROBE2(test_prov, two, 2, 3);
+	STAP_PROBE4(test_prov, args, argc, argv[0], argv[1] + 4, 18);
+}
+EOF
+
+${CC} ${CFLAGS} -o test test.c
+if [ $? -ne 0 ]; then
+	echo "failed to compile test.c" >& 2
+	exit 1
+fi
+
+$dtrace -c './test arg1val' -lP test_prov\$target
+status=$?
+
+exit $status
diff --git a/test/unittest/usdt/tst.stapsdt-notes-lv.sh b/test/unittest/usdt/tst.stapsdt-notes-lv.sh
new file mode 100755
index 000000000..f7b2d8691
--- /dev/null
+++ b/test/unittest/usdt/tst.stapsdt-notes-lv.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+
+# This test covers stapsdt probes fired by the STAP_PROBEn macros,
+# testing listing probes.
+
+if [ $# != 1 ]; then
+	echo expected one argument: '<'dtrace-path'>'
+	exit 2
+fi
+
+dtrace=$1
+CC=/usr/bin/gcc
+CFLAGS="-I${PWD}/test/unittest/usdt"
+
+DIRNAME="$tmpdir/usdt-notes.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+cat > test.c <<EOF
+#include <sdt_notes.h>
+
+int
+main(int argc, char **argv)
+{
+	STAP_PROBE(test_prov, zero);
+	STAP_PROBE1(test_prov, one, argc);
+	STAP_PROBE2(test_prov, two, argc, argv[0][0]);
+	STAP_PROBE4(test_prov, args, argc, argv[0], argv[1] + 4, 18);
+}
+EOF
+
+${CC} ${CFLAGS} -o test test.c
+if [ $? -ne 0 ]; then
+	echo "failed to compile test.c" >& 2
+	exit 1
+fi
+
+$dtrace -c './test arg1val' -lvP test_prov\$target
+status=$?
+
+exit $status
-- 
2.45.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.