Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: mptcp: add mptcp_lib_check_transfer

To avoid duplicated code in different MPTCP selftests, we can add
and use helpers defined in mptcp_lib.sh.

check_transfer() and print_file_err() helpers are defined both in
mptcp_connect.sh and mptcp_sockopt.sh, export them into mptcp_lib.sh
and rename them with mptcp_lib_ prefix. And use them in all scripts.

Note: In mptcp_sockopt.sh it is OK to drop 'ret=1' in check_transfer()
because it will be set in run_tests() anyway.

Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20231128-send-net-next-2023107-v4-14-8d6b94150f6b@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Geliang Tang and committed by
Jakub Kicinski
9d9095bb 3a96dea9

+29 -63
+2 -27
tools/testing/selftests/net/mptcp/mptcp_connect.sh
··· 254 254 set_ethtool_flags "$ns4" ns4eth3 "$ethtool_args" 255 255 fi 256 256 257 - print_file_err() 258 - { 259 - ls -l "$1" 1>&2 260 - echo "Trailing bytes are: " 261 - tail -c 27 "$1" 262 - } 263 - 264 - check_transfer() 265 - { 266 - local in=$1 267 - local out=$2 268 - local what=$3 269 - 270 - cmp "$in" "$out" > /dev/null 2>&1 271 - if [ $? -ne 0 ] ;then 272 - echo "[ FAIL ] $what does not match (in, out):" 273 - print_file_err "$in" 274 - print_file_err "$out" 275 - 276 - return 1 277 - fi 278 - 279 - return 0 280 - } 281 - 282 257 check_mptcp_disabled() 283 258 { 284 259 local disabled_ns="ns_disabled-$rndh" ··· 458 483 return 1 459 484 fi 460 485 461 - check_transfer $sin $cout "file received by client" 486 + mptcp_lib_check_transfer $sin $cout "file received by client" 462 487 retc=$? 463 - check_transfer $cin $sout "file received by server" 488 + mptcp_lib_check_transfer $cin $sout "file received by server" 464 489 rets=$? 465 490 466 491 local stat_synrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
+2 -9
tools/testing/selftests/net/mptcp/mptcp_join.sh
··· 511 511 done | sort -n 512 512 } 513 513 514 - print_file_err() 515 - { 516 - ls -l "$1" 1>&2 517 - echo -n "Trailing bytes are: " 518 - tail -c 27 "$1" 519 - } 520 - 521 514 check_transfer() 522 515 { 523 516 local in=$1 ··· 541 548 local sum=$((0${a} + 0${b})) 542 549 if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then 543 550 fail_test "$what does not match (in, out):" 544 - print_file_err "$in" 545 - print_file_err "$out" 551 + mptcp_lib_print_file_err "$in" 552 + mptcp_lib_print_file_err "$out" 546 553 547 554 return 1 548 555 else
+24
tools/testing/selftests/net/mptcp/mptcp_lib.sh
··· 256 256 dd if=/dev/urandom of="${name}" bs="${bs}" count="${size}" 2> /dev/null 257 257 echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "${name}" 258 258 } 259 + 260 + # $1: file 261 + mptcp_lib_print_file_err() { 262 + ls -l "${1}" 1>&2 263 + echo "Trailing bytes are: " 264 + tail -c 27 "${1}" 265 + } 266 + 267 + # $1: input file ; $2: output file ; $3: what kind of file 268 + mptcp_lib_check_transfer() { 269 + local in="${1}" 270 + local out="${2}" 271 + local what="${3}" 272 + 273 + if ! cmp "$in" "$out" > /dev/null 2>&1; then 274 + echo "[ FAIL ] $what does not match (in, out):" 275 + mptcp_lib_print_file_err "$in" 276 + mptcp_lib_print_file_err "$out" 277 + 278 + return 1 279 + fi 280 + 281 + return 0 282 + }
+1 -27
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
··· 135 135 return 0 136 136 } 137 137 138 - print_file_err() 139 - { 140 - ls -l "$1" 1>&2 141 - echo "Trailing bytes are: " 142 - tail -c 27 "$1" 143 - } 144 - 145 - check_transfer() 146 - { 147 - local in=$1 148 - local out=$2 149 - local what=$3 150 - 151 - cmp "$in" "$out" > /dev/null 2>&1 152 - if [ $? -ne 0 ] ;then 153 - echo "[ FAIL ] $what does not match (in, out):" 154 - print_file_err "$in" 155 - print_file_err "$out" 156 - ret=1 157 - 158 - return 1 159 - fi 160 - 161 - return 0 162 - } 163 - 164 138 do_transfer() 165 139 { 166 140 local listener_ns="$1" ··· 206 232 check_mark $connector_ns 4 || retc=1 207 233 fi 208 234 209 - check_transfer $cin $sout "file received by server" 235 + mptcp_lib_check_transfer $cin $sout "file received by server" 210 236 rets=$? 211 237 212 238 mptcp_lib_result_code "${retc}" "mark ${ip}"