From: Xiao Yang <yangx.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [RESENT RFC PATCH 5/5] st_net.sh: tst_rhost_run: Add -d option (debug)
Date: Tue, 23 Jun 2020 13:52:12 +0800 [thread overview]
Message-ID: <5EF1988C.3090008@cn.fujitsu.com> (raw)
In-Reply-To: <20200622070911.16123-6-petr.vorel@suse.com>
On 2020/6/22 15:09, Petr Vorel wrote:
> From: Petr Vorel <pvorel@suse.cz>
>
> -d debug mode (print command and netns/ssh handling into stderr)
>
> Add tst_net_debug() simple helper for printing into stderr.
>
> Also use new parameter in tst_rhost_run.sh.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Hi,
>
> RFC: I use it quite a lot, but not sure if needed.
>
> Probably using $TST_NET_DEBUG instead of -d would be better.
Hi Petr,
Agreed. $TST_NET_DEBUG is better for user to print debug info because we
don't need to change code(i.e. pass -d to tst_rhost_run()).
Debug info is only related to tst_rhost_run() so is $TST_RHOST_RUN_DEBUG
meaningful?
> If we merge "tst_test.sh: Print tst_{res, brk} into stdout" [1],
> simple tst_res_ could be used. I was also thinking about adding new flag
> "DEBUG", but that's probably not needed.
I think tst_res TINFO is enough. :-)
Thanks,
Xiao Yang
> Kind regards,
> Petr
>
> [1] https://patchwork.ozlabs.org/project/ltp/patch/20200619192542.20113-1-pvorel@suse.cz/
>
> lib/newlib_tests/shell/net/tst_rhost_run.sh | 8 +++---
> testcases/lib/tst_net.sh | 29 ++++++++++++++++-----
> 2 files changed, 27 insertions(+), 10 deletions(-)
>
> diff --git a/lib/newlib_tests/shell/net/tst_rhost_run.sh b/lib/newlib_tests/shell/net/tst_rhost_run.sh
> index 4c034a4ac..ebcd4ca03 100755
> --- a/lib/newlib_tests/shell/net/tst_rhost_run.sh
> +++ b/lib/newlib_tests/shell/net/tst_rhost_run.sh
> @@ -10,14 +10,14 @@ do_test()
> {
> local file="/etc/fstab"
>
> - tst_rhost_run -c 'which grep > /dev/null' || \
> + tst_rhost_run -d -c 'which grep > /dev/null' || \
> tst_res TCONF "grep not found on rhost"
>
> - tst_rhost_run -c "[ -f $file ]" || \
> + tst_rhost_run -d -c "[ -f $file ]" || \
> tst_res TCONF "$file not found on rhost"
>
> - tst_rhost_run -s -c "grep -q \"[^ ]\" $file"
> - tst_rhost_run -s -c "grep -q '[^ ]' $file"
> + tst_rhost_run -ds -c "grep -q \"[^ ]\" $file"
> + tst_rhost_run -ds -c "grep -q '[^ ]' $file"
>
> tst_res TPASS "tst_rhost_run is working"
> }
> diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
> index 2ed570a6b..d6845618d 100644
> --- a/testcases/lib/tst_net.sh
> +++ b/testcases/lib/tst_net.sh
> @@ -130,11 +130,17 @@ init_ltp_netspace()
> tst_restore_ipaddr rhost
> }
>
> +tst_net_debug()
> +{
> + echo "DEBUG: $@" >&2
> +}
> +
> # Run command on remote host.
> # tst_rhost_run -c CMD [-b] [-s] [-u USER]
> # Options:
> # -b run in background
> # -c CMD specify command to run (this must be binary, not shell builtin/function)
> +# -d debug mode (print command and netns/ssh handling into stderr)
> # -s safe option, if something goes wrong, will exit with TBROK
> # -u USER for ssh (default root)
> # RETURN: 0 on success, 1 on failure
> @@ -143,16 +149,17 @@ tst_rhost_run()
> local post_cmd=' || echo RTERR'
> local user="root"
> local ret=0
> - local cmd out output pre_cmd safe
> + local cmd debug out output pre_cmd rcmd sh_cmd safe use
>
> local OPTIND
> - while getopts :bsc:u: opt; do
> + while getopts :bc:dsu: opt; do
> case "$opt" in
> b) [ "${TST_USE_NETNS:-}" ] && pre_cmd= || pre_cmd="nohup"
> post_cmd=" > /dev/null 2>&1 &"
> out="1> /dev/null"
> ;;
> c) cmd="$OPTARG" ;;
> + d) debug=1 ;;
> s) safe=1 ;;
> u) user="$OPTARG" ;;
> *) tst_brk_ TBROK "tst_rhost_run: unknown option: $OPTARG" ;;
> @@ -166,14 +173,24 @@ tst_rhost_run()
> return 1
> fi
>
> + sh_cmd="$pre_cmd $cmd $post_cmd"
> +
> if [ -n "${TST_USE_NETNS:-}" ]; then
> - output=$($LTP_NETNS sh -c \
> - "$pre_cmd $cmd $post_cmd" $out 2>&1 || echo 'RTERR')
> + use="NETNS"
> + rcmd="$LTP_NETNS sh -c"
> else
> tst_require_cmds ssh
> - output=$(ssh -n -q $user@$RHOST \
> - "$pre_cmd $cmd $post_cmd" $out 2>&1 || echo 'RTERR')
> + use="SSH"
> + rcmd="ssh -n -q $user@$RHOST"
> fi
> +
> + if [ "$debug" ]; then
> + tst_net_debug "tst_rhost_run: cmd: $cmd"
> + tst_net_debug "$use: $rcmd \"$sh_cmd\" $out 2>&1"
> + fi
> +
> + output=$($rcmd "$sh_cmd" $out 2>&1 || echo 'RTERR')
> +
> echo "$output" | grep -q 'RTERR$' && ret=1
> if [ $ret -eq 1 ]; then
> output=$(echo "$output" | sed 's/RTERR//')
next prev parent reply other threads:[~2020-06-23 5:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-22 7:09 [LTP] [RESENT PATCH 0/5] tst_net.sh: Remove rsh, update docs add debug & test Petr Vorel
2020-06-22 7:09 ` [LTP] [RESENT PATCH 1/5] tst_net.sh: Remove rsh support Petr Vorel
2020-06-25 16:42 ` Alexey Kodanev
2020-06-26 6:27 ` Alexey Kodanev
2020-06-28 3:36 ` Xiao Yang
2020-06-22 7:09 ` [LTP] [RESENT PATCH 2/5] net: Update README.md Petr Vorel
2020-06-23 5:16 ` Xiao Yang
2020-06-22 7:09 ` [LTP] [RESENT PATCH 3/5] tst_net.sh: Drop 'sh -c' use from ssh in tst_rhost_run Petr Vorel
2020-06-25 16:44 ` Alexey Kodanev
2020-06-22 7:09 ` [LTP] [RESENT PATCH 4/5] net/test: Add basic testing for tst_rhost_run Petr Vorel
2020-06-25 16:52 ` Alexey Kodanev
2020-06-22 7:09 ` [LTP] [RESENT RFC PATCH 5/5] st_net.sh: tst_rhost_run: Add -d option (debug) Petr Vorel
2020-06-23 5:52 ` Xiao Yang [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-06-22 4:56 [LTP] [RESENT PATCH 0/5] tst_net.sh: Remove rsh, update docs add debug & test Petr Vorel
2020-06-22 4:56 ` [LTP] [RESENT RFC PATCH 5/5] st_net.sh: tst_rhost_run: Add -d option (debug) Petr Vorel
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=5EF1988C.3090008@cn.fujitsu.com \
--to=yangx.jy@cn.fujitsu.com \
--cc=ltp@lists.linux.it \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox