Skip to content

Commit 2a3eefc

Browse files
committed
tst_net.sh: Ignore stderr on tst_rhost_run -c tst_net_iface_prefix
This is another way to harden against the problem, which was manifested by 893ca0a and fixed by 02d5e99. There were previously two problems: 1) Unneeded multiple slow kernel config detection (TINFO: CONFIG_LATENCYTOP ...). 2) Printing TINFO message to stderr from tst_net_iface_prefix which was redirected by tst_rhost_run() to stdout and then used in "eval" in tst_net_setup_network(): eval: tst_kconfig.c:88:: not found [: tst_kconfig.c:88:: unexpected operator # ping01.sh ping01 1 TINFO: initialize 'rhost' 'ltp_ns_veth1' interface /opt/ltp/testcases/bin/ping01.sh: 142: [: tst_kconfig.c:88:: unexpected operator tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution /opt/ltp/testcases/bin/ping01.sh: 142: [: tst_kconfig.c:88:: unexpected operator ping01 1 TINFO: add remote addr 10.0.0.1/24 tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution /opt/ltp/testcases/bin/ping01.sh: 142: [: tst_kconfig.c:88:: unexpected operator ping01 1 TINFO: add remote addr fd00:1:1:1::1/64 tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_kconfig.c:667: TINFO: CONFIG_LATENCYTOP kernel option detected which might slow the execution /opt/ltp/testcases/bin/ping01.sh: 1: eval: tst_kconfig.c:88:: not found /opt/ltp/testcases/bin/ping01.sh: 1: eval: 34mTINFO:: not found /opt/ltp/testcases/bin/ping01.sh: 1: eval: 34mTINFO:: not found /opt/ltp/testcases/bin/ping01.sh: 142: [: tst_kconfig.c:88:: unexpected operator /opt/ltp/testcases/bin/ping01.sh: 1: eval: tst_kconfig.c:88:: not found /opt/ltp/testcases/bin/ping01.sh: 1: eval: 34mTINFO:: not found /opt/ltp/testcases/bin/ping01.sh: 1: eval: 34mTINFO:: not found ping01 1 TINFO: Network config (local -- remote): Link: https://lore.kernel.org/ltp/20250117143105.777229-1-pvorel@suse.cz/ Signed-off-by: Petr Vorel <pvorel@suse.cz>
1 parent e43c5b2 commit 2a3eefc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

testcases/lib/tst_net.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ tst_net_use_netns()
230230
# Options:
231231
# -b run in background
232232
# -c CMD specify command to run (this must be binary, not shell builtin/function)
233+
# -Q ignore stderr
233234
# -s safe option, if something goes wrong, will exit with TBROK
234235
# -u USER for ssh (default root)
235236
# RETURN: 0 on success, 1 on failure
@@ -239,16 +240,18 @@ tst_rhost_run()
239240
local post_cmd=' || echo RTERR'
240241
local user="root"
241242
local ret=0
243+
local stderr='2>&1'
242244
local cmd out output pre_cmd rcmd sh_cmd safe use
243245

244246
local OPTIND
245-
while getopts :bc:su: opt; do
247+
while getopts :bc:Qsu: opt; do
246248
case "$opt" in
247249
b) [ "${TST_USE_NETNS:-}" ] && pre_cmd= || pre_cmd="nohup"
248-
post_cmd=" > /dev/null 2>&1 &"
250+
post_cmd=" > /dev/null $stderr &"
249251
out="1> /dev/null"
250252
;;
251253
c) cmd="$OPTARG" ;;
254+
Q) stderr= ;;
252255
s) safe=1 ;;
253256
u) user="$OPTARG" ;;
254257
*) tst_brk_ TBROK "tst_rhost_run: unknown option: $OPTARG" ;;
@@ -275,10 +278,10 @@ tst_rhost_run()
275278

276279
if [ "$TST_NET_RHOST_RUN_DEBUG" = 1 ]; then
277280
tst_res_ TINFO "tst_rhost_run: cmd: $cmd"
278-
tst_res_ TINFO "$use: $rcmd \"$sh_cmd\" $out 2>&1"
281+
tst_res_ TINFO "$use: $rcmd \"$sh_cmd\" $out $stderr"
279282
fi
280283

281-
output=$($rcmd "$sh_cmd" $out 2>&1 || echo 'RTERR')
284+
output=$($rcmd "$sh_cmd" $out $stderr || echo 'RTERR')
282285

283286
echo "$output" | grep -q 'RTERR$' && ret=1
284287
if [ $ret -eq 1 ]; then
@@ -1089,15 +1092,15 @@ tst_net_setup_network()
10891092
tst_net_use_netns && init_ltp_netspace
10901093

10911094
eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
1092-
eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST \
1095+
eval $(tst_rhost_run -Q -c 'tst_net_iface_prefix -r '$IPV4_RHOST \
10931096
|| echo "exit $?")
10941097
eval $(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX \
10951098
$IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
10961099

10971100
if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
10981101
tst_net_check_ifaces_ipv6
10991102
eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
1100-
eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
1103+
eval $(tst_rhost_run -Q -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
11011104
|| echo "exit $?")
11021105
eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX \
11031106
$IPV6_RHOST/$IPV6_RPREFIX || echo "exit $?")

0 commit comments

Comments
 (0)