[PATCH v2] Make sure all probes are listed in default case

[email protected]
Newsgroups dev.linux.lists.dtrace
Message-ID <[email protected]>
From: Eugene Loh <[email protected]>

Signed-off-by: Eugene Loh <[email protected]>
Reviewed-by: Nick Alcock <[email protected]>
---
 INCOMPATIBILITIES                           |  2 +-
 cmd/dtrace.c                                | 11 +++
 test/unittest/dtrace-util/tst.ListProbes.r  | 14 ++++
 test/unittest/dtrace-util/tst.ListProbes.sh | 83 +++++++++++++++++++++
 4 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 test/unittest/dtrace-util/tst.ListProbes.r
 create mode 100755 test/unittest/dtrace-util/tst.ListProbes.sh

diff --git a/INCOMPATIBILITIES b/INCOMPATIBILITIES
index 035c3675b..bf55019ec 100644
--- a/INCOMPATIBILITIES
+++ b/INCOMPATIBILITIES
@@ -8,7 +8,7 @@ Missing providers
 Difficulty: Medium
 Likelihood: High
 
-A number of providers are missing, including pid, fbt, and net.
+Some providers are missing.
 
 
 
diff --git a/cmd/dtrace.c b/cmd/dtrace.c
index e0e778db0..ed517abff 100644
--- a/cmd/dtrace.c
+++ b/cmd/dtrace.c
@@ -1443,6 +1443,17 @@ main(int argc, char *argv[])
 			list_prog(&g_cmdv[i]);
 
 		if (g_cmdc == 0) {
+			dtrace_cmd_t pseudo_cmd;
+
+			/*
+			 * If we are listing the default case "dtrace -l",
+			 * compile the string ":::" to give providers an
+			 * attempt to provide probes.
+			 */
+			pseudo_cmd.dc_spec = DTRACE_PROBESPEC_NAME;
+			pseudo_cmd.dc_arg = ":::";
+			compile_str(&pseudo_cmd);
+
 			if (dtrace_probe_iter(g_dtp, NULL, list_probe, NULL) < 0)
 				dfatal(NULL); /* dtrace_errmsg() only */
 		}
diff --git a/test/unittest/dtrace-util/tst.ListProbes.r b/test/unittest/dtrace-util/tst.ListProbes.r
new file mode 100644
index 000000000..ad557253f
--- /dev/null
+++ b/test/unittest/dtrace-util/tst.ListProbes.r
@@ -0,0 +1,14 @@
+cpc
+dtrace
+fbt
+io
+ip
+lockstat
+proc
+profile
+rawfbt
+rawtp
+sched
+sdt
+syscall
+tcp
diff --git a/test/unittest/dtrace-util/tst.ListProbes.sh b/test/unittest/dtrace-util/tst.ListProbes.sh
new file mode 100755
index 000000000..a747a0458
--- /dev/null
+++ b/test/unittest/dtrace-util/tst.ListProbes.sh
@@ -0,0 +1,83 @@
+#!/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.
+#
+
+##
+# ASSERTION:
+# Testing -l option gives reasonable numbers of probes for each provider.
+#
+# SECTION: dtrace Utility/-ln Option
+##
+
+dtrace=$1
+
+# Decide whether to expect lockstat (disabled prior to 5.10).
+read MAJOR MINOR <<< `uname -r | grep -Eo '^[0-9]+\.[0-9]+' | tr '.' ' '`
+if [ $MAJOR -gt 5 ]; then
+        expect_lockstat=1
+elif [ $MAJOR -eq 5 -a $MINOR -ge 10 ]; then
+        expect_lockstat=1
+else
+        expect_lockstat=0
+fi
+
+# Run "dtrace -l", print the providers, aggregate by provider, then confirm counts.
+$dtrace $dt_flags -l \
+| gawk '{ print $2 }' \
+| sort | uniq -c \
+| gawk -v LCKSTT=$expect_lockstat '
+
+    BEGIN {
+        nerr = 0;
+
+        # Fake lockstat if not expected.
+        if (LCKSTT == 0) print "lockstat";
+    }
+
+    function mycheck(lbl, val, valmin, valmax) {
+        print lbl;
+        if (val < valmin) { print "ERROR:", lbl, val, "< MIN =", valmin; nerr++ }
+        if (val > valmax) { print "ERROR:", lbl, val, "> MAX =", valmax; nerr++ }
+    }
+
+    # Skip the banner.
+    /^ +1 PROVIDER$/ { next }
+
+    # Wrong number of fields.
+    NF != 2 {
+        print "ERROR: wrong number of fields", $0;
+        nerr++;
+        next;
+    }
+
+    # Recognize some providers; apply sanity check on number of probes.
+    $2 == "cpc"      { mycheck($2, $1,     5,    500); next }
+    $2 == "dtrace"   { mycheck($2, $1,     3,      3); next }
+    $2 == "fbt"      { mycheck($2, $1, 30000, 300000); next }
+    $2 == "io"       { mycheck($2, $1,     2,     20); next }
+    $2 == "ip"       { mycheck($2, $1,     2,     20); next }
+    $2 == "lockstat" { mycheck($2, $1,     4,     40); next }
+    # nothing for pid
+    $2 == "proc"     { mycheck($2, $1,     6,     30); next }
+    $2 == "profile"  { mycheck($2, $1,     6,     30); next }
+    $2 == "rawfbt"   { mycheck($2, $1, 30000, 300000); next }
+    $2 == "rawtp"    { mycheck($2, $1,   600,   6000); next }
+    $2 == "sched"    { mycheck($2, $1,     3,     30); next }
+    $2 == "sdt"      { mycheck($2, $1,   600,   6000); next }
+    $2 == "syscall"  { mycheck($2, $1,   300,   3000); next }
+    $2 == "tcp"      { mycheck($2, $1,     8,      8); next }
+    # nothing for usdt
+
+    # Unrecognized line.
+    {
+        print "ERROR: unrecognized line", $0;
+        nerr++;
+    }
+
+    END { exit(nerr == 0 ? 0 : 1) }'
+
+exit $?
-- 
2.43.5
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.