public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests: harness: fix printing of mismatch values in __EXPECT()
@ 2025-01-08 17:07 Dmitry V. Levin
  2025-01-08 21:57 ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry V. Levin @ 2025-01-08 17:07 UTC (permalink / raw)
  To: Kees Cook, Shuah Khan; +Cc: Gabi Falk, linux-kselftest, linux-kernel

intptr_t and uintptr_t are not big enough types on 32-bit architectures
when printing 64-bit values, resulting to the following incorrect
diagnostic output:

  # get_syscall_info.c:209:get_syscall_info:Expected exp_args[2] (3134324433) == info.entry.args[1] (3134324433)

Replace intptr_t and uintptr_t with intmax_t and uintmax_t, respectively.
With this fix, the same test produces more usable diagnostic output:

  # get_syscall_info.c:209:get_syscall_info:Expected exp_args[2] (3134324433) == info.entry.args[1] (18446744072548908753)

Fixes: b5bb6d3068ea ("selftests/seccomp: fix 32-bit build warnings")
Signed-off-by: Dmitry V. Levin <ldv@strace.io>
---
 tools/testing/selftests/kselftest_harness.h | 24 ++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index a5a72415e37b..666c9fde76da 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -760,33 +760,33 @@
 		/* Report with actual signedness to avoid weird output. */ \
 		switch (is_signed_type(__exp) * 2 + is_signed_type(__seen)) { \
 		case 0: { \
-			unsigned long long __exp_print = (uintptr_t)__exp; \
-			unsigned long long __seen_print = (uintptr_t)__seen; \
-			__TH_LOG("Expected %s (%llu) %s %s (%llu)", \
+			uintmax_t __exp_print = (uintmax_t)__exp; \
+			uintmax_t __seen_print = (uintmax_t)__seen; \
+			__TH_LOG("Expected %s (%ju) %s %s (%ju)", \
 				 _expected_str, __exp_print, #_t, \
 				 _seen_str, __seen_print); \
 			break; \
 			} \
 		case 1: { \
-			unsigned long long __exp_print = (uintptr_t)__exp; \
-			long long __seen_print = (intptr_t)__seen; \
-			__TH_LOG("Expected %s (%llu) %s %s (%lld)", \
+			uintmax_t __exp_print = (uintmax_t)__exp; \
+			intmax_t  __seen_print = (intmax_t)__seen; \
+			__TH_LOG("Expected %s (%ju) %s %s (%jd)", \
 				 _expected_str, __exp_print, #_t, \
 				 _seen_str, __seen_print); \
 			break; \
 			} \
 		case 2: { \
-			long long __exp_print = (intptr_t)__exp; \
-			unsigned long long __seen_print = (uintptr_t)__seen; \
-			__TH_LOG("Expected %s (%lld) %s %s (%llu)", \
+			intmax_t  __exp_print = (intmax_t)__exp; \
+			uintmax_t __seen_print = (uintmax_t)__seen; \
+			__TH_LOG("Expected %s (%jd) %s %s (%ju)", \
 				 _expected_str, __exp_print, #_t, \
 				 _seen_str, __seen_print); \
 			break; \
 			} \
 		case 3: { \
-			long long __exp_print = (intptr_t)__exp; \
-			long long __seen_print = (intptr_t)__seen; \
-			__TH_LOG("Expected %s (%lld) %s %s (%lld)", \
+			intmax_t  __exp_print = (intmax_t)__exp; \
+			intmax_t  __seen_print = (intmax_t)__seen; \
+			__TH_LOG("Expected %s (%jd) %s %s (%jd)", \
 				 _expected_str, __exp_print, #_t, \
 				 _seen_str, __seen_print); \
 			break; \
-- 
ldv

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests: harness: fix printing of mismatch values in __EXPECT()
  2025-01-08 17:07 [PATCH] selftests: harness: fix printing of mismatch values in __EXPECT() Dmitry V. Levin
@ 2025-01-08 21:57 ` Kees Cook
  2025-01-08 23:23   ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2025-01-08 21:57 UTC (permalink / raw)
  To: Dmitry V. Levin; +Cc: Shuah Khan, Gabi Falk, linux-kselftest, linux-kernel

On Wed, Jan 08, 2025 at 07:07:57PM +0200, Dmitry V. Levin wrote:
> intptr_t and uintptr_t are not big enough types on 32-bit architectures
> when printing 64-bit values, resulting to the following incorrect
> diagnostic output:
> 
>   # get_syscall_info.c:209:get_syscall_info:Expected exp_args[2] (3134324433) == info.entry.args[1] (3134324433)
> 
> Replace intptr_t and uintptr_t with intmax_t and uintmax_t, respectively.
> With this fix, the same test produces more usable diagnostic output:
> 
>   # get_syscall_info.c:209:get_syscall_info:Expected exp_args[2] (3134324433) == info.entry.args[1] (18446744072548908753)
> 
> Fixes: b5bb6d3068ea ("selftests/seccomp: fix 32-bit build warnings")
> Signed-off-by: Dmitry V. Levin <ldv@strace.io>

Ah nice, thanks!

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests: harness: fix printing of mismatch values in __EXPECT()
  2025-01-08 21:57 ` Kees Cook
@ 2025-01-08 23:23   ` Shuah Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2025-01-08 23:23 UTC (permalink / raw)
  To: Kees Cook, Dmitry V. Levin
  Cc: Shuah Khan, Gabi Falk, linux-kselftest, linux-kernel, Shuah Khan

On 1/8/25 14:57, Kees Cook wrote:
> On Wed, Jan 08, 2025 at 07:07:57PM +0200, Dmitry V. Levin wrote:
>> intptr_t and uintptr_t are not big enough types on 32-bit architectures
>> when printing 64-bit values, resulting to the following incorrect
>> diagnostic output:
>>
>>    # get_syscall_info.c:209:get_syscall_info:Expected exp_args[2] (3134324433) == info.entry.args[1] (3134324433)
>>
>> Replace intptr_t and uintptr_t with intmax_t and uintmax_t, respectively.
>> With this fix, the same test produces more usable diagnostic output:
>>
>>    # get_syscall_info.c:209:get_syscall_info:Expected exp_args[2] (3134324433) == info.entry.args[1] (18446744072548908753)
>>
>> Fixes: b5bb6d3068ea ("selftests/seccomp: fix 32-bit build warnings")
>> Signed-off-by: Dmitry V. Levin <ldv@strace.io>
> 
> Ah nice, thanks!
> 
> Reviewed-by: Kees Cook <kees@kernel.org>
> 

Thank you. Applied to linux-kselftest next for Linux 6.14-rc1.

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-08 23:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08 17:07 [PATCH] selftests: harness: fix printing of mismatch values in __EXPECT() Dmitry V. Levin
2025-01-08 21:57 ` Kees Cook
2025-01-08 23:23   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox