diff options
author | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2001-08-15 14:37:17 +0000 |
---|---|---|
committer | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2001-08-15 14:37:17 +0000 |
commit | ee29ce09990030fd5a7c6f78dde0dabfab952171 (patch) | |
tree | dc17f6ce9d5ba480f50f3c02569aa0737499684c /regress/lib/libpthread/stdarg | |
parent | 344dc84d0dc63d3256aca03797112a766d32f738 (diff) |
Regression tests for libc_r (pthreads) library.
Thanks to pval@ for resolving the license stuff.
Diffstat (limited to 'regress/lib/libpthread/stdarg')
-rw-r--r-- | regress/lib/libpthread/stdarg/Makefile | 8 | ||||
-rw-r--r-- | regress/lib/libpthread/stdarg/stdarg.c | 87 |
2 files changed, 95 insertions, 0 deletions
diff --git a/regress/lib/libpthread/stdarg/Makefile b/regress/lib/libpthread/stdarg/Makefile new file mode 100644 index 00000000000..60c57f3e876 --- /dev/null +++ b/regress/lib/libpthread/stdarg/Makefile @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile,v 1.1 2001/08/15 14:37:16 fgsch Exp $ + +PROG= stdarg +SRCS= stdarg.c + +CFLAGS+= -I${.CURDIR}/../include + +.include <bsd.prog.mk> diff --git a/regress/lib/libpthread/stdarg/stdarg.c b/regress/lib/libpthread/stdarg/stdarg.c new file mode 100644 index 00000000000..a3e07d58a21 --- /dev/null +++ b/regress/lib/libpthread/stdarg/stdarg.c @@ -0,0 +1,87 @@ +/* $OpenBSD: stdarg.c,v 1.1 2001/08/15 14:37:16 fgsch Exp $ */ +/* David Leonard <d@openbsd.org>, 2001. Public Domain. */ + +/* + * Test <stdarg.h> + */ + +#include <pthread.h> +#include <stdio.h> +#include <stdarg.h> +#include "test.h" + +#define EQ(v,exp) _CHECK(v, == exp, NULL) + +int thing; + +int +test1(char *fmt, ...) +{ + va_list ap; + + char ch; + int i; + char c; + long l; + void *p; + char *ofmt = fmt; + + va_start(ap, fmt); + for (; *fmt; fmt++) + switch ((ch =*fmt)) { + case 'i': + i = va_arg(ap, int); + EQ(i, 1234); + break; + case 'c': + c = va_arg(ap, char); + EQ(c, 'x'); + break; + case 'l': + l = va_arg(ap, long); + EQ(l, 123456789L); + break; + case 'p': + p = va_arg(ap, void *); + 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); + return 9; +} + +void * +run_test(arg) + void *arg; +{ + char *msg = (char *)arg; + int i; + + SET_NAME(msg); + + puts(msg); + for (i = 0; i < 1000000; i++) { + ASSERT(test1("iclp", 1234, 'x', 123456789L, &thing) == 9); + } + printf("ok\n"); + return NULL; +} + +int +main() +{ + pthread_t t1, t2; + + 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; +} |