]> git.ipfire.org Git - thirdparty/glibc.git/blob - conform/glibcconform.py
Merge branch 'master' of git://sourceware.org/git/glibc
[thirdparty/glibc.git] / conform / glibcconform.py
1 #!/usr/bin/python
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.
5 #
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.
10 #
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.
15 #
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/>.
19
20 import os.path
21 import re
22 import subprocess
23 import tempfile
24
25
26 # Compiler options for each standard.
27 CFLAGS = {'ISO': '-ansi',
28 'ISO99': '-std=c99',
29 'ISO11': '-std=c11',
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'}
37
38
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.
42
43 """
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)
50 fns = set()
51 cmd = ('%s -c %s -o /dev/null -aux-info %s'
52 % (cc_all, c_file_name, aux_file_name))
53 try:
54 subprocess.check_call(cmd, shell=True)
55 except subprocess.CalledProcessError:
56 return fns
57 with open(aux_file_name, 'r') as aux_file:
58 for line in aux_file:
59 line = re.sub(r'/\*.*?\*/', '', line)
60 line = line.strip()
61 if 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)
67 if m:
68 fns.add(m.group(1))
69 else:
70 raise ValueError("couldn't parse -aux-info output: %s"
71 % line)
72 return fns