Use Linux 6.6 in build-many-glibcs.py
[glibc.git] / stdio-common / tst-errno-manual.py
bloba86d35487571ce0f2847fa4a4ca0f4b3a1775988
1 #!/usr/bin/python3
2 # Check is all errno definitions at errlist.h documented in the manual.
3 # Copyright (C) 2020-2023 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <https://www.gnu.org/licenses/>.
20 import argparse
21 import sys
22 import re
24 RE_MANUAL = re.compile(
25 r'(?:^@errno){(\w+)')
27 RE_ERRLIST = re.compile(
28 r'\(E[a-zA-Z0-9]+\)')
30 PASS=0
31 FAIL=1
33 # Each manual entry is in the form:
35 # errno{EAGAIN, 35, Resource temporarily unavailable}
36 def parse_manual(f):
37 errlist = [RE_MANUAL.findall(s) for s in f]
38 return map(lambda x : x[0], filter(None, errlist))
40 # Each errlist entry is in the form:
42 # _S(ERR_MAP(EAGAIN), N_("Resource temporarily unavailable"))
43 def parse_errlist(f):
44 errlist = [RE_ERRLIST.findall(s) for s in f]
45 # Each element is '[]' or '['(EAGAIN)']'
46 return map(lambda s : s[0][s[0].find('(')+1:s[0].find(')')],
47 filter(None, errlist))
49 def check_errno_definitions(manual_fname, errlist_fname):
50 with open(manual_fname, 'r') as mfile, open(errlist_fname, 'r') as efile:
51 merr = parse_manual(mfile)
52 eerr = parse_errlist(efile)
53 diff = set(eerr).difference(merr)
54 if not diff:
55 sys.exit(PASS)
56 else:
57 print("Failure: the following value(s) are not in manual:",
58 ", ".join(str(e) for e in diff))
59 sys.exit(FAIL)
61 def main():
62 parser = argparse.ArgumentParser(description='Generate errlist.h')
63 parser.add_argument('-m', dest='manual', metavar='FILE',
64 help='manual errno texi file')
65 parser.add_argument('-e', dest='errlist', metavar='FILE',
66 help='errlist with errno definitions')
67 args = parser.parse_args()
69 check_errno_definitions(args.manual, args.errlist)
72 if __name__ == '__main__':
73 main()