Skip to contentSkip to conversation

selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL

PATCH In review Sean Christopherson 3 participants 5 messages Apr 9, 2024 – Apr 10, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: kselftest_harness: Print empty string, not empty fmt on PASS/FAIL

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 <[email protected]>
Cc Jakub Kicinski <[email protected]>
---
 tools/testing/selftests/kselftest_harness.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/testing/selftests/kselftest_harness.h +2 -3
index 4fd735e48ee7..79ac9e9ada33 100644
@@ -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

Signature · 1 line
2.44.0.478.gd926399ef9-goog
#1 lore raw

tools/testing/selftests/kselftest_harness.h void __run_test(struct __fixture_metadata *f, · line 1204

Quoted 3 lines · On Tue, 9 Apr 2024 15:42:56 -0700 Sean Christopherson wrote:
tools/testing/selftests/kselftest_harness.h +1 -2
-	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 ;)

#2 lore raw
Quoted 8 lines · Jakub Kicinski

tools/testing/selftests/kselftest_harness.h void __run_test(struct __fixture_metadata *f, · line 1204

Quoted 3 lines · On Tue, 9 Apr 2024 15:42:56 -0700 Sean Christopherson wrote:
tools/testing/selftests/kselftest_harness.h +1 -2
-	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 ?: "");
Signature · 1 line
Kees Cook
#3 lore raw
Quoted 2 lines · 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 :(

#4 lore raw
In reply to Jakub Kicinski
Quoted 8 lines · Jakub Kicinski

tools/testing/selftests/kselftest_harness.h void __run_test(struct __fixture_metadata *f, · line 1204

Quoted 3 lines · On Tue, 9 Apr 2024 15:42:56 -0700 Sean Christopherson wrote:
tools/testing/selftests/kselftest_harness.h +1 -2
-	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.