Skip to content

kunit: further reduce stack usage of asserts

Daniel Latypov linux-kselftest lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 10 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3kunit: remove va_format from kunit_assertinclude/kunit/assert.h lib/kunit/assert.c lib/kunit/test.c+36 -462 replies
2/3kunit: consolidate KUNIT_INIT_BINARY_ASSERT_STRUCT macrosinclude/kunit/assert.h include/kunit/test.h+22 -663 replies
3/3kunit: factor out str constants from binary assertion structsinclude/kunit/assert.h include/kunit/test.h lib/kunit/assert.c+54 -535 replies

Reviews trailers per patch

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

PatchDavid GowBrendan Higgins
1/3R-b R-b
2/3R-b R-b
3/3R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/3] kunit: further reduce stack usage of asserts

If the compiler doesn't optimize them away, each kunit assertion (use of KUNIT_EXPECT_EQ, etc.) can use 88 bytes of stack space in the worst and most common case. This has led to compiler warnings for certain configs
+ arches [1].

This series builds upon [2] which cut down kunit_assert from 48 => 24 bytes, but only reduced kunit_binary_assert (the most common one) from 88 => 48.

Now we have kunit_assert = 8 and kunit_binary_assert = 32. The cost is we need to pass around another parameter to some functions (struct va_format *), and we introduce a new type
(sturct kunit_binary_assert_text) for holding the textual representation of the KUNIT_EXPECT_EQ arguments.

Note: it's possible to get kunit_assert = 0 and kunit_binary_assert = 24 by removing the format function pointer field from kunit_assert. I think it's an improvement, but others might think that readability suffers from doing so, so I'm leaving that off from this series.

Meta: this series applies on top of 5.17-rc1 + [2] and [3]. That should be available at in Shuah's kunit branch [4], but my version of git is constantly segfaulting, so I can't try and rebase to verify.

[1] https://groups.google.com/g/kunit-dev/c/i3fZXgvBrfA/m/VULQg1z6BAAJ
[2] https://lore.kernel.org/linux-kselftest/[email protected]/
[3] https://lore.kernel.org/linux-kselftest/[email protected]/
[4] https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/?h=kunit

Daniel Latypov (3):
kunit: remove va_format from kunit_assert
kunit: consolidate KUNIT_INIT_BINARY_ASSERT_STRUCT macros
kunit: factor out str constants from binary assertion structs

 include/kunit/assert.h | 152 ++++++++++++-----------------------------
 include/kunit/test.h   |  32 +++++----
 lib/kunit/assert.c     |  65 ++++++++++--------
 lib/kunit/test.c       |  12 ++--
 4 files changed, 104 insertions(+), 157 deletions(-)
Signature · 1 line
2.35.0.rc2.247.g8bbb082509-goog