summaryrefslogtreecommitdiff
path: root/lib/kunit/test.c
diff options
context:
space:
mode:
authorDaniel Latypov <dlatypov@google.com>2022-01-25 13:00:09 -0800
committerShuah Khan <skhan@linuxfoundation.org>2022-01-31 11:55:27 -0700
commit6419abb80e82c603bbec6d7f5af6c2f79fa5c4ae (patch)
treec5d0b5344e3434598dbd5a9d4892eac6d58ebeaf /lib/kunit/test.c
parent95dcbc55fe4ffe262795bea02a42695c85a22dc4 (diff)
kunit: remove va_format from kunit_assert
The concern is that having a lot of redundant fields in kunit_assert can blow up stack usage if the compiler doesn't optimize them away [1]. The comment on this field implies that it was meant to be initialized when the expect/assert was declared, but this only happens when we run kunit_do_failed_assertion(). We don't need to access it outside of that function, so move it out of the struct and make it a local variable there. This change also takes the chance to reduce the number of macros by inlining the now simplified KUNIT_INIT_ASSERT_STRUCT() macro. [1] https://groups.google.com/g/kunit-dev/c/i3fZXgvBrfA/m/VULQg1z6BAAJ Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib/kunit/test.c')
-rw-r--r--lib/kunit/test.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 7dec3248562f..3bca3bf5c15b 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -241,7 +241,8 @@ static void kunit_print_string_stream(struct kunit *test,
}
static void kunit_fail(struct kunit *test, const struct kunit_loc *loc,
- enum kunit_assert_type type, struct kunit_assert *assert)
+ enum kunit_assert_type type, struct kunit_assert *assert,
+ const struct va_format *message)
{
struct string_stream *stream;
@@ -257,7 +258,7 @@ static void kunit_fail(struct kunit *test, const struct kunit_loc *loc,
}
kunit_assert_prologue(loc, type, stream);
- assert->format(assert, stream);
+ assert->format(assert, message, stream);
kunit_print_string_stream(test, stream);
@@ -284,12 +285,13 @@ void kunit_do_failed_assertion(struct kunit *test,
const char *fmt, ...)
{
va_list args;
+ struct va_format message;
va_start(args, fmt);
- assert->message.fmt = fmt;
- assert->message.va = &args;
+ message.fmt = fmt;
+ message.va = &args;
- kunit_fail(test, loc, type, assert);
+ kunit_fail(test, loc, type, assert, &message);
va_end(args);