summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord <d@openbsd.org>2000-10-04 05:50:58 +0000
committerd <d@openbsd.org>2000-10-04 05:50:58 +0000
commit03ea66e60701977441b0efa1013bd52e953b4461 (patch)
tree0334be8cad96c2c6ef8b93191a85c93d50e913ad
parentnothing uses this variable (diff)
downloadwireguard-openbsd-03ea66e60701977441b0efa1013bd52e953b4461.tar.xz
wireguard-openbsd-03ea66e60701977441b0efa1013bd52e953b4461.zip
bit of a cleanup
-rw-r--r--lib/libc_r/TEST/Makefile14
-rw-r--r--lib/libc_r/TEST/test.h12
-rw-r--r--lib/libc_r/TEST/test_close.c7
-rw-r--r--lib/libc_r/TEST/test_execve.c14
-rw-r--r--lib/libc_r/TEST/test_fork.c5
-rw-r--r--lib/libc_r/TEST/test_signal.c8
-rw-r--r--lib/libc_r/TEST/test_stdarg.c32
-rw-r--r--lib/libc_r/TEST/test_switch.c9
8 files changed, 63 insertions, 38 deletions
diff --git a/lib/libc_r/TEST/Makefile b/lib/libc_r/TEST/Makefile
index a5e268545ca..0fe59a01137 100644
--- a/lib/libc_r/TEST/Makefile
+++ b/lib/libc_r/TEST/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.20 2000/08/07 01:51:29 brad Exp $
+# $OpenBSD: Makefile,v 1.21 2000/10/04 05:50:58 d Exp $
# Copyright (c) 1993 Chris Provenzano, proven@athena.mit.edu
LIBC_R?= /usr/lib/libc_r.a
LIBPTHREAD?= /usr/lib/libpthread.a
-.if 1 # ${MACHINE_ARCH} == "i386"
+.if ${MACHINE_ARCH} == "sparc"
PTHREAD= -lpthread
DPADD += ${LIBPTHREAD}
.else
@@ -33,24 +33,26 @@ SKIP_TESTS += test_sock_2a
all : tests
+MAXTIME= 5
+
tests : ${TESTS}
- @faillist= ; ulimit -t 10; \
+ @faillist= ; \
for i in ${.ALLSRC} ; do \
case " ${SKIP_TESTS} " in \
*" $$i "*) \
: skip ;; \
*) \
echo ; echo "*** $$i ***"; \
- if ${.OBJDIR}/$$i; then \
+ if (ulimit -t ${MAXTIME}; ${.OBJDIR}/$$i); then \
echo "-- $$i passed"; \
else \
- echo "-- $$i FAILED (exit code $$?)"; \
+ echo "-- $$i FAILED (exit code $$?)" >&2; \
faillist="$$faillist $$i"; \
fi;; \
esac; \
done; \
if test -n "$$faillist"; then \
- echo; echo "*** tests that failed:$$faillist"; exit 1; \
+ echo; echo "*** tests that failed:$$faillist" >&2; exit 1; \
else \
echo; echo "All tests passed OK."; exit 0; \
fi
diff --git a/lib/libc_r/TEST/test.h b/lib/libc_r/TEST/test.h
index 34cd4f752c8..24afe9d4b1a 100644
--- a/lib/libc_r/TEST/test.h
+++ b/lib/libc_r/TEST/test.h
@@ -95,12 +95,18 @@ __panic(type, errstr, filenm, lineno, fmt)
} \
} while(0)
+#define _T(x) __builtin_classify_type(x)
+
#define _CHECK(x, rhs, efn) do { \
- int _x; \
- _x = (int)(x); \
+ typeof(x) _x; \
+ _x = (x); \
if (!(_x rhs)) \
__panic("check failed", efn, __FILE__, __LINE__, \
- "failed check %s (=%d) %s ", #x, _x, #rhs); \
+ ((_T(0) == _T(_x) )? "failed check %s (=%d) %s " : \
+ (_T("") == _T(_x) )? "failed check %s (=%s) %s " : \
+ (_T('x') == _T(_x) )? "failed check %s (=%c) %s " : \
+ (_T(0L) == _T(_x) )? "failed check %s (=%ld) %s " : "?") \
+ , #x, _x, #rhs); \
} while(0)
#define CHECKr(x) _CHECK(x, == 0, strerror(_x))
diff --git a/lib/libc_r/TEST/test_close.c b/lib/libc_r/TEST/test_close.c
index 851fae7c67e..1c2cc7fea7c 100644
--- a/lib/libc_r/TEST/test_close.c
+++ b/lib/libc_r/TEST/test_close.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_close.c,v 1.1 2000/01/06 06:51:20 d Exp $ */
+/* $OpenBSD: test_close.c,v 1.2 2000/10/04 05:50:58 d Exp $ */
/*
* Test the semantics of close() while a select() is happening.
@@ -48,7 +48,10 @@ main()
CHECKe(fd = socket(AF_INET, SOCK_STREAM, 0));
printf("main: connecting to discard port with fd %d\n", fd);
- CHECKe(connect(fd, (struct sockaddr *)&addr, sizeof addr));
+ ret = connect(fd, (struct sockaddr *)&addr, sizeof addr);
+ if (ret == -1)
+ fprintf(stderr, "connect() failed: ensure that the discard port is enabled for inetd(8)\n");
+ CHECKe(ret);
printf("main: connected on fd %d\n", fd);
CHECKr(pthread_attr_init(&attr));
diff --git a/lib/libc_r/TEST/test_execve.c b/lib/libc_r/TEST/test_execve.c
index 4ac696800a2..0074b3d3ae5 100644
--- a/lib/libc_r/TEST/test_execve.c
+++ b/lib/libc_r/TEST/test_execve.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_execve.c,v 1.4 2000/01/06 06:53:30 d Exp $ */
+/* $OpenBSD: test_execve.c,v 1.5 2000/10/04 05:50:58 d Exp $ */
/*
* Copyright (c) 1994 by Chris Provenzano, proven@athena.mit.edu
*
@@ -20,7 +20,6 @@ char *argv[] = {
};
char * should_succeed = "This line should be displayed\n";
-char * should_fail = "Error: This line should NOT be displayed\n";
int
main()
@@ -28,20 +27,21 @@ main()
int fd;
printf("This is the first message\n");
- if (isatty(1)) {
+ if (isatty(STDOUT_FILENO)) {
char *ttynm;
- CHECKn(ttynm = ttyname(1));
+ CHECKn(ttynm = ttyname(STDOUT_FILENO));
printf("tty is %s\n", ttynm);
CHECKe(fd = open(ttynm, O_RDWR));
} else
- PANIC("stdout not a tty");
+ PANIC("stdout is not a tty: this test needs a tty");
CHECKn(printf("This output is necessary to set the stdout fd to NONBLOCKING\n"));
/* do a dup2 */
- CHECKe(dup2(fd, 1));
- CHECKe(write(1, should_succeed, (size_t)strlen(should_succeed)));
+ CHECKe(dup2(fd, STDOUT_FILENO));
+ CHECKe(write(STDOUT_FILENO, should_succeed,
+ (size_t)strlen(should_succeed)));
CHECKe(execve(argv[0], argv, environ));
DIE(errno, "execve %s", argv[0]);
}
diff --git a/lib/libc_r/TEST/test_fork.c b/lib/libc_r/TEST/test_fork.c
index efd23860ca8..f5733fba627 100644
--- a/lib/libc_r/TEST/test_fork.c
+++ b/lib/libc_r/TEST/test_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_fork.c,v 1.7 2000/01/06 06:54:28 d Exp $ */
+/* $OpenBSD: test_fork.c,v 1.8 2000/10/04 05:50:58 d Exp $ */
/*
* Copyright (c) 1994 by Chris Provenzano, proven@athena.mit.edu
*
@@ -40,7 +40,8 @@ main()
CHECKe(flags = fcntl(STDOUT_FILENO, F_GETFL));
if ((flags & (O_NONBLOCK | O_NDELAY))) {
- CHECKe(fcntl(STDOUT_FILENO, F_SETFL,
+ /* This fails when stdout is /dev/null!? */
+ /*CHECKe*/(fcntl(STDOUT_FILENO, F_SETFL,
flags & ~(O_NONBLOCK | O_NDELAY)));
}
diff --git a/lib/libc_r/TEST/test_signal.c b/lib/libc_r/TEST/test_signal.c
index 4d7a43869a9..0ee35f6b908 100644
--- a/lib/libc_r/TEST/test_signal.c
+++ b/lib/libc_r/TEST/test_signal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_signal.c,v 1.2 2000/08/07 02:00:04 brad Exp $ */
+/* $OpenBSD: test_signal.c,v 1.3 2000/10/04 05:50:58 d Exp $ */
/*
* This program tests signal handler re-entrancy.
@@ -21,7 +21,7 @@ sleeper(arg)
sigfillset(&mask);
CHECKe(sigprocmask(SIG_SETMASK, &mask, NULL));
- ASSERT(sleep(10) == 0);
+ ASSERT(sleep(2) == 0);
SUCCEED;
}
@@ -37,11 +37,11 @@ handler(sig)
int
main()
{
- /* pthread_t slpr; */
+ pthread_t slpr;
ASSERT(signal(SIGALRM, handler) != SIG_ERR);
CHECKe(alarm(1));
- /* CHECKr(pthread_create(&slpr, NULL, sleeper, NULL)); */
+ CHECKr(pthread_create(&slpr, NULL, sleeper, NULL));
/* ASSERT(sleep(1) == 0); */
for (;;)
CHECKe(write(STDOUT_FILENO, ".", 1));
diff --git a/lib/libc_r/TEST/test_stdarg.c b/lib/libc_r/TEST/test_stdarg.c
index f2b4781cff2..fce6af523d4 100644
--- a/lib/libc_r/TEST/test_stdarg.c
+++ b/lib/libc_r/TEST/test_stdarg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_stdarg.c,v 1.2 2000/01/04 02:31:44 d Exp $ */
+/* $OpenBSD: test_stdarg.c,v 1.3 2000/10/04 05:50:58 d Exp $ */
/*
* Test <stdarg.h>
*/
@@ -8,6 +8,8 @@
#include <stdarg.h>
#include "test.h"
+#define EQ(v,exp) _CHECK(v, == exp, NULL)
+
int thing;
int
@@ -15,31 +17,35 @@ test1(char *fmt, ...)
{
va_list ap;
+ char ch;
int i;
char c;
long l;
- void * p;
+ void *p;
+ char *ofmt = fmt;
va_start(ap, fmt);
for (; *fmt; fmt++)
- switch (*fmt) {
+ switch ((ch =*fmt)) {
case 'i':
i = va_arg(ap, int);
- ASSERT(i == 1234);
+ EQ(i, 1234);
break;
case 'c':
c = va_arg(ap, char);
- ASSERT(c == 'x');
+ EQ(c, 'x');
break;
case 'l':
l = va_arg(ap, long);
- ASSERT(l == 123456789L);
+ EQ(l, 123456789L);
break;
case 'p':
p = va_arg(ap, void *);
- ASSERT(p == &thing);
+ EQ(p, &thing);
break;
default:
+ fprintf(stderr, "unexpected character 0x%02x `%c' in %s(%p) at %p\n",
+ ch, ch, ofmt, ofmt, fmt);
ASSERT(0);
}
va_end(ap);
@@ -53,7 +59,9 @@ run_test(arg)
char *msg = (char *)arg;
int i;
- printf("Testing stdarg: %s\n", msg);
+ SET_NAME(msg);
+
+ puts(msg);
for (i = 0; i < 1000000; i++) {
ASSERT(test1("iclp", 1234, 'x', 123456789L, &thing) == 9);
}
@@ -66,9 +74,11 @@ main()
{
pthread_t t1, t2;
- run_test("in main thread");
- CHECKr(pthread_create(&t1, NULL, run_test, "in child thread 1"));
- CHECKr(pthread_create(&t2, NULL, run_test, "in child thread 2"));
+ printf("trying loop in single-threaded mode:\n");
+ run_test("main");
+ printf("now running loop with 2 threads:\n");
+ CHECKr(pthread_create(&t1, NULL, run_test, "child 1"));
+ CHECKr(pthread_create(&t2, NULL, run_test, "child 2"));
CHECKr(pthread_join(t1, NULL));
CHECKr(pthread_join(t2, NULL));
SUCCEED;
diff --git a/lib/libc_r/TEST/test_switch.c b/lib/libc_r/TEST/test_switch.c
index d6fb34d4c39..384593960f5 100644
--- a/lib/libc_r/TEST/test_switch.c
+++ b/lib/libc_r/TEST/test_switch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: test_switch.c,v 1.6 2000/01/06 06:58:35 d Exp $ */
+/* $OpenBSD: test_switch.c,v 1.7 2000/10/04 05:50:58 d Exp $ */
/* ==== test_switch.c ========================================================
* Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu
*
@@ -19,6 +19,8 @@ const char buf[] = "abcdefghijklmnopqrstuvwxyz";
char x[sizeof(buf)];
int fd = 1;
+volatile int ending = 0;
+
/* ==========================================================================
* usage();
*/
@@ -34,11 +36,11 @@ new_thread(arg)
void *arg;
{
SET_NAME("writer");
- while(1) {
+ while (!ending) {
CHECKe(write (fd, (char *) arg, 1));
x[(char *)arg - buf] = 1;
}
- PANIC("while");
+ return NULL;
}
int
@@ -87,6 +89,7 @@ main(argc, argv)
/* give all threads a chance to run */
sleep (4);
+ ending = 1;
for (i = 0; i < count; i++)
ASSERT(x[i]); /* make sure each thread ran */