From patchwork Wed Oct 16 15:45:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99020 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 452C53858C2B for ; Wed, 16 Oct 2024 15:46:23 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 1CF1D3858CDA for ; Wed, 16 Oct 2024 15:45:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1CF1D3858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1CF1D3858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093527; cv=none; b=VOUZIVAIAVzxnQiH0HbgyEoPwJ2zOhLBe0GVnyTZDQCOniPJsTCgDEBMatciNUdVeu/DyztmsODj7MY0fZBrl3hNc/PqFkRlBjA4ODArz/wH51JWiguQgmit7OI92DXCn15q/2TSVQ+umlNx4/hQCrXYUUSYjQu2rtcnaLL/x7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093527; c=relaxed/simple; bh=3mL40pcX3I1XCaRaijJsAiIOQsVXZrbHFSlXqTIsEKU=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=X+iqEbe/Ye6u/dtql46s9NYv86uEzJkyjtx4kqvLu9Q6zLVm6QvY932vt266IpxEAPvbsDThyu+gJNGRiWczRbQDwdoNCbF4HPrx+MM82Npgek9jcGvgw61UVFkC6d/9YPgnbnIn6etuqm3GS3QeowxjP9d/yzD5RyKMtGnght0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 9E2BC92009C; Wed, 16 Oct 2024 17:45:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 95FA092009B; Wed, 16 Oct 2024 16:45:19 +0100 (BST) Date: Wed, 16 Oct 2024 16:45:19 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 01/12] stdio-common: Add tests for formatted printf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.7 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki 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. --- Changes from v2: - Report unrecognised input in the GAWK script and make it a test failure. - Change the test skeleton to call a program entity by the name of printf_under_test, to be supplied by the including test program, rather than just printf itself and move error reporting to within said entity. Provide a printf_under_test definition for printf itself. - Turn printf conversions tests into skeletons, to be included by individual printf family tests, and supply such tests for printf itself. - Only set TIMEOUT in the long double skeleton if not already set. - Update Makefile to handle all printf family functions rather than just lone printf itself. - Use auxiliary Makefile variables to remove duplication and instead build lists of tests and their sources with iterators. Remove extraneous .out entries from the list of generated files. - Add tst-printf-format.sh dispatcher script and update individual test scripts to build the name of the test program according to the printf family function under test marker supplied as a command-line argument. Remove dedicated Makefile rules no longer needed for double and long double tests. - Do not expect a conversion specifier to be supplied anymore as a command-line argument to test scripts that do not use it. - Correct test scripts to redirect stderr to stdout, respecting our error communication convention. - Correct the handling of mtrace output verification and actually add -mem.out tests corresponding to printf family tests, and an associated Makefile rule. - Update the change description for changed file names, new Makefile infrastructure and minor clean-ups. Changes from v1: - Split tst-printf-format-ldouble and tst-printf-format-double by the conversion specifier. - Update the change description to clarify the optional nature of the f/F conversions applies to GNU AWK, to add the B conversion and to mention the split arrangement for the floating-point format tests. - v1 at: . --- stdio-common/Makefile | 53 +++ stdio-common/tst-printf-format-c.c | 29 - stdio-common/tst-printf-format-c.sh | 34 ++ stdio-common/tst-printf-format-char.c | 31 - stdio-common/tst-printf-format-char.sh | 40 ++ stdio-common/tst-printf-format-double.c | 33 - stdio-common/tst-printf-format-double.sh | 74 ++++ stdio-common/tst-printf-format-int.c | 29 - stdio-common/tst-printf-format-int.sh | 53 +++ stdio-common/tst-printf-format-ldouble.c | 35 -- stdio-common/tst-printf-format-ldouble.sh | 74 ++++ stdio-common/tst-printf-format-llong.c | 29 - stdio-common/tst-printf-format-llong.sh | 53 +++ stdio-common/tst-printf-format-long.c | 29 - stdio-common/tst-printf-format-long.sh | 53 +++ stdio-common/tst-printf-format-p-c.c | 20 + stdio-common/tst-printf-format-p-char.c | 20 + stdio-common/tst-printf-format-p-double.c | 20 + stdio-common/tst-printf-format-p-int.c | 20 + stdio-common/tst-printf-format-p-ldouble.c | 20 + stdio-common/tst-printf-format-p-llong.c | 20 + stdio-common/tst-printf-format-p-long.c | 20 + stdio-common/tst-printf-format-p-s.c | 20 + stdio-common/tst-printf-format-p-short.c | 20 + stdio-common/tst-printf-format-p-uchar.c | 20 + stdio-common/tst-printf-format-p-uint.c | 20 + stdio-common/tst-printf-format-p-ullong.c | 20 + stdio-common/tst-printf-format-p-ulong.c | 20 + stdio-common/tst-printf-format-p-ushort.c | 20 + stdio-common/tst-printf-format-p.h | 29 + stdio-common/tst-printf-format-s.c | 30 - stdio-common/tst-printf-format-s.sh | 34 ++ stdio-common/tst-printf-format-short.c | 31 - stdio-common/tst-printf-format-short.sh | 40 ++ stdio-common/tst-printf-format-skeleton-c.c | 29 + stdio-common/tst-printf-format-skeleton-char.c | 31 + stdio-common/tst-printf-format-skeleton-double.c | 33 + stdio-common/tst-printf-format-skeleton-int.c | 29 + stdio-common/tst-printf-format-skeleton-ldouble.c | 38 ++ stdio-common/tst-printf-format-skeleton-llong.c | 29 + stdio-common/tst-printf-format-skeleton-long.c | 29 + stdio-common/tst-printf-format-skeleton-s.c | 30 + stdio-common/tst-printf-format-skeleton-short.c | 31 + stdio-common/tst-printf-format-skeleton-uchar.c | 30 + stdio-common/tst-printf-format-skeleton-uint.c | 29 + stdio-common/tst-printf-format-skeleton-ullong.c | 29 + stdio-common/tst-printf-format-skeleton-ulong.c | 29 + stdio-common/tst-printf-format-skeleton-ushort.c | 30 + stdio-common/tst-printf-format-skeleton.c | 371 ++++++++++++++++++++++ stdio-common/tst-printf-format-uchar.c | 30 - stdio-common/tst-printf-format-uchar.sh | 40 ++ stdio-common/tst-printf-format-uint.c | 29 - stdio-common/tst-printf-format-uint.sh | 53 +++ stdio-common/tst-printf-format-ullong.c | 29 - stdio-common/tst-printf-format-ullong.sh | 53 +++ stdio-common/tst-printf-format-ulong.c | 29 - stdio-common/tst-printf-format-ulong.sh | 53 +++ stdio-common/tst-printf-format-ushort.c | 30 - stdio-common/tst-printf-format-ushort.sh | 40 ++ stdio-common/tst-printf-format.awk | 127 +++++++ stdio-common/tst-printf-format.sh | 39 ++ 61 files changed, 2019 insertions(+), 423 deletions(-) glibc-tst-printf-format-all.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -22,6 +22,35 @@ subdir := stdio-common include ../Makeconfig +# List of markers for printf family function tests. +xprintf-funcs := p + +# List of data types and formats for individual per-conversion printf tests. +fmt-convs := double ldouble +fmts := E e F f G g + +# List of data types grouping all conversions in single printf tests. +nonfmt-convs := c char int llong long s short +nonfmt-convs += uchar uint ullong ulong ushort + +convs := $(sort $(fmt-convs) $(nonfmt-convs)) + +xprintf-srcs := \ + $(foreach p,$(xprintf-funcs), \ + $(foreach c,$(convs),tst-printf-format-$(p)-$(c))) + +fmt-xprintf-stems := \ + $(foreach f,$(fmts), \ + $(foreach p,$(xprintf-funcs), \ + $(foreach c,$(fmt-convs), \ + tst-printf-format-$(p)-$(c)-$(f)))) +nonfmt-xprintf-stems := \ + $(foreach p,$(xprintf-funcs), \ + $(foreach c,$(nonfmt-convs), \ + tst-printf-format-$(p)-$(c))) + +xprintf-stems := $(sort $(fmt-xprintf-stems) $(nonfmt-xprintf-stems)) + headers := \ bits/printf-ldbl.h \ bits/stdio_lim.h \ @@ -316,6 +345,7 @@ tests-internal = \ # tests-internal test-srcs = \ + $(xprintf-srcs) \ tst-printf \ tst-printfsz-islongdouble \ tst-unbputc \ @@ -323,6 +353,7 @@ test-srcs = \ ifeq ($(run-built-tests),yes) tests-special += \ + $(foreach f,$(xprintf-stems),$(objpfx)$(f).out) \ $(objpfx)tst-printf.out \ $(objpfx)tst-printfsz-islongdouble.out \ $(objpfx)tst-setvbuf1-cmp.out \ @@ -332,6 +363,7 @@ tests-special += \ ifeq (yes,$(build-shared)) ifneq ($(PERL),no) tests-special += \ + $(foreach f,$(xprintf-stems),$(objpfx)$(f)-mem.out) \ $(objpfx)tst-freopen2-mem.out \ $(objpfx)tst-freopen3-mem.out \ $(objpfx)tst-freopen4-mem.out \ @@ -352,6 +384,8 @@ tests-special += \ # tests-special generated += \ + $(foreach f,$(xprintf-stems),$(f)-mem.out) \ + $(foreach f,$(xprintf-stems),$(f).mtrace) \ tst-freopen2-mem.out \ tst-freopen2.mtrace \ tst-freopen3-mem.out \ @@ -525,6 +559,21 @@ $(objpfx)tst-printf.out: tst-printf.sh $ $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ $(evaluate-test) +# We can't split a quoted recipe line, so do it via an auxiliary variable. +make-tst-printf-format-out = \ + AWK='$(AWK)' BASH='$(BASH)' \ + $(BASH) $< $@ $(common-objpfx) \ + '$(run-program-prefix-before-env) \ + $(run-program-env) \ + MALLOC_TRACE=$(@:.out=.mtrace) \ + LD_PRELOAD=$(common-objpfx)malloc/libc_malloc_debug.so \ + $(run-program-prefix-after-env)' +$(objpfx)tst-printf-format-%.out: \ + tst-printf-format.sh $(foreach c,$(convs),tst-printf-format-$(c).sh) \ + $(foreach f,$(xprintf-srcs),$(objpfx)$(f)) tst-printf-format.awk + $(make-tst-printf-format-out) > $@; \ + $(evaluate-test) + $(objpfx)tst-printfsz-islongdouble.out: \ tst-printfsz-islongdouble.sh $(objpfx)tst-printfsz-islongdouble $(SHELL) $^ '$(test-program-prefix)' $@; \ @@ -538,6 +587,10 @@ $(objpfx)tst-printf-bz18872.c: tst-print $(objpfx)tst-%-mem.out: $(objpfx)tst-%.out $(common-objpfx)malloc/mtrace $(objpfx)tst-$*.mtrace > $@; \ $(evaluate-test) +$(objpfx)tst-printf-format-%-mem.out: $(objpfx)tst-printf-format-%.out + $(common-objpfx)malloc/mtrace \ + $(objpfx)tst-printf-format-$*.mtrace > $@; \ + $(evaluate-test) errlist-h = $(firstword $(wildcard $(addsuffix /errlist.h,$(sysdirs) .))) Index: glibc/stdio-common/tst-printf-format-c.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-c.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Test for formatted printf output for the 'c' conversion. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 3 -#define HUGE_WIDTH 4 -#define REF_FMT "c" -#define REF_VAL(v) (v) -typedef unsigned char type_t; -static const type_t vals[] = { 0, 42, UCHAR_MAX }; -static const char length[] = ""; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-c.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-c.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Testing of the 'c' printf conversion. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +echo Verifying c +(set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-c c | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion c output error, first line:\n/") 2>&1 || + exit 1 Index: glibc/stdio-common/tst-printf-format-char.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-char.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Test for formatted printf output for signed char conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 3 -#define HUGE_WIDTH 5 -#define REF_FMT "i" -#define REF_VAL(v) ((((v) & 0xff) ^ 0x80) - 0x80) -typedef int type_t; -static const type_t vals[] = - { SCHAR_MIN - 123, SCHAR_MIN - 1, SCHAR_MIN, -123, -1, 0, 1, 42, SCHAR_MAX, - SCHAR_MAX + 1, SCHAR_MAX + 42 }; -static const char length[] = "hh"; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-char.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-char.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Testing of signed char printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +status=0 + +for f in d i; do + echo Verifying $f + (set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-char $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-double.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-double.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Test for formatted printf output for double conversions. - Copyright (C) 2024 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 - . */ - -#include -#include - -#define MID_WIDTH 20 -#define HUGE_WIDTH 320 -#define REF_FMT ".35e" -#define REF_VAL(v) (v) -#define PREC DBL_MANT_DIG -typedef double type_t; -static const type_t vals[] = - { -HUGE_VAL, -DBL_MAX, -DBL_MIN, copysign (0, -1), -NAN, NAN, 0, DBL_MIN, - DBL_MAX, HUGE_VAL }; -static const char length[] = ""; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-double.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-double.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# Testing of double printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +format=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +# For floating-point formats we need to use the bignum mode even if the +# regular mode would do, because GAWK in the latter mode uses sprintf(3) +# internally to process the conversion requested, so any bug in our code +# would then be verified against itself, defeating the objective of doing +# the verification against an independent implementation. +AWK="${AWK:-awk} -M" + +status=77 + +# Verify that AWK can handle the range required. It also catches: +# "gawk: warning: -M ignored: MPFR/GMP support not compiled in" +# message produced where bignum support is not there, which is the +# only indication as the use of '-M' does not affect the exit status +# in this case. +ref="-1.79769313486231570814527423731704357e+308" +val=$(echo "$ref" | $AWK '{ printf "%.35e\n", $1 }' 2>&1) && + test "$val" = "$ref" && status=0 + +test $status -eq 0 || { echo "No working AWK found" && exit $status; } + +# Check for any additional conversions that AWK handles conditionally +# according to its version and/or the environment it has been built in. +# The 'A' and 'a' conversions are not suitable to use at this point, as +# output produced by AWK is different apparently due to a subtlety in +# rounding, so do not try them. +declare -A conversion_disabled +ref="-inf" +for f in f F; do + conversion_disabled[$f]=true + val=$(echo "$ref" | $AWK '{ printf "%'$f'\n", $1 }' 2>&1) && + test "${val^^}" = "${ref^^}" && unset conversion_disabled[$f] +done + +if test "${conversion_disabled[$format]+set}" = set; then + echo Unsupported $format + status=77 +else + echo Verifying $format + (set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-double $format | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | + sed "s/^/Conversion $format output error, first line:\n/") 2>&1 || + status=1 +fi + +exit $status Index: glibc/stdio-common/tst-printf-format-int.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-int.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Test for formatted printf output for int conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 8 -#define HUGE_WIDTH 15 -#define REF_FMT "i" -#define REF_VAL(v) (v) -typedef int type_t; -static const type_t vals[] = { INT_MIN, -123, -1, 0, 1, 42, INT_MAX }; -static const char length[] = ""; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-int.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-int.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Testing of int printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +status=77 + +# Verify that AWK can handle the range required. It also catches: +# "gawk: warning: -M ignored: MPFR/GMP support not compiled in" +# message produced where bignum support is not there, which is the +# only indication as the use of '-M' does not affect the exit status +# in this case. +ref="-2147483648" +for AWK in "$AWK -M" "$AWK"; do + val=$(echo "$ref" | $AWK '{ printf "%d\n", $1 }' 2>&1) || continue + test "$val" = "$ref" && status=0 && break +done + +test $status -eq 0 || { echo "No working AWK found" && exit $status; } + +for f in d i; do + echo Verifying $f + (set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-int $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-ldouble.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-ldouble.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Test for formatted printf output for long double conversions. - Copyright (C) 2024 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 - . */ - -#include -#include -#include - -#define MID_WIDTH 20 -#define HUGE_WIDTH 4950 -#define REF_FMT ".35Le" -#define REF_VAL(v) (v) -#define PREC LDBL_MANT_DIG -typedef long double type_t; -static const type_t vals[] = - { -HUGE_VAL, -LDBL_MAX, -LDBL_MIN, copysign (0, -1), -NAN, NAN, 0, LDBL_MIN, - LDBL_MAX, HUGE_VAL }; -static const char length[] = "L"; - -#define TIMEOUT (DEFAULT_TIMEOUT * 64) -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-ldouble.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-ldouble.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# Testing of long double printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +format=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +# For floating-point formats we need to use the bignum mode even if the +# regular mode would do, because GAWK in the latter mode uses sprintf(3) +# internally to process the conversion requested, so any bug in our code +# would then be verified against itself, defeating the objective of doing +# the verification against an independent implementation. +AWK="${AWK:-awk} -M" + +status=77 + +# Verify that AWK can handle the range required. It also catches: +# "gawk: warning: -M ignored: MPFR/GMP support not compiled in" +# message produced where bignum support is not there, which is the +# only indication as the use of '-M' does not affect the exit status +# in this case. +ref="-1.18973149535723176508575932662800702e+4932" +val=$(echo "$ref" | $AWK '{ PREC=113; printf "%.35e\n", $1 }' 2>&1) && + test "$val" = "$ref" && status=0 + +test $status -eq 0 || { echo "No working AWK found" && exit $status; } + +# Check for any additional conversions that AWK handles conditionally +# according to its version and/or the environment it has been built in. +# The 'A' and 'a' conversions are not suitable to use at this point, as +# output produced by AWK is different apparently due to a subtlety in +# rounding, so do not try them. +declare -A conversion_disabled +ref="-inf" +for f in f F; do + conversion_disabled[$f]=true + val=$(echo "$ref" | $AWK '{ printf "%'$f'\n", $1 }' 2>&1) && + test "${val^^}" = "${ref^^}" && unset conversion_disabled[$f] +done + +if test "${conversion_disabled[$format]+set}" = set; then + echo Unsupported $format + status=77 +else + echo Verifying $format + (set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-ldouble $format | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | + sed "s/^/Conversion $format output error, first line:\n/") 2>&1 || + status=1 +fi + +exit $status Index: glibc/stdio-common/tst-printf-format-llong.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-llong.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Test for formatted printf output for long long int conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 15 -#define HUGE_WIDTH 25 -#define REF_FMT "lli" -#define REF_VAL(v) (v) -typedef long long int type_t; -static const type_t vals[] = { LLONG_MIN, -123, -1, 0, 1, 42, LLONG_MAX }; -static const char length[] = "ll"; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-llong.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-llong.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Testing of long long int printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +status=77 + +# Verify that AWK can handle the range required. It also catches: +# "gawk: warning: -M ignored: MPFR/GMP support not compiled in" +# message produced where bignum support is not there, which is the +# only indication as the use of '-M' does not affect the exit status +# in this case. +ref="9223372036854775807" +for AWK in "$AWK -M" "$AWK"; do + val=$(echo "$ref" | $AWK '{ printf "%d\n", $1 }' 2>&1) || continue + test "$val" = "$ref" && status=0 && break +done + +test $status -eq 0 || { echo "No working AWK found" && exit $status; } + +for f in d i; do + echo Verifying $f + (set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-llong $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-long.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-long.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Test for formatted printf output for long int conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 15 -#define HUGE_WIDTH 25 -#define REF_FMT "li" -#define REF_VAL(v) (v) -typedef long int type_t; -static const type_t vals[] = { LONG_MIN, -123, -1, 0, 1, 42, LONG_MAX }; -static const char length[] = "l"; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-long.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-long.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Testing of long int printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +status=77 + +# Verify that AWK can handle the range required. It also catches: +# "gawk: warning: -M ignored: MPFR/GMP support not compiled in" +# message produced where bignum support is not there, which is the +# only indication as the use of '-M' does not affect the exit status +# in this case. +ref="9223372036854775807" +for AWK in "$AWK -M" "$AWK"; do + val=$(echo "$ref" | $AWK '{ printf "%d\n", $1 }' 2>&1) || continue + test "$val" = "$ref" && status=0 && break +done + +test $status -eq 0 || { echo "No working AWK found" && exit $status; } + +for f in d i; do + echo Verifying $f + (set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-long $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-p-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-p-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-p-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-p-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-p-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-p-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-p-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-p-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-p-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-p-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-p-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-p-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-p-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-p-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'printf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-p.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-p.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-p.h @@ -0,0 +1,29 @@ +/* Test feature wrapper for formatted 'printf' output. + Copyright (C) 2024 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 + . */ + +#include + +#define printf_under_test(...) \ +({ \ + int result; \ + \ + result = printf (__VA_ARGS__); \ + if (result < 0) \ + perror ("printf"); \ + result; \ +}) Index: glibc/stdio-common/tst-printf-format-s.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-s.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Test for formatted printf output for the 's' conversion. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 5 -#define HUGE_WIDTH 10 -#define REF_FMT "s" -#define REF_VAL(v) (v) -typedef const char *type_t; -static const type_t vals[] = - { "", "The", "quick", "brown fox", "jumps over the lazy dog" }; -static const char length[] = ""; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-s.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Testing of the 's' printf conversion. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +echo Verifying s +(set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-s s | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion s output error, first line:\n/") 2>&1 || + exit 1 Index: glibc/stdio-common/tst-printf-format-short.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-short.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Test for formatted printf output for short int conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 4 -#define HUGE_WIDTH 7 -#define REF_FMT "i" -#define REF_VAL(v) ((((v) & 0xffff) ^ 0x8000) - 0x8000) -typedef int type_t; -static const type_t vals[] = - { SHRT_MIN - 123, SHRT_MIN - 1, SHRT_MIN, -123, -1, 0, 1, 42, SHRT_MAX, - SHRT_MAX + 1, SHRT_MAX + 42 }; -static const char length[] = "h"; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-short.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-short.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Testing of short int printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +status=0 + +for f in d i; do + echo Verifying $f + (set -o pipefail + ${test_program_prefix} \ + ${common_objpfx}stdio-common/tst-printf-format-${xprintf}-short $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-skeleton-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-c.c @@ -0,0 +1,29 @@ +/* Test skeleton for formatted printf output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 3 +#define HUGE_WIDTH 4 +#define REF_FMT "c" +#define REF_VAL(v) (v) +typedef unsigned char type_t; +static const type_t vals[] = { 0, 42, UCHAR_MAX }; +static const char length[] = ""; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-char.c @@ -0,0 +1,31 @@ +/* Test skeleton for formatted printf output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 3 +#define HUGE_WIDTH 5 +#define REF_FMT "i" +#define REF_VAL(v) ((((v) & 0xff) ^ 0x80) - 0x80) +typedef int type_t; +static const type_t vals[] = + { SCHAR_MIN - 123, SCHAR_MIN - 1, SCHAR_MIN, -123, -1, 0, 1, 42, SCHAR_MAX, + SCHAR_MAX + 1, SCHAR_MAX + 42 }; +static const char length[] = "hh"; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-double.c @@ -0,0 +1,33 @@ +/* Test skeleton for formatted printf output for double conversions. + Copyright (C) 2024 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 + . */ + +#include +#include + +#define MID_WIDTH 20 +#define HUGE_WIDTH 320 +#define REF_FMT ".35e" +#define REF_VAL(v) (v) +#define PREC DBL_MANT_DIG +typedef double type_t; +static const type_t vals[] = + { -HUGE_VAL, -DBL_MAX, -DBL_MIN, copysign (0, -1), -NAN, NAN, 0, DBL_MIN, + DBL_MAX, HUGE_VAL }; +static const char length[] = ""; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-int.c @@ -0,0 +1,29 @@ +/* Test skeleton for formatted printf output for int conversions. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 8 +#define HUGE_WIDTH 15 +#define REF_FMT "i" +#define REF_VAL(v) (v) +typedef int type_t; +static const type_t vals[] = { INT_MIN, -123, -1, 0, 1, 42, INT_MAX }; +static const char length[] = ""; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-ldouble.c @@ -0,0 +1,38 @@ +/* Test skeleton for formatted printf output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include +#include +#include + +#define MID_WIDTH 20 +#define HUGE_WIDTH 4950 +#define REF_FMT ".35Le" +#define REF_VAL(v) (v) +#define PREC LDBL_MANT_DIG +typedef long double type_t; +static const type_t vals[] = + { -HUGE_VAL, -LDBL_MAX, -LDBL_MIN, copysign (0, -1), -NAN, NAN, 0, LDBL_MIN, + LDBL_MAX, HUGE_VAL }; +static const char length[] = "L"; + +#ifndef TIMEOUT +# define TIMEOUT (DEFAULT_TIMEOUT * 64) +#endif + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-llong.c @@ -0,0 +1,29 @@ +/* Test skeleton for formatted printf output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 15 +#define HUGE_WIDTH 25 +#define REF_FMT "lli" +#define REF_VAL(v) (v) +typedef long long int type_t; +static const type_t vals[] = { LLONG_MIN, -123, -1, 0, 1, 42, LLONG_MAX }; +static const char length[] = "ll"; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-long.c @@ -0,0 +1,29 @@ +/* Test skeleton for formatted printf output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 15 +#define HUGE_WIDTH 25 +#define REF_FMT "li" +#define REF_VAL(v) (v) +typedef long int type_t; +static const type_t vals[] = { LONG_MIN, -123, -1, 0, 1, 42, LONG_MAX }; +static const char length[] = "l"; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-s.c @@ -0,0 +1,30 @@ +/* Test skeleton for formatted printf output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 5 +#define HUGE_WIDTH 10 +#define REF_FMT "s" +#define REF_VAL(v) (v) +typedef const char *type_t; +static const type_t vals[] = + { "", "The", "quick", "brown fox", "jumps over the lazy dog" }; +static const char length[] = ""; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-short.c @@ -0,0 +1,31 @@ +/* Test skeleton for formatted printf output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 4 +#define HUGE_WIDTH 7 +#define REF_FMT "i" +#define REF_VAL(v) ((((v) & 0xffff) ^ 0x8000) - 0x8000) +typedef int type_t; +static const type_t vals[] = + { SHRT_MIN - 123, SHRT_MIN - 1, SHRT_MIN, -123, -1, 0, 1, 42, SHRT_MAX, + SHRT_MAX + 1, SHRT_MAX + 42 }; +static const char length[] = "h"; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-uchar.c @@ -0,0 +1,30 @@ +/* Test skeleton for formatted printf output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 3 +#define HUGE_WIDTH 4 +#define REF_FMT "u" +#define REF_VAL(v) ((v) & 0xff) +typedef unsigned int type_t; +static const type_t vals[] = + { 0, 1, 42, UCHAR_MAX, UCHAR_MAX + 1, UCHAR_MAX + 42 }; +static const char length[] = "hh"; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-uint.c @@ -0,0 +1,29 @@ +/* Test skeleton for formatted printf output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 7 +#define HUGE_WIDTH 14 +#define REF_FMT "u" +#define REF_VAL(v) (v) +typedef unsigned int type_t; +static const type_t vals[] = { 0, 1, 42, UINT_MAX }; +static const char length[] = ""; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-ullong.c @@ -0,0 +1,29 @@ +/* Test skeleton for formatted printf output for unsigned long long int convs. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 14 +#define HUGE_WIDTH 24 +#define REF_FMT "llu" +#define REF_VAL(v) (v) +typedef unsigned long long int type_t; +static const type_t vals[] = { 0, 1, 42, UINT_MAX, ULLONG_MAX }; +static const char length[] = "ll"; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-ulong.c @@ -0,0 +1,29 @@ +/* Test skeleton for formatted printf output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 14 +#define HUGE_WIDTH 24 +#define REF_FMT "lu" +#define REF_VAL(v) (v) +typedef unsigned long int type_t; +static const type_t vals[] = { 0, 1, 42, ULONG_MAX }; +static const char length[] = "l"; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton-ushort.c @@ -0,0 +1,30 @@ +/* Test skeleton for formatted printf output for unsigned short int convs. + Copyright (C) 2024 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 + . */ + +#include + +#define MID_WIDTH 3 +#define HUGE_WIDTH 6 +#define REF_FMT "u" +#define REF_VAL(v) ((v) & 0xffff) +typedef unsigned int type_t; +static const type_t vals[] = + { 0, 1, 42, USHRT_MAX, USHRT_MAX + 1, USHRT_MAX + 42 }; +static const char length[] = "h"; + +#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-skeleton.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-skeleton.c @@ -0,0 +1,371 @@ +/* Test skeleton for formatted printf output. + Copyright (C) 2024 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 + . */ + +/* The following definitions have to be supplied by the source including + this skeleton: + + Macros: + MID_WIDTH Medium width/precision positive integer constant. Choose + such as to cause some, but not all the strings produced + to be truncated for the conversions handled. + HUGE_WIDTH Large width/precision positive integer constant. Choose + such as to cause none of the strings produced to be + truncated for the conversions handled. + REF_FMT Reference output format string. Use no flags and such + a precision and length modifier, where applicable, and + a conversion as to make sure the output produced allows + the original value to be reproduced. + REF_VAL(v) Reference value V transformation. For conversions with + a truncating length modifier define such as to reproduce + the truncation operation, otherwise let V pass through. + PREC [optional] Working precision positive integer constant. + Set to the number of binary digits in the significand for + the argument type handled; usually for floating-point + conversions only, but it may be required for 128-bit or + wider integer data types as well. + + Typedefs: + type_t Variadic function argument type. Define to the promoted + type corresponding to the conversion argument type + handled. + + Variables: + vals Array of TYPE_T values. Choose such as to cover boundary + and any special cases. + length Length modifier string. Define according to the + conversion argument type handled. + + The feature to be tested is wrapped into 'printf_under_test'. It is up + to the source including this skeleton if this is going to be a macro + or an actual function. + + See tst-*printf-format-*.c for usage examples. */ + +#include +#include +#include +#include +#include +#include +#include + +/* Set to nonzero to select all possible tuples with repetitions of 1..n + elements from the set of flags as defined in FLAGS array below; n is + the length of FLAGS array. Otherwise select all possible tuples with + repetitions of 1..2 elements, followed by tuples of 3..n elements where + the index of each element k; k = 2..n in FLAGS is lower than the index + of element k-1 in FLAGS. */ +#ifndef TST_PRINTF_DUPS +# define TST_PRINTF_DUPS 0 +#endif +/* Set to nonzero to report the precision (number of significand digits) + required for floating-point calculations. */ +#ifndef PREC +# define PREC 0 +#endif + +/* The list of conversions permitted for the '#' flag, the '0' flag, + and precision respectively. */ +#define HASH_FORMATS "boxXaAeEfFgG" +#define ZERO_FORMATS "bdiouxXaAeEfFgG" +#define PREC_FORMATS "bdiouxXaAeEfFgGs" + +/* Output format conversion flags. */ +static struct +{ + /* Flag character. */ + char f; + /* List of conversion specifiers the flag is valid for; NULL if all. */ + const char *s; +} const flags[] = + { {'-'}, {'+'}, {' '}, {'#', HASH_FORMATS}, {'0', ZERO_FORMATS} }; + +/* Helper to initialize elements of the PW array for the width and + precision to be specified as a positive integer directly in the + format, and then as both a negative and a positive argument to '*'. */ +#define STR(v) #v +#define WPINIT(v) {0, STR (v)}, {v, NULL}, {-v, NULL} + +/* Width and precision settings to iterate over; zero is initialized + directly as it has no corresponding negated value and other values + use the helper above. */ +static struct wp +{ + /* Integer argument to '*', used if S is NULL. */ + int i; + /* String denoting an integer to use in the format, or NULL to use '*'. */ + const char *s; +} const wp[] = + { {0, "0"}, {0, NULL}, WPINIT (1), WPINIT (2), + WPINIT (MID_WIDTH), WPINIT (HUGE_WIDTH) }; + +/* Produce a record according to '%' and zero or more output format flags + already provided in FMT at indices 0..IDX-1, width W if non-NULL, '.' + precision specifier if POINT set to true, precision P if non-NULL, + any length modifiers L, conversion C, and value VAL. + + Record formats produced: + + %:: + %.:: + %:: + %.:: + %.

