From 70867817a93353653e367010b18416040740e75c Mon Sep 17 00:00:00 2001 From: Yumei Huang Date: Tue, 30 Sep 2025 09:41:58 +0800 Subject: test: Fix printf error when debug is enabled Running test pasta/tcp with debug enabled would get stuck with below error: + printf 'DEBUG: ns socat -u OPEN:__BASEPATH__/big.bin TCP6:[__GW6__%__IFNAME__]:10003\n' lib/term: line 38: printf: `_': invalid format character The error occurs because printf interprets the % character as the start of a format specifier, and the following '_' isn't one of them. Fix it by replacing 'printf "${*}"' with 'printf "%b" "${*}"'. Also update the docstring. Link: https://bugs.passt.top/show_bug.cgi?id=154 Fixes: de28c20d8051 ("test: Update lib/term for clearer output when DEBUG is enabled") Signed-off-by: Yumei Huang Reviewed-by: David Gibson Signed-off-by: Stefano Brivio --- test/lib/term | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/lib/term b/test/lib/term index 6400746..79aa2b7 100755 --- a/test/lib/term +++ b/test/lib/term @@ -29,32 +29,32 @@ PR_NC='\033[0m' PR_DELAY_INIT=100 # ms # info() - Highlight test log pane, print message to it and to log file -# $@: Message to print +# $*: Message to print info() { tmux select-pane -t ${PANE_INFO} - printf "${*}\n" >> $STATEBASE/log_pipe - printf "${*}\n" >> "${LOGFILE}" + printf "%b\n" "${*}" >> $STATEBASE/log_pipe + printf "%b\n" "${*}" >> "${LOGFILE}" } # info_n() - Highlight, print message to pane and to log file without newline -# $@: Message to print +# $*: Message to print info_n() { tmux select-pane -t ${PANE_INFO} - printf "${*}" >> $STATEBASE/log_pipe - printf "${*}" >> "${LOGFILE}" + printf "%b" "${*}" >> $STATEBASE/log_pipe + printf "%b" "${*}" >> "${LOGFILE}" } # info_nolog() - Highlight test log pane, print message to it -# $@: Message to print +# $*: Message to print info_nolog() { tmux select-pane -t ${PANE_INFO} - printf "${*}\n" >> $STATEBASE/log_pipe + printf "%b\n" "${*}" >> $STATEBASE/log_pipe } # info_nolog() - Print message to log file -# $@: Message to print +# $*: Message to print log() { - printf "${*}\n" >> "${LOGFILE}" + printf "%b\n" "${*}" >> "${LOGFILE}" } # info_nolog_n() - Send message to pane without highlighting it, without newline @@ -363,8 +363,8 @@ status_test_start() { info_check() { switch_pane ${PANE_INFO} - printf "${PR_YELLOW}?${PR_NC} ${*}" >> $STATEBASE/log_pipe - printf "? ${*}" >> "${LOGFILE}" + printf "%b" "${PR_YELLOW}?${PR_NC} ${*}" >> $STATEBASE/log_pipe + printf "? %b" "${*}" >> "${LOGFILE}" } # info_check_passed() - Display and log a new line when a check passes -- cgit v1.2.3