Skip to contentSkip to conversation

of: Add unit tests for applying overlays

PATCH Superseded [email protected] 3 participants 7 messages Apr 24, 2017 – Apr 26, 2017

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover of: Add unit tests for applying overlays

From: Frank Rowand <[email protected]>

Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.

Changes from v1:
- Move overlay base dtb unflattening into unittest.c. Call from fdt.c.
- Clarify file and variable names, 'overlay_test_' instead of 'ot_'
- Use proper naming convention for node names.
- A few added comments.
- Improve error messages in the new tests.

Frank Rowand (2):
of: support dtc compiler flags for device tree overlays
of: Add unit tests for applying overlays.

 drivers/of/fdt.c                                 |  14 +-
 drivers/of/of_private.h                          |  11 +
 drivers/of/unittest-data/Makefile                |  17 +-
 drivers/of/unittest-data/overlay.dts             |  53 ++++
 drivers/of/unittest-data/overlay_bad_phandle.dts |  20 ++
 drivers/of/unittest-data/overlay_base.dts        |  80 ++++++
 drivers/of/unittest.c                            | 318 +++++++++++++++++++++++
 scripts/Makefile.lib                             |   2 +
 8 files changed, 507 insertions(+), 8 deletions(-)
 create mode 100644 drivers/of/unittest-data/overlay.dts
 create mode 100644 drivers/of/unittest-data/overlay_bad_phandle.dts
 create mode 100644 drivers/of/unittest-data/overlay_base.dts
Signature · 1 line
Frank Rowand <[email protected]>
#1 lore raw

PATCH v2 1/2 of: support dtc compiler flags for overlays

From: Frank Rowand <[email protected]>

The dtc compiler version that adds initial support was available in 4.11-rc1. Add the ability to set the dtc compiler flags needed by overlays.

---
 scripts/Makefile.lib | 2 ++
 1 file changed, 2 insertions(+)
scripts/Makefile.lib +2 -0
index 0a07f9014944..0bbec480d323 100644
@@ -283,6 +283,8 @@ ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
 DTC_FLAGS += -Wno-unit_address_vs_reg
 endif
 
+DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
+
 # Generate an assembly file to wrap the output of the device tree compiler
 quiet_cmd_dt_S_dtb= DTB     $@
 cmd_dt_S_dtb=						\
Signature · 1 line
Frank Rowand <[email protected]>
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] of: support dtc compiler flags for overlays

2017-04-25 8:05 GMT+09:00 <[email protected]>:

Quoted 8 lines

From: Frank Rowand <frank.rowand-7U/[email protected]>

The dtc compiler version that adds initial support was available in 4.11-rc1. Add the ability to set the dtc compiler flags needed by overlays.

---

I know your motivation for 1/2 is overlay,
but this patch itself is more generic.
(support for per-file dtc compiler flag)

Could you reword the commit subject a little bit?

Otherwise,

Quoted 17 lines
 scripts/Makefile.lib | 2 ++
 1 file changed, 2 insertions(+)
scripts/Makefile.lib +2 -1
index 0a07f9014944..0bbec480d323 100644
@@ -283,6 +283,8 @@ ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
 DTC_FLAGS += -Wno-unit_address_vs_reg
 endif
 
+DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
+
 # Generate an assembly file to wrap the output of the device tree compiler
 quiet_cmd_dt_S_dtb= DTB     $@
 cmd_dt_S_dtb=                                          \
--
Signature · 6 lines
Best Regards
Masahiro Yamada
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Re: [PATCH v2 1/2] of: support dtc compiler flags for overlays

Quoted 15 lines · Masahiro Yamada

2017-04-25 8:05 GMT+09:00 <[email protected]>:

Quoted 8 lines

From: Frank Rowand <[email protected]>

The dtc compiler version that adds initial support was available in 4.11-rc1. Add the ability to set the dtc compiler flags needed by overlays.

---

I know your motivation for 1/2 is overlay,
but this patch itself is more generic.
(support for per-file dtc compiler flag)

Quoted 5 lines

Could you reword the commit subject a little bit?

Otherwise,

Fixed in version 4.

-Frank

Quoted 22 lines
Quoted 20 lines


 scripts/Makefile.lib | 2 ++
 1 file changed, 2 insertions(+)
scripts/Makefile.lib +2 -1
index 0a07f9014944..0bbec480d323 100644
@@ -283,6 +283,8 @@ ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
 DTC_FLAGS += -Wno-unit_address_vs_reg
 endif
 
+DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
+
 # Generate an assembly file to wrap the output of the device tree compiler
 quiet_cmd_dt_S_dtb= DTB     $@
 cmd_dt_S_dtb=                                          \
--
#4 lore raw

PATCH v2 2/2 of: Add unit tests for applying overlays

In reply to [email protected]

