xref: /linux/include/kunit/visibility.h (revision 9c988fae6f6ae3224a568ab985881b66bb50c9ec)
1*9c988faeSRae Moar /* SPDX-License-Identifier: GPL-2.0 */
2*9c988faeSRae Moar /*
3*9c988faeSRae Moar  * KUnit API to allow symbols to be conditionally visible during KUnit
4*9c988faeSRae Moar  * testing
5*9c988faeSRae Moar  *
6*9c988faeSRae Moar  * Copyright (C) 2022, Google LLC.
7*9c988faeSRae Moar  * Author: Rae Moar <rmoar@google.com>
8*9c988faeSRae Moar  */
9*9c988faeSRae Moar 
10*9c988faeSRae Moar #ifndef _KUNIT_VISIBILITY_H
11*9c988faeSRae Moar #define _KUNIT_VISIBILITY_H
12*9c988faeSRae Moar 
13*9c988faeSRae Moar #if IS_ENABLED(CONFIG_KUNIT)
14*9c988faeSRae Moar     /**
15*9c988faeSRae Moar      * VISIBLE_IF_KUNIT - A macro that sets symbols to be static if
16*9c988faeSRae Moar      * CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled
17*9c988faeSRae Moar      * there is no change to the symbol definition.
18*9c988faeSRae Moar      */
19*9c988faeSRae Moar     #define VISIBLE_IF_KUNIT
20*9c988faeSRae Moar     /**
21*9c988faeSRae Moar      * EXPORT_SYMBOL_IF_KUNIT(symbol) - Exports symbol into
22*9c988faeSRae Moar      * EXPORTED_FOR_KUNIT_TESTING namespace only if CONFIG_KUNIT is
23*9c988faeSRae Moar      * enabled. Must use MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING)
24*9c988faeSRae Moar      * in test file in order to use symbols.
25*9c988faeSRae Moar      */
26*9c988faeSRae Moar     #define EXPORT_SYMBOL_IF_KUNIT(symbol) EXPORT_SYMBOL_NS(symbol, \
27*9c988faeSRae Moar 	    EXPORTED_FOR_KUNIT_TESTING)
28*9c988faeSRae Moar #else
29*9c988faeSRae Moar     #define VISIBLE_IF_KUNIT static
30*9c988faeSRae Moar     #define EXPORT_SYMBOL_IF_KUNIT(symbol)
31*9c988faeSRae Moar #endif
32*9c988faeSRae Moar 
33*9c988faeSRae Moar #endif /* _KUNIT_VISIBILITY_H */
34