Go to file
Maciej W. Rozycki 7ec4d7e3d1 stdio-common: Add tests for formatted printf output specifiers
This is a collection of tests for formatted printf output specifiers
covering the d, i, o, u, x, and X integer conversions, the e, E, f, F,
g, and G floating-point conversions, the c character conversion, and the
s string conversion.  Also the hh, h, l, and ll length modifiers are
covered with the integer conversions as is the L length modifier with
the floating-point conversions.

The -, +, space, #, and 0 flags are iterated over, as permitted by the
conversion handled, in tuples of 1..5, including tuples with repetitions
of 2, and combined with field width and/or precision, again as permitted
by the conversion.  The resulting format string is then used to produce
output from respective sets of input data corresponding to the specific
conversion under test.  POSIX extensions beyond ISO C are not used.

Output is produced in the form of records which include both the format
string (and width and/or precision where given in the form of separate
arguments) and the conversion result, and is verified with GNU AWK using
the format obtained from each such record against the reference value
also supplied, relying on the fact that GNU AWK has its own independent
implementation of format processing, striving to be ISO C compatible.

In the course of implementation I have determined that in the non-bignum
mode GNU AWK uses system sprintf(3) for the floating-point conversions,
defeating the objective of doing the verification against an independent
implementation.  Additionally the bignum mode (using MPFR) is required
to correctly output wider integer and floating-point data.  Therefore
for the conversions affected the relevant shell scripts sanity-check AWK
and terminate with unsupported status if the bignum mode is unavailable
for floating-point data or where data is output incorrectly.

The f and F floating-point conversions are build-time options for GNU
AWK, depending on the environment, so they are probed for before being
used.  Similarly the a and A floating-point conversions, however they
are currently not used, see below.  Also GNU AWK does not handle the b
or B integer conversions at all at the moment, as at 5.3.0.  Support for
the a, A, b, and B conversions can however be easily added following the
approach taken for the f and F conversions.

Output produced by gawk for the a and A floating-point conversions does
not match one produced by us: insufficient precision is used where one
hasn't been explicitly given, e.g. for the negated maximum finite IEEE
754 64-bit value of -1.79769313486231570814527423731704357e+308 and "%a"
format we produce -0x1.fffffffffffffp+1023 vs gawk's -0x1.000000p+1024
and a different exponent is chosen otherwise, such as with "%.a" where
we output -0x2p+1023 vs gawk's -0x1p+1024 for the same value, or "%.20a"
where -0x1.fffffffffffff0000000p+1023 is our output, but gawk produces
-0xf.ffffffffffff80000000p+1020 instead.  Consequently I chose not to
include a and A conversions in testing at this time.

And last but not least there are numerous corner cases that GNU AWK does
not handle correctly, which are worked around by explicit handling in
the AWK script.  These are in particular:

- extraneous leading 0 produced for the alternative form with the o
  conversion, e.g. { printf "%#.2o", 1 } produces "001" rather than
  "01",

- unexpected 0 produced where no characters are expected for the input
  of 0 and the alternative form with the precision of 0 and the integer
  hexadecimal conversions, e.g. { printf "%#.x", 0 } produces "0" rather
  than "",

- missing + character in the non-bignum mode only for the input of 0
  with the + flag, precision of 0 and the signed integer conversions,
  e.g. { printf "%+.i", 0 } produces "" rather than "+",

- missing space character in the non-bignum mode only for the input of 0
  with the space flag, precision of 0 and the signed integer
  conversions, e.g. { printf "% .i", 0 } produces "" rather than " ",

- for released gawk versions of up to 4.2.1 missing - character for the
  input of -NaN with the floating-point conversions, e.g. { printf "%e",
  "-nan" }' produces "nan" rather than "-nan",

- for released gawk versions from 5.0.0 onwards + character output for
  the input of -NaN with the floating-point conversions, e.g. { printf
  "%e", "-nan" }' produces "+nan" rather than "-nan",

