[PATCH mptcp-next v3 07/13] selftests: mptcp: add mptcp_lib_print_test_counter

Geliang Tang posted 13 patches 9 months, 1 week ago
There is a newer version of this series
[PATCH mptcp-next v3 07/13] selftests: mptcp: add mptcp_lib_print_test_counter
Posted by Geliang Tang 9 months, 1 week ago
From: Geliang Tang <tanggeliang@kylinos.cn>

This patch adds a new helper mptcp_lib_print_test_counter() to print out
test counter in each test result and increase the counter. The counter
digits of most tests are 2, only mptcp_join.sh is 3.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 6 ++----
 tools/testing/selftests/net/mptcp/mptcp_lib.sh  | 9 +++++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 8e8977031fa0..abd5fb4704d1 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -48,7 +48,7 @@ declare -A all_tests
 declare -a only_tests_ids
 declare -a only_tests_names
 declare -A failed_tests
-TEST_COUNT=0
+TEST_COUNT=1
 TEST_NAME=""
 nr_blank=6
 
@@ -172,7 +172,7 @@ cleanup()
 
 print_title()
 {
-	printf "%03u %s\n" "${TEST_COUNT}" "${TEST_NAME}"
+	mptcp_lib_print_test_counter TEST_COUNT "%s\n" "${TEST_NAME}" 3
 }
 
 print_check()
@@ -268,8 +268,6 @@ reset()
 
 	TEST_NAME="${1}"
 
-	TEST_COUNT=$((TEST_COUNT+1))
-
 	if skip_test; then
 		last_test_ignored=1
 		return 1
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index 7e309493eda2..630fecb942e4 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -411,3 +411,12 @@ mptcp_lib_events() {
 	ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 &
 	pid=$!
 }
+
+mptcp_lib_print_test_counter() {
+	declare -n counter="${1}"
+	local fmt="${2}"
+	local msg="${3}"
+	local digit="${4-2}"
+
+	printf "%0${digit}u ${fmt}" "$((counter++))" "${msg}"
+}
-- 
2.40.1