blob: 10abd210a9c085df23857c4078d8ae4fc0ad01b5 [file] [log] [blame]
Daniel Vetter87042d62014-06-13 16:23:10 +02001// Semantic patch for common patters and their replacement by igt infrastructure
2// and macros. Please run with
3//
4// spatch --sp-file lib/igt.cocci --in-place tests/*.c
5//
6// on your new testcase.
7
8
Daniel Vetter6b73a9a2014-06-13 15:32:50 +02009// Replace open-coded augmented igt_assert/skip/require with macro versions
Daniel Vetter66b31b62014-06-13 11:16:28 +020010@@
11expression Ec;
12expression list[n] Ep;
13@@
14- if (Ec) {
Daniel Vetterbde52d12014-06-13 15:41:28 +020015(
16- igt_warn( Ep );
17|
18- igt_info( Ep );
19|
20- igt_debug( Ep );
21)
Daniel Vetter66b31b62014-06-13 11:16:28 +020022- igt_fail(...);
23- }
Daniel Vetter2347e6d2014-06-13 18:01:33 +020024+ igt_fail_on_f(Ec, Ep);
25@@
26expression Ec;
27@@
28- if (Ec) {
29- igt_fail(...);
30- }
31+ igt_fail_on(Ec);
Daniel Vetter66b31b62014-06-13 11:16:28 +020032@@
33expression Ec;
34expression list[n] Ep;
35@@
36- if (Ec) {
37- igt_skip(Ep);
38- }
39+ igt_skip_on_f(Ec, Ep);
Daniel Vetter46811c82014-06-13 15:45:30 +020040@@
41expression Ec;
42expression list[n] Ep;
43@@
44- if (Ec) {
45- igt_warn(Ep);
46- }
47+ igt_warn_on_f(Ec, Ep);
Daniel Vetterbde52d12014-06-13 15:41:28 +020048
49// Enforce use of logging functions
50@@
51expression list[n] Ep;
52@@
53-fprintf(stderr, Ep);
54+igt_warn(Ep);
55@@
56expression E;
57@@
58-perror(E);
59+igt_warn(E);
60@@
61expression list[n] Ep;
62@@
63-fprintf(stdout, Ep);
64+igt_info(Ep);
65@@
66expression list[n] Ep;
67@@
68-printf(Ep);
69+igt_info(Ep);
Daniel Vetter9eb93452014-06-13 15:45:12 +020070
71// No abort for tests, really. Should only be used for internal library checks
72// in lib/*
73@@
74@@
75-abort();
Thomas Woodb47032e2015-04-09 09:24:12 +010076+igt_fail(IGT_EXIT_FAILURE);
Daniel Vetter8bf115e2014-07-11 17:41:27 +020077
78@@
79iterator name for_each_pipe;
80igt_display_t *display;
81expression pipe;
82@@
83- for (pipe = 0; pipe < igt_display_get_n_pipes(display); pipe++) {
84+ for_each_pipe (display, pipe) {
85...
86}
Daniel Vetter428060c2014-07-15 10:21:37 +020087
88// Tests really shouldn't use plain assert!
89@@
90expression E;
91@@
92- assert(E);
93+ igt_assert(E);
Ville Syrjäläe1bdab92014-11-28 11:11:17 +020094
Daniel Vetter2eca38e2015-02-07 12:37:48 +010095// Replace open-coded igt_swap()
Ville Syrjäläe1bdab92014-11-28 11:11:17 +020096@@
97type T;
98T a, b, tmp;
99@@
100- tmp = a;
101- a = b;
102- b = tmp;
Daniel Vetter2eca38e2015-02-07 12:37:48 +0100103+ igt_swap(a, b);
Ville Syrjäläe1bdab92014-11-28 11:11:17 +0200104
105// Replace open-coded min()
106@@
107expression a;
108expression b;
109@@
110(
111- ((a) < (b) ? (a) : (b))
112+ min(a, b)
113|
114- ((a) <= (b) ? (a) : (b))
115+ min(a, b)
116)
117
118// Replace open-coded max()
119@@
120expression a;
121expression b;
122@@
123(
124- ((a) > (b) ? (a) : (b))
125+ max(a, b)
126|
127- ((a) >= (b) ? (a) : (b))
128+ max(a, b)
129)
Thomas Wood032f30c2015-01-13 13:33:57 +0000130
131// drm_open_any always returns a valid file descriptor
132@@
133expression a;
134@@
135a = drm_open_any();
136(
137- igt_assert(a >= 0);
138|
139- if (a < 0) {
140- ...
141- return ...;
142- }
143)
Matt Roper07be8fe2015-03-05 15:01:00 -0800144
145// Use comparison macros instead of raw igt_assert when possible
146@@
147typedef uint32_t;
148uint32_t E1, E2;
149int E3, E4;
150@@
151(
152- igt_assert(E1 == E2);
153+ igt_assert_eq_u32(E1, E2);
154|
155- igt_assert(E1 != E2);
156+ igt_assert_neq_u32(E1, E2);
157|
158- igt_assert(E1 <= E2);
159+ igt_assert_lte_u32(E1, E2);
160|
161- igt_assert(E1 < E2);
162+ igt_assert_lt_u32(E1, E2);
163|
Daniel Stone31821fc2015-10-01 13:25:48 +0100164- igt_assert(E1 >= E2);
165+ igt_assert_lte_u32(E2, E1);
166|
167- igt_assert(E1 > E2);
168+ igt_assert_lt_u32(E2, E1);
169|
Matt Roper07be8fe2015-03-05 15:01:00 -0800170- igt_assert(E3 == E4);
171+ igt_assert_eq(E3, E4);
172|
173- igt_assert(E3 != E4);
174+ igt_assert_neq(E3, E4);
175|
176- igt_assert(E3 <= E4);
177+ igt_assert_lte(E3, E4);
178|
179- igt_assert(E3 < E4);
180+ igt_assert_lt(E3, E4);
Daniel Stone31821fc2015-10-01 13:25:48 +0100181|
182- igt_assert(E3 >= E4);
183+ igt_assert_lte(E4, E3);
184|
185- igt_assert(E3 > E4);
186+ igt_assert_lt(E4, E3);
Matt Roper07be8fe2015-03-05 15:01:00 -0800187)
Thomas Wood47f6b132015-03-25 16:42:57 +0000188
189// avoid unused-result warnings when compiling with _FORTIFY_SOURCE defined
190@@
191identifier func =~ "^(read|write)$";
192expression list[2] E;
193expression size;
194@@
195-func(E, size);
196+igt_assert_eq(func(E, size), size);
197
198@@
199expression ptr, size, nmemb, stream;
200@@
201-fread(ptr, size, nmemb, stream);
202+igt_assert_eq(fread(ptr, size, nmemb, stream), nmemb);
203
204@@
205expression list E;
206@@
207-fgets(E);
Thomas Woodaa6c6342015-05-14 16:24:01 +0100208+igt_assert(fgets(E) != NULL);
Thomas Wood47f6b132015-03-25 16:42:57 +0000209
210@@
211identifier func =~ "^v?asprintf$";
212expression list E;
213@@
214-func(E);
215+igt_assert_neq(func(E), -1);
Daniel Stone668c0532015-10-01 14:16:23 +0100216
217// replace open-coded do_ioctl
218@@
219expression a, b, c, e;
220@@
221(
222-do_or_die(drmIoctl(a, b, c));
223+do_ioctl(a, b, c);
224|
225-igt_assert(drmIoctl(a, b, c) == 0);
226+do_ioctl(a, b, c);
227|
228-igt_assert(drmIoctl(a, b, c) == -1 && errno == e);
229+do_ioctl_err(a, b, c, e);
230|
231-igt_assert(drmIoctl(a, b, c) < 0 && errno == e);
232+do_ioctl_err(a, b, c, e);
233)