Skip to contentSkip to conversation

add helpers and vars in mptcp_lib.sh, part 4

PATCH In review Geliang Tang 3 participants 14 messages Mar 8, 2024

Subsystems (3)
lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v2 cover add helpers and vars in mptcp_lib.sh, part 4

From: Geliang Tang <[email protected]>

v2:
- add new patches #1 & #3
- #2 drop the tab in
"\tExpected value for '${var}': '${!exp}', got '${!var}'.", this breaks the alignments.
- drop 'rc' in patch #2 & #4
- use declare in #5
- drop
extra_srv_args+=" $extra_args"
extra_cl_args+=" $extra_args"
in #7

v1:
MPTCP events related patches and two cleanups.

Geliang Tang (7):
selftests: mptcp: call test_fail without argument
selftests: mptcp: extract mptcp_lib_check_expected
selftests: mptcp: print_test out of verify_listener_events
selftests: mptcp: add mptcp_lib_verify_listener_events
selftests: mptcp: declare event macros in mptcp_lib
selftests: mptcp: use KSFT_SKIP/KSFT_PASS/KSFT_FAIL
selftests: mptcp: join: use += operator to append strings

 .../selftests/net/mptcp/mptcp_connect.sh      | 18 ++--
 .../testing/selftests/net/mptcp/mptcp_join.sh | 92 +++++++------------
 .../testing/selftests/net/mptcp/mptcp_lib.sh  | 67 ++++++++++++++
 .../selftests/net/mptcp/mptcp_sockopt.sh      |  4 +-
 .../testing/selftests/net/mptcp/pm_netlink.sh |  8 +-
 .../selftests/net/mptcp/simult_flows.sh       |  4 +-
 .../selftests/net/mptcp/userspace_pm.sh       | 92 +++++--------------
 7 files changed, 143 insertions(+), 142 deletions(-)
Signature · 1 line
2.40.1
author reviewer
#1 lore raw

PATCH v2 1/7 selftests: mptcp: call test_fail without argument

From: Geliang Tang <[email protected]>

