mirror of
git://sourceware.org/git/glibc.git
synced 2026-09-08 23:58:31 +08:00
The formatted printf output tests verify their records against GNU AWK, relying on it to provide an implementation of format processing that is independent from ours. AWK has to run in the bignum mode for the floating-point conversions, because otherwise it uses the system sprintf(3) internally and we end up verifying our code against itself. That in turn makes gawk compiled with MPFR support a requirement for testing the library at all. Beyond that gawk mishandles a number of cases which the AWK script then has to undo by hand: the extraneous leading 0 produced for the alternative form with the octal conversion, the 0 produced where no characters are expected for the hexadecimal conversions, the missing + and space characters for a zero value with the precision of zero, and a collection of sign, flag and field width anomalies for Inf and NaN values. Each such workaround suppresses whatever we might get wrong in the same place. The a, A, b, and B conversions cannot be verified at all, because gawk either does not handle them or produces different output. Replace the AWK script with an equivalent one written in Python, which is already a requirement for building the library. Rather than calling into any formatting routine it computes the reference output directly, using exact integer and rational arithmetic. Working exactly means the result does not depend on the range or precision of any host floating-point type, so the wider types are handled without arbitrary-precision arithmetic having to be built into the interpreter, and none of the workarounds listed above are needed: the corner cases they cover are computed correctly. The same property removes the reason the a, A, b, and B conversions had to be left out; adding them is left for the commits that follow. Rendered digits are memoized per value, without which the exact arithmetic makes the long double conversions slower than AWK. As the capability probes only ever detected gawk build options, they go away along with the unsupported status they could produce, so the f and F conversions are now always verified rather than silently skipped where gawk was built without them. Drop the corresponding note on MPFR from the installation instructions. Tested on x86_64-linux-gnu, where all 576 results continue to pass. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
39 lines
1.2 KiB
Bash
39 lines
1.2 KiB
Bash
#!/bin/bash
|
|
# Testing of unsigned int printf conversions.
|
|
# Copyright (C) 2024-2026 Free Software Foundation, Inc.
|
|
# This file is part of the GNU C Library.
|
|
|
|
# The GNU C Library is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
# The GNU C Library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with the GNU C Library; if not, see
|
|
# <https://www.gnu.org/licenses/>.
|
|
|
|
set -e
|
|
|
|
xprintf=$1; shift
|
|
common_objpfx=$1; shift
|
|
test_program_prefix=$1; shift
|
|
|
|
status=0
|
|
|
|
for f in o u x X; do
|
|
echo Verifying $f
|
|
(set -o pipefail
|
|
${test_program_prefix} \
|
|
${common_objpfx}stdio-common/tst-printf-format-${xprintf}-uint $f |
|
|
${PYTHON:-python3} tst-printf-format.py 2>&1 |
|
|
head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 ||
|
|
status=1
|
|
done
|
|
|
|
exit $status
|