test.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2013 Google, Inc.
  4. */
  5. #ifndef __TEST_TEST_H
  6. #define __TEST_TEST_H
  7. #include <malloc.h>
  8. #include <linux/bitops.h>
  9. /*
  10. * struct unit_test_state - Entire state of test system
  11. *
  12. * @fail_count: Number of tests that failed
  13. * @start: Store the starting mallinfo when doing leak test
  14. * @priv: A pointer to some other info some suites want to track
  15. * @of_root: Record of the livetree root node (used for setting up tests)
  16. * @expect_str: Temporary string used to hold expected string value
  17. * @actual_str: Temporary string used to hold actual string value
  18. */
  19. struct unit_test_state {
  20. int fail_count;
  21. struct mallinfo start;
  22. void *priv;
  23. struct device_node *of_root;
  24. char expect_str[256];
  25. char actual_str[256];
  26. };
  27. /* Test flags for each test */
  28. enum {
  29. UT_TESTF_SCAN_PDATA = BIT(0), /* test needs platform data */
  30. UT_TESTF_PROBE_TEST = BIT(1), /* probe test uclass */
  31. UT_TESTF_SCAN_FDT = BIT(2), /* scan device tree */
  32. UT_TESTF_FLAT_TREE = BIT(3), /* test needs flat DT */
  33. UT_TESTF_LIVE_TREE = BIT(4), /* needs live device tree */
  34. };
  35. /**
  36. * struct unit_test - Information about a unit test
  37. *
  38. * @name: Name of test
  39. * @func: Function to call to perform test
  40. * @flags: Flags indicated pre-conditions for test
  41. */
  42. struct unit_test {
  43. const char *file;
  44. const char *name;
  45. int (*func)(struct unit_test_state *state);
  46. int flags;
  47. };
  48. /**
  49. * UNIT_TEST() - create linker generated list entry for unit a unit test
  50. *
  51. * The macro UNIT_TEST() is used to create a linker generated list entry. These
  52. * list entries are enumerate tests that can be execute using the ut command.
  53. * The list entries are used both by the implementation of the ut command as
  54. * well as in a related Python test.
  55. *
  56. * For Python testing the subtests are collected in Python function
  57. * generate_ut_subtest() by applying a regular expression to the lines of file
  58. * u-boot.sym. The list entries have to follow strict naming conventions to be
  59. * matched by the expression.
  60. *
  61. * Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in test suite
  62. * foo that can be executed via command 'ut foo bar' and is implemented in
  63. * function foo_test_bar().
  64. *
  65. * @_name: concatenation of name of the test suite, "_test_", and the name
  66. * of the test
  67. * @_flags: an integer field that can be evaluated by the test suite
  68. * implementation
  69. * @_suite: name of the test suite concatenated with "_test"
  70. */
  71. #define UNIT_TEST(_name, _flags, _suite) \
  72. ll_entry_declare(struct unit_test, _name, _suite) = { \
  73. .file = __FILE__, \
  74. .name = #_name, \
  75. .flags = _flags, \
  76. .func = _name, \
  77. }
  78. /* Sizes for devres tests */
  79. enum {
  80. TEST_DEVRES_SIZE = 100,
  81. TEST_DEVRES_COUNT = 10,
  82. TEST_DEVRES_TOTAL = TEST_DEVRES_SIZE * TEST_DEVRES_COUNT,
  83. /* A few different sizes */
  84. TEST_DEVRES_SIZE2 = 15,
  85. TEST_DEVRES_SIZE3 = 37,
  86. };
  87. #endif /* __TEST_TEST_H */