This patch modifies test_fail() to call mptcp_lib_pr_fail() only if there are arguments (if [ ${#} -gt 0 ]) in userspace_pm.sh, add arguments "unexpected type: ${type}" when calling test_fail() from test_remove(). Then mptcp_lib_pr_fail() can be used in check_expected_one() instead of test_fail().

The same in mptcp_join.sh, calling fail_test() without argument, and adapt this helper not to call print_fail() in this case.

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh   |  7 +++++--
 tools/testing/selftests/net/mptcp/userspace_pm.sh | 12 ++++++++----
 2 files changed, 13 insertions(+), 6 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +5 -2
index cecf09d14f46..7392fc9f5ea1 100755
@@ -452,7 +452,9 @@ fail_test()
 {
 	ret=1
 
-	print_fail "${@}"
+	if [ ${#} -gt 0 ]; then
+		print_fail "${@}"
+	fi
 
 	# just in case a test is marked twice as failed
 	if [ ${last_test_failed} -eq 0 ]; then
@@ -2834,7 +2836,8 @@ verify_listener_events()
 		print_ok
 		return 0
 	fi
-	fail_test "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport"
+	print_fail "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport"
+	fail_test
 }
 
 add_addr_ports_tests()
tools/testing/selftests/net/mptcp/userspace_pm.sh +8 -4
index 4e29aa9c2529..bc2f0184b1eb 100755
@@ -85,7 +85,10 @@ test_skip()
 # $1: msg
 test_fail()
 {
-	mptcp_lib_pr_fail "${@}"
+	if [ ${#} -gt 0 ]
+	then
+		mptcp_lib_pr_fail "${@}"
+	fi
 	ret=1
 	mptcp_lib_result_fail "${test_name}"
 }
@@ -239,7 +242,7 @@ check_expected_one()
 
 	if [ "${prev_ret}" = "0" ]
 	then
-		test_fail
+		mptcp_lib_pr_fail
 	fi
 
 	mptcp_lib_print_err "\tExpected value for '${var}': '${!exp}', got '${!var}'."
@@ -263,6 +266,7 @@ check_expected()
 		return 0
 	fi
 
+	test_fail
 	return 1
 }
 
@@ -412,7 +416,7 @@ test_remove()
 	then
 		test_pass
 	else
-		test_fail
+		test_fail "unexpected type: ${type}"
 	fi
 
 	# RM_ADDR using an invalid addr id should result in no action
@@ -425,7 +429,7 @@ test_remove()
 	then
 		test_pass
 	else
-		test_fail
+		test_fail "unexpected type: ${type}"
 	fi
 
 	# RM_ADDR from the client to server machine
Signature · 1 line
2.40.1
author reviewer
#2 lore raw

PATCH v2 2/7 selftests: mptcp: extract mptcp_lib_check_expected

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Extract the main part of check_expected() in userspace_pm.sh to a new function mptcp_lib_check_expected() in mptcp_lib.sh. It will be used in both mptcp_john.sh and userspace_pm.sh. check_expected_one() is moved into mptcp_lib.sh too as mptcp_lib_check_expected_one().

---
 .../testing/selftests/net/mptcp/mptcp_lib.sh  | 30 +++++++++++++++++
 .../selftests/net/mptcp/userspace_pm.sh       | 33 ++-----------------
 2 files changed, 32 insertions(+), 31 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_lib.sh +30 -0
index ea39392c68e7..44491f18ed17 100644
@@ -438,3 +438,33 @@ mptcp_lib_print_title() {
 	# shellcheck disable=SC2059 # the format is in a variable
 	printf "${MPTCP_LIB_TEST_FORMAT}" "$((++MPTCP_LIB_TEST_COUNTER))" "${*}"
 }
+
+# $1: var name ; $2: prev ret
+mptcp_lib_check_expected_one() {
+	local var="${1}"
+	local exp="e_${var}"
+	local prev_ret="${2}"
+
+	if [ "${!var}" = "${!exp}" ]; then
+		return 0
+	fi
+
+	if [ "${prev_ret}" = "0" ]; then
+		mptcp_lib_pr_fail
+	fi
+
+	mptcp_lib_print_err "Expected value for '${var}': '${!exp}', got '${!var}'."
+	return 1
+}
+
+# $@: all var names to check
+mptcp_lib_check_expected() {
+	local rc=0
+	local var
+
+	for var in "${@}"; do
+		mptcp_lib_check_expected_one "${var}" "${rc}" || rc=1
+	done
+
+	return "${rc}"
+}
tools/testing/selftests/net/mptcp/userspace_pm.sh +2 -31
index bc2f0184b1eb..6d0862a1b68d 100755
@@ -5,7 +5,7 @@
 # code but we accept it.
 #shellcheck disable=SC2086
 
-# Some variables are used below but indirectly, see check_expected_one()
+# Some variables are used below but indirectly, see verify_*_event()
 #shellcheck disable=SC2034
 
 . "$(dirname "${0}")/mptcp_lib.sh"
@@ -228,39 +228,10 @@ make_connection()
 	fi
 }
 
-# $1: var name ; $2: prev ret
-check_expected_one()
-{
-	local var="${1}"
-	local exp="e_${var}"
-	local prev_ret="${2}"
-
-	if [ "${!var}" = "${!exp}" ]
-	then
-		return 0
-	fi
-
-	if [ "${prev_ret}" = "0" ]
-	then
-		mptcp_lib_pr_fail
-	fi
-
-	mptcp_lib_print_err "\tExpected value for '${var}': '${!exp}', got '${!var}'."
-	return 1
-}
-
 # $@: all var names to check
 check_expected()
 {
-	local rc=0
-	local var
-
-	for var in "${@}"
-	do
-		check_expected_one "${var}" "${rc}" || rc=1
-	done
-
-	if [ ${rc} -eq 0 ]
+	if mptcp_lib_check_expected "${@}"
 	then
 		test_pass
 		return 0
Signature · 1 line
2.40.1
author reviewer
#3 lore raw

PATCH v2 3/7 selftests: mptcp: print_test out of verify_listener_events

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

verify_listener_events() helper will be exported into mptcp_lib.sh as a public function, but print_test() is invoked in it, which is a private function in userspace_pm.sh only. So this patch moves print_test() out of verify_listener_events().

---
 tools/testing/selftests/net/mptcp/userspace_pm.sh | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
tools/testing/selftests/net/mptcp/userspace_pm.sh +2 -6
index 6d0862a1b68d..e9aea44edee5 100755
@@ -845,12 +845,6 @@ verify_listener_events()
 	local saddr
 	local sport
 
-	if [ $e_type = $LISTENER_CREATED ]; then
-		print_test "CREATE_LISTENER $e_saddr:$e_sport"
-	elif [ $e_type = $LISTENER_CLOSED ]; then
-		print_test "CLOSE_LISTENER $e_saddr:$e_sport"
-	fi
-
 	type=$(mptcp_lib_evts_get_info type $evt $e_type)
 	family=$(mptcp_lib_evts_get_info family $evt $e_type)
 	sport=$(mptcp_lib_evts_get_info sport $evt $e_type)
@@ -882,6 +876,7 @@ test_listener()
 	local listener_pid=$!
 
 	sleep 0.5
+	print_test "CREATE_LISTENER 10.0.2.2:$client4_port"
 	verify_listener_events $client_evts $LISTENER_CREATED $AF_INET 10.0.2.2 $client4_port
 
 	# ADD_ADDR from client to server machine reusing the subflow port
@@ -898,6 +893,7 @@ test_listener()
 	mptcp_lib_kill_wait $listener_pid
 
 	sleep 0.5
+	print_test "CLOSE_LISTENER 10.0.2.2:$client4_port"
 	verify_listener_events $client_evts $LISTENER_CLOSED $AF_INET 10.0.2.2 $client4_port
 }
 
Signature · 1 line
2.40.1
author reviewer
#4 lore raw

PATCH v2 4/7 selftests: mptcp: add mptcp_lib_verify_listener_events

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

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

The helper verify_listener_events() is defined both in mptcp_join.sh and userspace_pm.sh, export it into mptcp_lib.sh and rename it with mptcp_lib_ prefix. Use this new helper in both scripts.

---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 21 +--------------
 .../testing/selftests/net/mptcp/mptcp_lib.sh  | 26 +++++++++++++++++++
 .../selftests/net/mptcp/userspace_pm.sh       | 21 +++------------
 3 files changed, 30 insertions(+), 38 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +1 -20
index 7392fc9f5ea1..84eb01a16fb8 100755
@@ -2794,15 +2794,9 @@ AF_INET6=10
 
 verify_listener_events()
 {
-	local evt=$1
 	local e_type=$2
-	local e_family=$3
 	local e_saddr=$4
 	local e_sport=$5
-	local type
-	local family
-	local saddr
-	local sport
 	local name
 
 	if [ $e_type = $LISTENER_CREATED ]; then
@@ -2820,23 +2814,10 @@ verify_listener_events()
 		return
 	fi
 
-	type=$(mptcp_lib_evts_get_info type "$evt" "$e_type")
-	family=$(mptcp_lib_evts_get_info family "$evt" "$e_type")
-	sport=$(mptcp_lib_evts_get_info sport "$evt" "$e_type")
-	if [ $family ] && [ $family = $AF_INET6 ]; then
-		saddr=$(mptcp_lib_evts_get_info saddr6 "$evt" "$e_type")
-	else
-		saddr=$(mptcp_lib_evts_get_info saddr4 "$evt" "$e_type")
-	fi
-
-	if [ $type ] && [ $type = $e_type ] &&
-	   [ $family ] && [ $family = $e_family ] &&
-	   [ $saddr ] && [ $saddr = $e_saddr ] &&
-	   [ $sport ] && [ $sport = $e_sport ]; then
+	if mptcp_lib_verify_listener_events "${@}"; then
 		print_ok
 		return 0
 	fi
-	print_fail "$e_type:$type $e_family:$family $e_saddr:$saddr $e_sport:$sport"
 	fail_test
 }
 
tools/testing/selftests/net/mptcp/mptcp_lib.sh +26 -0
index 44491f18ed17..a977a722fb3d 100644
@@ -468,3 +468,29 @@ mptcp_lib_check_expected() {
 
 	return "${rc}"
 }
+
+# shellcheck disable=SC2034 # Some variables are used below but indirectly
+mptcp_lib_verify_listener_events() {
+	local evt=${1}
+	local e_type=${2}
+	local e_family=${3}
+	local e_saddr=${4}
+	local e_sport=${5}
+	local type
+	local family
+	local saddr
+	local sport
+	local rc=0
+
+	type=$(mptcp_lib_evts_get_info type "${evt}" "${e_type}")
+	family=$(mptcp_lib_evts_get_info family "${evt}" "${e_type}")
+	if [ "${family}" ] && [ "${family}" = "${AF_INET6}" ]; then
+		saddr=$(mptcp_lib_evts_get_info saddr6 "${evt}" "${e_type}")
+	else
+		saddr=$(mptcp_lib_evts_get_info saddr4 "${evt}" "${e_type}")
+	fi
+	sport=$(mptcp_lib_evts_get_info sport "${evt}" "${e_type}")
+
+	mptcp_lib_check_expected "type" "family" "saddr" "sport" || rc="${?}"
+	return "${rc}"
+}
tools/testing/selftests/net/mptcp/userspace_pm.sh +3 -18
index e9aea44edee5..1e0b39e5525c 100755
@@ -835,26 +835,11 @@ test_prio()
 
 verify_listener_events()
 {
-	local evt=$1
-	local e_type=$2
-	local e_family=$3
-	local e_saddr=$4
-	local e_sport=$5
-	local type
-	local family
-	local saddr
-	local sport
-
-	type=$(mptcp_lib_evts_get_info type $evt $e_type)
-	family=$(mptcp_lib_evts_get_info family $evt $e_type)
-	sport=$(mptcp_lib_evts_get_info sport $evt $e_type)
-	if [ $family ] && [ $family = $AF_INET6 ]; then
-		saddr=$(mptcp_lib_evts_get_info saddr6 $evt $e_type)
+	if mptcp_lib_verify_listener_events "${@}"; then
+		test_pass
 	else
-		saddr=$(mptcp_lib_evts_get_info saddr4 $evt $e_type)
+		test_fail
 	fi
-
-	check_expected "type" "family" "saddr" "sport"
 }
 
 test_listener()
Signature · 1 line
2.40.1
author reviewer
#5 lore raw

PATCH v2 5/7 selftests: mptcp: declare event macros in mptcp_lib

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

MPTCP event macros (SUB_ESTABLISHED, LISTENER_CREATED, LISTENER_CLOSED), and the protocol family macros (AF_INET, AF_INET6) are defined in both mptcp_join.sh and userspace_pm.sh. In order not to duplicate code, this patch declares them all in mptcp_lib.sh with MPTCP_LIB_ prefixs.

---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 23 ++++++++-----------
 .../testing/selftests/net/mptcp/mptcp_lib.sh  | 11 +++++++++
 .../selftests/net/mptcp/userspace_pm.sh       | 18 +++++++--------
 3 files changed, 29 insertions(+), 23 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +9 -14
index 84eb01a16fb8..fc301789a8b5 100755
@@ -2785,13 +2785,6 @@ backup_tests()
 	fi
 }
 
-SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
-LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
-LISTENER_CLOSED=16  #MPTCP_EVENT_LISTENER_CLOSED
-
-AF_INET=2
-AF_INET6=10
-
 verify_listener_events()
 {
 	local e_type=$2
@@ -2799,9 +2792,9 @@ verify_listener_events()
 	local e_sport=$5
 	local name
 
-	if [ $e_type = $LISTENER_CREATED ]; then
+	if [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CREATED ]; then
 		name="LISTENER_CREATED"
-	elif [ $e_type = $LISTENER_CLOSED ]; then
+	elif [ $e_type = $MPTCP_LIB_EVENT_LISTENER_CLOSED ]; then
 		name="LISTENER_CLOSED "
 	else
 		name="$e_type"
@@ -2856,8 +2849,10 @@ add_addr_ports_tests()
 		chk_add_nr 1 1 1
 		chk_rm_nr 1 1 invert
 
-		verify_listener_events $evts_ns1 $LISTENER_CREATED $AF_INET 10.0.2.1 10100
-		verify_listener_events $evts_ns1 $LISTENER_CLOSED $AF_INET 10.0.2.1 10100
+		verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CREATED \
+				       $MPTCP_LIB_AF_INET 10.0.2.1 10100
+		verify_listener_events $evts_ns1 $MPTCP_LIB_EVENT_LISTENER_CLOSED \
+				       $MPTCP_LIB_AF_INET 10.0.2.1 10100
 		kill_events_pids
 	fi
 
@@ -3463,11 +3458,11 @@ userspace_tests()
 		userspace_pm_chk_get_addr "${ns1}" "10" "id 10 flags signal 10.0.2.1"
 		userspace_pm_chk_get_addr "${ns1}" "20" "id 20 flags signal 10.0.3.1"
 		userspace_pm_rm_addr $ns1 10
-		userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $SUB_ESTABLISHED
+		userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $MPTCP_LIB_EVENT_SUB_ESTABLISHED
 		userspace_pm_chk_dump_addr "${ns1}" \
 			"id 20 flags signal 10.0.3.1" "after rm_addr 10"
 		userspace_pm_rm_addr $ns1 20
-		userspace_pm_rm_sf $ns1 10.0.3.1 $SUB_ESTABLISHED
+		userspace_pm_rm_sf $ns1 10.0.3.1 $MPTCP_LIB_EVENT_SUB_ESTABLISHED
 		userspace_pm_chk_dump_addr "${ns1}" "" "after rm_addr 20"
 		chk_rm_nr 2 2 invert
 		chk_mptcp_info subflows 0 subflows 0
@@ -3494,7 +3489,7 @@ userspace_tests()
 			"subflow"
 		userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2"
 		userspace_pm_rm_addr $ns2 20
-		userspace_pm_rm_sf $ns2 10.0.3.2 $SUB_ESTABLISHED
+		userspace_pm_rm_sf $ns2 10.0.3.2 $MPTCP_LIB_EVENT_SUB_ESTABLISHED
 		userspace_pm_chk_dump_addr "${ns2}" \
 			"" \
 			"after rm_addr 20"
tools/testing/selftests/net/mptcp/mptcp_lib.sh +11 -0
index a977a722fb3d..d529b4b37af8 100644
@@ -8,6 +8,17 @@ readonly KSFT_SKIP=4
 # shellcheck disable=SC2155 # declare and assign separately
 readonly KSFT_TEST="${MPTCP_LIB_KSFT_TEST:-$(basename "${0}" .sh)}"
 
+# These variables are used in some selftests, read-only
+declare -rx MPTCP_LIB_EVENT_ANNOUNCED=6         # MPTCP_EVENT_ANNOUNCED
+declare -rx MPTCP_LIB_EVENT_REMOVED=7           # MPTCP_EVENT_REMOVED
+declare -rx MPTCP_LIB_EVENT_SUB_ESTABLISHED=10  # MPTCP_EVENT_SUB_ESTABLISHED
+declare -rx MPTCP_LIB_EVENT_SUB_CLOSED=11       # MPTCP_EVENT_SUB_CLOSED
+declare -rx MPTCP_LIB_EVENT_LISTENER_CREATED=15 # MPTCP_EVENT_LISTENER_CREATED
+declare -rx MPTCP_LIB_EVENT_LISTENER_CLOSED=16  # MPTCP_EVENT_LISTENER_CLOSED
+
+declare -rx MPTCP_LIB_AF_INET=2
+declare -rx MPTCP_LIB_AF_INET6=10
+
 MPTCP_LIB_SUBTESTS=()
 MPTCP_LIB_SUBTESTS_DUPLICATED=0
 MPTCP_LIB_TEST_COUNTER=0
tools/testing/selftests/net/mptcp/userspace_pm.sh +9 -9
index 1e0b39e5525c..72dca742280f 100755
@@ -19,15 +19,15 @@ if ! mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then
 fi
 mptcp_lib_check_tools ip
 
-ANNOUNCED=6        # MPTCP_EVENT_ANNOUNCED
-REMOVED=7          # MPTCP_EVENT_REMOVED
-SUB_ESTABLISHED=10 # MPTCP_EVENT_SUB_ESTABLISHED
-SUB_CLOSED=11      # MPTCP_EVENT_SUB_CLOSED
-LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
-LISTENER_CLOSED=16  #MPTCP_EVENT_LISTENER_CLOSED
-
-AF_INET=2
-AF_INET6=10
+ANNOUNCED=${MPTCP_LIB_EVENT_ANNOUNCED}
+REMOVED=${MPTCP_LIB_EVENT_REMOVED}
+SUB_ESTABLISHED=${MPTCP_LIB_EVENT_SUB_ESTABLISHED}
+SUB_CLOSED=${MPTCP_LIB_EVENT_SUB_CLOSED}
+LISTENER_CREATED=${MPTCP_LIB_EVENT_LISTENER_CREATED}
+LISTENER_CLOSED=${MPTCP_LIB_EVENT_LISTENER_CLOSED}
+
+AF_INET=${MPTCP_LIB_AF_INET}
+AF_INET6=${MPTCP_LIB_AF_INET6}
 
 file=""
 server_evts=""
Signature · 1 line
2.40.1
author reviewer
#6 lore raw

PATCH v2 6/7 selftests: mptcp: use KSFT_SKIP/KSFT_PASS/KSFT_FAIL

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch uses the public var KSFT_SKIP in mptcp_lib.sh instead of ksft_skip, and drop 'ksft_skip=4' in mptcp_join.sh.

Use KSFT_PASS and KSFT_FAIL macros instead of 0 and 1 after 'exit ' and 'ret=' in all scripts:

        exit 0 -> exit ${KSFT_PASS}
        exit 1 -> exit ${KSFT_FAIL}
         ret=0 ->  ret=${KSFT_PASS}
         ret=1 ->  ret=${KSFT_FAIL}
---
 .../selftests/net/mptcp/mptcp_connect.sh       | 18 +++++++++---------
 .../testing/selftests/net/mptcp/mptcp_join.sh  | 13 ++++++-------
 .../selftests/net/mptcp/mptcp_sockopt.sh       |  4 ++--
 .../testing/selftests/net/mptcp/pm_netlink.sh  |  8 ++++----
 .../selftests/net/mptcp/simult_flows.sh        |  4 ++--
 .../selftests/net/mptcp/userspace_pm.sh        |  4 ++--
 6 files changed, 25 insertions(+), 26 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +9 -9
index cb1837f2761a..4c4248554826 100755
@@ -65,14 +65,14 @@ while getopts "$optstring" option;do
 	case "$option" in
 	"h")
 		usage $0
-		exit 0
+		exit ${KSFT_PASS}
 		;;
 	"d")
 		if [ $OPTARG -ge 0 ];then
 			tc_delay="$OPTARG"
 		else
 			echo "-d requires numeric argument, got \"$OPTARG\"" 1>&2
-			exit 1
+			exit ${KSFT_FAIL}
 		fi
 		;;
 	"e")
@@ -96,7 +96,7 @@ while getopts "$optstring" option;do
 			sndbuf="$OPTARG"
 		else
 			echo "-S requires numeric argument, got \"$OPTARG\"" 1>&2
-			exit 1
+			exit ${KSFT_FAIL}
 		fi
 		;;
 	"R")
@@ -104,7 +104,7 @@ while getopts "$optstring" option;do
 			rcvbuf="$OPTARG"
 		else
 			echo "-R requires numeric argument, got \"$OPTARG\"" 1>&2
-			exit 1
+			exit ${KSFT_FAIL}
 		fi
 		;;
 	"m")
