From patchwork Wed Aug 15 20:16:27 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: 28930 Received: (qmail 20177 invoked by alias); 15 Aug 2018 20:16:48 -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 20040 invoked by uid 89); 15 Aug 2018 20:16:47 -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=sk:100000, Precision X-HELO: mo20.mail-out.ovh.net From: "Gabriel F. T. Gomes" To: Subject: [PATCH v2 1/3] Add tests for argp_error and argp_failure with floating-point parameters Date: Wed, 15 Aug 2018 17:16:27 -0300 Message-ID: <20180815201629.20657-2-gabriel@inconstante.eti.br> In-Reply-To: <20180815201629.20657-1-gabriel@inconstante.eti.br> References: <20180815201629.20657-1-gabriel@inconstante.eti.br> MIME-Version: 1.0 X-Ovh-Tracer-Id: 9955769927865388739 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtjedrudejgdduheegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenuc The functions argp_error and argp_failure, from argp.h, have a format string as parameter, which can possibly request the printing of floating-point values. These values could be of long double type, which can have different formats, depending on the architecture and on compilation parameters (for instance, on powerpc, long double values can have double format (-mlong-double-64) or IBM Extended Precision format (-mlong-double-128). This patch adds tests for argp_error and argp_failure that contain a format string with double and long double conversion specifiers ('%f' and '%Lf'). These tests automatically check that the default format of the long double type works. A future patch will extend the test for platforms that can have an optional format for long double. Tested for powerpc64le. * argp/Makefile: (tests-internal): Add tst-ldbl-argp-error and tst-ldbl-argp-failure. [run-built-tests == yes] (tests-special): Add $(objpfx)tst-ldbl-argp-error.out and $(objpfx)tst-ldbl-argp-failure.out. ($(objpfx)tst-ldbl-argp-error.out) ($(objpfx)tst-ldbl-argp-failure.out): New build and run rule. * argp/tst-ldbl-argp-error.c: New file. * argp/tst-ldbl-argp-error.sh: Likewise. * argp/tst-ldbl-argp-failure.c: Likewise. * argp/tst-ldbl-argp-failure.sh: Likewise. * argp/tst-ldbl-argp-template.c: Likewise. --- argp/Makefile | 12 ++++++++ argp/tst-ldbl-argp-error.c | 3 ++ argp/tst-ldbl-argp-error.sh | 46 +++++++++++++++++++++++++++++ argp/tst-ldbl-argp-failure.c | 3 ++ argp/tst-ldbl-argp-failure.sh | 45 ++++++++++++++++++++++++++++ argp/tst-ldbl-argp-template.c | 69 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 178 insertions(+) create mode 100644 argp/tst-ldbl-argp-error.c create mode 100644 argp/tst-ldbl-argp-error.sh create mode 100644 argp/tst-ldbl-argp-failure.c create mode 100644 argp/tst-ldbl-argp-failure.sh create mode 100644 argp/tst-ldbl-argp-template.c diff --git a/argp/Makefile b/argp/Makefile index 6e4799c220..8ca95c70a0 100644 --- a/argp/Makefile +++ b/argp/Makefile @@ -35,4 +35,16 @@ CFLAGS-argp-fmtstream.c += -fexceptions bug-argp1-ARGS = -- --help bug-argp2-ARGS = -- -d 111 --dstaddr 222 -p 333 --peer 444 +tests-internal += tst-ldbl-argp-error tst-ldbl-argp-failure + +ifeq ($(run-built-tests),yes) +tests-special += $(objpfx)tst-ldbl-argp-error.out +tests-special += $(objpfx)tst-ldbl-argp-failure.out +endif + +$(objpfx)tst-ldbl-argp-%.out: \ + tst-ldbl-argp-%.sh $(objpfx)tst-ldbl-argp-% + $(SHELL) $^ '$(test-program-prefix)' $@; \ + $(evaluate-test) + include ../Rules diff --git a/argp/tst-ldbl-argp-error.c b/argp/tst-ldbl-argp-error.c new file mode 100644 index 0000000000..8b24bd984d --- /dev/null +++ b/argp/tst-ldbl-argp-error.c @@ -0,0 +1,3 @@ +#define ARGP_FUNCTION argp_error +#define ARGP_FUNCTION_PARAMS (state, "%Lf%f%Lf%f", (long double) -1, (double) -2, (long double) -3, (double) -4) +#include diff --git a/argp/tst-ldbl-argp-error.sh b/argp/tst-ldbl-argp-error.sh new file mode 100644 index 0000000000..49a3c62ce9 --- /dev/null +++ b/argp/tst-ldbl-argp-error.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Testing of long double conversions in argp_error. +# 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 + +# Allow argp_error to end with non-zero exit status, run the test +# program, then restore the exit-on-error behavior +set +e +${test_program_prefix} \ + ${test_program} \ + 2> ${test_program_output} +set -e + +cat <<'EOF' | +test-argp: -1.000000-2.000000-3.000000-4.000000 +Try `test-argp --help' or `test-argp --usage' for more information. +EOF +cmp - ${test_program_output} > /dev/null 2>&1 || +{ + status=1 + echo "*** output comparison failed" +} + +exit $status diff --git a/argp/tst-ldbl-argp-failure.c b/argp/tst-ldbl-argp-failure.c new file mode 100644 index 0000000000..92a82ceadb --- /dev/null +++ b/argp/tst-ldbl-argp-failure.c @@ -0,0 +1,3 @@ +#define ARGP_FUNCTION argp_failure +#define ARGP_FUNCTION_PARAMS (state, 0, 0, "%Lf%f%Lf%f", (long double) -1, (double) -2, (long double) -3, (double) -4) +#include diff --git a/argp/tst-ldbl-argp-failure.sh b/argp/tst-ldbl-argp-failure.sh new file mode 100644 index 0000000000..f3f251702a --- /dev/null +++ b/argp/tst-ldbl-argp-failure.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# Testing of long double conversions in argp_failure. +# 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 + +# Allow argp_failure to end with non-zero exit status, run the test +# program, then restore the exit-on-error behavior +set +e +${test_program_prefix} \ + ${test_program} \ + 2> ${test_program_output} +set -e + +cat <<'EOF' | +test-argp: -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 diff --git a/argp/tst-ldbl-argp-template.c b/argp/tst-ldbl-argp-template.c new file mode 100644 index 0000000000..f52cd352e5 --- /dev/null +++ b/argp/tst-ldbl-argp-template.c @@ -0,0 +1,69 @@ +/* Testing of long double conversions in argp.h 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 const struct argp_option +options[] = +{ + { "test", 't', "format", 0, "Run argp function with a format string", 0 }, + { NULL, 0, NULL, 0, NULL } +}; + +static error_t +parser (int key, char *arg, struct argp_state *state) +{ + switch (key) + { + case 't': + ARGP_FUNCTION ARGP_FUNCTION_PARAMS; + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp +argp = +{ + options, parser +}; + +static int +do_test (void) +{ + int remaining; + int argc = 3; + char *argv[4] = + { + (char *) "test-argp", + (char *) "--test", + (char *) "%Lf - %f - %Lf - %f", + NULL + }; + + argp_parse (&argp, argc, argv, 0, &remaining, NULL); + + return 0; +} + +#include