Skip to content

Commit

Permalink
Replace gen-libm-test.pl with gen-libm-test.py.
Browse files Browse the repository at this point in the history
Following the recent discussion of using Python instead of Perl and
Awk for glibc build / test, this patch replaces gen-libm-test.pl with
a new gen-libm-test.py script.  This script should work with all
Python versions supported by glibc (tested by hand with Python 2.7,
tested in the build system with Python 3.5; configure prefers Python 3
if available).

This script is designed to give identical output to gen-libm-test.pl
for ease of verification of the change, except for generated comments
referring to .py instead of .pl.  (That is, identical for actual
inputs passed to the script, not necessarily for all possible input;
for example, this version more precisely follows the C standard syntax
for floating-point constants when deciding when to add LIT macro
calls.)  In one place a comment notes that the generation of
NON_FINITE flags is replicating a bug in the Perl script to assist in
such comparisons (with the expectation that this bug can then be
separately fixed in the Python script later).

Tested for x86_64, including comparison of generated files (and hand
testing of the case of generating a sorted libm-test-ulps file, which
isn't covered by normal "make check").

I'd expect to follow this up by extending the new script to produce
the ulps tables for the manual as well (replacing
manual/libm-err-tab.pl, so that then we just have one ulps file
parser) - at which point the manual build would depend on both Perl
and Python (eliminating the Perl dependency would require someone to
rewrite summary.pl in Python, and that would only eliminate the
*direct* Perl dependency; current makeinfo is written in Perl so there
would still be an indirect dependency).

I think install.texi is more or less equally out-of-date regarding
Perl and Python uses before and after this patch, so I don't think
this patch depends on my patch
<https://sourceware.org/ml/libc-alpha/2018-08/msg00133.html> to update
install.texi regarding such uses (pending review).

	* math/gen-libm-test.py: New file.
	* math/gen-libm-test.pl: Remove.
	* math/Makefile [$(PERL) != no]: Change condition to [PYTHON].
	($(objpfx)libm-test-ulps.h): Use gen-libm-test.py instead of
	gen-libm-test.pl.
	($(libm-test-c-noauto-obj)): Likewise.
	($(libm-test-c-auto-obj)): Likewise.
	($(libm-test-c-narrow-obj)): Likewise.
	(regen-ulps): Likewise.
	* math/README.libm-test: Update references to gen-libm-test.pl.
	* math/libm-test-driver.c (struct test_fj_f_data): Update comment
	referencing gen-libm-test.pl.
	* math/libm-test-nexttoward.inc (nexttoward_test_data): Likewise.
	* math/libm-test-support.c: Likewise.
	* math/libm-test-support.h: Likewise.
	* sysdeps/generic/libm-test-ulps: Likewise.
  • Loading branch information
jsm28 committed Aug 9, 2018
1 parent 8ac0f9e commit 2813e41
Show file tree
Hide file tree
Showing 10 changed files with 651 additions and 875 deletions.
19 changes: 19 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
2018-08-09 Joseph Myers <[email protected]>

* math/gen-libm-test.py: New file.
* math/gen-libm-test.pl: Remove.
* math/Makefile [$(PERL) != no]: Change condition to [PYTHON].
($(objpfx)libm-test-ulps.h): Use gen-libm-test.py instead of
gen-libm-test.pl.
($(libm-test-c-noauto-obj)): Likewise.
($(libm-test-c-auto-obj)): Likewise.
($(libm-test-c-narrow-obj)): Likewise.
(regen-ulps): Likewise.
* math/README.libm-test: Update references to gen-libm-test.pl.
* math/libm-test-driver.c (struct test_fj_f_data): Update comment
referencing gen-libm-test.pl.
* math/libm-test-nexttoward.inc (nexttoward_test_data): Likewise.
* math/libm-test-support.c: Likewise.
* math/libm-test-support.h: Likewise.
* sysdeps/generic/libm-test-ulps: Likewise.

2018-08-08 Siddhesh Poyarekar <[email protected]>

* sysdeps/aarch64/strlen.S [TEST_PAGE_CROSS](MIN_PAGE_SIZE):
Expand Down
26 changes: 13 additions & 13 deletions math/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ tests += test-math-isinff test-math-iszero test-math-issignaling \
test-math-iscanonical test-math-cxx11 test-math-iseqsig
endif

ifneq (no,$(PERL))
ifdef PYTHON
libm-vec-tests = $(addprefix test-,$(libmvec-tests))
libm-test-support = $(foreach t,$(test-types),libm-test-support-$(t))
test-extras += $(libm-test-support)
Expand All @@ -263,9 +263,9 @@ extra-test-objs += $(addsuffix .o, $(libm-vec-test-wrappers))

ulps-file = $(firstword $(wildcard $(sysdirs:%=%/libm-test-ulps)))

$(objpfx)libm-test-ulps.h: $(ulps-file) gen-libm-test.pl
$(objpfx)libm-test-ulps.h: $(ulps-file) gen-libm-test.py
$(make-target-directory)
$(PERL) gen-libm-test.pl -u $< -H $@
$(PYTHON) gen-libm-test.py -u $< -H $@

libm-test-funcs-auto = acos acosh asin asinh atan atan2 atanh cabs cacos \
cacosh carg casin casinh catan catanh cbrt ccos ccosh \
Expand Down Expand Up @@ -333,21 +333,21 @@ libm-test-c-noauto-obj = $(addprefix $(objpfx),$(libm-test-c-noauto))
libm-test-c-narrow-obj = $(addprefix $(objpfx),$(libm-test-c-narrow))

$(libm-test-c-noauto-obj): $(objpfx)libm-test%.c: libm-test%.inc \
gen-libm-test.pl
gen-libm-test.py
$(make-target-directory)
$(PERL) gen-libm-test.pl -c $< -a /dev/null -C $@
$(PYTHON) gen-libm-test.py -c $< -a /dev/null -C $@

$(libm-test-c-auto-obj): $(objpfx)libm-test%.c: libm-test%.inc \
gen-libm-test.pl \
gen-libm-test.py \
auto-libm-test-out%
$(make-target-directory)
$(PERL) gen-libm-test.pl -c $< -a auto-libm-test-out$* -C $@
$(PYTHON) gen-libm-test.py -c $< -a auto-libm-test-out$* -C $@

$(libm-test-c-narrow-obj): $(objpfx)libm-test%.c: libm-test%.inc \
gen-libm-test.pl \
gen-libm-test.py \
auto-libm-test-out%
$(make-target-directory)
$(PERL) gen-libm-test.pl -c $< -a auto-libm-test-out$* -C $@
$(PYTHON) gen-libm-test.py -c $< -a auto-libm-test-out$* -C $@
endif

ifdef PYTHON
Expand Down Expand Up @@ -473,7 +473,7 @@ $(objpfx)gen-libm-templates.stmp: Makefile
$(foreach t, $(call type-foreach, $(gen-all-calls)), \
$(objpfx)$(t).c): $(objpfx)gen-libm-templates.stmp

ifneq (no,$(PERL))
ifdef PYTHON
# This must come after the inclusion of sysdeps Makefiles via Rules.

$(foreach t,$(libm-tests-normal),$(objpfx)$(t).c): $(objpfx)test-%.c:
Expand Down Expand Up @@ -628,15 +628,15 @@ regen-ulps: $(addprefix $(objpfx),$(libm-tests))
cat $(objpfx)ULPs >> $(objpfx)libm-test-ulps; \
rm $(objpfx)ULPs; \
done; \
$(PERL) gen-libm-test.pl -n $(objpfx)NewUlps \
-u $(objpfx)libm-test-ulps; \
$(PYTHON) gen-libm-test.py -n $(objpfx)NewUlps \
-u $(objpfx)libm-test-ulps; \
echo "Automatic regeneration of ULPs complete."; \
echo "Difference between the current baseline and the new baseline is:";\
diff -urN $(ulps-file) $(objpfx)NewUlps; \
echo "Copy $(objpfx)NewUlps to $(ulps-file) (relative to source)."
else
regen-ulps:
@echo "Automatic regeneration of ULPs requires perl."; \
@echo "Automatic regeneration of ULPs requires python."; \
exit 1;
endif

Expand Down
20 changes: 10 additions & 10 deletions math/README.libm-test
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ README for libm-test math test suite

The libm-test math test suite tests a number of function points of
math functions in the GNU C library. The following sections contain a
brief overview. Please note that the test drivers and the Perl script
"gen-libm-test.pl" have some options. A full list of options is
available with --help (for the test drivers) and -h for
"gen-libm-test.pl".
brief overview. Please note that the test drivers and the Python
script "gen-libm-test.py" have some options. A full list of options
is available with --help (for the test drivers) and -h for
"gen-libm-test.py".


What is tested?
Expand All @@ -25,8 +25,8 @@ The main files are "libm-test-<func>.inc". They are independent of
the target platform and the specific real floating type and format and
contain placeholder test "templates" for math functions defined in
libm. These files, along with generated files named
"auto-libm-test-out-<func>", are preprocessed by the Perl script
"gen-libm-test.pl" to expand the templates and produce a set of test
"auto-libm-test-out-<func>", are preprocessed by the Python script
"gen-libm-test.py" to expand the templates and produce a set of test
cases for each math function that are specific to the target platform
but still independent of the real floating type. The results of the
processing are "libm-test-<func>.c" and a file "libm-test-ulps.h" with
Expand All @@ -48,7 +48,7 @@ defines or undefines the __NO_MATH_INLINES macro just before including
respectively. Each driver is compiled into a single executable test
program with the corresponding name.

As mentioned above, the "gen-libm-test.pl" script looks for a file
As mentioned above, the "gen-libm-test.py" script looks for a file
named "libm-test-ulps" in the platform specific sysdep directory (or
its fpu or nofpu subdirectory) and for each variant (real floating
type and rounding mode) of every tested function reads from it the
Expand Down Expand Up @@ -80,17 +80,17 @@ This generates a file "ULPs" with all double ULPs in it, ignoring any
previously calculated ULPs, and running with the newly built dynamic
loader and math library (assumes you didn't install your build). Now
generate the ULPs for all other formats, the tests will be appending the
data to the "ULPs" file. As final step run "gen-libm-test.pl" with the
data to the "ULPs" file. As final step run "gen-libm-test.py" with the
file as input and ask to generate a pretty printed output in the file
"NewUlps":
gen-libm-test.pl -u ULPs -n NewUlps
gen-libm-test.py -u ULPs -n NewUlps
Copy "NewUlps" to "libm-test-ulps" in the appropriate machine sysdep
directory.

Note that the test drivers have an option "-u" to output an unsorted
list of all epsilons that the functions have. The output can be read
in directly but it's better to pretty print it first.
"gen-libm-test.pl" has an option to generate a pretty-printed and
"gen-libm-test.py" has an option to generate a pretty-printed and
sorted new ULPs file from the output of the test drivers.

Contents of libm-test-ulps
Expand Down
Loading

0 comments on commit 2813e41

Please sign in to comment.