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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
|
AT_BANNER([checkpatch])
OVS_START_SHELL_HELPERS
# try_checkpatch PATCH [ERRORS]
#
# Runs checkpatch under Python 2 and Python 3, if installed, on the given
# PATCH, expecting the specified set of ERRORS (and warnings).
try_checkpatch() {
# Take the patch to test from $1. Remove an initial four-space indent
# from it and, if it is just headers with no body, add a null body.
# If it does not have a 'Subject', add a valid one.
echo "$1" | sed 's/^ //' > test.patch
if grep 'Subject\:' test.patch >/dev/null 2>&1; then :
else
sed -i'' -e '1i\
Subject: Patch this is.
' test.patch
fi
if grep '---' expout >/dev/null 2>&1; then :
else
printf '\n---\n' >> test.patch
fi
# Take expected output from $2.
if test -n "$2"; then
echo "$2" | sed 's/^ //' > expout
else
: > expout
fi
try_checkpatch__ "$PYTHON3"
}
try_checkpatch__() {
if test -s expout; then
AT_CHECK([$1 $top_srcdir/utilities/checkpatch.py -q test.patch],
[1], [stdout])
AT_CHECK([sed '/^Lines checked:/,$d' stdout], [0], [expout])
else
AT_CHECK([$1 $top_srcdir/utilities/checkpatch.py -q test.patch])
fi
}
OVS_END_SHELL_HELPERS
AT_SETUP([checkpatch - sign-offs])
# Sign-off for single author who is also the committer.
try_checkpatch \
"Author: A
Commit: A
Signed-off-by: A"
try_checkpatch \
"Author: A
Commit: A" \
"ERROR: Author A needs to sign off."
# Single author but somehow the mailing list is the author.
try_checkpatch \
"Author: Foo Bar via dev <ovs-dev@openvswitch.org>
Commit: A
Signed-off-by: A" \
"ERROR: Author should not be mailing list."
# Sign-off for single author and different committer.
try_checkpatch \
"Author: A
Commit: B
Signed-off-by: A
Signed-off-by: B"
try_checkpatch \
"Author: A
Commit: B" \
"ERROR: Author A needs to sign off.
ERROR: Committer B needs to sign off."
# Sign-off for multiple authors with one author also the committer.
try_checkpatch \
"Author: A
Commit: A
Signed-off-by: A
Co-authored-by: B
Signed-off-by: B"
try_checkpatch \
"Author: A
Commit: A
Co-authored-by: B
Signed-off-by: B" \
"ERROR: Author A needs to sign off."
try_checkpatch \
"Author: A
Commit: A
Signed-off-by: A
Co-authored-by: B" \
"ERROR: Co-author B needs to sign off."
try_checkpatch \
"Author: A
Commit: A
Co-authored-by: B" \
"ERROR: Author A needs to sign off.
ERROR: Co-author B needs to sign off."
# Sign-off for multiple authors and separate committer.
try_checkpatch \
"Author: A
Commit: C
Signed-off-by: A
Co-authored-by: B
Signed-off-by: B
Signed-off-by: C"
try_checkpatch \
"Author: A
Commit: C
Signed-off-by: A
Co-authored-by: B
Signed-off-by: B" \
"ERROR: Committer C needs to sign off."
# Extra sign-offs:
#
# - If we know the committer, one extra sign-off raises a warning.
#
# - If we do not know the committer, two extra sign-offs raise a warning.
try_checkpatch \
"Author: A
Commit: C
Signed-off-by: A
Co-authored-by: B
Signed-off-by: B
Signed-off-by: C
Signed-off-by: D" \
"WARNING: Unexpected sign-offs from developers who are not authors or co-authors or committers: D"
try_checkpatch \
"Author: A
Signed-off-by: A
Co-authored-by: B
Signed-off-by: B
Signed-off-by: C"
try_checkpatch \
"Author: A
Signed-off-by: A
Co-authored-by: B
Signed-off-by: B
Signed-off-by: C
Signed-off-by: D" \
"WARNING: Unexpected sign-offs from developers who are not authors or co-authors or committers: C, D"
# Missing committer is OK, missing author is an error.
try_checkpatch \
"Author: A
Signed-off-by: A"
try_checkpatch \
"Commit: A
Signed-off-by: A" \
"ERROR: Patch lacks author."
AT_CLEANUP
m4_define([COMMON_PATCH_HEADER], [dnl
Author: A
Signed-off-by: A
---
diff --git a/$([[ ! -z "$1" ]] && echo "$1" || echo "A.c") b/$([[ ! -z "$1" ]] && echo "$1" || echo "A.c")
index 0000000..1111111 100644
--- a/$([[ ! -z "$1" ]] && echo "$1" || echo "A.c")
+++ b/$([[ ! -z "$1" ]] && echo "$1" || echo "A.c")
@@ -1,1 +1,1 @@])
AT_SETUP([checkpatch - parenthesized constructs])
AT_KEYWORDS([slowtest])
for ctr in 'if' 'while' 'switch' 'HMAP_FOR_EACH' 'BITMAP_FOR_EACH_1'; do
try_checkpatch \
"COMMON_PATCH_HEADER
+ $ctr (first_run) {
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ $ctr ( first_run) {
" \
"ERROR: Improper whitespace around control block
#8 FILE: A.c:1:
$ctr ( first_run) {
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ $ctr (first_run ) {
" \
"ERROR: Inappropriate bracing around statement
#8 FILE: A.c:1:
$ctr (first_run ) {
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ $ctr (first_run)
" \
"ERROR: Inappropriate bracing around statement
#8 FILE: A.c:1:
$ctr (first_run)
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ $ctr(first_run)
" \
"ERROR: Improper whitespace around control block
#8 FILE: A.c:1:
$ctr(first_run)
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ $ctr (first_run) { /* foo */
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ $ctr (first_run) { \\
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ $ctr (a) { \\
"
done
AT_CLEANUP
AT_SETUP([checkpatch - catastrophic backtracking])
dnl Special case this rather than using the above construct because sometimes a
dnl warning needs to be generated for line lengths (f.e. when the 'while'
dnl keyword is used).
try_checkpatch \
"COMMON_PATCH_HEADER
+ if (!b_ctx_in->chassis_rec || !b_ctx_in->br_int || !b_ctx_in->ovs_idl_txn)
" \
"ERROR: Inappropriate bracing around statement
#8 FILE: A.c:1:
if (!b_ctx_in->chassis_rec || !b_ctx_in->br_int || !b_ctx_in->ovs_idl_txn)
"
AT_CLEANUP
AT_SETUP([checkpatch - parenthesized constructs - for])
try_checkpatch \
"COMMON_PATCH_HEADER
+ for (init; condition; increment) {
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ for ( init; condition; increment) {
" \
"ERROR: Improper whitespace around control block
#8 FILE: A.c:1:
for ( init; condition; increment) {
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ for (init; condition; increment ) {
" \
"ERROR: Inappropriate bracing around statement
#8 FILE: A.c:1:
for (init; condition; increment ) {
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ for (init; condition; increment)
" \
"ERROR: Inappropriate bracing around statement
#8 FILE: A.c:1:
for (init; condition; increment)
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ for(init; condition; increment)
" \
"ERROR: Improper whitespace around control block
#8 FILE: A.c:1:
for(init; condition; increment)
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ for (init; condition; increment) { /* foo */
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ for (init; condition; increment) { \\
"
try_checkpatch \
"COMMON_PATCH_HEADER
+#define SOME_FOR_EACH(a, b, c) /* Foo. */
"
AT_CLEANUP
AT_SETUP([checkpatch - comments])
try_checkpatch \
"COMMON_PATCH_HEADER
+ a = 1; /* C style comment. */
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ /* http://URL/inside/the/comment.html */
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ a = 1; // C99 style comment.
" \
"ERROR: C99 style comment
#8 FILE: A.c:1:
a = 1; // C99 style comment.
"
AT_CLEANUP
AT_SETUP([checkpatch - whitespace around operator])
try_checkpatch \
"COMMON_PATCH_HEADER
+ if (--mcs->n_refs == 0) {
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ if (--mcs->n_refs==0) {
" \
"WARNING: Line lacks whitespace around operator
WARNING: Line lacks whitespace around operator
#8 FILE: A.c:1:
if (--mcs->n_refs==0) {
"
AT_CLEANUP
AT_SETUP([checkpatch - line too long])
try_checkpatch \
"COMMON_PATCH_HEADER
+/* This is a very long line.................................................. */
" \
"WARNING: Line is 80 characters long (recommended limit is 79)
#8 FILE: A.c:1:
/* This is a very long line.................................................. */
"
AT_CLEANUP
AT_SETUP([checkpatch - check misuse APIs])
try_checkpatch \
"COMMON_PATCH_HEADER([a.c])
+ ovsrcu_barrier();
" \
"WARNING: Are you sure you need to use ovsrcu_barrier(), "\
"in most cases ovsrcu_synchronize() will be fine?
#8 FILE: a.c:1:
ovsrcu_barrier();
"
try_checkpatch \
"COMMON_PATCH_HEADER([lib/ovs-rcu.c])
+ ovsrcu_barrier();
"
AT_CLEANUP
AT_SETUP([checkpatch - check egrep / fgrep])
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+C_H_E_C_K([[ovs-vsctl show | grep -E 'my-port.*[[0-9]]$' | grep -F 'port']])
"
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+C_H_E_C_K([[ovs-vsctl show | egrep 'my-port.*[[0-9]]$']])
" \
"ERROR: grep -E/-F should be used instead of egrep/fgrep
#8 FILE: tests/something.at:1:
C_H_E_C_K([[ovs-vsctl show | egrep 'my-port.*[[0-9]]$']])
"
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+C_H_E_C_K([[ovs-vsctl show | fgrep 'my-port.*[[0-9]]$']])
" \
"ERROR: grep -E/-F should be used instead of egrep/fgrep
#8 FILE: tests/something.at:1:
C_H_E_C_K([[ovs-vsctl show | fgrep 'my-port.*[[0-9]]$']])
"
AT_CLEANUP
AT_SETUP([checkpatch - whitespace around cast])
try_checkpatch \
"COMMON_PATCH_HEADER
+ (int) a;
"
try_checkpatch \
"COMMON_PATCH_HEADER
+ (int)a;
" \
"ERROR: Inappropriate spacing around cast
#8 FILE: A.c:1:
(int)a;
"
AT_CLEANUP
AT_SETUP([checkpatch - malformed tags])
try_checkpatch \
" Author: A
Acked by: foo...
Signed-off-by: A" \
"ERROR: Acked-by tag is malformed.
1: Acked by: foo...
"
try_checkpatch \
" Author: A
Reported at: foo...
Signed-off-by: A" \
"ERROR: Reported-at tag is malformed.
1: Reported at: foo...
"
try_checkpatch \
" Author: A
Reported by: foo...
Signed-off-by: A" \
"ERROR: Reported-by tag is malformed.
1: Reported by: foo...
"
try_checkpatch \
" Author: A
Requested by: foo...
Signed-off-by: A" \
"ERROR: Requested-by tag is malformed.
1: Requested by: foo...
"
try_checkpatch \
" Author: A
Reviewed by: foo...
Signed-off-by: A" \
"ERROR: Reviewed-by tag is malformed.
1: Reviewed by: foo...
"
try_checkpatch \
" Author: A
Submitted at: foo...
Signed-off-by: A" \
"ERROR: Submitted-at tag is malformed.
1: Submitted at: foo...
"
try_checkpatch \
" Author: A
Suggested by: foo...
Signed-off-by: A" \
"ERROR: Suggested-by tag is malformed.
1: Suggested by: foo...
"
AT_CLEANUP
AT_SETUP([checkpatch - Unicode code])
try_checkpatch \
"COMMON_PATCH_HEADER
+ if (snowman == ☃️) { /* Emoji
+ void НelloWorld() { /* Homoglyph
+ ة /* ;C++ /* BiDi
" \
"ERROR: Inappropriate non-ascii characters detected.
#8 FILE: A.c:1:
if (snowman == ☃️) { /* Emoji
ERROR: Inappropriate non-ascii characters detected.
#9 FILE: A.c:2:
void НelloWorld() { /* Homoglyph
ERROR: Inappropriate non-ascii characters detected.
#10 FILE: A.c:3:
ة /* ;C++ /* BiDi
"
AT_CLEANUP
m4_define([FIXES_TAG_ERROR], [dnl
ERROR: \"Fixes\" tag is malformed.
Use the following format:
git log -1 --pretty=format:\"Fixes: %h (\\\"%s\\\")\" --abbrev=12 COMMIT_REF
])
AT_SETUP([checkpatch - Fixes tag])
try_checkpatch \
"Author: A
Commit: A
Fixes: 123456789abc (\"commit name\")
Signed-off-by: A"
try_checkpatch \
"Author: A
Commit: A
fixes: 123456789abc (\"commit name\")
Signed-off-by: A" \
"FIXES_TAG_ERROR
1: fixes: 123456789abc (\"commit name\")
"
try_checkpatch \
"Author: A
Commit: A
Fixes: 12345678 (\"commit name\")
Signed-off-by: A" \
"FIXES_TAG_ERROR
1: Fixes: 12345678 (\"commit name\")
"
try_checkpatch \
"Author: A
Commit: A
Fixes: 1234567890abcdef1234567890abcdef12345678 (\"commit name\")
Signed-off-by: A" \
"FIXES_TAG_ERROR
1: Fixes: 1234567890abcdef1234567890abcdef12345678 (\"commit name\")
"
try_checkpatch \
"Author: A
Commit: A
Fixes: 123456789abc \"commit name\"
Signed-off-by: A" \
"FIXES_TAG_ERROR
1: Fixes: 123456789abc \"commit name\"
"
try_checkpatch \
"Author: A
Commit: A
Fixes: 123456789abc (\"some very long commit name that doesn\'t fit into
a single line, but should not be wrapped.\")
Signed-off-by: A" \
"FIXES_TAG_ERROR
1: Fixes: 123456789abc (\"some very long commit name that doesn\'t fit into
"
AT_CLEANUP
AT_SETUP([checkpatch - subject])
try_checkpatch \
"Author: A
Commit: A
Subject: netdev: invalid case and dot ending
Signed-off-by: A" \
"WARNING: The subject summary should start with a capital.
WARNING: The subject summary should end with a dot.
Subject: netdev: invalid case and dot ending"
try_checkpatch \
"Author: A
Commit: A
Subject: netdev: This is a way to long commit summary and therefor it should report a WARNING!
Signed-off-by: A" \
"WARNING: The subject, '<area>: <summary>', is over 70 characters, i.e., 85.
Subject: netdev: This is a way to long commit summary and therefor it should report a WARNING!"
AT_CLEANUP
AT_SETUP([checkpatch - hardcoded table numbers])
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+table=12(ls_in_hairpin ), priority=1000 , match=(reg0[[14]] == 1), action=(next(pipeline=ingress, table=??);)
" \
"WARNING: Use of hardcoded table=<NUMBER> or resubmit=(,<NUMBER>) is discouraged in tests. Consider using MACRO instead.
#8 FILE: tests/something.at:1:
table=12(ls_in_hairpin ), priority=1000 , match=(reg0[[14]] == 1), action=(next(pipeline=ingress, table=??);)
"
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+table=??(ls_in_hairpin ), priority=1000 , match=(reg0[[14]] == 1), action=(next(pipeline=ingress, table=13);)
" \
"WARNING: Use of hardcoded table=<NUMBER> or resubmit=(,<NUMBER>) is discouraged in tests. Consider using MACRO instead.
#8 FILE: tests/something.at:1:
table=??(ls_in_hairpin ), priority=1000 , match=(reg0[[14]] == 1), action=(next(pipeline=ingress, table=13);)
"
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+priority=1100,ip,reg15=0x1,metadata=0x1,nw_src=10.0.0.1 actions=load:0x1->OXM_OF_PKT_REG4[[49]],resubmit(,47)
" \
"WARNING: Use of hardcoded table=<NUMBER> or resubmit=(,<NUMBER>) is discouraged in tests. Consider using MACRO instead.
#8 FILE: tests/something.at:1:
priority=1100,ip,reg15=0x1,metadata=0x1,nw_src=10.0.0.1 actions=load:0x1->OXM_OF_PKT_REG4[[49]],resubmit(,47)
"
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+C_H_E_C_K([as gw1 ovs-ofctl dump-flows br-int table=42 | grep "dl_dst=00:00:02:01:02:04" | wc -l], [0], [[1]])
" \
"WARNING: Use of hardcoded table=<NUMBER> or resubmit=(,<NUMBER>) is discouraged in tests. Consider using MACRO instead.
#8 FILE: tests/something.at:1:
C_H_E_C_K([as gw1 ovs-ofctl dump-flows br-int table=42 | grep "dl_dst=00:00:02:01:02:04" | wc -l], [0], [[1]])
"
AT_CLEANUP
AT_SETUP([checkpatch - check and check_uuid])
# Verify that missing check is covered.
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+ovn-nbctl lsp-add ls
" \
"WARNING: ovn-nbctl return should be checked Consider adding check or check_uuid in front.
#8 FILE: tests/something.at:1:
ovn-nbctl lsp-add ls
"
# Verify that existing check makes checkpatch happy.
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+check ovn-nbctl lsp-add ls
"
# Verify that missing check_uuid is covered.
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+ovn-sbctl -- create FDB mac='"00\:00\:00\:00\:00\:03"' dp_key=1 port_key=1
" \
"WARNING: ovn-sbctl return should be checked Consider adding check or check_uuid in front.
#8 FILE: tests/something.at:1:
ovn-sbctl -- create FDB mac='00:00:00:00:00:03' dp_key=1 port_key=1
"
# Verify that existing check_uuid makes checkpatch happy.
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+check_uuid ovn-sbctl -- create FDB mac='"00\:00\:00\:00\:00\:03"' dp_key=1 port_key=1
"
# Verify that missing check for a get command does not cause checkpatch failures.
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+ovn-nbctl get Logical-Switch-Port p1 dynamic_addresses
"
# Verify that missing check for a create command causes checkpatch failure - multiline.
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+ovn-sbctl \
+ -- create FDB mac='"00\:00\:00\:00\:00\:03"' dp_key=1 port_key=1
" \
"WARNING: ovn-sbctl return should be checked Consider adding check or check_uuid in front.
#8 FILE: tests/something.at:1:
ovn-sbctl + -- create FDB mac='00:00:00:00:00:03' dp_key=1 port_key=1
"
# Verify that missing check for a get command does not cause checkpatch failures - multiline.
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+ovn-nbctl \
+ -- get Logical-Switch-Port p1 dynamic_addresses
"
# Verify that we can still store outout of ovn-nbctl w/o check.
try_checkpatch \
"COMMON_PATCH_HEADER([tests/something.at])
+lsp1_uuid=$(ovn-nbctl --bare --columns _uuid find Logical_Switch_Port name=lsp1)
"
AT_CLEANUP
|