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 v2 3/3] Add tests with floating-point arguments for err* and verr* functions


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


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