at v6.12-rc5 61 lines 1.3 kB view raw
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> 7 8#include <kunit/test.h> 9 10#include "of_private.h" 11 12/* 13 * Test that the root node "/" can be found by path. 14 */ 15static void of_dtb_root_node_found_by_path(struct kunit *test) 16{ 17 struct device_node *np; 18 19 np = of_find_node_by_path("/"); 20 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, np); 21 of_node_put(np); 22} 23 24/* 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. 27 */ 28static void of_dtb_root_node_populates_of_root(struct kunit *test) 29{ 30 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, of_root); 31} 32 33static 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), 36 {} 37}; 38 39static int of_dtb_test_init(struct kunit *test) 40{ 41 of_root_kunit_skip(test); 42 if (!IS_ENABLED(CONFIG_OF_EARLY_FLATTREE)) 43 kunit_skip(test, "requires CONFIG_OF_EARLY_FLATTREE"); 44 45 return 0; 46} 47 48/* 49 * Test suite to confirm a DTB is loaded. 50 */ 51static struct kunit_suite of_dtb_suite = { 52 .name = "of_dtb", 53 .test_cases = of_dtb_test_cases, 54 .init = of_dtb_test_init, 55}; 56 57kunit_test_suites( 58 &of_dtb_suite, 59); 60MODULE_DESCRIPTION("KUnit tests for OF APIs"); 61MODULE_LICENSE("GPL");