Debian Codegraph @

test/litest-int.h

raw
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
24 #include "config.h"
25
26 #include <limits.h>
27
28 #ifndef LITEST_INT_H
29 #define LITEST_INT_H
30 #include "litest.h"
31
32 /* Use as designater for litest to change the value */
33 #define LITEST_AUTO_ASSIGN INT_MIN
34
35 /* Special event code to auto-assign the BTN_TOOL_PEN and friends */
36 #define LITEST_BTN_TOOL_AUTO (KEY_MAX << 1)
37
38 struct litest_test_device {
39 struct list node; /* global test device list */
40
41 enum litest_device_type type;
42 int64_t features;
43 const char *shortname;
44 void (*setup)(void); /* test fixture, used by check */
45 void (*teardown)(void); /* test fixture, used by check */
46 /**
47 * If create is non-NULL it will be called to initialize the device.
48 * For such devices, no overrides are possible. If create is NULL,
49 * the information in name, id, events, absinfo is used to
50 * create the device instead.
51 *
52 * @return true if the device needs to be created by litest, false if
53 * the device creates itself
54 */
55 bool (*create)(struct litest_device *d);
56
57 /**
58 * The device name. Only used when create is NULL.
59 */
60 const char *name;
61 /**
62 * The device id. Only used when create is NULL.
63 */
64 const struct input_id *id;
65 /**
66 * List of event type/code tuples, terminated with -1, e.g.
67 * EV_REL, REL_X, EV_KEY, BTN_LEFT, -1
68 * Special tuple is INPUT_PROP_MAX, <actual property> to set.
69 *
70 * Any EV_ABS codes in this list will be initialized with a default
71 * axis range.
72 */
73 int *events;
74 /**
75 * List of abs codes to enable, with absinfo.value determining the
76 * code to set. List must be terminated with absinfo.value -1
77 */
78 struct input_absinfo *absinfo;
79 struct litest_device_interface *interface;
80
81 const char *udev_rule;
82 const char *quirk_file;
83
84 const struct key_value_str udev_properties[32];
85 };
86
87 struct litest_device_interface {
88 bool (*touch_down)(struct litest_device *d,
89 unsigned int slot,
90 double x,
91 double y);
92 bool (*touch_move)(struct litest_device *d,
93 unsigned int slot,
94 double x,
95 double y);
96 bool (*touch_up)(struct litest_device *d, unsigned int slot);
97
98 /**
99 * Default value for the given EV_ABS axis.
100 * @return 0 on success, nonzero otherwise
101 */
102 int (*get_axis_default)(struct litest_device *d,
103 unsigned int code,
104 int32_t *value);
105
106 /**
107 * Set of of events to execute on touch down, terminated by a .type
108 * and .code value of -1. If the event value is LITEST_AUTO_ASSIGN,
109 * it will be automatically assigned by the framework (valid for x,
110 * y, tracking id and slot).
111 *
112 * These events are only used if touch_down is NULL.
113 */
114 struct input_event *touch_down_events;
115 struct input_event *touch_move_events;
116 struct input_event *touch_up_events;
117
118 /**
119 * Tablet events, LITEST_AUTO_ASSIGN is allowed on event values for
120 * ABS_X, ABS_Y, ABS_DISTANCE and ABS_PRESSURE.
121 */
122 struct input_event *tablet_proximity_in_events;
123 struct input_event *tablet_proximity_out_events;
124 struct input_event *tablet_motion_events;
125
126 bool (*tablet_proximity_in)(struct litest_device *d,
127 unsigned int tool_type,
128 double *x,
129 double *y,
130 struct axis_replacement *axes);
131 bool (*tablet_proximity_out)(struct litest_device *d, unsigned int tool_type);
132 bool (*tablet_tip_down)(struct litest_device *d,
133 double *x,
134 double *y,
135 struct axis_replacement *axes);
136 bool (*tablet_tip_up)(struct litest_device *d,
137 double *x,
138 double *y,
139 struct axis_replacement *axes);
140 bool (*tablet_motion)(struct litest_device *d,
141 double *x,
142 double *y,
143 struct axis_replacement *axes);
144
145 /**
146 * Pad events, LITEST_AUTO_ASSIGN is allowed on event values
147 * for ABS_WHEEL
148 */
149 struct input_event *pad_ring_start_events;
150 struct input_event *pad_ring_change_events;
151 struct input_event *pad_ring_end_events;
152
153 /**
154 * Pad events, LITEST_AUTO_ASSIGN is allowed on event values
155 * for ABS_WHEEL
156 */
157 struct input_event *pad_dial_start_events;
158 struct input_event *pad_dial_change_events;
159 struct input_event *pad_dial_end_events;
160
161 /**
162 * Pad events, LITEST_AUTO_ASSIGN is allowed on event values
163 * for ABS_RX
164 */
165 struct input_event *pad_strip_start_events;
166 struct input_event *pad_strip_change_events;
167 struct input_event *pad_strip_end_events;
168
169 int min[2]; /* x/y axis minimum */
170 int max[2]; /* x/y axis maximum */
171
172 unsigned int tool_type;
173 };
174
175 struct path {
176 struct list link;
177 char *path;
178 int fd;
179 };
180
181 struct litest_context {
182 struct litest_user_data *user_data;
183 struct list paths;
184 };
185
186 struct test {
187 struct list node;
188 char *name;
189 char *devname;
190 const void *func;
191 void *setup;
192 void *teardown;
193
194 struct range range;
195 int rangeval;
196 bool deviceless;
197
198 struct litest_test_parameters *params;
199 };
200
201 struct suite {
202 struct list node;
203 struct list tests;
204 char *name;
205 };
206
207 enum litest_runner_result
208 litest_run(struct list *suites, int jobs);
209
210 enum litest_mode {
211 LITEST_MODE_ERROR,
212 LITEST_MODE_TEST,
213 LITEST_MODE_LIST,
214 };
215 enum litest_mode
216 litest_parse_argv(int argc, char **argv, int *njobs_out);
217 void
218 litest_add_test_device(struct list *device);
219
220 void
221 litest_set_current_device(struct litest_device *device);
222 int
223 litest_scale(const struct litest_device *d, unsigned int axis, double val);
224 void
225 litest_generic_device_teardown(void);
226
227 #endif