Skip to content

kunit: Fix printf format specifier issues in KUnit assertions

David Gow dri-devel intel-xe linux-hardening linux-kselftest linux-rtc lkml netdev 1 version Applied

Status from this message: The following commit has been merged into the timers/core branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 37 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/9kunit: test: Log the correct filter string in executor_testlib/kunit/executor_test.c+1 -14 replies
2/9lib/cmdline: Fix an invalid format specifier in an assertion msglib/cmdline_kunit.c+1 -15 replies
3/9lib: memcpy_kunit: Fix an invalid format specifier in an assertion msglib/memcpy_kunit.c+2 -22 replies
4/9time: test: Fix incorrect format specifierkernel/time/time_test.c+1 -15 replies
5/9rtc: test: Fix invalid format specifier.drivers/rtc/lib_test.c+1 -16 replies
6/9net: test: Fix printf format specifier in skb_segment kunit testnet/core/gso_test.c+1 -12 replies
7/9drm: tests: Fix invalid printf format specifiers in KUnit testsdrivers/gpu/drm/tests/drm_buddy_test.c drivers/gpu/drm/tests/drm_mm_test.c+10 -105 replies
8/9drm/xe/tests: Fix printf format specifiers in xe_migrate testdrivers/gpu/drm/xe/tests/xe_migrate.c+4 -44 replies
9/9kunit: Annotate _MSG assertion variants with gnu printf specifiersinclude/kunit/test.h+6 -62 replies

Reviews trailers per patch

All 9 patches have a Reviewed-by or Acked-by.

PatchMatthew AuldChristian KönigGuenter RoeckJustin StittDaniel LatypovLucas De MarchiThomas HellströmRae MoarAlexandre Belloni
1/9T-b R-b R-b R-b
2/9T-b R-b
3/9T-b R-b
4/9T-b R-b
5/9T-b R-b A-b
6/9T-b R-b
7/9R-b A-b T-b R-b
8/9T-b R-b A-b
9/9T-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 9 reviewers.

Read the v1 thread

Cover letter [PATCH 0/9] kunit: Fix printf format specifier issues in KUnit assertions

KUnit has several macros which accept a log message, which can contain printf format specifiers. Some of these (the explicit log macros) already use the __printf() gcc attribute to ensure the format specifiers are valid, but those which could fail the test, and hence used __kunit_do_failed_assertion() behind the scenes, did not.

These include:
- KUNIT_EXPECT_*_MSG()
- KUNIT_ASSERT_*_MSG()
- KUNIT_FAIL()

This series adds the __printf() attribute, and fixes all of the issues uncovered. (Or, at least, all of those I could find with an x86_64 allyesconfig, and the default KUnit config on a number of other architectures. Please test!)

The issues in question basically take the following forms:
- int / long / long long confusion: typically a type being updated, but the format string not.
- Use of integer format specifiers (%d/%u/%li/etc) for types like size_t or pointer differences (technically ptrdiff_t), which would only work on some architectures.
- Use of integer format specifiers in combination with PTR_ERR(), where %pe would make more sense.
- Use of empty messages which, whilst technically not incorrect, are not useful and trigger a gcc warning.

We'd like to get these (or equivalent) in for 6.9 if possible, so please do take a look if possible.

Thanks,
-- David

David Gow (9):
kunit: test: Log the correct filter string in executor_test lib/cmdline: Fix an invalid format specifier in an assertion msg
lib: memcpy_kunit: Fix an invalid format specifier in an assertion msg
time: test: Fix incorrect format specifier
rtc: test: Fix invalid format specifier.
net: test: Fix printf format specifier in skb_segment kunit test
drm: tests: Fix invalid printf format specifiers in KUnit tests drm/xe/tests: Fix printf format specifiers in xe_migrate test
kunit: Annotate _MSG assertion variants with gnu printf specifiers

 drivers/gpu/drm/tests/drm_buddy_test.c | 14 +++++++-------
 drivers/gpu/drm/tests/drm_mm_test.c    |  6 +++---
 drivers/gpu/drm/xe/tests/xe_migrate.c  |  8 ++++----
 drivers/rtc/lib_test.c                 |  2 +-
 include/kunit/test.h                   | 12 ++++++------
 kernel/time/time_test.c                |  2 +-
 lib/cmdline_kunit.c                    |  2 +-
 lib/kunit/executor_test.c              |  2 +-
 lib/memcpy_kunit.c                     |  4 ++--
 net/core/gso_test.c                    |  2 +-
 10 files changed, 27 insertions(+), 27 deletions(-)
Signature · 1 line
2.44.0.rc0.258.g7320e95886-goog