2 # Shared code for glibc conformance tests.
3 # Copyright (C) 2018 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 # <http://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 def list_exported_functions(cc
, standard
, header
):
40 """Return the set of functions exported by a header, empty if an
41 include of the header does not compile.
44 cc_all
= '%s -D_ISOMAC %s' % (cc
, CFLAGS
[standard
])
45 with tempfile
.TemporaryDirectory() as temp_dir
:
46 c_file_name
= os
.path
.join(temp_dir
, 'test.c')
47 aux_file_name
= os
.path
.join(temp_dir
, 'test.c.aux')
48 with
open(c_file_name
, 'w') as c_file
:
49 c_file
.write('#include <%s>\n' % header
)
51 cmd
= ('%s -c %s -o /dev/null -aux-info %s'
52 % (cc_all
, c_file_name
, aux_file_name
))
54 subprocess
.check_call(cmd
, shell
=True)
55 except subprocess
.CalledProcessError
:
57 with
open(aux_file_name
, 'r') as aux_file
:
59 line
= re
.sub(r
'/\*.*?\*/', '', line
)
62 # The word before a '(' that isn't '(*' is the
63 # function name before the argument list (not
64 # fully general, but sufficient for -aux-info
65 # output on standard headers).
66 m
= re
.search(r
'([A-Za-z0-9_]+) *\([^*]', line
)
70 raise ValueError("couldn't parse -aux-info output: %s"