KUnit has several macros and functions intended for use from non-test
code. These hooks, currently the kunit_get_current_test() and
kunit_fail_current_test() macros, didn't work when CONFIG_KUNIT=m.
In order to support this case, the required functions and static data
need to be available unconditionally, even when KUnit itself is not
built-in. The new 'hooks.c' file is therefore always included, and has
both the static key required for kunit_get_current_test(), and a table
of function pointers in struct kunit_hooks_table. This is filled in with
the real implementations by kunit_install_hooks(), which is kept in
hooks-impl.h and called when the kunit module is loaded.
This can be extended for future features which require similar
"hook" behaviour, such as static stubs, by simply adding new entries to
the struct, and the appropriate code to set them.
Fixed white-space errors during commit:
Shuah Khan <skhan@linuxfoundation.org>
Resolved merge conflicts with:
db105c37a4
("kunit: Export kunit_running()")
This patch supersedes the above.
Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Rae Moar <rmoar@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
27 lines
724 B
C
27 lines
724 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Declarations for hook implementations.
|
|
*
|
|
* These will be set as the function pointers in struct kunit_hook_table,
|
|
* found in include/kunit/test-bug.h.
|
|
*
|
|
* Copyright (C) 2023, Google LLC.
|
|
* Author: David Gow <davidgow@google.com>
|
|
*/
|
|
|
|
#ifndef _KUNIT_HOOKS_IMPL_H
|
|
#define _KUNIT_HOOKS_IMPL_H
|
|
|
|
#include <kunit/test-bug.h>
|
|
|
|
/* List of declarations. */
|
|
void __kunit_fail_current_test_impl(const char *file, int line, const char *fmt, ...);
|
|
|
|
/* Code to set all of the function pointers. */
|
|
static inline void kunit_install_hooks(void)
|
|
{
|
|
/* Install the KUnit hook functions. */
|
|
kunit_hooks.fail_current_test = __kunit_fail_current_test_impl;
|
|
}
|
|
|
|
#endif /* _KUNIT_HOOKS_IMPL_H */
|