This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/3] Add tests for argp_error and argp_failure with floating-point parameters


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 <tst-ldbl-argp-template.c>
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
+# <http://www.gnu.org/licenses/>.
+
+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 <tst-ldbl-argp-template.c>
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
+# <http://www.gnu.org/licenses/>.
+
+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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <argp.h>
+#include <string.h>
+
+#include <support/check.h>
+
+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 <support/test-driver.c>
-- 
2.14.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]