All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	shuah@kernel.org, linux-kselftest@vger.kernel.org,
	mic@digikod.net, linux-security-module@vger.kernel.org,
	keescook@chromium.org, jakub@cloudflare.com,
	Jakub Kicinski <kuba@kernel.org>,
	luto@amacapital.net, wad@chromium.org
Subject: [PATCH net-next v3 01/11] selftests: kselftest_harness: pass step via shared memory
Date: Tue, 20 Feb 2024 11:22:25 -0800	[thread overview]
Message-ID: <20240220192235.2953484-2-kuba@kernel.org> (raw)
In-Reply-To: <20240220192235.2953484-1-kuba@kernel.org>

Commit 0ef67a888375 ("selftests/harness: Report skip reason")
added shared memory to communicate between harness and test.
Use that instead of exit codes to send the failing step back
to the harness. The exit codes are limited and because of
the step passing we can't use the full range of KSFT_* exit
codes.

Acked-by: Kees Cook <keescook@chromium.org>
Tested-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: mic@digikod.net
CC: luto@amacapital.net
CC: wad@chromium.org
CC: shuah@kernel.org
CC: linux-kselftest@vger.kernel.org
CC: linux-security-module@vger.kernel.org
---
 tools/testing/selftests/kselftest_harness.h | 21 ++++++++++-----------
 tools/testing/selftests/landlock/common.h   |  5 ++---
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index e05ac8261046..98bdedf9a53a 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -101,8 +101,8 @@
  * ASSERT_* number for which the test failed.  This behavior can be enabled by
  * writing `_metadata->no_print = true;` before the check sequence that is
  * unable to print.  When an error occur, instead of printing an error message
- * and calling `abort(3)`, the test process call `_exit(2)` with the assert
- * number as argument, which is then printed by the parent process.
+ * and calling `abort(3)`, the test process call `_exit(2)` and pass the error
+ * to be printed to the parent process via shared memory.
  */
 #define TH_LOG(fmt, ...) do { \
 	if (TH_LOG_ENABLED) \
@@ -695,9 +695,8 @@
 			__bail(_assert, _metadata))
 
 #define __INC_STEP(_metadata) \
-	/* Keep "step" below 255 (which is used for "SKIP" reporting). */	\
-	if (_metadata->passed && _metadata->step < 253) \
-		_metadata->step++;
+	if (_metadata->passed) \
+		_metadata->results->step++;
 
 #define is_signed_type(var)       (!!(((__typeof__(var))(-1)) < (__typeof__(var))1))
 
@@ -784,6 +783,7 @@
 
 struct __test_results {
 	char reason[1024];	/* Reason for test result */
+	unsigned int step;	/* Test step reached without failure */
 };
 
 struct __test_metadata;
@@ -837,7 +837,6 @@ struct __test_metadata {
 	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? */
-	__u8 step;
 	bool no_print; /* manual trigger when TH_LOG_STREAM is not available */
 	bool aborted;	/* stopped test due to failed ASSERT */
 	bool setup_completed; /* did setup finish? */
@@ -875,7 +874,7 @@ static inline void __test_check_assert(struct __test_metadata *t)
 {
 	if (t->aborted) {
 		if (t->no_print)
-			_exit(t->step);
+			_exit(1);
 		abort();
 	}
 }
@@ -960,7 +959,7 @@ void __wait_for_test(struct __test_metadata *t)
 				fprintf(TH_LOG_STREAM,
 					"# %s: Test failed at step #%d\n",
 					t->name,
-					WEXITSTATUS(status));
+					t->results->step);
 			}
 		}
 	} else if (WIFSIGNALED(status)) {
@@ -1114,9 +1113,9 @@ void __run_test(struct __fixture_metadata *f,
 	t->passed = 1;
 	t->skip = 0;
 	t->trigger = 0;
-	t->step = 1;
 	t->no_print = 0;
 	memset(t->results->reason, 0, sizeof(t->results->reason));
+	t->results->step = 1;
 
 	ksft_print_msg(" RUN           %s%s%s.%s ...\n",
 	       f->name, variant->name[0] ? "." : "", variant->name, t->name);
@@ -1137,8 +1136,8 @@ void __run_test(struct __fixture_metadata *f,
 		/* Pass is exit 0 */
 		if (t->passed)
 			_exit(0);
-		/* Something else happened, report the step. */
-		_exit(t->step);
+		/* Something else happened. */
+		_exit(1);
 	} else {
 		__wait_for_test(t);
 	}
diff --git a/tools/testing/selftests/landlock/common.h b/tools/testing/selftests/landlock/common.h
index e64bbdf0e86e..c15e22abdca6 100644
--- a/tools/testing/selftests/landlock/common.h
+++ b/tools/testing/selftests/landlock/common.h
@@ -50,13 +50,13 @@
 				_exit(255); \
 			if (_metadata->passed) \
 				_exit(0); \
-			_exit(_metadata->step); \
+			_exit(1); \
 		} \
 		if (child != waitpid(child, &status, 0)) \
 			abort(); \
 		if (WIFSIGNALED(status) || !WIFEXITED(status)) { \
 			_metadata->passed = 0; \
-			_metadata->step = 1; \
+			_metadata->results->step = 1; \
 			return; \
 		} \
 		switch (WEXITSTATUS(status)) { \
@@ -69,7 +69,6 @@
 			break; \
 		default: \
 			_metadata->passed = 0; \
-			_metadata->step = WEXITSTATUS(status); \
 			break; \
 		} \
 	} \
-- 
2.43.0


  reply	other threads:[~2024-02-20 19:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 19:22 [PATCH net-next v3 00/11] selftests: kselftest_harness: support using xfail Jakub Kicinski
2024-02-20 19:22 ` Jakub Kicinski [this message]
2024-02-20 19:22 ` [PATCH net-next v3 02/11] selftests: kselftest_harness: use KSFT_* exit codes Jakub Kicinski
2024-02-20 19:22 ` [PATCH net-next v3 03/11] selftests: kselftest_harness: generate test name once Jakub Kicinski
2024-02-20 19:22 ` [PATCH net-next v3 04/11] selftests: kselftest_harness: save full exit code in metadata Jakub Kicinski
2024-02-20 19:22 ` [PATCH net-next v3 05/11] selftests: kselftest_harness: use exit code to store skip Jakub Kicinski
2024-02-21  0:49   ` Kees Cook
2024-02-20 19:22 ` [PATCH net-next v3 06/11] selftests: kselftest: add ksft_test_result_code(), handling all exit codes Jakub Kicinski
2024-02-21  0:49   ` Kees Cook
2024-02-20 19:22 ` [PATCH net-next v3 07/11] selftests: kselftest_harness: print test name for SKIP Jakub Kicinski
2024-02-21  0:50   ` Kees Cook
2024-02-20 19:22 ` [PATCH net-next v3 08/11] selftests: kselftest_harness: separate diagnostic message with # in ksft_test_result_code() Jakub Kicinski
2024-02-21  0:50   ` Kees Cook
2024-02-20 19:22 ` [PATCH net-next v3 09/11] selftests: kselftest_harness: let PASS / FAIL provide diagnostic Jakub Kicinski
2024-02-21  0:52   ` Kees Cook
2024-02-20 19:22 ` [PATCH net-next v3 10/11] selftests: kselftest_harness: support using xfail Jakub Kicinski
2024-02-21  0:52   ` Kees Cook
2024-02-20 19:22 ` [PATCH net-next v3 11/11] selftests: ip_local_port_range: use XFAIL instead of SKIP Jakub Kicinski
2024-02-21 12:03 ` [PATCH net-next v3 00/11] selftests: kselftest_harness: support using xfail Paolo Abeni
2024-02-23 17:48   ` Kees Cook
2024-02-24  0:02 ` Jakub Kicinski
2024-02-26 16:23   ` [PATCH 0/2] Merge TEST_F_FORK() into TEST_F() Mickaël Salaün
2024-02-26 16:23     ` [PATCH 1/2] selftests/landlock: Redefine TEST_F() as TEST_F_FORK() Mickaël Salaün
2024-02-26 16:23     ` [PATCH 2/2] selftests/harness: Merge TEST_F_FORK() into TEST_F() Mickaël Salaün
2024-02-26 19:04       ` Kees Cook
2024-02-26 20:21         ` Mickaël Salaün
2024-02-26 16:27   ` [PATCH net-next v3 00/11] selftests: kselftest_harness: support using xfail Mickaël Salaün
2024-02-26 16:53     ` Jakub Kicinski

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=20240220192235.2953484-2-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jakub@cloudflare.com \
    --cc=keescook@chromium.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mic@digikod.net \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=wad@chromium.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.