Skip to content

Commit

Permalink
selftests: mptcp: connect: use += operator to append strings
Browse files Browse the repository at this point in the history
This patch uses addition assignment operator (+=) to append strings in
mptcp_connect.sh.

For extra_args, use += instead of open-coding to make the statements
shorter.

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]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Mar 5, 2024
1 parent f224fb6 commit d2abd26
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions tools/testing/selftests/net/mptcp/mptcp_connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ do_transfer()
port=$((port_base++))

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

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

if [ -n "$testmode" ]; then
extra_args="$extra_args -m $testmode"
extra_args+=" -m $testmode"
fi

if [ -n "$extra_args" ] && $options_log; then
Expand Down Expand Up @@ -508,39 +508,43 @@ do_transfer()
fi
fi

if [ $retc -eq 0 ] && [ $rets -eq 0 ]; then
printf "[ OK ]"
mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}"
else
mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}"
fi
local extra=""

if [ $cookies -eq 2 ];then
if [ $stat_cookietx_last -ge $stat_cookietx_now ] ;then
printf " WARN: CookieSent: did not advance"
extra+=" WARN: CookieSent: did not advance"
fi
if [ $stat_cookierx_last -ge $stat_cookierx_now ] ;then
printf " WARN: CookieRecv: did not advance"
extra+=" WARN: CookieRecv: did not advance"
fi
else
if [ $stat_cookietx_last -ne $stat_cookietx_now ] ;then
printf " WARN: CookieSent: changed"
extra+=" WARN: CookieSent: changed"
fi
if [ $stat_cookierx_last -ne $stat_cookierx_now ] ;then
printf " WARN: CookieRecv: changed"
extra+=" WARN: CookieRecv: changed"
fi
fi

if [ ${stat_synrx_now_l} -gt ${expect_synrx} ]; then
printf " WARN: SYNRX: expect %d, got %d (probably retransmissions)" \
"${expect_synrx}" "${stat_synrx_now_l}"
extra+=" WARN: SYNRX: expect ${expect_synrx},"
extra+=" got ${stat_synrx_now_l} (probably retransmissions)"
fi
if [ ${stat_ackrx_now_l} -gt ${expect_ackrx} ]; then
printf " WARN: ACKRX: expect %d, got %d (probably retransmissions)" \
"${expect_ackrx}" "${stat_ackrx_now_l}"
extra+=" WARN: ACKRX: expect ${expect_ackrx},"
extra+=" got ${stat_ackrx_now_l} (probably retransmissions)"
fi

if [ $retc -eq 0 ] && [ $rets -eq 0 ]; then
printf "[ OK ]${extra:1}\n"
mptcp_lib_result_pass "${TEST_GROUP}: ${result_msg}"
else
if [ -n "${extra}" ]; then
printf "${extra:1}\n"
fi
mptcp_lib_result_fail "${TEST_GROUP}: ${result_msg}"
fi

echo
cat "$capout"
[ $retc -eq 0 ] && [ $rets -eq 0 ]
}
Expand Down Expand Up @@ -866,8 +870,8 @@ stop_if_error "Could not even run ping tests"
echo "[ OK ]"

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

reorder_delay=$((tc_delay / 4))

Expand All @@ -878,17 +882,17 @@ if [ -z "${tc_reorder}" ]; then

if [ $reorder_delay -gt 0 ] && [ $reorder1 -lt 100 ] && [ $reorder2 -gt 0 ]; then
tc_reorder="reorder ${reorder1}% ${reorder2}%"
echo -n "$tc_reorder with delay ${reorder_delay}ms "
tc_info+="$tc_reorder with delay ${reorder_delay}ms "
fi
elif [ "$tc_reorder" = "0" ];then
tc_reorder=""
elif [ "$reorder_delay" -gt 0 ];then
# reordering requires some delay
tc_reorder="reorder $tc_reorder"
echo -n "$tc_reorder with delay ${reorder_delay}ms "
tc_info+="$tc_reorder with delay ${reorder_delay}ms "
fi

echo "on ns3eth4"
echo "INFO: Using ${tc_info}on ns3eth4"

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

Expand Down

0 comments on commit d2abd26

Please sign in to comment.