kunit: Add helpers for creating test-managed devices
Get series with b4
b4 am [email protected] change-id 20230718-kunit_bus-ab19c4ef48dcVersions newest first
- v4 Latest5 patches 2 repliesIn review
- v35 patches 2 repliesSuperseded
- v24 patches 3 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 4 patches | 13 replies | Superseded |
Changes in v4 from the cover letter
- Update tags, fix a missing Signed-off-by.
- Link to v3: https://lore.kernel.org/r/[email protected]
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | kunit: Add APIs for managing devicesDocumentation/ Documentation/ include/ +5 more | +475 | 1 reply | |
| 2/5 | fortify: test: Use kunit_devicelib/ | +3 | 0 replies | |
| 3/5 | overflow: Replace fake root_device with kunit_devicelib/ | +2 | 0 replies | |
| 4/5 | ASoC: topology: Replace fake root_device with kunit_device in testssound/ | +2 | 0 replies | |
| 5/5 | drm/tests: Switch to kunit devicesdrivers/ | +3 | 1 reply |
Reviews trailers per patch
All 5 patches have a Reviewed-by or Acked-by.
| Patch | Matti Vaittinen | Maxime Ripard | Kees Cook | Mark Brown | David Gow | Greg Kroah-Hartman | Rae Moar |
|---|---|---|---|---|---|---|---|
| 1/5 | R-b | R-b | R-b | ||||
| 2/5 | R-b | A-b | |||||
| 3/5 | R-b | A-b | |||||
| 4/5 | A-b | ||||||
| 5/5 | T-b | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 7 reviewers.
Cover letter [PATCH v4 0/5] kunit: Add helpers for creating test-managed devices
KUnit tests often need to provide a struct device, and thus far have mostly been using root_device_register() or platform devices to create a 'fake device' for use with, e.g., code which uses device-managed resources. This has several disadvantages, including not being designed for test use, scattering files in sysfs, and requiring manual teardown on test exit, which may not always be possible in case of failure.
Instead, introduce a set of helper functions which allow devices (internally a struct kunit_device) to be created and managed by KUnit -- i.e., they will be automatically unregistered on test exit. These helpers can either use a user-provided struct device_driver, or have one automatically created and managed by KUnit. In both cases, the device lives on a new kunit_bus.
This is a follow-up to a previous proposal here:
https://lore.kernel.org/linux-kselftest/[email protected]/
(The kunit_defer() function in the first patch there has since been merged as the 'deferred actions' feature.)
My intention is to take this whole series in via the kselftest/kunit branch, but I'm equally okay with splitting up the later patches which use this to go via the various subsystem trees in case there are merge conflicts.
Cheers,
-- David
---
Changes in v4:
- Update tags, fix a missing Signed-off-by.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Port the DRM tests to these new helpers (Thanks, Maxime!)
- Include the lib/kunit/device-impl.h file, which was missing from the previous revision.
- Fix a use-after-free bug in kunit_device_driver_test, which resulted
in memory corruption on some clang-built UML builds.
- The 'test_state' is now allocated with kunit_kzalloc(), not on the stack, as the stack will be gone when cleanup occurs.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Simplify device/driver/bus matching, removing the no-longer-required kunit_bus_match function. (Thanks, Greg)
- The return values are both more consistent (kunit_device_register now returns an explicit error pointer, rather than failing the test), and better documented.
- Add some basic documentation to the implementations as well as the headers. The documentation in the headers is still more complete, and is now properly compiled into the HTML documentation (under dev-tools/kunit/api/resources.html). (Thanks, Matti)
- Moved the internal-only kunit_bus_init() function to a private header, lib/kunit/device-impl.h to avoid polluting the public headers, and match other internal-only headers. (Thanks, Greg)
- Alphabetise KUnit includes in other test modules. (Thanks, Amadeusz.)
- Several code cleanups, particularly around error handling and allocation. (Thanks Greg, Maxime)
- Several const-correctness and casting improvements. (Thanks, Greg)
- Added a new test to verify KUnit cleanup triggers device cleanup. (Thanks, Maxime).
- Improved the user-specified device test to verify that probe/remove hooks are called correctly. (Thanks, Maxime).
- The overflow test no-longer needlessly calls
kunit_device_unregister().
- Several other minor cleanups and documentation improvements, which hopefully make this a bit clearer and more robust.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
David Gow (4):
kunit: Add APIs for managing devices
fortify: test: Use kunit_device
overflow: Replace fake root_device with kunit_device
ASoC: topology: Replace fake root_device with kunit_device in tests
Maxime Ripard (1):
drm/tests: Switch to kunit devices
Documentation/dev-tools/kunit/api/resource.rst | 9 ++ Documentation/dev-tools/kunit/usage.rst | 50 +++++++ drivers/gpu/drm/tests/drm_kunit_helpers.c | 66 +-------- include/kunit/device.h | 80 +++++++++++ lib/fortify_kunit.c | 5 +- lib/kunit/Makefile | 3 +- lib/kunit/device-impl.h | 17 +++ lib/kunit/device.c | 181 +++++++++++++++++++++++++ lib/kunit/kunit-test.c | 134 +++++++++++++++++- lib/kunit/test.c | 3 + lib/overflow_kunit.c | 5 +- sound/soc/soc-topology-test.c | 10 +- 12 files changed, 485 insertions(+), 78 deletions(-)
---
base-commit: b285ba6f8cc1b2bfece0b4350fdb92c8780bc698
change-id: 20230718-kunit_bus-ab19c4ef48dc
Best regards,
Signature · 1 line
David Gow <[email protected]>