@@ -121,7 +121,7 @@ while getopts "$optstring" option;do
 		;;
 	"?")
 		usage $0
-		exit 1
+		exit ${KSFT_FAIL}
 		;;
 	esac
 done
@@ -263,7 +263,7 @@ check_mptcp_disabled()
 	if [ "$(ip netns exec ${disabled_ns} sysctl net.mptcp.enabled | awk '{ print $3 }')" -ne 1 ]; then
 		mptcp_lib_pr_fail "net.mptcp.enabled sysctl is not 1 by default"
 		mptcp_lib_result_fail "net.mptcp.enabled sysctl is not 1 by default"
-		ret=1
+		ret=${KSFT_FAIL}
 		return 1
 	fi
 	ip netns exec ${disabled_ns} sysctl -q net.mptcp.enabled=0
@@ -276,7 +276,7 @@ check_mptcp_disabled()
 	if [ ${err} -eq 0 ]; then
 		mptcp_lib_pr_fail "New MPTCP socket cannot be blocked via sysctl"
 		mptcp_lib_result_fail "New MPTCP socket cannot be blocked via sysctl"
-		ret=1
+		ret=${KSFT_FAIL}
 		return 1
 	fi
 
@@ -302,7 +302,7 @@ do_ping()
 
 	if [ $rc -ne 0 ] ; then
 		mptcp_lib_pr_fail "$listener_ns -> $connect_addr connectivity"
