[DTrace-devel] [PATCH 11/23] dtprobed: a few test infrastructure improvements

Nick Alcock nick.alcock at oracle.com
Thu Feb 22 18:39:08 UTC 2024


The testsuite needs a few adjustments to cater for the DOF stash.  Firstly,
just as the testsuite instance of dtprobed uses a distinct device node, it
should also use a distinct DOF stash: putting it under the test tmpdir means
that it's even using the same filesystem type (tmpfs) as the DOF stash
usually does, without colliding with anything the systemwide instance may be
doing.

Also make the cleanup interval at which dtprobed cleans up dead internal
userdata structures and scans for kill -9'd processes in the DOF stash
configurable via the already-set _DTRACE_TESTING env var, and reduce it from
its default of 128 to 5, so that the cleanup code gets a good workout.

Also test the reparsing code (which by default would never kick in when the
testsuite ran at all, because the whole testsuite run is done with a single
daemon instance, so daemon upgrades are never relevant) by arranging to
kick off a forced reparse whenever the daemon is hit with a SIGUSR2.  (A
test added in a future commit will use this.)

Finally, avoid prefixing log messages with "dtprobed DEBUG $timestamp: "
when not testing: it's formatted like that to force inclusion in the
runtest.log as a trace message, but it's emitted even for non-debugging
messages so is more than a bit confusing.  Make it a testsuite-only
thing.

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 dtprobed/dtprobed.c | 42 ++++++++++++++++++++++++++++++++++++------
 runtest.sh          | 16 ++++++++++------
 2 files changed, 46 insertions(+), 12 deletions(-)

diff --git a/dtprobed/dtprobed.c b/dtprobed/dtprobed.c
index 9775fda5..0df23643 100644
--- a/dtprobed/dtprobed.c
+++ b/dtprobed/dtprobed.c
@@ -75,12 +75,11 @@
 #define DOF_MAXSZ 512 * 1024 * 1024
 #define DOF_CHUNKSZ 64 * 1024
 
-#define CLEANUP_INTERVAL 128
-
 static struct fuse_session *cuse_session;
 
 int _dtrace_debug = 0;
 static int foreground;
+static int testing;
 void dt_debug_dump(int unused) {} 		/* For libproc.  */
 
 static pid_t parser_pid;
@@ -89,6 +88,7 @@ static int parser_out_pipe;
 static int sync_fd = -1;
 static int timeout = 5000; 			/* In seconds.  */
 static int rq_count = 0;
