Skip to content

RFC KUnit device API proposal

David Gow linux-kselftest lkml llvm oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2kunit: resource: Add kunit_defer() functionalityinclude/kunit/resource.h lib/kunit/resource.c+197 -03 replies
2/2kunit: Add APIs for managing devicesinclude/kunit/device.h lib/kunit/Makefile lib/kunit/device.c+94 -02 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/2] KUnit device API proposal

Hi all,

This is a follow-up to the conversation[1] about adding helpers to create a struct device for use in KUnit tests. At the moment, most tests are using root_device_register(), which doesn't quite fit, and a few are using platform_devices instead.

This adds a KUnit-specific equivalent: kunit_device_register(), which creates a device which will be automatically cleaned up on test exit (such as, for example, if an assertion fails).
It's also possible to unregister it earlier with kunit_device_unregister().

This can replace the root_device_register() users pretty comfortably, though doesn't resolve the issue with devm_ resources not being released properly as laid out in [2]. Updating the implementation here to use a 'kunit' bus should, I think, be reasonably straightforward.

The first patch in the series is an in-progress implementation of a separate new 'kunit_defer()' API, upon which this device implementation is built.

If the overall idea seems good, I'll make sure to add better tests/documentation, and patches converting existing tests to this API.

Cheers,
-- David

[1]: https://lore.kernel.org/linux-kselftest/bad670ee135391eb902bd34b8bcbe777afabc7fd.1679474247.git.mazziesaccount@gmail.com/
[2]: https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/

---
David Gow (2):
kunit: resource: Add kunit_defer() functionality
kunit: Add APIs for managing devices

 include/kunit/device.h   |  25 +++++++++
 include/kunit/resource.h |  87 +++++++++++++++++++++++++++++++
 lib/kunit/Makefile       |   1 +
 lib/kunit/device.c       |  68 ++++++++++++++++++++++++
 lib/kunit/resource.c     | 110 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 291 insertions(+)
 create mode 100644 include/kunit/device.h
 create mode 100644 lib/kunit/device.c
Signature · 1 line
2.40.0.348.gf938b09366-goog