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 1/7] selftests: kselftest_harness: generate test name once
Date: Thu, 15 Feb 2024 16:41:16 -0800	[thread overview]
Message-ID: <20240216004122.2004689-2-kuba@kernel.org> (raw)
In-Reply-To: <20240216004122.2004689-1-kuba@kernel.org>

Since we added variant support generating full test case
name takes 4 string arguments. We're about to need it
in another two places. Stop the duplication and print
once into a temporary buffer.

Suggested-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/kselftest_harness.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 04177813930b..b271cb721b81 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -56,6 +56,7 @@
 #include <asm/types.h>
 #include <ctype.h>
 #include <errno.h>
+#include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -1140,6 +1141,8 @@ void __run_test(struct __fixture_metadata *f,
 		struct __fixture_variant_metadata *variant,
 		struct __test_metadata *t)
 {
+	char test_name[LINE_MAX];
+
 	/* reset test struct */
 	t->passed = 1;
 	t->skip = 0;
@@ -1149,8 +1152,10 @@ void __run_test(struct __fixture_metadata *f,
 	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);
+	snprintf(test_name, sizeof(test_name), "%s%s%s.%s",
+		 f->name, variant->name[0] ? "." : "", variant->name, t->name);
+
+	ksft_print_msg(" RUN           %s ...\n", test_name);
 
 	/* Make sure output buffers are flushed before fork */
 	fflush(stdout);
@@ -1174,8 +1179,8 @@ void __run_test(struct __fixture_metadata *f,
 	} else {
 		__wait_for_test(t);
 	}
-	ksft_print_msg("         %4s  %s%s%s.%s\n", t->passed ? "OK" : "FAIL",
-	       f->name, variant->name[0] ? "." : "", variant->name, t->name);
+	ksft_print_msg("         %4s  %s\n",
+		       t->passed ? "OK" : "FAIL", test_name);
 
 	if (t->skip)
 		ksft_test_result_skip("%s\n", t->results->reason[0] ?
@@ -1184,8 +1189,7 @@ void __run_test(struct __fixture_metadata *f,
 		ksft_test_result_xfail("%s\n", t->results->reason[0] ?
 				       t->results->reason : "unknown");
 	else
-		ksft_test_result(t->passed, "%s%s%s.%s\n",
-			f->name, variant->name[0] ? "." : "", variant->name, t->name);
+		ksft_test_result(t->passed, "%s\n", test_name);
 }
 
 static int test_harness_run(int argc, char **argv)
-- 
2.43.0


  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 ` Jakub Kicinski [this message]
2024-02-16 21:24   ` [RFC 1/7] selftests: kselftest_harness: generate test name once 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 ` [RFC 3/7] selftests: kselftest_harness: use exit code to store skip and xfail Jakub Kicinski
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-2-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).