Skip to content

Commit 3382bb0

Browse files
Geliang Tangkuba-moo
authored andcommitted
selftests: mptcp: add print_title in mptcp_lib
This patch adds a new variable MPTCP_LIB_TEST_FORMAT as the test title printing format. Also add a helper mptcp_lib_print_title() to use this format to print the test title with test counters. They are used in mptcp_join.sh first. Each MPTCP selftest is having subtests, and it helps to give them a number to quickly identify them. This can be managed by mptcp_lib.sh, reusing what has been done here. The following commit will use these new helpers in the other tests. Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://lore.kernel.org/r/20240308-upstream-net-next-20240308-selftests-mptcp-unification-v1-6-4f42c347b653@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 9e6a39e commit 3382bb0

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

tools/testing/selftests/net/mptcp/mptcp_join.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ declare -A all_tests
4848
declare -a only_tests_ids
4949
declare -a only_tests_names
5050
declare -A failed_tests
51+
MPTCP_LIB_TEST_FORMAT="%03u %s\n"
5152
TEST_NAME=""
5253
nr_blank=6
5354

@@ -169,11 +170,6 @@ cleanup()
169170
cleanup_partial
170171
}
171172

172-
print_title()
173-
{
174-
printf "%03u %s\n" "${MPTCP_LIB_TEST_COUNTER}" "${TEST_NAME}"
175-
}
176-
177173
print_check()
178174
{
179175
printf "%-${nr_blank}s%-36s" " " "${*}"
@@ -232,7 +228,7 @@ skip_test()
232228

233229
local i
234230
for i in "${only_tests_ids[@]}"; do
235-
if [ "${MPTCP_LIB_TEST_COUNTER}" -eq "${i}" ]; then
231+
if [ "$((MPTCP_LIB_TEST_COUNTER+1))" -eq "${i}" ]; then
236232
return 1
237233
fi
238234
done
@@ -267,14 +263,13 @@ reset()
267263

268264
TEST_NAME="${1}"
269265

270-
MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
271-
272266
if skip_test; then
267+
MPTCP_LIB_TEST_COUNTER=$((MPTCP_LIB_TEST_COUNTER+1))
273268
last_test_ignored=1
274269
return 1
275270
fi
276271

277-
print_title
272+
mptcp_lib_print_title "${TEST_NAME}"
278273

279274
if [ "${init}" != "1" ]; then
280275
init

tools/testing/selftests/net/mptcp/mptcp_lib.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ readonly KSFT_TEST="${MPTCP_LIB_KSFT_TEST:-$(basename "${0}" .sh)}"
1010

1111
MPTCP_LIB_SUBTESTS=()
1212
MPTCP_LIB_SUBTESTS_DUPLICATED=0
13-
# shellcheck disable=SC2034 # unused at this moment
1413
MPTCP_LIB_TEST_COUNTER=0
14+
MPTCP_LIB_TEST_FORMAT="%02u %-50s"
1515

1616
# only if supported (or forced) and not disabled, see no-color.org
1717
if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } &&
@@ -412,3 +412,11 @@ mptcp_lib_events() {
412412
ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 &
413413
pid=$!
414414
}
415+
416+
mptcp_lib_print_title() {
417+
: "${MPTCP_LIB_TEST_COUNTER:?}"
418+
: "${MPTCP_LIB_TEST_FORMAT:?}"
419+
420+
# shellcheck disable=SC2059 # the format is in a variable
421+
printf "${MPTCP_LIB_TEST_FORMAT}" "$((++MPTCP_LIB_TEST_COUNTER))" "${*}"
422+
}

0 commit comments

Comments
 (0)