of_overlay_apply_kunit(9)
π of_overlay_apply_kunit(9) π
okay so bestie, welcome to the Kernel API Manual β¨ β this one's a lil macro called of_overlay_apply_kunit, and it's genuinely iconic once you get what it's doing. let's get into it π«Ά
πΈ NAME πΈ
of_overlay_apply_kunit β it tests the managed of_overlay_fdt_apply() for built-in overlays π no cap, that's the whole job.
π¦ SYNOPSIS π¦
of_overlay_apply_kunit (test , overlay_name );
yep, that's it. two args, one macro, zero drama β¨
π ARGUMENTS π
testβ the test context, obvi. it's your KUnit test struct, the main character of the function πΈoverlay_nameβ the name of the overlay you wanna apply. literally just the name, we'll get to the wholedtbothing in a sec π§
β DESCRIPTION β
so this macro applies a device tree overlay. the overlay has to be built with the cmd_dt_S_dtbo rule in scripts/Makefile.lib, and it has to be compiled into the kernel image or into the KUnit test module. then β and this is the slay part β the overlay gets automatically removed when the test is finished π
the cleanup is handled for you, you don't have to think about it.
if your unit test needs device tree nodes, here's the vibe: compile an overlay file as overlay_name.dtbo.o in your Makefile right alongside your unit test, then load that overlay during the test. the overlay_name matches the filename of the overlay, minus the dtbo filename extension. easy β¨
π important vibe check: if CONFIG_OF_OVERLAY is not enabled, the test will be skipped. like, it just won't run. so don't come crying to me when nothing happens, check your config first bestie π
in the Makefile π
obj-$(CONFIG_OF_OVERLAY_KUNIT_TEST) += overlay_test.o kunit_overlay_test.dtbo.o
in the test π
static void of_overlay_kunit_of_overlay_apply(struct kunit *test)
{
struct device_node *np;
KUNIT_ASSERT_EQ(test, 0,
of_overlay_apply_kunit(test, kunit_overlay_test));
np = of_find_node_by_name(NULL, "test-kunit");
KUNIT_EXPECT_NOT_ERR_OR_NULL(test, np);
of_node_put(np);
}
see how kunit_overlay_test is the overlay name and it lines up with kunit_overlay_test.dtbo.o in the Makefile? that's the whole bit π₯ also peep the of_node_put(np) at the end β put your nodes back, don't leak, that's just manners π«Ά
π RETURN π
0on success β we love a clean win π- negative
errnoon failure β not the vibe, but at least you know π
π¦ SEE ALSO π¦
- Kernel file
./include/kunit/of.h __of_overlay_apply_kunit(9)β the lowercase-undercover version of this whole thing, go read it iykyk π
and that's the page babes β¨ this lil gem lives under ./include/kunit and the manual's dated October 2026 π
β so if you're reading this in the future, hi, hope the overlay applied cleanly πππ¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms