From: eugene.loh@oracle.com
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH 19/19] test: Add another USDT open/close test
Date: Thu, 29 Aug 2024 01:25:58 -0400 [thread overview]
Message-ID: <20240829052558.3525-19-eugene.loh@oracle.com> (raw)
In-Reply-To: <20240829052558.3525-1-eugene.loh@oracle.com>
From: Eugene Loh <eugene.loh@oracle.com>
There is already a test to check that "dtrace -l" sees USDT
probes come and go as an executable loads and unloads a shared
library with USDT probes. (See dlclose1.sh.) But it could
also fail if DTrace does not immediately notice USDT probes
coming or going.
Introduce a test that allows a grace period before DTrace
notices a USDT probe come or go.
There is a deadlib.so here. It is not needed for the test.
It simply mimics other, similar tests. The real thing to do
might be to put these shared libraries, common to multiple
tests, in test/triggers.
Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
---
test/unittest/usdt/tst.dlclose4.r | 5 +
test/unittest/usdt/tst.dlclose4.sh | 225 +++++++++++++++++++++++++++++
2 files changed, 230 insertions(+)
create mode 100644 test/unittest/usdt/tst.dlclose4.r
create mode 100755 test/unittest/usdt/tst.dlclose4.sh
diff --git a/test/unittest/usdt/tst.dlclose4.r b/test/unittest/usdt/tst.dlclose4.r
new file mode 100644
index 00000000..07927a4a
--- /dev/null
+++ b/test/unittest/usdt/tst.dlclose4.r
@@ -0,0 +1,5 @@
+as expected: USDT probe appeared
+as expected: USDT probe disappeared
+as expected: USDT probe appeared
+as expected: USDT probe disappeared
+success
diff --git a/test/unittest/usdt/tst.dlclose4.sh b/test/unittest/usdt/tst.dlclose4.sh
new file mode 100755
index 00000000..015bc52c
--- /dev/null
+++ b/test/unittest/usdt/tst.dlclose4.sh
@@ -0,0 +1,225 @@
+#!/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.
+#
+PATH=/usr/bin:/usr/sbin:$PATH
+
+#
+# In this test, we send alternating USR1 and USR2 signals to an executable
+# that responds by opening and closing, respectively, a shared library with
+# USDT probes. After each signal, we check "dtrace -l" to confirm that the
+# USDT probes are and are not listed, as expected.
+#
+
+dtrace=$1
+CC=/usr/bin/gcc
+CFLAGS=
+
+DIRNAME="$tmpdir/usdt-dlclose4.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+#
+# Set up the source files.
+#
+
+cat > Makefile <<EOF
+all: main livelib.so deadlib.so
+
+main: main.o prov.o
+ \$(CC) -o main main.o -ldl
+
+main.o: main.c
+ \$(CC) -c main.c
+
+
+livelib.so: livelib.o prov.o
+ \$(CC) -shared -o livelib.so livelib.o prov.o -lc
+
+livelib.o: livelib.c prov.h
+ \$(CC) -c livelib.c
+
+prov.o: livelib.o prov.d
+ $dtrace -G -s prov.d livelib.o
+
+prov.h: prov.d
+ $dtrace -h -s prov.d
+
+
+deadlib.so: deadlib.o
+ \$(CC) -shared -o deadlib.so deadlib.o -lc
+
+deadlib.o: deadlib.c
+ \$(CC) -c deadlib.c
+
+clean:
+ rm -f main.o livelib.o prov.o prov.h deadlib.o
+
+clobber: clean
+ rm -f main livelib.so deadlib.so
+EOF
+
+cat > prov.d <<EOF
+provider test_prov {
+ probe go();
+};
+EOF
+
+cat > livelib.c <<EOF
+#include "prov.h"
+
+void
+go(void)
+{
+ TEST_PROV_GO();
+}
+EOF
+
+cat > deadlib.c <<EOF
+void
+go(void)
+{
+}
+EOF
+
+cat > main.c <<EOF
+#include <dlfcn.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void *live;
+
+/*
+ * Open and close livelib.so, thereby adding or removing USDT probes.
+ */
+
+static void my_open(int sig) {
+ live = dlopen("./livelib.so", RTLD_LAZY | RTLD_LOCAL);
+ if (live == NULL) {
+ printf("dlopen of livelib.so failed: %s\n", dlerror());
+ exit(1);
+ }
+}
+
+static void my_close(int sig) {
+ dlclose(live);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sigaction act;
+
+ /*
+ * Set USR1 (USR2) to open (close) the livelib.so.
+ */
+ act.sa_flags = 0;
+ act.sa_handler = my_open;
+ if (sigaction(SIGUSR1, &act, NULL)) {
+ printf("set handler failed\n");
+ return 1;
+ }
+ act.sa_handler = my_close;
+ if (sigaction(SIGUSR2, &act, NULL)) {
+ printf("set handler failed\n");
+ return 1;
+ }
+
+ /*
+ * Listen for signals.
+ */
+ while (pause() == -1)
+ ;
+
+ return 0;
+}
+EOF
+
+#
+# Build.
+#
+
+make > /dev/null
+if [ $? -ne 0 ]; then
+ echo "failed to build" >& 2
+ exit 1
+fi
+
+# Define a function that looks for the USDT probe with "dtrace -l".
+# For debugging, one could also check:
+# ls /run/dtrace/probes/$pid/test_prov$pid/livelib.so/go/go
+# ls /run/dtrace/stash/dof-pid/$pid/*/parsed/test_prov:livelib.so:go:go
+
+function check_USDT_probes() {
+ $dtrace -lP test_prov$pid |& awk '
+ /ID *PROVIDER *MODULE *FUNCTION *NAME/ { next }
+ /test_prov'$pid' *livelib\.so *go *go/ { exit(0) }
+ /No probe matches description/ { exit(1) }'
+ return $?
+}
+
+# Define a function that checks loading the library:
+# send USR1 and wait up to 6 seconds for the USDT probe to appear.
+
+function load_lib() {
+ kill -s USR1 $pid
+ for iter in `seq 6`; do
+ sleep 1
+ if check_USDT_probes; then
+ iter=0
+ break
+ fi
+ done
+ if [[ $iter -ne 0 ]]; then
+ echo did not see USDT probe
+ kill -s KILL $pid
+ exit 1
+ fi
+ echo as expected: USDT probe appeared
+}
+
+# Define a function that checks unloading the library:
+# send USR2 and wait up to 6 seconds for the USDT probe to disappear.
+
+function unload_lib() {
+ kill -s USR2 $pid # send USR2 to unload library and USDT probe
+ for iter in `seq 6`; do
+ sleep 1
+ if ! check_USDT_probes; then
+ iter=0
+ break
+ fi
+ done
+ if [[ $iter -ne 0 ]]; then
+ echo still see USDT probe after timeout
+ kill -s KILL $pid
+ exit 1
+ fi
+ echo as expected: USDT probe disappeared
+}
+
+# Start the process.
+
+./main &
+pid=$!
+sleep 2
+
+# Check.
+
+load_lib
+unload_lib
+load_lib
+unload_lib
+
+# Clean up.
+
+kill -s KILL $pid
+wait $pid >& /dev/null
+
+echo success
+exit 0
--
2.43.5
next prev parent reply other threads:[~2024-08-29 5:27 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 5:25 [PATCH 01/19] Change probes from having lists of clauses to lists of stmts eugene.loh
2024-08-29 5:25 ` [PATCH 02/19] Add a hook for a provider-specific "update" function eugene.loh
2024-08-29 5:25 ` [PATCH 03/19] Widen the EPID to include the PRID eugene.loh
2024-08-29 20:28 ` [DTrace-devel] " Sam James
2024-08-29 20:38 ` Kris Van Hees
2024-08-29 5:25 ` [PATCH 04/19] Eliminate dt_pdesc eugene.loh
2024-09-03 17:47 ` Eugene Loh
2024-08-29 5:25 ` [PATCH 05/19] Add flag to dt_pid_create_probes() eugene.loh
2024-09-18 20:33 ` Kris Van Hees
2024-09-24 20:24 ` Eugene Loh
2024-08-29 5:25 ` [PATCH 06/19] Allow for USDT wildcards eugene.loh
2024-09-17 17:34 ` Eugene Loh
2024-08-29 5:25 ` [PATCH 07/19] Create the BPF usdt_prids map eugene.loh
2024-08-29 5:25 ` [PATCH 08/19] Support multiple overlying probes in the uprobe trampoline eugene.loh
2024-10-24 2:42 ` Kris Van Hees
2024-10-24 13:52 ` [DTrace-devel] " Kris Van Hees
2024-10-24 23:30 ` Eugene Loh
2024-10-25 0:14 ` Kris Van Hees
2024-08-29 5:25 ` [PATCH 09/19] Use usdt_prids map to call clauses conditionally for USDT probes eugene.loh
2024-08-29 5:25 ` [PATCH 10/19] Remove the is-enabled provider eugene.loh
2024-10-24 15:18 ` Kris Van Hees
2024-10-26 1:13 ` Eugene Loh
2024-08-29 5:25 ` [PATCH 11/19] Support USDT wildcard provider descriptions eugene.loh
2024-08-29 5:25 ` [PATCH 12/19] Increase size of BPF probes map eugene.loh
2024-08-29 20:30 ` [DTrace-devel] " Sam James
2024-10-08 22:15 ` Eugene Loh
2024-08-29 5:25 ` [PATCH 13/19] Get rid of relocatable EPID, dt_nextepid, and dt_ddesc[] eugene.loh
2024-09-03 17:49 ` Eugene Loh
2024-08-29 5:25 ` [PATCH 14/19] Ignore clauses in USDT trampoline if we know they are impossible eugene.loh
2024-08-29 5:25 ` [PATCH 15/19] Ignore clauses: some clauses are impossible regardless of uprp eugene.loh
2024-08-29 20:31 ` [DTrace-devel] " Sam James
2024-09-03 19:54 ` Eugene Loh
2024-09-03 20:10 ` Kris Van Hees
2024-08-29 5:25 ` [PATCH 16/19] Ignore clauses: use underlying probe's function information eugene.loh
2024-10-24 16:52 ` Kris Van Hees
2024-08-29 5:25 ` [PATCH 17/19] test: Add a pid-USDT test eugene.loh
2024-08-29 20:32 ` [DTrace-devel] " Sam James
2024-10-04 4:49 ` Eugene Loh
2024-10-04 5:51 ` Sam James
2024-08-29 5:25 ` [PATCH 18/19] test: Add a lazy USDT test eugene.loh
2024-09-28 2:11 ` Eugene Loh
2024-08-29 5:25 ` eugene.loh [this message]
2024-10-24 17:01 ` [PATCH 19/19] test: Add another USDT open/close test Kris Van Hees
2024-09-18 14:18 ` [PATCH 01/19] Change probes from having lists of clauses to lists of stmts Kris Van Hees
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240829052558.3525-19-eugene.loh@oracle.com \
--to=eugene.loh@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox