From patchwork Fri Aug 10 22:00:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel F. T. Gomes" X-Patchwork-Id: 28848 Received: (qmail 95331 invoked by alias); 10 Aug 2018 22:01:09 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 94938 invoked by uid 89); 10 Aug 2018 22:00:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=H*r:Sat X-HELO: mo19.mail-out.ovh.net From: "Gabriel F. T. Gomes" To: Subject: [PATCH 2/3] Add test for warn, warnx, vwarn, and vwarnx with floating-point parameters Date: Fri, 10 Aug 2018 19:00:10 -0300 Message-ID: <20180810220011.8432-3-gabriel@inconstante.eti.br> In-Reply-To: <20180810220011.8432-1-gabriel@inconstante.eti.br> References: <20180810220011.8432-1-gabriel@inconstante.eti.br> MIME-Version: 1.0 X-Ovh-Tracer-Id: 791507634555178691 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtjedrtdejgddthecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu Similarly to what has been done for argp_error and argp_failure, this patch patch adds new tests for the warn, warnx, vwarn, and vwarnx functions. The new tests use the format string to request the conversion of long double parameters into string. Currently, these tests only check that the default format of the long double type works. Future patches will extend the test for platforms that can have an optional format for long double. Tested for powerpc64le. * misc/Makefile (tests-internal): Add tst-ldbl-warn. [run-built-tests == yes] (test-special): Add $(objpfx)tst-ldbl-warn.out. ($(objpfx)tst-ldbl-warn.out): New build and run rule. * misc/tst-ldbl-warn.c: New file. * misc/tst-ldbl-warn.sh: Likewise. --- misc/Makefile | 9 ++++++++ misc/tst-ldbl-warn.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ misc/tst-ldbl-warn.sh | 48 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 misc/tst-ldbl-warn.c create mode 100644 misc/tst-ldbl-warn.sh diff --git a/misc/Makefile b/misc/Makefile index b7be2bc19a..eb77b87b0d 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -89,11 +89,20 @@ tests := tst-dirname tst-tsearch tst-fdset tst-efgcvt tst-mntent tst-hsearch \ tests-internal := tst-atomic tst-atomic-long tst-allocate_once tests-static := tst-empty +tests-internal += tst-ldbl-warn + ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-error1-mem.out \ $(objpfx)tst-allocate_once-mem.out + +tests-special += $(objpfx)tst-ldbl-warn.out endif +$(objpfx)tst-ldbl-warn.out: \ + tst-ldbl-warn.sh $(objpfx)tst-ldbl-warn + $(SHELL) $^ '$(test-program-prefix)' $@; \ + $(evaluate-test) + CFLAGS-select.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-tsearch.c += $(uses-callbacks) CFLAGS-lsearch.c += $(uses-callbacks) diff --git a/misc/tst-ldbl-warn.c b/misc/tst-ldbl-warn.c new file mode 100644 index 0000000000..db771b5c59 --- /dev/null +++ b/misc/tst-ldbl-warn.c @@ -0,0 +1,61 @@ +/* Test for the long double conversions in *warn* functions. + Copyright (C) 2018 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 void +do_test_call_varg (const char *format, ...) +{ + va_list args; + + va_start (args, format); + vwarn (format, args); + va_end (args); + + va_start (args, format); + vwarnx (format, args); + va_end (args); +} + +static void +do_test_call_rarg (const char *format, long double ld1, double d1, + long double ld2, double d2) +{ + warn (format, ld1, d1, ld2, d2); + warnx (format, ld1, d1, ld2, d2); +} + +static int +do_test (void) +{ + double d1 = -2; + double d2 = -4; + long double ld1 = -1; + long double ld2 = -3; + + /* Print in decimal notation. */ + do_test_call_rarg ("%Lf - %f - %Lf - %f", ld1, d1, ld2, d2); + do_test_call_varg ("%Lf - %f - %Lf - %f", ld1, d1, ld2, d2); + + return 0; +} + +#include diff --git a/misc/tst-ldbl-warn.sh b/misc/tst-ldbl-warn.sh new file mode 100644 index 0000000000..5827be9dbe --- /dev/null +++ b/misc/tst-ldbl-warn.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Test for the long double conversions in *warn* functions. +# Copyright (C) 2018 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 + +test_program=$1; shift +test_program_prefix=$1; shift +test_program_output=$1; shift + +status=0 + +${test_program_prefix} \ + ${test_program} \ + 2> ${test_program_output} || status=1 + +# Remove the program name from the output, because checking the program +# name is out of the scope of this test case. +sed -i "s/.*tst-[^:]*: //" ${test_program_output} + +cat <<'EOF' | +-1.000000 - -2.000000 - -3.000000 - -4.000000: Success +-1.000000 - -2.000000 - -3.000000 - -4.000000 +-1.000000 - -2.000000 - -3.000000 - -4.000000: Success +-1.000000 - -2.000000 - -3.000000 - -4.000000 +EOF +cmp - ${test_program_output} > /dev/null 2>&1 || +{ + status=1 + echo "*** output comparison failed" +} + +exit $status