diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2023-04-04 21:42:37 +0200 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2023-04-22 08:00:00 +0000 |
commit | 8de5b1e633d524d641ba9c93007939f01751ee8c (patch) | |
tree | ae3a621a806fc991889e66ce1decb72facb8cc34 | |
parent | 2bece0624ff52a26ea58e26fc48f94e01a01ec9a (diff) | |
download | strace-8de5b1e633d524d641ba9c93007939f01751ee8c.tar.gz |
tests: fix strace--tips test
Apparently, it has been broken in many places and checked the output
incorrectly, so it was basically useless. Make it a bit less broken
by properly escaping all the regular expressions and implement the logic
that actually checks the output against the expected patterns.
* tests/strace--tips.test (IFS): Set the variable to avoid stripping
whitespace from the read lines.
(grep_ere_escape): A variant of sed_re_escape that also escapes "{",
"}", and "|" characters.
Add "-r" option to the read call to avoid interpreting backslashes,
especially at the end of the line; escape "|", "/", and "\" characters
in $pat/$end/$btm definitions and fix the whitespace usage in there;
use grep_ere_escape instead of sed_re_escape; break after matching one
last line against $btm if TIPS_FULL is not set; pass "-x" option
to the grep calls.
Fixes: v5.18~38 "Raise strace awareness"
-rwxr-xr-x | tests/strace--tips.test | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/tests/strace--tips.test b/tests/strace--tips.test index 7bb89c0d0..328e55fbb 100755 --- a/tests/strace--tips.test +++ b/tests/strace--tips.test @@ -6,10 +6,15 @@ : "${TIPS_FULL:=0}" RAND_TIPS=5 MAX_TIPS=500 - +IFS=' +' tips_fmt_opt="" [ 1 -ne "$TIPS_FULL" ] || tips_fmt_opt="--tips=full" +grep_ere_escape() +{ + printf "%s" "$*" | sed 's/[].*&^$()|[\/]/\\&/g' +} # Check that simple "strace --tips=0" works as expected args='--tips=0' @@ -35,42 +40,44 @@ while [ "$i" -lt "$MAX_TIPS" ]; do j=0 end_seen=0 - cat $srcdir/strace--tips.exp | while read line; do + cat $srcdir/strace--tips.exp | while read -r line; do j="$((j + 1))" case "$j" in - 1) pat=' ______________________________________________ '"$(sed_re_escape "$line")";; - 2) pat=' / \\ '"$(sed_re_escape "$line")";; - 3) pat=' | .{44} | '"$(sed_re_escape "$line")";; - 4) pat=' | .{44} \ '"$(sed_re_escape "$line")";; - 5) pat=' | .{44} \ '"$(sed_re_escape "$line")";; - 6) pat=' | .{44} _\ '"$(sed_re_escape "$line")";; - 7) pat=' | .{44} / '"$(sed_re_escape "$line")";; - *) pat=' | .{44} | '"$(sed_re_escape "$line")";; + 1) pat=' ______________________________________________ '"$(grep_ere_escape "$line")";; + 2) pat=' \/ \\ '"$(grep_ere_escape "$line")";; + 3) pat=' \| .{44} \| '"$(grep_ere_escape "$line")";; + 4) pat=' \| .{44} \\ '"$(grep_ere_escape "$line")";; + 5) pat=' \| .{44} \\ '"$(grep_ere_escape "$line")";; + 6) pat=' \| .{44} _\\ '"$(grep_ere_escape "$line")";; + 7) pat=' \| .{44} \/ '"$(grep_ere_escape "$line")";; + *) pat=' \| .{44} \| '"$(grep_ere_escape "$line")";; esac - end=' \______________________________________________/ '"$(sed_re_escape "$line")" - btm=' '"$(sed_re_escape "$line")" + end=' \\______________________________________________\/ '"$(grep_ere_escape "$line")" + btm=' '"$(grep_ere_escape "$line")" s=$(tail -n"+$j" "${OUT}.${i}" | head -n1) if [ 0 -ne "$end_seen" ]; then - printf '%s' "$s" | grep -Eq "$btm" || \ + printf '%s' "$s" | grep -Exq "$btm" || \ fail_ "Can't match line $j of ${OUT}.${i}" \ "('$s') against '$btm'" + if [ 0 -ne "$TIPS_FULL" ]; then + continue + else + break + fi fi - printf '%s' "$s" | grep -Eqv "$pat" || continue - if [ 8 -lt "$j" ]; then - printf '%s' "$s" | grep -Eq "$end" || \ - fail_ "Can't match line $j of ${OUT}.${i}" \ - "('$s') against neither '$pat' nor '$end'" + if ! printf '%s' "$s" | grep -Exq "$pat"; then + if [ 8 -lt "$j" ]; then + printf '%s' "$s" | grep -Exq "$end" || \ + fail_ "Can't match line $j of ${OUT}.${i}" \ + "('$s') against neither '$pat' nor '$end'" - if [ 0 -ne "$TIPS_FULL" ]; then end_seen=1 else - break + fail_ "Can't match line $j of ${OUT}.${i} ('$s')" \ + "against '$pat'" fi - else - fail_ "Can't match line $j of ${OUT}.${i} ('$s')" \ - "against '$pat'" fi done |