kunit: string-stream-test: Avoid cast warning when testing gfp_t flags
PATCH 1/1 kunit: string-stream-test: Avoid cast warning when testing gfp_t flags
Passing a gfp_t to KUNIT_EXPECT_EQ() causes a cast warning:
lib/kunit/string-stream-test.c:73:9: sparse: sparse: incorrect type in initializer (different base types) expected long long right_value got restricted gfp_t const __right
Avoid this by testing stream->gfp for the expected value and passing the boolean result of this comparison to KUNIT_EXPECT_TRUE(), as was already done a few lines above in string_stream_managed_init_test().
--- lib/kunit/string-stream-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kunit/string-stream-test.c +1 -1
@@ -72,7 +72,7 @@ static void string_stream_unmanaged_init_test(struct kunit *test)KUNIT_EXPECT_EQ (test, stream->length,0 );KUNIT_EXPECT_TRUE (test,list_empty (&stream->fragments)); -KUNIT_EXPECT_EQ (test, stream->gfp,GFP_KERNEL ); +KUNIT_EXPECT_TRUE (test, (stream->gfp ==GFP_KERNEL ));KUNIT_EXPECT_FALSE (test, stream->append_newlines);KUNIT_EXPECT_TRUE (test,string_stream_is_empty (stream));
Signature · 1 line
2.30.2
Quoted 7 lines · Richard Fitzgerald
Passing a
gfp_ttoKUNIT_EXPECT_EQ()causes a cast warning:
lib/kunit/string-stream-test.c:73:9: sparse: sparse: incorrect type in initializer (different base types) expected long longright_valuegot restrictedgfp_tconst__right
Quoted 8 lines
Avoid this by testing
stream->gfpfor the expected value and passing the boolean result of this comparison toKUNIT_EXPECT_TRUE(), as was already done a few lines above instring_stream_managed_init_test().Signed-off-by Richard Fitzgerald <[email protected]>Fixes d1a0d699bfc0 ("kunit: string-stream: Add tests for freeing resource-managed string_stream")Reported-by kernel test robot <[email protected]>
Hello!
This looks good to me. Thanks for fixing this!
-Rae
Quoted 20 lines
--- lib/kunit/string-stream-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/kunit/string-stream-test.c +1
-2@@ -72,7 +72,7 @@ static void string_stream_unmanaged_init_test(struct kunit *test)KUNIT_EXPECT_EQ (test, stream->length,0 );KUNIT_EXPECT_TRUE (test,list_empty (&stream->fragments)); -KUNIT_EXPECT_EQ (test, stream->gfp,GFP_KERNEL ); +KUNIT_EXPECT_TRUE (test, (stream->gfp ==GFP_KERNEL ));KUNIT_EXPECT_FALSE (test, stream->append_newlines);KUNIT_EXPECT_TRUE (test,string_stream_is_empty (stream)); --2.30.2
Quoted 11 lines · Richard Fitzgerald
Passing a
gfp_ttoKUNIT_EXPECT_EQ()causes a cast warning:
lib/kunit/string-stream-test.c:73:9: sparse: sparse: incorrect type in initializer (different base types) expected long longright_valuegot restrictedgfp_tconst__rightAvoid this by testing
stream->gfpfor the expected value and passing the boolean result of this comparison toKUNIT_EXPECT_TRUE(), as was already done a few lines above instring_stream_managed_init_test().
Quoted 5 lines
Signed-off-by Richard Fitzgerald <[email protected]>Fixes d1a0d699bfc0 ("kunit: string-stream: Add tests for freeing resource-managed string_stream")Reported-by kernel test robot <[email protected]>---
Looks good to me.
Cheers,
-- David
Quoted 19 lines
lib/kunit/string-stream-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/kunit/string-stream-test.c +1
-2@@ -72,7 +72,7 @@ static void string_stream_unmanaged_init_test(struct kunit *test)KUNIT_EXPECT_EQ (test, stream->length,0 );KUNIT_EXPECT_TRUE (test,list_empty (&stream->fragments)); -KUNIT_EXPECT_EQ (test, stream->gfp,GFP_KERNEL ); +KUNIT_EXPECT_TRUE (test, (stream->gfp ==GFP_KERNEL ));KUNIT_EXPECT_FALSE (test, stream->append_newlines);KUNIT_EXPECT_TRUE (test,string_stream_is_empty (stream)); --2.30.2