1 /* SPDX-License-Identifier: GPL-2.0 */ 1 2 #ifndef _KUNIT_OF_H 3 #define _KUNIT_OF_H 4 5 #include <kunit/test.h> 6 7 struct device_node; 8 9 #ifdef CONFIG_OF 10 11 void of_node_put_kunit(struct kunit *test, str 12 13 #else 14 15 static inline 16 void of_node_put_kunit(struct kunit *test, str 17 { 18 kunit_skip(test, "requires CONFIG_OF") 19 } 20 21 #endif /* !CONFIG_OF */ 22 23 #if defined(CONFIG_OF) && defined(CONFIG_OF_OV 24 25 int of_overlay_fdt_apply_kunit(struct kunit *t 26 u32 overlay_fdt 27 #else 28 29 static inline int 30 of_overlay_fdt_apply_kunit(struct kunit *test, 31 u32 overlay_fdt_siz 32 { 33 kunit_skip(test, "requires CONFIG_OF a 34 return -EINVAL; 35 } 36 37 #endif 38 39 /** 40 * __of_overlay_apply_kunit() - Test managed o 41 * @test: test context 42 * @overlay_begin: start address of overlay to 43 * @overlay_end: end address of overlay to app 44 * 45 * This is mostly internal API. See of_overlay 46 * that makes this easier to use. 47 * 48 * Similar to of_overlay_fdt_apply(), except t 49 * case and is automatically removed with of_o 50 * case concludes. 51 * 52 * Return: 0 on success, negative errno on fai 53 */ 54 static inline int __of_overlay_apply_kunit(str 55 u8 56 con 57 { 58 int unused; 59 60 return of_overlay_fdt_apply_kunit(test 61 over 62 &unu 63 } 64 65 /** 66 * of_overlay_apply_kunit() - Test managed of_ 67 * @test: test context 68 * @overlay_name: name of overlay to apply 69 * 70 * This macro is used to apply a device tree o 71 * cmd_dt_S_dtbo rule in scripts/Makefile.lib 72 * kernel image or KUnit test module. The over 73 * the test is finished. 74 * 75 * Unit tests that need device tree nodes shou 76 * @overlay_name\.dtbo.o in their Makefile alo 77 * load the overlay during their test. The @ov 78 * of the overlay without the dtbo filename ex 79 * not enabled, the @test will be skipped. 80 * 81 * In the Makefile 82 * 83 * .. code-block:: none 84 * 85 * obj-$(CONFIG_OF_OVERLAY_KUNIT_TEST) += 86 * 87 * In the test 88 * 89 * .. code-block:: c 90 * 91 * static void of_overlay_kunit_of_overla 92 * { 93 * struct device_node *np; 94 * 95 * KUNIT_ASSERT_EQ(test, 0, 96 * of_overlay_app 97 * 98 * np = of_find_node_by_name(NULL 99 * KUNIT_EXPECT_NOT_ERR_OR_NULL(t 100 * of_node_put(np); 101 * } 102 * 103 * Return: 0 on success, negative errno on fai 104 */ 105 #define of_overlay_apply_kunit(test, overlay_n 106 ({ 107 extern uint8_t __dtbo_##overlay_name## 108 extern uint8_t __dtbo_##overlay_name## 109 110 __of_overlay_apply_kunit((test), 111 __dtbo_##overlay_name# 112 __dtbo_##overlay_name# 113 }) 114 115 #endif 116
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.