:: + %.

:: + %*::: + %*.::: + %.*:

:: + %*.*::

:: + + Return 0 on success, -1 on failure. */ + +static int +do_printf (char *fmt, size_t idx, + const struct wp *w, bool point, const struct wp *p, + const char *l, char c, type_t val) +{ + int wpval[2] = { 0 }; + size_t nint = 0; + int result; + size_t i; + + if (w != NULL) + { + if (w->s == NULL) + { + fmt[idx++] = '*'; + wpval[nint++] = w->i; + } + else + for (i = 0; w->s[i] != '\0'; i++) + fmt[idx++] = w->s[i]; + } + if (point) + fmt[idx++] = '.'; + if (p != NULL) + { + if (p->s == NULL) + { + fmt[idx++] = '*'; + wpval[nint++] = p->i; + } + else + for (i = 0; p->s[i] != '\0'; i++) + fmt[idx++] = p->s[i]; + } + for (i = 0; length[i] != '\0'; i++) + fmt[idx++] = length[i]; + fmt[idx++] = c; + fmt[idx] = ':'; + fmt[idx + 1] = '\0'; + if (fputs (fmt, stdout) == EOF) + { + perror ("fputs"); + return -1; + } + fmt[idx++] = '\0'; + if (nint > 0) + { + result = printf ("%i:", wpval[0]); + if (result < 0) + { + perror ("printf"); + return -1; + } + if (nint > 1) + { + result = printf ("%i:", wpval[1]); + if (result < 0) + { + perror ("printf"); + return -1; + } + } + } + switch (nint) + { + case 0: + result = printf_under_test (fmt, val); + break; + case 1: + result = printf_under_test (fmt, wpval[0], val); + break; + case 2: + result = printf_under_test (fmt, wpval[0], wpval[1], val); + break; + default: + fputs ("Broken test, nint > 2\n", stderr); + return -1; + } + if (result < 0) + return -1; + if (fputs (":\n", stdout) == EOF) + { + perror ("fputs"); + return -1; + } + return 0; +} + +/* Produce a list of records according to '%' and zero or more output + format flags already provided in FMT at indices 0..IDX-1, iterating + over widths and precisions defined in global WP array, any length + modifiers L, conversion C, and value VAL. Inline '0' is omitted for + the width, as it is a flag already handled among the flags supplied. + Precision is omitted where the conversion does not allow it. + + Return 0 on success, -1 on failure. */ + +static int +do_printf_flags (char *fmt, size_t idx, const char *l, char c, type_t val) +{ + bool do_prec = strchr (PREC_FORMATS, c) != NULL; + size_t i; + + if (do_printf (fmt, idx, NULL, false, NULL, l, c, val) < 0) + return -1; + if (do_prec && do_printf (fmt, idx, NULL, true, NULL, l, c, val) < 0) + return -1; + for (i = 0; i < array_length (wp); i++) + { + size_t j; + + if (do_prec && do_printf (fmt, idx, NULL, true, wp + i, l, c, val) < 0) + return -1; + /* Inline '0' is a flag rather than width and is handled elsewhere. */ + if (wp[i].s != NULL && wp[i].s[0] == '0' && wp[i].s[1] == '\0') + continue; + if (do_printf (fmt, idx, wp + i, false, NULL, l, c, val) < 0) + return -1; + if (do_prec) + { + if (do_printf (fmt, idx, wp + i, true, NULL, l, c, val) < 0) + return -1; + for (j = 0; j < array_length (wp); j++) + if (do_printf (fmt, idx, wp + i, true, wp + j, l, c, val) < 0) + return -1; + } + } + return 0; +} + +/* Produce a list of records using the formatted output specifier + supplied in ARGV[1] preceded by any length modifier supplied in + the global LENGTH variable, iterating over format flags defined + in the global FLAGS array, and values supplied in the global VALS + array. Note that the output specifier supplied is not verified + against TYPE_T, so undefined behavior will result if this is used + incorrectly. + + If PREC is nonzero, then this record: + + prec: + + is produced at the beginning. Then for each VAL from VALS a block + of records is produced starting with: + + val: + + where VAL is formatted according to REF_FMT output format. The + block continues with records as shown with DO_PRINTF above using + flags iterated over according to TST_PRINTF_DUPS. + + See the top of this file for the definitions that have to be + provided by the source including this skeleton. */ + +static int +do_test (int argc, char *argv[]) +{ + char fmt[100] = {'%'}; + size_t j; + size_t v; + char c; + + if (argc < 2 || *argv[1] == '\0') + { + fprintf (stderr, "Usage: %s \n", basename (argv[0])); + return EXIT_FAILURE; + } + + mtrace (); + + if (PREC && printf ("prec:%i\n", PREC) < 0) + { + perror ("printf"); + return EXIT_FAILURE; + } + + c = *argv[1]; + for (v = 0; v < array_length (vals); v++) + { + if (printf ("val:%" REF_FMT "\n", REF_VAL (vals[v])) < 0) + { + perror ("printf"); + return EXIT_FAILURE; + } + + if (do_printf_flags (fmt, 1, length, c, vals[v]) < 0) + return EXIT_FAILURE; + for (j = 0; j < array_length (flags); j++) + { + bool done = false; + size_t i[j + 1]; + size_t k; + + memset (i, 0, sizeof (i)); + while (!done) + { + bool skip = false; + size_t idx = 1; + char f; + + for (k = 0; k <= j; k++) + { + const char *s = flags[i[k]].s; + + if (s && strchr (s, c) == NULL) + skip = true; + if (!TST_PRINTF_DUPS && j > 1 && k > 0 && i[k] >= i[k - 1]) + skip = true; + if (skip) + break; + + f = flags[i[k]].f; + fmt[idx++] = f; + } + if (!skip && do_printf_flags (fmt, idx, length, c, vals[v]) < 0) + return EXIT_FAILURE; + for (k = 0; k <= j; k++) + { + i[k]++; + if (i[k] < array_length (flags)) + break; + else if (k == j) + done = true; + else + i[k] = 0; + } + } + } + } + + return EXIT_SUCCESS; +} + +#define TEST_FUNCTION_ARGV do_test +#include Index: glibc/stdio-common/tst-printf-format-uchar.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-uchar.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Test for formatted printf output for unsigned char conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 3 -#define HUGE_WIDTH 4 -#define REF_FMT "u" -#define REF_VAL(v) ((v) & 0xff) -typedef unsigned int type_t; -static const type_t vals[] = - { 0, 1, 42, UCHAR_MAX, UCHAR_MAX + 1, UCHAR_MAX + 42 }; -static const char length[] = "hh"; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-uchar.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-uchar.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Testing of unsigned char printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +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}-uchar $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-uint.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-uint.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Test for formatted printf output for unsigned int conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 7 -#define HUGE_WIDTH 14 -#define REF_FMT "u" -#define REF_VAL(v) (v) -typedef unsigned int type_t; -static const type_t vals[] = { 0, 1, 42, UINT_MAX }; -static const char length[] = ""; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-uint.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-uint.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Testing of unsigned int printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +status=77 + +# Verify that AWK can handle the range required. It also catches: +# "gawk: warning: -M ignored: MPFR/GMP support not compiled in" +# message produced where bignum support is not there, which is the +# only indication as the use of '-M' does not affect the exit status +# in this case. +ref="4294967295" +for AWK in "$AWK -M" "$AWK"; do + val=$(echo "$ref" | $AWK '{ printf "%d\n", $1 }' 2>&1) || continue + test "$val" = "$ref" && status=0 && break +done + +test $status -eq 0 || { echo "No working AWK found" && exit $status; } + +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 | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-ullong.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-ullong.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Test for formatted printf output for unsigned long long int conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 14 -#define HUGE_WIDTH 24 -#define REF_FMT "llu" -#define REF_VAL(v) (v) -typedef unsigned long long int type_t; -static const type_t vals[] = { 0, 1, 42, UINT_MAX, ULLONG_MAX }; -static const char length[] = "ll"; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-ullong.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-ullong.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Testing of unsigned long long int printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +status=77 + +# Verify that AWK can handle the range required. It also catches: +# "gawk: warning: -M ignored: MPFR/GMP support not compiled in" +# message produced where bignum support is not there, which is the +# only indication as the use of '-M' does not affect the exit status +# in this case. +ref="18446744073709551615" +for AWK in "$AWK -M" "$AWK"; do + val=$(echo "$ref" | $AWK '{ printf "%d\n", $1 }' 2>&1) || continue + test "$val" = "$ref" && status=0 && break +done + +test $status -eq 0 || { echo "No working AWK found" && exit $status; } + +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}-ullong $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-ulong.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-ulong.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Test for formatted printf output for unsigned long int conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 14 -#define HUGE_WIDTH 24 -#define REF_FMT "lu" -#define REF_VAL(v) (v) -typedef unsigned long int type_t; -static const type_t vals[] = { 0, 1, 42, ULONG_MAX }; -static const char length[] = "l"; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-ulong.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-ulong.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Testing of unsigned long int printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +status=77 + +# Verify that AWK can handle the range required. It also catches: +# "gawk: warning: -M ignored: MPFR/GMP support not compiled in" +# message produced where bignum support is not there, which is the +# only indication as the use of '-M' does not affect the exit status +# in this case. +ref="18446744073709551615" +for AWK in "$AWK -M" "$AWK"; do + val=$(echo "$ref" | $AWK '{ printf "%d\n", $1 }' 2>&1) || continue + test "$val" = "$ref" && status=0 && break +done + +test $status -eq 0 || { echo "No working AWK found" && exit $status; } + +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}-ulong $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format-ushort.c =================================================================== --- glibc.orig/stdio-common/tst-printf-format-ushort.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Test for formatted printf output for unsigned short int conversions. - Copyright (C) 2024 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 - . */ - -#include - -#define MID_WIDTH 3 -#define HUGE_WIDTH 6 -#define REF_FMT "u" -#define REF_VAL(v) ((v) & 0xffff) -typedef unsigned int type_t; -static const type_t vals[] = - { 0, 1, 42, USHRT_MAX, USHRT_MAX + 1, USHRT_MAX + 42 }; -static const char length[] = "h"; - -#include "tst-printf-format-skeleton.c" Index: glibc/stdio-common/tst-printf-format-ushort.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-ushort.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Testing of unsigned short int printf conversions. +# Copyright (C) 2024 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 +# . + +set -e + +xprintf=$1; shift +common_objpfx=$1; shift +test_program_prefix=$1; shift + +AWK=${AWK:-awk} + +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}-ushort $f | + $AWK -f tst-printf-format.awk 2>&1 | + head -n 1 | sed "s/^/Conversion $f output error, first line:\n/") 2>&1 || + status=1 +done + +exit $status Index: glibc/stdio-common/tst-printf-format.awk =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format.awk @@ -0,0 +1,127 @@ +# Testing of printf conversions. +# Copyright (C) 2024 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 +# . + +BEGIN { + FS = ":" +} + +/^prec:/ { + PREC = $2 + next +} + +/^val:/ { + val = $2 + # Prepend "+" for +Inf or +NaN value lacking a sign, because gawk + # interpretes them as strings rather than numeric values in the + # non-bignum mode unless a sign has been explicitly given. Keep + # original 'val' for reporting. + value = gensub(/^(INF|NAN|inf|nan)/, "+\\1", 1, val) + next +} + +/^%/ { + # Discard the trailing empty field, used to improve legibility of data. + input = $--NF + format = $1 + width = $2 + precision = "." $(NF - 1) + # Discard any negative precision, which is to be taken as if omitted. + sub(/\.-.*/, "", precision) + # Simplify handling and paste the precision and width specified as + # arguments to '*' directly into the format. + sub(/\.\*/, precision, format) + sub(/\*/, width, format) + # Discard length modifiers. They are only relevant to C data types. + sub(/([DHLjhltz]|wf?[1-9][0-9]*)/, "", format) + # Discard the '#' flag with the octal conversion if output starts with + # 0 in the absence of this flag. In that case no extra 0 is supposed + # to be produced, but gawk prepends it anyway. + if (format ~ /#.*o/) + { + tmpfmt = gensub(/#/, "", "g", format) + tmpout = sprintf(tmpfmt, value) + if (tmpout ~ /^ *0/) + format = tmpfmt + } + # Likewise with the hexadecimal conversion where zero value with the + # precision of zero is supposed to produce no characters, but gawk + # outputs 0 instead. + else if (format ~ /#.*[Xx]/) + { + tmpfmt = gensub(/#/, "", "g", format) + tmpout = sprintf(tmpfmt, value) + if (tmpout ~ /^ *$/) + format = tmpfmt + } + # AWK interpretes input opportunistically as a number, which interferes + # with how the 'c' conversion works: "a" input will result in "a" output + # however "0" input will result in "^@" output rather than "0". Force + # the value to be interpreted as a string then, by appending "". + output = sprintf(format, value "") + # Make up for various anomalies with the handling of +/-Inf and +/-NaN + # values and reprint the output produced using the string conversion, + # with the field width carried over and the relevant flags handled by + # hand. + if (format ~ /[EFGefg]/ && value ~ /(INF|NAN|inf|nan)/) + { + minus = format ~ /-/ ? "-" : "" + sign = value ~ /-/ ? "-" : format ~ /\+/ ? "+" : format ~ / / ? " " : "" + if (format ~ /^%[^\.1-9]*[1-9][0-9]*/) + width = gensub(/^%[^\.1-9]*([1-9][0-9]*).*$/, "\\1", 1, format) + else + width = "" + output = gensub(/[-+ ]/, "", "g", output) + output = sprintf("%" minus width "s", sign output) + } + # Produce "+" where the '+' flag has been used with a signed integer + # conversion for zero value, observing any field width in effect. + # In that case "+" is always supposed to be produced, but with the + # precision of zero gawk in the non-bignum mode produces any padding + # requested only. + else if (format ~ /\+.*[di]/ && value == 0) + { + output = gensub(/^( *) $/, format ~ /-/ ? "+\\1" : "\\1+", 1, output) + output = gensub(/^$/, "+", 1, output) + } + # Produce " " where the space flag has been used with a signed integer + # conversion for zero value. In that case at least one " " is + # supposed to be produced, but with the precision of zero gawk in the + # non-bignum mode produces nothing. + else if (format ~ / .*[di]/ && value == 0) + { + output = gensub(/^$/, " ", 1, output) + } + if (output != input) + { + printf "(\"%s\"%s%s, %s) => \"%s\", expected \"%s\"\n", \ + $1, (NF > 2 ? ", " $2 : ""), (NF > 3 ? ", " $3 : ""), val, \ + input, output > "/dev/stderr" + status = 1 + } + next +} + +{ + printf "unrecognized input: \"%s\"\n", $0 > "/dev/stderr" + status = 1 +} + +END { + exit status +} Index: glibc/stdio-common/tst-printf-format.sh =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Formatted printf output test script dispatcher. +# Copyright (C) 2024 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 +# . + +set -e + +output=${1##*/}; shift + +tmp=${output#tst-printf-format-} +tmp=${tmp%.out} + +# We are given the name of the make target in $1. With the common prefix +# and suffix both removed we are left with the inner part, which encodes +# the function under test, the conversion type, and optionally the format +# specifier, all separated with hyphens, i.e. F-T-S or F-T. Extract them +# and call the script corresponding to the conversion type, passing the +# function under test and any format specifier as arguments. + +xprintf=${tmp%%-*}; tmp=${tmp#*-} +conv=${tmp%%-*}; tmp=${tmp#${conv}} +fmt=${tmp#*-} +script=tst-printf-format-$conv.sh + +exec ${BASH:-bash} $script $xprintf $fmt "$@" From patchwork Wed Oct 16 15:45:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99024 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 526BB3857BA5 for ; Wed, 16 Oct 2024 15:48:09 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id A8CBA3858D20 for ; Wed, 16 Oct 2024 15:45:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A8CBA3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A8CBA3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093532; cv=none; b=CbjQa5ZaOWyfent7p4HMhsNMN1C+NtpUzX32msfJMdZqxU1JxcmvBjSYFjoYgPY0mNdlKm+RZjDTJAac65HqjpPVWbuUJqssOvl7I3D/+ZJXv69nSr76T0IMjwI1dxpVPcx7uCVw3oM1G6rdxfRWekYUTIbPzMBTneijT+pOPhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093532; c=relaxed/simple; bh=xLIZhZKQAndlMn+MnJOmfAeHK6h7/juT+dGzsK01qL0=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=KiZOK+vWIKi38a9cENbFWyqHuDH18SNAq5sDs0zBelvIomXkpfTTBIUClDedkAlHS03vgfJLwcGsEp9BSQNk3BAZtCJ3dSLtgK7XjJp5R1xKYz4eTff6owjQGKALhAo9IeMV0qFgndGLft43lX9p6pA4u9j8Eu7a3AFQIgTzMFs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id C94AB92009E; Wed, 16 Oct 2024 17:45:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id C712992009D; Wed, 16 Oct 2024 16:45:26 +0100 (BST) Date: Wed, 16 Oct 2024 16:45:26 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 02/12] stdio-common: Add tests for formatted asprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.5 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire asprintf into test infrastructure for formatted printf output specifiers. Owing to mtrace logging of lots of memory allocation calls these tests take a considerable amount of time to complete, except for the character conversion, taking from 00m51s for 'tst-printf-format-as-s --direct s', through 03m23s and 09m21s for 'tst-printf-format-as-char --direct i' and 'tst-printf-format-as-double --direct f' respectively, to 31m35s for 'tst-printf-format-as-ldouble --direct f', all in standalone execution from NFS on a RISC-V FU740@1.2GHz system and with output redirected over 100Mbps network via SSH. Set timeouts for the tests accordingly then, with a global default for all the asprintf tests, and then individual higher settings for double and long double tests each. --- New change in v2. --- stdio-common/Makefile | 2 - stdio-common/tst-printf-format-as-c.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-char.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-double.c | 22 +++++++++++++ stdio-common/tst-printf-format-as-int.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-ldouble.c | 22 +++++++++++++ stdio-common/tst-printf-format-as-llong.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-long.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-s.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-short.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-uchar.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-uint.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-ullong.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-ulong.c | 20 ++++++++++++ stdio-common/tst-printf-format-as-ushort.c | 20 ++++++++++++ stdio-common/tst-printf-format-as.h | 46 ++++++++++++++++++++++++++++ 16 files changed, 331 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-asprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p +xprintf-funcs := p as # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-as-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-as-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-as-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-double.c @@ -0,0 +1,22 @@ +/* Test for formatted 'asprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#define TIMEOUT (DEFAULT_TIMEOUT * 64) + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-as-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-as-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-ldouble.c @@ -0,0 +1,22 @@ +/* Test for formatted 'asprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#define TIMEOUT (DEFAULT_TIMEOUT * 192) + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-as-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-as-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-as-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-as-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-as-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-as-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-as-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-as-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-as-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'asprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-as.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-as.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-as.h @@ -0,0 +1,46 @@ +/* Test feature wrapper for formatted 'asprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include + +#define printf_under_test(...) \ +({ \ + __label__ out; \ + int result; \ + char *str; \ + \ + result = asprintf (&str, __VA_ARGS__); \ + if (result < 0) \ + { \ + perror ("asprintf"); \ + goto out; \ + } \ + if (fwrite (str, sizeof (*str), result, stdout) != result) \ + { \ + perror ("fwrite"); \ + result = -1; \ + } \ + free (str); \ +out: \ + result; \ +}) + +#ifndef TIMEOUT +# define TIMEOUT (DEFAULT_TIMEOUT * 24) +#endif From patchwork Wed Oct 16 15:45:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99021 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A37353858417 for ; Wed, 16 Oct 2024 15:46:58 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id 055A2385841E for ; Wed, 16 Oct 2024 15:45:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 055A2385841E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 055A2385841E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093540; cv=none; b=nx6r6x0FgIKgZ81h1z+a/gIbM3llMvGfllgVf8U/cRkj5ljGwCnvk564h2rPJ+kPWXI4gAMceBWDQT24ATga4HONtXJ878+NbEuVY6+ds4/tefE2XzsCbeYeH5xhNSW0PiMUbihdyKkDJQ1dznS5C68k6u9907CN1ICueTkv/Mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093540; c=relaxed/simple; bh=X+iz6qqKw9hzWuZr6gXEfOZB7RP2DwDwq0p9v4ydnag=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=SqyBVPPvg+Mma96+7Ibpm8cGJTdkBJjHcgBeSZmGe42v5x3AN1lX7+APcFptwjW8LhcK1qrEn4CikVouXquekaUKaXKj6nDdKtXSpUMSPlPEnV/bOe1DP17RHS0qVw68Qwx5TxM4uWYFdvV3FYRgxWfI+f15mZw+yEP+Ymu8RZQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 8BE9192009C; Wed, 16 Oct 2024 17:45:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 866C992009B; Wed, 16 Oct 2024 16:45:33 +0100 (BST) Date: Wed, 16 Oct 2024 16:45:33 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 03/12] stdio-common: Add tests for formatted dprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.5 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire dprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 - stdio-common/tst-printf-format-d-c.c | 20 ++++++++++ stdio-common/tst-printf-format-d-char.c | 20 ++++++++++ stdio-common/tst-printf-format-d-double.c | 20 ++++++++++ stdio-common/tst-printf-format-d-int.c | 20 ++++++++++ stdio-common/tst-printf-format-d-ldouble.c | 20 ++++++++++ stdio-common/tst-printf-format-d-llong.c | 20 ++++++++++ stdio-common/tst-printf-format-d-long.c | 20 ++++++++++ stdio-common/tst-printf-format-d-s.c | 20 ++++++++++ stdio-common/tst-printf-format-d-short.c | 20 ++++++++++ stdio-common/tst-printf-format-d-uchar.c | 20 ++++++++++ stdio-common/tst-printf-format-d-uint.c | 20 ++++++++++ stdio-common/tst-printf-format-d-ullong.c | 20 ++++++++++ stdio-common/tst-printf-format-d-ulong.c | 20 ++++++++++ stdio-common/tst-printf-format-d-ushort.c | 20 ++++++++++ stdio-common/tst-printf-format-d.h | 58 +++++++++++++++++++++++++++++ 16 files changed, 339 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-dprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as +xprintf-funcs := p as d # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-d-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-d-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-d-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-d-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-d-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-d-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-d-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-d-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-d-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-d-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-d-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-d-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-d-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-d-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'dprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-d.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-d.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-d.h @@ -0,0 +1,58 @@ +/* Test feature wrapper for formatted 'dprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include +#include + +/* We need to go through the POSIX-mandated dance to switch between + handles on an open file description. */ + +#define printf_under_test(...) \ +({ \ + __label__ out; \ + int result; \ + \ + result = fflush (stdout); \ + if (result == EOF) \ + { \ + perror ("fflush"); \ + goto out; \ + } \ + result = lseek (STDOUT_FILENO, 0, SEEK_END); \ + if (result < 0 && errno == ESPIPE) \ + result = 0; \ + if (result < 0) \ + { \ + perror ("lseek"); \ + goto out; \ + } \ + result = dprintf (STDOUT_FILENO, __VA_ARGS__); \ + if (result < 0) \ + { \ + perror ("dprintf"); \ + goto out; \ + } \ + result = fseek (stdout, 0, SEEK_END); \ + if (result < 0 && errno == ESPIPE) \ + result = 0; \ + if (result < 0) \ + perror ("fseek"); \ +out: \ + result; \ +}) From patchwork Wed Oct 16 15:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99025 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C91343858282 for ; Wed, 16 Oct 2024 15:48:11 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 4F078385840E for ; Wed, 16 Oct 2024 15:45:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F078385840E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4F078385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093546; cv=none; b=oUjFxcfyi+CtvLSJtGkC4kAmdbxwP2cs1VBczXKA7Z5FCycbUCShcR1dE2OIbhkTGoebJcZ7NOobCh2UDxGKMhY0flTTzzfrzDoUwr2aRgWvL0cYfYz9zQyshd4q35ZeleUeBytLBNpQi/SsPdRXWMbAqLgFNZEm/ETWRaQnmwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093546; c=relaxed/simple; bh=fZMDXQ4lV58Cv0adrdkrKRo0h3qBiIBE6GmQEZ/Qmck=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=I26ThCMuIzqWmDkdcD6AUt5+NfVcpuAweK+i07ibl5f2DQ74vaVZXbXMBe0SE4jjBOtmC4laZTFVbcXCboX6UGNzh2XuErrTG/GWVV3MeMDvKZml+mhw4R7GbxoPpBJKDuF3ehWjpMfVesm1voxNC3Ybe+o/zbxC9jXVCEgwnys= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id CD79992009E; Wed, 16 Oct 2024 17:45:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id C76C392009D; Wed, 16 Oct 2024 16:45:39 +0100 (BST) Date: Wed, 16 Oct 2024 16:45:39 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 04/12] stdio-common: Add tests for formatted fprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.7 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire fprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 +- stdio-common/tst-printf-format-f-c.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-char.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-double.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-int.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-ldouble.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-llong.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-long.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-s.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-short.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-uchar.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-uint.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-ullong.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-ulong.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f-ushort.c | 20 ++++++++++++++++++++ stdio-common/tst-printf-format-f.h | 29 +++++++++++++++++++++++++++++ 16 files changed, 310 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-fprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d +xprintf-funcs := p as d f # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-f-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-f-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-f-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-f-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-f-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-f-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-f-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-f-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-f-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-f-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-f-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-f-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-f-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-f-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'fprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-f.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-f.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-f.h @@ -0,0 +1,29 @@ +/* Test feature wrapper for formatted 'fprintf' output. + Copyright (C) 2024 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 + . */ + +#include + +#define printf_under_test(...) \ +({ \ + int result; \ + \ + result = fprintf (stdout, __VA_ARGS__); \ + if (result < 0) \ + perror ("fprintf"); \ + result; \ +}) From patchwork Wed Oct 16 15:45:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99023 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E5D7385840A for ; Wed, 16 Oct 2024 15:47:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id 0CB863858023 for ; Wed, 16 Oct 2024 15:45:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CB863858023 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0CB863858023 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093549; cv=none; b=KW+LYZJiRwKi6mYHHKl8TtehCGMAW3aAPsg6d2CROi6lbxQwn5m8E+AkGrkb3Ynp5bNO5gLbG3TX3FNkI7FW0ZBXJJDBDsKuNNYs/nQxiMsW9lgXxCOHDW0WASVDllmOHOk1xSOitjTqM1/ZmH7m9Z97TrTmuQudZwd77UfHiEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093549; c=relaxed/simple; bh=YwO/Se6VfCTEysAL84mVOEhniC/6m0aKjVCVzTbyZQU=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=CHLnSZtGKrGMtRAf1217jKI5vlPFjBIEXQmadv85BBlCapvn8qxghCQARaKMtb/JVqFiE7+YAkwm3Qjn8Xf0ATpipy7/vdxW38nmZJMkhwdMm+tXfYPV2YtcpAZHd62/zTEIde4gmc02kFYKRv/Bpf3VpWbiEtt6Ad/fopNRbfs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 8EA1D92009C; Wed, 16 Oct 2024 17:45:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 8886492009B; Wed, 16 Oct 2024 16:45:45 +0100 (BST) Date: Wed, 16 Oct 2024 16:45:45 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 05/12] stdio-common: Add tests for formatted sprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.5 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire sprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 stdio-common/tst-printf-format-s-c.c | 20 +++++++++ stdio-common/tst-printf-format-s-char.c | 20 +++++++++ stdio-common/tst-printf-format-s-double.c | 20 +++++++++ stdio-common/tst-printf-format-s-int.c | 20 +++++++++ stdio-common/tst-printf-format-s-ldouble.c | 20 +++++++++ stdio-common/tst-printf-format-s-llong.c | 20 +++++++++ stdio-common/tst-printf-format-s-long.c | 20 +++++++++ stdio-common/tst-printf-format-s-s.c | 20 +++++++++ stdio-common/tst-printf-format-s-short.c | 20 +++++++++ stdio-common/tst-printf-format-s-uchar.c | 20 +++++++++ stdio-common/tst-printf-format-s-uint.c | 20 +++++++++ stdio-common/tst-printf-format-s-ullong.c | 20 +++++++++ stdio-common/tst-printf-format-s-ulong.c | 20 +++++++++ stdio-common/tst-printf-format-s-ushort.c | 20 +++++++++ stdio-common/tst-printf-format-s.h | 60 +++++++++++++++++++++++++++++ 16 files changed, 341 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-sprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d f +xprintf-funcs := p as d f s # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-s-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-s-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-s-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-s-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-s-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-s-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-s-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-s-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-s-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-s-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-s-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-s-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-s-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-s-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'sprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-s.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-s.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-s.h @@ -0,0 +1,60 @@ +/* Test feature wrapper for formatted 'sprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include + +#include + +#define SPRINTF_BUFFER_SIZE 65536 + +static struct support_next_to_fault ntf; + +#define PREPARE printf_under_test_init +static void +printf_under_test_init (int argc, char **argv) +{ + ntf = support_next_to_fault_allocate (SPRINTF_BUFFER_SIZE); +} + +static void __attribute__ ((destructor)) +printf_under_test_fini (void) +{ + support_next_to_fault_free (&ntf); +} + +#define printf_under_test(...) \ +({ \ + __label__ out; \ + char *str = ntf.buffer; \ + int result; \ + \ + result = sprintf (str, __VA_ARGS__); \ + if (result < 0) \ + { \ + perror ("sprintf"); \ + goto out; \ + } \ + if (fwrite (str, sizeof (*str), result, stdout) != result) \ + { \ + perror ("fwrite"); \ + result = -1; \ + } \ +out: \ + result; \ +}) From patchwork Wed Oct 16 15:45:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99028 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E144E3857823 for ; Wed, 16 Oct 2024 15:49:20 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id 9D8A53858429 for ; Wed, 16 Oct 2024 15:45:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D8A53858429 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9D8A53858429 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093555; cv=none; b=LFBZi6f1kuCq1a0NnWAz6yb8xU0REAhTXcXGf6utirrn6FAjUrMEpaioPoqDNW40Xqp3YCp7MhS6m6uVxXXbLVeGdQkXhIlY4OjgoI81WUAOfEzd/a6z18ChRFlGtbHH8ePzv3WjbY5GO8xJAHllnAIkuqF/utjoczBorIO1Dlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093555; c=relaxed/simple; bh=h49n0h7vfyB2izxAsl8dt8lbSd3pepvRzNLJ+nJNLEg=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=Fy4JTq+jgAEmDc+oX5MNC+XfrIvtQjnkExmtV374VpRvtPfxA7OPEPR4wavFBqjryl+SZkyFl4byi12oQ/41rWkuri+rKLclonFUM9QQFg9G1u8blB74ezmKhfgne8MyuXuPykHOK8jFOAjr3WrHCgHvAgwTrU09UB0q7bUeE04= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 2D16492009C; Wed, 16 Oct 2024 17:45:51 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 26E1B92009B; Wed, 16 Oct 2024 16:45:51 +0100 (BST) Date: Wed, 16 Oct 2024 16:45:51 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 06/12] stdio-common: Add tests for formatted snprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.5 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire snprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 stdio-common/tst-printf-format-sn-c.c | 20 +++++++++ stdio-common/tst-printf-format-sn-char.c | 20 +++++++++ stdio-common/tst-printf-format-sn-double.c | 20 +++++++++ stdio-common/tst-printf-format-sn-int.c | 20 +++++++++ stdio-common/tst-printf-format-sn-ldouble.c | 20 +++++++++ stdio-common/tst-printf-format-sn-llong.c | 20 +++++++++ stdio-common/tst-printf-format-sn-long.c | 20 +++++++++ stdio-common/tst-printf-format-sn-s.c | 20 +++++++++ stdio-common/tst-printf-format-sn-short.c | 20 +++++++++ stdio-common/tst-printf-format-sn-uchar.c | 20 +++++++++ stdio-common/tst-printf-format-sn-uint.c | 20 +++++++++ stdio-common/tst-printf-format-sn-ullong.c | 20 +++++++++ stdio-common/tst-printf-format-sn-ulong.c | 20 +++++++++ stdio-common/tst-printf-format-sn-ushort.c | 20 +++++++++ stdio-common/tst-printf-format-sn.h | 60 ++++++++++++++++++++++++++++ 16 files changed, 341 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-snprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d f s +xprintf-funcs := p as d f s sn # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-sn-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-sn-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-sn-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-sn-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-sn-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-sn-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-sn-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-sn-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-sn-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-sn-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-sn-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-sn-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-sn-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-sn-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'snprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-sn.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-sn.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-sn.h @@ -0,0 +1,60 @@ +/* Test feature wrapper for formatted 'snprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include + +#include + +#define SPRINTF_BUFFER_SIZE 65536 + +static struct support_next_to_fault ntf; + +#define PREPARE printf_under_test_init +static void +printf_under_test_init (int argc, char **argv) +{ + ntf = support_next_to_fault_allocate (SPRINTF_BUFFER_SIZE); +} + +static void __attribute__ ((destructor)) +printf_under_test_fini (void) +{ + support_next_to_fault_free (&ntf); +} + +#define printf_under_test(...) \ +({ \ + __label__ out; \ + char *str = ntf.buffer; \ + int result; \ + \ + result = snprintf (str, ntf.length, __VA_ARGS__); \ + if (result < 0) \ + { \ + perror ("snprintf"); \ + goto out; \ + } \ + if (fwrite (str, sizeof (*str), result, stdout) != result) \ + { \ + perror ("fwrite"); \ + result = -1; \ + } \ +out: \ + result; \ +}) From patchwork Wed Oct 16 15:45:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99026 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 209693858430 for ; Wed, 16 Oct 2024 15:48:54 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id E9EE53858288 for ; Wed, 16 Oct 2024 15:45:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E9EE53858288 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E9EE53858288 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093561; cv=none; b=ZnvwTBdJw5ZJhLquiQQYAUEOSEMysiJft9FDyscd9ZOXJfwL++KYLPGYqQqVn1hTBDHCM2A4COIkSDQZWVwEYdBjUFQ4sQ3nLfQDTXJTZj3rZo36nkcwHUqsAyVRt+WJ5tzFjGZkDD6Gcvs0PREGyH+oAWnd1xacjl5wrRE31Zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093561; c=relaxed/simple; bh=Hvl78+lYexNomWPVOrdHp56OLUIj2llRPVqHLs1LibU=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=Uopz7EZ5rkc9QKq+BUJXTO9rn/pdBfyQksE0gp4MwD4isB4A3zJe70aVTGBHM9UAo7t3JYzpIRfq5BTKnuYKdYoKu5dfpTGiUkFuvY5rmWVFsLyCKUp4zgJZOnZpRwXqNJGrbRSnax9+VYCEobu2wjds+VvIE6IuM6+hvVyZDWk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 7A6AC92009C; Wed, 16 Oct 2024 17:45:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 7399992009B; Wed, 16 Oct 2024 16:45:57 +0100 (BST) Date: Wed, 16 Oct 2024 16:45:57 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 07/12] stdio-common: Add tests for formatted vprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.7 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire vprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 - stdio-common/tst-printf-format-v-c.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-char.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-double.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-int.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-ldouble.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-llong.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-long.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-s.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-short.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-uchar.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-uint.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-ullong.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-ulong.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v-ushort.c | 20 +++++++++++++++++ stdio-common/tst-printf-format-v.h | 34 +++++++++++++++++++++++++++++ 16 files changed, 315 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-vprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d f s sn +xprintf-funcs := p as d f s sn v # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-v-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-v-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-v-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-v-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-v-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-v-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-v-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-v-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-v-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-v-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-v-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-v-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-v-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-v-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-v.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-v.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-v.h @@ -0,0 +1,34 @@ +/* Test feature wrapper for formatted 'vprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include + +static int +printf_under_test (const char *restrict fmt, ...) +{ + va_list ap; + int result; + + va_start (ap, fmt); + result = vprintf (fmt, ap); + va_end (ap); + if (result < 0) + perror ("vprintf"); + return result; +} From patchwork Wed Oct 16 15:46:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99022 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FAB23857C6D for ; Wed, 16 Oct 2024 15:47:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id 1070A3858D37 for ; Wed, 16 Oct 2024 15:46:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1070A3858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1070A3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093569; cv=none; b=FaCE5peaMwzTw4Q7yIJJLSrrl9Z+czcEOOWHfyu5crIOsqsXNA/T1u9RDKcPuoZSfTomK12YVPK0gke83MuktM8pgHNpfohgtJN9H01EGFvw/KqcCcdhrVg6ojAmY2wZPr2z+avN34JA4Vnh0/wmOOr6Wgacs89VTSbLnElWZCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093569; c=relaxed/simple; bh=Q9P0n2hjXZKRR5iONl/cMLgUA9JxCyG5P4DMa31NMwc=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=RAKof/T7mIcXfRxKM3Itv8Q/ONLUqvoOrFJU4TnHniXjAN0VsyNhZwdYJ4DLuDQOvwv6P8vN8bLodoVpthT6Z/SyC0ux+tirG3gyhHtZb6XTTkXTnc7w7CJX5kmI8riV8H+ez6JhPGMtYnlaI2AAn9nUPTad5UOy3URUEUYACHE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 98ABE92009D; Wed, 16 Oct 2024 17:46:04 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 921A392009C; Wed, 16 Oct 2024 16:46:04 +0100 (BST) Date: Wed, 16 Oct 2024 16:46:04 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 08/12] stdio-common: Add tests for formatted vasprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.5 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire vasprintf into test infrastructure for formatted printf output specifiers. Owing to mtrace logging these tests take amounts of time to complete similar to those of corresponding asprintf tests, so set timeouts for the tests accordingly, with a global default for all the vasprintf tests, and then individual higher settings for double and long double tests each. --- New change in v2. --- stdio-common/Makefile | 2 - stdio-common/tst-printf-format-vas-c.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-char.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-double.c | 22 +++++++++++ stdio-common/tst-printf-format-vas-int.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-ldouble.c | 22 +++++++++++ stdio-common/tst-printf-format-vas-llong.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-long.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-s.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-short.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-uchar.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-uint.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-ullong.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-ulong.c | 20 ++++++++++ stdio-common/tst-printf-format-vas-ushort.c | 20 ++++++++++ stdio-common/tst-printf-format-vas.h | 50 +++++++++++++++++++++++++++ 16 files changed, 335 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-vasprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d f s sn v +xprintf-funcs := p as d f s sn v vas # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-vas-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-vas-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-vas-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-double.c @@ -0,0 +1,22 @@ +/* Test for formatted 'vasprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#define TIMEOUT (DEFAULT_TIMEOUT * 64) + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-vas-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-vas-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-ldouble.c @@ -0,0 +1,22 @@ +/* Test for formatted 'vasprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#define TIMEOUT (DEFAULT_TIMEOUT * 192) + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-vas-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-vas-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-vas-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-vas-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-vas-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-vas-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-vas-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-vas-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-vas-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vasprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vas.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-vas.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vas.h @@ -0,0 +1,50 @@ +/* Test feature wrapper for formatted 'vasprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include +#include + +static int +printf_under_test (const char *restrict fmt, ...) +{ + va_list ap; + int result; + char *str; + + va_start (ap, fmt); + result = vasprintf (&str, fmt, ap); + va_end (ap); + if (result < 0) + { + perror ("vasprintf"); + goto out; + } + if (fwrite (str, sizeof (*str), result, stdout) != result) + { + perror ("fwrite"); + result = -1; + } + free (str); +out: + return result; +} + +#ifndef TIMEOUT +# define TIMEOUT (DEFAULT_TIMEOUT * 24) +#endif From patchwork Wed Oct 16 15:46:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99030 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16555385802C for ; Wed, 16 Oct 2024 15:49:41 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id CE177385802C for ; Wed, 16 Oct 2024 15:46:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE177385802C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CE177385802C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093576; cv=none; b=A52Dkgn0mHUgnlmBrfn/ijIZ09GHDenEn6wfjwQau6Dslp9E5simVT45+vsDFGBsnTS3Sgp5vOikmmEpRJyD7Z9JuDRAmwzKSgcHhZdRYL1F5vaNsp0sQfshgbvpRS+81U7RLsJkXpW7j9Hc5VRryZTeQVFB4jx2lI2sYIPk1kA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093576; c=relaxed/simple; bh=extDugNUgRQyRygBdA4koQ13PeEXoh/jLRXJKsZMIWw=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=Vo7D9WhS1gqRySRii/qwsEGxHAnxio/JqtB3en2ZjO5YBCdDKEW3yvgW4YfsglmKPAG9/vmdR0G54qUR/CYhq7G1HfPez5pneFq258cwxSsXwgvqQJtqR5rGfqseSUyp2KulseDPKdCmKKc4sTlSVau+Tyi3Rv0ysz/uKLhQ12Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 56E8F92009C; Wed, 16 Oct 2024 17:46:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 540B592009B; Wed, 16 Oct 2024 16:46:10 +0100 (BST) Date: Wed, 16 Oct 2024 16:46:10 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 09/12] stdio-common: Add tests for formatted vdprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.7 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire vdprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 stdio-common/tst-printf-format-vd-c.c | 20 +++++++++ stdio-common/tst-printf-format-vd-char.c | 20 +++++++++ stdio-common/tst-printf-format-vd-double.c | 20 +++++++++ stdio-common/tst-printf-format-vd-int.c | 20 +++++++++ stdio-common/tst-printf-format-vd-ldouble.c | 20 +++++++++ stdio-common/tst-printf-format-vd-llong.c | 20 +++++++++ stdio-common/tst-printf-format-vd-long.c | 20 +++++++++ stdio-common/tst-printf-format-vd-s.c | 20 +++++++++ stdio-common/tst-printf-format-vd-short.c | 20 +++++++++ stdio-common/tst-printf-format-vd-uchar.c | 20 +++++++++ stdio-common/tst-printf-format-vd-uint.c | 20 +++++++++ stdio-common/tst-printf-format-vd-ullong.c | 20 +++++++++ stdio-common/tst-printf-format-vd-ulong.c | 20 +++++++++ stdio-common/tst-printf-format-vd-ushort.c | 20 +++++++++ stdio-common/tst-printf-format-vd.h | 62 ++++++++++++++++++++++++++++ 16 files changed, 343 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-vdprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d f s sn v vas +xprintf-funcs := p as d f s sn v vas vd # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-vd-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-vd-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-vd-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-vd-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-vd-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-vd-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-vd-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-vd-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-vd-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-vd-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-vd-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-vd-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-vd-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-vd-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vdprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vd.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-vd.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vd.h @@ -0,0 +1,62 @@ +/* Test feature wrapper for formatted 'vdprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include +#include +#include + +/* We need to go through the POSIX-mandated dance to switch between + handles on an open file description. */ + +static int +printf_under_test (const char *restrict fmt, ...) +{ + va_list ap; + int result; + + result = fflush (stdout); + if (result == EOF) + { + perror ("fflush"); + goto out; + } + result = lseek (STDOUT_FILENO, 0, SEEK_END); + if (result < 0 && errno == ESPIPE) + result = 0; + if (result < 0) + { + perror ("lseek"); + goto out; + } + va_start (ap, fmt); + result = vdprintf (STDOUT_FILENO, fmt, ap); + va_end (ap); + if (result < 0) + { + perror ("vdprintf"); + goto out; + } + result = fseek (stdout, 0, SEEK_END); + if (result < 0 && errno == ESPIPE) + result = 0; + if (result < 0) + perror ("fseek"); +out: + return result; +} From patchwork Wed Oct 16 15:46:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99027 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7A293857C6D for ; Wed, 16 Oct 2024 15:49:01 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 46FB5385842A for ; Wed, 16 Oct 2024 15:46:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46FB5385842A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 46FB5385842A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093581; cv=none; b=KTppCW0F7r1XTbLYYagwx1Rvk5SNoAnbakTEoG4PVKEmppXIcl/Jizccr6Aaqp2K5Lny4xOeXDjynT5APu4EXR5MUFpRfWii8UqndU/SZYuC4YmZ3wSGKiMDzKECJUswJEEJtgniOurznyrwDe0LGvttakZ6gTvyp3ADVkPLDIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093581; c=relaxed/simple; bh=hzVua6yLuKyUa1qNjOUbobJxN2kpDSKXGP9EjbdsFXU=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=Ckps5cTam51s05W9quhIRBoglgCAmTjPsYBiCX9hu+xFTo1UMgpEzMWdYulimUp/UMHy5RWBefmyriIHfeAyK1pCUF+Ui0tXQWTdLnWaHiCazhusVkQYoNAMZl40kXjZRSEI6hAXYK4bAz/4fSlDljeQmF6IOAuth6WtacZ1llc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id C20FE92009C; Wed, 16 Oct 2024 17:46:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id BBED692009B; Wed, 16 Oct 2024 16:46:16 +0100 (BST) Date: Wed, 16 Oct 2024 16:46:16 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 10/12] stdio-common: Add tests for formatted vfprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.7 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire vfprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 - stdio-common/tst-printf-format-vf-c.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-char.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-double.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-int.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-ldouble.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-llong.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-long.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-s.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-short.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-uchar.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-uint.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-ullong.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-ulong.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf-ushort.c | 20 ++++++++++++++++ stdio-common/tst-printf-format-vf.h | 34 ++++++++++++++++++++++++++++ 16 files changed, 315 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-vfprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d f s sn v vas vd +xprintf-funcs := p as d f s sn v vas vd vf # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-vf-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-vf-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-vf-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-vf-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-vf-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-vf-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-vf-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-vf-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-vf-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-vf-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-vf-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-vf-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-vf-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-vf-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vfprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vf.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-vf.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vf.h @@ -0,0 +1,34 @@ +/* Test feature wrapper for formatted 'vfprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include + +static int +printf_under_test (const char *restrict fmt, ...) +{ + va_list ap; + int result; + + va_start (ap, fmt); + result = vfprintf (stdout, fmt, ap); + va_end (ap); + if (result < 0) + perror ("vfprintf"); + return result; +} From patchwork Wed Oct 16 15:46:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99032 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DEC8F3858D33 for ; Wed, 16 Oct 2024 15:50:46 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 90C803858430 for ; Wed, 16 Oct 2024 15:46:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90C803858430 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 90C803858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093592; cv=none; b=RcrWAZZd+DmOKo8UsB+EYOeawui+zWweMzse6PnJHuVkqdn1R7tTp67jAVAFdBtk94DDCodJwx0Gps/YaVMwPAn1NOgUp/b2dEOXkuY2Ky8zUM+f1WqA+62qIfKS9H4C5NLcweFjeB58uIffsedSh7DKH+ky+0xX4lopMo285oA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093592; c=relaxed/simple; bh=MnoHorzLfMg9acCoc7Bx1KDj3tlTffCHC0ffL8r8oho=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=ULEOXFC8s7TLFj2xPIVA/zlezFSE2oNq9eFPUXzAIrcOXmnaXsa0fDt55D3zZRCrS9dJJy7FjtkQvqGDN2k7ru9gC7Ba8dkNIsnw0l8GlpONqYpwUzElU/lbkXkaMFFm8ZcVGe/BN1a6o4cAxXlQKtg5C62CsMyLgeuWalUd7Sw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 1F14A92009D; Wed, 16 Oct 2024 17:46:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 1925192009B; Wed, 16 Oct 2024 16:46:22 +0100 (BST) Date: Wed, 16 Oct 2024 16:46:22 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 11/12] stdio-common: Add tests for formatted vsprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.7 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire vsprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 stdio-common/tst-printf-format-vs-c.c | 20 ++++++++ stdio-common/tst-printf-format-vs-char.c | 20 ++++++++ stdio-common/tst-printf-format-vs-double.c | 20 ++++++++ stdio-common/tst-printf-format-vs-int.c | 20 ++++++++ stdio-common/tst-printf-format-vs-ldouble.c | 20 ++++++++ stdio-common/tst-printf-format-vs-llong.c | 20 ++++++++ stdio-common/tst-printf-format-vs-long.c | 20 ++++++++ stdio-common/tst-printf-format-vs-s.c | 20 ++++++++ stdio-common/tst-printf-format-vs-short.c | 20 ++++++++ stdio-common/tst-printf-format-vs-uchar.c | 20 ++++++++ stdio-common/tst-printf-format-vs-uint.c | 20 ++++++++ stdio-common/tst-printf-format-vs-ullong.c | 20 ++++++++ stdio-common/tst-printf-format-vs-ulong.c | 20 ++++++++ stdio-common/tst-printf-format-vs-ushort.c | 20 ++++++++ stdio-common/tst-printf-format-vs.h | 64 ++++++++++++++++++++++++++++ 16 files changed, 345 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-vsprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d f s sn v vas vd vf +xprintf-funcs := p as d f s sn v vas vd vf vs # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-vs-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-vs-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-vs-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-vs-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-vs-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-vs-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-vs-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-vs-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-vs-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-vs-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-vs-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-vs-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-vs-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-vs-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vs.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-vs.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vs.h @@ -0,0 +1,64 @@ +/* Test feature wrapper for formatted 'vsprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include +#include + +#include + +#define SPRINTF_BUFFER_SIZE 65536 + +static struct support_next_to_fault ntf; + +#define PREPARE printf_under_test_init +static void +printf_under_test_init (int argc, char **argv) +{ + ntf = support_next_to_fault_allocate (SPRINTF_BUFFER_SIZE); +} + +static void __attribute__ ((destructor)) +printf_under_test_fini (void) +{ + support_next_to_fault_free (&ntf); +} + +static int +printf_under_test (const char *restrict fmt, ...) +{ + char *str = ntf.buffer; + va_list ap; + int result; + + va_start (ap, fmt); + result = vsprintf (str, fmt, ap); + va_end (ap); + if (result < 0) + { + perror ("vsprintf"); + goto out; + } + if (fwrite (str, sizeof (*str), result, stdout) != result) + { + perror ("fwrite"); + result = -1; + } +out: + return result; +} From patchwork Wed Oct 16 15:46:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 99031 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53DC33858420 for ; Wed, 16 Oct 2024 15:50:03 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id E0CCA3857C58 for ; Wed, 16 Oct 2024 15:46:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0CCA3857C58 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E0CCA3857C58 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093591; cv=none; b=fUfkHrIsBb6z7VirYa8QTEkQp85ZUcUdxgs2RIXjTR274uQoOyIX/r67+XNCnqQsT+5AyMLT4uJyK6QWTp/D46hfgU3xDwHe1pUNg3YJCAS/0SDuWBMqqKU1G0by7SSegivLZyvTB3db3fKOroKkAZeJu/elAD+/jX5jYQC533k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729093591; c=relaxed/simple; bh=YMRAfoAeqGYm7sDeUGZHwYQcOMkAHYZLrr/r0TQemaE=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=Ey0QqxEzbkEYueShmGoNYKSQAvfgdLPv+lPUQeuDgj6bQXB1tbBCVynvwFCEQVPa+v68dVisUAJ1E+sbWadLJJv1G4CwgLVgcF89ZCkY+yPLrWsqFwhgJhqDcGwfqo75cwUd3fQUTzWwa+HtZw7o5RX5VnqgSMi5K6RkiPrpXgk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 6DBDC92009C; Wed, 16 Oct 2024 17:46:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 5FC4292009B; Wed, 16 Oct 2024 16:46:27 +0100 (BST) Date: Wed, 16 Oct 2024 16:46:27 +0100 (BST) From: "Maciej W. Rozycki" To: libc-alpha@sourceware.org cc: "Maciej W. Rozycki" Subject: [PATCH v3 12/12] stdio-common: Add tests for formatted vsnprintf output specifiers In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3487.7 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: "Maciej W. Rozycki" Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Wire vsnprintf into test infrastructure for formatted printf output specifiers. --- New change in v2. --- stdio-common/Makefile | 2 stdio-common/tst-printf-format-vsn-c.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-char.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-double.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-int.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-ldouble.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-llong.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-long.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-s.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-short.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-uchar.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-uint.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-ullong.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-ulong.c | 20 ++++++++ stdio-common/tst-printf-format-vsn-ushort.c | 20 ++++++++ stdio-common/tst-printf-format-vsn.h | 64 +++++++++++++++++++++++++++ 16 files changed, 345 insertions(+), 1 deletion(-) glibc-tst-printf-format-all-vsnprintf.diff Index: glibc/stdio-common/Makefile =================================================================== --- glibc.orig/stdio-common/Makefile +++ glibc/stdio-common/Makefile @@ -23,7 +23,7 @@ subdir := stdio-common include ../Makeconfig # List of markers for printf family function tests. -xprintf-funcs := p as d f s sn v vas vd vf vs +xprintf-funcs := p as d f s sn v vas vd vf vs vsn # List of data types and formats for individual per-conversion printf tests. fmt-convs := double ldouble Index: glibc/stdio-common/tst-printf-format-vsn-c.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-c.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for the 'c' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-c.c" Index: glibc/stdio-common/tst-printf-format-vsn-char.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-char.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for signed char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-char.c" Index: glibc/stdio-common/tst-printf-format-vsn-double.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-double.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-double.c" Index: glibc/stdio-common/tst-printf-format-vsn-int.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-int.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-int.c" Index: glibc/stdio-common/tst-printf-format-vsn-ldouble.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-ldouble.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for long double conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-ldouble.c" Index: glibc/stdio-common/tst-printf-format-vsn-llong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-llong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-llong.c" Index: glibc/stdio-common/tst-printf-format-vsn-long.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-long.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-long.c" Index: glibc/stdio-common/tst-printf-format-vsn-s.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-s.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for the 's' conversion. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-s.c" Index: glibc/stdio-common/tst-printf-format-vsn-short.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-short.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-short.c" Index: glibc/stdio-common/tst-printf-format-vsn-uchar.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-uchar.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for unsigned char conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-uchar.c" Index: glibc/stdio-common/tst-printf-format-vsn-uint.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-uint.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for unsigned int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-uint.c" Index: glibc/stdio-common/tst-printf-format-vsn-ullong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-ullong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for unsigned long long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-ullong.c" Index: glibc/stdio-common/tst-printf-format-vsn-ulong.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-ulong.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for unsigned long int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-ulong.c" Index: glibc/stdio-common/tst-printf-format-vsn-ushort.c =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn-ushort.c @@ -0,0 +1,20 @@ +/* Test for formatted 'vsnprintf' output for unsigned short int conversions. + Copyright (C) 2024 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 + . */ + +#include "tst-printf-format-vsn.h" +#include "tst-printf-format-skeleton-ushort.c" Index: glibc/stdio-common/tst-printf-format-vsn.h =================================================================== --- /dev/null +++ glibc/stdio-common/tst-printf-format-vsn.h @@ -0,0 +1,64 @@ +/* Test feature wrapper for formatted 'vsnprintf' output. + Copyright (C) 2024 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 + . */ + +#include +#include +#include + +#include + +#define SPRINTF_BUFFER_SIZE 65536 + +static struct support_next_to_fault ntf; + +#define PREPARE printf_under_test_init +static void +printf_under_test_init (int argc, char **argv) +{ + ntf = support_next_to_fault_allocate (SPRINTF_BUFFER_SIZE); +} + +static void __attribute__ ((destructor)) +printf_under_test_fini (void) +{ + support_next_to_fault_free (&ntf); +} + +static int +printf_under_test (const char *restrict fmt, ...) +{ + char *str = ntf.buffer; + va_list ap; + int result; + + va_start (ap, fmt); + result = vsnprintf (str, ntf.length, fmt, ap); + va_end (ap); + if (result < 0) + { + perror ("vsnprintf"); + goto out; + } + if (fwrite (str, sizeof (*str), result, stdout) != result) + { + perror ("fwrite"); + result = -1; + } +out: + return result; +}