]>
Commit | Line | Data |
---|---|---|
3267343a BP |
1 | AT_BANNER([checkpatch]) |
2 | ||
3 | OVS_START_SHELL_HELPERS | |
4 | # try_checkpatch PATCH [ERRORS] | |
5 | # | |
1ca0323e BP |
6 | # Runs checkpatch, if installed, on the given PATCH, expecting the |
7 | # specified set of ERRORS (and warnings). | |
3267343a | 8 | try_checkpatch() { |
3267343a BP |
9 | # Take the patch to test from $1. Remove an initial four-space indent |
10 | # from it and, if it is just headers with no body, add a null body. | |
11 | echo "$1" | sed 's/^ //' > test.patch | |
12 | if grep '---' expout >/dev/null 2>&1; then : | |
13 | else | |
14 | printf '\n---\n' >> test.patch | |
15 | fi | |
16 | ||
17 | # Take expected output from $2. | |
18 | if test -n "$2"; then | |
19 | echo "$2" | sed 's/^ //' > expout | |
20 | else | |
21 | : > expout | |
22 | fi | |
23 | ||
1ca0323e BP |
24 | if test -s expout; then |
25 | AT_CHECK([$PYTHON3 $top_srcdir/utilities/checkpatch.py -q test.patch], | |
241bc88a | 26 | [1], [stdout]) |
3267343a BP |
27 | AT_CHECK([sed '/^Lines checked:/,$d' stdout], [0], [expout]) |
28 | else | |
1ca0323e | 29 | AT_CHECK([$PYTHON3 $top_srcdir/utilities/checkpatch.py -q test.patch]) |
3267343a BP |
30 | fi |
31 | } | |
32 | OVS_END_SHELL_HELPERS | |
33 | ||
34 | AT_SETUP([checkpatch - sign-offs]) | |
35 | ||
36 | # Sign-off for single author who is also the committer. | |
37 | try_checkpatch \ | |
38 | "Author: A | |
39 | Commit: A | |
40 | ||
41 | Signed-off-by: A" | |
42 | try_checkpatch \ | |
43 | "Author: A | |
44 | Commit: A" \ | |
45 | "ERROR: Author A needs to sign off." | |
46 | ||
3bd2e465 BP |
47 | # Single author but somehow the mailing list is the author. |
48 | try_checkpatch \ | |
49 | "Author: Foo Bar via dev <ovs-dev@openvswitch.org> | |
50 | Commit: A | |
51 | ||
52 | Signed-off-by: A" \ | |
53 | "ERROR: Author should not be mailing list." | |
54 | ||
3267343a BP |
55 | # Sign-off for single author and different committer. |
56 | try_checkpatch \ | |
57 | "Author: A | |
58 | Commit: B | |
59 | ||
60 | Signed-off-by: A | |
61 | Signed-off-by: B" | |
62 | try_checkpatch \ | |
63 | "Author: A | |
64 | Commit: B" \ | |
65 | "ERROR: Author A needs to sign off. | |
66 | ERROR: Committer B needs to sign off." | |
67 | ||
68 | # Sign-off for multiple authors with one author also the committer. | |
69 | try_checkpatch \ | |
70 | "Author: A | |
71 | Commit: A | |
72 | ||
73 | Signed-off-by: A | |
74 | Co-authored-by: B | |
75 | Signed-off-by: B" | |
76 | try_checkpatch \ | |
77 | "Author: A | |
78 | Commit: A | |
79 | ||
80 | Co-authored-by: B | |
81 | Signed-off-by: B" \ | |
82 | "ERROR: Author A needs to sign off." | |
83 | try_checkpatch \ | |
84 | "Author: A | |
85 | Commit: A | |
86 | ||
87 | Signed-off-by: A | |
88 | Co-authored-by: B" \ | |
89 | "ERROR: Co-author B needs to sign off." | |
90 | try_checkpatch \ | |
91 | "Author: A | |
92 | Commit: A | |
93 | ||
94 | Co-authored-by: B" \ | |
95 | "ERROR: Author A needs to sign off. | |
96 | ERROR: Co-author B needs to sign off." | |
97 | ||
98 | # Sign-off for multiple authors and separate committer. | |
99 | try_checkpatch \ | |
100 | "Author: A | |
101 | Commit: C | |
102 | ||
103 | Signed-off-by: A | |
104 | Co-authored-by: B | |
105 | Signed-off-by: B | |
106 | Signed-off-by: C" | |
107 | try_checkpatch \ | |
108 | "Author: A | |
109 | Commit: C | |
110 | ||
111 | Signed-off-by: A | |
112 | Co-authored-by: B | |
113 | Signed-off-by: B" \ | |
114 | "ERROR: Committer C needs to sign off." | |
115 | ||
116 | # Extra sign-offs: | |
117 | # | |
118 | # - If we know the committer, one extra sign-off raises a warning. | |
119 | # | |
120 | # - If we do not know the committer, two extra sign-offs raise a warning. | |
121 | try_checkpatch \ | |
122 | "Author: A | |
123 | Commit: C | |
124 | ||
125 | Signed-off-by: A | |
126 | Co-authored-by: B | |
127 | Signed-off-by: B | |
128 | Signed-off-by: C | |
129 | Signed-off-by: D" \ | |
130 | "WARNING: Unexpected sign-offs from developers who are not authors or co-authors or committers: D" | |
131 | try_checkpatch \ | |
132 | "Author: A | |
133 | ||
134 | Signed-off-by: A | |
135 | Co-authored-by: B | |
136 | Signed-off-by: B | |
137 | Signed-off-by: C" | |
138 | try_checkpatch \ | |
139 | "Author: A | |
140 | ||
141 | Signed-off-by: A | |
142 | Co-authored-by: B | |
143 | Signed-off-by: B | |
144 | Signed-off-by: C | |
145 | Signed-off-by: D" \ | |
146 | "WARNING: Unexpected sign-offs from developers who are not authors or co-authors or committers: C, D" | |
147 | ||
148 | # Missing committer is OK, missing author is an error. | |
149 | try_checkpatch \ | |
150 | "Author: A | |
151 | ||
152 | Signed-off-by: A" | |
153 | try_checkpatch \ | |
154 | "Commit: A | |
155 | ||
156 | Signed-off-by: A" \ | |
157 | "ERROR: Patch lacks author." | |
158 | ||
159 | AT_CLEANUP | |
16770c6d | 160 | |
74920866 IM |
161 | |
162 | m4_define([COMMON_PATCH_HEADER], [dnl | |
163 | Author: A | |
164 | ||
16770c6d BS |
165 | Signed-off-by: A |
166 | --- | |
167 | diff --git a/A.c b/A.c | |
168 | index 0000000..1111111 100644 | |
169 | --- a/A.c | |
170 | +++ b/A.c | |
74920866 IM |
171 | @@ -1,1 +1,1 @@]) |
172 | ||
173 | ||
174 | AT_SETUP([checkpatch - parenthesized constructs]) | |
df8c04b1 | 175 | for ctr in 'if' 'while' 'switch' 'HMAP_FOR_EACH' 'BITMAP_FOR_EACH_1'; do |
74920866 IM |
176 | try_checkpatch \ |
177 | "COMMON_PATCH_HEADER | |
16770c6d BS |
178 | + $ctr (first_run) { |
179 | " | |
180 | ||
181 | try_checkpatch \ | |
74920866 | 182 | "COMMON_PATCH_HEADER |
16770c6d BS |
183 | + $ctr ( first_run) { |
184 | " \ | |
185 | "ERROR: Improper whitespace around control block | |
186 | #8 FILE: A.c:1: | |
187 | $ctr ( first_run) { | |
188 | " | |
189 | ||
190 | try_checkpatch \ | |
74920866 | 191 | "COMMON_PATCH_HEADER |
16770c6d BS |
192 | + $ctr (first_run ) { |
193 | " \ | |
194 | "ERROR: Inappropriate bracing around statement | |
195 | #8 FILE: A.c:1: | |
196 | $ctr (first_run ) { | |
197 | " | |
198 | ||
199 | try_checkpatch \ | |
74920866 | 200 | "COMMON_PATCH_HEADER |
16770c6d BS |
201 | + $ctr (first_run) |
202 | " \ | |
203 | "ERROR: Inappropriate bracing around statement | |
204 | #8 FILE: A.c:1: | |
205 | $ctr (first_run) | |
206 | " | |
207 | ||
208 | try_checkpatch \ | |
74920866 | 209 | "COMMON_PATCH_HEADER |
16770c6d BS |
210 | + $ctr(first_run) |
211 | " \ | |
212 | "ERROR: Improper whitespace around control block | |
213 | #8 FILE: A.c:1: | |
214 | $ctr(first_run) | |
215 | " | |
216 | ||
217 | try_checkpatch \ | |
74920866 | 218 | "COMMON_PATCH_HEADER |
16770c6d BS |
219 | + $ctr (first_run) { /* foo */ |
220 | " | |
221 | ||
222 | try_checkpatch \ | |
74920866 | 223 | "COMMON_PATCH_HEADER |
16770c6d BS |
224 | + $ctr (first_run) { \\ |
225 | " | |
aacad868 IM |
226 | |
227 | try_checkpatch \ | |
228 | "COMMON_PATCH_HEADER | |
229 | + $ctr (a) { \\ | |
230 | " | |
16770c6d BS |
231 | done |
232 | AT_CLEANUP | |
233 | ||
234 | ||
16770c6d BS |
235 | AT_SETUP([checkpatch - parenthesized constructs - for]) |
236 | try_checkpatch \ | |
74920866 | 237 | "COMMON_PATCH_HEADER |
16770c6d BS |
238 | + for (init; condition; increment) { |
239 | " | |
240 | ||
241 | try_checkpatch \ | |
74920866 | 242 | "COMMON_PATCH_HEADER |
16770c6d BS |
243 | + for ( init; condition; increment) { |
244 | " \ | |
245 | "ERROR: Improper whitespace around control block | |
246 | #8 FILE: A.c:1: | |
247 | for ( init; condition; increment) { | |
248 | " | |
249 | ||
250 | try_checkpatch \ | |
74920866 | 251 | "COMMON_PATCH_HEADER |
16770c6d BS |
252 | + for (init; condition; increment ) { |
253 | " \ | |
254 | "ERROR: Inappropriate bracing around statement | |
255 | #8 FILE: A.c:1: | |
256 | for (init; condition; increment ) { | |
257 | " | |
258 | ||
259 | try_checkpatch \ | |
74920866 | 260 | "COMMON_PATCH_HEADER |
16770c6d BS |
261 | + for (init; condition; increment) |
262 | " \ | |
263 | "ERROR: Inappropriate bracing around statement | |
264 | #8 FILE: A.c:1: | |
265 | for (init; condition; increment) | |
266 | " | |
267 | ||
268 | try_checkpatch \ | |
74920866 | 269 | "COMMON_PATCH_HEADER |
16770c6d BS |
270 | + for(init; condition; increment) |
271 | " \ | |
272 | "ERROR: Improper whitespace around control block | |
273 | #8 FILE: A.c:1: | |
274 | for(init; condition; increment) | |
275 | " | |
276 | ||
277 | try_checkpatch \ | |
74920866 | 278 | "COMMON_PATCH_HEADER |
16770c6d BS |
279 | + for (init; condition; increment) { /* foo */ |
280 | " | |
281 | ||
282 | try_checkpatch \ | |
74920866 | 283 | "COMMON_PATCH_HEADER |
16770c6d BS |
284 | + for (init; condition; increment) { \\ |
285 | " | |
286 | ||
287 | AT_CLEANUP | |
b48aa143 IM |
288 | |
289 | ||
290 | AT_SETUP([checkpatch - comments]) | |
291 | try_checkpatch \ | |
292 | "COMMON_PATCH_HEADER | |
293 | + a = 1; /* C style comment. */ | |
294 | " | |
295 | ||
296 | try_checkpatch \ | |
297 | "COMMON_PATCH_HEADER | |
298 | + /* http://URL/inside/the/comment.html */ | |
299 | " | |
300 | ||
301 | try_checkpatch \ | |
302 | "COMMON_PATCH_HEADER | |
303 | + a = 1; // C99 style comment. | |
304 | " \ | |
305 | "ERROR: C99 style comment | |
306 | #8 FILE: A.c:1: | |
307 | a = 1; // C99 style comment. | |
308 | " | |
309 | ||
310 | AT_CLEANUP | |
9307fc46 IM |
311 | |
312 | AT_SETUP([checkpatch - whitespace around operator]) | |
313 | try_checkpatch \ | |
314 | "COMMON_PATCH_HEADER | |
315 | + if (--mcs->n_refs == 0) { | |
316 | " | |
317 | ||
318 | try_checkpatch \ | |
319 | "COMMON_PATCH_HEADER | |
320 | + if (--mcs->n_refs==0) { | |
321 | " \ | |
322 | "WARNING: Line lacks whitespace around operator | |
323 | WARNING: Line lacks whitespace around operator | |
324 | #8 FILE: A.c:1: | |
325 | if (--mcs->n_refs==0) { | |
326 | " | |
327 | ||
328 | AT_CLEANUP |