Commit 9da74836 authored by Matthieu Baerts (NGI0)'s avatar Matthieu Baerts (NGI0) Committed by Jakub Kicinski

selftests: mptcp: lib: catch duplicated subtest entries

It is important to have a unique (sub)test name in TAP, because some CI
environments drop tests with duplicated name.

When adding a new subtest entry, an error message is printed in case of
duplicated entries. If there were duplicated entries and if all features
were expected to work, the script exits with an error at the end, after
having printed all subtests in the TAP format. Thanks to that, the MPTCP
CI will catch such issues early.
Reviewed-by: default avatarGeliang Tang <geliang@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240223-upstream-net-next-20240223-misc-improvements-v1-1-b6c8a10396bd@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c3718936
...@@ -9,6 +9,7 @@ readonly KSFT_SKIP=4 ...@@ -9,6 +9,7 @@ readonly KSFT_SKIP=4
readonly KSFT_TEST="${MPTCP_LIB_KSFT_TEST:-$(basename "${0}" .sh)}" readonly KSFT_TEST="${MPTCP_LIB_KSFT_TEST:-$(basename "${0}" .sh)}"
MPTCP_LIB_SUBTESTS=() MPTCP_LIB_SUBTESTS=()
MPTCP_LIB_SUBTESTS_DUPLICATED=0
# only if supported (or forced) and not disabled, see no-color.org # only if supported (or forced) and not disabled, see no-color.org
if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } && if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } &&
...@@ -146,12 +147,26 @@ mptcp_lib_kversion_ge() { ...@@ -146,12 +147,26 @@ mptcp_lib_kversion_ge() {
mptcp_lib_fail_if_expected_feature "kernel version ${1} lower than ${v}" mptcp_lib_fail_if_expected_feature "kernel version ${1} lower than ${v}"
} }
__mptcp_lib_result_check_duplicated() {
local subtest
for subtest in "${MPTCP_LIB_SUBTESTS[@]}"; do
if [[ "${subtest}" == *" - ${KSFT_TEST}: ${*%% #*}" ]]; then
MPTCP_LIB_SUBTESTS_DUPLICATED=1
mptcp_lib_print_err "Duplicated entry: ${*}"
break
fi
done
}
__mptcp_lib_result_add() { __mptcp_lib_result_add() {
local result="${1}" local result="${1}"
shift shift
local id=$((${#MPTCP_LIB_SUBTESTS[@]} + 1)) local id=$((${#MPTCP_LIB_SUBTESTS[@]} + 1))
__mptcp_lib_result_check_duplicated "${*}"
MPTCP_LIB_SUBTESTS+=("${result} ${id} - ${KSFT_TEST}: ${*}") MPTCP_LIB_SUBTESTS+=("${result} ${id} - ${KSFT_TEST}: ${*}")
} }
...@@ -206,6 +221,12 @@ mptcp_lib_result_print_all_tap() { ...@@ -206,6 +221,12 @@ mptcp_lib_result_print_all_tap() {
for subtest in "${MPTCP_LIB_SUBTESTS[@]}"; do for subtest in "${MPTCP_LIB_SUBTESTS[@]}"; do
printf "%s\n" "${subtest}" printf "%s\n" "${subtest}"
done done
if [ "${MPTCP_LIB_SUBTESTS_DUPLICATED}" = 1 ] &&
mptcp_lib_expect_all_features; then
mptcp_lib_print_err "Duplicated test entries"
exit ${KSFT_FAIL}
fi
} }
# get the value of keyword $1 in the line marked by keyword $2 # get the value of keyword $1 in the line marked by keyword $2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment