Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests

2024-02-27 Thread Shuah Khan

On 2/21/24 14:29, Justin Stitt wrote:

Hi,

On Wed, Feb 21, 2024 at 05:27:20PM +0800, David Gow wrote:

The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
which was then updated to be an 'unsigned long' to avoid 64-bit
multiplication division helpers.

However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
'%d' or '%llu' format specifiers, the former of which is always wrong,
and the latter is no longer correct now that ps is no longer a u64. Fix
these to all use '%lu'.

Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
message. gcc warns if a printf format string is empty (apparently), so


clang does too; under -Wformat-zero-length


give these some more detailed error messages, which should be more
useful anyway.

Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
Signed-off-by: David Gow 


Reviewed-by: Justin Stitt 


David,

Please send this on top of Linux 6.9-rc6 - this one doesn't
apply as is due to conflict between this one and fca7526b7d89

I think if we can fix this here - we won't problems during pull
request merge.

thanks,
-- Shuah




Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests

2024-02-21 Thread Justin Stitt
Hi,

On Wed, Feb 21, 2024 at 05:27:20PM +0800, David Gow wrote:
> The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
> which was then updated to be an 'unsigned long' to avoid 64-bit
> multiplication division helpers.
>
> However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
> '%d' or '%llu' format specifiers, the former of which is always wrong,
> and the latter is no longer correct now that ps is no longer a u64. Fix
> these to all use '%lu'.
>
> Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
> message. gcc warns if a printf format string is empty (apparently), so

clang does too; under -Wformat-zero-length

> give these some more detailed error messages, which should be more
> useful anyway.
>
> Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
> Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit 
> targets")
> Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
> Signed-off-by: David Gow 

Reviewed-by: Justin Stitt 
> ---
>  drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++---
>  drivers/gpu/drm/tests/drm_mm_test.c|  6 +++---
>  2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c 
> b/drivers/gpu/drm/tests/drm_buddy_test.c
> index 8a464f7f4c61..3dbfa3078449 100644
> --- a/drivers/gpu/drm/tests/drm_buddy_test.c
> +++ b/drivers/gpu/drm/tests/drm_buddy_test.c
> @@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit 
> *test)
>   KUNIT_ASSERT_FALSE_MSG(test,
>  drm_buddy_alloc_blocks(, 0, mm_size,
> ps, ps, list, 0),
> -"buddy_alloc hit an error size=%d\n",
> +"buddy_alloc hit an error size=%lu\n",
>  ps);
>   } while (++i < n_pages);
>
>   KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>  3 * ps, ps, 
> ,
>  
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc didn't error size=%d\n", 3 * ps);
> +"buddy_alloc didn't error size=%lu\n", 3 * ps);
>
>   drm_buddy_free_list(, );
>   KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>  3 * ps, ps, 
> ,
>  
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc didn't error size=%llu\n", 3 * ps);
> +"buddy_alloc didn't error size=%lu\n", 3 * ps);
>   KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>  2 * ps, ps, 
> ,
>  
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc didn't error size=%llu\n", 2 * ps);
> +"buddy_alloc didn't error size=%lu\n", 2 * ps);
>
>   drm_buddy_free_list(, );
>   KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>  3 * ps, ps, 
> ,
>  
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc didn't error size=%llu\n", 3 * ps);
> +"buddy_alloc didn't error size=%lu\n", 3 * ps);
>   /*
>* At this point we should have enough contiguous space for 2 blocks,
>* however they are never buddies (since we freed middle and right) so
> @@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit 
> *test)
>   KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>   2 * ps, ps, 
> ,
>   
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc hit an error size=%d\n", 2 * ps);
> +"buddy_alloc hit an error size=%lu\n", 2 * ps);
>
>   drm_buddy_free_list(, );
>   KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>   3 * ps, ps, 
> ,
>   
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc hit an error size=%d\n", 3 * ps);
> +"buddy_alloc hit an error size=%lu\n", 3 * ps);
>
>   total = 0;
>   list_for_each_entry(block, , link)
> diff --git a/drivers/gpu/drm/tests/drm_mm_test.c 
> b/drivers/gpu/drm/tests/drm_mm_test.c
> index 1eb0c304f960..f37c0d765865 100644
> --- 

Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests

2024-02-21 Thread Guenter Roeck
On Wed, Feb 21, 2024 at 05:27:20PM +0800, David Gow wrote:
> The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
> which was then updated to be an 'unsigned long' to avoid 64-bit
> multiplication division helpers.
> 
> However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
> '%d' or '%llu' format specifiers, the former of which is always wrong,
> and the latter is no longer correct now that ps is no longer a u64. Fix
> these to all use '%lu'.
> 
> Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
> message. gcc warns if a printf format string is empty (apparently), so
> give these some more detailed error messages, which should be more
> useful anyway.
> 
> Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
> Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit 
> targets")
> Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
> Signed-off-by: David Gow 

Tested-by: Guenter Roeck 

> ---
>  drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++---
>  drivers/gpu/drm/tests/drm_mm_test.c|  6 +++---
>  2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c 
> b/drivers/gpu/drm/tests/drm_buddy_test.c
> index 8a464f7f4c61..3dbfa3078449 100644
> --- a/drivers/gpu/drm/tests/drm_buddy_test.c
> +++ b/drivers/gpu/drm/tests/drm_buddy_test.c
> @@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit 
> *test)
>   KUNIT_ASSERT_FALSE_MSG(test,
>  drm_buddy_alloc_blocks(, 0, mm_size,
> ps, ps, list, 0),
> -"buddy_alloc hit an error size=%d\n",
> +"buddy_alloc hit an error size=%lu\n",
>  ps);
>   } while (++i < n_pages);
>  
>   KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>  3 * ps, ps, 
> ,
>  
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc didn't error size=%d\n", 3 * ps);
> +"buddy_alloc didn't error size=%lu\n", 3 * ps);
>  
>   drm_buddy_free_list(, );
>   KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>  3 * ps, ps, 
> ,
>  
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc didn't error size=%llu\n", 3 * ps);
> +"buddy_alloc didn't error size=%lu\n", 3 * ps);
>   KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>  2 * ps, ps, 
> ,
>  
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc didn't error size=%llu\n", 2 * ps);
> +"buddy_alloc didn't error size=%lu\n", 2 * ps);
>  
>   drm_buddy_free_list(, );
>   KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>  3 * ps, ps, 
> ,
>  
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc didn't error size=%llu\n", 3 * ps);
> +"buddy_alloc didn't error size=%lu\n", 3 * ps);
>   /*
>* At this point we should have enough contiguous space for 2 blocks,
>* however they are never buddies (since we freed middle and right) so
> @@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit 
> *test)
>   KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>   2 * ps, ps, 
> ,
>   
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc hit an error size=%d\n", 2 * ps);
> +"buddy_alloc hit an error size=%lu\n", 2 * ps);
>  
>   drm_buddy_free_list(, );
>   KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
>   3 * ps, ps, 
> ,
>   
> DRM_BUDDY_CONTIGUOUS_ALLOCATION),
> -"buddy_alloc hit an error size=%d\n", 3 * ps);
> +"buddy_alloc hit an error size=%lu\n", 3 * ps);
>  
>   total = 0;
>   list_for_each_entry(block, , link)
> diff --git a/drivers/gpu/drm/tests/drm_mm_test.c 
> b/drivers/gpu/drm/tests/drm_mm_test.c
> index 1eb0c304f960..f37c0d765865 100644
> --- a/drivers/gpu/drm/tests/drm_mm_test.c
> +++ 

Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests

2024-02-21 Thread Christian König

Am 21.02.24 um 10:27 schrieb David Gow:

The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
which was then updated to be an 'unsigned long' to avoid 64-bit
multiplication division helpers.

However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
'%d' or '%llu' format specifiers, the former of which is always wrong,
and the latter is no longer correct now that ps is no longer a u64. Fix
these to all use '%lu'.

Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
message. gcc warns if a printf format string is empty (apparently), so
give these some more detailed error messages, which should be more
useful anyway.

Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
Signed-off-by: David Gow 


Acked-by: Christian König 

Ping me if you want this patch pushed upstream through the DRM tree.

Christian.


---
  drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++---
  drivers/gpu/drm/tests/drm_mm_test.c|  6 +++---
  2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c 
b/drivers/gpu/drm/tests/drm_buddy_test.c
index 8a464f7f4c61..3dbfa3078449 100644
--- a/drivers/gpu/drm/tests/drm_buddy_test.c
+++ b/drivers/gpu/drm/tests/drm_buddy_test.c
@@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit 
*test)
KUNIT_ASSERT_FALSE_MSG(test,
   drm_buddy_alloc_blocks(, 0, mm_size,
  ps, ps, list, 0),
-  "buddy_alloc hit an error size=%d\n",
+  "buddy_alloc hit an error size=%lu\n",
   ps);
} while (++i < n_pages);
  
  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,

   3 * ps, ps, 
,
   
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc didn't error size=%d\n", 3 * ps);
+  "buddy_alloc didn't error size=%lu\n", 3 * ps);
  
  	drm_buddy_free_list(, );

KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
   3 * ps, ps, 
,
   
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc didn't error size=%llu\n", 3 * ps);
+  "buddy_alloc didn't error size=%lu\n", 3 * ps);
KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
   2 * ps, ps, 
,
   
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc didn't error size=%llu\n", 2 * ps);
+  "buddy_alloc didn't error size=%lu\n", 2 * ps);
  
  	drm_buddy_free_list(, );

KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
   3 * ps, ps, 
,
   
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc didn't error size=%llu\n", 3 * ps);
+  "buddy_alloc didn't error size=%lu\n", 3 * ps);
/*
 * At this point we should have enough contiguous space for 2 blocks,
 * however they are never buddies (since we freed middle and right) so
@@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit 
*test)
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
2 * ps, ps, 
,

DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc hit an error size=%d\n", 2 * ps);
+  "buddy_alloc hit an error size=%lu\n", 2 * ps);
  
  	drm_buddy_free_list(, );

KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
3 * ps, ps, 
,

DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc hit an error size=%d\n", 3 * ps);
+  "buddy_alloc hit an error size=%lu\n", 3 * ps);
  
  	total = 0;

list_for_each_entry(block, , link)
diff --git a/drivers/gpu/drm/tests/drm_mm_test.c 
b/drivers/gpu/drm/tests/drm_mm_test.c
index 1eb0c304f960..f37c0d765865 100644
--- a/drivers/gpu/drm/tests/drm_mm_test.c
+++ b/drivers/gpu/drm/tests/drm_mm_test.c
@@ -157,7 +157,7 @@ static 

Re: [PATCH 7/9] drm: tests: Fix invalid printf format specifiers in KUnit tests

2024-02-21 Thread Matthew Auld

On 21/02/2024 09:27, David Gow wrote:

The drm_buddy_test's alloc_contiguous test used a u64 for the page size,
which was then updated to be an 'unsigned long' to avoid 64-bit
multiplication division helpers.

However, the variable is logged by some KUNIT_ASSERT_EQ_MSG() using the
'%d' or '%llu' format specifiers, the former of which is always wrong,
and the latter is no longer correct now that ps is no longer a u64. Fix
these to all use '%lu'.

Also, drm_mm_test calls KUNIT_FAIL() with an empty string as the
message. gcc warns if a printf format string is empty (apparently), so
give these some more detailed error messages, which should be more
useful anyway.

Fixes: a64056bb5a32 ("drm/tests/drm_buddy: add alloc_contiguous test")
Fixes: fca7526b7d89 ("drm/tests/drm_buddy: fix build failure on 32-bit targets")
Fixes: fc8d29e298cf ("drm: selftest: convert drm_mm selftest to KUnit")
Signed-off-by: David Gow 
---
  drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++---
  drivers/gpu/drm/tests/drm_mm_test.c|  6 +++---
  2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c 
b/drivers/gpu/drm/tests/drm_buddy_test.c
index 8a464f7f4c61..3dbfa3078449 100644
--- a/drivers/gpu/drm/tests/drm_buddy_test.c
+++ b/drivers/gpu/drm/tests/drm_buddy_test.c
@@ -55,30 +55,30 @@ static void drm_test_buddy_alloc_contiguous(struct kunit 
*test)
KUNIT_ASSERT_FALSE_MSG(test,
   drm_buddy_alloc_blocks(, 0, mm_size,
  ps, ps, list, 0),
-  "buddy_alloc hit an error size=%d\n",
+  "buddy_alloc hit an error size=%lu\n",
   ps);
} while (++i < n_pages);
  
  	KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,

   3 * ps, ps, 
,
   
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc didn't error size=%d\n", 3 * ps);
+  "buddy_alloc didn't error size=%lu\n", 3 * ps);
  
  	drm_buddy_free_list(, );

KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
   3 * ps, ps, 
,
   
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc didn't error size=%llu\n", 3 * ps);
+  "buddy_alloc didn't error size=%lu\n", 3 * ps);
KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
   2 * ps, ps, 
,
   
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc didn't error size=%llu\n", 2 * ps);
+  "buddy_alloc didn't error size=%lu\n", 2 * ps);
  
  	drm_buddy_free_list(, );

KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
   3 * ps, ps, 
,
   
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc didn't error size=%llu\n", 3 * ps);
+  "buddy_alloc didn't error size=%lu\n", 3 * ps);
/*
 * At this point we should have enough contiguous space for 2 blocks,
 * however they are never buddies (since we freed middle and right) so
@@ -87,13 +87,13 @@ static void drm_test_buddy_alloc_contiguous(struct kunit 
*test)
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
2 * ps, ps, 
,

DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc hit an error size=%d\n", 2 * ps);
+  "buddy_alloc hit an error size=%lu\n", 2 * ps);
  
  	drm_buddy_free_list(, );

KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(, 0, mm_size,
3 * ps, ps, 
,

DRM_BUDDY_CONTIGUOUS_ALLOCATION),
-  "buddy_alloc hit an error size=%d\n", 3 * ps);
+  "buddy_alloc hit an error size=%lu\n", 3 * ps);


There was also a fix for this in: 335126937753 ("drm/tests/drm_buddy: 
fix 32b build"), but there everything was made u32.


Reviewed-by: Matthew Auld 

  
  	total = 0;

list_for_each_entry(block, , link)
diff --git a/drivers/gpu/drm/tests/drm_mm_test.c 
b/drivers/gpu/drm/tests/drm_mm_test.c
index 1eb0c304f960..f37c0d765865 100644
--- a/drivers/gpu/drm/tests/drm_mm_test.c
+++