test.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2013 Google, Inc.
  4. */
  5. #ifndef __DM_TEST_H
  6. #define __DM_TEST_H
  7. #include <dm.h>
  8. #include <test/test.h>
  9. /**
  10. * struct dm_test_cdata - configuration data for test instance
  11. *
  12. * @ping_add: Amonut to add each time we get a ping
  13. * @base: Base address of this device
  14. */
  15. struct dm_test_pdata {
  16. int ping_add;
  17. uint32_t base;
  18. };
  19. /**
  20. * struct test_ops - Operations supported by the test device
  21. *
  22. * @ping: Ping operation
  23. * @dev: Device to operate on
  24. * @pingval: Value to ping the device with
  25. * @pingret: Returns resulting value from driver
  26. * @return 0 if OK, -ve on error
  27. */
  28. struct test_ops {
  29. int (*ping)(struct udevice *dev, int pingval, int *pingret);
  30. };
  31. /* Operations that our test driver supports */
  32. enum {
  33. DM_TEST_OP_BIND = 0,
  34. DM_TEST_OP_UNBIND,
  35. DM_TEST_OP_PROBE,
  36. DM_TEST_OP_REMOVE,
  37. /* For uclass */
  38. DM_TEST_OP_POST_BIND,
  39. DM_TEST_OP_PRE_UNBIND,
  40. DM_TEST_OP_PRE_PROBE,
  41. DM_TEST_OP_POST_PROBE,
  42. DM_TEST_OP_PRE_REMOVE,
  43. DM_TEST_OP_INIT,
  44. DM_TEST_OP_DESTROY,
  45. DM_TEST_OP_COUNT,
  46. };
  47. /* Test driver types */
  48. enum {
  49. DM_TEST_TYPE_FIRST = 0,
  50. DM_TEST_TYPE_SECOND,
  51. };
  52. /* The number added to the ping total on each probe */
  53. #define DM_TEST_START_TOTAL 5
  54. /**
  55. * struct dm_test_priv - private data for the test devices
  56. */
  57. struct dm_test_priv {
  58. int ping_total;
  59. int op_count[DM_TEST_OP_COUNT];
  60. int uclass_flag;
  61. int uclass_total;
  62. int uclass_postp;
  63. };
  64. /**
  65. * struct dm_test_perdev_class_priv - private per-device data for test uclass
  66. */
  67. struct dm_test_uclass_perdev_priv {
  68. int base_add;
  69. };
  70. /**
  71. * struct dm_test_uclass_priv - private data for test uclass
  72. */
  73. struct dm_test_uclass_priv {
  74. int total_add;
  75. };
  76. /**
  77. * struct dm_test_parent_data - parent's information on each child
  78. *
  79. * @sum: Test value used to check parent data works correctly
  80. * @flag: Used to track calling of parent operations
  81. * @uclass_flag: Used to track calling of parent operations by uclass
  82. */
  83. struct dm_test_parent_data {
  84. int sum;
  85. int flag;
  86. };
  87. /* Test values for test device's uclass platform data */
  88. enum {
  89. TEST_UC_PDATA_INTVAL1 = 2,
  90. TEST_UC_PDATA_INTVAL2 = 334,
  91. TEST_UC_PDATA_INTVAL3 = 789452,
  92. };
  93. /**
  94. * struct dm_test_uclass_platda - uclass's information on each device
  95. *
  96. * @intval1: set to TEST_UC_PDATA_INTVAL1 in .post_bind method of test uclass
  97. * @intval2: set to TEST_UC_PDATA_INTVAL2 in .post_bind method of test uclass
  98. * @intval3: set to TEST_UC_PDATA_INTVAL3 in .post_bind method of test uclass
  99. */
  100. struct dm_test_perdev_uc_pdata {
  101. int intval1;
  102. int intval2;
  103. int intval3;
  104. };
  105. /*
  106. * Operation counts for the test driver, used to check that each method is
  107. * called correctly
  108. */
  109. extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
  110. extern struct unit_test_state global_dm_test_state;
  111. /*
  112. * struct dm_test_state - Entire state of dm test system
  113. *
  114. * This is often abreviated to dms.
  115. *
  116. * @root: Root device
  117. * @testdev: Test device
  118. * @force_fail_alloc: Force all memory allocs to fail
  119. * @skip_post_probe: Skip uclass post-probe processing
  120. * @removed: Used to keep track of a device that was removed
  121. */
  122. struct dm_test_state {
  123. struct udevice *root;
  124. struct udevice *testdev;
  125. int force_fail_alloc;
  126. int skip_post_probe;
  127. struct udevice *removed;
  128. };
  129. /* Test flags for each test */
  130. enum {
  131. DM_TESTF_SCAN_PDATA = 1 << 0, /* test needs platform data */
  132. DM_TESTF_PROBE_TEST = 1 << 1, /* probe test uclass */
  133. DM_TESTF_SCAN_FDT = 1 << 2, /* scan device tree */
  134. DM_TESTF_FLAT_TREE = 1 << 3, /* test needs flat DT */
  135. DM_TESTF_LIVE_TREE = 1 << 4, /* needs live device tree */
  136. };
  137. /* Declare a new driver model test */
  138. #define DM_TEST(_name, _flags) UNIT_TEST(_name, _flags, dm_test)
  139. /* This platform data is needed in tests, so declare it here */
  140. struct sandbox_sdl_plat {
  141. int xres;
  142. int yres;
  143. int bpix;
  144. int rot;
  145. const char *vidconsole_drv_name;
  146. int font_size;
  147. };
  148. /* Declare ping methods for the drivers */
  149. int test_ping(struct udevice *dev, int pingval, int *pingret);
  150. int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
  151. /**
  152. * dm_check_operations() - Check that we can perform ping operations
  153. *
  154. * This checks that the ping operations work as expected for a device
  155. *
  156. * @dms: Overall test state
  157. * @dev: Device to test
  158. * @base: Base address, used to check ping return value
  159. * @priv: Pointer to private test information
  160. * @return 0 if OK, -ve on error
  161. */
  162. int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
  163. uint32_t base, struct dm_test_priv *priv);
  164. /**
  165. * dm_check_devices() - check the devices respond to operations correctly
  166. *
  167. * @dms: Overall test state
  168. * @num_devices: Number of test devices to check
  169. * @return 0 if OK, -ve on error
  170. */
  171. int dm_check_devices(struct unit_test_state *uts, int num_devices);
  172. /**
  173. * dm_leak_check_start() - Prepare to check for a memory leak
  174. *
  175. * Call this before allocating memory to record the amount of memory being
  176. * used.
  177. *
  178. * @dms: Overall test state
  179. */
  180. void dm_leak_check_start(struct unit_test_state *uts);
  181. /**
  182. * dm_leak_check_end() - Check that no memory has leaked
  183. *
  184. * Call this after dm_leak_check_start() and after you have hopefuilly freed
  185. * all the memory that was allocated. This function will print an error if
  186. * it sees a different amount of total memory allocated than before.
  187. *
  188. * @dms: Overall test state
  189. */int dm_leak_check_end(struct unit_test_state *uts);
  190. #endif