summaryrefslogtreecommitdiff
path: root/lib/kunit/test.c
diff options
context:
space:
mode:
authordavidgow@google.com <davidgow@google.com>2023-12-15 15:39:08 +0800
committerShuah Khan <skhan@linuxfoundation.org>2023-12-18 13:28:08 -0700
commitd03c720e03bd9bf0b784d80b5d3ede7e2daf3b6e (patch)
tree283ce85c21b45fd4ba3782367727f85afdc6dc4a /lib/kunit/test.c
parente9f0e21ceb65ea5e450ede7c9b9a5bfc90a403ae (diff)
kunit: Add APIs for managing devices
Tests for drivers often require a struct device to pass to other functions. While it's possible to create these with root_device_register(), or to use something like a platform device, this is both a misuse of those APIs, and can be difficult to clean up after, for example, a failed assertion. Add some KUnit-specific functions for registering and unregistering a struct device: - kunit_device_register() - kunit_device_register_with_driver() - kunit_device_unregister() These helpers allocate a on a 'kunit' bus which will either probe the driver passed in (kunit_device_register_with_driver), or will create a stub driver (kunit_device_register) which is cleaned up on test shutdown. Devices are automatically unregistered on test shutdown, but can be manually unregistered earlier with kunit_device_unregister() in order to, for example, test device release code. Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Reviewed-by: Maxime Ripard <mripard@kernel.org> Signed-off-by: David Gow <davidgow@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib/kunit/test.c')
-rw-r--r--lib/kunit/test.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 088489856db8..14a77b2d702a 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -19,6 +19,7 @@
#include <linux/sched.h>
#include "debugfs.h"
+#include "device-impl.h"
#include "hooks-impl.h"
#include "string-stream.h"
#include "try-catch-impl.h"
@@ -900,6 +901,8 @@ static int __init kunit_init(void)
kunit_install_hooks();
kunit_debugfs_init();
+
+ kunit_bus_init();
#ifdef CONFIG_MODULES
return register_module_notifier(&kunit_mod_nb);
#else