litest-int.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright © 2013 Red Hat, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #include "config.h"
  24. #include <limits.h>
  25. #ifndef LITEST_INT_H
  26. #define LITEST_INT_H
  27. #include "litest.h"
  28. /* Use as designater for litest to change the value */
  29. #define LITEST_AUTO_ASSIGN INT_MIN
  30. /* Special event code to auto-assign the BTN_TOOL_PEN and friends */
  31. #define LITEST_BTN_TOOL_AUTO (KEY_MAX << 1)
  32. struct litest_test_device {
  33. struct list node; /* global test device list */
  34. enum litest_device_type type;
  35. int64_t features;
  36. const char *shortname;
  37. void (*setup)(void); /* test fixture, used by check */
  38. void (*teardown)(void); /* test fixture, used by check */
  39. /**
  40. * If create is non-NULL it will be called to initialize the device.
  41. * For such devices, no overrides are possible. If create is NULL,
  42. * the information in name, id, events, absinfo is used to
  43. * create the device instead.
  44. *
  45. * @return true if the device needs to be created by litest, false if
  46. * the device creates itself
  47. */
  48. bool (*create)(struct litest_device *d);
  49. /**
  50. * The device name. Only used when create is NULL.
  51. */
  52. const char *name;
  53. /**
  54. * The device id. Only used when create is NULL.
  55. */
  56. const struct input_id *id;
  57. /**
  58. * List of event type/code tuples, terminated with -1, e.g.
  59. * EV_REL, REL_X, EV_KEY, BTN_LEFT, -1
  60. * Special tuple is INPUT_PROP_MAX, <actual property> to set.
  61. *
  62. * Any EV_ABS codes in this list will be initialized with a default
  63. * axis range.
  64. */
  65. int *events;
  66. /**
  67. * List of abs codes to enable, with absinfo.value determining the
  68. * code to set. List must be terminated with absinfo.value -1
  69. */
  70. struct input_absinfo *absinfo;
  71. struct litest_device_interface *interface;
  72. const char *udev_rule;
  73. const char *quirk_file;
  74. const struct key_value_str udev_properties[32];
  75. };
  76. struct litest_device_interface {
  77. bool (*touch_down)(struct litest_device *d,
  78. unsigned int slot,
  79. double x,
  80. double y);
  81. bool (*touch_move)(struct litest_device *d,
  82. unsigned int slot,
  83. double x,
  84. double y);
  85. bool (*touch_up)(struct litest_device *d, unsigned int slot);
  86. /**
  87. * Default value for the given EV_ABS axis.
  88. * @return 0 on success, nonzero otherwise
  89. */
  90. int (*get_axis_default)(struct litest_device *d,
  91. unsigned int code,
  92. int32_t *value);
  93. /**
  94. * Set of of events to execute on touch down, terminated by a .type
  95. * and .code value of -1. If the event value is LITEST_AUTO_ASSIGN,
  96. * it will be automatically assigned by the framework (valid for x,
  97. * y, tracking id and slot).
  98. *
  99. * These events are only used if touch_down is NULL.
  100. */
  101. struct input_event *touch_down_events;
  102. struct input_event *touch_move_events;
  103. struct input_event *touch_up_events;
  104. /**
  105. * Tablet events, LITEST_AUTO_ASSIGN is allowed on event values for
  106. * ABS_X, ABS_Y, ABS_DISTANCE and ABS_PRESSURE.
  107. */
  108. struct input_event *tablet_proximity_in_events;
  109. struct input_event *tablet_proximity_out_events;
  110. struct input_event *tablet_motion_events;
  111. bool (*tablet_proximity_in)(struct litest_device *d,
  112. unsigned int tool_type,
  113. double *x,
  114. double *y,
  115. struct axis_replacement *axes);
  116. bool (*tablet_proximity_out)(struct litest_device *d, unsigned int tool_type);
  117. bool (*tablet_tip_down)(struct litest_device *d,
  118. double *x,
  119. double *y,
  120. struct axis_replacement *axes);
  121. bool (*tablet_tip_up)(struct litest_device *d,
  122. double *x,
  123. double *y,
  124. struct axis_replacement *axes);
  125. bool (*tablet_motion)(struct litest_device *d,
  126. double *x,
  127. double *y,
  128. struct axis_replacement *axes);
  129. /**
  130. * Pad events, LITEST_AUTO_ASSIGN is allowed on event values
  131. * for ABS_WHEEL
  132. */
  133. struct input_event *pad_ring_start_events;
  134. struct input_event *pad_ring_change_events;
  135. struct input_event *pad_ring_end_events;
  136. /**
  137. * Pad events, LITEST_AUTO_ASSIGN is allowed on event values
  138. * for ABS_WHEEL
  139. */
  140. struct input_event *pad_dial_start_events;
  141. struct input_event *pad_dial_change_events;
  142. struct input_event *pad_dial_end_events;
  143. /**
  144. * Pad events, LITEST_AUTO_ASSIGN is allowed on event values
  145. * for ABS_RX
  146. */
  147. struct input_event *pad_strip_start_events;
  148. struct input_event *pad_strip_change_events;
  149. struct input_event *pad_strip_end_events;
  150. int min[2]; /* x/y axis minimum */
  151. int max[2]; /* x/y axis maximum */
  152. unsigned int tool_type;
  153. };
  154. struct path {
  155. struct list link;
  156. char *path;
  157. int fd;
  158. };
  159. struct litest_context {
  160. struct litest_user_data *user_data;
  161. struct list paths;
  162. };
  163. struct test {
  164. struct list node;
  165. char *name;
  166. char *devname;
  167. const void *func;
  168. void *setup;
  169. void *teardown;
  170. struct range range;
  171. int rangeval;
  172. bool deviceless;
  173. struct litest_test_parameters *params;
  174. };
  175. struct suite {
  176. struct list node;
  177. struct list tests;
  178. char *name;
  179. };
  180. enum litest_runner_result
  181. litest_run(struct list *suites, int jobs);
  182. enum litest_mode {
  183. LITEST_MODE_ERROR,
  184. LITEST_MODE_TEST,
  185. LITEST_MODE_LIST,
  186. };
  187. enum litest_mode
  188. litest_parse_argv(int argc, char **argv, int *njobs_out);
  189. void
  190. litest_add_test_device(struct list *device);
  191. void
  192. litest_set_current_device(struct litest_device *device);
  193. int
  194. litest_scale(const struct litest_device *d, unsigned int axis, double val);
  195. void
  196. litest_generic_device_teardown(void);
  197. #endif