Skip to contentSkip to conversation

lib: Improve the is_signed_type() kunit test

PATCH Applied Bart Van Assche 2 participants 2 messages Sep 7, 2022 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 <[email protected]>
Cc Rasmus Villemoes <[email protected]>
---
 lib/is_signed_type_kunit.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/is_signed_type_kunit.c +6 -1
index f2eedb1f0935..207207522925 100644
@@ -5,7 +5,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <kunit/test.h>
-#include <linux/overflow.h>
+#include <linux/compiler.h>
 
 enum unsigned_enum {
 	constant_a = 3,
@@ -21,6 +21,11 @@ static void is_signed_type_test(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, is_signed_type(bool), false);
 	KUNIT_EXPECT_EQ(test, is_signed_type(signed char), true);
 	KUNIT_EXPECT_EQ(test, is_signed_type(unsigned char), false);
+#ifdef __CHAR_UNSIGNED__
+	KUNIT_EXPECT_EQ(test, is_signed_type(char), false);
+#else
+	KUNIT_EXPECT_EQ(test, is_signed_type(char), true);
+#endif
 	KUNIT_EXPECT_EQ(test, is_signed_type(int), true);
 	KUNIT_EXPECT_EQ(test, is_signed_type(unsigned int), false);
 	KUNIT_EXPECT_EQ(test, is_signed_type(long), true);
Applied
#1 lore raw
Quoted 5 lines · Bart Van Assche

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'.

Applied to for-next/hardening, thanks!

[1/1] lib: Improve the is_signed_type() kunit test

      https://git.kernel.org/kees/c/9d684f6d2d87
Signature · 1 line
Kees Cook