kunit: factor out kunit_base_assert_format() call into kunit_fail()
We call this function first thing for all the assertion `format()` functions. This is the part that prints the file and line number and assertion type (EXPECTATION, ASSERTION). Having it as part of the format functions lets us have the flexibility to not print that information (or print it differently) for new assertion types, but I think this we don't need that. And in the future, we'd like to consider factoring that data (file, line#, type) out of the kunit_assert struct and into a `static` variable, as Linus suggested [1], so we'd need to extract it anyways. [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>
This commit is contained in:
parent
a91e9ade40
commit
dd640d7087
|
@ -40,7 +40,6 @@ EXPORT_SYMBOL_GPL(kunit_assert_print_msg);
|
||||||
void kunit_fail_assert_format(const struct kunit_assert *assert,
|
void kunit_fail_assert_format(const struct kunit_assert *assert,
|
||||||
struct string_stream *stream)
|
struct string_stream *stream)
|
||||||
{
|
{
|
||||||
kunit_base_assert_format(assert, stream);
|
|
||||||
string_stream_add(stream, "%pV", &assert->message);
|
string_stream_add(stream, "%pV", &assert->message);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(kunit_fail_assert_format);
|
EXPORT_SYMBOL_GPL(kunit_fail_assert_format);
|
||||||
|
@ -52,7 +51,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,
|
||||||
|
|
||||||
unary_assert = container_of(assert, struct kunit_unary_assert, assert);
|
unary_assert = container_of(assert, struct kunit_unary_assert, assert);
|
||||||
|
|
||||||
kunit_base_assert_format(assert, stream);
|
|
||||||
if (unary_assert->expected_true)
|
if (unary_assert->expected_true)
|
||||||
string_stream_add(stream,
|
string_stream_add(stream,
|
||||||
KUNIT_SUBTEST_INDENT "Expected %s to be true, but is false\n",
|
KUNIT_SUBTEST_INDENT "Expected %s to be true, but is false\n",
|
||||||
|
@ -73,7 +71,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
|
||||||
ptr_assert = container_of(assert, struct kunit_ptr_not_err_assert,
|
ptr_assert = container_of(assert, struct kunit_ptr_not_err_assert,
|
||||||
assert);
|
assert);
|
||||||
|
|
||||||
kunit_base_assert_format(assert, stream);
|
|
||||||
if (!ptr_assert->value) {
|
if (!ptr_assert->value) {
|
||||||
string_stream_add(stream,
|
string_stream_add(stream,
|
||||||
KUNIT_SUBTEST_INDENT "Expected %s is not null, but is\n",
|
KUNIT_SUBTEST_INDENT "Expected %s is not null, but is\n",
|
||||||
|
@ -119,7 +116,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
|
||||||
binary_assert = container_of(assert, struct kunit_binary_assert,
|
binary_assert = container_of(assert, struct kunit_binary_assert,
|
||||||
assert);
|
assert);
|
||||||
|
|
||||||
kunit_base_assert_format(assert, stream);
|
|
||||||
string_stream_add(stream,
|
string_stream_add(stream,
|
||||||
KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n",
|
KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n",
|
||||||
binary_assert->left_text,
|
binary_assert->left_text,
|
||||||
|
@ -147,7 +143,6 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
|
||||||
binary_assert = container_of(assert, struct kunit_binary_ptr_assert,
|
binary_assert = container_of(assert, struct kunit_binary_ptr_assert,
|
||||||
assert);
|
assert);
|
||||||
|
|
||||||
kunit_base_assert_format(assert, stream);
|
|
||||||
string_stream_add(stream,
|
string_stream_add(stream,
|
||||||
KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n",
|
KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n",
|
||||||
binary_assert->left_text,
|
binary_assert->left_text,
|
||||||
|
@ -187,7 +182,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
|
||||||
binary_assert = container_of(assert, struct kunit_binary_str_assert,
|
binary_assert = container_of(assert, struct kunit_binary_str_assert,
|
||||||
assert);
|
assert);
|
||||||
|
|
||||||
kunit_base_assert_format(assert, stream);
|
|
||||||
string_stream_add(stream,
|
string_stream_add(stream,
|
||||||
KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n",
|
KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n",
|
||||||
binary_assert->left_text,
|
binary_assert->left_text,
|
||||||
|
|
|
@ -255,6 +255,7 @@ static void kunit_fail(struct kunit *test, struct kunit_assert *assert)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kunit_base_assert_format(assert, stream);
|
||||||
assert->format(assert, stream);
|
assert->format(assert, stream);
|
||||||
|
|
||||||
kunit_print_string_stream(test, stream);
|
kunit_print_string_stream(test, stream);
|
||||||
|
|
Loading…
Reference in New Issue