- for released gawk versions from 5.0.0 onwards + character output for
  the input of Inf or NaN in the absence of the + or space flags with
  the floating-point conversions, e.g. { printf "%e", "inf" }' produces
  "+inf" rather than "inf",

- for released gawk versions of up to 4.2.1 missing + character for the
  input of Inf or NaN with the + flag and the floating-point
  conversions, e.g. { printf "%+e", "inf" }' produces "inf" rather than
  "+inf",

- for released gawk versions of up to 4.2.1 missing space character for
  the input of Inf or NaN with the space flag and the floating-point
  conversions, e.g. { printf "% e", "nan" }' produces "nan" rather than
  " nan",

- for released gawk versions from 5.0.0 onwards + character output for
  the input of Inf or NaN with the space flag and the floating-point
  conversions, e.g. { printf "% e", "inf" }' produces "+inf" rather than
  " inf",

- for released gawk versions from 5.0.0 onwards the field width is
  ignored for the input of Inf or NaN and the floating-point
  conversions, e.g. { printf "%20e", "-inf" }' produces "-inf" rather
  than "                -inf",

NB for released gawk versions of up to 4.2.1 floating-point conversion
issues apply to the bignum mode only, as in the non-bignum mode system
sprintf(3) is used.  As from version 5.0.0 specialized handling has been
added for [-]Inf and [-]NaN inputs and the issues listed apply to both
modes.  The '--posix' flag makes gawk versions from 5.0.0 onwards avoid
the issue with field width and the + character unconditionally output
for the input of Inf or NaN, however not the remaining issues and then
the 'gensub' function is not supported in the POSIX mode, so to go this
path I deemed not worth it.

Each test completes within single seconds except for the long double
one.  There the F/f formats produce a large number of digits, which
appears to be computationally intensive and CPU-bound.  Standalone
execution time for 'tst-printf-format-p-ldouble --direct f' is in the
range of 00m36s for POWER9@2.166GHz and 09m52s for FU740@1.2GHz and
output redirected locally to /dev/null, and 10m11s for FU740 and output
redirected over 100Mbps network via SSH to /dev/null, so the throughput
of the network adds very little (~3.2% in this case) to the processing
time.  This is with IEEE 754 quad.

So I have scaled the timeout for 'tst-printf-format-skeleton-ldouble'
accordingly.  Regardless, following recent practice the test has been
added to the standard rather than extended set.  However, unlike most
of the remaining tests it has been split by the conversion specifier,
so as to allow better parallelization of this long-running test.  As
a side effect this lets the test report the unsupported status for the
F/f conversions where applicable, so 'tst-printf-format-p-double' has
been split for consistency as well.

Only printf itself is handled at the moment, but the infrastructure
provides for all the printf family functions to be verified, changes
for which to be supplied separately.  The complication around having
some tests iterating over all the relevant conversion specifiers and
other verifying conversion specifiers individually combined with
iterating over printf family functions has hit a peculiarity in GNU
make where the use of multiple targets with a pattern rule is handled
differently from such use with an ordinary rule.  Consequently it
seems impossible to bulk-define a pattern rule using '$(foreach ...)',
where each target would simply trigger the recipe according to the
pattern and matching dependencies individually (such a rule does work,
but implies all targets to be updated with a single recipe execution).

Therefore as a compromise a single single-target pattern rule has been
defined that has listed all the conversion-specific scripts and all the
test executables as dependencies.  Consequently tests will be rerun in
the absence of changes to their actual sources or scripts whenever an
unrelated file has changed that has been listed.  Also all the formatted
printf output tests will always be built whenever any single one is to
be run.  This only affects test development and not test runs in the
field, though it does change the order of execution of the individual
steps and also acts as a Makefile barrier in parallel runs.  As the
execution time dominates the compilation time for these tests it is not
seen as a serious shortcoming.

As pointed out by Florian Weimer <fweimer@redhat.com> the malloc tracing
facility can take a substantial amount of time in calling dladdr(3) to
determine the caller's location.  This is not needed by the verification
made with these tests, so I chose to interpose the symbol with a stub
implementation that always fails in the shared skeleton.  We have total
control over the test environment, so I think it is a safe and minimal
impact approach.  If there's ever anything else added to the tests that
would actually rely on dladdr(3) returning usable results, only then we
can think of a different approach.

Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-07 06:14:24 +00:00
advisories Document CVE-2024-33599, CVE-2024-33600, CVE-2024-33601, CVE-2024-33602 2024-05-06 15:12:31 -04:00
argp Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
assert assert: Mark __assert_fail as cold 2024-07-26 20:41:00 +08:00
benchtests benchtests: Add log10p1f benchmark 2024-11-01 11:17:20 -03:00
bits AArch64: Add vector logp1 alias for log1p 2024-09-19 17:53:34 +01:00
catgets Fix conditionals on mtrace-based tests (bug 31892) 2024-07-01 17:20:30 +02:00
ChangeLog.old Add ChangeLog file 2024-07-21 18:33:37 +02:00
conform Disable _TIME_BITS if the compiler defaults to it 2024-10-01 08:44:41 -03:00
csu Add crt1-2.0.o for glibc 2.0 compatibility tests 2024-05-06 07:49:40 -07:00
ctype ctype: Reformat Makefile. 2024-02-25 13:38:16 -05:00
debug stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
dirent Linux: readdir64_r should not skip d_ino == 0 entries (bug 32126) 2024-09-21 19:32:34 +02:00
dlfcn dlfcn: Reformat Makefile. 2024-02-25 13:38:16 -05:00
elf elf: Switch to main malloc after final ld.so self-relocation 2024-11-06 10:33:44 +01:00
gmon Define write_profiling functions only in profile library [BZ #31756] 2024-05-22 06:12:55 -07:00
gnulib Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
hesiod hesiod: Reformat Makefile. 2024-02-25 13:38:16 -05:00
htl hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
hurd x86_64 hurd: ensure we have a large enough buffer to receive exception_raise requests. 2024-07-30 16:59:12 +02:00
iconv iconv: Use $(run-program-prefix) for running iconv (bug 32197) 2024-09-24 12:35:40 +02:00
iconvdata iconv: Preserve iconv -c error exit on invalid inputs (bug 32046) 2024-09-20 13:51:09 +02:00
include Add feature test macro _ISOC2Y_SOURCE 2024-11-04 22:40:55 +00:00
inet Add IPPROTO_SMC from Linux 6.11 to netinet/in.h 2024-10-10 10:28:04 -03:00
intl locale: Fix some spelling typos 2024-10-14 15:38:26 +01:00
io linux: Update stat-generic.h with linux 6.11 2024-10-10 10:27:58 -03:00
libio libio: Fix crash in fputws [BZ #20632] 2024-10-25 15:05:06 -03:00
locale locale: Fix some spelling typos 2024-10-14 15:38:26 +01:00
localedata Enable transliteration rules with two input characters in scn_IT [BZ #32280] 2024-10-16 17:15:39 +02:00
login login: Re-flow and sort multiline Makefile definitions 2024-08-07 11:02:03 -03:00
mach mach: Drop some unnecessary vm_param.h includes 2024-01-03 21:59:54 +01:00
malloc malloc: Link threading tests with $(shared-thread-library) 2024-08-20 16:16:25 +02:00
manual manual: Use more precise wording for memory protection keys 2024-11-06 13:11:33 +00:00
math replace tgammaf by the CORE-MATH implementation 2024-10-11 11:12:32 +02:00
mathvec Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
misc misc: Add support for Linux uio.h RWF_ATOMIC flag 2024-10-10 10:28:01 -03:00
nis Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
nptl Add more tests of pthread attributes initial values 2024-10-29 17:35:21 +00:00
nptl_db Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
nscd nscd: Use time_t for return type of addgetnetgrentX 2024-05-02 18:59:29 +02:00
nss nss: Fix incorrect switch fall-through in tst-nss-gai-actions 2024-08-07 15:00:25 +02:00
po po/*: regenerate (only line number changes) 2024-07-21 17:50:35 +02:00
posix libio: Fix a deadlock after fork in popen 2024-10-23 13:40:16 +02:00
resolv resolv: Fix tst-resolv-short-response for older GCC (bug 32042) 2024-08-01 21:07:48 +02:00
resource Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-04-02 15:28:36 -03:00
rt rt: more clock_nanosleep tests addendum 2024-10-08 14:30:21 -04:00
scripts Use Linux 6.11 in build-many-glibcs.py 2024-10-10 10:27:47 -03:00
setjmp Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
signal stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
socket Fix name space violation in fortify wrappers (bug 32052) 2024-08-05 16:49:58 +02:00
soft-fp soft-fp: Add brain format support 2024-02-01 19:06:54 +01:00
stdio-common stdio-common: Add tests for formatted printf output specifiers 2024-11-07 06:14:24 +00:00
stdlib stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
string string: strerror, strsignal cannot use buffer after dlmopen (bug 32026) 2024-08-19 15:48:03 +02:00
sunrpc Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
support support: Make support_process_state_wait return the found state 2024-10-16 14:32:28 -03:00
sysdeps nptl: fix __builtin_thread_pointer detection on LoongArch 2024-11-07 14:08:30 +08:00
sysvipc Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-04-02 15:28:36 -03:00
termios Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
time Link tst-clock_gettime with $(librt) 2024-10-31 17:43:52 +00:00
timezone timezone: sync to TZDB 2024b 2024-09-05 20:57:17 +00:00
wcsmbs Do not use -Wp to disable fortify (BZ 31928) 2024-10-01 08:44:40 -03:00
wctype Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
.b4-config Add .b4-config file 2024-10-21 14:26:42 +01:00
.clang-format Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
.gitattributes Assume __NR_openat is always defined 2016-03-23 23:35:08 +01:00
.gitignore Add *.pyc to .gitignore 2015-05-18 15:26:26 +05:30
abi-tags Remove the bulk of the NaCl port. 2017-05-20 08:09:10 -04:00
aclocal.m4 Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
config.h.in arc: Remove HAVE_ARC_BE macro and disable big-endian port 2024-09-25 11:25:22 +02:00
config.make.in manual: add syscalls 2024-07-09 11:54:29 +02:00
configure Disable _TIME_BITS if the compiler defaults to it 2024-10-01 08:44:41 -03:00
configure.ac Disable _TIME_BITS if the compiler defaults to it 2024-10-01 08:44:41 -03:00
CONTRIBUTED-BY crypt: Remove libcrypt support 2023-10-30 13:03:59 -03:00
COPYING Update to latest versions of GPL-2.0 and LGPL-2.1 2013-09-09 12:52:48 +10:00
COPYING.LIB Update to latest versions of GPL-2.0 and LGPL-2.1 2013-09-09 12:52:48 +10:00
extra-lib.mk Rename cppflags-iterator.mk to libof-iterator.mk, remove extra-modules.mk. 2017-05-09 07:06:29 -04:00
gen-locales.mk locale: Handle loading a missing locale twice (Bug 14247) 2024-04-22 16:03:00 -04:00
INSTALL install.texi: bump "latest verified" versions 2024-07-21 00:27:35 +02:00
libc-abis riscv: support GNU indirect function 2021-01-10 21:25:13 -05:00
libof-iterator.mk Rename cppflags-iterator.mk to libof-iterator.mk, remove extra-modules.mk. 2017-05-09 07:06:29 -04:00
LICENSES added license for sysdeps/ieee754/flt-32/e_gammaf_r.c 2024-11-04 08:55:07 +01:00
MAINTAINERS Add MAINTAINERS 2017-05-11 13:38:30 -04:00
Makeconfig Disable _TIME_BITS if the compiler defaults to it 2024-10-01 08:44:41 -03:00
Makefile Pass -nostdlib -nostartfiles together with -r [BZ #31753] 2024-05-19 16:29:02 -07:00
Makefile.help math: Add support for auto static math tests 2024-05-21 16:53:27 -03:00
Makefile.in New make target to only build benchmark binaries 2016-04-20 10:23:28 +05:30
Makerules Support compiling .S files with additional options 2024-02-25 09:22:40 -08:00
NEWS Add feature test macro _ISOC2Y_SOURCE 2024-11-04 22:40:55 +00:00
o-iterator.mk
README Remove ia64-linux-gnu 2024-01-08 17:09:36 -03:00
Rules Implement run-built-tests=no for make xcheck, always build xtests 2024-09-21 00:29:55 +02:00
SECURITY.md Adapt the security policy for the security page 2023-12-05 09:15:10 -05:00
SHARED-FILES math: Use log10p1f from CORE-MATH 2024-11-01 11:27:40 -03:00
shlib-versions crypt: Remove libcrypt support 2023-10-30 13:03:59 -03:00
test-skeleton.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
version.h Increase version number to 2.40.9000 2024-07-21 18:49:35 +02:00

This directory contains the sources of the GNU C Library.
See the file "version.h" for what release version you have.

The GNU C Library is the standard system C library for all GNU systems,
and is an important part of what makes up a GNU system.  It provides the
system API for all programs written in C and C-compatible languages such
as C++ and Objective C; the runtime facilities of other programming
languages use the C library to access the underlying operating system.

In GNU/Linux systems, the C library works with the Linux kernel to
implement the operating system behavior seen by user applications.
In GNU/Hurd systems, it works with a microkernel and Hurd servers.

The GNU C Library implements much of the POSIX.1 functionality in the
GNU/Hurd system, using configurations i[4567]86-*-gnu and x86_64-gnu.

When working with Linux kernels, this version of the GNU C Library
requires Linux kernel version 3.2 or later.

Also note that the shared version of the libgcc_s library must be
installed for the pthread library to work correctly.

The GNU C Library supports these configurations for using Linux kernels:

	aarch64*-*-linux-gnu
	alpha*-*-linux-gnu
	arc*-*-linux-gnu
	arm-*-linux-gnueabi
	csky-*-linux-gnuabiv2
	hppa-*-linux-gnu
	i[4567]86-*-linux-gnu
	x86_64-*-linux-gnu	Can build either x86_64 or x32
	loongarch64-*-linux-gnu Hardware floating point, LE only.
	m68k-*-linux-gnu
	microblaze*-*-linux-gnu
	mips-*-linux-gnu
	mips64-*-linux-gnu
	or1k-*-linux-gnu
	powerpc-*-linux-gnu	Hardware or software floating point, BE only.
	powerpc64*-*-linux-gnu	Big-endian and little-endian.
	s390-*-linux-gnu
	s390x-*-linux-gnu
	riscv32-*-linux-gnu
	riscv64-*-linux-gnu
	sh[34]-*-linux-gnu
	sparc*-*-linux-gnu
	sparc64*-*-linux-gnu

If you are interested in doing a port, please contact the glibc
maintainers; see https://www.gnu.org/software/libc/ for more
information.

See the file INSTALL to find out how to configure, build, and install
the GNU C Library.  You might also consider reading the WWW pages for
the C library at https://www.gnu.org/software/libc/.

The GNU C Library is (almost) completely documented by the Texinfo manual
found in the `manual/' subdirectory.  The manual is still being updated
and contains some known errors and omissions; we regret that we do not
have the resources to work on the manual as much as we would like.  For
corrections to the manual, please file a bug in the `manual' component,
following the bug-reporting instructions below.  Please be sure to check
the manual in the current development sources to see if your problem has
already been corrected.

Please see https://www.gnu.org/software/libc/bugs.html for bug reporting
information.  We are now using the Bugzilla system to track all bug reports.
This web page gives detailed information on how to report bugs properly.

The GNU C Library is free software.  See the file COPYING.LIB for copying
conditions, and LICENSES for notices about a few contributions that require
these additional notices to be distributed.  License copyright years may be
listed using range notation, e.g., 1996-2015, indicating that every year in
the range, inclusive, is a copyrightable year that would otherwise be listed
individually.