test.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2013 Google, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef __DM_TEST_H
  7. #define __DM_TEST_H
  8. #include <dm.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 device *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_POST_PROBE,
  41. DM_TEST_OP_PRE_REMOVE,
  42. DM_TEST_OP_INIT,
  43. DM_TEST_OP_DESTROY,
  44. DM_TEST_OP_COUNT,
  45. };
  46. /* Test driver types */
  47. enum {
  48. DM_TEST_TYPE_FIRST = 0,
  49. DM_TEST_TYPE_SECOND,
  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. };
  60. /**
  61. * struct dm_test_perdev_class_priv - private per-device data for test uclass
  62. */
  63. struct dm_test_uclass_perdev_priv {
  64. int base_add;
  65. };
  66. /**
  67. * struct dm_test_uclass_priv - private data for test uclass
  68. */
  69. struct dm_test_uclass_priv {
  70. int total_add;
  71. };
  72. /*
  73. * Operation counts for the test driver, used to check that each method is
  74. * called correctly
  75. */
  76. extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
  77. extern struct dm_test_state global_test_state;
  78. /*
  79. * struct dm_test_state - Entire state of dm test system
  80. *
  81. * This is often abreviated to dms.
  82. *
  83. * @root: Root device
  84. * @testdev: Test device
  85. * @fail_count: Number of tests that failed
  86. * @force_fail_alloc: Force all memory allocs to fail
  87. * @skip_post_probe: Skip uclass post-probe processing
  88. */
  89. struct dm_test_state {
  90. struct device *root;
  91. struct device *testdev;
  92. int fail_count;
  93. int force_fail_alloc;
  94. int skip_post_probe;
  95. };
  96. /* Test flags for each test */
  97. enum {
  98. DM_TESTF_SCAN_PDATA = 1 << 0, /* test needs platform data */
  99. DM_TESTF_PROBE_TEST = 1 << 1, /* probe test uclass */
  100. DM_TESTF_SCAN_FDT = 1 << 2, /* scan device tree */
  101. };
  102. /**
  103. * struct dm_test - Information about a driver model test
  104. *
  105. * @name: Name of test
  106. * @func: Function to call to perform test
  107. * @flags: Flags indicated pre-conditions for test
  108. */
  109. struct dm_test {
  110. const char *name;
  111. int (*func)(struct dm_test_state *dms);
  112. int flags;
  113. };
  114. /* Declare a new driver model test */
  115. #define DM_TEST(_name, _flags) \
  116. ll_entry_declare(struct dm_test, _name, dm_test) = { \
  117. .name = #_name, \
  118. .flags = _flags, \
  119. .func = _name, \
  120. }
  121. /* Declare ping methods for the drivers */
  122. int test_ping(struct device *dev, int pingval, int *pingret);
  123. int testfdt_ping(struct device *dev, int pingval, int *pingret);
  124. /**
  125. * dm_check_operations() - Check that we can perform ping operations
  126. *
  127. * This checks that the ping operations work as expected for a device
  128. *
  129. * @dms: Overall test state
  130. * @dev: Device to test
  131. * @base: Base address, used to check ping return value
  132. * @priv: Pointer to private test information
  133. * @return 0 if OK, -ve on error
  134. */
  135. int dm_check_operations(struct dm_test_state *dms, struct device *dev,
  136. uint32_t base, struct dm_test_priv *priv);
  137. /**
  138. * dm_test_main() - Run all the tests
  139. *
  140. * This runs all available driver model tests
  141. *
  142. * @return 0 if OK, -ve on error
  143. */
  144. int dm_test_main(void);
  145. #endif