public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 2/3] Add test for warn, warnx, vwarn, and vwarnx with floating-point parameters
  2018-08-15 20:16 [PATCH v2 0/3] Tests for argp/err/error functions with long double Gabriel F. T. Gomes
  2018-08-15 20:16 ` [PATCH v2 3/3] Add tests with floating-point arguments for err* and verr* functions Gabriel F. T. Gomes
  2018-08-15 20:16 ` [PATCH v2 1/3] Add tests for argp_error and argp_failure with floating-point parameters Gabriel F. T. Gomes
@ 2018-08-15 20:16 ` Gabriel F. T. Gomes
  2018-08-16  9:26   ` Florian Weimer
  2 siblings, 1 reply; 6+ messages in thread
From: Gabriel F. T. Gomes @ 2018-08-15 20:16 UTC (permalink / raw)
  To: libc-alpha

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.
	* misc/tst-ldbl-warn.c: New file.
---
 misc/Makefile        |   2 +
 misc/tst-ldbl-warn.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 misc/tst-ldbl-warn.c

diff --git a/misc/Makefile b/misc/Makefile
index 9a87e81ae5..c15707878f 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -89,6 +89,8 @@ 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
diff --git a/misc/tst-ldbl-warn.c b/misc/tst-ldbl-warn.c
new file mode 100644
index 0000000000..a9406404bf
--- /dev/null
+++ b/misc/tst-ldbl-warn.c
@@ -0,0 +1,115 @@
+/* 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <err.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <support/check.h>
+
+enum {WARN, WARNX, VWARN, VWARNX};
+
+static void
+do_one_test (int select, const char *format, va_list args,
+	     long double arg1, double arg2, long double arg3,
+	     double arg4, const char *expected)
+{
+  /* Prepare in-memory buffer to hold the output.  */
+  char *buffer = NULL;
+  size_t length = 0;
+  FILE *fp = open_memstream (&buffer, &length);
+  TEST_VERIFY_EXIT (fp != NULL);
+  FILE *old_stderr = stderr;
+  stderr = fp;
+
+  /* Write to the buffer using one of the *warn* functions.  */
+  switch (select)
+    {
+      case WARN:
+	warn (format, arg1, arg2, arg3, arg4);
+	break;
+      case WARNX:
+	warnx (format, arg1, arg2, arg3, arg4);
+	break;
+      case VWARN:
+	vwarn (format, args);
+	break;
+      case VWARNX:
+	vwarnx (format, args);
+	break;
+    }
+
+  stderr = old_stderr;
+  TEST_VERIFY_EXIT (!ferror (fp));
+  TEST_COMPARE (fclose (fp), 0);
+
+  /* Check that the rest of the output is as expected.  */
+  if (strcmp (buffer, expected) != 0)
+    FAIL_EXIT1 ("unexpected output: %s", buffer);
+  free (buffer);
+}
+
+static void
+do_test_call_varg (const char *format, ...)
+{
+  va_list args;
+
+  va_start (args, format);
+  do_one_test (VWARN, format, args, 0, 0, 0, 0,
+	       "tst-ldbl-warn: "
+	       "-1.000000 - -2.000000 - -3.000000 - -4.000000: Success\n");
+  va_end (args);
+
+  va_start (args, format);
+  do_one_test (VWARNX, format, args, 0, 0, 0, 0,
+	       "tst-ldbl-warn: "
+	       "-1.000000 - -2.000000 - -3.000000 - -4.000000\n");
+  va_end (args);
+}
+
+static void
+do_test_call_rarg (const char *format, long double arg1, double arg2,
+		   long double arg3, double arg4)
+{
+  va_list args;
+  memset (&args, 0, sizeof (args));
+  do_one_test (WARN, format, args, arg1, arg2, arg3, arg4,
+	       "tst-ldbl-warn: "
+	       "-1.000000 - -2.000000 - -3.000000 - -4.000000: Success\n");
+  do_one_test (WARNX, format, args, arg1, arg2, arg3, arg4,
+	       "tst-ldbl-warn: "
+	       "-1.000000 - -2.000000 - -3.000000 - -4.000000\n");
+}
+
+static int
+do_test (void)
+{
+  long double arg1 = -1;
+  long double arg3 = -3;
+  double arg2 = -2;
+  double arg4 = -4;
+
+  do_test_call_rarg ("%Lf - %f - %Lf - %f", arg1, arg2, arg3, arg4);
+  do_test_call_varg ("%Lf - %f - %Lf - %f", arg1, arg2, arg3, arg4);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.14.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 0/3] Tests for argp/err/error functions with long double
@ 2018-08-15 20:16 Gabriel F. T. Gomes
  2018-08-15 20:16 ` [PATCH v2 3/3] Add tests with floating-point arguments for err* and verr* functions Gabriel F. T. Gomes
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Gabriel F. T. Gomes @ 2018-08-15 20:16 UTC (permalink / raw)
  To: libc-alpha

Changes since v1:

  - Removed tst-ldbl-warn.sh from patch 2/3 and replaced it with an
    in-memory buffer, as suggested by Florian.
  - No changes to patches 1/3, and 3/3.

Gabriel F. T. Gomes (3):
  Add tests for argp_error and argp_failure with floating-point
    parameters
  Add test for warn, warnx, vwarn, and vwarnx with floating-point
    parameters
  Add tests with floating-point arguments for err* and verr* functions

 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 ++++++++++++++++++++++
 misc/Makefile                       |  20 +++++++
 misc/tst-ldbl-error-err.c           |   3 +
 misc/tst-ldbl-error-error.c         |   3 +
 misc/tst-ldbl-error-error_at_line.c |   3 +
 misc/tst-ldbl-error-errx.c          |   3 +
 misc/tst-ldbl-error-template.c      |  45 ++++++++++++++
 misc/tst-ldbl-error-verr.c          |   3 +
 misc/tst-ldbl-error-verrx.c         |   3 +
 misc/tst-ldbl-error.sh              |  55 +++++++++++++++++
 misc/tst-ldbl-warn.c                | 114 ++++++++++++++++++++++++++++++++++++
 16 files changed, 430 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
 create mode 100644 misc/tst-ldbl-error-err.c
 create mode 100644 misc/tst-ldbl-error-error.c
 create mode 100644 misc/tst-ldbl-error-error_at_line.c
 create mode 100644 misc/tst-ldbl-error-errx.c
 create mode 100644 misc/tst-ldbl-error-template.c
 create mode 100644 misc/tst-ldbl-error-verr.c
 create mode 100644 misc/tst-ldbl-error-verrx.c
 create mode 100644 misc/tst-ldbl-error.sh
 create mode 100644 misc/tst-ldbl-warn.c

-- 
2.14.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] Add tests with floating-point arguments for err* and verr* functions
  2018-08-15 20:16 [PATCH v2 0/3] Tests for argp/err/error functions with long double Gabriel F. T. Gomes
@ 2018-08-15 20:16 ` Gabriel F. T. Gomes
  2018-08-16  9:28   ` Florian Weimer
  2018-08-15 20:16 ` [PATCH v2 1/3] Add tests for argp_error and argp_failure with floating-point parameters Gabriel F. T. Gomes
  2018-08-15 20:16 ` [PATCH v2 2/3] Add test for warn, warnx, vwarn, and vwarnx " Gabriel F. T. Gomes
  2 siblings, 1 reply; 6+ messages in thread
From: Gabriel F. T. Gomes @ 2018-08-15 20:16 UTC (permalink / raw)
  To: libc-alpha

Similarly to what has been done for argp_error, and argp_failure, as
well as for warn, warnx, vwarn, and vwarnx, this patch adds new tests
for the following functions: err, errx, verr, verrx, error, and
error_at_line.  The new tests check that the conversion of long double
variables into string works correctly on the default format of the type.
Future patches will reuse these tests for other formats that long double
can take.  Since the functions do not return, each of them has its own
test case file.

Tested for powerpc64le.

	* misc/Makefile (tests-internal): Add tst-ldbl-error-err
	tst-ldbl-error-errx, tst-ldbl-error-verr, tst-ldbl-error-verrx,
	tst-ldbl-error-error, and tst-ldbl-error-error_at_line.
	[run-built-tests == yes] (tests-special): Add
	$(objpfx)tst-ldbl-warn.out, $(objpfx)tst-ldbl-error-err.out,
	$(objpfx)tst-ldbl-error-errx.out,
	$(objpfx)tst-ldbl-error-verr.out,
	$(objpfx)tst-ldbl-error-verrx.out,
	$(objpfx)tst-ldbl-error-error.out, and
	$(objpfx)tst-ldbl-error-error_at_line.out.
	($(objpfx)tst-ldbl-error-%.out): New build and run rule.
	* misc/tst-ldbl-error-err.c: New file.
	* misc/tst-ldbl-error-error.c: Likewise.
	* misc/tst-ldbl-error-error_at_line.c: Likewise.
	* misc/tst-ldbl-error-errx.c: Likewise.
	* misc/tst-ldbl-error-template.c: Likewise.
	* misc/tst-ldbl-error-verr.c: Likewise.
	* misc/tst-ldbl-error-verrx.c: Likewise.
	* misc/tst-ldbl-error.sh: Likewise.
---
 misc/Makefile                       | 18 ++++++++++++
 misc/tst-ldbl-error-err.c           |  3 ++
 misc/tst-ldbl-error-error.c         |  3 ++
 misc/tst-ldbl-error-error_at_line.c |  3 ++
 misc/tst-ldbl-error-errx.c          |  3 ++
 misc/tst-ldbl-error-template.c      | 45 ++++++++++++++++++++++++++++++
 misc/tst-ldbl-error-verr.c          |  3 ++
 misc/tst-ldbl-error-verrx.c         |  3 ++
 misc/tst-ldbl-error.sh              | 55 +++++++++++++++++++++++++++++++++++++
 9 files changed, 136 insertions(+)
 create mode 100644 misc/tst-ldbl-error-err.c
 create mode 100644 misc/tst-ldbl-error-error.c
 create mode 100644 misc/tst-ldbl-error-error_at_line.c
 create mode 100644 misc/tst-ldbl-error-errx.c
 create mode 100644 misc/tst-ldbl-error-template.c
 create mode 100644 misc/tst-ldbl-error-verr.c
 create mode 100644 misc/tst-ldbl-error-verrx.c
 create mode 100644 misc/tst-ldbl-error.sh

diff --git a/misc/Makefile b/misc/Makefile
index c15707878f..c0000ef1d3 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -90,12 +90,30 @@ tests-internal := tst-atomic tst-atomic-long tst-allocate_once
 tests-static := tst-empty
 
 tests-internal += tst-ldbl-warn
+tests-internal += tst-ldbl-error-err
+tests-internal += tst-ldbl-error-errx
+tests-internal += tst-ldbl-error-verr
+tests-internal += tst-ldbl-error-verrx
+tests-internal += tst-ldbl-error-error
+tests-internal += tst-ldbl-error-error_at_line
 
 ifeq ($(run-built-tests),yes)
 tests-special += $(objpfx)tst-error1-mem.out \
   $(objpfx)tst-allocate_once-mem.out
+
+tests-special += $(objpfx)tst-ldbl-error-err.out
+tests-special += $(objpfx)tst-ldbl-error-errx.out
+tests-special += $(objpfx)tst-ldbl-error-verr.out
+tests-special += $(objpfx)tst-ldbl-error-verrx.out
+tests-special += $(objpfx)tst-ldbl-error-error.out
+tests-special += $(objpfx)tst-ldbl-error-error_at_line.out
 endif
 
+$(objpfx)tst-ldbl-error-%.out: \
+  tst-ldbl-error.sh $(objpfx)tst-ldbl-error-%
+	$(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-error-err.c b/misc/tst-ldbl-error-err.c
new file mode 100644
index 0000000000..9a57b13025
--- /dev/null
+++ b/misc/tst-ldbl-error-err.c
@@ -0,0 +1,3 @@
+#define ERROR_FUNCTION		err
+#define ERROR_FUNCTION_PARAMS	(0, format, ld)
+#include <tst-ldbl-error-template.c>
diff --git a/misc/tst-ldbl-error-error.c b/misc/tst-ldbl-error-error.c
new file mode 100644
index 0000000000..be06513c0b
--- /dev/null
+++ b/misc/tst-ldbl-error-error.c
@@ -0,0 +1,3 @@
+#define ERROR_FUNCTION		error
+#define ERROR_FUNCTION_PARAMS	(0, 0, format, ld)
+#include <tst-ldbl-error-template.c>
diff --git a/misc/tst-ldbl-error-error_at_line.c b/misc/tst-ldbl-error-error_at_line.c
new file mode 100644
index 0000000000..ca4cea13ae
--- /dev/null
+++ b/misc/tst-ldbl-error-error_at_line.c
@@ -0,0 +1,3 @@
+#define ERROR_FUNCTION		error_at_line
+#define ERROR_FUNCTION_PARAMS	(0, 0, "", 1234, format, ld)
+#include <tst-ldbl-error-template.c>
diff --git a/misc/tst-ldbl-error-errx.c b/misc/tst-ldbl-error-errx.c
new file mode 100644
index 0000000000..bf3e6ac64e
--- /dev/null
+++ b/misc/tst-ldbl-error-errx.c
@@ -0,0 +1,3 @@
+#define ERROR_FUNCTION		errx
+#define ERROR_FUNCTION_PARAMS	(0, format, ld)
+#include <tst-ldbl-error-template.c>
diff --git a/misc/tst-ldbl-error-template.c b/misc/tst-ldbl-error-template.c
new file mode 100644
index 0000000000..24fd580d4c
--- /dev/null
+++ b/misc/tst-ldbl-error-template.c
@@ -0,0 +1,45 @@
+/* Test for the long double conversions in *err* 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 <err.h>
+#include <error.h>
+#include <stdarg.h>
+
+#include <support/check.h>
+
+static void
+do_test_call (long double ld, const char *format, ...)
+{
+  va_list args;
+
+  va_start (args, format);
+  ERROR_FUNCTION ERROR_FUNCTION_PARAMS;
+  va_end (args);
+}
+
+static int
+do_test (void)
+{
+  long double ld = -1;
+
+  do_test_call (ld, "%.60Lf", ld);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/misc/tst-ldbl-error-verr.c b/misc/tst-ldbl-error-verr.c
new file mode 100644
index 0000000000..9ac51f1c34
--- /dev/null
+++ b/misc/tst-ldbl-error-verr.c
@@ -0,0 +1,3 @@
+#define ERROR_FUNCTION		verr
+#define ERROR_FUNCTION_PARAMS	(0, format, args)
+#include <tst-ldbl-error-template.c>
diff --git a/misc/tst-ldbl-error-verrx.c b/misc/tst-ldbl-error-verrx.c
new file mode 100644
index 0000000000..995f4a26b1
--- /dev/null
+++ b/misc/tst-ldbl-error-verrx.c
@@ -0,0 +1,3 @@
+#define ERROR_FUNCTION		verrx
+#define ERROR_FUNCTION_PARAMS	(0, format, args)
+#include <tst-ldbl-error-template.c>
diff --git a/misc/tst-ldbl-error.sh b/misc/tst-ldbl-error.sh
new file mode 100644
index 0000000000..cec3f53a63
--- /dev/null
+++ b/misc/tst-ldbl-error.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# Test for the long double conversions in *err* 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/>.
+
+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
+
+# This script is shared among different test cases that have different
+# names and print different messages, however, the goal of the tests is
+# to detect if floating-point conversions worked, not if the messages
+# and filenames are correct, thus:
+#
+# Remove the trailing messages, if any.
+sed -i ${test_program_output} -e "s/: Success//"
+#
+# Remove the program name.
+sed -i ${test_program_output} -e "s/.*tst-[^:]*: //"
+#
+# Remove the line number annotation (error_at_line).
+sed -i ${test_program_output} -e "s/.*1234: //"
+
+cat <<'EOF' |
+-1.000000000000000000000000000000000000000000000000000000000000
+EOF
+cmp - ${test_program_output} > /dev/null 2>&1 ||
+{
+  status=1
+  echo "*** output comparison failed"
+}
+
+exit $status
-- 
2.14.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] Add tests for argp_error and argp_failure with floating-point parameters
  2018-08-15 20:16 [PATCH v2 0/3] Tests for argp/err/error functions with long double Gabriel F. T. Gomes
  2018-08-15 20:16 ` [PATCH v2 3/3] Add tests with floating-point arguments for err* and verr* functions Gabriel F. T. Gomes
@ 2018-08-15 20:16 ` Gabriel F. T. Gomes
  2018-08-15 20:16 ` [PATCH v2 2/3] Add test for warn, warnx, vwarn, and vwarnx " Gabriel F. T. Gomes
  2 siblings, 0 replies; 6+ messages in thread
From: Gabriel F. T. Gomes @ 2018-08-15 20:16 UTC (permalink / raw)
  To: libc-alpha

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/3] Add test for warn, warnx, vwarn, and vwarnx with floating-point parameters
  2018-08-15 20:16 ` [PATCH v2 2/3] Add test for warn, warnx, vwarn, and vwarnx " Gabriel F. T. Gomes
@ 2018-08-16  9:26   ` Florian Weimer
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Weimer @ 2018-08-16  9:26 UTC (permalink / raw)
  To: Gabriel F. T. Gomes, libc-alpha

On 08/15/2018 10:16 PM, Gabriel F. T. Gomes wrote:

> +  /* Prepare in-memory buffer to hold the output.  */
> +  char *buffer = NULL;
> +  size_t length = 0;
> +  FILE *fp = open_memstream (&buffer, &length);
> +  TEST_VERIFY_EXIT (fp != NULL);

You could use <support/xmemstream.h> here.  (My other test couldn't use 
this because it needed wide-oriented streams.)

Thanks,
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 3/3] Add tests with floating-point arguments for err* and verr* functions
  2018-08-15 20:16 ` [PATCH v2 3/3] Add tests with floating-point arguments for err* and verr* functions Gabriel F. T. Gomes
@ 2018-08-16  9:28   ` Florian Weimer
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Weimer @ 2018-08-16  9:28 UTC (permalink / raw)
  To: Gabriel F. T. Gomes, libc-alpha

On 08/15/2018 10:16 PM, Gabriel F. T. Gomes wrote:
> Similarly to what has been done for argp_error, and argp_failure, as
> well as for warn, warnx, vwarn, and vwarnx, this patch adds new tests
> for the following functions: err, errx, verr, verrx, error, and
> error_at_line.  The new tests check that the conversion of long double
> variables into string works correctly on the default format of the type.
> Future patches will reuse these tests for other formats that long double
> can take.  Since the functions do not return, each of them has its own
> test case file.

You could avoid the shell script with <support/capture_subprocess.h>.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-08-16  9:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-15 20:16 [PATCH v2 0/3] Tests for argp/err/error functions with long double Gabriel F. T. Gomes
2018-08-15 20:16 ` [PATCH v2 3/3] Add tests with floating-point arguments for err* and verr* functions Gabriel F. T. Gomes
2018-08-16  9:28   ` Florian Weimer
2018-08-15 20:16 ` [PATCH v2 1/3] Add tests for argp_error and argp_failure with floating-point parameters Gabriel F. T. Gomes
2018-08-15 20:16 ` [PATCH v2 2/3] Add test for warn, warnx, vwarn, and vwarnx " Gabriel F. T. Gomes
2018-08-16  9:26   ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).