xref: /linux/include/kunit/visibility.h (revision a4311c274e08001b129bd5ffd2a41dcbd3e0a855)
19c988faeSRae Moar /* SPDX-License-Identifier: GPL-2.0 */
29c988faeSRae Moar /*
39c988faeSRae Moar  * KUnit API to allow symbols to be conditionally visible during KUnit
49c988faeSRae Moar  * testing
59c988faeSRae Moar  *
69c988faeSRae Moar  * Copyright (C) 2022, Google LLC.
79c988faeSRae Moar  * Author: Rae Moar <rmoar@google.com>
89c988faeSRae Moar  */
99c988faeSRae Moar 
109c988faeSRae Moar #ifndef _KUNIT_VISIBILITY_H
119c988faeSRae Moar #define _KUNIT_VISIBILITY_H
129c988faeSRae Moar 
139c988faeSRae Moar #if IS_ENABLED(CONFIG_KUNIT)
149c988faeSRae Moar     /**
159c988faeSRae Moar      * VISIBLE_IF_KUNIT - A macro that sets symbols to be static if
169c988faeSRae Moar      * CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled
179c988faeSRae Moar      * there is no change to the symbol definition.
189c988faeSRae Moar      */
199c988faeSRae Moar     #define VISIBLE_IF_KUNIT
209c988faeSRae Moar     /**
219c988faeSRae Moar      * EXPORT_SYMBOL_IF_KUNIT(symbol) - Exports symbol into
229c988faeSRae Moar      * EXPORTED_FOR_KUNIT_TESTING namespace only if CONFIG_KUNIT is
239c988faeSRae Moar      * enabled. Must use MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING)
249c988faeSRae Moar      * in test file in order to use symbols.
25*a4311c27SMichal Wajdeczko      * @symbol: the symbol identifier to export
269c988faeSRae Moar      */
279c988faeSRae Moar     #define EXPORT_SYMBOL_IF_KUNIT(symbol) EXPORT_SYMBOL_NS(symbol, \
289c988faeSRae Moar 	    EXPORTED_FOR_KUNIT_TESTING)
299c988faeSRae Moar #else
309c988faeSRae Moar     #define VISIBLE_IF_KUNIT static
319c988faeSRae Moar     #define EXPORT_SYMBOL_IF_KUNIT(symbol)
329c988faeSRae Moar #endif
339c988faeSRae Moar 
349c988faeSRae Moar #endif /* _KUNIT_VISIBILITY_H */
35