public inbox for dtrace@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] test: Make tests more resilient to different prid widths
@ 2025-03-13  0:39 eugene.loh
  2025-07-16 11:15 ` Nick Alcock
  0 siblings, 1 reply; 2+ messages in thread
From: eugene.loh @ 2025-03-13  0:39 UTC (permalink / raw)
  To: dtrace, dtrace-devel

From: Eugene Loh <eugene.loh@oracle.com>

Various tests convert run-dependent values -- like PIDs and probe IDs
-- to run-independent strings before checking against their .r results
files.  But the conversions could be remarkably sensitive to the width
of probe IDs.  E.g., some conversions assumed probe IDs were flush with
the beginning of the line, but if they were narrower they were preceded
by white space and were not detected.  This will be important in up-coming
fbt work, where probe IDs for fbt probes can be much lower in value
(fewer digits).

Also, these conversions were being carried out by a hodgepodge of scripts
-- sed, awk, and grep;  some using run-independent strings like "NNN" or
"XXXX" instead of more informative "PID" and "PRID" strings;  some
incorrectly using "PID" for PRIDs, etc.

Replace these .r.p postprocessing scripts with a single script that is
more resilient to PRID widths and is commented.

Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
---
 test/unittest/usdt/convert_PID_and_PRID.awk   | 20 +++++++++++++++++
 test/unittest/usdt/err.argmap-null.r          |  2 +-
 test/unittest/usdt/err.argmap-null.r.p        |  3 +--
 test/unittest/usdt/tst.dlclose1.r             |  8 +++----
 test/unittest/usdt/tst.dlclose1.r.p           | 13 +----------
 test/unittest/usdt/tst.enable_pid.r           | 22 +++++++++----------
 test/unittest/usdt/tst.enable_pid.r.p         |  8 +------
 test/unittest/usdt/tst.exec-dof-replacement.r |  2 +-
 .../usdt/tst.exec-dof-replacement.r.p         |  3 +--
 .../usdt/tst.multiprov-dupprobe-fire.r.p      |  3 +--
 test/unittest/usdt/tst.multiprov-dupprobe.r.p |  6 +----
 test/unittest/usdt/tst.multiprovider-fire.r.p |  3 +--
 test/unittest/usdt/tst.multiprovider.r.p      |  6 +----
 13 files changed, 44 insertions(+), 55 deletions(-)
 create mode 100755 test/unittest/usdt/convert_PID_and_PRID.awk
 mode change 100755 => 120000 test/unittest/usdt/err.argmap-null.r.p
 mode change 100755 => 120000 test/unittest/usdt/tst.dlclose1.r.p
 mode change 100755 => 120000 test/unittest/usdt/tst.enable_pid.r.p
 mode change 100755 => 120000 test/unittest/usdt/tst.exec-dof-replacement.r.p
 mode change 100755 => 120000 test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p
 mode change 100755 => 120000 test/unittest/usdt/tst.multiprov-dupprobe.r.p
 mode change 100755 => 120000 test/unittest/usdt/tst.multiprovider-fire.r.p
 mode change 100755 => 120000 test/unittest/usdt/tst.multiprovider.r.p

diff --git a/test/unittest/usdt/convert_PID_and_PRID.awk b/test/unittest/usdt/convert_PID_and_PRID.awk
new file mode 100755
index 000000000..1dbb31301
--- /dev/null
+++ b/test/unittest/usdt/convert_PID_and_PRID.awk
@@ -0,0 +1,20 @@
+#!/usr/bin/gawk -f
+
+# ignore the banner
+/^ *ID *PROVIDER *MODULE *FUNCTION *NAME *$/ { next; }
+
+# process other lines
+{
+	# convert run-dependent PID values to "PID"
+	$0 = gensub("prov([abc]?)[0-9]+", "prov\\1PID", "g");
+	sub("pid [0-9]+", "pid PID");
+
+	# convert run-dependent probe ID values to "PRID"
+	sub("^ *[0-9]+", "PRID");
+
+	# squash blanks
+	gsub(" +", " ");
+
+	# print
+	print;
+}
diff --git a/test/unittest/usdt/err.argmap-null.r b/test/unittest/usdt/err.argmap-null.r
index 215475e39..97b1850de 100644
--- a/test/unittest/usdt/err.argmap-null.r
+++ b/test/unittest/usdt/err.argmap-null.r
@@ -1,2 +1,2 @@
 -- @@stderr --
-dtrace: failed to compile script test/unittest/usdt/err.argmap-null.d: line 24: index 0 is out of range for test_provXXXX:::place4 args[ ]
+dtrace: failed to compile script test/unittest/usdt/err.argmap-null.d: line 24: index 0 is out of range for test_provPID:::place4 args[ ]
diff --git a/test/unittest/usdt/err.argmap-null.r.p b/test/unittest/usdt/err.argmap-null.r.p
deleted file mode 100755
index c575983ad..000000000
--- a/test/unittest/usdt/err.argmap-null.r.p
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sed -rf
-s,test_prov[0-9]*,test_provXXXX,g; s,^ *[0-9]+, XX,g;
diff --git a/test/unittest/usdt/err.argmap-null.r.p b/test/unittest/usdt/err.argmap-null.r.p
new file mode 120000
index 000000000..11a06e058
--- /dev/null
+++ b/test/unittest/usdt/err.argmap-null.r.p
@@ -0,0 +1 @@
+convert_PID_and_PRID.awk
\ No newline at end of file
diff --git a/test/unittest/usdt/tst.dlclose1.r b/test/unittest/usdt/tst.dlclose1.r
index 7873cb51f..70bb50d76 100644
--- a/test/unittest/usdt/tst.dlclose1.r
+++ b/test/unittest/usdt/tst.dlclose1.r
@@ -1,6 +1,4 @@
-started pid NNN
- ID PROVIDER MODULE FUNCTION NAME
-NNN test_provNNN livelib.so go go
- ID PROVIDER MODULE FUNCTION NAME
+started pid PID
+PRID test_provPID livelib.so go go
 -- @@stderr --
-dtrace: failed to match test_provNNN:::: No probe matches description
+dtrace: failed to match test_provPID:::: No probe matches description
diff --git a/test/unittest/usdt/tst.dlclose1.r.p b/test/unittest/usdt/tst.dlclose1.r.p
deleted file mode 100755
index 85725f3bb..000000000
--- a/test/unittest/usdt/tst.dlclose1.r.p
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/gawk -f
-{
-	# ignore the specific probe ID or process ID
-	# (the script ensures the process ID is consistent)
-	gsub(/[0-9]+/, "NNN");
-
-	# ignore the numbers of spaces for alignment
-	# (they depend on the ID widths)
-	gsub(/ +/, " ");
-
-	print;
-}
diff --git a/test/unittest/usdt/tst.dlclose1.r.p b/test/unittest/usdt/tst.dlclose1.r.p
new file mode 120000
index 000000000..11a06e058
--- /dev/null
+++ b/test/unittest/usdt/tst.dlclose1.r.p
@@ -0,0 +1 @@
+convert_PID_and_PRID.awk
\ No newline at end of file
diff --git a/test/unittest/usdt/tst.enable_pid.r b/test/unittest/usdt/tst.enable_pid.r
index 675fcdd6f..9241202d7 100644
--- a/test/unittest/usdt/tst.enable_pid.r
+++ b/test/unittest/usdt/tst.enable_pid.r
@@ -1,14 +1,14 @@
-                   FUNCTION:NAME
-                        :tick-1s 
+ FUNCTION:NAME
+ :tick-1s 
 
-                   FUNCTION:NAME
-                        :tick-1s 
+ FUNCTION:NAME
+ :tick-1s 
 
-                   FUNCTION:NAME
-                        :tick-1s 
+ FUNCTION:NAME
+ :tick-1s 
 
-                   FUNCTION:NAME
-                        :tick-1s 
+ FUNCTION:NAME
+ :tick-1s 
 
 done
 ========== out 1
@@ -39,7 +39,7 @@ is not enabled
 === epoch ===
 success
 -- @@stderr --
-dtrace: description 'test_provNNN:::go ' matched 1 probe
-dtrace: description 'test_provNNN:::go ' matched 2 probes
-dtrace: description 'test_provNNN:::go ' matched 2 probes
+dtrace: description 'test_provPID:::go ' matched 1 probe
+dtrace: description 'test_provPID:::go ' matched 2 probes
+dtrace: description 'test_provPID:::go ' matched 2 probes
 dtrace: description 'test_prov*:::go ' matched 3 probes
diff --git a/test/unittest/usdt/tst.enable_pid.r.p b/test/unittest/usdt/tst.enable_pid.r.p
deleted file mode 100755
index baf9d2a90..000000000
--- a/test/unittest/usdt/tst.enable_pid.r.p
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/awk -f
-{
-	# ignore the specific process ID
-	gsub(/test_prov[0-9]+/, "test_provNNN");
-
-	print;
-}
diff --git a/test/unittest/usdt/tst.enable_pid.r.p b/test/unittest/usdt/tst.enable_pid.r.p
new file mode 120000
index 000000000..11a06e058
--- /dev/null
+++ b/test/unittest/usdt/tst.enable_pid.r.p
@@ -0,0 +1 @@
+convert_PID_and_PRID.awk
\ No newline at end of file
diff --git a/test/unittest/usdt/tst.exec-dof-replacement.r b/test/unittest/usdt/tst.exec-dof-replacement.r
index 7547f85e5..226ab7c8a 100644
--- a/test/unittest/usdt/tst.exec-dof-replacement.r
+++ b/test/unittest/usdt/tst.exec-dof-replacement.r
@@ -1 +1 @@
-PID test_prov test2 main succeeded
+PRID test_provPID test2 main succeeded
diff --git a/test/unittest/usdt/tst.exec-dof-replacement.r.p b/test/unittest/usdt/tst.exec-dof-replacement.r.p
deleted file mode 100755
index 1a5871f73..000000000
--- a/test/unittest/usdt/tst.exec-dof-replacement.r.p
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-grep -v '^ *ID' | sed 's,^[0-9]*,PID,; s,prov[0-9]*,prov,g; s,  *, ,g'
diff --git a/test/unittest/usdt/tst.exec-dof-replacement.r.p b/test/unittest/usdt/tst.exec-dof-replacement.r.p
new file mode 120000
index 000000000..11a06e058
--- /dev/null
+++ b/test/unittest/usdt/tst.exec-dof-replacement.r.p
@@ -0,0 +1 @@
+convert_PID_and_PRID.awk
\ No newline at end of file
diff --git a/test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p b/test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p
deleted file mode 100755
index bdbce0189..000000000
--- a/test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-sed 's,prov\(.\)[0-9]*,prov\1PID,; s,  *, ,g'
diff --git a/test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p b/test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p
new file mode 120000
index 000000000..11a06e058
--- /dev/null
+++ b/test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p
@@ -0,0 +1 @@
+convert_PID_and_PRID.awk
\ No newline at end of file
diff --git a/test/unittest/usdt/tst.multiprov-dupprobe.r.p b/test/unittest/usdt/tst.multiprov-dupprobe.r.p
deleted file mode 100755
index 5d11db2d4..000000000
--- a/test/unittest/usdt/tst.multiprov-dupprobe.r.p
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-# Remove banner.
-# Replace numerical values with generic PRID and PID labels.
-grep -v '^ *ID' | sed 's,^[0-9][0-9]*,PRID,; s,prov\(.\)[0-9]*,prov\1PID,; s,  *, ,g'
diff --git a/test/unittest/usdt/tst.multiprov-dupprobe.r.p b/test/unittest/usdt/tst.multiprov-dupprobe.r.p
new file mode 120000
index 000000000..11a06e058
--- /dev/null
+++ b/test/unittest/usdt/tst.multiprov-dupprobe.r.p
@@ -0,0 +1 @@
+convert_PID_and_PRID.awk
\ No newline at end of file
diff --git a/test/unittest/usdt/tst.multiprovider-fire.r.p b/test/unittest/usdt/tst.multiprovider-fire.r.p
deleted file mode 100755
index bdbce0189..000000000
--- a/test/unittest/usdt/tst.multiprovider-fire.r.p
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-sed 's,prov\(.\)[0-9]*,prov\1PID,; s,  *, ,g'
diff --git a/test/unittest/usdt/tst.multiprovider-fire.r.p b/test/unittest/usdt/tst.multiprovider-fire.r.p
new file mode 120000
index 000000000..11a06e058
--- /dev/null
+++ b/test/unittest/usdt/tst.multiprovider-fire.r.p
@@ -0,0 +1 @@
+convert_PID_and_PRID.awk
\ No newline at end of file
diff --git a/test/unittest/usdt/tst.multiprovider.r.p b/test/unittest/usdt/tst.multiprovider.r.p
deleted file mode 100755
index 5d11db2d4..000000000
--- a/test/unittest/usdt/tst.multiprovider.r.p
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-# Remove banner.
-# Replace numerical values with generic PRID and PID labels.
-grep -v '^ *ID' | sed 's,^[0-9][0-9]*,PRID,; s,prov\(.\)[0-9]*,prov\1PID,; s,  *, ,g'
diff --git a/test/unittest/usdt/tst.multiprovider.r.p b/test/unittest/usdt/tst.multiprovider.r.p
new file mode 120000
index 000000000..11a06e058
--- /dev/null
+++ b/test/unittest/usdt/tst.multiprovider.r.p
@@ -0,0 +1 @@
+convert_PID_and_PRID.awk
\ No newline at end of file
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] test: Make tests more resilient to different prid widths
  2025-03-13  0:39 [PATCH] test: Make tests more resilient to different prid widths eugene.loh
@ 2025-07-16 11:15 ` Nick Alcock
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Alcock @ 2025-07-16 11:15 UTC (permalink / raw)
  To: eugene.loh; +Cc: dtrace, dtrace-devel

