From e379badf6bf016b5b18359e0690caf8f8217f64e Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Tue, 4 Apr 2023 21:42:37 +0200 Subject: 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" --- tests/strace--tips.test | 53 ++++++++++++++++++++++++++++--------------------- 1 file 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 -- cgit v1.2.1