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

lib: Improve the is_signed_type() kunit test

Since the definition of is_signed_type() has been moved from
<linux/overflow.h> to <linux/compiler.h>, include the latter header file
instead of the former. Additionally, add a test for the type 'char'.

Cc: Isabella Basso <isabbasso@riseup.net>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220907180329.3825417-1-bvanassche@acm.org

authored by

Bart Van Assche and committed by
Kees Cook
98388bda 6e42aec7

+6 -1
+6 -1
lib/is_signed_type_kunit.c
··· 5 5 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 6 6 7 7 #include <kunit/test.h> 8 - #include <linux/overflow.h> 8 + #include <linux/compiler.h> 9 9 10 10 enum unsigned_enum { 11 11 constant_a = 3, ··· 21 21 KUNIT_EXPECT_EQ(test, is_signed_type(bool), false); 22 22 KUNIT_EXPECT_EQ(test, is_signed_type(signed char), true); 23 23 KUNIT_EXPECT_EQ(test, is_signed_type(unsigned char), false); 24 + #ifdef __CHAR_UNSIGNED__ 25 + KUNIT_EXPECT_EQ(test, is_signed_type(char), false); 26 + #else 27 + KUNIT_EXPECT_EQ(test, is_signed_type(char), true); 28 + #endif 24 29 KUNIT_EXPECT_EQ(test, is_signed_type(int), true); 25 30 KUNIT_EXPECT_EQ(test, is_signed_type(unsigned int), false); 26 31 KUNIT_EXPECT_EQ(test, is_signed_type(long), true);