Debian Codegraph @

math/README.libm-test

raw
1 README for libm-test math test suite
2 ====================================
3
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 Python
7 script "gen-libm-test.py" have some options. A full list of options
8 is available with --help (for the test drivers) and -h for
9 "gen-libm-test.py".
10
11
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.
17
18 Besides testing the special values mandated by IEEE 754 (infinities,
19 NaNs and minus zero), some more or less random values are tested.
20
21 Files that are part of libm-test
22 ================================
23
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 Python script
29 "gen-libm-test.py" 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 specific math results that can be either generic for the floating
34 type or platform specific.
35
36 The test drivers "test-double-<func>.c", "test-float-<func>.c", and
37 "test-ldouble-<func>.c", generated by the Makefile, test the normal
38 double, float and long double implementation of libm. Each driver
39 selects the desired real floating type to exercise the math functions
40 to test with (float, double, or long double) by defining a small set
41 of macros just before including the generic "libm-test.c" file. Each
42 driver is compiled into a single executable test program with the
43 corresponding name.
44
45 The math tests do not report up to 9 Units of Least Precision (ULP)
46 (13 for IBM long double format) difference between the obtained
47 result and the expected one as a regression. The "gen-libm-test.py"
48 script looks for files named "libm-test-ulps" in the sysdep directories
49 to generate the "libm-test-ulps.h" file.
50
51 The "auto-libm-test-out-<func>" files contain sets of test cases to
52 exercise, the conditions under which to exercise each, and the
53 expected results. The files are generated by the
54 "gen-auto-libm-tests" program from the "auto-libm-test-in" file. See
55 the comments in gen-auto-libm-tests.c for details about the content
56 and format of the -in and -out files.
57
58 How can I use "libm-test-ulps"?
59 ====================================
60
61 A "libm-test-ulps" is required only to test for extra constraints in
62 the math tests. The file contains lines for maximal errors of single
63 functions, like:
64
65 Function "yn":
66 float: 2
67 double: 6
68
69 It means that if the "yn" shows error larger than 2 ULP for float
70 or 6 ULP for double, the related test for "symbol" will fail. It can
71 be useful to check for correctly rounded implementation, where the
72 expected ULP is 0.
73
74 The function is tested with default FE_TONEAREST rounding mode. To
75 check with a different one, the function definition name should be
76 prepended with an underline plus the rounding mode 'downward' (FE_DOWNWARD),
77 'towardzero' (FE_TOWARDZERO), or 'upward' (FE_UPWARD). For instance,
78
79 Function "yn_downward":
80 float: 3
81 double: 7
82
83 It means that 'yn' will be checked with FE_DOWNWARD rounding mode
84 and any error larger than 3 ULPs for float or 7 ULPs for double will be
85 reported as a regression.
86
87 The keywords are float, double, ldouble, and float128.
88
89 Also, multiple "libm-test-ulps" can be added, "gen-libm-test.py" will
90 merge the input in only one table.
91
92 Note that the test drivers have an option "-u" to output an unsorted
93 list of all epsilons that the functions have. The output can be read
94 in directly but it's better to pretty print it first.
95 "gen-libm-test.py" has an option to generate a pretty-printed and
96 sorted new ULPs file from the output of the test drivers.
97
98
99 Adding tests to libm-test-<func>.inc
100 ====================================
101
102 The tests are evaluated by a set of special test macros. The macros
103 start with "TEST_" followed by a specification the input values, an
104 underscore and a specification of the output values. As an example,
105 the test macro for a function with input of type FLOAT (FLOAT is
106 either float, double, long double) and output of type FLOAT is
107 "TEST_f_f". The macro's parameter are the name of the function, the
108 input parameter, output parameter and optionally one exception
109 parameter.
110
111 The accepted parameter types are:
112 - "f" for FLOAT
113 - "j" for long double.
114 - "a" for ARG_FLOAT, the argument type for narrowing functions.
115 - "b" for boolean - just tests if the output parameter evaluates to 0
116 or 1 (only for output).
117 - "c" for complex. This parameter needs two values, first the real,
118 then the imaginary part.
119 - "i" for int.
120 - "l" for long int.
121 - "L" for long long int.
122 - "u" for unsigned int.
123 - "M" for intmax_t.
124 - "U" for uintmax_t.
125 - "p" for an argument (described in the previous character) passed
126 through a pointer rather than directly.
127 - "F" for the address of a FLOAT (only as input parameter)
128 - "I" for the address of an int (only as input parameter)
129 - "1" for an additional output (either output through a pointer passed
130 as an argument, or to a global variable such as signgam).
131
132 How to read the test output
133 ===========================
134
135 Running each test on its own at the default level of verbosity will
136 print on stdout a line describing the implementation of math functions
137 exercised by the test (float, double, or long double). This is then
138 followed by the details of test failures (if any). The output concludes
139 by a summary listing the number of test cases exercised and the number
140 of test failures uncovered.
141
142 For each test failure (and for each test case at higher levels of
143 verbosity), the output contains the name of the function under test
144 and its arguments or conditions that triggered the failure. Note
145 that the name of the function in the output need not correspond
146 exactly to the name of the math function actually invoked. For example,
147 the output will refer to the "acos" function even if the actual function
148 under test is acosf (for the float version) or acosl (for the long
149 double version). Also note that the function arguments may be shown
150 in either the decimal or the hexadecimal floating point format which
151 may or may not correspond to the format used in the auto-libm-test-in
152 file. Besides the name of the function, for each test failure the
153 output contains the actual and expected results and the difference
154 between the two, printed in both the decimal and hexadecimal
155 floating point format, and the ULP and maximum ULP for the test
156 case.