Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers
@ 2024-01-31 22:02 Nícolas F. R. A. Prado
  2024-01-31 22:02 ` [PATCH 1/4] selftests: ktap_helpers: Add helper to print diagnostic messages Nícolas F. R. A. Prado
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Nícolas F. R. A. Prado @ 2024-01-31 22:02 UTC (permalink / raw)
  To: Shuah Khan
  Cc: kernel, linux-kselftest, linux-kernel, Laura Nao,
	Nícolas F. R. A. Prado

This series adds a few missing functions to the shell KTAP helpers
script which are present in the C counterpart, kselftest.h.

This series depends on
"selftests: Move KTAP bash helpers to selftests common folder"
https://lore.kernel.org/all/20240102141528.169947-1-laura.nao@collabora.com/

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
Nícolas F. R. A. Prado (4):
      selftests: ktap_helpers: Add helper to print diagnostic messages
      selftests: ktap_helpers: Add helper to pass/fail test based on exit code
      selftests: ktap_helpers: Add a helper to abort the test
      selftests: ktap_helpers: Add a helper to finish the test

 tools/testing/selftests/kselftest/ktap_helpers.sh | 39 +++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
---
base-commit: f1ca07220ad16a9efae7f68e4bade0db89b63a3c
change-id: 20240131-ktap-sh-helpers-extend-805b77ca773c

Best regards,
-- 
Nícolas F. R. A. Prado <nfraprado@collabora.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] selftests: ktap_helpers: Add helper to print diagnostic messages
  2024-01-31 22:02 [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Nícolas F. R. A. Prado
@ 2024-01-31 22:02 ` Nícolas F. R. A. Prado
  2024-01-31 22:02 ` [PATCH 2/4] selftests: ktap_helpers: Add helper to pass/fail test based on exit code Nícolas F. R. A. Prado
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nícolas F. R. A. Prado @ 2024-01-31 22:02 UTC (permalink / raw)
  To: Shuah Khan
  Cc: kernel, linux-kselftest, linux-kernel, Laura Nao,
	Nícolas F. R. A. Prado

Similar to the C counterpart, add a helper to print a diagnostic
message.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
 tools/testing/selftests/kselftest/ktap_helpers.sh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/kselftest/ktap_helpers.sh b/tools/testing/selftests/kselftest/ktap_helpers.sh
index dd79d96f3b5a..ecc1413c22cd 100644
--- a/tools/testing/selftests/kselftest/ktap_helpers.sh
+++ b/tools/testing/selftests/kselftest/ktap_helpers.sh
@@ -19,6 +19,11 @@ ktap_print_header() {
 	echo "TAP version 13"
 }
 
+ktap_print_msg()
+{
+	echo "#" $@
+}
+
 ktap_set_plan() {
 	num_tests="$1"
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] selftests: ktap_helpers: Add helper to pass/fail test based on exit code
  2024-01-31 22:02 [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Nícolas F. R. A. Prado
  2024-01-31 22:02 ` [PATCH 1/4] selftests: ktap_helpers: Add helper to print diagnostic messages Nícolas F. R. A. Prado
@ 2024-01-31 22:02 ` Nícolas F. R. A. Prado
  2024-01-31 22:02 ` [PATCH 3/4] selftests: ktap_helpers: Add a helper to abort the test Nícolas F. R. A. Prado
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nícolas F. R. A. Prado @ 2024-01-31 22:02 UTC (permalink / raw)
  To: Shuah Khan
  Cc: kernel, linux-kselftest, linux-kernel, Laura Nao,
	Nícolas F. R. A. Prado

Similar to the C counterpart, add a helper function that runs a command
and passes or fails the test based on the result.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
 tools/testing/selftests/kselftest/ktap_helpers.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/testing/selftests/kselftest/ktap_helpers.sh b/tools/testing/selftests/kselftest/ktap_helpers.sh
index ecc1413c22cd..29107924f5c2 100644
--- a/tools/testing/selftests/kselftest/ktap_helpers.sh
+++ b/tools/testing/selftests/kselftest/ktap_helpers.sh
@@ -76,6 +76,17 @@ ktap_test_fail() {
 	KTAP_CNT_FAIL=$((KTAP_CNT_FAIL+1))
 }
 
+ktap_test_result() {
+	description="$1"
+	shift
+
+	if $@; then
+		ktap_test_pass "$description"
+	else
+		ktap_test_fail "$description"
+	fi
+}
+
 ktap_print_totals() {
 	echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:0 xpass:0 skip:$KTAP_CNT_SKIP error:0"
 }

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] selftests: ktap_helpers: Add a helper to abort the test
  2024-01-31 22:02 [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Nícolas F. R. A. Prado
  2024-01-31 22:02 ` [PATCH 1/4] selftests: ktap_helpers: Add helper to print diagnostic messages Nícolas F. R. A. Prado
  2024-01-31 22:02 ` [PATCH 2/4] selftests: ktap_helpers: Add helper to pass/fail test based on exit code Nícolas F. R. A. Prado
@ 2024-01-31 22:02 ` Nícolas F. R. A. Prado
  2024-01-31 22:02 ` [PATCH 4/4] selftests: ktap_helpers: Add a helper to finish " Nícolas F. R. A. Prado
  2024-02-20 22:59 ` [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Shuah Khan
  4 siblings, 0 replies; 6+ messages in thread
From: Nícolas F. R. A. Prado @ 2024-01-31 22:02 UTC (permalink / raw)
  To: Shuah Khan
  Cc: kernel, linux-kselftest, linux-kernel, Laura Nao,
	Nícolas F. R. A. Prado

Similar to the C counterpart, add a helper function to abort the
remainder of the test.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
 tools/testing/selftests/kselftest/ktap_helpers.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/kselftest/ktap_helpers.sh b/tools/testing/selftests/kselftest/ktap_helpers.sh
index 29107924f5c2..87f93c6900c5 100644
--- a/tools/testing/selftests/kselftest/ktap_helpers.sh
+++ b/tools/testing/selftests/kselftest/ktap_helpers.sh
@@ -87,6 +87,13 @@ ktap_test_result() {
 	fi
 }
 
+ktap_exit_fail_msg() {
+	echo "Bail out! " $@
+	ktap_print_totals
+
+	exit "$KSFT_FAIL"
+}
+
 ktap_print_totals() {
 	echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:0 xpass:0 skip:$KTAP_CNT_SKIP error:0"
 }

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] selftests: ktap_helpers: Add a helper to finish the test
  2024-01-31 22:02 [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Nícolas F. R. A. Prado
                   ` (2 preceding siblings ...)
  2024-01-31 22:02 ` [PATCH 3/4] selftests: ktap_helpers: Add a helper to abort the test Nícolas F. R. A. Prado
@ 2024-01-31 22:02 ` Nícolas F. R. A. Prado
  2024-02-20 22:59 ` [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Shuah Khan
  4 siblings, 0 replies; 6+ messages in thread
From: Nícolas F. R. A. Prado @ 2024-01-31 22:02 UTC (permalink / raw)
  To: Shuah Khan
  Cc: kernel, linux-kselftest, linux-kernel, Laura Nao,
	Nícolas F. R. A. Prado

Similar to the C counterpart, keep track of the number of test cases in
the test plan and add a helper function to be called at the end of the
test to print the results and exit with the corresponding exit code.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
 tools/testing/selftests/kselftest/ktap_helpers.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kselftest/ktap_helpers.sh b/tools/testing/selftests/kselftest/ktap_helpers.sh
index 87f93c6900c5..f2fbb914e058 100644
--- a/tools/testing/selftests/kselftest/ktap_helpers.sh
+++ b/tools/testing/selftests/kselftest/ktap_helpers.sh
@@ -15,6 +15,8 @@ KSFT_XFAIL=2
 KSFT_XPASS=3
 KSFT_SKIP=4
 
+KSFT_NUM_TESTS=0
+
 ktap_print_header() {
 	echo "TAP version 13"
 }
@@ -25,9 +27,9 @@ ktap_print_msg()
 }
 
 ktap_set_plan() {
-	num_tests="$1"
+	KSFT_NUM_TESTS="$1"
 
-	echo "1..$num_tests"
+	echo "1..$KSFT_NUM_TESTS"
 }
 
 ktap_skip_all() {
@@ -94,6 +96,16 @@ ktap_exit_fail_msg() {
 	exit "$KSFT_FAIL"
 }
 
+ktap_finished() {
+	ktap_print_totals
+
+	if [ $(("$KTAP_CNT_PASS" + "$KTAP_CNT_SKIP")) -eq "$KSFT_NUM_TESTS" ]; then
+		exit "$KSFT_PASS"
+	else
+		exit "$KSFT_FAIL"
+	fi
+}
+
 ktap_print_totals() {
 	echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:0 xpass:0 skip:$KTAP_CNT_SKIP error:0"
 }

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers
  2024-01-31 22:02 [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Nícolas F. R. A. Prado
                   ` (3 preceding siblings ...)
  2024-01-31 22:02 ` [PATCH 4/4] selftests: ktap_helpers: Add a helper to finish " Nícolas F. R. A. Prado
@ 2024-02-20 22:59 ` Shuah Khan
  4 siblings, 0 replies; 6+ messages in thread
From: Shuah Khan @ 2024-02-20 22:59 UTC (permalink / raw)
  To: Nícolas F. R. A. Prado, Shuah Khan
  Cc: kernel, linux-kselftest, linux-kernel, Laura Nao, Shuah Khan

On 1/31/24 15:02, Nícolas F. R. A. Prado wrote:
> This series adds a few missing functions to the shell KTAP helpers
> script which are present in the C counterpart, kselftest.h.
> 
> This series depends on
> "selftests: Move KTAP bash helpers to selftests common folder"
> https://lore.kernel.org/all/20240102141528.169947-1-laura.nao@collabora.com/
> 
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> ---
> Nícolas F. R. A. Prado (4):
>        selftests: ktap_helpers: Add helper to print diagnostic messages
>        selftests: ktap_helpers: Add helper to pass/fail test based on exit code
>        selftests: ktap_helpers: Add a helper to abort the test
>        selftests: ktap_helpers: Add a helper to finish the test
> 
>   tools/testing/selftests/kselftest/ktap_helpers.sh | 39 +++++++++++++++++++++--
>   1 file changed, 37 insertions(+), 2 deletions(-)
> ---
> base-commit: f1ca07220ad16a9efae7f68e4bade0db89b63a3c
> change-id: 20240131-ktap-sh-helpers-extend-805b77ca773c
> 
> Best regards,

Applied to next for Linux 6.9-rc1

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-02-20 22:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-31 22:02 [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Nícolas F. R. A. Prado
2024-01-31 22:02 ` [PATCH 1/4] selftests: ktap_helpers: Add helper to print diagnostic messages Nícolas F. R. A. Prado
2024-01-31 22:02 ` [PATCH 2/4] selftests: ktap_helpers: Add helper to pass/fail test based on exit code Nícolas F. R. A. Prado
2024-01-31 22:02 ` [PATCH 3/4] selftests: ktap_helpers: Add a helper to abort the test Nícolas F. R. A. Prado
2024-01-31 22:02 ` [PATCH 4/4] selftests: ktap_helpers: Add a helper to finish " Nícolas F. R. A. Prado
2024-02-20 22:59 ` [PATCH 0/4] selftests: ktap_helpers: Add some missing helpers Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox