diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/pkg/manifests/system-test-libctest.mf | 5 | ||||
-rw-r--r-- | usr/src/test/libc-tests/runfiles/default.run | 2 | ||||
-rw-r--r-- | usr/src/test/libc-tests/tests/Makefile | 2 | ||||
-rw-r--r-- | usr/src/test/libc-tests/tests/fpround/Makefile | 24 | ||||
-rw-r--r-- | usr/src/test/libc-tests/tests/fpround/fpround_test.c | 111 |
5 files changed, 143 insertions, 1 deletions
diff --git a/usr/src/pkg/manifests/system-test-libctest.mf b/usr/src/pkg/manifests/system-test-libctest.mf index bfb547a911..b635e7c74b 100644 --- a/usr/src/pkg/manifests/system-test-libctest.mf +++ b/usr/src/pkg/manifests/system-test-libctest.mf @@ -28,6 +28,11 @@ dir path=opt/libc-tests/tests file path=opt/libc-tests/README mode=0444 file path=opt/libc-tests/bin/libctest mode=0555 file path=opt/libc-tests/runfiles/default.run mode=0444 +file path=opt/libc-tests/tests/fpround_test mode=0555 +$(i386_ONLY)file path=opt/libc-tests/tests/fpround_test.amd64 mode=0555 +$(i386_ONLY)file path=opt/libc-tests/tests/fpround_test.i386 mode=0555 +$(sparc_ONLY)file path=opt/libc-tests/tests/fpround_test.sparc mode=0555 +$(sparc_ONLY)file path=opt/libc-tests/tests/fpround_test.sparcv9 mode=0555 file path=opt/libc-tests/tests/newlocale_test mode=0555 $(i386_ONLY)file path=opt/libc-tests/tests/newlocale_test.amd64 mode=0555 $(i386_ONLY)file path=opt/libc-tests/tests/newlocale_test.i386 mode=0555 diff --git a/usr/src/test/libc-tests/runfiles/default.run b/usr/src/test/libc-tests/runfiles/default.run index 8602bbc543..deadcb8c1c 100644 --- a/usr/src/test/libc-tests/runfiles/default.run +++ b/usr/src/test/libc-tests/runfiles/default.run @@ -22,6 +22,8 @@ timeout = 60 post = outputdir = /var/tmp/test_results +[/opt/libc-tests/tests/fpround_test] + [/opt/libc-tests/tests/newlocale_test] [/opt/libc-tests/tests/nl_langinfo_test] diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile index ece9ea77b3..0ce3902862 100644 --- a/usr/src/test/libc-tests/tests/Makefile +++ b/usr/src/test/libc-tests/tests/Makefile @@ -14,7 +14,7 @@ # Copyright 2014 Garrett D'Amore <garrett@damore.org> # -SUBDIRS = newlocale nl_langinfo wcsrtombs wctype +SUBDIRS = fpround newlocale nl_langinfo wcsrtombs wctype include $(SRC)/Makefile.master include $(SRC)/test/Makefile.com diff --git a/usr/src/test/libc-tests/tests/fpround/Makefile b/usr/src/test/libc-tests/tests/fpround/Makefile new file mode 100644 index 0000000000..1debb4676a --- /dev/null +++ b/usr/src/test/libc-tests/tests/fpround/Makefile @@ -0,0 +1,24 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2014 Garrett D'Amore <garrett@damore.org> +# + +include $(SRC)/Makefile.master + +PROG = fpround_test +ARCHPROG = fpround_test + +include ../Makefile.com + +LDLIBS += -lm +LDLIBS64 += -lm diff --git a/usr/src/test/libc-tests/tests/fpround/fpround_test.c b/usr/src/test/libc-tests/tests/fpround/fpround_test.c new file mode 100644 index 0000000000..709d40ad4a --- /dev/null +++ b/usr/src/test/libc-tests/tests/fpround/fpround_test.c @@ -0,0 +1,111 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2014 PALO, Richard. All rights reserved. + * Copyright 2014 OmniTI Computer Consulting, Inc. All rights reserved. + */ + +/* + * Test rounding of floating point numbers in libc's *printf() routines. + * + * C99 must be enabled to get DECIMAL_DIG defined, but it looks like all + * of usr/src/test/libc is compiled that way. + */ + +#include <float.h> +#include <fenv.h> +#include <stdio.h> +#include <strings.h> +#include "test_common.h" + +/* + * Returns negative if snprintf() fails. Returns 0 upon + * successful execution of the test, return 1 upon a failure. + * Spews output if verbose is TRUE. + */ +int +run_one(test_t t, int i, int j, int precision, boolean_t verbose) +{ + const int size = 100; + char buffer[size], check[size]; + double val; + int status; + + val = (double)(0.0 + j) / i; + /* first get max precision for control check */ + status = snprintf(check, size, "%+-.*f", DECIMAL_DIG, val); + if (status < 0) { + test_failed(t, "Max precision snprintf() " + "(i = %d, j = %d) returned %d\n", i, j, status); + return (status); + } + /* then get specific precision */ + status = snprintf(buffer, size, "%+-#.*f", precision, val); + if (status < 0) { + test_failed(t, "Specific precision snprintf() " + "(i = %d, j = %d, precision = %d) returned %d\n", i, j, + precision, status); + return (status); + } + + if (strlen(check) > strlen(buffer) && + strncmp(buffer, check, strlen(buffer))) { + /* last check if correctly rounded up */ + if (check[strlen(buffer)] < '5' && + buffer[strlen(buffer) - 1] > check[strlen(buffer) - 1]) { + if (verbose) + (void) printf("failure:f precision %d " + "for %02d/%02d => %s (%s)\n", + precision, j, i, buffer, check); + return (1); + } + } + + return (0); +} + +int +main(int argc, char *argv[]) +{ + int status, i, j, precision; + int failures = 0; + int runs = 0; + test_t t; + /* NOTE: Any argument after the command enables "VERBOSE" mode. */ + boolean_t verbose = (argc > 1); + + t = test_start("*printf() floating-point rounding tests."); + + (void) fesetround(FE_TONEAREST); + + for (j = 1; j < 100; j++) { + for (i = 2; i < 100; i++) { + for (precision = DBL_DIG - 1; precision <= DECIMAL_DIG; + precision++) { + runs++; + status = run_one(t, i, j, precision, verbose); + if (status < 0) + return (status); + failures += status; + } + } + } + + if (failures > 0) { + test_failed(t, "Tests failed %d times out of %d attempts.\n" + "Run '%s full' to see the %d failures individually.\n", + failures, runs, argv[0], failures); + } else + test_passed(t); + + return (0); +} |