-		ret=1
+		ret=${KSFT_FAIL}
 
 		return 1
 	fi
@@ -821,7 +821,7 @@ log_if_error()
 		mptcp_lib_pr_fail "${msg}"
 
 		final_ret=${ret}
-		ret=0
+		ret=${KSFT_PASS}
 
 		return ${final_ret}
 	fi
tools/testing/selftests/net/mptcp/mptcp_join.sh +6 -7
index fc301789a8b5..140d80289b51 100755
@@ -25,7 +25,6 @@ err=""
 capout=""
 ns1=""
 ns2=""
-ksft_skip=4
 iptables="iptables"
 ip6tables="ip6tables"
 timeout_poll=30
@@ -392,15 +391,15 @@ setup_fail_rules()
 		-p tcp \
 		-m length --length 150:9999 \
 		-m statistic --mode nth --packet 1 --every 99999 \
-		-j MARK --set-mark 42 || return ${ksft_skip}
+		-j MARK --set-mark 42 || return ${KSFT_SKIP}
 
-	tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${ksft_skip}
+	tc -n $ns2 qdisc add dev ns2eth$i clsact || return ${KSFT_SKIP}
 	tc -n $ns2 filter add dev ns2eth$i egress \
 		protocol ip prio 1000 \
 		handle 42 fw \
 		action pedit munge offset 148 u8 invert \
 		pipe csum tcp \
-		index 100 || return ${ksft_skip}
+		index 100 || return ${KSFT_SKIP}
 }
 
 reset_with_fail()
@@ -414,7 +413,7 @@ reset_with_fail()
 	local rc=0
 	setup_fail_rules "${@}" || rc=$?
 
-	if [ ${rc} -eq ${ksft_skip} ]; then
+	if [ ${rc} -eq ${KSFT_SKIP} ]; then
 		mark_as_skipped "unable to set the 'fail' rules"
 		return 1
 	fi
@@ -450,7 +449,7 @@ reset_with_tcp_filter()
 # $1: err msg
 fail_test()
 {
-	ret=1
+	ret=${KSFT_FAIL}
 
 	if [ ${#} -gt 0 ]; then
 		print_fail "${@}"
@@ -3632,7 +3631,7 @@ usage()
 {
 	if [ -n "${1}" ]; then
 		echo "${1}"
-		ret=1
+		ret=${KSFT_FAIL}
 	fi
 
 	echo "mptcp_join usage:"
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +2 -2
index 96aa8f71bbb0..e2d70c18786e 100755
@@ -105,7 +105,7 @@ check_mark()
 		if [ $v -ne 0 ]; then
 			mptcp_lib_pr_fail "got $tables $values in ns $ns," \
 					  "not 0 - not all expected packets marked"
-			ret=1
+			ret=${KSFT_FAIL}
 			return 1
 		fi
 	done
@@ -178,7 +178,7 @@ do_transfer()
 
 		mptcp_lib_result_fail "transfer ${ip}"
 
-		ret=1
+		ret=${KSFT_FAIL}
 		return 1
 	fi
 	if ! mptcp_lib_check_transfer $cin $sout "file received by server"; then
tools/testing/selftests/net/mptcp/pm_netlink.sh +4 -4
index 69ffff8b076b..6ab8c5d36340 100755
@@ -19,11 +19,11 @@ while getopts "$optstring" option;do
 	case "$option" in
 	"h")
 		usage $0
-		exit 0
+		exit ${KSFT_PASS}
 		;;
 	"?")
 		usage $0
-		exit 1
+		exit ${KSFT_FAIL}
 		;;
 	esac
 done
@@ -57,13 +57,13 @@ check()
 	mptcp_lib_check_output "${err}" "${cmd}" "${expected}" || rc=${?}
 	if [ ${rc} -eq 2 ]; then
 		mptcp_lib_result_fail "${msg} # error ${rc}"
-		ret=1
+		ret=${KSFT_FAIL}
 	elif [ ${rc} -eq 0 ]; then
 		mptcp_lib_print_ok "[ OK ]"
 		mptcp_lib_result_pass "${msg}"
 	elif [ ${rc} -eq 1 ]; then
 		mptcp_lib_result_fail "${msg} # different output"
-		ret=1
+		ret=${KSFT_FAIL}
 	fi
 }
 
tools/testing/selftests/net/mptcp/simult_flows.sh +2 -2
index 4ee18406ee50..68ee92eccccb 100755
@@ -263,7 +263,7 @@ while getopts "bcdh" option;do
 	case "$option" in
 	"h")
 		usage $0
