test: Make tests more resilient to different prid widths
PATCH 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. 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.
--- 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 10 lines · eugene loh
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. 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.
Quoted 9 lines
test/unittest/usdt/convert_PID_and_PRID.awk new file +3
-0@@ -0,0 +1,20 @@ +#!/usr/bin/gawk -f + +# ignore the banner
test/unittest/usdt/convert_PID_and_PRID.awk line 13
Quoted 10 lines
test/unittest/usdt/convert_PID_and_PRID.awk new file +10
-0+/^ *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.
Signature · 1 line
NULL && (void)