|
|
194aa3 |
commit a8110b727e508f7ddf34f940af622e6f95435201
|
|
|
194aa3 |
Author: Joseph Myers <joseph@codesourcery.com>
|
|
|
194aa3 |
Date: Mon Dec 10 22:27:13 2018 +0000
|
|
|
194aa3 |
|
|
|
194aa3 |
Move tst-signal-numbers to Python.
|
|
|
194aa3 |
|
|
|
194aa3 |
This patch converts the tst-signal-numbers test from shell + awk to
|
|
|
194aa3 |
Python.
|
|
|
194aa3 |
|
|
|
194aa3 |
As with gen-as-const, the point is not so much that shell and awk are
|
|
|
194aa3 |
problematic for this code, as that it's useful to build up general
|
|
|
194aa3 |
infrastructure in Python for use of a range of code involving
|
|
|
194aa3 |
extracting values from C headers. This patch moves some code from
|
|
|
194aa3 |
gen-as-const.py to a new glibcextract.py, which also gains functions
|
|
|
194aa3 |
relating to listing macros, and comparing the values of a set of
|
|
|
194aa3 |
macros from compiling two different pieces of code.
|
|
|
194aa3 |
|
|
|
194aa3 |
It's not just signal numbers that should have such tests; pretty much
|
|
|
194aa3 |
any case where glibc copies constants from Linux kernel headers should
|
|
|
194aa3 |
have such tests that the values and sets of constants agree except
|
|
|
194aa3 |
where differences are known to be OK. Much the same also applies to
|
|
|
194aa3 |
structure layouts (although testing those without hardcoding lists of
|
|
|
194aa3 |
fields to test will be more complicated).
|
|
|
194aa3 |
|
|
|
194aa3 |
Given this patch, another test for a set of macros would essentially
|
|
|
194aa3 |
be just a call to glibcextract.compare_macro_consts (plus boilerplate
|
|
|
194aa3 |
code - and we could move to having separate text files defining such
|
|
|
194aa3 |
tests, like the .sym inputs to gen-as-const, so that only a single
|
|
|
194aa3 |
Python script is needed for most such tests). Some such tests would
|
|
|
194aa3 |
of course need new features, e.g. where the set of macros changes in
|
|
|
194aa3 |
new kernel versions (so you need to allow new macro names on the
|
|
|
194aa3 |
kernel side if the kernel headers are newer than the version known to
|
|
|
194aa3 |
glibc, and extra macros on the glibc side if the kernel headers are
|
|
|
194aa3 |
older). tst-syscall-list.sh could become a Python script that uses
|
|
|
194aa3 |
common code to generate lists of macros but does other things with its
|
|
|
194aa3 |
own custom logic.
|
|
|
194aa3 |
|
|
|
194aa3 |
There are a few differences from the existing shell + awk test.
|
|
|
194aa3 |
Because the new test evaluates constants using the compiler, no
|
|
|
194aa3 |
special handling is needed any more for one signal name being defined
|
|
|
194aa3 |
to another. Because asm/signal.h now needs to pass through the
|
|
|
194aa3 |
compiler, not just the preprocessor, stddef.h is included as well
|
|
|
194aa3 |
(given the asm/signal.h issue that it requires an externally provided
|
|
|
194aa3 |
definition of size_t). The previous code defined __ASSEMBLER__ with
|
|
|
194aa3 |
asm/signal.h; this is removed (__ASSEMBLY__, a different macro,
|
|
|
194aa3 |
eliminates the requirement for stddef.h on some but not all
|
|
|
194aa3 |
architectures).
|
|
|
194aa3 |
|
|
|
194aa3 |
Tested for x86_64, and with build-many-glibcs.py.
|
|
|
194aa3 |
|
|
|
194aa3 |
* scripts/glibcextract.py: New file.
|
|
|
194aa3 |
* scripts/gen-as-const.py: Do not import os.path, re, subprocess
|
|
|
194aa3 |
or tempfile. Import glibcexctract.
|
|
|
194aa3 |
(compute_c_consts): Remove. Moved to glibcextract.py.
|
|
|
194aa3 |
(gen_test): Update reference to compute_c_consts.
|
|
|
194aa3 |
(main): Likewise.
|
|
|
194aa3 |
* sysdeps/unix/sysv/linux/tst-signal-numbers.py: New file.
|
|
|
194aa3 |
* sysdeps/unix/sysv/linux/tst-signal-numbers.sh: Remove.
|
|
|
194aa3 |
* sysdeps/unix/sysv/linux/Makefile
|
|
|
194aa3 |
($(objpfx)tst-signal-numbers.out): Use tst-signal-numbers.py.
|
|
|
194aa3 |
Redirect stderr as well as stdout.
|
|
|
194aa3 |
|
|
|
194aa3 |
diff --git a/scripts/gen-as-const.py b/scripts/gen-as-const.py
|
|
|
194aa3 |
index eb85ef1aa0f4934d..f85e359394acb1a4 100644
|
|
|
194aa3 |
--- a/scripts/gen-as-const.py
|
|
|
194aa3 |
+++ b/scripts/gen-as-const.py
|
|
|
194aa3 |
@@ -24,68 +24,14 @@
|
|
|
194aa3 |
# A line giving just a name implies an expression consisting of just that name.
|
|
|
194aa3 |
|
|
|
194aa3 |
import argparse
|
|
|
194aa3 |
-import os.path
|
|
|
194aa3 |
-import re
|
|
|
194aa3 |
-import subprocess
|
|
|
194aa3 |
-import tempfile
|
|
|
194aa3 |
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-def compute_c_consts(sym_data, cc):
|
|
|
194aa3 |
- """Compute the values of some C constants.
|
|
|
194aa3 |
-
|
|
|
194aa3 |
- The first argument is a list whose elements are either strings
|
|
|
194aa3 |
- (preprocessor directives, or the special string 'START' to
|
|
|
194aa3 |
- indicate this function should insert its initial boilerplate text
|
|
|
194aa3 |
- in the output there) or pairs of strings (a name and a C
|
|
|
194aa3 |
- expression for the corresponding value). Preprocessor directives
|
|
|
194aa3 |
- in the middle of the list may be used to select which constants
|
|
|
194aa3 |
- end up being evaluated using which expressions.
|
|
|
194aa3 |
-
|
|
|
194aa3 |
- """
|
|
|
194aa3 |
- out_lines = []
|
|
|
194aa3 |
- for arg in sym_data:
|
|
|
194aa3 |
- if isinstance(arg, str):
|
|
|
194aa3 |
- if arg == 'START':
|
|
|
194aa3 |
- out_lines.append('void\ndummy (void)\n{')
|
|
|
194aa3 |
- else:
|
|
|
194aa3 |
- out_lines.append(arg)
|
|
|
194aa3 |
- continue
|
|
|
194aa3 |
- name = arg[0]
|
|
|
194aa3 |
- value = arg[1]
|
|
|
194aa3 |
- out_lines.append('asm ("@@@name@@@%s@@@value@@@%%0@@@end@@@" '
|
|
|
194aa3 |
- ': : \"i\" ((long int) (%s)));'
|
|
|
194aa3 |
- % (name, value))
|
|
|
194aa3 |
- out_lines.append('}')
|
|
|
194aa3 |
- out_lines.append('')
|
|
|
194aa3 |
- out_text = '\n'.join(out_lines)
|
|
|
194aa3 |
- with tempfile.TemporaryDirectory() as temp_dir:
|
|
|
194aa3 |
- c_file_name = os.path.join(temp_dir, 'test.c')
|
|
|
194aa3 |
- s_file_name = os.path.join(temp_dir, 'test.s')
|
|
|
194aa3 |
- with open(c_file_name, 'w') as c_file:
|
|
|
194aa3 |
- c_file.write(out_text)
|
|
|
194aa3 |
- # Compilation has to be from stdin to avoid the temporary file
|
|
|
194aa3 |
- # name being written into the generated dependencies.
|
|
|
194aa3 |
- cmd = ('%s -S -o %s -x c - < %s' % (cc, s_file_name, c_file_name))
|
|
|
194aa3 |
- subprocess.check_call(cmd, shell=True)
|
|
|
194aa3 |
- consts = {}
|
|
|
194aa3 |
- with open(s_file_name, 'r') as s_file:
|
|
|
194aa3 |
- for line in s_file:
|
|
|
194aa3 |
- match = re.search('@@@name@@@([^@]*)'
|
|
|
194aa3 |
- '@@@value@@@[^0-9Xxa-fA-F-]*'
|
|
|
194aa3 |
- '([0-9Xxa-fA-F-]+).*@@@end@@@', line)
|
|
|
194aa3 |
- if match:
|
|
|
194aa3 |
- if (match.group(1) in consts
|
|
|
194aa3 |
- and match.group(2) != consts[match.group(1)]):
|
|
|
194aa3 |
- raise ValueError('duplicate constant %s'
|
|
|
194aa3 |
- % match.group(1))
|
|
|
194aa3 |
- consts[match.group(1)] = match.group(2)
|
|
|
194aa3 |
- return consts
|
|
|
194aa3 |
+import glibcextract
|
|
|
194aa3 |
|
|
|
194aa3 |
|
|
|
194aa3 |
def gen_test(sym_data):
|
|
|
194aa3 |
"""Generate a test for the values of some C constants.
|
|
|
194aa3 |
|
|
|
194aa3 |
- The first argument is as for compute_c_consts.
|
|
|
194aa3 |
+ The first argument is as for glibcextract.compute_c_consts.
|
|
|
194aa3 |
|
|
|
194aa3 |
"""
|
|
|
194aa3 |
out_lines = []
|
|
|
194aa3 |
@@ -158,7 +104,7 @@ def main():
|
|
|
194aa3 |
if args.test:
|
|
|
194aa3 |
print(gen_test(sym_data))
|
|
|
194aa3 |
else:
|
|
|
194aa3 |
- consts = compute_c_consts(sym_data, args.cc)
|
|
|
194aa3 |
+ consts = glibcextract.compute_c_consts(sym_data, args.cc)
|
|
|
194aa3 |
print(''.join('#define %s %s\n' % c for c in sorted(consts.items())), end='')
|
|
|
194aa3 |
|
|
|
194aa3 |
if __name__ == '__main__':
|
|
|
194aa3 |
diff --git a/scripts/glibcextract.py b/scripts/glibcextract.py
|
|
|
194aa3 |
new file mode 100644
|
|
|
194aa3 |
index 0000000000000000..ecc4d5b6cc387c7d
|
|
|
194aa3 |
--- /dev/null
|
|
|
194aa3 |
+++ b/scripts/glibcextract.py
|
|
|
194aa3 |
@@ -0,0 +1,162 @@
|
|
|
194aa3 |
+#!/usr/bin/python3
|
|
|
194aa3 |
+# Extract information from C headers.
|
|
|
194aa3 |
+# Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
194aa3 |
+# This file is part of the GNU C Library.
|
|
|
194aa3 |
+#
|
|
|
194aa3 |
+# The GNU C Library is free software; you can redistribute it and/or
|
|
|
194aa3 |
+# modify it under the terms of the GNU Lesser General Public
|
|
|
194aa3 |
+# License as published by the Free Software Foundation; either
|
|
|
194aa3 |
+# version 2.1 of the License, or (at your option) any later version.
|
|
|
194aa3 |
+#
|
|
|
194aa3 |
+# The GNU C Library is distributed in the hope that it will be useful,
|
|
|
194aa3 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
194aa3 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
194aa3 |
+# Lesser General Public License for more details.
|
|
|
194aa3 |
+#
|
|
|
194aa3 |
+# You should have received a copy of the GNU Lesser General Public
|
|
|
194aa3 |
+# License along with the GNU C Library; if not, see
|
|
|
194aa3 |
+# <http://www.gnu.org/licenses/>.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+import os.path
|
|
|
194aa3 |
+import re
|
|
|
194aa3 |
+import subprocess
|
|
|
194aa3 |
+import tempfile
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+def compute_c_consts(sym_data, cc):
|
|
|
194aa3 |
+ """Compute the values of some C constants.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+ The first argument is a list whose elements are either strings
|
|
|
194aa3 |
+ (preprocessor directives, or the special string 'START' to
|
|
|
194aa3 |
+ indicate this function should insert its initial boilerplate text
|
|
|
194aa3 |
+ in the output there) or pairs of strings (a name and a C
|
|
|
194aa3 |
+ expression for the corresponding value). Preprocessor directives
|
|
|
194aa3 |
+ in the middle of the list may be used to select which constants
|
|
|
194aa3 |
+ end up being evaluated using which expressions.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+ """
|
|
|
194aa3 |
+ out_lines = []
|
|
|
194aa3 |
+ for arg in sym_data:
|
|
|
194aa3 |
+ if isinstance(arg, str):
|
|
|
194aa3 |
+ if arg == 'START':
|
|
|
194aa3 |
+ out_lines.append('void\ndummy (void)\n{')
|
|
|
194aa3 |
+ else:
|
|
|
194aa3 |
+ out_lines.append(arg)
|
|
|
194aa3 |
+ continue
|
|
|
194aa3 |
+ name = arg[0]
|
|
|
194aa3 |
+ value = arg[1]
|
|
|
194aa3 |
+ out_lines.append('asm ("@@@name@@@%s@@@value@@@%%0@@@end@@@" '
|
|
|
194aa3 |
+ ': : \"i\" ((long int) (%s)));'
|
|
|
194aa3 |
+ % (name, value))
|
|
|
194aa3 |
+ out_lines.append('}')
|
|
|
194aa3 |
+ out_lines.append('')
|
|
|
194aa3 |
+ out_text = '\n'.join(out_lines)
|
|
|
194aa3 |
+ with tempfile.TemporaryDirectory() as temp_dir:
|
|
|
194aa3 |
+ c_file_name = os.path.join(temp_dir, 'test.c')
|
|
|
194aa3 |
+ s_file_name = os.path.join(temp_dir, 'test.s')
|
|
|
194aa3 |
+ with open(c_file_name, 'w') as c_file:
|
|
|
194aa3 |
+ c_file.write(out_text)
|
|
|
194aa3 |
+ # Compilation has to be from stdin to avoid the temporary file
|
|
|
194aa3 |
+ # name being written into the generated dependencies.
|
|
|
194aa3 |
+ cmd = ('%s -S -o %s -x c - < %s' % (cc, s_file_name, c_file_name))
|
|
|
194aa3 |
+ subprocess.check_call(cmd, shell=True)
|
|
|
194aa3 |
+ consts = {}
|
|
|
194aa3 |
+ with open(s_file_name, 'r') as s_file:
|
|
|
194aa3 |
+ for line in s_file:
|
|
|
194aa3 |
+ match = re.search('@@@name@@@([^@]*)'
|
|
|
194aa3 |
+ '@@@value@@@[^0-9Xxa-fA-F-]*'
|
|
|
194aa3 |
+ '([0-9Xxa-fA-F-]+).*@@@end@@@', line)
|
|
|
194aa3 |
+ if match:
|
|
|
194aa3 |
+ if (match.group(1) in consts
|
|
|
194aa3 |
+ and match.group(2) != consts[match.group(1)]):
|
|
|
194aa3 |
+ raise ValueError('duplicate constant %s'
|
|
|
194aa3 |
+ % match.group(1))
|
|
|
194aa3 |
+ consts[match.group(1)] = match.group(2)
|
|
|
194aa3 |
+ return consts
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+def list_macros(source_text, cc):
|
|
|
194aa3 |
+ """List the preprocessor macros defined by the given source code.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+ The return value is a pair of dicts, the first one mapping macro
|
|
|
194aa3 |
+ names to their expansions and the second one mapping macro names
|
|
|
194aa3 |
+ to lists of their arguments, or to None for object-like macros.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+ """
|
|
|
194aa3 |
+ with tempfile.TemporaryDirectory() as temp_dir:
|
|
|
194aa3 |
+ c_file_name = os.path.join(temp_dir, 'test.c')
|
|
|
194aa3 |
+ i_file_name = os.path.join(temp_dir, 'test.i')
|
|
|
194aa3 |
+ with open(c_file_name, 'w') as c_file:
|
|
|
194aa3 |
+ c_file.write(source_text)
|
|
|
194aa3 |
+ cmd = ('%s -E -dM -o %s %s' % (cc, i_file_name, c_file_name))
|
|
|
194aa3 |
+ subprocess.check_call(cmd, shell=True)
|
|
|
194aa3 |
+ macros_exp = {}
|
|
|
194aa3 |
+ macros_args = {}
|
|
|
194aa3 |
+ with open(i_file_name, 'r') as i_file:
|
|
|
194aa3 |
+ for line in i_file:
|
|
|
194aa3 |
+ match = re.fullmatch('#define ([0-9A-Za-z_]+)(.*)\n', line)
|
|
|
194aa3 |
+ if not match:
|
|
|
194aa3 |
+ raise ValueError('bad -dM output line: %s' % line)
|
|
|
194aa3 |
+ name = match.group(1)
|
|
|
194aa3 |
+ value = match.group(2)
|
|
|
194aa3 |
+ if value.startswith(' '):
|
|
|
194aa3 |
+ value = value[1:]
|
|
|
194aa3 |
+ args = None
|
|
|
194aa3 |
+ elif value.startswith('('):
|
|
|
194aa3 |
+ match = re.fullmatch(r'\((.*?)\) (.*)', value)
|
|
|
194aa3 |
+ if not match:
|
|
|
194aa3 |
+ raise ValueError('bad -dM output line: %s' % line)
|
|
|
194aa3 |
+ args = match.group(1).split(',')
|
|
|
194aa3 |
+ value = match.group(2)
|
|
|
194aa3 |
+ else:
|
|
|
194aa3 |
+ raise ValueError('bad -dM output line: %s' % line)
|
|
|
194aa3 |
+ if name in macros_exp:
|
|
|
194aa3 |
+ raise ValueError('duplicate macro: %s' % line)
|
|
|
194aa3 |
+ macros_exp[name] = value
|
|
|
194aa3 |
+ macros_args[name] = args
|
|
|
194aa3 |
+ return macros_exp, macros_args
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+def compute_macro_consts(source_text, cc, macro_re, exclude_re=None):
|
|
|
194aa3 |
+ """Compute the integer constant values of macros defined by source_text.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+ Macros must match the regular expression macro_re, and if
|
|
|
194aa3 |
+ exclude_re is defined they must not match exclude_re. Values are
|
|
|
194aa3 |
+ computed with compute_c_consts.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+ """
|
|
|
194aa3 |
+ macros_exp, macros_args = list_macros(source_text, cc)
|
|
|
194aa3 |
+ macros_set = {m for m in macros_exp
|
|
|
194aa3 |
+ if (macros_args[m] is None
|
|
|
194aa3 |
+ and re.fullmatch(macro_re, m)
|
|
|
194aa3 |
+ and (exclude_re is None
|
|
|
194aa3 |
+ or not re.fullmatch(exclude_re, m)))}
|
|
|
194aa3 |
+ sym_data = [source_text, 'START']
|
|
|
194aa3 |
+ sym_data.extend(sorted((m, m) for m in macros_set))
|
|
|
194aa3 |
+ return compute_c_consts(sym_data, cc)
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+def compare_macro_consts(source_1, source_2, cc, macro_re, exclude_re=None):
|
|
|
194aa3 |
+ """Compare the values of macros defined by two different sources.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+ The sources would typically be includes of a glibc header and a
|
|
|
194aa3 |
+ kernel header. Return 1 if there were any differences, 0 if the
|
|
|
194aa3 |
+ macro values were the same.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+ """
|
|
|
194aa3 |
+ macros_1 = compute_macro_consts(source_1, cc, macro_re, exclude_re)
|
|
|
194aa3 |
+ macros_2 = compute_macro_consts(source_2, cc, macro_re, exclude_re)
|
|
|
194aa3 |
+ if macros_1 == macros_2:
|
|
|
194aa3 |
+ return 0
|
|
|
194aa3 |
+ print('First source:\n%s\n' % source_1)
|
|
|
194aa3 |
+ print('Second source:\n%s\n' % source_2)
|
|
|
194aa3 |
+ for name, value in sorted(macros_1.items()):
|
|
|
194aa3 |
+ if name not in macros_2:
|
|
|
194aa3 |
+ print('Only in first source: %s' % name)
|
|
|
194aa3 |
+ elif macros_1[name] != macros_2[name]:
|
|
|
194aa3 |
+ print('Different values for %s: %s != %s'
|
|
|
194aa3 |
+ % (name, macros_1[name], macros_2[name]))
|
|
|
194aa3 |
+ for name in sorted(macros_2.keys()):
|
|
|
194aa3 |
+ if name not in macros_1:
|
|
|
194aa3 |
+ print('Only in second source: %s' % name)
|
|
|
194aa3 |
+ return 1
|
|
|
194aa3 |
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
|
|
|
194aa3 |
index bb055f9d6b841ff5..9c10ee53b26e1b1b 100644
|
|
|
194aa3 |
--- a/sysdeps/unix/sysv/linux/Makefile
|
|
|
194aa3 |
+++ b/sysdeps/unix/sysv/linux/Makefile
|
|
|
194aa3 |
@@ -113,11 +113,14 @@ tests-special += $(objpfx)tst-signal-numbers.out
|
|
|
194aa3 |
# in this context, but signal.c includes signal.h and not much else so it'll
|
|
|
194aa3 |
# be conservatively correct.
|
|
|
194aa3 |
$(objpfx)tst-signal-numbers.out: \
|
|
|
194aa3 |
- ../sysdeps/unix/sysv/linux/tst-signal-numbers.sh \
|
|
|
194aa3 |
+ ../sysdeps/unix/sysv/linux/tst-signal-numbers.py \
|
|
|
194aa3 |
$(objpfx)signal.o*
|
|
|
194aa3 |
- AWK=$(AWK) $(SHELL) ../sysdeps/unix/sysv/linux/tst-signal-numbers.sh \
|
|
|
194aa3 |
- $(CC) $(patsubst -DMODULE_NAME=%,-DMODULE_NAME=testsuite,$(CPPFLAGS)) \
|
|
|
194aa3 |
- < /dev/null > $@; $(evaluate-test)
|
|
|
194aa3 |
+ PYTHONPATH=../scripts \
|
|
|
194aa3 |
+ $(PYTHON) ../sysdeps/unix/sysv/linux/tst-signal-numbers.py \
|
|
|
194aa3 |
+ --cc="$(CC) $(patsubst -DMODULE_NAME=%, \
|
|
|
194aa3 |
+ -DMODULE_NAME=testsuite, \
|
|
|
194aa3 |
+ $(CPPFLAGS))" \
|
|
|
194aa3 |
+ < /dev/null > $@ 2>&1; $(evaluate-test)
|
|
|
194aa3 |
endif
|
|
|
194aa3 |
|
|
|
194aa3 |
ifeq ($(subdir),socket)
|
|
|
194aa3 |
diff --git a/sysdeps/unix/sysv/linux/tst-signal-numbers.py b/sysdeps/unix/sysv/linux/tst-signal-numbers.py
|
|
|
194aa3 |
new file mode 100644
|
|
|
194aa3 |
index 0000000000000000..48c63d1218e8303d
|
|
|
194aa3 |
--- /dev/null
|
|
|
194aa3 |
+++ b/sysdeps/unix/sysv/linux/tst-signal-numbers.py
|
|
|
194aa3 |
@@ -0,0 +1,48 @@
|
|
|
194aa3 |
+#!/usr/bin/python3
|
|
|
194aa3 |
+# Test that glibc's signal numbers match the kernel's.
|
|
|
194aa3 |
+# Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
194aa3 |
+# This file is part of the GNU C Library.
|
|
|
194aa3 |
+#
|
|
|
194aa3 |
+# The GNU C Library is free software; you can redistribute it and/or
|
|
|
194aa3 |
+# modify it under the terms of the GNU Lesser General Public
|
|
|
194aa3 |
+# License as published by the Free Software Foundation; either
|
|
|
194aa3 |
+# version 2.1 of the License, or (at your option) any later version.
|
|
|
194aa3 |
+#
|
|
|
194aa3 |
+# The GNU C Library is distributed in the hope that it will be useful,
|
|
|
194aa3 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
194aa3 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
194aa3 |
+# Lesser General Public License for more details.
|
|
|
194aa3 |
+#
|
|
|
194aa3 |
+# You should have received a copy of the GNU Lesser General Public
|
|
|
194aa3 |
+# License along with the GNU C Library; if not, see
|
|
|
194aa3 |
+# <http://www.gnu.org/licenses/>.
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+import argparse
|
|
|
194aa3 |
+import sys
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+import glibcextract
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+def main():
|
|
|
194aa3 |
+ """The main entry point."""
|
|
|
194aa3 |
+ parser = argparse.ArgumentParser(
|
|
|
194aa3 |
+ description="Test that glibc's signal numbers match the kernel's.")
|
|
|
194aa3 |
+ parser.add_argument('--cc', metavar='CC',
|
|
|
194aa3 |
+ help='C compiler (including options) to use')
|
|
|
194aa3 |
+ args = parser.parse_args()
|
|
|
194aa3 |
+ sys.exit(glibcextract.compare_macro_consts(
|
|
|
194aa3 |
+ '#define _GNU_SOURCE 1\n'
|
|
|
194aa3 |
+ '#include <signal.h>\n',
|
|
|
194aa3 |
+ '#define _GNU_SOURCE 1\n'
|
|
|
194aa3 |
+ '#include <stddef.h>\n'
|
|
|
194aa3 |
+ '#include <asm/signal.h>\n',
|
|
|
194aa3 |
+ args.cc,
|
|
|
194aa3 |
+ # Filter out constants that aren't signal numbers.
|
|
|
194aa3 |
+ 'SIG[A-Z]+',
|
|
|
194aa3 |
+ # Discard obsolete signal numbers and unrelated constants:
|
|
|
194aa3 |
+ # SIGCLD, SIGIOT, SIGSWI, SIGUNUSED.
|
|
|
194aa3 |
+ # SIGSTKSZ, SIGRTMIN, SIGRTMAX.
|
|
|
194aa3 |
+ 'SIG(CLD|IOT|RT(MIN|MAX)|STKSZ|SWI|UNUSED)'))
|
|
|
194aa3 |
+
|
|
|
194aa3 |
+if __name__ == '__main__':
|
|
|
194aa3 |
+ main()
|
|
|
194aa3 |
diff --git a/sysdeps/unix/sysv/linux/tst-signal-numbers.sh b/sysdeps/unix/sysv/linux/tst-signal-numbers.sh
|
|
|
194aa3 |
deleted file mode 100644
|
|
|
194aa3 |
index e1f7be0337c720a6..0000000000000000
|
|
|
194aa3 |
--- a/sysdeps/unix/sysv/linux/tst-signal-numbers.sh
|
|
|
194aa3 |
+++ /dev/null
|
|
|
194aa3 |
@@ -1,86 +0,0 @@
|
|
|
194aa3 |
-#! /bin/sh
|
|
|
194aa3 |
-# Test that glibc's signal numbers match the kernel's.
|
|
|
194aa3 |
-# Copyright (C) 2017-2018 Free Software Foundation, Inc.
|
|
|
194aa3 |
-# This file is part of the GNU C Library.
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-# The GNU C Library is free software; you can redistribute it and/or
|
|
|
194aa3 |
-# modify it under the terms of the GNU Lesser General Public
|
|
|
194aa3 |
-# License as published by the Free Software Foundation; either
|
|
|
194aa3 |
-# version 2.1 of the License, or (at your option) any later version.
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-# The GNU C Library is distributed in the hope that it will be useful,
|
|
|
194aa3 |
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
194aa3 |
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
194aa3 |
-# Lesser General Public License for more details.
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-# You should have received a copy of the GNU Lesser General Public
|
|
|
194aa3 |
-# License along with the GNU C Library; if not, see
|
|
|
194aa3 |
-# <http://www.gnu.org/licenses/>.
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-set -e
|
|
|
194aa3 |
-if [ -n "$BASH_VERSION" ]; then set -o pipefail; fi
|
|
|
194aa3 |
-LC_ALL=C; export LC_ALL
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-# We cannot use Linux's asm/signal.h to define signal numbers, because
|
|
|
194aa3 |
-# it isn't sufficiently namespace-clean. Instead, this test checks
|
|
|
194aa3 |
-# that our signal numbers match the kernel's. This script expects
|
|
|
194aa3 |
-# "$@" to be $(CC) $(CPPFLAGS) as set by glibc's Makefiles, and $AWK
|
|
|
194aa3 |
-# to be set in the environment.
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-# Before doing anything else, fail if the compiler doesn't work.
|
|
|
194aa3 |
-"$@" -E -xc -dM - < /dev/null > /dev/null
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-tmpG=`mktemp -t signums_glibc.XXXXXXXXX`
|
|
|
194aa3 |
-tmpK=`mktemp -t signums_kernel.XXXXXXXXX`
|
|
|
194aa3 |
-trap "rm -f '$tmpG' '$tmpK'" 0
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-# Filter out constants that aren't signal numbers.
|
|
|
194aa3 |
-# If SIGPOLL is defined as SIGIO, swap it around so SIGIO is defined as
|
|
|
194aa3 |
-# SIGPOLL. Similarly for SIGABRT and SIGIOT.
|
|
|
194aa3 |
-# Discard obsolete signal numbers and unrelated constants:
|
|
|
194aa3 |
-# SIGCLD, SIGIOT, SIGSWI, SIGUNUSED.
|
|
|
194aa3 |
-# SIGSTKSZ, SIGRTMIN, SIGRTMAX.
|
|
|
194aa3 |
-# Then sort the list.
|
|
|
194aa3 |
-filter_defines ()
|
|
|
194aa3 |
-{
|
|
|
194aa3 |
- $AWK '
|
|
|
194aa3 |
-/^#define SIG[A-Z]+ ([0-9]+|SIG[A-Z0-9]+)$/ { signals[$2] = $3 }
|
|
|
194aa3 |
-END {
|
|
|
194aa3 |
- if ("SIGPOLL" in signals && "SIGIO" in signals &&
|
|
|
194aa3 |
- signals["SIGPOLL"] == "SIGIO") {
|
|
|
194aa3 |
- signals["SIGPOLL"] = signals["SIGIO"]
|
|
|
194aa3 |
- signals["SIGIO"] = "SIGPOLL"
|
|
|
194aa3 |
- }
|
|
|
194aa3 |
- if ("SIGABRT" in signals && "SIGIOT" in signals &&
|
|
|
194aa3 |
- signals["SIGABRT"] == "SIGIOT") {
|
|
|
194aa3 |
- signals["SIGABRT"] = signals["SIGIOT"]
|
|
|
194aa3 |
- signals["SIGIOT"] = "SIGABRT"
|
|
|
194aa3 |
- }
|
|
|
194aa3 |
- for (sig in signals) {
|
|
|
194aa3 |
- if (sig !~ /^SIG(CLD|IOT|RT(MIN|MAX)|STKSZ|SWI|UNUSED)$/) {
|
|
|
194aa3 |
- printf("#define %s %s\n", sig, signals[sig])
|
|
|
194aa3 |
- }
|
|
|
194aa3 |
- }
|
|
|
194aa3 |
-}' | sort
|
|
|
194aa3 |
-}
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-# $CC may contain command-line switches, so it should be word-split.
|
|
|
194aa3 |
-printf '%s' '#define _GNU_SOURCE 1
|
|
|
194aa3 |
-#include <signal.h>
|
|
|
194aa3 |
-' |
|
|
|
194aa3 |
- "$@" -E -xc -dM - |
|
|
|
194aa3 |
- filter_defines > "$tmpG"
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-printf '%s' '#define _GNU_SOURCE 1
|
|
|
194aa3 |
-#define __ASSEMBLER__ 1
|
|
|
194aa3 |
-#include <asm/signal.h>
|
|
|
194aa3 |
-' |
|
|
|
194aa3 |
- "$@" -E -xc -dM - |
|
|
|
194aa3 |
- filter_defines > "$tmpK"
|
|
|
194aa3 |
-
|
|
|
194aa3 |
-if cmp -s "$tmpG" "$tmpK"; then
|
|
|
194aa3 |
- exit 0
|
|
|
194aa3 |
-else
|
|
|
194aa3 |
- diff -u "$tmpG" "$tmpK"
|
|
|
194aa3 |
- exit 1
|
|
|
194aa3 |
-fi
|