public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] kunit: Deferred action helpers
@ 2023-04-21  8:42 David Gow
  2023-04-21  8:42 ` [PATCH v1 1/3] kunit: Add kunit_add_action() to defer a call until test exit David Gow
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: David Gow @ 2023-04-21  8:42 UTC (permalink / raw)
  To: Matti Vaittinen, Maxime Ripard, Brendan Higgins, Stephen Boyd,
	Shuah Khan, Daniel Latypov, Rae Moar, Benjamin Berg
  Cc: David Gow, Greg Kroah-Hartman, Rafael J . Wysocki,
	Heikki Krogerus, Jonathan Cameron, linux-kernel, linux-kselftest,
	kunit-dev

This is v1 of the KUnit deferred actions API, which implements an
equivalent of devm_add_action[1] on top of KUnit managed resources. This
provides a simple way of scheduling a function to run when the test
terminates (whether successfully, or with an error). It's therefore very
useful for freeing resources, or otherwise cleaning up.

The notable changes since RFCv2[2] are:
- Got rid of the 'cancellation token' concept. It was overcomplicated,
  and we can add it back if we need to.
- kunit_add_action() therefore now returns 0 on success, and an error
  otherwise (like devm_add_action()). Though you may wish to use:
- Added kunit_add_action_or_reset(), which will call the deferred
  function if an error occurs. (See devm_add_action_or_reset()). This
  also returns an error on failure, which can be asserted safely.
- Got rid of the function pointer typedef. Personally, I liked it, but
  it's more typedef-y than most kernel code.
- Got rid of the 'internal_gfp' argument: all internal state is now
  allocated with GFP_KERNEL. The main KUnit resource API can be used
  instead if this doesn't work for your use-case.

I'd love to hear any further thoughts!

Cheers,
-- David

[1]: https://docs.kernel.org/driver-api/basics.html#c.devm_add_action
[2]: https://patchwork.kernel.org/project/linux-kselftest/list/?series=735720


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  | 76 +++++++++++++++++++++++++++++++
 include/kunit/test.h      | 10 ++++-
 lib/kunit/executor_test.c | 11 ++---
 lib/kunit/kunit-test.c    | 88 +++++++++++++++++++++++++++++++++++-
 lib/kunit/resource.c      | 95 +++++++++++++++++++++++++++++++++++++++
 lib/kunit/test.c          | 48 ++++----------------
 6 files changed, 279 insertions(+), 49 deletions(-)

-- 
2.40.0.634.g4ca3ef3211-goog


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-04-26  7:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-21  8:42 [PATCH v1 0/3] kunit: Deferred action helpers David Gow
2023-04-21  8:42 ` [PATCH v1 1/3] kunit: Add kunit_add_action() to defer a call until test exit David Gow
2023-04-26  2:12   ` Daniel Latypov
2023-04-26  6:59     ` David Gow
2023-04-21  8:42 ` [PATCH v1 2/3] kunit: executor_test: Use kunit_add_action() David Gow
2023-04-21  8:42 ` [PATCH v1 3/3] kunit: kmalloc_array: " David Gow
2023-04-24 12:32 ` [PATCH v1 0/3] kunit: Deferred action helpers Benjamin Berg
2023-04-24 14:02   ` Benjamin Berg
2023-04-26  6:51     ` David Gow
2023-04-25 15:23 ` Maxime Ripard
2023-04-26  6:51   ` David Gow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox