2 # Generate tests for libm functions.
3 # Copyright (C) 2018-2024 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <https://www.gnu.org/licenses/>.
21 from collections
import defaultdict
26 # Sorted list of all float types in ulps files.
27 ALL_FLOATS
= ('double', 'float', 'float128', 'ldouble')
29 # Map float types in ulps files to C-like prefix for macros.
30 ALL_FLOATS_PFX
= {'double': 'DBL',
35 # Float types in the order used in the generated ulps tables in the
37 ALL_FLOATS_MANUAL
= ('float', 'double', 'ldouble', 'float128')
39 # Map float types in ulps files to C function suffix.
40 ALL_FLOATS_SUFFIX
= {'double': '',
45 # Number of arguments in structure (as opposed to arguments that are
46 # pointers to return values) for an argument descriptor.
47 DESCR_NUM_ARGS
= {'f': 1, 'a': 1, 'j': 1, 'i': 1, 'u': 1, 'l': 1, 'L': 1,
48 'p': 0, 'F': 0, 'I': 0,
51 # Number of results in structure for a result descriptor.
52 DESCR_NUM_RES
= {'f': 1, 'i': 1, 'l': 1, 'L': 1, 'M': 1, 'U': 1, 'b': 1,
56 # Rounding modes, in the form in which they appear in
57 # auto-libm-test-out-* and the order in which expected results appear
58 # in structures and TEST_* calls.
59 ROUNDING_MODES
= ('downward', 'tonearest', 'towardzero', 'upward')
61 # Map from special text in TEST_* calls for rounding-mode-specific
62 # results and flags, to those results for each mode.
64 'plus_oflow': ('max_value', 'plus_infty', 'max_value', 'plus_infty'),
65 'minus_oflow': ('minus_infty', 'minus_infty', '-max_value', '-max_value'),
66 'plus_uflow': ('plus_zero', 'plus_zero', 'plus_zero', 'min_subnorm_value'),
67 'minus_uflow': ('-min_subnorm_value', 'minus_zero', 'minus_zero',
69 'ERRNO_PLUS_OFLOW': ('0', 'ERRNO_ERANGE', '0', 'ERRNO_ERANGE'),
70 'ERRNO_MINUS_OFLOW': ('ERRNO_ERANGE', 'ERRNO_ERANGE', '0', '0'),
71 'ERRNO_PLUS_UFLOW': ('ERRNO_ERANGE', 'ERRNO_ERANGE', 'ERRNO_ERANGE', '0'),
72 'ERRNO_MINUS_UFLOW': ('0', 'ERRNO_ERANGE', 'ERRNO_ERANGE', 'ERRNO_ERANGE'),
73 'XFAIL_ROUNDING_IBM128_LIBGCC': ('XFAIL_IBM128_LIBGCC', '0',
74 'XFAIL_IBM128_LIBGCC',
75 'XFAIL_IBM128_LIBGCC')
78 # Map from raw test arguments to a nicer form to use when displaying
80 BEAUTIFY_MAP
= {'minus_zero': '-0',
88 'minus_infty': '-inf',
92 'snan_value_ld': 'sNaN'}
94 # Flags in auto-libm-test-out that map directly to C flags.
95 FLAGS_SIMPLE
= {'ignore-zero-inf-sign': 'IGNORE_ZERO_INF_SIGN',
96 'xfail': 'XFAIL_TEST',
97 'no-mathvec': 'NO_TEST_MATHVEC'}
99 # Exceptions in auto-libm-test-out, and their corresponding C flags
100 # for being required, OK or required to be absent.
101 EXC_EXPECTED
= {'divbyzero': 'DIVBYZERO_EXCEPTION',
102 'inexact': 'INEXACT_EXCEPTION',
103 'invalid': 'INVALID_EXCEPTION',
104 'overflow': 'OVERFLOW_EXCEPTION',
105 'underflow': 'UNDERFLOW_EXCEPTION'}
106 EXC_OK
= {'divbyzero': 'DIVBYZERO_EXCEPTION_OK',
108 'invalid': 'INVALID_EXCEPTION_OK',
109 'overflow': 'OVERFLOW_EXCEPTION_OK',
110 'underflow': 'UNDERFLOW_EXCEPTION_OK'}
111 EXC_NO
= {'divbyzero': '0',
112 'inexact': 'NO_INEXACT_EXCEPTION',
119 """Maximum expected errors of libm functions."""
122 """Initialize an Ulps object."""
123 # normal[function][float_type] is the ulps value, and likewise
125 self
.normal
= defaultdict(lambda: defaultdict(lambda: 0))
126 self
.real
= defaultdict(lambda: defaultdict(lambda: 0))
127 self
.imag
= defaultdict(lambda: defaultdict(lambda: 0))
128 # List of ulps kinds, in the order in which they appear in
130 self
.ulps_kinds
= (('Real part of ', self
.real
),
131 ('Imaginary part of ', self
.imag
),
135 def read(self
, ulps_file
):
136 """Read ulps from a file into an Ulps object."""
137 self
.ulps_file
= ulps_file
138 with
open(ulps_file
, 'r') as f
:
143 if line
.startswith('#'):
146 # Ignore empty lines.
149 m
= re
.match(r
'([^:]*): (.*)\Z', line
)
151 raise ValueError('bad ulps line: %s' % line
)
152 line_first
= m
.group(1)
153 line_second
= m
.group(2)
154 if line_first
== 'Function':
157 for k_prefix
, k_dict
in self
.ulps_kinds
:
158 if line_second
.startswith(k_prefix
):
160 fn
= line_second
[len(k_prefix
):]
162 if not fn
.startswith('"') or not fn
.endswith('":'):
163 raise ValueError('bad ulps line: %s' % line
)
166 if line_first
not in ALL_FLOATS
:
167 raise ValueError('bad ulps line: %s' % line
)
168 ulps_val
= int(line_second
)
170 ulps_dict
[ulps_fn
][line_first
] = max(
171 ulps_dict
[ulps_fn
][line_first
],
174 def all_functions(self
):
175 """Return the set of functions with ulps and whether they are
179 for k_prefix
, k_dict
in self
.ulps_kinds
:
182 complex[f
] = True if k_prefix
else False
183 return funcs
, complex
185 def write(self
, ulps_file
):
186 """Write ulps back out as a sorted ulps file."""
187 # Output is sorted first by function name, then by (real,
188 # imag, normal), then by float type.
190 for order
, (prefix
, d
) in enumerate(self
.ulps_kinds
):
192 fn_data
= ['%s: %d' % (f
, d
[fn
][f
])
193 for f
in sorted(d
[fn
].keys())]
194 fn_text
= 'Function: %s"%s":\n%s' % (prefix
, fn
,
196 out_data
[(fn
, order
)] = fn_text
197 out_list
= [out_data
[fn_order
] for fn_order
in sorted(out_data
.keys())]
198 out_text
= ('# Begin of automatic generation\n\n'
199 '# Maximal error of functions:\n'
201 '# end of automatic generation\n'
202 % '\n\n'.join(out_list
))
203 with
open(ulps_file
, 'w') as f
:
207 def ulps_table(name
, ulps_dict
):
208 """Return text of a C table of ulps."""
210 for fn
in sorted(ulps_dict
.keys()):
211 fn_ulps
= [str(ulps_dict
[fn
][f
]) for f
in ALL_FLOATS
]
212 ulps_list
.append(' { "%s", {%s} },' % (fn
, ', '.join(fn_ulps
)))
213 ulps_text
= ('static const struct ulp_data %s[] =\n'
217 % (name
, '\n'.join(ulps_list
)))
220 def write_header(self
, ulps_header
):
221 """Write header file with ulps data."""
222 header_text_1
= ('/* This file is automatically generated\n'
223 ' from %s with gen-libm-test.py.\n'
224 ' Don\'t change it - change instead the master '
228 ' const char *name;\n'
229 ' FLOAT max_ulp[%d];\n'
231 % (self
.ulps_file
, len(ALL_FLOATS
)))
233 for i
, f
in enumerate(ALL_FLOATS
):
234 if f
.startswith('i'):
239 macro_list
.append('#define ULP_%s%s %d'
240 % (itxt
, ALL_FLOATS_PFX
[f
], i
))
241 header_text
= ('%s\n\n'
243 '/* Maximal error of functions. */\n'
247 % (header_text_1
, '\n'.join(macro_list
),
248 self
.ulps_table('func_ulps', self
.normal
),
249 self
.ulps_table('func_real_ulps', self
.real
),
250 self
.ulps_table('func_imag_ulps', self
.imag
)))
251 with
open(ulps_header
, 'w') as f
:
255 def read_all_ulps(srcdir
):
256 """Read all platforms' libm-test-ulps files."""
258 for dirpath
, dirnames
, filenames
in os
.walk(srcdir
):
259 if 'libm-test-ulps' in filenames
:
260 with
open(os
.path
.join(dirpath
, 'libm-test-ulps-name')) as f
:
261 name
= f
.read().rstrip()
262 all_ulps
[name
] = Ulps()
263 all_ulps
[name
].read(os
.path
.join(dirpath
, 'libm-test-ulps'))
267 def read_auto_tests(test_file
):
268 """Read tests from auto-libm-test-out-<function> (possibly None)."""
269 auto_tests
= defaultdict(lambda: defaultdict(dict))
270 if test_file
is None:
272 with
open(test_file
, 'r') as f
:
274 if not line
.startswith('= '):
276 line
= line
[len('= '):].rstrip()
277 # Function, rounding mode, condition and inputs, outputs
279 m
= re
.match(r
'([^ ]+) ([^ ]+) ([^: ][^ ]* [^:]*) : (.*)\Z', line
)
281 raise ValueError('bad automatic test line: %s' % line
)
282 auto_tests
[m
.group(1)][m
.group(2)][m
.group(3)] = m
.group(4)
287 """Return a nicer representation of a test argument."""
288 if arg
in BEAUTIFY_MAP
:
289 return BEAUTIFY_MAP
[arg
]
290 if arg
.startswith('-') and arg
[1:] in BEAUTIFY_MAP
:
291 return '-' + BEAUTIFY_MAP
[arg
[1:]]
292 if re
.match(r
'-?0x[0-9a-f.]*p[-+][0-9]+f\Z', arg
):
294 if re
.search(r
'[0-9]L\Z', arg
):
299 def complex_beautify(arg_real
, arg_imag
):
300 """Return a nicer representation of a complex test argument."""
301 res_real
= beautify(arg_real
)
302 res_imag
= beautify(arg_imag
)
303 if res_imag
.startswith('-'):
304 return '%s - %s i' % (res_real
, res_imag
[1:])
306 return '%s + %s i' % (res_real
, res_imag
)
309 def apply_lit_token(arg
, macro
):
310 """Apply the LIT or ARG_LIT macro to a single token."""
311 # The macro must only be applied to a floating-point constant, not
312 # to an integer constant or lit_* value.
314 exp_re
= r
'([+-])?[0-9]+'
315 suffix_re
= r
'[lLfF]?'
316 dec_exp_re
= r
'[eE]' + exp_re
317 hex_exp_re
= r
'[pP]' + exp_re
318 dec_frac_re
= r
'(?:[0-9]*\.[0-9]+|[0-9]+\.)'
319 hex_frac_re
= r
'(?:[0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.)'
320 dec_int_re
= r
'[0-9]+'
321 hex_int_re
= r
'[0-9a-fA-F]+'
322 dec_cst_re
= r
'(?:%s(?:%s)?|%s%s)' % (dec_frac_re
, dec_exp_re
,
323 dec_int_re
, dec_exp_re
)
324 hex_cst_re
= r
'0[xX](?:%s|%s)%s' % (hex_frac_re
, hex_int_re
, hex_exp_re
)
325 fp_cst_re
= r
'(%s(?:%s|%s))%s\Z' % (sign_re
, dec_cst_re
, hex_cst_re
,
327 m
= re
.match(fp_cst_re
, arg
)
329 return '%s (%s)' % (macro
, m
.group(1))
334 def apply_lit(arg
, macro
):
335 """Apply the LIT or ARG_LIT macro to constants within an expression."""
336 # Assume expressions follow the GNU Coding Standards, with tokens
337 # separated by spaces.
338 return ' '.join([apply_lit_token(t
, macro
) for t
in arg
.split()])
341 def gen_test_args_res(descr_args
, descr_res
, args
, res_rm
):
342 """Generate a test given the arguments and per-rounding-mode results."""
344 all_args_res
= list(args
)
346 all_args_res
.extend(r
[:len(r
)-1])
347 for a
in all_args_res
:
348 if 'snan_value' in a
:
350 # Process the arguments.
355 if DESCR_NUM_ARGS
[d
] == 0:
358 args_disp
.append(complex_beautify(args
[arg_pos
],
360 args_c
.append(apply_lit(args
[arg_pos
], 'LIT'))
361 args_c
.append(apply_lit(args
[arg_pos
+ 1], 'LIT'))
363 args_disp
.append(beautify(args
[arg_pos
]))
365 args_c
.append(apply_lit(args
[arg_pos
], 'LIT'))
367 args_c
.append(apply_lit(args
[arg_pos
], 'ARG_LIT'))
369 args_c
.append(args
[arg_pos
])
370 arg_pos
+= DESCR_NUM_ARGS
[d
]
371 args_disp_text
= ', '.join(args_disp
).replace('"', '\\"')
372 # Process the results.
373 for rm
in range(len(ROUNDING_MODES
)):
377 ignore_result_any
= False
378 ignore_result_all
= True
382 special
.append(res
[res_pos
])
383 elif DESCR_NUM_RES
[d
] == 1:
384 result
= res
[res_pos
]
385 if result
== 'IGNORE':
386 ignore_result_any
= True
389 ignore_result_all
= False
391 result
= apply_lit(result
, 'LIT')
392 rm_args
.append(result
)
395 result1
= res
[res_pos
]
396 if result1
== 'IGNORE':
397 ignore_result_any
= True
400 ignore_result_all
= False
401 result1
= apply_lit(result1
, 'LIT')
402 rm_args
.append(result1
)
403 result2
= res
[res_pos
+ 1]
404 if result2
== 'IGNORE':
405 ignore_result_any
= True
408 ignore_result_all
= False
409 result2
= apply_lit(result2
, 'LIT')
410 rm_args
.append(result2
)
411 res_pos
+= DESCR_NUM_RES
[d
]
412 if ignore_result_any
and not ignore_result_all
:
413 raise ValueError('some but not all function results ignored')
415 if ignore_result_any
:
416 flags
.append('IGNORE_RESULT')
418 flags
.append('TEST_SNAN')
419 flags
.append(res
[res_pos
])
420 rm_args
.append('|'.join(flags
))
423 rm_args
.extend(['0', '0'])
425 rm_args
.extend(['1', apply_lit(sp
, 'LIT')])
426 for k
in sorted(ROUNDING_MAP
.keys()):
427 rm_args
= [arg
.replace(k
, ROUNDING_MAP
[k
][rm
]) for arg
in rm_args
]
428 args_c
.append('{ %s }' % ', '.join(rm_args
))
429 return ' { "%s", %s },\n' % (args_disp_text
, ', '.join(args_c
))
432 def convert_condition(cond
):
433 """Convert a condition from auto-libm-test-out to C form."""
434 conds
= cond
.split(':')
437 if not c
.startswith('arg_fmt('):
438 c
= c
.replace('-', '_')
439 conds_c
.append('TEST_COND_' + c
)
440 return '(%s)' % ' && '.join(conds_c
)
443 def cond_value(cond
, if_val
, else_val
):
444 """Return a C conditional expression between two values."""
450 return '(%s ? %s : %s)' % (cond
, if_val
, else_val
)
453 def gen_auto_tests(auto_tests
, descr_args
, descr_res
, fn
):
454 """Generate C code for the auto-libm-test-out-* tests for a function."""
455 for rm_idx
, rm_name
in enumerate(ROUNDING_MODES
):
456 this_tests
= sorted(auto_tests
[fn
][rm_name
].keys())
458 rm_tests
= this_tests
460 raise ValueError('no automatic tests for %s' % fn
)
462 if rm_tests
!= this_tests
:
463 raise ValueError('inconsistent lists of tests of %s' % fn
)
465 for test
in rm_tests
:
466 fmt_args
= test
.split()
469 test_list
.append('#if %s\n' % convert_condition(fmt
))
471 for rm
in ROUNDING_MODES
:
472 test_out
= auto_tests
[fn
][rm
][test
]
473 out_str
, flags_str
= test_out
.split(':', 1)
474 this_res
= out_str
.split()
475 flags
= flags_str
.split()
478 m
= re
.match(r
'([^:]*):(.*)\Z', flag
)
481 cond
= convert_condition(m
.group(2))
482 if f_name
in flag_cond
:
483 if flag_cond
[f_name
] != '1':
484 flag_cond
[f_name
] = ('%s || %s'
485 % (flag_cond
[f_name
], cond
))
487 flag_cond
[f_name
] = cond
489 flag_cond
[flag
] = '1'
491 for flag
in sorted(FLAGS_SIMPLE
.keys()):
492 if flag
in flag_cond
:
493 flags_c
.append(cond_value(flag_cond
[flag
],
494 FLAGS_SIMPLE
[flag
], '0'))
495 for exc
in sorted(EXC_EXPECTED
.keys()):
496 exc_expected
= EXC_EXPECTED
[exc
]
499 exc_cond
= flag_cond
.get(exc
, '0')
500 exc_ok_cond
= flag_cond
.get(exc
+ '-ok', '0')
501 flags_c
.append(cond_value(exc_cond
,
502 cond_value(exc_ok_cond
, exc_ok
,
504 cond_value(exc_ok_cond
, exc_ok
,
506 if 'errno-edom' in flag_cond
and 'errno-erange' in flag_cond
:
507 raise ValueError('multiple errno values expected')
508 if 'errno-edom' in flag_cond
:
509 if flag_cond
['errno-edom'] != '1':
510 raise ValueError('unexpected condition for errno-edom')
511 errno_expected
= 'ERRNO_EDOM'
512 elif 'errno-erange' in flag_cond
:
513 if flag_cond
['errno-erange'] != '1':
514 raise ValueError('unexpected condition for errno-erange')
515 errno_expected
= 'ERRNO_ERANGE'
517 errno_expected
= 'ERRNO_UNCHANGED'
518 if 'errno-edom-ok' in flag_cond
:
519 if ('errno-erange-ok' in flag_cond
520 and (flag_cond
['errno-erange-ok']
521 != flag_cond
['errno-edom-ok'])):
522 errno_unknown_cond
= ('%s || %s'
523 % (flag_cond
['errno-edom-ok'],
524 flag_cond
['errno-erange-ok']))
526 errno_unknown_cond
= flag_cond
['errno-edom-ok']
528 errno_unknown_cond
= flag_cond
.get('errno-erange-ok', '0')
529 flags_c
.append(cond_value(errno_unknown_cond
, '0', errno_expected
))
530 flags_c
= [flag
for flag
in flags_c
if flag
!= '0']
532 flags_c
= ['NO_EXCEPTION']
533 this_res
.append(' | '.join(flags_c
))
534 res_rm
.append(this_res
)
535 test_list
.append(gen_test_args_res(descr_args
, descr_res
, args
,
537 test_list
.append('#endif\n')
538 return ''.join(test_list
)
541 def gen_test_line(descr_args
, descr_res
, args_str
):
542 """Generate C code for the tests for a single TEST_* line."""
543 test_args
= args_str
.split(',')
544 test_args
= test_args
[1:]
545 test_args
= [a
.strip() for a
in test_args
]
546 num_args
= sum([DESCR_NUM_ARGS
[c
] for c
in descr_args
])
547 num_res
= sum([DESCR_NUM_RES
[c
] for c
in descr_res
])
548 args
= test_args
[:num_args
]
549 res
= test_args
[num_args
:]
550 if len(res
) == num_res
:
551 # One set of results for all rounding modes, no flags.
553 res_rm
= [res
, res
, res
, res
]
554 elif len(res
) == num_res
+ 1:
555 # One set of results for all rounding modes, with flags.
556 if not ('EXCEPTION' in res
[-1]
557 or 'ERRNO' in res
[-1]
558 or 'IGNORE_ZERO_INF_SIGN' in res
[-1]
559 or 'TEST_NAN_SIGN' in res
[-1]
560 or 'XFAIL' in res
[-1]):
561 raise ValueError('wrong number of arguments: %s' % args_str
)
562 res_rm
= [res
, res
, res
, res
]
563 elif len(res
) == (num_res
+ 1) * 4:
564 # One set of results per rounding mode, with flags.
565 nr_plus
= num_res
+ 1
566 res_rm
= [res
[:nr_plus
], res
[nr_plus
:2*nr_plus
],
567 res
[2*nr_plus
:3*nr_plus
], res
[3*nr_plus
:]]
568 return gen_test_args_res(descr_args
, descr_res
, args
, res_rm
)
571 def generate_testfile(inc_input
, auto_tests
, c_output
):
572 """Generate test .c file from .inc input."""
574 with
open(inc_input
, 'r') as f
:
576 line_strip
= line
.strip()
577 if line_strip
.startswith('AUTO_TESTS_'):
578 m
= re
.match(r
'AUTO_TESTS_([^_]*)_([^_ ]*) *\(([^)]*)\),\Z',
581 raise ValueError('bad AUTO_TESTS line: %s' % line
)
582 test_list
.append(gen_auto_tests(auto_tests
, m
.group(1),
583 m
.group(2), m
.group(3)))
584 elif line_strip
.startswith('TEST_'):
585 m
= re
.match(r
'TEST_([^_]*)_([^_ ]*) *\((.*)\),\Z', line_strip
)
587 raise ValueError('bad TEST line: %s' % line
)
588 test_list
.append(gen_test_line(m
.group(1), m
.group(2),
591 test_list
.append(line
)
592 with
open(c_output
, 'w') as f
:
593 f
.write(''.join(test_list
))
596 def generate_err_table_sub(all_ulps
, all_functions
, fns_complex
, platforms
):
597 """Generate a single table within the overall ulps table section."""
598 plat_width
= [' {1000 + i 1000}' for p
in platforms
]
599 plat_header
= [' @tab %s' % p
for p
in platforms
]
600 table_list
= ['@multitable {nexttowardf} %s\n' % ''.join(plat_width
),
601 '@item Function %s\n' % ''.join(plat_header
)]
602 for func
in all_functions
:
603 for flt
in ALL_FLOATS_MANUAL
:
607 if fns_complex
[func
]:
608 ulp_real
= p_ulps
.real
[func
][flt
]
609 ulp_imag
= p_ulps
.imag
[func
][flt
]
610 ulp_str
= '%d + i %d' % (ulp_real
, ulp_imag
)
611 ulp_str
= ulp_str
if ulp_real
or ulp_imag
else '-'
613 ulp
= p_ulps
.normal
[func
][flt
]
614 ulp_str
= str(ulp
) if ulp
else '-'
615 func_ulps
.append(ulp_str
)
616 table_list
.append('@item %s%s @tab %s\n'
617 % (func
, ALL_FLOATS_SUFFIX
[flt
],
618 ' @tab '.join(func_ulps
)))
619 table_list
.append('@end multitable\n')
620 return ''.join(table_list
)
623 def generate_err_table(all_ulps
, err_table
):
624 """Generate ulps table for manual."""
625 all_platforms
= sorted(all_ulps
.keys())
626 functions_set
= set()
627 functions_complex
= {}
628 for p
in all_platforms
:
629 p_functions
, p_complex
= all_ulps
[p
].all_functions()
630 functions_set
.update(p_functions
)
631 functions_complex
.update(p_complex
)
632 all_functions
= sorted([f
for f
in functions_set
633 if ('_downward' not in f
634 and '_towardzero' not in f
635 and '_upward' not in f
636 and '_vlen' not in f
)])
638 # Print five platforms at a time.
639 num_platforms
= len(all_platforms
)
640 for i
in range((num_platforms
+ 4) // 5):
642 end
= i
* 5 + 5 if num_platforms
>= i
* 5 + 5 else num_platforms
643 err_table_list
.append(generate_err_table_sub(all_ulps
, all_functions
,
645 all_platforms
[start
:end
]))
646 with
open(err_table
, 'w') as f
:
647 f
.write(''.join(err_table_list
))
651 """The main entry point."""
652 parser
= argparse
.ArgumentParser(description
='Generate libm tests.')
653 parser
.add_argument('-a', dest
='auto_input', metavar
='FILE',
654 help='input file with automatically generated tests')
655 parser
.add_argument('-c', dest
='inc_input', metavar
='FILE',
656 help='input file .inc file with tests')
657 parser
.add_argument('-u', dest
='ulps_file', metavar
='FILE',
658 help='input file with ulps')
659 parser
.add_argument('-s', dest
='srcdir', metavar
='DIR',
660 help='input source directory with all ulps')
661 parser
.add_argument('-n', dest
='ulps_output', metavar
='FILE',
662 help='generate sorted ulps file FILE')
663 parser
.add_argument('-C', dest
='c_output', metavar
='FILE',
664 help='generate output C file FILE from .inc file')
665 parser
.add_argument('-H', dest
='ulps_header', metavar
='FILE',
666 help='generate output ulps header FILE')
667 parser
.add_argument('-m', dest
='err_table', metavar
='FILE',
668 help='generate output ulps table for manual FILE')
669 args
= parser
.parse_args()
671 if args
.ulps_file
is not None:
672 ulps
.read(args
.ulps_file
)
673 auto_tests
= read_auto_tests(args
.auto_input
)
674 if args
.srcdir
is not None:
675 all_ulps
= read_all_ulps(args
.srcdir
)
676 if args
.ulps_output
is not None:
677 ulps
.write(args
.ulps_output
)
678 if args
.ulps_header
is not None:
679 ulps
.write_header(args
.ulps_header
)
680 if args
.c_output
is not None:
681 generate_testfile(args
.inc_input
, auto_tests
, args
.c_output
)
682 if args
.err_table
is not None:
683 generate_err_table(all_ulps
, args
.err_table
)
686 if __name__
== '__main__':