From: Frank Rowand <frank.rowand-7U/[email protected]>

Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.

---

There are checkpatch warnings. I have reviewed them and feel they can be ignored.

 drivers/of/fdt.c                                 |  14 +-
 drivers/of/of_private.h                          |  11 +
 drivers/of/unittest-data/Makefile                |  17 +-
 drivers/of/unittest-data/overlay.dts             |  53 ++++
 drivers/of/unittest-data/overlay_bad_phandle.dts |  20 ++
 drivers/of/unittest-data/overlay_base.dts        |  80 ++++++
 drivers/of/unittest.c                            | 318 +++++++++++++++++++++++
 7 files changed, 505 insertions(+), 8 deletions(-)
 create mode 100644 drivers/of/unittest-data/overlay.dts
 create mode 100644 drivers/of/unittest-data/overlay_bad_phandle.dts
 create mode 100644 drivers/of/unittest-data/overlay_base.dts
drivers/of/fdt.c +9 -5
index e5ce4b59e162..e33f7818bc6c 100644
@@ -31,6 +31,8 @@
 #include <asm/setup.h>  /* for COMMAND_LINE_SIZE */
 #include <asm/page.h>
 
+#include "of_private.h"
+
 /*
  * of_fdt_limit_memory - limit the number of regions in the /memory node
  * @limit: maximum entries
@@ -469,11 +471,11 @@ static int unflatten_dt_nodes(const void *blob,
  * Returns NULL on failure or the memory chunk containing the unflattened
  * device tree on success.
  */
-static void *__unflatten_device_tree(const void *blob,
-				     struct device_node *dad,
-				     struct device_node **mynodes,
-				     void *(*dt_alloc)(u64 size, u64 align),
-				     bool detached)
+void *__unflatten_device_tree(const void *blob,
+			      struct device_node *dad,
+			      struct device_node **mynodes,
+			      void *(*dt_alloc)(u64 size, u64 align),
+			      bool detached)
 {
 	int size;
 	void *mem;
@@ -1261,6 +1263,8 @@ void __init unflatten_device_tree(void)
 
 	/* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */
 	of_alias_scan(early_init_dt_alloc_memory_arch);
+
+	unittest_unflatten_overlay_base();
 }
 
 /**
drivers/of/of_private.h +11 -0
index 18bbb4517e25..cc76b3b81eab 100644
@@ -55,6 +55,17 @@ static inline int of_property_notify(int action, struct device_node *np,
 }
 #endif /* CONFIG_OF_DYNAMIC */
 
+#ifdef CONFIG_OF_UNITTEST
+extern void __init unittest_unflatten_overlay_base(void);
+extern void *__unflatten_device_tree(const void *blob,
+			      struct device_node *dad,
+			      struct device_node **mynodes,
+			      void *(*dt_alloc)(u64 size, u64 align),
+			      bool detached);
+#else
+static inline void unittest_unflatten_overlay_base(void) {};
+#endif
+
 /**
  * General utilities for working with live trees.
  *
drivers/of/unittest-data/Makefile +14 -3
index 1ac5cc01d627..6e00a9c69e58 100644
@@ -1,7 +1,18 @@
 obj-y += testcases.dtb.o
+obj-y += overlay.dtb.o
+obj-y += overlay_bad_phandle.dtb.o
+obj-y += overlay_base.dtb.o
 
 targets += testcases.dtb testcases.dtb.S
+targets += overlay.dtb overlay.dtb.S
+targets += overlay_bad_phandle.dtb overlay_bad_phandle.dtb.S
+targets += overlay_base.dtb overlay_base.dtb.S
 
-.SECONDARY: \
-	$(obj)/testcases.dtb.S \
-	$(obj)/testcases.dtb
+.PRECIOUS: \
+	$(obj)/%.dtb.S \
+	$(obj)/%.dtb
+
+# enable creation of __symbols__ node
+DTC_FLAGS_overlay := -@
+DTC_FLAGS_overlay_bad_phandle := -@
+DTC_FLAGS_overlay_base := -@
drivers/of/unittest-data/overlay.dts new file +53 -0

53 lines not on this page · raw message

drivers/of/unittest-data/overlay_bad_phandle.dts new file +20 -0
new file mode 100644
index 000000000000..270ee885a623
@@ -0,0 +1,20 @@
+/dts-v1/;
+/plugin/;
+
+/ {
+
+	fragment@0 {
+		target = <&electric_1>;
+
+		__overlay__ {
+
+			// This label should cause an error when the overlay
+			// is applied.  There is already a phandle value
+			// in the base tree for motor-1.
+			spin_ctrl_1_conflict: motor-1 {
+				accelerate = < 3 >;
+				decelerate = < 5 >;
+			};
+		};
+	};
+};
drivers/of/unittest-data/overlay_base.dts new file +80 -0

80 lines not on this page · raw message

drivers/of/unittest.c +318 -0

336 lines not on this page · raw message

Signature · 6 lines
Frank Rowand <frank.rowand-7U/[email protected]>

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
Quoted 4 lines · On Mon, Apr 24, 2017 at 6:05 PM, <[email protected]> wrote:

From: Frank Rowand <[email protected]>

Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.

Just a few nits.

Quoted 1 line

[...]

drivers/of/of_private.h static inline int of_property_notify(int action, struct device_node *np, · line 60

Quoted 11 lines
drivers/of/of_private.h +3 -0
index 18bbb4517e25..cc76b3b81eab 100644
@@ -55,6 +55,17 @@ static inline int of_property_notify(int action, struct device_node *np,
 }
 #endif /* CONFIG_OF_DYNAMIC */
 
