test: Make tests more resilient to different prid widths
PATCH v2 1/1 test: Make tests more resilient to different prid widths
From: Eugene Loh <[email protected]>
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. E.g., this happened in recent fbt work, where probe IDs for fbt probes became much smaller in value.
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.
--- 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
test/unittest/usdt/convert_PID_and_PRID.awk new file +20 -0
@@ -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; +}
test/unittest/usdt/err.argmap-null.r +1 -1
@@ -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[ ]
test/unittest/usdt/err.argmap-null.r.p deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/sed -rf -s,test_prov[0-9]*,test_provXXXX,g; s,^ *[0-9]+, XX,g;
test/unittest/usdt/err.argmap-null.r.p new file +1 -0
@@ -0,0 +1 @@ +convert_PID_and_PRID.awk
test/unittest/usdt/tst.dlclose1.r +3 -5
@@ -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
test/unittest/usdt/tst.dlclose1.r.p deleted +0 -12
@@ -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; -}
test/unittest/usdt/tst.dlclose1.r.p new file +1 -0
@@ -0,0 +1 @@ +convert_PID_and_PRID.awk
test/unittest/usdt/tst.enable_pid.r +11 -11
@@ -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
test/unittest/usdt/tst.enable_pid.r.p deleted +0 -7
@@ -1,7 +0,0 @@ -#!/usr/bin/awk -f -{ - # ignore the specific process ID - gsub(/test_prov[0-9]+/, "test_provNNN"); - - print; -}
test/unittest/usdt/tst.enable_pid.r.p new file +1 -0
@@ -0,0 +1 @@ +convert_PID_and_PRID.awk
test/unittest/usdt/tst.exec-dof-replacement.r +1 -1
@@ -1 +1 @@ -PID test_prov test2 main succeeded +PRID test_provPID test2 main succeeded
test/unittest/usdt/tst.exec-dof-replacement.r.p deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/sh -grep -v '^ *ID' | sed 's,^[0-9]*,PID,; s,prov[0-9]*,prov,g; s, *, ,g'
test/unittest/usdt/tst.exec-dof-replacement.r.p new file +1 -0
@@ -0,0 +1 @@ +convert_PID_and_PRID.awk
test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/sh -sed 's,prov\(.\)[0-9]*,prov\1PID,; s, *, ,g'
test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p new file +1 -0
@@ -0,0 +1 @@ +convert_PID_and_PRID.awk
test/unittest/usdt/tst.multiprov-dupprobe.r.p deleted +0 -5
@@ -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'
test/unittest/usdt/tst.multiprov-dupprobe.r.p new file +1 -0
@@ -0,0 +1 @@ +convert_PID_and_PRID.awk
test/unittest/usdt/tst.multiprovider-fire.r.p deleted +0 -2
@@ -1,2 +0,0 @@ -#!/bin/sh -sed 's,prov\(.\)[0-9]*,prov\1PID,; s, *, ,g'
test/unittest/usdt/tst.multiprovider-fire.r.p new file +1 -0
@@ -0,0 +1 @@ +convert_PID_and_PRID.awk
test/unittest/usdt/tst.multiprovider.r.p deleted +0 -5
@@ -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'
test/unittest/usdt/tst.multiprovider.r.p new file +1 -0
@@ -0,0 +1 @@ +convert_PID_and_PRID.awk
Signature · 1 line
2.43.5
Quoted 50 lines · On Wed, Mar 19, 2025 at 01:15:25PM -0400, [email protected] wrote:
From: Eugene Loh <[email protected]>
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. E.g., this happened in recent fbt work, where probe IDs for fbt probes became much smaller in value.
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 <[email protected]>--- 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.ptest/unittest/usdt/convert_PID_and_PRID.awk new file +0
-0
test/unittest/usdt/convert_PID_and_PRID.awk line 4
Quoted 4 lines
test/unittest/usdt/convert_PID_and_PRID.awk new file +4
-0@@ -0,0 +1,20 @@ +#!/usr/bin/gawk -f + +# ignore the banner +/^ *ID *PROVIDER *MODULE *FUNCTION *NAME *$/ { next; }
I think that using / +/ for the whitespace instances might be better, or perhaps even /[ \t]+/ if we want to guard against future use of tabs. But at a minimum / +/ seems most prudent.
test/unittest/usdt/convert_PID_and_PRID.awk line 10
Quoted 6 lines
test/unittest/usdt/convert_PID_and_PRID.awk new file +6
-0+ +# 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");
First arg of each function is a regexp, so should be specified as /.../ rather than "...".
test/unittest/usdt/convert_PID_and_PRID.awk line 13
Quoted 3 lines
test/unittest/usdt/convert_PID_and_PRID.awk new file +3
-0+ + # convert run-dependent probe ID values to "PRID" + sub("^ *[0-9]+", "PRID");
Same.
test/unittest/usdt/convert_PID_and_PRID.awk line 16
Quoted 3 lines
test/unittest/usdt/convert_PID_and_PRID.awk new file +3
-0+ + # squash blanks + gsub(" +", " ");
Same.
Quoted 223 lines
test/unittest/usdt/convert_PID_and_PRID.awk new file +4
-0+ + # print + print; +}test/unittest/usdt/err.argmap-null.r +1
-1@@ -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[ ]test/unittest/usdt/err.argmap-null.r.p deleted +0
-2@@ -1,2 +0,0 @@ -#!/bin/sed -rf -s,test_prov[0-9]*,test_provXXXX,g; s,^ *[0-9]+, XX,g;test/unittest/usdt/err.argmap-null.r.p new file +1
-0@@ -0,0 +1 @@ +convert_PID_and_PRID.awktest/unittest/usdt/tst.dlclose1.r +3
-5@@ -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 descriptiontest/unittest/usdt/tst.dlclose1.r.p deleted +0
-12@@ -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; -}test/unittest/usdt/tst.dlclose1.r.p new file +1
-0@@ -0,0 +1 @@ +convert_PID_and_PRID.awktest/unittest/usdt/tst.enable_pid.r +11
-11@@ -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 probestest/unittest/usdt/tst.enable_pid.r.p deleted +0
-7@@ -1,7 +0,0 @@ -#!/usr/bin/awk -f -{ - # ignore the specific process ID - gsub(/test_prov[0-9]+/, "test_provNNN"); - - print; -}test/unittest/usdt/tst.enable_pid.r.p new file +1
-0@@ -0,0 +1 @@ +convert_PID_and_PRID.awktest/unittest/usdt/tst.exec-dof-replacement.r +1
-1@@ -1 +1 @@ -PID test_prov test2 main succeeded +PRID test_provPID test2 main succeededtest/unittest/usdt/tst.exec-dof-replacement.r.p deleted +0
-2@@ -1,2 +0,0 @@ -#!/bin/sh -grep -v '^ *ID' | sed 's,^[0-9]*,PID,; s,prov[0-9]*,prov,g; s, *, ,g'test/unittest/usdt/tst.exec-dof-replacement.r.p new file +1
-0@@ -0,0 +1 @@ +convert_PID_and_PRID.awktest/unittest/usdt/tst.multiprov-dupprobe-fire.r.p deleted +0
-2@@ -1,2 +0,0 @@ -#!/bin/sh -sed 's,prov\(.\)[0-9]*,prov\1PID,; s, *, ,g'test/unittest/usdt/tst.multiprov-dupprobe-fire.r.p new file +1
-0@@ -0,0 +1 @@ +convert_PID_and_PRID.awktest/unittest/usdt/tst.multiprov-dupprobe.r.p deleted +0
-5@@ -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'test/unittest/usdt/tst.multiprov-dupprobe.r.p new file +1
-0@@ -0,0 +1 @@ +convert_PID_and_PRID.awktest/unittest/usdt/tst.multiprovider-fire.r.p deleted +0
-2@@ -1,2 +0,0 @@ -#!/bin/sh -sed 's,prov\(.\)[0-9]*,prov\1PID,; s, *, ,g'test/unittest/usdt/tst.multiprovider-fire.r.p new file +1
-0@@ -0,0 +1 @@ +convert_PID_and_PRID.awktest/unittest/usdt/tst.multiprovider.r.p deleted +0
-5@@ -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'test/unittest/usdt/tst.multiprovider.r.p new file +1
-0@@ -0,0 +1 @@ +convert_PID_and_PRID.awkSignature · 1 line
2.43.5