From: David Gibson <david@gibson.dropbear.id.au>
To: Yumei Huang <yuhuang@redhat.com>
Cc: passt-dev@passt.top, sbrivio@redhat.com
Subject: Re: [PATCH] test: Fix printf error when debug is enabled
Date: Mon, 29 Sep 2025 16:41:15 +1000 [thread overview]
Message-ID: <aNoqCzM2qMoCe5zK@zatzit> (raw)
In-Reply-To: <20250929063014.17293-1-yuhuang@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3124 bytes --]
On Mon, Sep 29, 2025 at 02:30:14PM +0800, Yumei Huang wrote:
> 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 "${*}\n"' with 'printf "%s\n" "$*"'.
> 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 <yuhuang@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
I'm a little embarrassed I didn't spot this gotcha when I suggested
the initial change.
> ---
> test/lib/term | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/test/lib/term b/test/lib/term
> index 6400746..2293474 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 "%s\n" "$*" >> $STATEBASE/log_pipe
> + printf "%s\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 "%s\n" "$*" >> $STATEBASE/log_pipe
> + printf "%s\n" "$*" >> "${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 "%s\n" "$*" >> $STATEBASE/log_pipe
> }
>
> # info_nolog() - Print message to log file
> -# $@: Message to print
> +# $*: Message to print
> log() {
> - printf "${*}\n" >> "${LOGFILE}"
> + printf "%s\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 "%s" "${PR_YELLOW}?${PR_NC} ${*}" >> $STATEBASE/log_pipe
> + printf "? %s" "${*}" >> "${LOGFILE}"
> }
>
> # info_check_passed() - Display and log a new line when a check passes
> --
> 2.47.0
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2025-09-29 6:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 6:30 Yumei Huang
2025-09-29 6:41 ` David Gibson [this message]
2025-09-29 22:24 ` Stefano Brivio
2025-09-30 0:23 ` David Gibson
2025-09-30 1:32 ` Yumei Huang
2025-09-30 11:13 ` Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aNoqCzM2qMoCe5zK@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
--cc=yuhuang@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).