public inbox for linux-kselftest@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] kunit: Function Redirection ("static stub") support
@ 2022-12-08  6:18 David Gow
  2022-12-08  6:18 ` [PATCH 1/2] kunit: Expose 'static stub' API to redirect functions David Gow
  2022-12-08  6:18 ` [PATCH 2/2] Documentation: Add Function Redirection API docs David Gow
  0 siblings, 2 replies; 9+ messages in thread
From: David Gow @ 2022-12-08  6:18 UTC (permalink / raw)
  To: Brendan Higgins, Shuah Khan, Daniel Latypov, Kees Cook
  Cc: David Gow, Steven Rostedt, Joe Fradley, Steve Muckle,
	Jonathan Corbet, linux-kselftest, kunit-dev, linux-doc,
	linux-kernel

When writing tests, it'd often be very useful to be able to intercept
calls to a function in the code being tested and replace it with a
test-specific stub. This has always been an obviously missing piece of
KUnit, and the solutions always involve some tradeoffs with cleanliness,
performance, or impact on non-test code. See the folowing document for
some of the challenges:
https://kunit.dev/mocking.html

This series introduces a new "static_stub" feature add support for this
sort of redirection to KUnit tests.

Any function which might want to be intercepted adds a
call to a macro which checks if a test has redirected calls to it, and
calls the corresponding replacement.

Note that at alternate implementation (based on ftrace) was also
proposed in an earlier RFC:
https://lore.kernel.org/linux-kselftest/20220910212804.670622-3-davidgow@google.com/

This series only implements "static" stubbing, as it is more compatible
across different architectures, and more flexible w/r/t inlined code,
but we don't rule out offering the ftrace-based solution as well if the
demand is there in the future.

This feature was presented at LPC 2022, see:
- https://lpc.events/event/16/contributions/1308/
- https://www.youtube.com/watch?v=0Nm06EdXWsE

The KUnit 'example' test suite now includes an example of static stubs
being used, and the new 'Function Redirection' API documentation
provides a step-by-step walkthrough for using the new feature.

In addition, an (in-progress) test for the atkbd driver, which provides
an example of static stubs being used, can be found here:
https://kunit-review.googlesource.com/c/linux/+/5631

Cheers,
-- David

---
David Gow (1):
  kunit: Expose 'static stub' API to redirect functions

Sadiya Kazi (1):
  Documentation: Add Function Redirection API docs

 .../kunit/api/functionredirection.rst         | 162 ++++++++++++++++++
 Documentation/dev-tools/kunit/api/index.rst   |  13 +-
 include/kunit/static_stub.h                   | 117 +++++++++++++
 lib/kunit/Makefile                            |   1 +
 lib/kunit/kunit-example-test.c                |  38 ++++
 lib/kunit/static_stub.c                       | 123 +++++++++++++
 6 files changed, 451 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/dev-tools/kunit/api/functionredirection.rst
 create mode 100644 include/kunit/static_stub.h
 create mode 100644 lib/kunit/static_stub.c

-- 
2.39.0.rc0.267.gcb52ba06e7-goog


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

end of thread, other threads:[~2022-12-17  5:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08  6:18 [PATCH 0/2] kunit: Function Redirection ("static stub") support David Gow
2022-12-08  6:18 ` [PATCH 1/2] kunit: Expose 'static stub' API to redirect functions David Gow
2022-12-17  5:09   ` Brendan Higgins
2022-12-08  6:18 ` [PATCH 2/2] Documentation: Add Function Redirection API docs David Gow
2022-12-08 10:07   ` Bagas Sanjaya
2022-12-15 19:01     ` Daniel Latypov
2022-12-15 18:54   ` Daniel Latypov
2022-12-16  7:17     ` David Gow
2022-12-17  5:14   ` Brendan Higgins

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