All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Shuah Khan <shuah@kernel.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Jiri Slaby <jirislaby@kernel.org>
Cc: Michal Sekletar <msekleta@redhat.com>,
	linux-serial@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,  Mark Brown <broonie@kernel.org>
Subject: [PATCH 1/2] kselftest: Add mechanism for reporting a KSFT_ result code
Date: Wed, 06 Mar 2024 19:21:25 +0000	[thread overview]
Message-ID: <20240306-kselftest-tty-tname-v1-1-33505b31629e@kernel.org> (raw)
In-Reply-To: <20240306-kselftest-tty-tname-v1-0-33505b31629e@kernel.org>

Currently there's no helper which a test can use to report it's result as
a KSFT_ result code, we can report a boolean pass/fail but not a skip. This
is sometimes a useful idiom so let's add a helper ksft_test_result_report()
which translates into the relevant report types.

Due to the use of va_args in the result reporting functions this is done as
a macro rather than an inline function as one might expect, none of the
alternatives looked particularly great.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 tools/testing/selftests/kselftest.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index a781e6311810..9bc130c269d7 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -20,6 +20,7 @@
  * and finally report the pass/fail/skip/xfail state of the test with one of:
  *
  *     ksft_test_result(condition, fmt, ...);
+ *     ksft_test_result_report(result, fmt, ...);
  *     ksft_test_result_pass(fmt, ...);
  *     ksft_test_result_fail(fmt, ...);
  *     ksft_test_result_skip(fmt, ...);
@@ -254,6 +255,27 @@ static inline __printf(1, 2) void ksft_test_result_error(const char *msg, ...)
 	va_end(args);
 }
 
+/**
+ * ksft_test_result() - Report test success based on truth of condition
+ *
+ * @condition: if true, report test success, otherwise failure.
+ */
+#define ksft_test_result_report(result, fmt, ...) do {		\
+	switch (result) {					\
+	case KSFT_PASS:						\
+		ksft_test_result_pass(fmt, ##__VA_ARGS__);	\
+		break;						\
+	case KSFT_FAIL:						\
+		ksft_test_result_fail(fmt, ##__VA_ARGS__);	\
+		break;						\
+	case KSFT_XFAIL:					\
+		ksft_test_result_xfail(fmt, ##__VA_ARGS__);	\
+		break;						\
+	case KSFT_SKIP:						\
+		ksft_test_result_skip(fmt, ##__VA_ARGS__);	\
+		break;						\
+	} } while (0)
+
 static inline int ksft_exit_pass(void)
 {
 	ksft_print_cnts();

-- 
2.30.2


  reply	other threads:[~2024-03-06 19:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-06 19:21 [PATCH 0/2] kselftest/tty: Improve integration with automated systems Mark Brown
2024-03-06 19:21 ` Mark Brown [this message]
2024-03-06 19:21 ` [PATCH 2/2] kselftest/tty: Report a consistent test name for the one test we run Mark Brown
2024-03-06 22:51 ` [PATCH 0/2] kselftest/tty: Improve integration with automated systems Greg Kroah-Hartman
2024-03-26 19:49   ` Shuah Khan
2024-03-26 20:07     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240306-kselftest-tty-tname-v1-1-33505b31629e@kernel.org \
    --to=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=msekleta@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.