From: Stefan Kerkmann <s.kerkmann@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
"open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Subject: [PATCH v2 5/5] tests: of_overlay: add fragment application tests
Date: Mon, 19 Oct 2026 12:05:48 +0200 [thread overview]
Message-ID: <20261019-fix-overlay-v2-5-24e9ff1c0e12@pengutronix.de> (raw)
In-Reply-To: <20261019-fix-overlay-v2-0-24e9ff1c0e12@pengutronix.de>
These tests exercise the application of the overlay fragments by
of_overlay_apply_fragment() with the following test cases:
1. Fragment target is found by target-path and phandle
2. Fragment properties are merged into existing nodes
3. Fragment children without an __overlay__ node are skipped
4. Error path for a fragment whose target does not exist
Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
test/self/Makefile | 1 +
test/self/of_overlay.c | 68 ++++++++++++++++++++++++++++++++
test/self/of_overlay.dtso | 34 ++++++++++++++++
test/self/of_overlay_missing_target.dtso | 24 +++++++++++
4 files changed, 127 insertions(+)
diff --git a/test/self/Makefile b/test/self/Makefile
index f6cec81011..0fba7ac566 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay.o
# Enforce generation of __symbols__ table for overlay tests
DTC_FLAGS_of_overlay_with_symbols := -@
obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay_with_symbols.dtb.o of_overlay_with_symbols.dtbo.o
+obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay.dtbo.o of_overlay_missing_target.dtbo.o
obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o
obj-$(CONFIG_SELFTEST_DIRFD) += dirfd.o
diff --git a/test/self/of_overlay.c b/test/self/of_overlay.c
index 2804c936c0..4c17cae16d 100644
--- a/test/self/of_overlay.c
+++ b/test/self/of_overlay.c
@@ -98,9 +98,77 @@ static void test_of_overlay_symbol_outside_overlay(void)
of_delete_node(root);
}
+extern char __dtbo_of_overlay_start[], __dtbo_of_overlay_end[];
+
+static void test_of_overlay_fragments(void)
+{
+ struct device_node *root, *overlay, *node;
+ int ret;
+
+ if (!test_setup(&root, &overlay, __dtb_of_overlay_with_symbols_start,
+ __dtb_of_overlay_with_symbols_end,
+ __dtbo_of_overlay_start, __dtbo_of_overlay_end))
+ return;
+
+ ret = of_overlay_apply_tree(root, overlay);
+ assert_inteq(ret, 0);
+
+ node = of_find_node_by_path_from(root, "/target-node");
+ assert_cond(node != NULL);
+ assert_inteq(of_property_match_string(node, "new-prop", "target-path"),
+ 0);
+ assert_cond(of_get_child_by_name(node, "added-child") != NULL);
+
+ node = of_find_node_by_path_from(root, "/target-node/existing-child");
+ assert_cond(node != NULL);
+ assert_inteq(of_property_match_string(node, "old-prop", "old"), 0);
+ assert_inteq(of_property_match_string(node, "new-prop", "merged"), 0);
+
+ node = of_find_node_by_path_from(root, "/phandle-target-node");
+ assert_cond(node != NULL);
+ assert_inteq(of_property_match_string(node, "new-prop",
+ "target-phandle"),
+ 0);
+
+ node = of_find_node_by_path_from(root, "/non-fragment-node");
+ assert_cond(node == NULL);
+
+ of_delete_node(overlay);
+ of_delete_node(root);
+}
+
+extern char __dtbo_of_overlay_missing_target_start[],
+ __dtbo_of_overlay_missing_target_end[];
+
+static void test_of_overlay_missing_target(void)
+{
+ struct device_node *root, *overlay, *node;
+ int ret;
+
+ if (!test_setup(&root, &overlay, __dtb_of_overlay_with_symbols_start,
+ __dtb_of_overlay_with_symbols_end,
+ __dtbo_of_overlay_missing_target_start,
+ __dtbo_of_overlay_missing_target_end))
+ return;
+
+ ret = of_overlay_apply_tree(root, overlay);
+ assert_inteq(ret, -ENOENT);
+
+ node = of_find_node_by_path_from(root, "/does-not-exist");
+ assert_cond(node == NULL);
+
+ node = of_find_node_by_path_from(root, "/target-node/applied-anyway");
+ assert_cond(node != NULL);
+
+ of_delete_node(overlay);
+ of_delete_node(root);
+}
+
static void test_of_overlay(void)
{
test_of_overlay_symbol_without_overlay();
test_of_overlay_symbol_outside_overlay();
+ test_of_overlay_fragments();
+ test_of_overlay_missing_target();
}
bselftest(core, test_of_overlay);
diff --git a/test/self/of_overlay.dtso b/test/self/of_overlay.dtso
new file mode 100644
index 0000000000..21dc85a8e4
--- /dev/null
+++ b/test/self/of_overlay.dtso
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/dts-v1/;
+/plugin/;
+
+/ {
+ /* not a fragment, must not be applied */
+ non-fragment-node {
+ };
+
+ fragment@0 {
+ target-path = "/target-node";
+
+ __overlay__ {
+ new-prop = "target-path";
+
+ added-child {
+ child-prop;
+ };
+
+ existing-child {
+ new-prop = "merged";
+ };
+ };
+ };
+
+ fragment@1 {
+ target = <&phandle_target>;
+
+ __overlay__ {
+ new-prop = "target-phandle";
+ };
+ };
+};
diff --git a/test/self/of_overlay_missing_target.dtso b/test/self/of_overlay_missing_target.dtso
new file mode 100644
index 0000000000..39362b0a0e
--- /dev/null
+++ b/test/self/of_overlay_missing_target.dtso
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/dts-v1/;
+/plugin/;
+
+/ {
+ fragment@0 {
+ target-path = "/does-not-exist";
+
+ __overlay__ {
+ never-applied {
+ };
+ };
+ };
+
+ fragment@1 {
+ target-path = "/target-node";
+
+ __overlay__ {
+ applied-anyway {
+ };
+ };
+ };
+};
--
2.47.3
next prev parent reply other threads:[~2026-10-19 10:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 10:05 [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite Stefan Kerkmann
2026-10-19 10:05 ` [PATCH v2 1/5] of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node Stefan Kerkmann
2026-10-19 10:05 ` [PATCH v2 2/5] of: overlay: fix_path/apply_symbols: add more debugging calls Stefan Kerkmann
2026-10-19 10:05 ` [PATCH v2 3/5] tests: of_overlay: add selftests skeleton Stefan Kerkmann
2026-10-19 10:05 ` [PATCH v2 4/5] tests: of_overlay: add __symbols__ merging tests Stefan Kerkmann
2026-10-19 10:05 ` Stefan Kerkmann [this message]
2026-10-20 7:14 ` [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261019-fix-overlay-v2-5-24e9ff1c0e12@pengutronix.de \
--to=s.kerkmann@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox