Skip to content

Commit e7c42bf

Browse files
Geliang Tangkuba-moo
authored andcommitted
selftests: mptcp: use += operator to append strings
This patch uses addition assignment operator (+=) to append strings instead of duplicating the variable name in mptcp_connect.sh and mptcp_join.sh. This can make the statements shorter. Note: in mptcp_connect.sh, add a local variable extra in do_transfer to save the various extra warning logs, using += to append it. And add a new variable tc_info to save various tc info, also using += to append it. This can make the code more readable and prepare for the next commit. Signed-off-by: Geliang Tang <[email protected]> Reviewed-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://lore.kernel.org/r/20240308-upstream-net-next-20240308-selftests-mptcp-unification-v1-8-4f42c347b653@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent aa76947 commit e7c42bf

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

tools/testing/selftests/net/mptcp/mptcp_connect.sh

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,15 @@ do_transfer()
323323
port=$((port + 1))
324324

325325
if [ "$rcvbuf" -gt 0 ]; then
326-
extra_args="$extra_args -R $rcvbuf"
326+
extra_args+=" -R $rcvbuf"
327327
fi
328328

329329
if [ "$sndbuf" -gt 0 ]; then
330-
extra_args="$extra_args -S $sndbuf"
330+
extra_args+=" -S $sndbuf"
331331
fi
332332

333333
if [ -n "$testmode" ]; then
334-
extra_args="$extra_args -m $testmode"
334+
extra_args+=" -m $testmode"
335335
fi
336336

337337
if [ -n "$extra_args" ] && $options_log; then
@@ -451,6 +451,7 @@ do_transfer()
451451
mptcp_lib_check_transfer $cin $sout "file received by server"
452452
rets=$?
453453

454+
local extra=""
454455
local stat_synrx_now_l
455456
local stat_ackrx_now_l
456457
local stat_cookietx_now
@@ -484,7 +485,7 @@ do_transfer()
484485
"${stat_ackrx_now_l}" "${expect_ackrx}"
485486
rets=1
486487
else
487-
printf "[ Note ] fallback due to TCP OoO"
488+
extra+=" [ Note ] fallback due to TCP OoO"
488489
fi
489490
fi
490491

@@ -507,39 +508,41 @@ do_transfer()
507508
fi
508509
fi
509510

510-
if [ $retc -eq 0 ] && [ $rets -eq 0 ]; then
511-
printf "[ OK ]"
512-
mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}"
513-
else
514-
mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}"
515-
fi
516-
517511
if [ $cookies -eq 2 ];then
518512
if [ $stat_cookietx_last -ge $stat_cookietx_now ] ;then
519-
printf " WARN: CookieSent: did not advance"
513+
extra+=" WARN: CookieSent: did not advance"
520514
fi
521515
if [ $stat_cookierx_last -ge $stat_cookierx_now ] ;then
522-
printf " WARN: CookieRecv: did not advance"
516+
extra+=" WARN: CookieRecv: did not advance"
523517
fi
524518
else
525519
if [ $stat_cookietx_last -ne $stat_cookietx_now ] ;then
526-
printf " WARN: CookieSent: changed"
520+
extra+=" WARN: CookieSent: changed"
527521
fi
528522
if [ $stat_cookierx_last -ne $stat_cookierx_now ] ;then
529-
printf " WARN: CookieRecv: changed"
523+
extra+=" WARN: CookieRecv: changed"
530524
fi
531525
fi
532526

533527
if [ ${stat_synrx_now_l} -gt ${expect_synrx} ]; then
534-
printf " WARN: SYNRX: expect %d, got %d (probably retransmissions)" \
535-
"${expect_synrx}" "${stat_synrx_now_l}"
528+
extra+=" WARN: SYNRX: expect ${expect_synrx},"
529+
extra+=" got ${stat_synrx_now_l} (probably retransmissions)"
536530
fi
537531
if [ ${stat_ackrx_now_l} -gt ${expect_ackrx} ]; then
538-
printf " WARN: ACKRX: expect %d, got %d (probably retransmissions)" \
539-
"${expect_ackrx}" "${stat_ackrx_now_l}"
532+
extra+=" WARN: ACKRX: expect ${expect_ackrx},"
533+
extra+=" got ${stat_ackrx_now_l} (probably retransmissions)"
534+
fi
535+
536+
if [ $retc -eq 0 ] && [ $rets -eq 0 ]; then
537+
printf "[ OK ]%s\n" "${extra:1}"
538+
mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}"
539+
else
540+
if [ -n "${extra}" ]; then
541+
printf "%s\n" "${extra:1}"
542+
fi
543+
mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}"
540544
fi
541545

542-
echo
543546
cat "$capout"
544547
[ $retc -eq 0 ] && [ $rets -eq 0 ]
545548
}
@@ -865,8 +868,8 @@ stop_if_error "Could not even run ping tests"
865868
echo "[ OK ]"
866869

867870
[ -n "$tc_loss" ] && tc -net "$ns2" qdisc add dev ns2eth3 root netem loss random $tc_loss delay ${tc_delay}ms
868-
echo -n "INFO: Using loss of $tc_loss "
869-
test "$tc_delay" -gt 0 && echo -n "delay $tc_delay ms "
871+
tc_info="loss of $tc_loss "
872+
test "$tc_delay" -gt 0 && tc_info+="delay $tc_delay ms "
870873

871874
reorder_delay=$((tc_delay / 4))
872875

