]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests: mptcp: add mptcp_lib_check_transfer
authorGeliang Tang <geliang.tang@suse.com>
Tue, 28 Nov 2023 23:18:58 +0000 (15:18 -0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 30 Nov 2023 04:06:19 +0000 (20:06 -0800)
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>
tools/testing/selftests/net/mptcp/mptcp_connect.sh
tools/testing/selftests/net/mptcp/mptcp_join.sh
tools/testing/selftests/net/mptcp/mptcp_lib.sh
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh

index d20e278480fb620b4a1ffac93c89fead6631acea..537f180aa51e43118cf35146d8224495006d6ec3 100755 (executable)
@@ -254,31 +254,6 @@ else
        set_ethtool_flags "$ns4" ns4eth3 "$ethtool_args"
 fi
 
-print_file_err()
-{
-       ls -l "$1" 1>&2
-       echo "Trailing bytes are: "
-       tail -c 27 "$1"
-}
-
-check_transfer()
-{
-       local in=$1
-       local out=$2
-       local what=$3
-
-       cmp "$in" "$out" > /dev/null 2>&1
-       if [ $? -ne 0 ] ;then
-               echo "[ FAIL ] $what does not match (in, out):"
-               print_file_err "$in"
-               print_file_err "$out"
-
-               return 1
-       fi
-
-       return 0
-}
-
 check_mptcp_disabled()
 {
        local disabled_ns="ns_disabled-$rndh"
@@ -483,9 +458,9 @@ do_transfer()
                return 1
        fi
 
-       check_transfer $sin $cout "file received by client"
+       mptcp_lib_check_transfer $sin $cout "file received by client"
        retc=$?
-       check_transfer $cin $sout "file received by server"
+       mptcp_lib_check_transfer $cin $sout "file received by server"
        rets=$?
 
        local stat_synrx_now_l=$(mptcp_lib_get_counter "${listener_ns}" "MPTcpExtMPCapableSYNRX")
index 37f434cbfa4473494030f84535001119bce31a61..420e4b3f9ad0650df7bb5d145cfaf89df8a3ca6e 100755 (executable)
@@ -511,13 +511,6 @@ get_failed_tests_ids()
        done | sort -n
 }
 
-print_file_err()
-{
-       ls -l "$1" 1>&2
-       echo -n "Trailing bytes are: "
-       tail -c 27 "$1"
-}
-
 check_transfer()
 {
        local in=$1
@@ -548,8 +541,8 @@ check_transfer()
                local sum=$((0${a} + 0${b}))
                if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then
                        fail_test "$what does not match (in, out):"
-                       print_file_err "$in"
-                       print_file_err "$out"
+                       mptcp_lib_print_file_err "$in"
+                       mptcp_lib_print_file_err "$out"
 
                        return 1
                else
index 61be4f29a69a797d3b152049bcd0a1f38ed5fb8a..86f4003ab6f62d21462ebd1696391d7b14072dbd 100644 (file)
@@ -256,3 +256,27 @@ mptcp_lib_make_file() {
        dd if=/dev/urandom of="${name}" bs="${bs}" count="${size}" 2> /dev/null
        echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "${name}"
 }
+
+# $1: file
+mptcp_lib_print_file_err() {
+       ls -l "${1}" 1>&2
+       echo "Trailing bytes are: "
+       tail -c 27 "${1}"
+}
+
+# $1: input file ; $2: output file ; $3: what kind of file
+mptcp_lib_check_transfer() {
+       local in="${1}"
+       local out="${2}"
+       local what="${3}"
+
+       if ! cmp "$in" "$out" > /dev/null 2>&1; then
+               echo "[ FAIL ] $what does not match (in, out):"
+               mptcp_lib_print_file_err "$in"
+               mptcp_lib_print_file_err "$out"
+
+               return 1
+       fi
+
+       return 0
+}
index 96dc46eda133cada72d39ed9012f162049b2f991..c643872ddf478983b2f3000cc1100c109e521f00 100755 (executable)
@@ -135,32 +135,6 @@ check_mark()
        return 0
 }
 
-print_file_err()
-{
-       ls -l "$1" 1>&2
-       echo "Trailing bytes are: "
-       tail -c 27 "$1"
-}
-
-check_transfer()
-{
-       local in=$1
-       local out=$2
-       local what=$3
-
-       cmp "$in" "$out" > /dev/null 2>&1
-       if [ $? -ne 0 ] ;then
-               echo "[ FAIL ] $what does not match (in, out):"
-               print_file_err "$in"
-               print_file_err "$out"
-               ret=1
-
-               return 1
-       fi
-
-       return 0
-}
-
 do_transfer()
 {
        local listener_ns="$1"
@@ -232,7 +206,7 @@ do_transfer()
                check_mark $connector_ns 4 || retc=1
        fi
 
-       check_transfer $cin $sout "file received by server"
+       mptcp_lib_check_transfer $cin $sout "file received by server"
        rets=$?
 
        mptcp_lib_result_code "${retc}" "mark ${ip}"