1 // SPDX-License-Identifier: GPL-2.0
3 * Test managed DeviceTree APIs
7 #include <linux/of_fdt.h>
10 #include <kunit/test.h>
11 #include <kunit/resource.h>
13 #include "of_private.h"
16 * of_root_kunit_skip() - Skip test if the root node isn't populated
17 * @test: test to skip if the root node isn't populated
19 void of_root_kunit_skip(struct kunit
*test
)
21 if (IS_ENABLED(CONFIG_ARM64
) && IS_ENABLED(CONFIG_ACPI
) && !of_root
)
22 kunit_skip(test
, "arm64+acpi doesn't populate a root node");
24 EXPORT_SYMBOL_GPL(of_root_kunit_skip
);
26 #if defined(CONFIG_OF_OVERLAY) && defined(CONFIG_OF_EARLY_FLATTREE)
28 static void of_overlay_fdt_apply_kunit_exit(void *ovcs_id
)
30 of_overlay_remove(ovcs_id
);
34 * of_overlay_fdt_apply_kunit() - Test managed of_overlay_fdt_apply()
36 * @overlay_fdt: device tree overlay to apply
37 * @overlay_fdt_size: size in bytes of @overlay_fdt
38 * @ovcs_id: identifier of overlay, used to remove the overlay
40 * Just like of_overlay_fdt_apply(), except the overlay is managed by the test
41 * case and is automatically removed with of_overlay_remove() after the test
44 * Return: 0 on success, negative errno on failure
46 int of_overlay_fdt_apply_kunit(struct kunit
*test
, void *overlay_fdt
,
47 u32 overlay_fdt_size
, int *ovcs_id
)
52 of_root_kunit_skip(test
);
54 copy_id
= kunit_kmalloc(test
, sizeof(*copy_id
), GFP_KERNEL
);
58 ret
= of_overlay_fdt_apply(overlay_fdt
, overlay_fdt_size
,
65 return kunit_add_action_or_reset(test
, of_overlay_fdt_apply_kunit_exit
,
68 EXPORT_SYMBOL_GPL(of_overlay_fdt_apply_kunit
);
72 KUNIT_DEFINE_ACTION_WRAPPER(of_node_put_wrapper
, of_node_put
, struct device_node
*);
75 * of_node_put_kunit() - Test managed of_node_put()
77 * @node: node to pass to `of_node_put()`
79 * Just like of_node_put(), except the node is managed by the test case and is
80 * automatically put with of_node_put() after the test case concludes.
82 void of_node_put_kunit(struct kunit
*test
, struct device_node
*node
)
84 if (kunit_add_action(test
, of_node_put_wrapper
, node
)) {
86 "Can't allocate a kunit resource to put of_node\n");
89 EXPORT_SYMBOL_GPL(of_node_put_kunit
);
91 MODULE_LICENSE("GPL");
92 MODULE_DESCRIPTION("Test managed DeviceTree APIs");