mail archive of the barebox mailing list
 help / color / mirror / Atom feed
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 4/5] tests: of_overlay: add __symbols__ merging tests
Date: Mon, 19 Oct 2026 12:05:47 +0200	[thread overview]
Message-ID: <20261019-fix-overlay-v2-4-24e9ff1c0e12@pengutronix.de> (raw)
In-Reply-To: <20261019-fix-overlay-v2-0-24e9ff1c0e12@pengutronix.de>

These tests exercise the merging of the __symbols__ table from a overlay
into the target device tree.

Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
 test/self/Makefile                     |  3 ++
 test/self/of_overlay.c                 | 90 ++++++++++++++++++++++++++++++++++
 test/self/of_overlay_with_symbols.dts  | 14 ++++++
 test/self/of_overlay_with_symbols.dtso | 43 ++++++++++++++++
 4 files changed, 150 insertions(+)

diff --git a/test/self/Makefile b/test/self/Makefile
index f912afe5a6..f6cec81011 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -11,6 +11,9 @@ CFLAGS_printf.o += -Wno-format-security -Wno-format
 obj-$(CONFIG_SELFTEST_PROGRESS_NOTIFIER) += progress-notifier.o
 obj-$(CONFIG_SELFTEST_OF_MANIPULATION) += of_manipulation.o of_manipulation.dtb.o
 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_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 d60898358f..2804c936c0 100644
--- a/test/self/of_overlay.c
+++ b/test/self/of_overlay.c
@@ -10,7 +10,97 @@
 
 BSELFTEST_GLOBALS();
 
+extern char __dtb_of_overlay_with_symbols_start[],
+	__dtb_of_overlay_with_symbols_end[];
+extern char __dtbo_of_overlay_with_symbols_start[],
+	__dtbo_of_overlay_with_symbols_end[];
+
+static struct device_node *unflatten(char *start, char *end)
+{
+	struct device_node *root;
+
+	root = of_unflatten_dtb(start, end - start);
+	if (IS_ERR(root)) {
+		pr_err("failed to unflatten dtb");
+		return NULL;
+	}
+
+	return root;
+}
+
+static bool test_setup(struct device_node **root, struct device_node **overlay,
+		       char *dtb_start, char *dtb_end, char *dtbo_start,
+		       char *dtbo_end)
+{
+	*root = unflatten(dtb_start, dtb_end);
+	if (!assert_cond(*root != NULL))
+		return false;
+
+	*overlay = unflatten(dtbo_start, dtbo_end);
+	if (!assert_cond(*overlay != NULL)) {
+		of_delete_node(*root);
+		return false;
+	}
+
+	return true;
+}
+
+static void test_of_overlay_symbol_without_overlay(void)
+{
+	struct device_node *root, *overlay, *symbols;
+	const char *path;
+	int ret;
+
+	if (!test_setup(&root, &overlay, __dtb_of_overlay_with_symbols_start,
+			__dtb_of_overlay_with_symbols_end,
+			__dtbo_of_overlay_with_symbols_start,
+			__dtbo_of_overlay_with_symbols_end))
+		return;
+
+	ret = of_overlay_apply_tree(root, overlay);
+	assert_inteq(ret, 0);
+
+	symbols = of_get_child_by_name(root, "__symbols__");
+	assert_cond(symbols != NULL);
+
+	assert_inteq(of_property_read_string(symbols, "added", &path), 0);
+	assert_inteq(of_property_read_string(symbols, "toplevel", &path),
+		     -EINVAL);
+	assert_inteq(of_property_read_string(symbols, "target", &path), 0);
+
+	of_delete_node(overlay);
+	of_delete_node(root);
+}
+
+static void test_of_overlay_symbol_outside_overlay(void)
+{
+	struct device_node *root, *overlay, *symbols;
+	const char *path;
+	int ret;
+
+	if (!test_setup(&root, &overlay, __dtb_of_overlay_with_symbols_start,
+			__dtb_of_overlay_with_symbols_end,
+			__dtbo_of_overlay_with_symbols_start,
+			__dtbo_of_overlay_with_symbols_end))
+		return;
+
+	ret = of_overlay_apply_tree(root, overlay);
+	assert_inteq(ret, 0);
+
+	symbols = of_get_child_by_name(root, "__symbols__");
+	assert_cond(symbols != NULL);
+
+	assert_inteq(of_property_read_string(symbols, "added", &path), 0);
+	assert_inteq(of_property_read_string(symbols, "local", &path), -EINVAL);
+	assert_inteq(of_property_read_string(symbols, "outside", &path), -EINVAL);
+
+	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();
 }
 bselftest(core, test_of_overlay);
diff --git a/test/self/of_overlay_with_symbols.dts b/test/self/of_overlay_with_symbols.dts
new file mode 100644
index 0000000000..ac568025ed
--- /dev/null
+++ b/test/self/of_overlay_with_symbols.dts
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/dts-v1/;
+
+/ {
+	target: target-node {
+		existing-child {
+			old-prop = "old";
+		};
+	};
+
+	phandle_target: phandle-target-node {
+	};
+};
diff --git a/test/self/of_overlay_with_symbols.dtso b/test/self/of_overlay_with_symbols.dtso
new file mode 100644
index 0000000000..9f26e31aee
--- /dev/null
+++ b/test/self/of_overlay_with_symbols.dtso
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/dts-v1/;
+/plugin/;
+
+/ {
+	/* label that ends up in no fragment at all */
+	toplevel: toplevel-node {};
+
+	fragment@0 {
+		target-path = "/target-node";
+
+		__overlay__ {
+			/* label that resolves into an __overlay__ */
+			added: added-by-fragment0 {};
+		};
+	};
+
+	fragment@1 {
+		target-path = "/target-node";
+
+		localinfo {
+			/* label below a fragment but outside its __overlay__ */
+			local: subnode {};
+		};
+
+		__overlay__ {
+			added-by-fragment1 {};
+		};
+	};
+
+	fragment@2 {
+		target-path = "/target-node";
+
+		__overlay__ {
+			added-by-fragment2 {};
+		};
+
+		__overlay__extra {
+			outside: subnode {};
+		};
+	};
+};

-- 
2.47.3




  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 ` Stefan Kerkmann [this message]
2026-10-19 10:05 ` [PATCH v2 5/5] tests: of_overlay: add fragment application tests Stefan Kerkmann
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-4-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