This patch adds a new helper get_info_value(), using 'sed' command to
parse the value of the given item name in the line with the given keyword,
to make chk_mptcp_info() and pedit_action_pkts() more readable.
Also add another helper evts_get_info() to use get_info_value() to parse
the output of 'pm_nl_ctl events' command, to make the userpsace pm
selftests more readable.
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
.../testing/selftests/net/mptcp/mptcp_join.sh | 31 ++++++++++++-------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index ee1f89a872b3..8540a1ba5ef2 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -1850,6 +1850,12 @@ chk_subflow_nr()
fi
}
+# $1: get value of this info $2: keyword in this line
+get_info_value()
+{
+ grep "${2}" | sed -n 's/.*\('${1}':\)\([0-9a-f:.]*\).*$/\2/p;q'
+}
+
chk_mptcp_info()
{
local info1=$1
@@ -1862,10 +1868,8 @@ chk_mptcp_info()
print_check "mptcp_info ${info1:0:8}=$exp1:$exp2"
- cnt1=$(ss -N $ns1 -inmHM | grep "$info1:" |
- sed -n 's/.*\('"$info1"':\)\([[:digit:]]*\).*$/\2/p;q')
- cnt2=$(ss -N $ns2 -inmHM | grep "$info2:" |
- sed -n 's/.*\('"$info2"':\)\([[:digit:]]*\).*$/\2/p;q')
+ cnt1=$(ss -N $ns1 -inmHM | get_info_value "$info1" "$info1")
+ cnt2=$(ss -N $ns2 -inmHM | get_info_value "$info2" "$info2")
# 'ss' only display active connections and counters that are not 0.
[ -z "$cnt1" ] && cnt1=0
[ -z "$cnt2" ] && cnt2=0
@@ -2794,6 +2798,12 @@ backup_tests()
fi
}
+# $1: info name ; $2: evts_ns ; $3: event type
+evts_get_info()
+{
+ cat "${2}" | get_info_value "${1}" "^type:${3:-1},"
+}
+
LISTENER_CREATED=15 #MPTCP_EVENT_LISTENER_CREATED
LISTENER_CLOSED=16 #MPTCP_EVENT_LISTENER_CLOSED
@@ -2828,13 +2838,13 @@ verify_listener_events()
return
fi
- type=$(grep "type:$e_type," $evt | sed -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q')
- family=$(grep "type:$e_type," $evt | sed -n 's/.*\(family:\)\([[:digit:]]*\).*$/\2/p;q')
- sport=$(grep "type:$e_type," $evt | sed -n 's/.*\(sport:\)\([[:digit:]]*\).*$/\2/p;q')
+ type=$(evts_get_info type "$evt" "$e_type")
+ family=$(evts_get_info family "$evt" "$e_type")
+ sport=$(evts_get_info sport "$evt" "$e_type")
if [ $family ] && [ $family = $AF_INET6 ]; then
- saddr=$(grep "type:$e_type," $evt | sed -n 's/.*\(saddr6:\)\([0-9a-f:.]*\).*$/\2/p;q')
+ saddr=$(evts_get_info saddr6 "$evt" "$e_type")
else
- saddr=$(grep "type:$e_type," $evt | sed -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
+ saddr=$(evts_get_info saddr4 "$evt" "$e_type")
fi
if [ $type ] && [ $type = $e_type ] &&
@@ -3229,8 +3239,7 @@ fastclose_tests()
pedit_action_pkts()
{
tc -n $ns2 -j -s action show action pedit index 100 | \
- grep "packets" | \
- sed 's/.*"packets":\([0-9]\+\),.*/\1/'
+ get_info_value \"packets\" packets
}
fail_tests()
--
2.35.3