* [PATCH] selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL
@ 2024-04-09 22:42 Sean Christopherson
2024-04-09 23:09 ` Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2024-04-09 22:42 UTC (permalink / raw)
To: Kees Cook, Shuah Khan, Nathan Chancellor
Cc: linux-kselftest, llvm, linux-kernel, Jakub Kicinski,
Sean Christopherson
When printing nothing for the diagnostic on PASS/FAIL, use a string format
with an empty string, not an empty format with a NULL parameter. Clang
complains about the empty format string, which in turn breaks building
with -Werror.
../kselftest_harness.h:1205:30: error: format string is empty [-Werror,-Wformat-zero-length]
diagnostic ? "%s" : "", diagnostic);
^~
Fixes: 378193eff339 ("selftests: kselftest_harness: let PASS / FAIL provide diagnostic")
Cc: Kees Cook <keescook@chromium.org>
Cc: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
tools/testing/selftests/kselftest_harness.h | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 4fd735e48ee7..79ac9e9ada33 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -1197,12 +1197,11 @@ void __run_test(struct __fixture_metadata *f,
if (t->results->reason[0])
diagnostic = t->results->reason;
else if (t->exit_code == KSFT_PASS || t->exit_code == KSFT_FAIL)
- diagnostic = NULL;
+ diagnostic = "";
else
diagnostic = "unknown";
- ksft_test_result_code(t->exit_code, test_name,
- diagnostic ? "%s" : "", diagnostic);
+ ksft_test_result_code(t->exit_code, test_name, "%s", diagnostic);
}
static int test_harness_run(int argc, char **argv)
base-commit: 2c71fdf02a95b3dd425b42f28fd47fb2b1d22702
--
2.44.0.478.gd926399ef9-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL
2024-04-09 22:42 [PATCH] selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL Sean Christopherson
@ 2024-04-09 23:09 ` Jakub Kicinski
2024-04-09 23:46 ` Kees Cook
2024-04-10 0:14 ` Sean Christopherson
0 siblings, 2 replies; 5+ messages in thread
From: Jakub Kicinski @ 2024-04-09 23:09 UTC (permalink / raw)
To: Sean Christopherson
Cc: Kees Cook, Shuah Khan, Nathan Chancellor, linux-kselftest, llvm,
linux-kernel
On Tue, 9 Apr 2024 15:42:56 -0700 Sean Christopherson wrote:
> - ksft_test_result_code(t->exit_code, test_name,
> - diagnostic ? "%s" : "", diagnostic);
> + ksft_test_result_code(t->exit_code, test_name, "%s", diagnostic);
Have you tested that to make sure it doesn't change the output?
.. warning: ^^ leading question ;)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL
2024-04-09 23:09 ` Jakub Kicinski
@ 2024-04-09 23:46 ` Kees Cook
2024-04-09 23:53 ` Jakub Kicinski
2024-04-10 0:14 ` Sean Christopherson
1 sibling, 1 reply; 5+ messages in thread
From: Kees Cook @ 2024-04-09 23:46 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Sean Christopherson, Shuah Khan, Nathan Chancellor,
linux-kselftest, llvm, linux-kernel
On Tue, Apr 09, 2024 at 04:09:20PM -0700, Jakub Kicinski wrote:
> On Tue, 9 Apr 2024 15:42:56 -0700 Sean Christopherson wrote:
> > - ksft_test_result_code(t->exit_code, test_name,
> > - diagnostic ? "%s" : "", diagnostic);
> > + ksft_test_result_code(t->exit_code, test_name, "%s", diagnostic);
>
> Have you tested that to make sure it doesn't change the output?
>
> .. warning: ^^ leading question ;)
Probably should be just this, without changing the NULL init?
ksft_test_result_code(t->exit_code, test_name, "%s",
diagnostic ?: "");
--
Kees Cook
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL
2024-04-09 23:46 ` Kees Cook
@ 2024-04-09 23:53 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2024-04-09 23:53 UTC (permalink / raw)
To: Kees Cook
Cc: Sean Christopherson, Shuah Khan, Nathan Chancellor,
linux-kselftest, llvm, linux-kernel
On Tue, 9 Apr 2024 16:46:40 -0700 Kees Cook wrote:
> ksft_test_result_code(t->exit_code, test_name, "%s",
> diagnostic ?: "");
Could work, but we need to change the callee to extract the first arg
after format from va_arg, which I wasn't sufficiently familiar with :(
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL
2024-04-09 23:09 ` Jakub Kicinski
2024-04-09 23:46 ` Kees Cook
@ 2024-04-10 0:14 ` Sean Christopherson
1 sibling, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2024-04-10 0:14 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Kees Cook, Shuah Khan, Nathan Chancellor, linux-kselftest, llvm,
linux-kernel
On Tue, Apr 09, 2024, Jakub Kicinski wrote:
> On Tue, 9 Apr 2024 15:42:56 -0700 Sean Christopherson wrote:
> > - ksft_test_result_code(t->exit_code, test_name,
> > - diagnostic ? "%s" : "", diagnostic);
> > + ksft_test_result_code(t->exit_code, test_name, "%s", diagnostic);
>
> Have you tested that to make sure it doesn't change the output?
>
> .. warning: ^^ leading question ;)
Heh, I was *this* close to adding a blurb saying this was probably only compile
tested.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-10 0:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09 22:42 [PATCH] selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL Sean Christopherson
2024-04-09 23:09 ` Jakub Kicinski
2024-04-09 23:46 ` Kees Cook
2024-04-09 23:53 ` Jakub Kicinski
2024-04-10 0:14 ` Sean Christopherson
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).