summaryrefslogtreecommitdiff
path: root/lib/igt.cocci
blob: 0d337bf734cfff3d938ff331ca573d02ee495039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Semantic patch for common patters and their replacement by igt infrastructure
// and macros. Please run with
//
// spatch --sp-file lib/igt.cocci --in-place tests/*.c
//
// on your new testcase.


// Replace open-coded augmented igt_assert/skip/require with macro versions
@@
expression Ec;
expression list[n] Ep;
@@
- if (Ec) {
(
- igt_warn( Ep );
|
- igt_info( Ep );
|
- igt_debug( Ep );
)
- igt_fail(...);
- }
+ igt_fail_on_f(Ec, Ep);
@@
expression Ec;
@@
- if (Ec) {
- igt_fail(...);
- }
+ igt_fail_on(Ec);
@@
expression Ec;
expression list[n] Ep;
@@
- if (Ec) {
- igt_skip(Ep);
- }
+ igt_skip_on_f(Ec, Ep);
@@
expression Ec;
expression list[n] Ep;
@@
- if (Ec) {
- igt_warn(Ep);
- }
+ igt_warn_on_f(Ec, Ep);

// Enforce use of logging functions
@@
expression list[n] Ep;
@@
-fprintf(stderr, Ep);
+igt_warn(Ep);
@@
expression E;
@@
-perror(E);
+igt_warn(E);
@@
expression list[n] Ep;
@@
-fprintf(stdout, Ep);
+igt_info(Ep);
@@
expression list[n] Ep;
@@
-printf(Ep);
+igt_info(Ep);

// No abort for tests, really. Should only be used for internal library checks
// in lib/*
@@
@@
-abort();
+igt_fail(1);

@@
iterator name for_each_pipe;
igt_display_t *display;
expression pipe;
@@
- for (pipe = 0; pipe < igt_display_get_n_pipes(display); pipe++) {
+ for_each_pipe (display, pipe) {
...
}

// Tests really shouldn't use plain assert!
@@
expression E;
@@
- assert(E);
+ igt_assert(E);

// Replace open-coded swap()
@@
type T;
T a, b, tmp;
@@
- tmp = a;
- a = b;
- b = tmp;
+ swap(a, b);

// Replace open-coded min()
@@
expression a;
expression b;
@@
(
- ((a) < (b) ? (a) : (b))
+ min(a, b)
|
- ((a) <= (b) ? (a) : (b))
+ min(a, b)
)

// Replace open-coded max()
@@
expression a;
expression b;
@@
(
- ((a) > (b) ? (a) : (b))
+ max(a, b)
|
- ((a) >= (b) ? (a) : (b))
+ max(a, b)
)