mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-06 03:45:24 -04:00
selftests/harness: Display signed values correctly
[ Upstream commit d088c92802549fc1cf77a12a4e3986160d63662a ]
Since forever the harness output for signed value tests have reported
unsigned values to avoid casting. Instead, actually test the variable
types and perform the correct casts and choose the correct format
specifiers.
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Stable-dep-of: 02bc220dc6dc ("selftests: harness: fix printing of mismatch values in __EXPECT()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
a84063de83
commit
822a5a0521
1 changed files with 37 additions and 5 deletions
|
|
@ -603,17 +603,49 @@
|
|||
if (_metadata->passed && _metadata->step < 255) \
|
||||
_metadata->step++;
|
||||
|
||||
#define is_signed_type(var) (!!(((__typeof__(var))(-1)) < (__typeof__(var))1))
|
||||
|
||||
#define __EXPECT(_expected, _expected_str, _seen, _seen_str, _t, _assert) do { \
|
||||
/* Avoid multiple evaluation of the cases */ \
|
||||
__typeof__(_expected) __exp = (_expected); \
|
||||
__typeof__(_seen) __seen = (_seen); \
|
||||
if (_assert) __INC_STEP(_metadata); \
|
||||
if (!(__exp _t __seen)) { \
|
||||
unsigned long long __exp_print = (uintptr_t)__exp; \
|
||||
unsigned long long __seen_print = (uintptr_t)__seen; \
|
||||
__TH_LOG("Expected %s (%llu) %s %s (%llu)", \
|
||||
_expected_str, __exp_print, #_t, \
|
||||
_seen_str, __seen_print); \
|
||||
/* 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)", \
|
||||
_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)", \
|
||||
_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)", \
|
||||
_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)", \
|
||||
_expected_str, __exp_print, #_t, \
|
||||
_seen_str, __seen_print); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
_metadata->passed = 0; \
|
||||
/* Ensure the optional handler is triggered */ \
|
||||
_metadata->trigger = 1; \
|
||||
|
|
|
|||
Loading…
Reference in a new issue