Skip to content

RFC kunit: Deferred action helpers

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. v2 RFC Latest3 patches 13 repliesIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3kunit: Add kunit_add_action() to defer a call until test exitinclude/kunit/resource.h lib/kunit/kunit-test.c lib/kunit/resource.c+310 -111 replies
2/3kunit: executor_test: Use kunit_add_action()lib/kunit/executor_test.c+5 -70 replies
3/3kunit: kmalloc_array: Use kunit_add_action()lib/kunit/test.c+8 -402 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [RFC PATCH v2 0/3] kunit: Deferred action helpers

This is a follow-up to the kunit_defer() parts of 'KUnit device API proposal'[1], with a number of changes suggested by Matti Vaittinen, Maxime Ripard and Benjamin Berg.

Most notably, kunit_defer() has been renamed to kunit_add_action(), in order to match the equivalent devres API[2]. Likewise:
kunit_defer_cancel() has become kunit_remove_action(), and kunit_defer_trigger() has become kunit_release_action().

The _token() versions of these APIs remain, for the moment, even though they're a bit more awkward and less useful, as they have two advantages:
1. They're faster, as the action doesn't need to be looked up.
2. They provide more flexibility in the ordering of actions in cases where several identical actions are interleaved with other, different actions.

Similarly, the internal_gfp argument remains for now, as this is useful in implementing kunit_kalloc() and similar.

The implementation now uses a single allocation for both the kunit_resource and the kunit_action_ctx (previously kunit_defer_ctx).

The 'cancellation token' is now of type 'struct kunit_action_ctx', instead of void*.

Tests have been added to the kunit-resource-test suite which exercise this functionality. Similarly, the kunit executor tests and kunit allocation functions have been updated to make use of this API.

I'd love to hear any further thoughts!

Cheers,
-- David

[1]: https://lore.kernel.org/linux-kselftest/[email protected]/
[2]: https://docs.kernel.org/driver-api/basics.html#c.devm_add_action

David Gow (3):
kunit: Add kunit_add_action() to defer a call until test exit
kunit: executor_test: Use kunit_add_action()
kunit: kmalloc_array: Use kunit_add_action()

 include/kunit/resource.h  |  89 +++++++++++++++++++++++++++
 lib/kunit/executor_test.c |  12 ++--
 lib/kunit/kunit-test.c    | 123 +++++++++++++++++++++++++++++++++++++-
 lib/kunit/resource.c      |  99 ++++++++++++++++++++++++++++++
 lib/kunit/test.c          |  48 +++------------
 5 files changed, 323 insertions(+), 48 deletions(-)
Signature · 1 line
2.40.0.348.gf938b09366-goog