diff mbox series

[4/6] selftests/pidfd: Fix ksft print formats

Message ID ac9c6c136a9e249453f866f56eab175c27f48061.1693216959.git.maciej.wieczor-retman@intel.com (mailing list archive)
State Accepted
Commit 4d7f4e8158b62f63031510cdc24acc520956c091
Headers show
Series Add printf attribute to kselftest functions | expand

Commit Message

Maciej Wieczor-Retman Aug. 28, 2023, 10:49 a.m. UTC
Many calls to ksft print functions have format strings that don't match
with other passed arguments. One call expects a string but doesn't
provide any argument after the format string.

Fix format specifiers so they match the passed variables.

Add a missing variable to ksft_test_result_pass() inside
pidfd_fdinfo_test() so it matches other cases in the switch statement.

Signed-off-by: Wieczor-Retman, Maciej <maciej.wieczor-retman@intel.com>
---
 tools/testing/selftests/pidfd/pidfd_fdinfo_test.c |  2 +-
 tools/testing/selftests/pidfd/pidfd_test.c        | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

Comments

Ilpo Järvinen Aug. 28, 2023, 11:01 a.m. UTC | #1
On Mon, 28 Aug 2023, Wieczor-Retman, Maciej wrote:

> Many calls to ksft print functions have format strings that don't match
> with other passed arguments. One call expects a string but doesn't
> provide any argument after the format string.
> 
> Fix format specifiers so they match the passed variables.
> 
> Add a missing variable to ksft_test_result_pass() inside
> pidfd_fdinfo_test() so it matches other cases in the switch statement.
> 
> Signed-off-by: Wieczor-Retman, Maciej <maciej.wieczor-retman@intel.com>
> ---
>  tools/testing/selftests/pidfd/pidfd_fdinfo_test.c |  2 +-
>  tools/testing/selftests/pidfd/pidfd_test.c        | 12 ++++++------
>  2 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c b/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
> index 4e86f927880c..01cc37bf611c 100644
> --- a/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
> +++ b/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
> @@ -62,7 +62,7 @@ static void error_report(struct error *err, const char *test_name)
>  		break;
>  
>  	case PIDFD_PASS:
> -		ksft_test_result_pass("%s test: Passed\n");
> +		ksft_test_result_pass("%s test: Passed\n", test_name);

Missing test_name leads to crash so this looks a Fixes: class thing for
me but you didn't provide one.

