test.h 5.4 KB

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