@@ -877,17 +880,17 @@ if [ -z "${tc_reorder}" ]; then
877880

878881
if [ $reorder_delay -gt 0 ] && [ $reorder1 -lt 100 ] && [ $reorder2 -gt 0 ]; then
879882
tc_reorder="reorder ${reorder1}% ${reorder2}%"
880-
echo -n "$tc_reorder with delay ${reorder_delay}ms "
883+
tc_info+="$tc_reorder with delay ${reorder_delay}ms "
881884
fi
882885
elif [ "$tc_reorder" = "0" ];then
883886
tc_reorder=""
884887
elif [ "$reorder_delay" -gt 0 ];then
885888
# reordering requires some delay
886889
tc_reorder="reorder $tc_reorder"
887-
echo -n "$tc_reorder with delay ${reorder_delay}ms "
890+
tc_info+="$tc_reorder with delay ${reorder_delay}ms "
888891
fi
889892

890-
echo "on ns3eth4"
893+
echo "INFO: Using ${tc_info}on ns3eth4"
891894

892895
tc -net "$ns3" qdisc add dev ns3eth4 root netem delay ${reorder_delay}ms $tc_reorder
893896

tools/testing/selftests/net/mptcp/mptcp_join.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -754,18 +754,18 @@ pm_nl_check_endpoint()
754754
line="${line% }"
755755
# the dump order is: address id flags port dev
756756
[ -n "$addr" ] && expected_line="$addr"
757-
expected_line="$expected_line $id"
758-
[ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}"
759-
[ -n "$dev" ] && expected_line="$expected_line $dev"
760-
[ -n "$port" ] && expected_line="$expected_line $port"
757+
expected_line+=" $id"
758+
[ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}"
759+
[ -n "$dev" ] && expected_line+=" $dev"
760+
[ -n "$port" ] && expected_line+=" $port"
761761
else
762762
line=$(ip netns exec $ns ./pm_nl_ctl get $_id)
763763
# the dump order is: id flags dev address port
764764
expected_line="$id"
765-
[ -n "$flags" ] && expected_line="$expected_line $flags"
766-
[ -n "$dev" ] && expected_line="$expected_line $dev"
767-
[ -n "$addr" ] && expected_line="$expected_line $addr"
768-
[ -n "$_port" ] && expected_line="$expected_line $_port"
765+
[ -n "$flags" ] && expected_line+=" $flags"
766+
[ -n "$dev" ] && expected_line+=" $dev"
767+
[ -n "$addr" ] && expected_line+=" $addr"
768+
[ -n "$_port" ] && expected_line+=" $_port"
769769
fi
770770
if [ "$line" = "$expected_line" ]; then
771771
print_ok
@@ -1216,7 +1216,7 @@ chk_csum_nr()
12161216
print_check "sum"
12171217
count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr")
12181218
if [ "$count" != "$csum_ns1" ]; then
1219-
extra_msg="$extra_msg ns1=$count"
1219+
extra_msg+=" ns1=$count"
12201220
fi
12211221
if [ -z "$count" ]; then
12221222
print_skip
@@ -1229,7 +1229,7 @@ chk_csum_nr()
12291229
print_check "csum"
12301230
count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr")
12311231
if [ "$count" != "$csum_ns2" ]; then
1232-
extra_msg="$extra_msg ns2=$count"
1232+
extra_msg+=" ns2=$count"
12331233
fi
12341234
if [ -z "$count" ]; then
12351235
print_skip
@@ -1273,7 +1273,7 @@ chk_fail_nr()
12731273
print_check "ftx"
12741274
count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx")
12751275
if [ "$count" != "$fail_tx" ]; then
1276-
extra_msg="$extra_msg,tx=$count"
1276+
extra_msg+=",tx=$count"
12771277
fi
12781278
if [ -z "$count" ]; then
12791279
print_skip
@@ -1287,7 +1287,7 @@ chk_fail_nr()
12871287
print_check "failrx"
12881288
count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx")
12891289
if [ "$count" != "$fail_rx" ]; then
1290-
extra_msg="$extra_msg,rx=$count"
1290+
extra_msg+=",rx=$count"
12911291
fi
12921292
if [ -z "$count" ]; then
12931293
print_skip
@@ -1322,7 +1322,7 @@ chk_fclose_nr()
13221322
if [ -z "$count" ]; then
13231323
print_skip
13241324
elif [ "$count" != "$fclose_tx" ]; then
1325-
extra_msg="$extra_msg,tx=$count"
1325+
extra_msg+=",tx=$count"
13261326
fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx"
13271327
else
13281328
print_ok
@@ -1333,7 +1333,7 @@ chk_fclose_nr()
13331333
if [ -z "$count" ]; then
13341334
print_skip
13351335
elif [ "$count" != "$fclose_rx" ]; then
1336-
extra_msg="$extra_msg,rx=$count"
1336+
extra_msg+=",rx=$count"
13371337
fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx"
13381338
else
13391339
print_ok
@@ -1702,7 +1702,7 @@ chk_rm_nr()
17021702
count=$((count + cnt))
17031703
if [ "$count" != "$rm_subflow_nr" ]; then
17041704
suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]"
1705-
extra_msg="$extra_msg simult"
1705+
extra_msg+=" simult"
17061706
fi
17071707
if [ $count -ge "$rm_subflow_nr" ] && \
17081708
[ "$count" -le "$((rm_subflow_nr *2 ))" ]; then

0 commit comments

Comments
 (0)