[DTrace-devel] [PATCH 4/5] test: USDT probes with multiple providers and shared libs
eugene.loh at oracle.com
eugene.loh at oracle.com
Fri Dec 20 22:24:54 UTC 2024
From: Eugene Loh <eugene.loh at oracle.com>
A simple executable links in two shared libraries. There is
a different USDT provider for the executable and for each of
the two libraries. Each provider has probes named the same
as for the other providers, but the probes differ in arguments.
Run dtrace on the executable. The D script first dumps the
target pid for later post-processing. All USDT probes are
traced and their argument values tested.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
.../usdt/tst.multiprov-dupprobe-shlibs.r | 20 ++
.../usdt/tst.multiprov-dupprobe-shlibs.r.p | 7 +
.../usdt/tst.multiprov-dupprobe-shlibs.sh | 180 ++++++++++++++++++
3 files changed, 207 insertions(+)
create mode 100644 test/unittest/usdt/tst.multiprov-dupprobe-shlibs.r
create mode 100755 test/unittest/usdt/tst.multiprov-dupprobe-shlibs.r.p
create mode 100755 test/unittest/usdt/tst.multiprov-dupprobe-shlibs.sh
diff --git a/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.r b/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.r
new file mode 100644
index 000000000..c3b21177d
--- /dev/null
+++ b/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.r
@@ -0,0 +1,20 @@
+provmain$target:main:main:third
+provmain$target:::third abcdef 1234
+provliba$target:liba.so:libafunc:third
+provliba$target:::third 123 abc
+provliba$target:liba.so:libafunc:second
+provliba$target:::second 456
+provliba$target:liba.so:libafunc:first
+provliba$target:::first 789 def
+provmain$target:main:main:second
+provmain$target:::second 56 78 90
+provlibb$target:libb.so:libbfunc:third
+provlibb$target:::third 12 AB
+provlibb$target:libb.so:libbfunc:second
+provlibb$target:::second 34 CD
+provlibb$target:libb.so:libbfunc:first
+provlibb$target:::first 56
+provmain$target:main:main:first
+provmain$target:::first
+
+success
diff --git a/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.r.p b/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.r.p
new file mode 100755
index 000000000..ff7128a2a
--- /dev/null
+++ b/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.r.p
@@ -0,0 +1,7 @@
+#!/usr/bin/gawk -f
+
+# first line: get the target pid
+/^target = [0-9]*$/ { tgt = $3; next }
+
+# other lines: substitute the target pid with "$target"
+{ gsub(tgt, "$target"); print }
diff --git a/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.sh b/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.sh
new file mode 100755
index 000000000..6595737f9
--- /dev/null
+++ b/test/unittest/usdt/tst.multiprov-dupprobe-shlibs.sh
@@ -0,0 +1,180 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2024, 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.
+#
+
+#
+# Try multiple shared libraries with multiple providers,
+# all with duplicate probe names but with different arguments.
+#
+# @@nosort
+
+dtrace=$1
+CC=/usr/bin/gcc
+
+DIRNAME="$tmpdir/usdt-multiprov-dupprobe-shlibs.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+#
+# Set up the source files.
+#
+
+cat > provliba.d <<EOF
+provider provliba {
+ probe first(int, char *);
+ probe second(int);
+ probe third(char *a, int b) : (int b, char *a);
+};
+EOF
+
+cat > provlibb.d <<EOF
+provider provlibb {
+ probe first(int);
+ probe second(char *a, int b) : (int b, char *a);
+ probe third(int, char *);
+};
+EOF
+
+cat > provmain.d <<EOF
+provider provmain {
+ probe first();
+ probe second(int, int, int);
+ probe third(char *, int);
+};
+EOF
+
+cat > liba.c <<EOF
+#include "provliba.h"
+
+void
+libafunc(void)
+{
+ PROVLIBA_THIRD("abc", 123);
+ PROVLIBA_SECOND(456);
+ PROVLIBA_FIRST(789, "def");
+}
+EOF
+
+cat > libb.c <<EOF
+#include "provlibb.h"
+
+void
+libbfunc(void)
+{
+ PROVLIBB_THIRD(12, "AB");
+ PROVLIBB_SECOND("CD", 34);
+ PROVLIBB_FIRST(56);
+}
+EOF
+
+cat > main.c <<EOF
+#include "provmain.h"
+void libafunc(void);
+void libbfunc(void);
+
+int
+main(int c, char **v)
+{
+ PROVMAIN_THIRD("abcdef", 1234);
+ libafunc();
+ PROVMAIN_SECOND(56, 78, 90);
+ libbfunc();
+ PROVMAIN_FIRST();
+
+ return 0;
+}
+EOF
+
+#
+# Build.
+#
+
+for x in liba libb main; do
+ $dtrace $dt_flags -h -s prov$x.d
+ if [ $? -ne 0 ]; then
+ echo failed to generate header file from prov$x.d >&2
+ exit 1
+ fi
+ $CC $test_cppflags -fPIC -c $x.c
+ if [ $? -ne 0 ]; then
+ echo failed to compile test $x.c >&2
+ exit 1
+ fi
+ $dtrace $dt_flags -G -s prov$x.d $x.o
+ if [ $? -ne 0 ]; then
+ echo failed to create DOF for $x.o >&2
+ exit 1
+ fi
+done
+
+for x in liba libb; do
+ $CC $test_ldflags -shared -o $x.so $x.o prov$x.o -lc
+ if [ $? -ne 0 ]; then
+ echo failed to build $x.so >&2
+ exit 1
+ fi
+done
+
+LD_RUN_PATH=$PWD $CC $test_ldflags -o main main.o provmain.o -L. -la -lb
+if [ $? -ne 0 ]; then
+ echo failed to build main >&2
+ exit 1
+fi
+
+#
+# Run DTrace.
+#
+
+$dtrace $dt_flags -c ./main -qn '
+/* report the target pid for post processing */
+BEGIN
+{
+ printf("target = %d\n", $target);
+}
+
+/* have all USDT probes report their fully qualified probe names */
+prov*:::
+{
+ printf("%s:%s:%s:%s\n", probeprov,
+ probemod,
+ probefunc,
+ probename);
+}
+
+/* use different clauses to report args for different probes */
+provmain$target:::first
+{
+ printf("%s:::%s\n", probeprov, probename);
+}
+provliba$target:::second,
+provlibb$target:::first
+{
+ printf("%s:::%s %d\n", probeprov, probename, arg0);
+}
+provliba$target:::first,
+provliba$target:::third,
+provlibb$target:::second,
+provlibb$target:::third
+{
+ printf("%s:::%s %d %s\n", probeprov, probename, arg0, stringof(arg1));
+}
+provmain$target:::third
+{
+ printf("%s:::%s %s %d\n", probeprov, probename, stringof(arg0), arg1);
+}
+provmain$target:::second
+{
+ printf("%s:::%s %d %d %d\n", probeprov, probename, arg0, arg1, arg2);
+}
+'
+if [ $? -ne 0 ]; then
+ echo ERROR: dtrace
+ exit 1
+fi
+
+echo success
+exit 0
--
2.43.5
More information about the DTrace-devel
mailing list