Blame math/README.libm-test

Packit Service 82fcde
README for libm-test math test suite
Packit Service 82fcde
====================================
Packit Service 82fcde
Packit Service 82fcde
The libm-test math test suite tests a number of function points of
Packit Service 82fcde
math functions in the GNU C library.  The following sections contain a
Packit Service 82fcde
brief overview.  Please note that the test drivers and the Perl script
Packit Service 82fcde
"gen-libm-test.pl" have some options.  A full list of options is
Packit Service 82fcde
available with --help (for the test drivers) and -h for
Packit Service 82fcde
"gen-libm-test.pl".
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
What is tested?
Packit Service 82fcde
===============
Packit Service 82fcde
The tests just evaluate the functions at specified points and compare
Packit Service 82fcde
the results with precomputed values and the requirements of the ISO
Packit Service 82fcde
C99 standard.
Packit Service 82fcde
Packit Service 82fcde
Besides testing the special values mandated by IEEE 754 (infinities,
Packit Service 82fcde
NaNs and minus zero), some more or less random values are tested.
Packit Service 82fcde
Packit Service 82fcde
Files that are part of libm-test
Packit Service 82fcde
================================
Packit Service 82fcde
Packit Service 82fcde
The main files are "libm-test-<func>.inc".  They are independent of
Packit Service 82fcde
the target platform and the specific real floating type and format and
Packit Service 82fcde
contain placeholder test "templates" for math functions defined in
Packit Service 82fcde
libm.  These files, along with generated files named
Packit Service 82fcde
"auto-libm-test-out-<func>", are preprocessed by the Perl script
Packit Service 82fcde
"gen-libm-test.pl" to expand the templates and produce a set of test
Packit Service 82fcde
cases for each math function that are specific to the target platform
Packit Service 82fcde
but still independent of the real floating type.  The results of the
Packit Service 82fcde
processing are "libm-test-<func>.c" and a file "libm-test-ulps.h" with
Packit Service 82fcde
platform specific deltas by which the actual math function results may
Packit Service 82fcde
deviate from the expected results and still be considered correct.
Packit Service 82fcde
Packit Service 82fcde
The test drivers "test-double-<func>.c", "test-float-<func>.c", and
Packit Service 82fcde
"test-ldouble-<func>.c", generated by the Makefile, test the normal
Packit Service 82fcde
double, float and long double implementation of libm.  The test
Packit Service 82fcde
drivers with an 'i' in their name ("test-idouble-<func>.c",
Packit Service 82fcde
"test-ifloat-<func>.c", and "test-ildoubl-<func>.c") test the
Packit Service 82fcde
corresponding inline functions (where available - otherwise they also
Packit Service 82fcde
test the real functions in libm).  Each driver selects the desired
Packit Service 82fcde
real floating type to exercise the math functions to test with (float,
Packit Service 82fcde
double, or long double) by defining a small set of macros just before
Packit Service 82fcde
including the generic "libm-test.c" file.  Each driver also either
Packit Service 82fcde
defines or undefines the __NO_MATH_INLINES macro just before including
Packit Service 82fcde
"libm-test-<func>.c" to select either the real or inline functions,
Packit Service 82fcde
respectively.  Each driver is compiled into a single executable test
Packit Service 82fcde
program with the corresponding name.
Packit Service 82fcde
Packit Service 82fcde
As mentioned above, the "gen-libm-test.pl" script looks for a file
Packit Service 82fcde
named "libm-test-ulps" in the platform specific sysdep directory (or
Packit Service 82fcde
its fpu or nofpu subdirectory) and for each variant (real floating
Packit Service 82fcde
type and rounding mode) of every tested function reads from it the
Packit Service 82fcde
maximum difference expressed as Units of Least Precision (ULP) the
Packit Service 82fcde
actual result of the function may deviate from the expected result
Packit Service 82fcde
before it's considered incorrect.
Packit Service 82fcde
Packit Service 82fcde
The "auto-libm-test-out-<func>" files contain sets of test cases to
Packit Service 82fcde
exercise, the conditions under which to exercise each, and the
Packit Service 82fcde
expected results.  The files are generated by the
Packit Service 82fcde
"gen-auto-libm-tests" program from the "auto-libm-test-in" file.  See
Packit Service 82fcde
the comments in gen-auto-libm-tests.c for details about the content
Packit Service 82fcde
and format of the -in and -out files.
Packit Service 82fcde
Packit Service 82fcde
How can I generate "libm-test-ulps"?
Packit Service 82fcde
====================================
Packit Service 82fcde
Packit Service 82fcde
To automatically generate a new "libm-test-ulps" run "make regen-ulps".
Packit Service 82fcde
This generates the file "math/NewUlps" in the build directory.  The file
Packit Service 82fcde
contains the sorted results of all the tests.  You can use the "NewUlps"
Packit Service 82fcde
file as the machine's updated "libm-test-ulps" file.  Copy "NewUlps" to
Packit Service 82fcde
"libm-test-ulps" in the appropriate machine sysdep directory.  Verify
Packit Service 82fcde
the changes, post your patch, and check it in after review.
Packit Service 82fcde
Packit Service 82fcde
To manually generate a new "libm-test-ulps" file, first remove "ULPs"
Packit Service 82fcde
file in the current directory, then you can execute for example:
Packit Service 82fcde
    ./testrun.sh math/test-double -u --ignore-max-ulp=yes
Packit Service 82fcde
This generates a file "ULPs" with all double ULPs in it, ignoring any
Packit Service 82fcde
previously calculated ULPs, and running with the newly built dynamic
Packit Service 82fcde
loader and math library (assumes you didn't install your build).  Now
Packit Service 82fcde
generate the ULPs for all other formats, the tests will be appending the
Packit Service 82fcde
data to the "ULPs" file.  As final step run "gen-libm-test.pl" with the
Packit Service 82fcde
file as input and ask to generate a pretty printed output in the file
Packit Service 82fcde
"NewUlps":
Packit Service 82fcde
  gen-libm-test.pl -u ULPs -n NewUlps
Packit Service 82fcde
Copy "NewUlps" to "libm-test-ulps" in the appropriate machine sysdep
Packit Service 82fcde
directory.
Packit Service 82fcde
Packit Service 82fcde
Note that the test drivers have an option "-u" to output an unsorted
Packit Service 82fcde
list of all epsilons that the functions have.  The output can be read
Packit Service 82fcde
in directly but it's better to pretty print it first.
Packit Service 82fcde
"gen-libm-test.pl" has an option to generate a pretty-printed and
Packit Service 82fcde
sorted new ULPs file from the output of the test drivers.
Packit Service 82fcde
Packit Service 82fcde
Contents of libm-test-ulps
Packit Service 82fcde
==========================
Packit Service 82fcde
Packit Service 82fcde
Since libm-test-ulps can be generated automatically, just a few notes.
Packit Service 82fcde
The file contains lines for maximal errors of single functions, like:
Packit Service 82fcde
Packit Service 82fcde
Function "yn":
Packit Service 82fcde
idouble: 6
Packit Service 82fcde
Packit Service 82fcde
The keywords are float, ifloat, double, idouble, ldouble and ildouble
Packit Service 82fcde
(the prefix i stands for inline).
Packit Service 82fcde
Packit Service 82fcde
Adding tests to libm-test-<func>.inc
Packit Service 82fcde
====================================
Packit Service 82fcde
Packit Service 82fcde
The tests are evaluated by a set of special test macros.  The macros
Packit Service 82fcde
start with "TEST_" followed by a specification the input values, an
Packit Service 82fcde
underscore and a specification of the output values.  As an example,
Packit Service 82fcde
the test macro for a function with input of type FLOAT (FLOAT is
Packit Service 82fcde
either float, double, long double) and output of type FLOAT is
Packit Service 82fcde
"TEST_f_f".  The macro's parameter are the name of the function, the
Packit Service 82fcde
input parameter, output parameter and optionally one exception
Packit Service 82fcde
parameter.
Packit Service 82fcde
Packit Service 82fcde
The accepted parameter types are:
Packit Service 82fcde
- "f" for FLOAT
Packit Service 82fcde
- "j" for long double.
Packit Service 82fcde
- "a" for ARG_FLOAT, the argument type for narrowing functions.
Packit Service 82fcde
- "b" for boolean - just tests if the output parameter evaluates to 0
Packit Service 82fcde
  or 1 (only for output).
Packit Service 82fcde
- "c" for complex.  This parameter needs two values, first the real,
Packit Service 82fcde
  then the imaginary part.
Packit Service 82fcde
- "i" for int.
Packit Service 82fcde
- "l" for long int.
Packit Service 82fcde
- "L" for long long int.
Packit Service 82fcde
- "u" for unsigned int.
Packit Service 82fcde
- "M" for intmax_t.
Packit Service 82fcde
- "U" for uintmax_t.
Packit Service 82fcde
- "p" for an argument (described in the previous character) passed
Packit Service 82fcde
  through a pointer rather than directly.
Packit Service 82fcde
- "F" for the address of a FLOAT (only as input parameter)
Packit Service 82fcde
- "I" for the address of an int (only as input parameter)
Packit Service 82fcde
- "1" for an additional output (either output through a pointer passed
Packit Service 82fcde
  as an argument, or to a global variable such as signgam).
Packit Service 82fcde
Packit Service 82fcde
How to read the test output
Packit Service 82fcde
===========================
Packit Service 82fcde
Packit Service 82fcde
Running each test on its own at the default level of verbosity will
Packit Service 82fcde
print on stdout a line describing the implementation of math functions
Packit Service 82fcde
exercised by the test (float, double, or long double), along with
Packit Service 82fcde
whether the inline set has been selected, regardless of whether or
Packit Service 82fcde
not any inline functions actually exist.  This is then followed by
Packit Service 82fcde
the details of test failures (if any).  The output concludes by
Packit Service 82fcde
a summary listing the number of test cases exercised and the number
Packit Service 82fcde
of test failures uncovered.
Packit Service 82fcde
Packit Service 82fcde
For each test failure (and for each test case at higher levels of
Packit Service 82fcde
verbosity), the output contains the name of the function under test
Packit Service 82fcde
and its arguments or conditions that triggered the failure.  Note
Packit Service 82fcde
that the name of the function in the output need not correspond
Packit Service 82fcde
exactly to the name of the math function actually invoked. For example,
Packit Service 82fcde
the output will refer to the "acos" function even if the actual function
Packit Service 82fcde
under test is acosf (for the float version) or acosl (for the long
Packit Service 82fcde
double version).  Also note that the function arguments may be shown
Packit Service 82fcde
in either the decimal or the  hexadecimal floating point format which
Packit Service 82fcde
may or may not correspond to the format used in the auto-libm-test-in
Packit Service 82fcde
file. Besides the name of the function, for each test failure the
Packit Service 82fcde
output contains the actual and expected results and the difference
Packit Service 82fcde
between the two, printed in both the decimal and hexadecimal
Packit Service 82fcde
floating point format, and the ULP and maximum ULP for the test
Packit Service 82fcde
case.