2 # Shared code for glibc conformance tests.
3 # Copyright (C) 2018-2019 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/>.
26 # Compiler options for each standard.
27 CFLAGS
= {'ISO': '-ansi',
30 'POSIX': '-D_POSIX_C_SOURCE=199506L -ansi',
31 'XPG4': '-ansi -D_XOPEN_SOURCE',
32 'XPG42': '-ansi -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED',
33 'UNIX98': '-ansi -D_XOPEN_SOURCE=500',
34 'XOPEN2K': '-std=c99 -D_XOPEN_SOURCE=600',
35 'XOPEN2K8': '-std=c99 -D_XOPEN_SOURCE=700',
36 'POSIX2008': '-std=c99 -D_POSIX_C_SOURCE=200809L'}
39 KEYWORDS_C90
= {'auto', 'break', 'case', 'char', 'const', 'continue',
40 'default', 'do', 'double', 'else', 'enum', 'extern', 'float',
41 'for', 'goto', 'if', 'int', 'long', 'register', 'return',
42 'short', 'signed', 'sizeof', 'static', 'struct', 'switch',
43 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while'}
46 KEYWORDS_C99
= KEYWORDS_C90 |
{'inline', 'restrict'}
48 # Keywords for each standard.
49 KEYWORDS
= {'ISO': KEYWORDS_C90
,
50 'ISO99': KEYWORDS_C99
,
51 'ISO11': KEYWORDS_C99
,
52 'POSIX': KEYWORDS_C90
,
54 'XPG42': KEYWORDS_C90
,
55 'UNIX98': KEYWORDS_C90
,
56 'XOPEN2K': KEYWORDS_C99
,
57 'XOPEN2K8': KEYWORDS_C99
,
58 'POSIX2008': KEYWORDS_C99
}
61 def list_exported_functions(cc
, standard
, header
):
62 """Return the set of functions exported by a header, empty if an
63 include of the header does not compile.
66 cc_all
= '%s -D_ISOMAC %s' % (cc
, CFLAGS
[standard
])
67 with tempfile
.TemporaryDirectory() as temp_dir
:
68 c_file_name
= os
.path
.join(temp_dir
, 'test.c')
69 aux_file_name
= os
.path
.join(temp_dir
, 'test.c.aux')
70 with
open(c_file_name
, 'w') as c_file
:
71 c_file
.write('#include <%s>\n' % header
)
73 cmd
= ('%s -c %s -o /dev/null -aux-info %s'
74 % (cc_all
, c_file_name
, aux_file_name
))
76 subprocess
.check_call(cmd
, shell
=True)
77 except subprocess
.CalledProcessError
:
79 with
open(aux_file_name
, 'r') as aux_file
:
81 line
= re
.sub(r
'/\*.*?\*/', '', line
)
84 # The word before a '(' that isn't '(*' is the
85 # function name before the argument list (not
86 # fully general, but sufficient for -aux-info
87 # output on standard headers).
88 m
= re
.search(r
'([A-Za-z0-9_]+) *\([^*]', line
)
92 raise ValueError("couldn't parse -aux-info output: %s"