-		exit 0
+		exit ${KSFT_PASS}
 		;;
 	"b")
 		bail=1
@@ -276,7 +276,7 @@ while getopts "bcdh" option;do
 		;;
 	"?")
 		usage $0
-		exit 1
+		exit ${KSFT_FAIL}
 		;;
 	esac
 done
tools/testing/selftests/net/mptcp/userspace_pm.sh +2 -2
index 72dca742280f..9e2981f2d7f5 100755
@@ -89,7 +89,7 @@ test_fail()
 	then
 		mptcp_lib_pr_fail "${@}"
 	fi
-	ret=1
+	ret=${KSFT_FAIL}
 	mptcp_lib_result_fail "${test_name}"
 }
 
@@ -209,7 +209,7 @@ make_connection()
 	else
 		test_fail "Expected tokens (c:${client_token} - s:${server_token}) and server (c:${client_serverside} - s:${server_serverside})"
 		mptcp_lib_result_print_all_tap
-		exit 1
+		exit ${KSFT_FAIL}
 	fi
 
 	if [ "$is_v6" = "v6" ]
Signature · 1 line
2.40.1
author reviewer
#7 lore raw

PATCH v2 7/7 selftests: mptcp: join: use += operator to append strings

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch uses addition assignment operator (+=) to append strings instead of open-coding in mptcp_join.sh. This can make the statements shorter.

---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 30 +++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +15 -15
index 140d80289b51..5e9211e89825 100755
@@ -755,18 +755,18 @@ pm_nl_check_endpoint()
 		line="${line% }"
 		# the dump order is: address id flags port dev
 		[ -n "$addr" ] && expected_line="$addr"
-		expected_line="$expected_line $id"
-		[ -n "$_flags" ] && expected_line="$expected_line ${_flags//","/" "}"
-		[ -n "$dev" ] && expected_line="$expected_line $dev"
-		[ -n "$port" ] && expected_line="$expected_line $port"
+		expected_line+=" $id"
+		[ -n "$_flags" ] && expected_line+=" ${_flags//","/" "}"
+		[ -n "$dev" ] && expected_line+=" $dev"
+		[ -n "$port" ] && expected_line+=" $port"
 	else
 		line=$(ip netns exec $ns ./pm_nl_ctl get $_id)
 		# the dump order is: id flags dev address port
 		expected_line="$id"
-		[ -n "$flags" ] && expected_line="$expected_line $flags"
-		[ -n "$dev" ] && expected_line="$expected_line $dev"
-		[ -n "$addr" ] && expected_line="$expected_line $addr"
-		[ -n "$_port" ] && expected_line="$expected_line $_port"
+		[ -n "$flags" ] && expected_line+=" $flags"
+		[ -n "$dev" ] && expected_line+=" $dev"
+		[ -n "$addr" ] && expected_line+=" $addr"
+		[ -n "$_port" ] && expected_line+=" $_port"
 	fi
 	if [ "$line" = "$expected_line" ]; then
 		print_ok
