of_overlay_apply_kunit(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 whole dtbo thing 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 πŸ‘‘

  • 0 on success β€” we love a clean win πŸ’–
  • negative errno on 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