diff mbox series

[v4,10/12] selftests: kselftest_harness: let PASS / FAIL provide diagnostic

Message ID 20240229005920.2407409-11-kuba@kernel.org (mailing list archive)
State Accepted
Commit 378193eff3399acb8529d0b553709e8f91d34fe3
Headers show
Series selftests: kselftest_harness: support using xfail | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: wad@chromium.org luto@amacapital.net
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-29--21-00 (tests: 885)

Commit Message

Jakub Kicinski Feb. 29, 2024, 12:59 a.m. UTC
Switch to printing KTAP line for PASS / FAIL with ksft_test_result_code(),
this gives us the ability to report diagnostic messages.

Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/kselftest_harness.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Muhammad Usama Anjum April 16, 2024, 2:11 p.m. UTC | #1
On 2/29/24 5:59 AM, Jakub Kicinski wrote:
> Switch to printing KTAP line for PASS / FAIL with ksft_test_result_code(),
> this gives us the ability to report diagnostic messages.
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  tools/testing/selftests/kselftest_harness.h | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index 5b0592e4b7a4..b643a577f9e1 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -1143,14 +1143,13 @@ 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;
>  	else
>  		diagnostic = "unknown";
>  
> -	if (t->exit_code == KSFT_SKIP)
> -		ksft_test_result_code(t->exit_code, test_name,
> -				      "%s", diagnostic);
> -	else
> -		ksft_test_result(__test_passed(t), "%s\n", test_name);
> +	ksft_test_result_code(t->exit_code, test_name,
> +			      diagnostic ? "%s" : "", diagnostic);
We are getting the following annoying warning while using clang:

./../kselftest_harness.h:1207:30: warning: format string is empty
[-Wformat-zero-length]
 1207 |            diagnostic ? "%s" : "", diagnostic);
      |                                 ^~
1 warning generated.

I've tried to look for solution. In my opinion, the best solution would be
to just revert this patch. Any thoughts?

>  }
>  
>  static int test_harness_run(int argc, char **argv)
diff mbox series

Patch

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 5b0592e4b7a4..b643a577f9e1 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -1143,14 +1143,13 @@  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;
 	else
 		diagnostic = "unknown";
 
-	if (t->exit_code == KSFT_SKIP)
-		ksft_test_result_code(t->exit_code, test_name,
-				      "%s", diagnostic);
-	else
-		ksft_test_result(__test_passed(t), "%s\n", test_name);
+	ksft_test_result_code(t->exit_code, test_name,
+			      diagnostic ? "%s" : "", diagnostic);
 }
 
 static int test_harness_run(int argc, char **argv)