+#ifdef CONFIG_OF_UNITTEST
+extern void __init unittest_unflatten_overlay_base(void);
+extern void *__unflatten_device_tree(const void *blob,

This can and should be outside the ifdef.

Quoted 11 lines
drivers/of/of_private.h +8 -0
+                             struct device_node *dad,
+                             struct device_node **mynodes,
+                             void *(*dt_alloc)(u64 size, u64 align),
+                             bool detached);
+#else
+static inline void unittest_unflatten_overlay_base(void) {};
+#endif
+
 /**
  * General utilities for working with live trees.
  *

[...]

Quoted 13 lines
drivers/of/unittest.c +1 -0
index 62db55b97c10..884f6c1f8ae9 100644
@@ -8,6 +8,7 @@
 #include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/hashtable.h>
+#include <linux/libfdt.h>
 #include <linux/of.h>
 #include <linux/of_fdt.h>
 #include <linux/of_irq.h>

drivers/of/unittest.c static void __init of_unittest_overlay(void) · line 1929

Quoted 4 lines
drivers/of/unittest.c +1 -0
@@ -1925,6 +1926,320 @@ static void __init of_unittest_overlay(void)
 static inline void __init of_unittest_overlay(void) { }
 #endif
 
+#ifdef CONFIG_OF_OVERLAY

This can move down to...

Quoted 18 lines
drivers/of/unittest.c +18 -0
+
+/*
+ * __dtb_ot_begin[] and __dtb_ot_end[] are created by cmd_dt_S_dtb
+ * in scripts/Makefile.lib
+ */
+
+#define OVERLAY_INFO_EXTERN(name) \
+       extern uint8_t __dtb_##name##_begin[]; \
+       extern uint8_t __dtb_##name##_end[]
+
+#define OVERLAY_INFO(name, expected) \
+{      .dtb_begin       = __dtb_##name##_begin, \
+       .dtb_end         = __dtb_##name##_end, \
+       .expected_result = expected, \
+}
+
+struct overlay_info {
+       uint8_t            *dtb_begin;

drivers/of/unittest.c static void __init of_unittest_overlay(void) · line 1957

Quoted 10 lines
drivers/of/unittest.c +10 -0
+       uint8_t            *dtb_end;
+       void               *data;
+       struct device_node *np_overlay;
+       int                expected_result;
+       int                overlay_id;
+};
+
+OVERLAY_INFO_EXTERN(overlay_base);
+OVERLAY_INFO_EXTERN(overlay);
+OVERLAY_INFO_EXTERN(overlay_bad_phandle);

...here. Maybe we want to move all this to a separate file instead.

drivers/of/unittest.c static void __init of_unittest_overlay(void) · line 1960

Quoted 3 lines
drivers/of/unittest.c +3 -0
+
+/* order of entries is hard-coded into users of overlays[] */
+struct overlay_info overlays[] = {

static?

Quoted 5 lines
drivers/of/unittest.c +5 -0
+       OVERLAY_INFO(overlay_base, -9999),
+       OVERLAY_INFO(overlay, 0),
+       OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
+       {}
+};

[...]

drivers/of/unittest.c static int __init of_unittest(void) · line 2280

Quoted 5 lines
drivers/of/unittest.c +1 -0
@@ -1962,6 +2277,9 @@ static int __init of_unittest(void)
        /* Double check linkage after removing testcase data */
        of_unittest_check_tree_linkage();
 
+

Extra blank line.

Quoted 8 lines
drivers/of/unittest.c +2 -1
+       of_unittest_overlay_high_level();
+
        pr_info("end of unittest - %i passed, %i failed\n",
                unittest_results.passed, unittest_results.failed);
 
--

Frank Rowand <[email protected]>

#6 lore raw
Quoted 20 lines · Rob Herring
Quoted 4 lines · On Mon, Apr 24, 2017 at 6:05 PM, <[email protected]…

From: Frank Rowand <frank.rowand-7U/[email protected]>

Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.

