* [PATCH v3] Documentation: KUnit: Update the instructions on how to test static functions
@ 2024-01-10 17:39 Arthur Grillo
2024-01-12 4:34 ` David Gow
0 siblings, 1 reply; 2+ messages in thread
From: Arthur Grillo @ 2024-01-10 17:39 UTC (permalink / raw)
To: Brendan Higgins, David Gow, Jonathan Corbet
Cc: linux-kselftest, kunit-dev, linux-doc, linux-kernel,
Arthur Grillo
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 <arthurgrillo@riseup.net>
---
Changes in v3:
- Maintain the old '#include' way
- Link to v2: https://lore.kernel.org/r/20240108-kunit-doc-export-v2-1-8f2dd3395fed@riseup.net
Changes in v2:
- Fix #if condition
- Link to v1: https://lore.kernel.org/r/20240108-kunit-doc-export-v1-1-119368df0d96@riseup.net
---
Documentation/dev-tools/kunit/usage.rst | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
index c27e1646ecd9..8e35b94a17ec 100644
--- a/Documentation/dev-tools/kunit/usage.rst
+++ b/Documentation/dev-tools/kunit/usage.rst
@@ -671,8 +671,23 @@ Testing Static Functions
------------------------
If we do not want to expose functions or variables for testing, one option is to
-conditionally ``#include`` the test file at the end of your .c file. For
-example:
+conditionally export the used symbol. For example:
+
+.. code-block:: c
+
+ /* In my_file.c */
+
+ VISIBLE_IF_KUNIT int do_interesting_thing();
+ EXPORT_SYMBOL_IF_KUNIT(do_interesting_thing);
+
+ /* In my_file.h */
+
+ #if IS_ENABLED(CONFIG_KUNIT)
+ int do_interesting_thing(void);
+ #endif
+
+Alternatively, you could conditionally ``#include`` the test file at the end of
+your .c file. For example:
.. code-block:: c
---
base-commit: eeb8e8d9f124f279e80ae679f4ba6e822ce4f95f
change-id: 20240108-kunit-doc-export-eec1f910ab67
Best regards,
--
Arthur Grillo <arthurgrillo@riseup.net>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] Documentation: KUnit: Update the instructions on how to test static functions
2024-01-10 17:39 [PATCH v3] Documentation: KUnit: Update the instructions on how to test static functions Arthur Grillo
@ 2024-01-12 4:34 ` David Gow
0 siblings, 0 replies; 2+ messages in thread
From: David Gow @ 2024-01-12 4:34 UTC (permalink / raw)
To: Arthur Grillo
Cc: Brendan Higgins, Jonathan Corbet, linux-kselftest, kunit-dev,
linux-doc, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 822 bytes --]
On Thu, 11 Jan 2024 at 01:39, Arthur Grillo <arthurgrillo@riseup.net> wrote:
>
> 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 <arthurgrillo@riseup.net>
> ---
> Changes in v3:
> - Maintain the old '#include' way
> - Link to v2: https://lore.kernel.org/r/20240108-kunit-doc-export-v2-1-8f2dd3395fed@riseup.net
>
> Changes in v2:
> - Fix #if condition
> - Link to v1: https://lore.kernel.org/r/20240108-kunit-doc-export-v1-1-119368df0d96@riseup.net
> ---
This looks good, thanks!
Reviewed-by: David Gow <davidgow@google.com>
We may try to add some more reference documentation for the
visibility.h header later on, but this example is probably more useful
anyway.
Cheers,
-- David
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4014 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-12 4:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-10 17:39 [PATCH v3] Documentation: KUnit: Update the instructions on how to test static functions Arthur Grillo
2024-01-12 4:34 ` David Gow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).