The export symbols feature allows to use some additional symbols
provided in an export symbols node to resolve overlay symbols.
Add tests to exercise the export symbols feature.
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
drivers/of/unittest-data/Makefile | 5 ++
.../unittest-data/overlay_export_symbols.dtso | 15 +++++
.../of/unittest-data/testcases_common.dtsi | 1 +
.../unittest-data/tests-export-symbols.dtsi | 30 +++++++++
drivers/of/unittest.c | 64 +++++++++++++++++++
5 files changed, 115 insertions(+)
create mode 100644 drivers/of/unittest-data/overlay_export_symbols.dtso
create mode 100644 drivers/of/unittest-data/tests-export-symbols.dtsi
diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/Makefile
index 01a966e39f23..b51be046749a 100644
--- a/drivers/of/unittest-data/Makefile
+++ b/drivers/of/unittest-data/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtbo.o \
overlay_gpio_04a.dtbo.o \
overlay_gpio_04b.dtbo.o \
overlay_pci_node.dtbo.o \
+ overlay_export_symbols.dtbo.o \
overlay_bad_unresolved.dtbo.o
# enable creation of __symbols__ node
@@ -66,6 +67,10 @@ DTC_FLAGS_testcases += -Wno-interrupts_property \
# overlay_bad_add_dup_prop.dtbo \
# overlay_bad_phandle.dtbo \
# overlay_bad_symbol.dtbo \
+#
+# Also overlay_export_symbols_ovl.dtbo is designed to be applied to a specific
+# node and cannot be applied statically with fdtoverlay
+
apply_static_overlay_1 := overlay_0.dtbo \
overlay_1.dtbo \
diff --git a/drivers/of/unittest-data/overlay_export_symbols.dtso b/drivers/of/unittest-data/overlay_export_symbols.dtso
new file mode 100644
index 000000000000..89c9df4ef89b
--- /dev/null
+++ b/drivers/of/unittest-data/overlay_export_symbols.dtso
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+/plugin/;
+
+/ {
+ fragment@0 {
+ target-path="";
+ __overlay__ {
+ ovl_node {
+ ref-base = <&test_export_base>;
+ ref-node = <&test_export_node>;
+ };
+ };
+ };
+};
diff --git a/drivers/of/unittest-data/testcases_common.dtsi b/drivers/of/unittest-data/testcases_common.dtsi
index 1c2cdf353ae3..21ffe0fb03ef 100644
--- a/drivers/of/unittest-data/testcases_common.dtsi
+++ b/drivers/of/unittest-data/testcases_common.dtsi
@@ -18,4 +18,5 @@ node-remove {
#include "tests-address.dtsi"
#include "tests-platform.dtsi"
#include "tests-overlay.dtsi"
+#include "tests-export-symbols.dtsi"
#include "tests-lifecycle.dtsi"
diff --git a/drivers/of/unittest-data/tests-export-symbols.dtsi b/drivers/of/unittest-data/tests-export-symbols.dtsi
new file mode 100644
index 000000000000..1650289b34cd
--- /dev/null
+++ b/drivers/of/unittest-data/tests-export-symbols.dtsi
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/ {
+ testcase-data {
+ test-export-symbols {
+ test_export_symbols_b0: base0 {
+ test_export_symbols_n0: node {
+ dummy;
+ };
+
+ export-symbols {
+ test_export_base = <&test_export_symbols_b0>;
+ test_export_node = <&test_export_symbols_n0>;
+ };
+ };
+
+ test_export_symbols_b1: base1 {
+
+ test_export_symbols_n1: node {
+ dummy;
+ };
+
+ export-symbols {
+ test_export_base = <&test_export_symbols_b1>;
+ test_export_node = <&test_export_symbols_n1>;
+ };
+ };
+ };
+ };
+};
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index f19e15f8b288..1be4ffb7a4db 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -4043,6 +4043,69 @@ static __init void of_unittest_overlay_high_level(void)
mutex_unlock(&of_mutex);
}
+OVERLAY_INFO_EXTERN(overlay_export_symbols);
+
+static __init void of_unittest_export_symbols(const char *prefix,
+ const char *base_full_path)
+{
+ const struct overlay_info ovl = OVERLAY_INFO(overlay_export_symbols, 0, 0);
+ struct device_node *ovl_node;
+ struct device_node *base;
+ struct device_node *node;
+ struct device_node *ref;
+ int ovcs_id;
+ u32 size;
+ int ret;
+
+ base = of_find_node_by_path(base_full_path);
+ if (unittest(base, "%s: Get base (%s) failed\n", prefix, base_full_path))
+ return;
+
+ node = of_get_child_by_name(base, "node");
+ if (unittest(base, "%s: Get node from %pOF failed\n", prefix, base))
+ goto end_put_base;
+
+ size = ovl.dtbo_end - ovl.dtbo_begin;
+ ret = of_overlay_fdt_apply(ovl.dtbo_begin, size, &ovcs_id, base, "export-symbols");
+ if (unittest(!ret, "%s: Apply '%s' failed (%d)\n", prefix, ovl.name, ret))
+ goto end_put_node;
+
+ ovl_node = of_get_child_by_name(base, "ovl_node");
+ if (unittest(ovl_node, "%s: Get ovl_node from %pOF failed\n", prefix, base))
+ goto end_remove_overlay;
+
+ ref = of_parse_phandle(ovl_node, "ref-base", 0);
+ if (unittest(ref, "%s: Parse 'ref-base' from %pOF failed\n", prefix, ovl_node))
+ goto end_put_ovl_node;
+ unittest(ref == base,
+ "%s: Node from 'ref-base' phandle mismatches (got %pOF, expected %pOF)\n",
+ prefix, ref, base);
+ of_node_put(ref);
+
+ ref = of_parse_phandle(ovl_node, "ref-node", 0);
+ if (unittest(ref, "%s: Parse 'ref-node' from %pOF failed\n", prefix, ovl_node))
+ goto end_put_ovl_node;
+ unittest(ref == node,
+ "%s: Node from 'ref-node' phandle mismatches (got %pOF, expected %pOF)\n",
+ prefix, ref, node);
+ of_node_put(ref);
+
+end_put_ovl_node:
+ of_node_put(ovl_node);
+end_remove_overlay:
+ of_overlay_remove(&ovcs_id);
+end_put_node:
+ of_node_put(node);
+end_put_base:
+ of_node_put(base);
+}
+
+static __init void of_unittest_overlay_export_symbols(void)
+{
+ of_unittest_export_symbols("base0", "/testcase-data/test-export-symbols/base0");
+ of_unittest_export_symbols("base1", "/testcase-data/test-export-symbols/base1");
+}
+
static int of_unittest_pci_dev_num;
static int of_unittest_pci_child_num;
@@ -4281,6 +4344,7 @@ static int __init of_unittest(void)
of_unittest_overlay();
of_unittest_lifecycle();
of_unittest_pci_node();
+ of_unittest_overlay_export_symbols();
/* Double check linkage after removing testcase data */
of_unittest_check_tree_linkage();
--
2.47.0
Hi Herve,
kernel test robot noticed the following build errors:
[auto build test ERROR on robh/for-next]
[also build test ERROR on linus/master v6.13-rc2 next-20241211]
[cannot apply to char-misc/char-misc-testing char-misc/char-misc-next char-misc/char-misc-linus]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Herve-Codina/dt-bindings-Add-support-for-export-symbols-node/20241209-232324
base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link: https://lore.kernel.org/r/20241209151830.95723-8-herve.codina%40bootlin.com
patch subject: [PATCH 7/7] of: unittest: Add tests for export symbols
config: arc-randconfig-001-20241210 (https://download.01.org/0day-ci/archive/20241212/202412120806.IiuXJ0WZ-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241212/202412120806.IiuXJ0WZ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412120806.IiuXJ0WZ-lkp@intel.com/
All errors (new ones prefixed by >>):
drivers/of/unittest.c: In function 'of_unittest':
>> drivers/of/unittest.c:4347:9: error: implicit declaration of function 'of_unittest_overlay_export_symbols'; did you mean 'of_unittest_overlay_high_level'? [-Werror=implicit-function-declaration]
4347 | of_unittest_overlay_export_symbols();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| of_unittest_overlay_high_level
cc1: some warnings being treated as errors
vim +4347 drivers/of/unittest.c
4297
4298 static int __init of_unittest(void)
4299 {
4300 struct device_node *np;
4301 int res;
4302
4303 pr_info("start of unittest - you will see error messages\n");
4304
4305 /* Taint the kernel so we know we've run tests. */
4306 add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
4307
4308 /* adding data for unittest */
4309 res = unittest_data_add();
4310 if (res)
4311 return res;
4312 if (!of_aliases)
4313 of_aliases = of_find_node_by_path("/aliases");
4314
4315 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
4316 if (!np) {
4317 pr_info("No testcase data in device tree; not running tests\n");
4318 return 0;
4319 }
4320 of_node_put(np);
4321
4322 of_unittest_check_tree_linkage();
4323 of_unittest_check_phandles();
4324 of_unittest_find_node_by_name();
4325 of_unittest_dynamic();
4326 of_unittest_parse_phandle_with_args();
4327 of_unittest_parse_phandle_with_args_map();
4328 of_unittest_printf();
4329 of_unittest_property_string();
4330 of_unittest_property_copy();
4331 of_unittest_changeset();
4332 of_unittest_changeset_prop();
4333 of_unittest_parse_interrupts();
4334 of_unittest_parse_interrupts_extended();
4335 of_unittest_dma_get_max_cpu_address();
4336 of_unittest_parse_dma_ranges();
4337 of_unittest_pci_dma_ranges();
4338 of_unittest_bus_ranges();
4339 of_unittest_bus_3cell_ranges();
4340 of_unittest_reg();
4341 of_unittest_translate_addr();
4342 of_unittest_match_node();
4343 of_unittest_platform_populate();
4344 of_unittest_overlay();
4345 of_unittest_lifecycle();
4346 of_unittest_pci_node();
> 4347 of_unittest_overlay_export_symbols();
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Herve,
kernel test robot noticed the following build errors:
[auto build test ERROR on robh/for-next]
[also build test ERROR on linus/master v6.13-rc2 next-20241210]
[cannot apply to char-misc/char-misc-testing char-misc/char-misc-next char-misc/char-misc-linus]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Herve-Codina/dt-bindings-Add-support-for-export-symbols-node/20241209-232324
base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link: https://lore.kernel.org/r/20241209151830.95723-8-herve.codina%40bootlin.com
patch subject: [PATCH 7/7] of: unittest: Add tests for export symbols
config: i386-buildonly-randconfig-004-20241210 (https://download.01.org/0day-ci/archive/20241211/202412110002.61YacCza-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241211/202412110002.61YacCza-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412110002.61YacCza-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/of/unittest.c:8:
In file included from include/linux/memblock.h:12:
In file included from include/linux/mm.h:2223:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
>> drivers/of/unittest.c:4347:2: error: call to undeclared function 'of_unittest_overlay_export_symbols'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
4347 | of_unittest_overlay_export_symbols();
| ^
1 warning and 1 error generated.
vim +/of_unittest_overlay_export_symbols +4347 drivers/of/unittest.c
4297
4298 static int __init of_unittest(void)
4299 {
4300 struct device_node *np;
4301 int res;
4302
4303 pr_info("start of unittest - you will see error messages\n");
4304
4305 /* Taint the kernel so we know we've run tests. */
4306 add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
4307
4308 /* adding data for unittest */
4309 res = unittest_data_add();
4310 if (res)
4311 return res;
4312 if (!of_aliases)
4313 of_aliases = of_find_node_by_path("/aliases");
4314
4315 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
4316 if (!np) {
4317 pr_info("No testcase data in device tree; not running tests\n");
4318 return 0;
4319 }
4320 of_node_put(np);
4321
4322 of_unittest_check_tree_linkage();
4323 of_unittest_check_phandles();
4324 of_unittest_find_node_by_name();
4325 of_unittest_dynamic();
4326 of_unittest_parse_phandle_with_args();
4327 of_unittest_parse_phandle_with_args_map();
4328 of_unittest_printf();
4329 of_unittest_property_string();
4330 of_unittest_property_copy();
4331 of_unittest_changeset();
4332 of_unittest_changeset_prop();
4333 of_unittest_parse_interrupts();
4334 of_unittest_parse_interrupts_extended();
4335 of_unittest_dma_get_max_cpu_address();
4336 of_unittest_parse_dma_ranges();
4337 of_unittest_pci_dma_ranges();
4338 of_unittest_bus_ranges();
4339 of_unittest_bus_3cell_ranges();
4340 of_unittest_reg();
4341 of_unittest_translate_addr();
4342 of_unittest_match_node();
4343 of_unittest_platform_populate();
4344 of_unittest_overlay();
4345 of_unittest_lifecycle();
4346 of_unittest_pci_node();
> 4347 of_unittest_overlay_export_symbols();
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.