Just a few nits.

Quoted 1 line

[...]

Quoted 8 lines
drivers/of/of_private.h +0 -0
index 18bbb4517e25..cc76b3b81eab 100644
@@ -55,6 +55,17 @@ static inline int of_property_notify(int action, struct device_node *np,
 }
 #endif /* CONFIG_OF_DYNAMIC */
 
Quoted 5 lines

drivers/of/of_private.h static inline int of_property_notify(int action, struct device_node *np, · line 60

Quoted 3 lines
drivers/of/of_private.h +3 -0
+#ifdef CONFIG_OF_UNITTEST
+extern void __init unittest_unflatten_overlay_base(void);
+extern void *__unflatten_device_tree(const void *blob,

This can and should be outside the ifdef.

Will do.

Quoted 31 lines
Quoted 12 lines
drivers/of/of_private.h +8 -0
+                             struct device_node *dad,
+                             struct device_node **mynodes,
+                             void *(*dt_alloc)(u64 size, u64 align),
+                             bool detached);
+#else
+static inline void unittest_unflatten_overlay_base(void) {};
+#endif
+
 /**
  * General utilities for working with live trees.
  *

[...]

Quoted 16 lines
drivers/of/unittest.c +1 -0
index 62db55b97c10..884f6c1f8ae9 100644
@@ -8,6 +8,7 @@
 #include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/hashtable.h>
+#include <linux/libfdt.h>
 #include <linux/of.h>
 #include <linux/of_fdt.h>
 #include <linux/of_irq.h>
@@ -1925,6 +1926,320 @@ static void __init of_unittest_overlay(void)
 static inline void __init of_unittest_overlay(void) { }
 #endif
 
Quoted 3 lines

drivers/of/unittest.c static void __init of_unittest_overlay(void) · line 1929

Quoted 1 line
drivers/of/unittest.c +1 -0
+#ifdef CONFIG_OF_OVERLAY

This can move down to...

Will do.

Quoted 23 lines
Quoted 23 lines
drivers/of/unittest.c +22 -0
+
+/*
+ * __dtb_ot_begin[] and __dtb_ot_end[] are created by cmd_dt_S_dtb
+ * in scripts/Makefile.lib
+ */
+
+#define OVERLAY_INFO_EXTERN(name) \
+       extern uint8_t __dtb_##name##_begin[]; \
+       extern uint8_t __dtb_##name##_end[]
+
+#define OVERLAY_INFO(name, expected) \
+{      .dtb_begin       = __dtb_##name##_begin, \
+       .dtb_end         = __dtb_##name##_end, \
+       .expected_result = expected, \
+}
+
+struct overlay_info {
+       uint8_t            *dtb_begin;
+       uint8_t            *dtb_end;
+       void               *data;
+       struct device_node *np_overlay;
+       int                expected_result;
Quoted 8 lines

drivers/of/unittest.c static void __init of_unittest_overlay(void) · line 1957

Quoted 6 lines
drivers/of/unittest.c +6 -0
+       int                overlay_id;
+};
+
+OVERLAY_INFO_EXTERN(overlay_base);
+OVERLAY_INFO_EXTERN(overlay);
+OVERLAY_INFO_EXTERN(overlay_bad_phandle);

...here. Maybe we want to move all this to a separate file instead.

In the medium term, yes. At the moment it is good enough for this localized use for unittest. I do not think it is baked enough for general use. I want to see how well it works for the previously existing overlay unit tests and make sure it meets the majority of the needs of wider use cases before making it more widely visible.

Quoted 5 lines

drivers/of/unittest.c static void __init of_unittest_overlay(void) · line 1960

Quoted 3 lines
drivers/of/unittest.c +3 -0
+
+/* order of entries is hard-coded into users of overlays[] */
+struct overlay_info overlays[] = {

static?

Yes, thanks.

Quoted 8 lines
Quoted 5 lines
drivers/of/unittest.c +5 -0
+       OVERLAY_INFO(overlay_base, -9999),
+       OVERLAY_INFO(overlay, 0),
+       OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
+       {}
+};

[...]

Quoted 7 lines

drivers/of/unittest.c static int __init of_unittest(void) · line 2280

Quoted 5 lines
drivers/of/unittest.c +1 -0
@@ -1962,6 +2277,9 @@ static int __init of_unittest(void)
        /* Double check linkage after removing testcase data */
        of_unittest_check_tree_linkage();
 
+

Extra blank line.

thanks

Quoted 10 lines
Quoted 9 lines
drivers/of/unittest.c +2 -1
+       of_unittest_overlay_high_level();
+
        pr_info("end of unittest - %i passed, %i failed\n",
                unittest_results.passed, unittest_results.failed);
 
--

Frank Rowand <frank.rowand-7U/[email protected]>

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html