@@ -1217,7 +1217,7 @@ chk_csum_nr()
 	print_check "sum"
 	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtDataCsumErr")
 	if [ "$count" != "$csum_ns1" ]; then
-		extra_msg="$extra_msg ns1=$count"
+		extra_msg+=" ns1=$count"
 	fi
 	if [ -z "$count" ]; then
 		print_skip
@@ -1230,7 +1230,7 @@ chk_csum_nr()
 	print_check "csum"
 	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtDataCsumErr")
 	if [ "$count" != "$csum_ns2" ]; then
-		extra_msg="$extra_msg ns2=$count"
+		extra_msg+=" ns2=$count"
 	fi
 	if [ -z "$count" ]; then
 		print_skip
@@ -1274,7 +1274,7 @@ chk_fail_nr()
 	print_check "ftx"
 	count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPFailTx")
 	if [ "$count" != "$fail_tx" ]; then
-		extra_msg="$extra_msg,tx=$count"
+		extra_msg+=",tx=$count"
 	fi
 	if [ -z "$count" ]; then
 		print_skip
@@ -1288,7 +1288,7 @@ chk_fail_nr()
 	print_check "failrx"
 	count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPFailRx")
 	if [ "$count" != "$fail_rx" ]; then
-		extra_msg="$extra_msg,rx=$count"
+		extra_msg+=",rx=$count"
 	fi
 	if [ -z "$count" ]; then
 		print_skip
@@ -1323,7 +1323,7 @@ chk_fclose_nr()
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$fclose_tx" ]; then
-		extra_msg="$extra_msg,tx=$count"
+		extra_msg+=",tx=$count"
 		fail_test "got $count MP_FASTCLOSE[s] TX expected $fclose_tx"
 	else
 		print_ok
@@ -1334,7 +1334,7 @@ chk_fclose_nr()
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$fclose_rx" ]; then
-		extra_msg="$extra_msg,rx=$count"
+		extra_msg+=",rx=$count"
 		fail_test "got $count MP_FASTCLOSE[s] RX expected $fclose_rx"
 	else
 		print_ok
@@ -1703,7 +1703,7 @@ chk_rm_nr()
 		count=$((count + cnt))
 		if [ "$count" != "$rm_subflow_nr" ]; then
 			suffix="$count in [$rm_subflow_nr:$((rm_subflow_nr*2))]"
-			extra_msg="$extra_msg simult"
+			extra_msg+=" simult"
 		fi
 		if [ $count -ge "$rm_subflow_nr" ] && \
 		   [ "$count" -le "$((rm_subflow_nr *2 ))" ]; then
Signature · 1 line
2.40.1
#8 lore raw

Re: selftests: mptcp: join: use += operator to append strings: Tests Results

Hi Geliang,

Thank you for your modifications, that's great!

Our CI (GitHub Action) did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8199507878

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/8829c80abe7d

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

#9 lore raw

Re: selftests: mptcp: join: use += operator to append strings: Tests Results

In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI (Cirrus) did some validations with a debug kernel and here is its report:

- KVM Validation: debug (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_regressions 🔴:
- Task: https://cirrus-ci.com/task/5589567441469440
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5589567441469440/summary/summary.txt

- KVM Validation: debug (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6715467348312064
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6715467348312064/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/8829c80abe7d

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-debug

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer Reviewed-by on the v2 series
#10 lore raw
In reply to Geliang Tang

Hi Geliang,

Quoted 13 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v2:
- add new patches #1 & #3
- #2 drop the tab in
"\tExpected value for '${var}': '${!exp}', got '${!var}'.", this breaks the alignments.
- drop 'rc' in patch #2 & #4
- use declare in #5
- drop
extra_srv_args+=" $extra_args"
extra_cl_args+=" $extra_args"
in #7

Thank you for the new version!

Did you check that after your modifications errors are still caught as before, and presented correctly? (the CI didn't get any error)

If yes, the series looks good to me:

To be able to send them to netdev before the closure of the merge window -- if I can apply these patches in our tree soon --, I might have to squash 2 commits, maybe "use += operator to append strings" for join and connect, I will see.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#11 lore raw

Hi Geliang,

Quoted 17 lines · Matthieu Baerts

Hi Geliang,

Quoted 13 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v2:
- add new patches #1 & #3
- #2 drop the tab in
"\tExpected value for '${var}': '${!exp}', got '${!var}'.", this breaks the alignments.
- drop 'rc' in patch #2 & #4
- use declare in #5
- drop
extra_srv_args+=" $extra_args"
extra_cl_args+=" $extra_args"
in #7

Quoted 4 lines

Thank you for the new version!

Did you check that after your modifications errors are still caught as before, and presented correctly? (the CI didn't get any error)

While waiting for your reply to this question ↑, I just applied these patches in our tree (feat. for net-next), so I can check if we can already send them to netdev today or tomorrow:

New patches for t/upstream:
- a472412db36f: selftests: mptcp: call test_fail without argument
- b4d6c3097bd0: selftests: mptcp: extract mptcp_lib_check_expected
- f826a35f7b2d: selftests: mptcp: print_test out of verify_listener_events
- f469a988b798: selftests: mptcp: add mptcp_lib_verify_listener_events
- 0f5aa3b047a7: selftests: mptcp: declare event macros in mptcp_lib
- 31fffc8fa3b8: selftests: mptcp: use KSFT_SKIP/KSFT_PASS/KSFT_FAIL
- 4913857b325c: selftests: mptcp: join: use += operator to append strings
- Results: 2d8b9fa0983b..2c35e2ddd1b1 (export)

Tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20240308T121027

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#12 lore raw

Hi Matt,

Quoted 25 lines · Matthieu Baerts

Hi Geliang,

Quoted 21 lines · Matthieu Baerts

Hi Geliang,

Quoted 13 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v2:
- add new patches #1 & #3
- #2 drop the tab in
"\tExpected value for '${var}': '${!exp}', got '${!var}'.", this breaks the alignments.
- drop 'rc' in patch #2 & #4
- use declare in #5
- drop
extra_srv_args+=" $extra_args"
extra_cl_args+=" $extra_args"
in #7

Thank you for the new version!

Did you check that after your modifications errors are still caught as before, and presented correctly? (the CI didn't get any error)

Yes, I checked the error logs, they are fine as before.

Old userspace_pm log:

34 MP_PRIO TX [ OK ]
35 MP_PRIO RX [ OK ]
INFO: Listener tests
36 CREATE_LISTENER 0:57916 [FAIL]

	Expected value for 'family': '0', got '2'.
	Expected value for 'saddr': '0', got '10.0.2.2'.
37 CLOSE_LISTENER 0:57916                                              [FAIL]
	Expected value for 'family': '0', got '2'.
	Expected value for 'saddr': '0', got '10.0.2.2'.

... ...
not ok 36 - userspace_pm: CREATE_LISTENER 0:57916
not ok 37 - userspace_pm: CLOSE_LISTENER 0:57916

New userspace_pm log:

34 MP_PRIO TX [ OK ]
35 MP_PRIO RX [ OK ]
INFO: Listener tests
36 CREATE_LISTENER 10.0.2.2:57310 [FAIL]
Expected value for 'family': '0', got '2'. Expected value for 'saddr': '0', got '10.0.2.2'.
37 CLOSE_LISTENER 10.0.2.2:57310 [FAIL]
Expected value for 'family': '0', got '2'. Expected value for 'saddr': '0', got '10.0.2.2'. ... ...
not ok 36 - userspace_pm: CREATE_LISTENER 10.0.2.2:57310 not ok 37 - userspace_pm: CLOSE_LISTENER 10.0.2.2:57310

Old mptcp_join.sh log:

rm [ OK ]
rmsf [ OK ]
Info: invert
LISTENER_CREATED 0:10100 [FAIL] 15:15 0:2 0:10.0.2.1 10100:10100
Server ns stats

MPTcpExtPortAdd                 1                  0.0
MPTcpExtMPJoinPortSynAckRx      1                  0.0
MPTcpExtRmAddr                  1                  0.0
... ...
      LISTENER_CLOSED  0:10100            [FAIL] 16:16 0:2 0:10.0.2.1 10100:10100

... ...
not ok 3 - mptcp_join: remove single address with port

New mptcp_join.sh log:

rmsf [ OK ]
Info: invert
LISTENER_CREATED 10.0.2.1:10100 [FAIL]
Expected value for 'family': '0', got '2'.
Expected value for 'saddr': '0', got '10.0.2.1'.

MPTcpExtPortAdd                 1                  0.0
MPTcpExtMPJoinPortSynAckRx      1                  0.0
MPTcpExtRmAddr                  1                  0.0
... ...
      LISTENER_CLOSED  10.0.2.1:10100     [FAIL]

Expected value for 'family': '0', got '2'. Expected value for 'saddr': '0', got '10.0.2.1'. ... ...
not ok 3 - mptcp_join: remove single address with port

Thanks,
-Geliang

Quoted 23 lines

While waiting for your reply to this question ↑, I just applied these patches in our tree (feat. for net-next), so I can check if we can already send them to netdev today or tomorrow:

New patches for t/upstream:
- a472412db36f: selftests: mptcp: call test_fail without argument
- b4d6c3097bd0: selftests: mptcp: extract mptcp_lib_check_expected
- f826a35f7b2d: selftests: mptcp: print_test out of verify_listener_events
- f469a988b798: selftests: mptcp: add mptcp_lib_verify_listener_events
- 0f5aa3b047a7: selftests: mptcp: declare event macros in mptcp_lib
- 31fffc8fa3b8: selftests: mptcp: use KSFT_SKIP/KSFT_PASS/KSFT_FAIL
- 4913857b325c: selftests: mptcp: join: use += operator to append strings
- Results: 2d8b9fa0983b..2c35e2ddd1b1 (export)

Tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20240308T121027

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#13 lore raw

Hi Geliang,

Quoted 23 lines · Geliang Tang

Hi Matt,

Quoted 20 lines · Matthieu Baerts

Hi Geliang,

Quoted 17 lines · Matthieu Baerts

Hi Geliang,

Quoted 13 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v2:
- add new patches #1 & #3
- #2 drop the tab in
"\tExpected value for '${var}': '${!exp}', got '${!var}'.", this breaks the alignments.
- drop 'rc' in patch #2 & #4
- use declare in #5
- drop
extra_srv_args+=" $extra_args"
extra_cl_args+=" $extra_args"
in #7

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

Thank you for the new version!

Did you check that after your modifications errors are still caught as before, and presented correctly? (the CI didn't get any error)

Yes, I checked the error logs, they are fine as before.

Thank you for having checked!

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.