netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: jakub@cloudflare.com
Cc: shuah@kernel.org, keescook@chromium.org,
	linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
	Jakub Kicinski <kuba@kernel.org>
Subject: [RFC 3/7] selftests: kselftest_harness: use exit code to store skip and xfail
Date: Thu, 15 Feb 2024 16:41:18 -0800	[thread overview]
Message-ID: <20240216004122.2004689-4-kuba@kernel.org> (raw)
In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org>

We always use skip / xfail with combination of exit_code being 0
(KSFT_PASS). This are just basic KSFT / KTAP semantics.
Store the right KSFT_* code in exit_code directly.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/kselftest_harness.h | 35 ++++++---------------
 1 file changed, 9 insertions(+), 26 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 70366864ffd9..6923cd7060fc 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -136,8 +136,7 @@
 		fprintf(TH_LOG_STREAM, "#      SKIP      %s\n", \
 			_metadata->results->reason); \
 	} \
-	_metadata->exit_code = KSFT_PASS; \
-	_metadata->skip = 1; \
+	_metadata->exit_code = KSFT_SKIP; \
 	_metadata->trigger = 0; \
 	statement; \
 } while (0)
@@ -163,8 +162,7 @@
 		fprintf(TH_LOG_STREAM, "#      XFAIL     %s\n", \
 			_metadata->results->reason); \
 	} \
-	_metadata->exit_code = KSFT_PASS; \
-	_metadata->xfail = 1; \
+	_metadata->exit_code = KSFT_XFAIL; \
 	_metadata->trigger = 0; \
 	statement; \
 } while (0)
@@ -416,7 +414,7 @@
 		if (setjmp(_metadata->env) == 0) { \
 			fixture_name##_setup(_metadata, &self, variant->data); \
 			/* Let setup failure terminate early. */ \
-			if (!__test_passed(_metadata) || _metadata->skip) \
+			if (_metadata->exit_code) \
 				return; \
 			_metadata->setup_completed = true; \
 			fixture_name##_##test_name(_metadata, &self, variant->data); \
@@ -861,8 +859,6 @@ struct __test_metadata {
 	struct __fixture_metadata *fixture;
 	int termsig;
 	int exit_code;
-	int skip;	/* did SKIP get used? */
-	int xfail;	/* did XFAIL get used? */
 	int trigger; /* extra handler after the evaluation */
 	int timeout;	/* seconds to wait for test timeout */
 	bool timed_out;	/* did this test timeout instead of exiting? */
@@ -972,13 +968,9 @@ void __wait_for_test(struct __test_metadata *t)
 		fprintf(TH_LOG_STREAM,
 			"# %s: Test terminated by timeout\n", t->name);
 	} else if (WIFEXITED(status)) {
-		if (WEXITSTATUS(status) == KSFT_SKIP) {
-			/* SKIP */
-			t->exit_code = KSFT_PASS;
-			t->skip = 1;
-		} else if (WEXITSTATUS(status) == KSFT_XFAIL) {
-			t->exit_code = KSFT_PASS;
-			t->xfail = 1;
+		if (WEXITSTATUS(status) == KSFT_SKIP ||
+		    WEXITSTATUS(status) == KSFT_XFAIL) {
+			t->exit_code = WEXITSTATUS(status);
 		} else if (t->termsig != -1) {
 			t->exit_code = KSFT_FAIL;
 			fprintf(TH_LOG_STREAM,
@@ -1151,8 +1143,6 @@ void __run_test(struct __fixture_metadata *f,
 
 	/* reset test struct */
 	t->exit_code = KSFT_PASS;
-	t->skip = 0;
-	t->xfail = 0;
 	t->trigger = 0;
 	t->no_print = 0;
 	memset(t->results->reason, 0, sizeof(t->results->reason));
@@ -1174,24 +1164,17 @@ void __run_test(struct __fixture_metadata *f,
 	} else if (t->pid == 0) {
 		setpgrp();
 		t->fn(t, variant);
-		if (t->skip)
-			_exit(KSFT_SKIP);
-		if (t->xfail)
-			_exit(KSFT_XFAIL);
-		if (__test_passed(t))
-			_exit(KSFT_PASS);
-		/* Something else happened. */
-		_exit(KSFT_FAIL);
+		_exit(t->exit_code);
 	} else {
 		__wait_for_test(t);
 	}
 	ksft_print_msg("         %4s  %s\n",
 		       __test_passed(t) ? "OK" : "FAIL", test_name);
 
-	if (t->skip)
+	if (t->exit_code == KSFT_SKIP)
 		ksft_test_result_skip("%s\n", t->results->reason[0] ?
 					t->results->reason : "unknown");
-	else if (t->xfail)
+	else if (t->exit_code == KSFT_XFAIL)
 		ksft_test_result_xfail("%s\n", t->results->reason[0] ?
 				       t->results->reason : "unknown");
 	else
-- 
2.43.0


  parent reply	other threads:[~2024-02-16  0:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16  0:41 [RFC 0/7] selftests: kselftest_harness: use common result printing helper Jakub Kicinski
2024-02-16  0:41 ` [RFC 1/7] selftests: kselftest_harness: generate test name once Jakub Kicinski
2024-02-16 21:24   ` Kees Cook
2024-02-16  0:41 ` [RFC 2/7] selftests: kselftest_harness: save full exit code in metadata Jakub Kicinski
2024-02-16  0:41 ` Jakub Kicinski [this message]
2024-02-16  0:41 ` [RFC 4/7] selftests: kselftest: add ksft_test_result_code(), handling all exit codes Jakub Kicinski
2024-02-16  0:41 ` [RFC 5/7] selftests: kselftest_harness: print test name for SKIP and XFAIL Jakub Kicinski
2024-02-16  0:41 ` [RFC 6/7] selftests: kselftest_harness: let ksft_test_result_code() handle line termination Jakub Kicinski
2024-02-16  0:41 ` [RFC 7/7] selftests: kselftest_harness: let PASS / FAIL provide diagnostic Jakub Kicinski
2024-02-16 21:32 ` [RFC 0/7] selftests: kselftest_harness: use common result printing helper Kees Cook
2024-02-17  0:31   ` Jakub Kicinski
2024-02-17  0:33     ` Jakub Kicinski
2024-02-17  1:26       ` Jakub Kicinski
2024-02-17  1:48         ` Kees Cook

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=20240216004122.2004689-4-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=jakub@cloudflare.com \
    --cc=keescook@chromium.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).