]> www.infradead.org Git - users/dwmw2/linux.git/commit
kunit: Cover 'assert.c' with tests
authorIvan Orlov <ivan.orlov0322@gmail.com>
Thu, 16 May 2024 21:17:31 +0000 (22:17 +0100)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 30 May 2024 18:53:47 +0000 (12:53 -0600)
commit2c7afc2a880cd4899f9dd6bfa62f10f84773148b
tree78c90ba817d7d386ea759d91007107bded7bf845
parent1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
kunit: Cover 'assert.c' with tests

There are multiple assertion formatting functions in the `assert.c`
file, which are not covered with tests yet. Implement the KUnit test
for these functions.

The test consists of 11 test cases for the following functions:

1) 'is_literal'
2) 'is_str_literal'
3) 'kunit_assert_prologue', test case for multiple assert types
4) 'kunit_assert_print_msg'
5) 'kunit_unary_assert_format'
6) 'kunit_ptr_not_err_assert_format'
7) 'kunit_binary_assert_format'
8) 'kunit_binary_ptr_assert_format'
9) 'kunit_binary_str_assert_format'
10) 'kunit_assert_hexdump'
11) 'kunit_mem_assert_format'

The test aims at maximizing the branch coverage for the assertion
formatting functions.

As you can see, it covers some of the static helper functions as
well, so mark the static functions in `assert.c` as 'VISIBLE_IF_KUNIT'
and conditionally export them with EXPORT_SYMBOL_IF_KUNIT. Add the
corresponding definitions to `assert.h`.

Build the assert test when CONFIG_KUNIT_TEST is enabled, similar to
how it is done for the string stream test.

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Reviewed-by: Rae Moar <rmoar@google.com>
Acked-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
include/kunit/assert.h
lib/kunit/Makefile
lib/kunit/assert.c
lib/kunit/assert_test.c [new file with mode: 0644]