of_test.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #include <kunit/test.h>
  8. #include "of_private.h"
  9. /*
  10. * Test that the root node "/" can be found by path.
  11. */
  12. static void of_dtb_root_node_found_by_path(struct kunit *test)
  13. {
  14. struct device_node *np;
  15. np = of_find_node_by_path("/");
  16. KUNIT_EXPECT_NOT_ERR_OR_NULL(test, np);
  17. of_node_put(np);
  18. }
  19. /*
  20. * Test that the 'of_root' global variable is always populated when DT code is
  21. * enabled. Remove this test once of_root is removed from global access.
  22. */
  23. static void of_dtb_root_node_populates_of_root(struct kunit *test)
  24. {
  25. KUNIT_EXPECT_NOT_ERR_OR_NULL(test, of_root);
  26. }
  27. static struct kunit_case of_dtb_test_cases[] = {
  28. KUNIT_CASE(of_dtb_root_node_found_by_path),
  29. KUNIT_CASE(of_dtb_root_node_populates_of_root),
  30. {}
  31. };
  32. static int of_dtb_test_init(struct kunit *test)
  33. {
  34. of_root_kunit_skip(test);
  35. if (!IS_ENABLED(CONFIG_OF_EARLY_FLATTREE))
  36. kunit_skip(test, "requires CONFIG_OF_EARLY_FLATTREE");
  37. return 0;
  38. }
  39. /*
  40. * Test suite to confirm a DTB is loaded.
  41. */
  42. static struct kunit_suite of_dtb_suite = {
  43. .name = "of_dtb",
  44. .test_cases = of_dtb_test_cases,
  45. .init = of_dtb_test_init,
  46. };
  47. kunit_test_suites(
  48. &of_dtb_suite,
  49. );
  50. MODULE_DESCRIPTION("KUnit tests for OF APIs");
  51. MODULE_LICENSE("GPL");