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