On 13 Mar 2025, eugene loh said:

> From: Eugene Loh <eugene.loh@oracle.com>
>
> Various tests convert run-dependent values -- like PIDs and probe IDs
> -- to run-independent strings before checking against their .r results
> files.  But the conversions could be remarkably sensitive to the width
> of probe IDs.  E.g., some conversions assumed probe IDs were flush with
> the beginning of the line, but if they were narrower they were preceded
> by white space and were not detected.  This will be important in up-coming
> fbt work, where probe IDs for fbt probes can be much lower in value
> (fewer digits).

I have long wished for some way to fix this.

Reviewed-by: Nick Alcock <nick.alcock@oracle.com>

> diff --git a/test/unittest/usdt/convert_PID_and_PRID.awk b/test/unittest/usdt/convert_PID_and_PRID.awk
> new file mode 100755
> index 000000000..1dbb31301
> --- /dev/null
> +++ b/test/unittest/usdt/convert_PID_and_PRID.awk
> @@ -0,0 +1,20 @@
> +#!/usr/bin/gawk -f
> +
> +# ignore the banner
> +/^ *ID *PROVIDER *MODULE *FUNCTION *NAME *$/ { next; }
> +
> +# process other lines
> +{
> +	# convert run-dependent PID values to "PID"
> +	$0 = gensub("prov([abc]?)[0-9]+", "prov\\1PID", "g");
> +	sub("pid [0-9]+", "pid PID");
> +
> +	# convert run-dependent probe ID values to "PRID"
> +	sub("^ *[0-9]+", "PRID");

... that seems like a rather wide net to cast. I suppose as long as it's
not used outside usdt and possibly pid, this should do.

-- 
NULL && (void)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-16 11:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-13  0:39 [PATCH] test: Make tests more resilient to different prid widths eugene.loh
2025-07-16 11:15 ` Nick Alcock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox