summaryrefslogtreecommitdiffstats
path: root/tools/regression
diff options
context:
space:
mode:
Diffstat (limited to 'tools/regression')
-rw-r--r--tools/regression/lib/msun/Makefile4
-rw-r--r--tools/regression/lib/msun/test-exponential.c2
-rw-r--r--tools/regression/lib/msun/test-fma.c3
-rw-r--r--tools/regression/lib/msun/test-fmaxmin.c9
-rw-r--r--tools/regression/lib/msun/test-invtrig.c2
-rw-r--r--tools/regression/lib/msun/test-logarithm.c158
-rw-r--r--tools/regression/lib/msun/test-logarithm.t10
-rw-r--r--tools/regression/lib/msun/test-lrint.c7
-rw-r--r--tools/regression/lib/msun/test-nearbyint.c100
-rw-r--r--tools/regression/lib/msun/test-nearbyint.t10
-rw-r--r--tools/regression/lib/msun/test-trig.c2
-rw-r--r--tools/regression/sockets/unix_gc/unix_gc.c63
-rw-r--r--tools/regression/usr.bin/printf/regress.m5.out1
-rw-r--r--tools/regression/usr.bin/printf/regress.sh3
14 files changed, 353 insertions, 21 deletions
diff --git a/tools/regression/lib/msun/Makefile b/tools/regression/lib/msun/Makefile
index 4a19dc2..eb9a6ae 100644
--- a/tools/regression/lib/msun/Makefile
+++ b/tools/regression/lib/msun/Makefile
@@ -1,8 +1,8 @@
# $FreeBSD$
TESTS= test-conj test-csqrt test-exponential test-fenv test-fma \
- test-fmaxmin test-ilogb test-invtrig test-lrint \
- test-lround test-nan test-next test-rem test-trig
+ test-fmaxmin test-ilogb test-invtrig test-logarithm test-lrint \
+ test-lround test-nan test-nearbyint test-next test-rem test-trig
CFLAGS+= -O0 -lm
.PHONY: tests
diff --git a/tools/regression/lib/msun/test-exponential.c b/tools/regression/lib/msun/test-exponential.c
index 6111e96..53a6116 100644
--- a/tools/regression/lib/msun/test-exponential.c
+++ b/tools/regression/lib/msun/test-exponential.c
@@ -89,7 +89,7 @@ __FBSDID("$FreeBSD$");
int
fpequal(long double x, long double y)
{
- return ((x == y && signbit(x) == signbit(y)) || isnan(x) && isnan(y));
+ return ((x == y && !signbit(x) == !signbit(y)) || isnan(x) && isnan(y));
}
void
diff --git a/tools/regression/lib/msun/test-fma.c b/tools/regression/lib/msun/test-fma.c
index 5511eb3..00620f8 100644
--- a/tools/regression/lib/msun/test-fma.c
+++ b/tools/regression/lib/msun/test-fma.c
@@ -85,7 +85,8 @@ int
fpequal(long double x, long double y)
{
- return ((x == y && signbit(x) == signbit(y)) || (isnan(x) && isnan(y)));
+ return ((x == y && !signbit(x) == !signbit(y))
+ || (isnan(x) && isnan(y)));
}
static void
diff --git a/tools/regression/lib/msun/test-fmaxmin.c b/tools/regression/lib/msun/test-fmaxmin.c
index f1e0a7e..fdba529 100644
--- a/tools/regression/lib/msun/test-fmaxmin.c
+++ b/tools/regression/lib/msun/test-fmaxmin.c
@@ -46,11 +46,12 @@ __FBSDID("$FreeBSD$");
* fpequal(NaN, NaN) is true
* fpequal(+0.0, -0.0) is false
*/
-inline int
+static inline int
fpequal(long double x, long double y)
{
- return ((x == y && signbit(x) == signbit(y)) || (isnan(x) && isnan(y)));
+ return ((x == y && !signbit(x) == !signbit(y))
+ || (isnan(x) && isnan(y)));
}
/*
@@ -63,7 +64,7 @@ fpequal(long double x, long double y)
feclearexcept(ALL_STD_EXCEPT); \
long double __result = func((__x), (__y)); \
if (fetestexcept(ALL_STD_EXCEPT)) { \
- fprintf(stderr, #func "(%L.20g, %L.20g) raised 0x%x\n", \
+ fprintf(stderr, #func "(%.20Lg, %.20Lg) raised 0x%x\n", \
(x), (y), fetestexcept(FE_ALL_EXCEPT)); \
ok = 0; \
} \
@@ -104,7 +105,7 @@ testall_r(long double big, long double small)
* in all rounding modes and with the arguments in different orders.
* The input 'big' must be >= 'small'.
*/
-int
+void
testall(int testnum, long double big, long double small)
{
static const int rmodes[] = {
diff --git a/tools/regression/lib/msun/test-invtrig.c b/tools/regression/lib/msun/test-invtrig.c
index 5900f5b..05d310f 100644
--- a/tools/regression/lib/msun/test-invtrig.c
+++ b/tools/regression/lib/msun/test-invtrig.c
@@ -118,7 +118,7 @@ fpequal(long double x, long double y, long double tol)
if (isnan(x) && isnan(y))
return (1);
- if (signbit(x) != signbit(y))
+ if (!signbit(x) != !signbit(y))
return (0);
if (x == y)
return (1);
diff --git a/tools/regression/lib/msun/test-logarithm.c b/tools/regression/lib/msun/test-logarithm.c
new file mode 100644
index 0000000..52f562c
--- /dev/null
+++ b/tools/regression/lib/msun/test-logarithm.c
@@ -0,0 +1,158 @@
+/*-
+ * Copyright (c) 2008-2010 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Tests for corner cases in log*().
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
+ FE_OVERFLOW | FE_UNDERFLOW)
+
+#pragma STDC FENV_ACCESS ON
+
+/*
+ * Test that a function returns the correct value and sets the
+ * exception flags correctly. The exceptmask specifies which
+ * exceptions we should check. We need to be lenient for several
+ * reasoons, but mainly because on some architectures it's impossible
+ * to raise FE_OVERFLOW without raising FE_INEXACT.
+ *
+ * These are macros instead of functions so that assert provides more
+ * meaningful error messages.
+ *
+ * XXX The volatile here is to avoid gcc's bogus constant folding and work
+ * around the lack of support for the FENV_ACCESS pragma.
+ */
+#define test(func, x, result, exceptmask, excepts) do { \
+ volatile long double _d = x; \
+ assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
+ assert(fpequal((func)(_d), (result))); \
+ assert(((func), fetestexcept(exceptmask) == (excepts))); \
+} while (0)
+
+/* Test all the functions that compute log(x). */
+#define testall0(x, result, exceptmask, excepts) do { \
+ test(log, x, result, exceptmask, excepts); \
+ test(logf, x, result, exceptmask, excepts); \
+ test(log2, x, result, exceptmask, excepts); \
+ test(log2f, x, result, exceptmask, excepts); \
+ test(log10, x, result, exceptmask, excepts); \
+ test(log10f, x, result, exceptmask, excepts); \
+} while (0)
+
+/* Test all the functions that compute log(1+x). */
+#define testall1(x, result, exceptmask, excepts) do { \
+ test(log1p, x, result, exceptmask, excepts); \
+ test(log1pf, x, result, exceptmask, excepts); \
+} while (0)
+
+/*
+ * Determine whether x and y are equal, with two special rules:
+ * +0.0 != -0.0
+ * NaN == NaN
+ */
+int
+fpequal(long double x, long double y)
+{
+ return ((x == y && !signbit(x) == !signbit(y)) || isnan(x) && isnan(y));
+}
+
+void
+run_generic_tests(void)
+{
+
+ /* exp(1) == 0, no exceptions raised */
+ testall0(1.0, 0.0, ALL_STD_EXCEPT, 0);
+ testall1(0.0, 0.0, ALL_STD_EXCEPT, 0);
+ testall1(-0.0, -0.0, ALL_STD_EXCEPT, 0);
+
+ /* log(NaN) == NaN, no exceptions raised */
+ testall0(NAN, NAN, ALL_STD_EXCEPT, 0);
+ testall1(NAN, NAN, ALL_STD_EXCEPT, 0);
+
+ /* log(Inf) == Inf, no exceptions raised */
+ testall0(INFINITY, INFINITY, ALL_STD_EXCEPT, 0);
+ testall1(INFINITY, INFINITY, ALL_STD_EXCEPT, 0);
+
+ /* log(x) == NaN for x < 0, invalid exception raised */
+ testall0(-INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall1(-INFINITY, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall0(-1.0, NAN, ALL_STD_EXCEPT, FE_INVALID);
+ testall1(-1.5, NAN, ALL_STD_EXCEPT, FE_INVALID);
+
+ /* log(0) == -Inf, divide-by-zero exception */
+ testall0(0.0, -INFINITY, ALL_STD_EXCEPT & ~FE_INEXACT, FE_DIVBYZERO);
+ testall0(-0.0, -INFINITY, ALL_STD_EXCEPT & ~FE_INEXACT, FE_DIVBYZERO);
+ testall1(-1.0, -INFINITY, ALL_STD_EXCEPT & ~FE_INEXACT, FE_DIVBYZERO);
+}
+
+void
+run_log2_tests(void)
+{
+ int i;
+
+ /*
+ * We should insist that log2() return exactly the correct
+ * result and not raise an inexact exception for powers of 2.
+ */
+ feclearexcept(FE_ALL_EXCEPT);
+ for (i = FLT_MIN_EXP - FLT_MANT_DIG; i < FLT_MAX_EXP; i++) {
+ assert(log2f(ldexpf(1.0, i)) == i);
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+ }
+ for (i = DBL_MIN_EXP - DBL_MANT_DIG; i < DBL_MAX_EXP; i++) {
+ assert(log2(ldexp(1.0, i)) == i);
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ printf("1..2\n");
+
+ run_generic_tests();
+ printf("ok 1 - logarithm\n");
+
+ run_log2_tests();
+ printf("ok 2 - logarithm\n");
+
+ return (0);
+}
diff --git a/tools/regression/lib/msun/test-logarithm.t b/tools/regression/lib/msun/test-logarithm.t
new file mode 100644
index 0000000..8bdfd03
--- /dev/null
+++ b/tools/regression/lib/msun/test-logarithm.t
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+executable=`basename $0 .t`
+
+make $executable 2>&1 > /dev/null
+
+exec ./$executable
diff --git a/tools/regression/lib/msun/test-lrint.c b/tools/regression/lib/msun/test-lrint.c
index 1693a34a..ba099aa 100644
--- a/tools/regression/lib/msun/test-lrint.c
+++ b/tools/regression/lib/msun/test-lrint.c
@@ -41,9 +41,14 @@ __FBSDID("$FreeBSD$");
#include <ieeefp.h>
#endif
+/*
+ * XXX The volatile here is to avoid gcc's bogus constant folding and work
+ * around the lack of support for the FENV_ACCESS pragma.
+ */
#define test(func, x, result, excepts) do { \
+ volatile double _d = x; \
assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
- assert((func)(x) == (result) || fetestexcept(FE_INVALID)); \
+ assert((func)(_d) == (result) || fetestexcept(FE_INVALID)); \
assert(fetestexcept(FE_ALL_EXCEPT) == (excepts)); \
} while (0)
diff --git a/tools/regression/lib/msun/test-nearbyint.c b/tools/regression/lib/msun/test-nearbyint.c
new file mode 100644
index 0000000..630ddb9
--- /dev/null
+++ b/tools/regression/lib/msun/test-nearbyint.c
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 2010 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Tests for nearbyint{,f,l}()
+ *
+ * TODO:
+ * - adapt tests for rint(3)
+ * - tests for harder values (more mantissa bits than float)
+ * - tests in other rounding modes
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+#include <fenv.h>
+#include <math.h>
+#include <stdio.h>
+
+#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
+ FE_OVERFLOW | FE_UNDERFLOW)
+
+/*
+ * Compare d1 and d2 using special rules: NaN == NaN and +0 != -0.
+ * Fail an assertion if they differ.
+ */
+static int
+fpequal(long double d1, long double d2)
+{
+
+ if (d1 != d2)
+ return (isnan(d1) && isnan(d2));
+ return (copysignl(1.0, d1) == copysignl(1.0, d2));
+}
+
+static void testit(int testnum, float in, float out)
+{
+
+ feclearexcept(ALL_STD_EXCEPT);
+ assert(fpequal(out, nearbyintf(in)));
+ assert(fpequal(-out, nearbyintf(-in)));
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+
+ assert(fpequal(out, nearbyint(in)));
+ assert(fpequal(-out, nearbyint(-in)));
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+
+ assert(fpequal(out, nearbyintl(in)));
+ assert(fpequal(-out, nearbyintl(-in)));
+ assert(fetestexcept(ALL_STD_EXCEPT) == 0);
+
+ printf("ok %d\t\t# nearbyint(%g)\n", testnum, in);
+}
+
+static const float tests[] = {
+/* input output (expected) */
+ 0.0, 0.0,
+ 0.5, 0.0,
+ M_PI, 3,
+ 65536.5, 65536,
+ INFINITY, INFINITY,
+ NAN, NAN,
+};
+
+int
+main(int argc, char *argv[])
+{
+ static const int ntests = sizeof(tests) / sizeof(tests[0]) / 2;
+ int i;
+
+ printf("1..%d\n", ntests);
+ for (i = 0; i < ntests; i++)
+ testit(i + 1, tests[i * 2], tests[i * 2 + 1]);
+
+ return (0);
+}
diff --git a/tools/regression/lib/msun/test-nearbyint.t b/tools/regression/lib/msun/test-nearbyint.t
new file mode 100644
index 0000000..8bdfd03
--- /dev/null
+++ b/tools/regression/lib/msun/test-nearbyint.t
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+executable=`basename $0 .t`
+
+make $executable 2>&1 > /dev/null
+
+exec ./$executable
diff --git a/tools/regression/lib/msun/test-trig.c b/tools/regression/lib/msun/test-trig.c
index e08c4a7..1ac7873 100644
--- a/tools/regression/lib/msun/test-trig.c
+++ b/tools/regression/lib/msun/test-trig.c
@@ -90,7 +90,7 @@ __FBSDID("$FreeBSD$");
int
fpequal(long double x, long double y)
{
- return ((x == y && signbit(x) == signbit(y)) || isnan(x) && isnan(y));
+ return ((x == y && !signbit(x) == !signbit(y)) || isnan(x) && isnan(y));
}
/*
diff --git a/tools/regression/sockets/unix_gc/unix_gc.c b/tools/regression/sockets/unix_gc/unix_gc.c
index a60aa85..8cae2d9 100644
--- a/tools/regression/sockets/unix_gc/unix_gc.c
+++ b/tools/regression/sockets/unix_gc/unix_gc.c
@@ -55,27 +55,36 @@ static char dpath[PATH_MAX];
static const char *test;
static int
-getopenfiles(void)
+getsysctl(const char *name)
{
size_t len;
int i;
len = sizeof(i);
- if (sysctlbyname("kern.openfiles", &i, &len, NULL, 0) < 0)
- err(-1, "kern.openfiles");
+ if (sysctlbyname(name, &i, &len, NULL, 0) < 0)
+ err(-1, "%s", name);
return (i);
}
static int
+getopenfiles(void)
+{
+
+ return (getsysctl("kern.openfiles"));
+}
+
+static int
getinflight(void)
{
- size_t len;
- int i;
- len = sizeof(i);
- if (sysctlbyname("net.local.inflight", &i, &len, NULL, 0) < 0)
- err(-1, "net.local.inflight");
- return (i);
+ return (getsysctl("net.local.inflight"));
+}
+
+static int
+getdeferred(void)
+{
+
+ return (getsysctl("net.local.deferred"));
}
static void
@@ -707,6 +716,40 @@ listen_connect_drop(void)
test_sysctls(inflight, openfiles);
}
+static void
+recursion(void)
+{
+ int fd[2], ff[2];
+ int inflight, openfiles, deferred, deferred1;
+
+ test = "recursion";
+ printf("%s\n", test);
+ save_sysctls(&inflight, &openfiles);
+ deferred = getdeferred();
+
+ my_socketpair(fd);
+
+ for (;;) {
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, ff) == -1) {
+ if (errno == EMFILE || errno == ENFILE)
+ break;
+ err(-1, "socketpair");
+ }
+ sendfd(ff[0], fd[0]);
+ sendfd(ff[0], fd[1]);
+ close2(fd[1], fd[0]);
+ fd[0] = ff[0];
+ fd[1] = ff[1];
+ }
+ close2(fd[0], fd[1]);
+ sleep(1);
+ test_sysctls(inflight, openfiles);
+ deferred1 = getdeferred();
+ if (deferred != deferred1)
+ errx(-1, "recursion: deferred before %d after %d", deferred,
+ deferred1);
+}
+
#define RMDIR "rm -Rf "
int
main(int argc, char *argv[])
@@ -757,6 +800,8 @@ main(int argc, char *argv[])
listen_connect_nothing();
listen_connect_drop();
+ recursion();
+
printf("Finish: inflight %d open %d\n", getinflight(),
getopenfiles());
return (0);
diff --git a/tools/regression/usr.bin/printf/regress.m5.out b/tools/regression/usr.bin/printf/regress.m5.out
new file mode 100644
index 0000000..2838468
--- /dev/null
+++ b/tools/regression/usr.bin/printf/regress.m5.out
@@ -0,0 +1 @@
+-d
diff --git a/tools/regression/usr.bin/printf/regress.sh b/tools/regression/usr.bin/printf/regress.sh
index 86c600f..980fc70 100644
--- a/tools/regression/usr.bin/printf/regress.sh
+++ b/tools/regression/usr.bin/printf/regress.sh
@@ -2,7 +2,7 @@
REGRESSION_START($1)
-echo '1..8'
+echo '1..9'
REGRESSION_TEST(`b', `printf "abc%b%b" "def\n" "\cghi"')
REGRESSION_TEST(`d', `printf "%d,%5d,%.5d,%0*d,%.*d\n" 123 123 123 5 123 5 123')
@@ -11,6 +11,7 @@ REGRESSION_TEST(`m1', `printf "%c%%%d\0\045\n" abc \"abc')
REGRESSION_TEST(`m2', `printf "abc\n\cdef"')
REGRESSION_TEST(`m3', `printf "%%%s\n" abc def ghi jkl')
REGRESSION_TEST(`m4', `printf "%d,%f,%c,%s\n"')
+REGRESSION_TEST(`m5', `printf -- "-d\n"')
REGRESSION_TEST(`s', `printf "%.3s,%-5s\n" abcd abc')
REGRESSION_END()
OpenPOWER on IntegriCloud