Skip to content

Commit 1a9f2c7

Browse files
Grillo-0shuahkh
authored andcommitted
Documentation: KUnit: Update the instructions on how to test static functions
Now that we have the VISIBLE_IF_KUNIT and EXPORT_SYMBOL_IF_KUNIT macros, update the instructions to recommend this way of testing static functions. Signed-off-by: Arthur Grillo <[email protected]> Reviewed-by: David Gow <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent a1af6a2 commit 1a9f2c7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Documentation/dev-tools/kunit/usage.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,23 @@ Testing Static Functions
671671
------------------------
672672

673673
If we do not want to expose functions or variables for testing, one option is to
674-
conditionally ``#include`` the test file at the end of your .c file. For
675-
example:
674+
conditionally export the used symbol. For example:
675+
676+
.. code-block:: c
677+
678+
/* In my_file.c */
679+
680+
VISIBLE_IF_KUNIT int do_interesting_thing();
681+
EXPORT_SYMBOL_IF_KUNIT(do_interesting_thing);
682+
683+
/* In my_file.h */
684+
685+
#if IS_ENABLED(CONFIG_KUNIT)
686+
int do_interesting_thing(void);
687+
#endif
688+
689+
Alternatively, you could conditionally ``#include`` the test file at the end of
690+
your .c file. For example:
676691

677692
.. code-block:: c
678693

0 commit comments

Comments
 (0)