Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: harness: fix printing of mismatch values in __EXPECT()

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)

Link: https://lore.kernel.org/r/20250108170757.GA6723@strace.io
Fixes: b5bb6d3068ea ("selftests/seccomp: fix 32-bit build warnings")
Signed-off-by: Dmitry V. Levin <ldv@strace.io>
Reviewed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Dmitry V. Levin and committed by
Shuah Khan
02bc220d b6f9cd83

+12 -12
+12 -12
tools/testing/selftests/kselftest_harness.h
··· 760 760 /* Report with actual signedness to avoid weird output. */ \ 761 761 switch (is_signed_type(__exp) * 2 + is_signed_type(__seen)) { \ 762 762 case 0: { \ 763 - unsigned long long __exp_print = (uintptr_t)__exp; \ 764 - unsigned long long __seen_print = (uintptr_t)__seen; \ 765 - __TH_LOG("Expected %s (%llu) %s %s (%llu)", \ 763 + uintmax_t __exp_print = (uintmax_t)__exp; \ 764 + uintmax_t __seen_print = (uintmax_t)__seen; \ 765 + __TH_LOG("Expected %s (%ju) %s %s (%ju)", \ 766 766 _expected_str, __exp_print, #_t, \ 767 767 _seen_str, __seen_print); \ 768 768 break; \ 769 769 } \ 770 770 case 1: { \ 771 - unsigned long long __exp_print = (uintptr_t)__exp; \ 772 - long long __seen_print = (intptr_t)__seen; \ 773 - __TH_LOG("Expected %s (%llu) %s %s (%lld)", \ 771 + uintmax_t __exp_print = (uintmax_t)__exp; \ 772 + intmax_t __seen_print = (intmax_t)__seen; \ 773 + __TH_LOG("Expected %s (%ju) %s %s (%jd)", \ 774 774 _expected_str, __exp_print, #_t, \ 775 775 _seen_str, __seen_print); \ 776 776 break; \ 777 777 } \ 778 778 case 2: { \ 779 - long long __exp_print = (intptr_t)__exp; \ 780 - unsigned long long __seen_print = (uintptr_t)__seen; \ 781 - __TH_LOG("Expected %s (%lld) %s %s (%llu)", \ 779 + intmax_t __exp_print = (intmax_t)__exp; \ 780 + uintmax_t __seen_print = (uintmax_t)__seen; \ 781 + __TH_LOG("Expected %s (%jd) %s %s (%ju)", \ 782 782 _expected_str, __exp_print, #_t, \ 783 783 _seen_str, __seen_print); \ 784 784 break; \ 785 785 } \ 786 786 case 3: { \ 787 - long long __exp_print = (intptr_t)__exp; \ 788 - long long __seen_print = (intptr_t)__seen; \ 789 - __TH_LOG("Expected %s (%lld) %s %s (%lld)", \ 787 + intmax_t __exp_print = (intmax_t)__exp; \ 788 + intmax_t __seen_print = (intmax_t)__seen; \ 789 + __TH_LOG("Expected %s (%jd) %s %s (%jd)", \ 790 790 _expected_str, __exp_print, #_t, \ 791 791 _seen_str, __seen_print); \ 792 792 break; \