Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / of / of_test.c
blobb0557ded838fdf70f0b679c31ead38f501371304
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * KUnit tests for OF APIs
4 */
5 #include <linux/module.h>
6 #include <linux/of.h>
8 #include <kunit/test.h>
10 #include "of_private.h"
13 * Test that the root node "/" can be found by path.
15 static void of_dtb_root_node_found_by_path(struct kunit *test)
17 struct device_node *np;
19 np = of_find_node_by_path("/");
20 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, np);
21 of_node_put(np);
25 * Test that the 'of_root' global variable is always populated when DT code is
26 * enabled. Remove this test once of_root is removed from global access.
28 static void of_dtb_root_node_populates_of_root(struct kunit *test)
30 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, of_root);
33 static struct kunit_case of_dtb_test_cases[] = {
34 KUNIT_CASE(of_dtb_root_node_found_by_path),
35 KUNIT_CASE(of_dtb_root_node_populates_of_root),
39 static int of_dtb_test_init(struct kunit *test)
41 of_root_kunit_skip(test);
42 if (!IS_ENABLED(CONFIG_OF_EARLY_FLATTREE))
43 kunit_skip(test, "requires CONFIG_OF_EARLY_FLATTREE");
45 return 0;
49 * Test suite to confirm a DTB is loaded.
51 static struct kunit_suite of_dtb_suite = {
52 .name = "of_dtb",
53 .test_cases = of_dtb_test_cases,
54 .init = of_dtb_test_init,
57 kunit_test_suites(
58 &of_dtb_suite,
60 MODULE_DESCRIPTION("KUnit tests for OF APIs");
61 MODULE_LICENSE("GPL");