check-safety.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/bin/sh
  2. # Copyright 2014-2026 Free Software Foundation, Inc.
  3. # This file is part of the GNU C Library.
  4. # The GNU C Library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. # The GNU C Library is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # Lesser General Public License for more details.
  12. # You should have received a copy of the GNU Lesser General Public
  13. # License along with the GNU C Library; if not, see
  14. # <https://www.gnu.org/licenses/>.
  15. # Check that the @safety notes are self-consistent, i.e., that they're
  16. # in proper order (mt then as then ac), that remarks appear within
  17. # corresponding sections (mt within mt, etc), that unsafety always has
  18. # an explicit reason and when there's a reason for unsafety it's not
  19. # safe.
  20. success=:
  21. # If no arguments are given, take all *.texi files in the current directory.
  22. test $# != 0 || set *.texi
  23. # FIXME: check that each @deftypefu?n is followed by a @safety note,
  24. # with nothing but @deftypefu?nx and comment lines in between. (There
  25. # might be more stuff too).
  26. # Check that all safety remarks have entries for all of MT, AS and AC,
  27. # in this order, with an optional prelim note before them.
  28. ret=true
  29. grep -n '^@safety' "$@" |
  30. grep -v ':@safety{\(@prelim{}\)\?@mt\(un\)\?safe{.*}'\
  31. '@as\(un\)\?safe{.*}@ac\(un\)\?safe{.*}}' &&
  32. ret=false
  33. if ! $ret; then
  34. echo "FAIL: #1 - Missing context in @safety macro."
  35. success=false
  36. fi
  37. # Check that @mt-started notes appear within @mtsafe or @mtunsafe,
  38. # that @as-started notes appear within @assafe or @asunsafe, and that
  39. # @ac-started notes appear within @acsafe or @acunsafe. Also check
  40. # that @mt, @as and @ac are followed by an s (for safe) or u (for
  41. # unsafe), but let @mt have as, ac or asc before [su], and let @as
  42. # have a c (for cancel) before [su]. Also make sure blanks separate
  43. # each of the annotations.
  44. ret=true
  45. grep -n '^@safety' "$@" |
  46. grep -v ':@safety{\(@prelim{}\)\?'\
  47. '@mt\(un\)\?safe{\(@mt\(asc\?\|ac\)\?[su][^ ]*}\)\?'\
  48. '\( @mt\(asc\?\|ac\)\?[su][^ ]*}\)*}'\
  49. '@as\(un\)\?safe{\(@asc\?[su][^ ]*}\)\?'\
  50. '\( @asc\?[su][^ ]*}\)*}'\
  51. '@ac\(un\)\?safe{\(@ac[su][^ ]*}\)\?'\
  52. '\( @ac[su][^ ]*}\)*}}' &&
  53. ret=false
  54. if ! $ret; then
  55. echo "FAIL: #2 - Incorrect @safety macro formatting."
  56. success=false
  57. fi
  58. # Make sure safety lines marked as @mtsafe do not contain any
  59. # MT-Unsafe remark; that would be @mtu, but there could be as, ac or
  60. # asc between mt and u.
  61. ret=true
  62. grep -n '^@safety.*@mtsafe' "$@" |
  63. grep '@mt\(asc\?\|ac\)\?u' &&
  64. ret=false
  65. if ! $ret; then
  66. echo "FAIL: #3 - MT context contains remarks when it should not."
  67. success=false
  68. fi
  69. # Make sure @mtunsafe lines contain at least one @mtu remark (with
  70. # optional as, ac or asc between mt and u).
  71. ret=true
  72. grep -n '^@safety.*@mtunsafe' "$@" |
  73. grep -v '@mtunsafe{.*@mt\(asc\?\|ac\)\?u' &&
  74. ret=false
  75. if ! $ret; then
  76. echo "FAIL: #4 - MT context lacks at least one remark."
  77. success=false
  78. fi
  79. # Make sure safety lines marked as @assafe do not contain any AS-Unsafe
  80. # remark, which could be @asu or @mtasu note (with an optional c
  81. # between as and u in both cases).
  82. ret=true
  83. grep -n '^@safety.*@assafe' "$@" |
  84. grep '@\(mt\)\?asc\?u' &&
  85. ret=false
  86. if ! $ret; then
  87. echo "FAIL: #5 - AS context contains remarks when it should not."
  88. success=false
  89. fi
  90. # Make sure @asunsafe lines contain at least one @asu remark (which
  91. # could be @ascu, or @mtasu or even @mtascu). We allow the AS safety
  92. # remark from an earlier MT-unsafe to count towards such a remark
  93. # e.g. @mtunsafe{@mtasurace{:LogMask}}@asunsafe{}@acsafe{} is allowed.
  94. ret=true
  95. grep -n '^@safety.*@asunsafe' "$@" |
  96. grep -v '@mtasc\?u.*@asunsafe\|@asunsafe{.*@asc\?u' &&
  97. ret=false
  98. if ! $ret; then
  99. echo "FAIL: #6 - AS unsafe context lacks at least one remark."
  100. success=false
  101. fi
  102. # Make sure safety lines marked as @acsafe do not contain any
  103. # AC-Unsafe remark, which could be @acu, @ascu or even @mtacu or
  104. # @mtascu.
  105. ret=true
  106. grep -n '^@safety.*@acsafe' "$@" |
  107. grep '@\(mt\)\?as\?cu' &&
  108. ret=false
  109. if ! $ret; then
  110. echo "FAIL: #7 - AC context contains remarks when it should not."
  111. success=false
  112. fi
  113. # Make sure @acunsafe lines contain at least one @acu remark (possibly
  114. # implied by @ascu, @mtacu or @mtascu).
  115. ret=true
  116. grep -n '^@safety.*@acunsafe' "$@" |
  117. grep -v '@\(mtas\?\|as\)cu.*@acunsafe\|@acunsafe{.*@acu' &&
  118. ret=false
  119. if ! $ret; then
  120. echo "FAIL: #8 - AC unsafe context lacks at least one remark."
  121. success=false
  122. fi
  123. # Check that comments containing safety remarks do not contain {}s,
  124. # that all @mt remarks appear before @as remarks, that in turn appear
  125. # before @ac remarks, all properly blank-separated, and that an
  126. # optional comment about exclusions is between []s at the end of the
  127. # line.
  128. ret=true
  129. grep -n '^@c \+[^@ ]\+\( dup\)\?'\
  130. '\( @\(mt\|a[sc]\)[^ ]*\)*\( \[.*]\)\?$' "$@" |
  131. grep -v ':@c *[^@{}]*\( @mt[^ {}]*\)*'\
  132. '\( @as[^ {}]*\)*\( @ac[^ {}]*\)*\( \[.*]\)\?$' &&
  133. ret=false
  134. if ! $ret; then
  135. echo "FAIL: #9 - Comment safety note ordering, brackets, or"\
  136. "exclusions are incorrect."
  137. success=false
  138. fi
  139. $success