mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-22 04:50:07 +00:00
8e554659ad
This patch continues preparations for adding TS 18661-1 narrowing libm functions by adding the required testsuite infrastructure to test such functions through the libm-test infrastructure. That infrastructure is based around testing for a single type, FLOAT. For the narrowing functions, FLOAT, the "main" type for testing, is the function return type; the argument type is ARG_FLOAT. This is consistent with how the code built once for each type, libm-test-support.c, depends on FLOAT for such things as calculating ulps errors in results but can already handle different argument types (pointers, integers, long double for nexttoward). Makefile machinery is added to handle building tests for all pairs of types for which there are narrowing functions (as with non-narrowing functions, aliases are tested just the same as the functions they alias). gen-auto-libm-tests gains a --narrow option for building outputs for narrowing functions (so narrowing sqrt and fma will share the same inputs as non-narrowing, but gen-auto-libm-tests will be run with and without that option to generate different output files). In the narrowing case, the auto-libm-test-out-narrow-* files include annotations for each test about what properties ARG_FLOAT must have to be able to represent all the inputs for that test; those annotations result in calls to the TEST_COND_arg_fmt macro. gen-libm-test.pl has some minor updates to handle narrowing tests (for example, arguments in such tests must be surrounded by ARG_LIT calls instead of LIT calls). Various new macros are added to the C test support code (for example, sNaN initializers need to be properly typed, so arg_snan_value is added; other such arg_* macros are added as it seems cleanest to do so, though some are not strictly required). Special-casing of the ibm128 format to allow for its limitations is adjusted to handle it as the argument format as well as as the result format; thus, the tests of the new functions allow nonzero ulps only in the case where ibm128 is the argument format, as otherwise the functions correspond to fully-defined IEEE operations. The ulps in question appear as e.g. 'Function: "add_ldouble"' in libm-test-ulps (with 1ulp errors then listed for double and float for that function in powerpc); no support is added to generate corresponding faddl / daddl ulps listings in the ulps table in the manual. For the previous patch, I noted the need to avoid spurious macro expansions of identifiers such as "add". A test test-narrow-macros.c is added to verify such macro expansions are successfully avoided, and there is also a -mlong-double-64 version of that test for ldbl-opt. This test is set up to cover the full set of relevant identifiers from the start rather than adding functions one at a time as each function group is added. Tested for x86_64 (this patch in isolation, as well as testing for various configurations in conjunction with the actual addition of "add" functions). * math/Makefile (test-type-pairs): New variable. (test-type-pairs-f64xf128-yes): Likewise. (tests): Add test-narrow-macros. (libm-test-funcs-narrow): New variable. (libm-test-c-narrow): Likewise. (generated): Add $(libm-test-c-narrow). (libm-tests-base-narrow): New variable. (libm-tests-narrow): Likewise. (libm-tests): Add $(libm-tests-narrow). (libm-tests-for-type): Handle $(libm-tests-narrow). (libm-test-c-narrow-obj): New variable. ($(libm-test-c-narrow-obj)): New rule. ($(foreach t,$(libm-tests-narrow),$(objpfx)$(t).c)): Likewise. ($(foreach f,$(libm-test-funcs-narrow),$(objpfx)$(o)-$(f).o)): Use $(o-iterator) to set dependencies and CFLAGS. * math/gen-auto-libm-tests.c: Document use for narrowing functions. (output_for_one_input_case): Take argument NARROW. (generate_output): Likewise. Update call to output_for_one_input_case. (main): Take --narrow option. Update call to generate_output. * math/gen-libm-test.pl (_apply_lit): Take macro name as argument. (apply_lit): Update call to _apply_lit. (apply_arglit): New function. (parse_args): Handle "a" arguments. (parse_auto_input): Handle format names using ":". * math/README.libm-test: Document "a" parameter type. * math/libm-test-support.h (ARG_TYPE_MIN): New macro. (ARG_TYPE_TRUE_MIN): Likewise. (ARG_TYPE_MAX): Likwise. (ARG_MIN_EXP): Likewise. (ARG_MAX_EXP): Likewise. (ARG_MANT_DIG): Likewise. (TEST_COND_arg_ibm128): Likewise. (TEST_COND_ibm128_libgcc): Define conditional on [ARG_FLOAT]. (TEST_COND_arg_fmt): New macro. (init_max_error): Update prototype. * math/libm-test-support.c (test_ibm128): New variable. (init_max_error): Take argument testing_ibm128 and set test_ibm128 instead of using [TEST_COND_ibm128] conditional. (test_exceptions): Use test_ibm128 instead of TEST_COND_ibm128. * math/libm-test-driver.c (STR_ARG_FLOAT): New macro. [TEST_NARROW] (TEST_MSG): New definition. (arg_plus_zero): New macro. (arg_minus_zero): Likewise. (arg_plus_infty): Likewise. (arg_minus_infty): Likewise. (arg_qnan_value_pl): Likewise. (arg_qnan_value): Likewise. (arg_snan_value_pl): Likewise. (arg_snan_value): Likewise. (arg_max_value): Likewise. (arg_min_value): Likewise. (arg_min_subnorm_value): Likewise. [ARG_FLOAT] (struct test_aa_f_data): New struct type. (RUN_TEST_LOOP_aa_f): New macro. (TEST_SUFF): New macro. (TEST_SUFF_STR): Likewise. [!TEST_MATHVEC] (VEC_SUFF): Don't define. (TEST_COND_any_ibm128): New macro. (START): Use TEST_SUFF and TEST_SUFF_STR in initializer for this_func. Update call to init_max_error. * math/test-double.h (FUNC_NARROW_PREFIX): New macro. * math/test-float.h (FUNC_NARROW_PREFIX): Likewise. * math/test-float128.h (FUNC_NARROW_PREFIX): Likewise. * math/test-float32.h (FUNC_NARROW_PREFIX): Likewise. * math/test-float32x.h (FUNC_NARROW_PREFIX): Likewise. * math/test-float64.h (FUNC_NARROW_PREFIX): Likewise. * math/test-float64x.h (FUNC_NARROW_PREFIX): Likewise. * math/test-math-scalar.h (TEST_NARROW): Likewise. * math/test-math-vector.h (TEST_NARROW): Likewise. * math/test-arg-double.h: New file. * math/test-arg-float128.h: Likewise. * math/test-arg-float32x.h: Likewise. * math/test-arg-float64.h: Likewise. * math/test-arg-float64x.h: Likewise. * math/test-arg-ldouble.h: Likewise. * math/test-math-narrow.h: Likewise. * math/test-narrow-macros.c: Likewise. * sysdeps/ieee754/ldbl-opt/test-narrow-macros-ldbl-64.c: Likewise. * sysdeps/ieee754/ldbl-opt/Makefile (tests): Add test-narrow-macros-ldbl-64. (CFLAGS-test-narrow-macros-ldbl-64.c): New variable.
168 lines
7.8 KiB
Plaintext
168 lines
7.8 KiB
Plaintext
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".
|
|
|
|
|
|
What is tested?
|
|
===============
|
|
The tests just evaluate the functions at specified points and compare
|
|
the results with precomputed values and the requirements of the ISO
|
|
C99 standard.
|
|
|
|
Besides testing the special values mandated by IEEE 754 (infinities,
|
|
NaNs and minus zero), some more or less random values are tested.
|
|
|
|
Files that are part of libm-test
|
|
================================
|
|
|
|
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
|
|
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
|
|
platform specific deltas by which the actual math function results may
|
|
deviate from the expected results and still be considered correct.
|
|
|
|
The test drivers "test-double-<func>.c", "test-float-<func>.c", and
|
|
"test-ldouble-<func>.c", generated by the Makefile, test the normal
|
|
double, float and long double implementation of libm. The test
|
|
drivers with an 'i' in their name ("test-idouble-<func>.c",
|
|
"test-ifloat-<func>.c", and "test-ildoubl-<func>.c") test the
|
|
corresponding inline functions (where available - otherwise they also
|
|
test the real functions in libm). Each driver selects the desired
|
|
real floating type to exercise the math functions to test with (float,
|
|
double, or long double) by defining a small set of macros just before
|
|
including the generic "libm-test.c" file. Each driver also either
|
|
defines or undefines the __NO_MATH_INLINES macro just before including
|
|
"libm-test-<func>.c" to select either the real or inline functions,
|
|
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
|
|
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
|
|
maximum difference expressed as Units of Least Precision (ULP) the
|
|
actual result of the function may deviate from the expected result
|
|
before it's considered incorrect.
|
|
|
|
The "auto-libm-test-out-<func>" files contain sets of test cases to
|
|
exercise, the conditions under which to exercise each, and the
|
|
expected results. The files are generated by the
|
|
"gen-auto-libm-tests" program from the "auto-libm-test-in" file. See
|
|
the comments in gen-auto-libm-tests.c for details about the content
|
|
and format of the -in and -out files.
|
|
|
|
How can I generate "libm-test-ulps"?
|
|
====================================
|
|
|
|
To automatically generate a new "libm-test-ulps" run "make regen-ulps".
|
|
This generates the file "math/NewUlps" in the build directory. The file
|
|
contains the sorted results of all the tests. You can use the "NewUlps"
|
|
file as the machine's updated "libm-test-ulps" file. Copy "NewUlps" to
|
|
"libm-test-ulps" in the appropriate machine sysdep directory. Verify
|
|
the changes, post your patch, and check it in after review.
|
|
|
|
To manually generate a new "libm-test-ulps" file, first remove "ULPs"
|
|
file in the current directory, then you can execute for example:
|
|
./testrun.sh math/test-double -u --ignore-max-ulp=yes
|
|
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
|
|
file as input and ask to generate a pretty printed output in the file
|
|
"NewUlps":
|
|
gen-libm-test.pl -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
|
|
sorted new ULPs file from the output of the test drivers.
|
|
|
|
Contents of libm-test-ulps
|
|
==========================
|
|
|
|
Since libm-test-ulps can be generated automatically, just a few notes.
|
|
The file contains lines for maximal errors of single functions, like:
|
|
|
|
Function "yn":
|
|
idouble: 6
|
|
|
|
The keywords are float, ifloat, double, idouble, ldouble and ildouble
|
|
(the prefix i stands for inline).
|
|
|
|
Adding tests to libm-test-<func>.inc
|
|
====================================
|
|
|
|
The tests are evaluated by a set of special test macros. The macros
|
|
start with "TEST_" followed by a specification the input values, an
|
|
underscore and a specification of the output values. As an example,
|
|
the test macro for a function with input of type FLOAT (FLOAT is
|
|
either float, double, long double) and output of type FLOAT is
|
|
"TEST_f_f". The macro's parameter are the name of the function, the
|
|
input parameter, output parameter and optionally one exception
|
|
parameter.
|
|
|
|
The accepted parameter types are:
|
|
- "f" for FLOAT
|
|
- "j" for long double.
|
|
- "a" for ARG_FLOAT, the argument type for narrowing functions.
|
|
- "b" for boolean - just tests if the output parameter evaluates to 0
|
|
or 1 (only for output).
|
|
- "c" for complex. This parameter needs two values, first the real,
|
|
then the imaginary part.
|
|
- "i" for int.
|
|
- "l" for long int.
|
|
- "L" for long long int.
|
|
- "u" for unsigned int.
|
|
- "M" for intmax_t.
|
|
- "U" for uintmax_t.
|
|
- "p" for an argument (described in the previous character) passed
|
|
through a pointer rather than directly.
|
|
- "F" for the address of a FLOAT (only as input parameter)
|
|
- "I" for the address of an int (only as input parameter)
|
|
- "1" for an additional output (either output through a pointer passed
|
|
as an argument, or to a global variable such as signgam).
|
|
|
|
How to read the test output
|
|
===========================
|
|
|
|
Running each test on its own at the default level of verbosity will
|
|
print on stdout a line describing the implementation of math functions
|
|
exercised by the test (float, double, or long double), along with
|
|
whether the inline set has been selected, regardless of whether or
|
|
not any inline functions actually exist. This is then followed by
|
|
the details of test failures (if any). The output concludes by
|
|
a summary listing the number of test cases exercised and the number
|
|
of test failures uncovered.
|
|
|
|
For each test failure (and for each test case at higher levels of
|
|
verbosity), the output contains the name of the function under test
|
|
and its arguments or conditions that triggered the failure. Note
|
|
that the name of the function in the output need not correspond
|
|
exactly to the name of the math function actually invoked. For example,
|
|
the output will refer to the "acos" function even if the actual function
|
|
under test is acosf (for the float version) or acosl (for the long
|
|
double version). Also note that the function arguments may be shown
|
|
in either the decimal or the hexadecimal floating point format which
|
|
may or may not correspond to the format used in the auto-libm-test-in
|
|
file. Besides the name of the function, for each test failure the
|
|
output contains the actual and expected results and the difference
|
|
between the two, printed in both the decimal and hexadecimal
|
|
floating point format, and the ULP and maximum ULP for the test
|
|
case.
|