>  		break;
>  
>  	default:
> diff --git a/tools/testing/selftests/pidfd/pidfd_test.c b/tools/testing/selftests/pidfd/pidfd_test.c
> index 00a07e7c571c..c081ae91313a 100644
> --- a/tools/testing/selftests/pidfd/pidfd_test.c
> +++ b/tools/testing/selftests/pidfd/pidfd_test.c
> @@ -381,13 +381,13 @@ static int test_pidfd_send_signal_syscall_support(void)
>  
>  static void *test_pidfd_poll_exec_thread(void *priv)
>  {
> -	ksft_print_msg("Child Thread: starting. pid %d tid %d ; and sleeping\n",
> +	ksft_print_msg("Child Thread: starting. pid %d tid %ld ; and sleeping\n",
>  			getpid(), syscall(SYS_gettid));
>  	ksft_print_msg("Child Thread: doing exec of sleep\n");
>  
>  	execl("/bin/sleep", "sleep", str(CHILD_THREAD_MIN_WAIT), (char *)NULL);
>  
> -	ksft_print_msg("Child Thread: DONE. pid %d tid %d\n",
> +	ksft_print_msg("Child Thread: DONE. pid %d tid %ld\n",
>  			getpid(), syscall(SYS_gettid));
>  	return NULL;
>  }
> @@ -427,7 +427,7 @@ static int child_poll_exec_test(void *args)
>  {
>  	pthread_t t1;
>  
> -	ksft_print_msg("Child (pidfd): starting. pid %d tid %d\n", getpid(),
> +	ksft_print_msg("Child (pidfd): starting. pid %d tid %ld\n", getpid(),
>  			syscall(SYS_gettid));
>  	pthread_create(&t1, NULL, test_pidfd_poll_exec_thread, NULL);
>  	/*
> @@ -480,10 +480,10 @@ static void test_pidfd_poll_exec(int use_waitpid)
>  
>  static void *test_pidfd_poll_leader_exit_thread(void *priv)
>  {
> -	ksft_print_msg("Child Thread: starting. pid %d tid %d ; and sleeping\n",
> +	ksft_print_msg("Child Thread: starting. pid %d tid %ld ; and sleeping\n",
>  			getpid(), syscall(SYS_gettid));
>  	sleep(CHILD_THREAD_MIN_WAIT);
> -	ksft_print_msg("Child Thread: DONE. pid %d tid %d\n", getpid(), syscall(SYS_gettid));
> +	ksft_print_msg("Child Thread: DONE. pid %d tid %ld\n", getpid(), syscall(SYS_gettid));
>  	return NULL;
>  }
>  
> @@ -492,7 +492,7 @@ static int child_poll_leader_exit_test(void *args)
>  {
>  	pthread_t t1, t2;
>  
> -	ksft_print_msg("Child: starting. pid %d tid %d\n", getpid(), syscall(SYS_gettid));
> +	ksft_print_msg("Child: starting. pid %d tid %ld\n", getpid(), syscall(SYS_gettid));
>  	pthread_create(&t1, NULL, test_pidfd_poll_leader_exit_thread, NULL);
>  	pthread_create(&t2, NULL, test_pidfd_poll_leader_exit_thread, NULL);
>  
>
Maciej Wieczor-Retman Aug. 28, 2023, 1:07 p.m. UTC | #2
On 2023-08-28 at 14:01:18 +0300, Ilpo Järvinen wrote:
>On Mon, 28 Aug 2023, Wieczor-Retman, Maciej wrote:
>> Signed-off-by: Wieczor-Retman, Maciej <maciej.wieczor-retman@intel.com>
>> ---
>>  tools/testing/selftests/pidfd/pidfd_fdinfo_test.c |  2 +-
>>  tools/testing/selftests/pidfd/pidfd_test.c        | 12 ++++++------
>>  2 files changed, 7 insertions(+), 7 deletions(-)
>> 
>> diff --git a/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c b/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
>> index 4e86f927880c..01cc37bf611c 100644
>> --- a/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
>> +++ b/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
>> @@ -62,7 +62,7 @@ static void error_report(struct error *err, const char *test_name)
>>  		break;
>>  
>>  	case PIDFD_PASS:
>> -		ksft_test_result_pass("%s test: Passed\n");
>> +		ksft_test_result_pass("%s test: Passed\n", test_name);
>
>Missing test_name leads to crash so this looks a Fixes: class thing for
>me but you didn't provide one.

Thanks, I'll add this tag.

In my case it just gives a warning but compiles anyway:

pidfd_fdinfo_test.c: In function ‘error_report’:
pidfd_fdinfo_test.c:65:41: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
   65 |                 ksft_test_result_pass("%s test: Passed\n");
      |                                        ~^
      |                                         |
      |                                         char *

Could I be missing some strict config?
diff mbox series

Patch

diff --git a/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c b/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
index 4e86f927880c..01cc37bf611c 100644
--- a/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
+++ b/tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
@@ -62,7 +62,7 @@  static void error_report(struct error *err, const char *test_name)
 		break;
 
 	case PIDFD_PASS:
-		ksft_test_result_pass("%s test: Passed\n");
+		ksft_test_result_pass("%s test: Passed\n", test_name);
 		break;
 
 	default:
diff --git a/tools/testing/selftests/pidfd/pidfd_test.c b/tools/testing/selftests/pidfd/pidfd_test.c
index 00a07e7c571c..c081ae91313a 100644
--- a/tools/testing/selftests/pidfd/pidfd_test.c
+++ b/tools/testing/selftests/pidfd/pidfd_test.c
@@ -381,13 +381,13 @@  static int test_pidfd_send_signal_syscall_support(void)
 
 static void *test_pidfd_poll_exec_thread(void *priv)
 {
-	ksft_print_msg("Child Thread: starting. pid %d tid %d ; and sleeping\n",
+	ksft_print_msg("Child Thread: starting. pid %d tid %ld ; and sleeping\n",
 			getpid(), syscall(SYS_gettid));
 	ksft_print_msg("Child Thread: doing exec of sleep\n");
 
 	execl("/bin/sleep", "sleep", str(CHILD_THREAD_MIN_WAIT), (char *)NULL);
 
-	ksft_print_msg("Child Thread: DONE. pid %d tid %d\n",
+	ksft_print_msg("Child Thread: DONE. pid %d tid %ld\n",
 			getpid(), syscall(SYS_gettid));
 	return NULL;
 }
@@ -427,7 +427,7 @@  static int child_poll_exec_test(void *args)
 {
 	pthread_t t1;
 
-	ksft_print_msg("Child (pidfd): starting. pid %d tid %d\n", getpid(),
+	ksft_print_msg("Child (pidfd): starting. pid %d tid %ld\n", getpid(),
 			syscall(SYS_gettid));
 	pthread_create(&t1, NULL, test_pidfd_poll_exec_thread, NULL);
 	/*
@@ -480,10 +480,10 @@  static void test_pidfd_poll_exec(int use_waitpid)
 
 static void *test_pidfd_poll_leader_exit_thread(void *priv)
 {
-	ksft_print_msg("Child Thread: starting. pid %d tid %d ; and sleeping\n",
+	ksft_print_msg("Child Thread: starting. pid %d tid %ld ; and sleeping\n",
 			getpid(), syscall(SYS_gettid));
 	sleep(CHILD_THREAD_MIN_WAIT);
-	ksft_print_msg("Child Thread: DONE. pid %d tid %d\n", getpid(), syscall(SYS_gettid));
+	ksft_print_msg("Child Thread: DONE. pid %d tid %ld\n", getpid(), syscall(SYS_gettid));
 	return NULL;
 }
 
@@ -492,7 +492,7 @@  static int child_poll_leader_exit_test(void *args)
 {
 	pthread_t t1, t2;
 
-	ksft_print_msg("Child: starting. pid %d tid %d\n", getpid(), syscall(SYS_gettid));
+	ksft_print_msg("Child: starting. pid %d tid %ld\n", getpid(), syscall(SYS_gettid));
 	pthread_create(&t1, NULL, test_pidfd_poll_leader_exit_thread, NULL);
 	pthread_create(&t2, NULL, test_pidfd_poll_leader_exit_thread, NULL);