linux/drivers/of
Stephen Boyd 6774e90f31 of: Add test managed wrappers for of_overlay_apply()/of_node_put()
Add test managed wrappers for of_overlay_apply() that automatically
removes the overlay when the test is finished. This API is intended for
use by KUnit tests that test code which relies on 'struct device_node's
and of_*() APIs.

KUnit tests will call of_overlay_apply_kunit() to load an overlay that's
been built into the kernel image. When the test is complete, the overlay
will be removed.

This has a few benefits:

 1) It keeps the tests hermetic because the overlay is removed when the
    test is complete. Tests won't even be aware that an overlay was
    loaded in another test.

 2) The overlay code can live right next to the unit test that loads it.
    The overlay and the unit test can be compiled into one kernel module
    if desired.

 3) We can test different device tree configurations by loading
    different overlays. The overlays can be written for a specific test,
    and there can be many of them loaded per-test without needing to jam
    all possible combinations into one DTB.

 4) It also allows KUnit to test device tree dependent code on any
    architecture, not just UML. This allows KUnit tests to test
    architecture specific device tree code.

There are some potential pitfalls though. Test authors need to be
careful to not overwrite properties in the live tree. The easiest way to
do this is to add and remove nodes with a 'kunit-' prefix, almost
guaranteeing that the same node won't be present in the tree loaded at
boot.

Suggested-by: Rob Herring <robh@kernel.org>
Cc: Rob Herring <robh@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Link: https://lore.kernel.org/r/20240718210513.3801024-3-sboyd@kernel.org
2024-07-29 15:33:12 -07:00
..
unittest-data of: Fix double free in of_parse_phandle_with_args_map 2024-01-09 12:54:02 -06:00
.kunitconfig of: Add KUnit test to confirm DTB is loaded 2024-03-08 12:50:39 -06:00
address.c of: Use scope based of_node_put() cleanups 2024-04-15 08:40:40 -05:00
base.c of: Use scope based kfree() cleanups 2024-04-15 08:40:40 -05:00
cpu.c of: Move CPU node related functions to their own file 2023-04-13 17:46:34 -05:00
device.c OF: Simplify of_iommu_configure() 2024-07-04 14:36:04 +01:00
dynamic.c of: dynamic: Introduce of_changeset_add_prop_bool() 2024-07-08 17:40:30 -06:00
empty_root.dts of: Create of_root if no dtb provided by firmware 2024-03-08 12:50:39 -06:00
fdt_address.c
fdt.c of/fdt: avoid re-parsing '#{address,size}-cells' in of_fdt_limit_memory 2024-05-31 08:33:54 -05:00
irq.c of/irq: Disable "interrupt-map" parsing for PASEMI Nemo 2024-07-08 15:42:20 -06:00
Kconfig of: Add KUnit test to confirm DTB is loaded 2024-03-08 12:50:39 -06:00
kexec.c arm64, crash: wrap crash dumping code into crash related ifdefs 2024-02-23 17:48:23 -08:00
kobj.c of: make of_node_ktype constant 2023-02-06 11:03:00 -06:00
Makefile of: Add test managed wrappers for of_overlay_apply()/of_node_put() 2024-07-29 15:33:12 -07:00
module.c Devicetree for v6.10: 2024-05-17 17:27:49 -07:00
of_kunit_helpers.c of: Add test managed wrappers for of_overlay_apply()/of_node_put() 2024-07-29 15:33:12 -07:00
of_numa.c of, numa: Fetch empty NUMA node ID from distance map 2021-10-04 13:13:44 -05:00
of_private.h of/irq: Factor out parsing of interrupt-map parent phandle+args from of_irq_parse_raw() 2024-05-30 19:43:19 -05:00
of_reserved_mem.c of: reserved_mem: Remove the use of phandle from the reserved_mem APIs 2024-05-03 07:49:13 -05:00
of_test.c of: of_test: add MODULE_DESCRIPTION() 2024-05-28 12:10:00 -05:00
overlay.c of: Add a helper to free property struct 2024-04-15 08:40:40 -05:00
pdt.c
platform.c of/platform: Allow overlays to create platform devices from the root node 2024-07-29 15:33:12 -07:00
property.c of: property: Fix fw_devlink handling of interrupt-map 2024-05-30 19:43:47 -05:00
resolver.c of: Use scope based kfree() cleanups 2024-04-15 08:40:40 -05:00
unittest.c of: unittest: Add a test case for of_changeset_add_prop_bool() 2024-07-08 17:40:30 -06:00