]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/README.libm-test
Add build infrastructure for narrowing libm functions.
[thirdparty/glibc.git] / math / README.libm-test
CommitLineData
a9b5d2ee
UD
1README for libm-test math test suite
2====================================
3
4The libm-test math test suite tests a number of function points of
5math functions in the GNU C library. The following sections contain a
6brief overview. Please note that the test drivers and the Perl script
7"gen-libm-test.pl" have some options. A full list of options is
8available with --help (for the test drivers) and -h for
9"gen-libm-test.pl".
10
11
12What is tested?
13===============
14The tests just evaluate the functions at specified points and compare
15the results with precomputed values and the requirements of the ISO
16C99 standard.
17
18Besides testing the special values mandated by IEEE 754 (infinities,
19NaNs and minus zero), some more or less random values are tested.
20
21Files that are part of libm-test
22================================
23
5cbb5849
JM
24The main files are "libm-test-<func>.inc". They are independent of
25the target platform and the specific real floating type and format and
26contain placeholder test "templates" for math functions defined in
27libm. These files, along with generated files named
28"auto-libm-test-out-<func>", are preprocessed by the Perl script
29"gen-libm-test.pl" to expand the templates and produce a set of test
30cases for each math function that are specific to the target platform
31but still independent of the real floating type. The results of the
32processing are "libm-test-<func>.c" and a file "libm-test-ulps.h" with
33platform specific deltas by which the actual math function results may
34deviate from the expected results and still be considered correct.
527de9e4 35
92061bb0
JM
36The test drivers "test-double-<func>.c", "test-float-<func>.c", and
37"test-ldouble-<func>.c", generated by the Makefile, test the normal
38double, float and long double implementation of libm. The test
39drivers with an 'i' in their name ("test-idouble-<func>.c",
40"test-ifloat-<func>.c", and "test-ildoubl-<func>.c") test the
41corresponding inline functions (where available - otherwise they also
42test the real functions in libm). Each driver selects the desired
43real floating type to exercise the math functions to test with (float,
44double, or long double) by defining a small set of macros just before
45including the generic "libm-test.c" file. Each driver also either
46defines or undefines the __NO_MATH_INLINES macro just before including
47"libm-test-<func>.c" to select either the real or inline functions,
527de9e4
MS
48respectively. Each driver is compiled into a single executable test
49program with the corresponding name.
50
51As mentioned above, the "gen-libm-test.pl" script looks for a file
52named "libm-test-ulps" in the platform specific sysdep directory (or
53its fpu or nofpu subdirectory) and for each variant (real floating
54type and rounding mode) of every tested function reads from it the
55maximum difference expressed as Units of Least Precision (ULP) the
56actual result of the function may deviate from the expected result
57before it's considered incorrect.
58
4f1bc131
JM
59The "auto-libm-test-out-<func>" files contain sets of test cases to
60exercise, the conditions under which to exercise each, and the
61expected results. The files are generated by the
62"gen-auto-libm-tests" program from the "auto-libm-test-in" file. See
63the comments in gen-auto-libm-tests.c for details about the content
64and format of the -in and -out files.
a9b5d2ee
UD
65
66How can I generate "libm-test-ulps"?
67====================================
68
26510bdd
CD
69To automatically generate a new "libm-test-ulps" run "make regen-ulps".
70This generates the file "math/NewUlps" in the build directory. The file
71contains the sorted results of all the tests. You can use the "NewUlps"
72file as the machine's updated "libm-test-ulps" file. Copy "NewUlps" to
73"libm-test-ulps" in the appropriate machine sysdep directory. Verify
74the changes, post your patch, and check it in after review.
75
76To manually generate a new "libm-test-ulps" file, first remove "ULPs"
77file in the current directory, then you can execute for example:
085b2d41 78 ./testrun.sh math/test-double -u --ignore-max-ulp=yes
a9b5d2ee 79This generates a file "ULPs" with all double ULPs in it, ignoring any
26510bdd
CD
80previously calculated ULPs, and running with the newly built dynamic
81loader and math library (assumes you didn't install your build). Now
82generate the ULPs for all other formats, the tests will be appending the
83data to the "ULPs" file. As final step run "gen-libm-test.pl" with the
84file as input and ask to generate a pretty printed output in the file
85"NewUlps":
7e1e68b4 86 gen-libm-test.pl -u ULPs -n NewUlps
26510bdd
CD
87Copy "NewUlps" to "libm-test-ulps" in the appropriate machine sysdep
88directory.
89
90Note that the test drivers have an option "-u" to output an unsorted
91list of all epsilons that the functions have. The output can be read
92in directly but it's better to pretty print it first.
93"gen-libm-test.pl" has an option to generate a pretty-printed and
94sorted new ULPs file from the output of the test drivers.
a9b5d2ee
UD
95
96Contents of libm-test-ulps
97==========================
a9b5d2ee 98
e6b6a857
JM
99Since libm-test-ulps can be generated automatically, just a few notes.
100The file contains lines for maximal errors of single functions, like:
101
a9b5d2ee 102Function "yn":
e6b6a857 103idouble: 6
a9b5d2ee
UD
104
105The keywords are float, ifloat, double, idouble, ldouble and ildouble
b7dab1e4 106(the prefix i stands for inline).
a9b5d2ee 107
5cbb5849
JM
108Adding tests to libm-test-<func>.inc
109====================================
a9b5d2ee
UD
110
111The tests are evaluated by a set of special test macros. The macros
112start with "TEST_" followed by a specification the input values, an
113underscore and a specification of the output values. As an example,
114the test macro for a function with input of type FLOAT (FLOAT is
115either float, double, long double) and output of type FLOAT is
116"TEST_f_f". The macro's parameter are the name of the function, the
117input parameter, output parameter and optionally one exception
118parameter.
119
120The accepted parameter types are:
121- "f" for FLOAT
76475eae 122- "j" for long double.
a9b5d2ee
UD
123- "b" for boolean - just tests if the output parameter evaluates to 0
124 or 1 (only for output).
125- "c" for complex. This parameter needs two values, first the real,
126 then the imaginary part.
127- "i" for int.
128- "l" for long int.
129- "L" for long long int.
76475eae
JM
130- "u" for unsigned int.
131- "M" for intmax_t.
132- "U" for uintmax_t.
133- "p" for an argument (described in the previous character) passed
134 through a pointer rather than directly.
a9b5d2ee
UD
135- "F" for the address of a FLOAT (only as input parameter)
136- "I" for the address of an int (only as input parameter)
76475eae
JM
137- "1" for an additional output (either output through a pointer passed
138 as an argument, or to a global variable such as signgam).
527de9e4
MS
139
140How to read the test output
141===========================
142
143Running each test on its own at the default level of verbosity will
144print on stdout a line describing the implementation of math functions
145exercised by the test (float, double, or long double), along with
146whether the inline set has been selected, regardless of whether or
147not any inline functions actually exist. This is then followed by
148the details of test failures (if any). The output concludes by
149a summary listing the number of test cases exercised and the number
150of test failures uncovered.
151
152For each test failure (and for each test case at higher levels of
153verbosity), the output contains the name of the function under test
154and its arguments or conditions that triggered the failure. Note
155that the name of the function in the output need not correspond
156exactly to the name of the math function actually invoked. For example,
157the output will refer to the "acos" function even if the actual function
158under test is acosf (for the float version) or acosl (for the long
159double version). Also note that the function arguments may be shown
160in either the decimal or the hexadecimal floating point format which
161may or may not correspond to the format used in the auto-libm-test-in
162file. Besides the name of the function, for each test failure the
163output contains the actual and expected results and the difference
164between the two, printed in both the decimal and hexadecimal
165floating point format, and the ULP and maximum ULP for the test
166case.