Centos-kernel-stream-9/lib/kunit/device-impl.h

20 lines
484 B
C
Raw Normal View History

kunit: Add APIs for managing devices JIRA: https://issues.redhat.com/browse/RHEL-24101 Upstream Status: v6.8-rc1 Conflicts: lib/kunit/kunit-test.c commit d03c720e03bd9bf0b784d80b5d3ede7e2daf3b6e Author: davidgow@google.com <davidgow@google.com> AuthorDate: Fri Dec 15 15:39:08 2023 +0800 Commit: Shuah Khan <skhan@linuxfoundation.org> CommitDate: Mon Dec 18 13:28:08 2023 -0700 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> Signed-off-by: Dave Airlie <airlied@redhat.com>
2024-04-03 06:55:03 +00:00
/* SPDX-License-Identifier: GPL-2.0 */
/*
* KUnit internal header for device helpers
*
* Header for KUnit-internal driver / bus management.
*
* Copyright (C) 2023, Google LLC.
* Author: David Gow <davidgow@google.com>
*/
#ifndef _KUNIT_DEVICE_IMPL_H
#define _KUNIT_DEVICE_IMPL_H
// For internal use only -- registers the kunit_bus.
int kunit_bus_init(void);
// For internal use only -- unregisters the kunit_bus.
void kunit_bus_shutdown(void);
kunit: Add APIs for managing devices JIRA: https://issues.redhat.com/browse/RHEL-24101 Upstream Status: v6.8-rc1 Conflicts: lib/kunit/kunit-test.c commit d03c720e03bd9bf0b784d80b5d3ede7e2daf3b6e Author: davidgow@google.com <davidgow@google.com> AuthorDate: Fri Dec 15 15:39:08 2023 +0800 Commit: Shuah Khan <skhan@linuxfoundation.org> CommitDate: Mon Dec 18 13:28:08 2023 -0700 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> Signed-off-by: Dave Airlie <airlied@redhat.com>
2024-04-03 06:55:03 +00:00
#endif //_KUNIT_DEVICE_IMPL_H