Merge 0507d2526f ("Merge tag 'erofs-for-6.8-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs") into android-mainline
Steps on the way to 6.8-rc1 Change-Id: Ic5d03b4d7e56e77f9210b7ff3483a1743a9562b9 Signed-off-by: Lee Jones <joneslee@google.com>
This commit is contained in:
@@ -11,3 +11,12 @@ state on a per-test basis, register custom cleanup actions, and more.
|
||||
|
||||
.. kernel-doc:: include/kunit/resource.h
|
||||
:internal:
|
||||
|
||||
Managed Devices
|
||||
---------------
|
||||
|
||||
Functions for using KUnit-managed struct device and struct device_driver.
|
||||
Include ``kunit/device.h`` to use these.
|
||||
|
||||
.. kernel-doc:: include/kunit/device.h
|
||||
:internal:
|
||||
|
||||
@@ -49,9 +49,52 @@ loaded.
|
||||
|
||||
The results will appear in TAP format in ``dmesg``.
|
||||
|
||||
debugfs
|
||||
=======
|
||||
|
||||
KUnit can be accessed from userspace via the debugfs filesystem (See more
|
||||
information about debugfs at Documentation/filesystems/debugfs.rst).
|
||||
|
||||
If ``CONFIG_KUNIT_DEBUGFS`` is enabled, the KUnit debugfs filesystem is
|
||||
mounted at /sys/kernel/debug/kunit. You can use this filesystem to perform
|
||||
the following actions.
|
||||
|
||||
Retrieve Test Results
|
||||
=====================
|
||||
|
||||
You can use debugfs to retrieve KUnit test results. The test results are
|
||||
accessible from the debugfs filesystem in the following read-only file:
|
||||
|
||||
.. code-block :: bash
|
||||
|
||||
/sys/kernel/debug/kunit/<test_suite>/results
|
||||
|
||||
The test results are printed in a KTAP document. Note this document is separate
|
||||
to the kernel log and thus, may have different test suite numbering.
|
||||
|
||||
Run Tests After Kernel Has Booted
|
||||
=================================
|
||||
|
||||
You can use the debugfs filesystem to trigger built-in tests to run after
|
||||
boot. To run the test suite, you can use the following command to write to
|
||||
the ``/sys/kernel/debug/kunit/<test_suite>/run`` file:
|
||||
|
||||
.. code-block :: bash
|
||||
|
||||
echo "any string" > /sys/kernel/debugfs/kunit/<test_suite>/run
|
||||
|
||||
As a result, the test suite runs and the results are printed to the kernel
|
||||
log.
|
||||
|
||||
However, this feature is not available with KUnit suites that use init data,
|
||||
because init data may have been discarded after the kernel boots. KUnit
|
||||
suites that use init data should be defined using the
|
||||
kunit_test_init_section_suites() macro.
|
||||
|
||||
Also, you cannot use this feature to run tests concurrently. Instead a test
|
||||
will wait to run until other tests have completed or failed.
|
||||
|
||||
.. note ::
|
||||
|
||||
If ``CONFIG_KUNIT_DEBUGFS`` is enabled, KUnit test results will
|
||||
be accessible from the ``debugfs`` filesystem (if mounted).
|
||||
They will be in ``/sys/kernel/debug/kunit/<test_suite>/results``, in
|
||||
TAP format.
|
||||
For test authors, to use this feature, tests will need to correctly initialise
|
||||
and/or clean up any data, so the test runs correctly a second time.
|
||||
|
||||
@@ -428,3 +428,10 @@ This attribute indicates the name of the module associated with the test.
|
||||
|
||||
This attribute is automatically saved as a string and is printed for each suite.
|
||||
Tests can also be filtered using this attribute.
|
||||
|
||||
``is_init``
|
||||
|
||||
This attribute indicates whether the test uses init data or functions.
|
||||
|
||||
This attribute is automatically saved as a boolean and tests can also be
|
||||
filtered using this attribute.
|
||||
|
||||
@@ -651,12 +651,16 @@ For example:
|
||||
}
|
||||
|
||||
Note that, for functions like device_unregister which only accept a single
|
||||
pointer-sized argument, it's possible to directly cast that function to
|
||||
a ``kunit_action_t`` rather than writing a wrapper function, for example:
|
||||
pointer-sized argument, it's possible to automatically generate a wrapper
|
||||
with the ``KUNIT_DEFINE_ACTION_WRAPPER()`` macro, for example:
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
kunit_add_action(test, (kunit_action_t *)&device_unregister, &dev);
|
||||
KUNIT_DEFINE_ACTION_WRAPPER(device_unregister, device_unregister_wrapper, struct device *);
|
||||
kunit_add_action(test, &device_unregister_wrapper, &dev);
|
||||
|
||||
You should do this in preference to manually casting to the ``kunit_action_t`` type,
|
||||
as casting function pointers will break Control Flow Integrity (CFI).
|
||||
|
||||
``kunit_add_action`` can fail if, for example, the system is out of memory.
|
||||
You can use ``kunit_add_action_or_reset`` instead which runs the action
|
||||
@@ -793,3 +797,53 @@ structures as shown below:
|
||||
KUnit is not enabled, or if no test is running in the current task, it will do
|
||||
nothing. This compiles down to either a no-op or a static key check, so will
|
||||
have a negligible performance impact when no test is running.
|
||||
|
||||
Managing Fake Devices and Drivers
|
||||
---------------------------------
|
||||
|
||||
When testing drivers or code which interacts with drivers, many functions will
|
||||
require a ``struct device`` or ``struct device_driver``. In many cases, setting
|
||||
up a real device is not required to test any given function, so a fake device
|
||||
can be used instead.
|
||||
|
||||
KUnit provides helper functions to create and manage these fake devices, which
|
||||
are internally of type ``struct kunit_device``, and are attached to a special
|
||||
``kunit_bus``. These devices support managed device resources (devres), as
|
||||
described in Documentation/driver-api/driver-model/devres.rst
|
||||
|
||||
To create a KUnit-managed ``struct device_driver``, use ``kunit_driver_create()``,
|
||||
which will create a driver with the given name, on the ``kunit_bus``. This driver
|
||||
will automatically be destroyed when the corresponding test finishes, but can also
|
||||
be manually destroyed with ``driver_unregister()``.
|
||||
|
||||
To create a fake device, use the ``kunit_device_register()``, which will create
|
||||
and register a device, using a new KUnit-managed driver created with ``kunit_driver_create()``.
|
||||
To provide a specific, non-KUnit-managed driver, use ``kunit_device_register_with_driver()``
|
||||
instead. Like with managed drivers, KUnit-managed fake devices are automatically
|
||||
cleaned up when the test finishes, but can be manually cleaned up early with
|
||||
``kunit_device_unregister()``.
|
||||
|
||||
The KUnit devices should be used in preference to ``root_device_register()``, and
|
||||
instead of ``platform_device_register()`` in cases where the device is not otherwise
|
||||
a platform device.
|
||||
|
||||
For example:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#include <kunit/device.h>
|
||||
|
||||
static void test_my_device(struct kunit *test)
|
||||
{
|
||||
struct device *fake_device;
|
||||
const char *dev_managed_string;
|
||||
|
||||
// Create a fake device.
|
||||
fake_device = kunit_device_register(test, "my_device");
|
||||
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fake_device)
|
||||
|
||||
// Pass it to functions which need a device.
|
||||
dev_managed_string = devm_kstrdup(fake_device, "Hello, World!");
|
||||
|
||||
// Everything is cleaned up automatically when the test ends.
|
||||
}
|
||||
Reference in New Issue
Block a user