2020-01-07 06:28:22 +08:00
|
|
|
obj-$(CONFIG_KUNIT) += kunit.o
|
|
|
|
|
|
|
|
kunit-objs += test.o \
|
2022-03-29 01:41:43 +08:00
|
|
|
resource.o \
|
2024-06-13 03:59:18 +08:00
|
|
|
user_alloc.o \
|
kunit: Expose 'static stub' API to redirect functions
Add a simple way of redirecting calls to functions by including a
special prologue in the "real" function which checks to see if the
replacement function should be called (and, if so, calls it).
To redirect calls to a function, make the first (non-declaration) line
of the function:
KUNIT_STATIC_STUB_REDIRECT(function_name, [function arguments]);
(This will compile away to nothing if KUnit is not enabled, otherwise it
will check if a redirection is active, call the replacement function,
and return. This check is protected by a static branch, so has very
little overhead when there are no KUnit tests running.)
Calls to the real function can be redirected to a replacement using:
kunit_activate_static_stub(test, real_fn, replacement_fn);
The redirection will only affect calls made from within the kthread of
the current test, and will be automatically disabled when the test
completes. It can also be manually disabled with
kunit_deactivate_static_stub().
The 'example' KUnit test suite has a more complete example.
Co-developed-by: Daniel Latypov <dlatypov@google.com>
Signed-off-by: Daniel Latypov <dlatypov@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2023-01-31 14:46:40 +08:00
|
|
|
static_stub.o \
|
2019-09-23 17:02:34 +08:00
|
|
|
string-stream.o \
|
2019-09-23 17:02:39 +08:00
|
|
|
assert.o \
|
2020-08-05 04:47:42 +08:00
|
|
|
try-catch.o \
|
2023-07-26 05:25:12 +08:00
|
|
|
executor.o \
|
2023-12-15 15:39:08 +08:00
|
|
|
attributes.o \
|
2024-07-19 05:05:04 +08:00
|
|
|
device.o \
|
|
|
|
platform.o
|
2019-09-23 17:02:37 +08:00
|
|
|
|
2020-03-26 22:25:07 +08:00
|
|
|
ifeq ($(CONFIG_KUNIT_DEBUGFS),y)
|
|
|
|
kunit-objs += debugfs.o
|
|
|
|
endif
|
|
|
|
|
kunit: Add "hooks" to call into KUnit when it's built as a module
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:
db105c37a4d6 ("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>
2023-01-28 15:10:07 +08:00
|
|
|
# KUnit 'hooks' are built-in even when KUnit is built as a module.
|
2023-02-25 09:45:30 +08:00
|
|
|
obj-y += hooks.o
|
kunit: Add "hooks" to call into KUnit when it's built as a module
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:
db105c37a4d6 ("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>
2023-01-28 15:10:07 +08:00
|
|
|
|
2020-01-07 06:28:20 +08:00
|
|
|
obj-$(CONFIG_KUNIT_TEST) += kunit-test.o
|
2024-07-19 05:05:04 +08:00
|
|
|
obj-$(CONFIG_KUNIT_TEST) += platform-test.o
|
2019-09-23 17:02:37 +08:00
|
|
|
|
2020-01-07 06:28:20 +08:00
|
|
|
# string-stream-test compiles built-in only.
|
|
|
|
ifeq ($(CONFIG_KUNIT_TEST),y)
|
|
|
|
obj-$(CONFIG_KUNIT_TEST) += string-stream-test.o
|
2024-05-17 05:17:31 +08:00
|
|
|
obj-$(CONFIG_KUNIT_TEST) += assert_test.o
|
2020-01-07 06:28:20 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += kunit-example-test.o
|