Skip to content

Commit 81d0848

Browse files
frowandrobherring
authored andcommitted
of: Add unit tests for applying overlays
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay. Signed-off-by: Frank Rowand <frank.rowand@sony.com> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 331f741 commit 81d0848

File tree

7 files changed

+505
-8
lines changed

7 files changed

+505
-8
lines changed

drivers/of/fdt.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <asm/setup.h> /* for COMMAND_LINE_SIZE */
3232
#include <asm/page.h>
3333

34+
#include "of_private.h"
35+
3436
/*
3537
* of_fdt_limit_memory - limit the number of regions in the /memory node
3638
* @limit: maximum entries
@@ -469,11 +471,11 @@ static int unflatten_dt_nodes(const void *blob,
469471
* Returns NULL on failure or the memory chunk containing the unflattened
470472
* device tree on success.
471473
*/
472-
static void *__unflatten_device_tree(const void *blob,
473-
struct device_node *dad,
474-
struct device_node **mynodes,
475-
void *(*dt_alloc)(u64 size, u64 align),
476-
bool detached)
474+
void *__unflatten_device_tree(const void *blob,
475+
struct device_node *dad,
476+
struct device_node **mynodes,
477+
void *(*dt_alloc)(u64 size, u64 align),
478+
bool detached)
477479
{
478480
int size;
479481
void *mem;
@@ -1261,6 +1263,8 @@ void __init unflatten_device_tree(void)
12611263

12621264
/* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */
12631265
of_alias_scan(early_init_dt_alloc_memory_arch);
1266+
1267+
unittest_unflatten_overlay_base();
12641268
}
12651269

12661270
/**

drivers/of/of_private.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ static inline int of_property_notify(int action, struct device_node *np,
5555
}
5656
#endif /* CONFIG_OF_DYNAMIC */
5757

58+
#ifdef CONFIG_OF_UNITTEST
59+
extern void __init unittest_unflatten_overlay_base(void);
60+
#else
61+
static inline void unittest_unflatten_overlay_base(void) {};
62+
#endif
63+
64+
extern void *__unflatten_device_tree(const void *blob,
65+
struct device_node *dad,
66+
struct device_node **mynodes,
67+
void *(*dt_alloc)(u64 size, u64 align),
68+
bool detached);
69+
5870
/**
5971
* General utilities for working with live trees.
6072
*

drivers/of/unittest-data/Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
obj-y += testcases.dtb.o
2+
obj-y += overlay.dtb.o
3+
obj-y += overlay_bad_phandle.dtb.o
4+
obj-y += overlay_base.dtb.o
25

36
targets += testcases.dtb testcases.dtb.S
7+
targets += overlay.dtb overlay.dtb.S
8+
targets += overlay_bad_phandle.dtb overlay_bad_phandle.dtb.S
9+
targets += overlay_base.dtb overlay_base.dtb.S
410

5-
.SECONDARY: \
6-
$(obj)/testcases.dtb.S \
7-
$(obj)/testcases.dtb
11+
.PRECIOUS: \
12+
$(obj)/%.dtb.S \
13+
$(obj)/%.dtb
14+
15+
# enable creation of __symbols__ node
16+
DTC_FLAGS_overlay := -@
17+
DTC_FLAGS_overlay_bad_phandle := -@
18+
DTC_FLAGS_overlay_base := -@
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/dts-v1/;
2+
/plugin/;
3+
4+
/ {
5+
6+
fragment@0 {
7+
target = <&electric_1>;
8+
9+
__overlay__ {
10+
status = "ok";
11+
12+
hvac_2: hvac-large-1 {
13+
compatible = "ot,hvac-large";
14+
heat-range = < 40 75 >;
15+
cool-range = < 65 80 >;
16+
};
17+
};
18+
};
19+
20+
fragment@1 {
21+
target = <&rides_1>;
22+
23+
__overlay__ {
24+
#address-cells = <1>;
25+
#size-cells = <1>;
26+
status = "ok";
27+
28+
ride@200 {
29+
compatible = "ot,ferris-wheel";
30+
reg = < 0x00000200 0x100 >;
31+
hvac-provider = < &hvac_2 >;
32+
hvac-thermostat = < 27 32 > ;
33+
hvac-zones = < 12 5 >;
34+
hvac-zone-names = "operator", "snack-bar";
35+
spin-controller = < &spin_ctrl_1 3 >;
36+
spin-rph = < 30 >;
37+
gondolas = < 16 >;
38+
gondola-capacity = < 6 >;
39+
};
40+
};
41+
};
42+
43+
fragment@2 {
44+
target = <&lights_2>;
45+
46+
__overlay__ {
47+
status = "ok";
48+
color = "purple", "white", "red", "green";
49+
rate = < 3 256 >;
50+
};
51+
};
52+
53+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/dts-v1/;
2+
/plugin/;
3+
4+
/ {
5+
6+
fragment@0 {
7+
target = <&electric_1>;
8+
9+
__overlay__ {
10+
11+
// This label should cause an error when the overlay
12+
// is applied. There is already a phandle value
13+
// in the base tree for motor-1.
14+
spin_ctrl_1_conflict: motor-1 {
15+
accelerate = < 3 >;
16+
decelerate = < 5 >;
17+
};
18+
};
19+
};
20+
};
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/dts-v1/;
2+
/plugin/;
3+
4+
/*
5+
* Base device tree that overlays will be applied against.
6+
*
7+
* Do not add any properties in node "/".
8+
* Do not add any nodes other than "/testcase-data-2" in node "/".
9+
* Do not add anything that would result in dtc creating node "/__fixups__".
10+
* dtc will create nodes "/__symbols__" and "/__local_fixups__".
11+
*/
12+
13+
/ {
14+
testcase-data-2 {
15+
#address-cells = <1>;
16+
#size-cells = <1>;
17+
18+
electric_1: substation@100 {
19+
compatible = "ot,big-volts-control";
20+
reg = < 0x00000100 0x100 >;
21+
status = "disabled";
22+
23+
hvac_1: hvac-medium-1 {
24+
compatible = "ot,hvac-medium";
25+
heat-range = < 50 75 >;
26+
cool-range = < 60 80 >;
27+
};
28+
29+
spin_ctrl_1: motor-1 {
30+
compatible = "ot,ferris-wheel-motor";
31+
spin = "clockwise";
32+
};
33+
34+
spin_ctrl_2: motor-8 {
35+
compatible = "ot,roller-coaster-motor";
36+
};
37+
};
38+
39+
rides_1: fairway-1 {
40+
#address-cells = <1>;
41+
#size-cells = <1>;
42+
compatible = "ot,rides";
43+
status = "disabled";
44+
orientation = < 127 >;
45+
46+
ride@100 {
47+
compatible = "ot,roller-coaster";
48+
reg = < 0x00000100 0x100 >;
49+
hvac-provider = < &hvac_1 >;
50+
hvac-thermostat = < 29 > ;
51+
hvac-zones = < 14 >;
52+
hvac-zone-names = "operator";
53+
spin-controller = < &spin_ctrl_2 5 &spin_ctrl_2 7 >;
54+
spin-controller-names = "track_1", "track_2";
55+
queues = < 2 >;
56+
};
57+
};
58+
59+
lights_1: lights@30000 {
60+
compatible = "ot,work-lights";
61+
reg = < 0x00030000 0x1000 >;
62+
status = "disabled";
63+
};
64+
65+
lights_2: lights@40000 {
66+
compatible = "ot,show-lights";
67+
reg = < 0x00040000 0x1000 >;
68+
status = "disabled";
69+
rate = < 13 138 >;
70+
};
71+
72+
retail_1: vending@50000 {
73+
reg = < 0x00050000 0x1000 >;
74+
compatible = "ot,tickets";
75+
status = "disabled";
76+
};
77+
78+
};
79+
};
80+

0 commit comments

Comments
 (0)