+static int cleanup_interval = 128;		/* In requests.  */
 
 static void helper_ioctl(fuse_req_t req, int cmd, void *arg,
 			 struct fuse_file_info *fi, unsigned int flags,
@@ -110,10 +110,12 @@ log_msg(enum fuse_log_level level, const char *fmt, va_list ap)
 		return;
 
 	if (foreground) {
-		fprintf(stderr, "dtprobed DEBUG %li: ", time(NULL));
+		if (testing)
+			fprintf(stderr, "dtprobed DEBUG %li: ", time(NULL));
 		vfprintf(stderr, fmt, ap);
 	} else if (sync_fd >= 0) {
-		daemon_log(sync_fd, "dtprobed DEBUG %li: ", time(NULL));
+		if (testing)
+			daemon_log(sync_fd, "dtprobed DEBUG %li: ", time(NULL));
 		daemon_vlog(sync_fd, fmt, ap);
 	} else
 		vsyslog(level, fmt, ap);
@@ -127,7 +129,8 @@ dt_debug_printf(const char *subsys, const char *fmt, va_list ap)
 		return;
 
 	if (foreground) {
-		fprintf(stderr, "%s DEBUG %li: ", subsys, time(NULL));
+		if (testing)
+			fprintf(stderr, "%s DEBUG %li: ", subsys, time(NULL));
 		vfprintf(stderr, fmt, ap);
 	} else if (sync_fd >= 0)
 		daemon_vlog(sync_fd, fmt, ap);
@@ -699,7 +702,7 @@ helper_ioctl(fuse_req_t req, int cmd, void *arg,
 	 * Periodically clean up old userdata (applying to pids with no live
 	 * transaction, or pids which no longer exist).
 	 */
-	if (rq_count++ > CLEANUP_INTERVAL) {
+	if (rq_count++ > cleanup_interval) {
 		cleanup_userdata();
 		dof_stash_prune_dead();
 		rq_count = 0;
@@ -916,6 +919,19 @@ loop(void)
 }
 #endif
 
+/*
+ * Force a reparse of all parsed DOF on demand.
+ *
+ * Only hooked up during in-source-tree testing.
+ */
+static void
+force_reparse(int sig)
+{
+	fuse_log(FUSE_LOG_DEBUG, "Forced reparse\n");
+	reparse_dof(parser_out_pipe, parser_in_pipe, process_dof, 1);
+	fuse_log(FUSE_LOG_DEBUG, "Forced reparse complete\n");
+}
+
 static void
 usage(void)
 {
@@ -1009,6 +1025,20 @@ main(int argc, char *argv[])
 	sa.sa_handler = SIG_IGN;
 	(void) sigaction(SIGPIPE, &sa, NULL);
 
+	/*
+	 * When doing (in-tree) testing, use a shorter cleanup interval, and
+	 * hook up a signal allowing the test scripts to force a DOF cleanup.
+	 */
+	if (getenv("_DTRACE_TESTING")) {
+		struct sigaction tmp = {0};
+
+		cleanup_interval = 5;
+		tmp.sa_handler = force_reparse;
+		tmp.sa_flags = SA_RESTART;
+		(void) sigaction(SIGUSR2, &tmp, NULL);
+		testing = 1;
+	}
+
 	dof_parser_start();
 
 	if (dof_stash_init(statedir) < 0)
diff --git a/runtest.sh b/runtest.sh
index 89dfe3ba..f04cce94 100755
--- a/runtest.sh
+++ b/runtest.sh
@@ -8,7 +8,7 @@
 #               and generated intermediate representation.
 #
 # Oracle Linux DTrace.
-# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 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.
 
@@ -551,14 +551,22 @@ resultslog()
     rm -f $testdebug
 }
 
+# Flip a few env vars to tell dtrace to produce reproducible output.
+export _DTRACE_TESTING=t
+export LANGUAGE=C
+
 if [[ -z $USE_INSTALLED ]]; then
     dtrace="$(pwd)/build*/dtrace"
     test_libdir="$(pwd)/build/dlibs"
     test_ldflags="-L$(pwd)/build"
     test_incflags="-Iinclude -Iuts/common -Ibuild -Ilibdtrace -DARCH_$arch"
     helper_device="dtrace/test-$$"
-    dtprobed_flags="-n $helper_device -F"
+    # Pre-existing directories from earlier tests are just fine!
+    # dtprobed will clean things up.
+    mkdir -p $tmpdir/run/dtrace
+    dtprobed_flags="-n $helper_device -s${tmpdir}/run/dtrace -F"
     export DTRACE_DOF_INIT_DEVNAME="/dev/$helper_device"
+    export DTRACE_OPT_DOFSTASHPATH="${tmpdir}/run/dtrace"
 
     if [[ -z $(eval echo $dtrace) ]]; then
     	echo "No dtraces available." >&2
@@ -580,10 +588,6 @@ else
 fi
 export dtrace
 
-# Flip a few env vars to tell dtrace to produce reproducible output.
-export _DTRACE_TESTING=t
-export LANGUAGE=C
-
 # Figure out if the preprocessor supports -fno-diagnostics-show-option: if it
 # does, add a bunch of options designed to make GCC output look like it used
 # to.
-- 
2.42.0




More information about the DTrace-devel mailing list