CVS commit: src/tests/lib/libpthread

2020-06-21 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Jun 21 07:06:05 UTC 2020

Modified Files:
src/tests/lib/libpthread: Makefile

Log Message:
fix build of h_thread_local_dtor.cpp


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libpthread/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/Makefile
diff -u src/tests/lib/libpthread/Makefile:1.14 src/tests/lib/libpthread/Makefile:1.15
--- src/tests/lib/libpthread/Makefile:1.14	Wed Apr 24 11:43:19 2019
+++ src/tests/lib/libpthread/Makefile	Sun Jun 21 07:06:05 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.14 2019/04/24 11:43:19 kamil Exp $
+# $NetBSD: Makefile,v 1.15 2020/06/21 07:06:05 lukem Exp $
 
 NOMAN=		# defined
 
@@ -55,6 +55,7 @@ TESTS_C+=	t_call_once t_cnd t_mtx t_thrd
 COPTS.h_thread_local_dtor.cpp+=	-std=c++11
 # Deal with questionable warning and header quality in libstdc++.
 COPTS.h_thread_local_dtor.cpp+=	 ${${ACTIVE_CC} == "gcc" :?  -Wno-ctor-dtor-privacy -Wno-sign-compare -Wno-shadow :}
+SRCS.h_thread_local_dtor= h_thread_local_dtor.cpp
 
 FILESDIR=	${TESTSDIR}
 FILES=		d_mach



CVS commit: src/tests/lib/libpthread

2020-06-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jun 11 11:40:54 UTC 2020

Modified Files:
src/tests/lib/libpthread: t_mtx.c

Log Message:
Do not destroy mutices that failed to init - fixes a run with
PTHREAD_DIAGASSERT set to "a". Pointed out by joerg.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_mtx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mtx.c
diff -u src/tests/lib/libpthread/t_mtx.c:1.1 src/tests/lib/libpthread/t_mtx.c:1.2
--- src/tests/lib/libpthread/t_mtx.c:1.1	Wed Apr 24 11:43:19 2019
+++ src/tests/lib/libpthread/t_mtx.c	Thu Jun 11 11:40:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_mtx.c,v 1.1 2019/04/24 11:43:19 kamil Exp $	*/
+/*	$NetBSD: t_mtx.c,v 1.2 2020/06/11 11:40:54 martin Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2019\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mtx.c,v 1.1 2019/04/24 11:43:19 kamil Exp $");
+__RCSID("$NetBSD: t_mtx.c,v 1.2 2020/06/11 11:40:54 martin Exp $");
 
 #include 
 #include 
@@ -62,13 +62,10 @@ ATF_TC_BODY(mtx_init, tc)
 	mtx_destroy(&m);
 
 	ATF_REQUIRE_EQ(mtx_init(&m, mtx_recursive), thrd_error);
-	mtx_destroy(&m);
 
 	ATF_REQUIRE_EQ(mtx_init(&m, mtx_plain | mtx_timed), thrd_error);
-	mtx_destroy(&m);
 
 	ATF_REQUIRE_EQ(mtx_init(&m, -1), thrd_error);
-	mtx_destroy(&m);
 }
 
 ATF_TC(mtx_lock);



CVS commit: src/tests/lib/libpthread

2020-06-10 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun 10 21:46:50 UTC 2020

Modified Files:
src/tests/lib/libpthread: t_cond.c

Log Message:
Adjust cond_timedwait_race to take account of spurious wakeups (which are
completely legit).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libpthread/t_cond.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_cond.c
diff -u src/tests/lib/libpthread/t_cond.c:1.7 src/tests/lib/libpthread/t_cond.c:1.8
--- src/tests/lib/libpthread/t_cond.c:1.7	Sun Jul  3 14:24:59 2016
+++ src/tests/lib/libpthread/t_cond.c	Wed Jun 10 21:46:50 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cond.c,v 1.7 2016/07/03 14:24:59 christos Exp $ */
+/* $NetBSD: t_cond.c,v 1.8 2020/06/10 21:46:50 ad Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_cond.c,v 1.7 2016/07/03 14:24:59 christos Exp $");
+__RCSID("$NetBSD: t_cond.c,v 1.8 2020/06/10 21:46:50 ad Exp $");
 
 #include 
 
@@ -329,7 +329,7 @@ pthread_cond_timedwait_func(void *arg)
 		 * Sometimes we catch ESRCH.
 		 * This should never happen.
 		 */
-		ATF_REQUIRE(rv == ETIMEDOUT);
+		ATF_REQUIRE(rv == ETIMEDOUT || rv == 0);
 		PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
 	}
 }



CVS commit: src/tests/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 13:40:23 UTC 2020

Modified Files:
src/tests/lib/libpthread: t_join.c

Log Message:
Fix the t_join test

For pthread_attr_get_np() attr should be initialized prior to the call by
using pthread_attr_init(3). pthread_getattr_np() does this
automatically so switch to it.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libpthread/t_join.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_join.c
diff -u src/tests/lib/libpthread/t_join.c:1.9 src/tests/lib/libpthread/t_join.c:1.10
--- src/tests/lib/libpthread/t_join.c:1.9	Sun Jul  2 16:41:33 2017
+++ src/tests/lib/libpthread/t_join.c	Wed Jan 29 13:40:23 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.9 2017/07/02 16:41:33 joerg Exp $ */
+/* $NetBSD: t_join.c,v 1.10 2020/01/29 13:40:23 kamil Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_join.c,v 1.9 2017/07/02 16:41:33 joerg Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.10 2020/01/29 13:40:23 kamil Exp $");
 
 #include 
 #include 
@@ -153,7 +153,7 @@ threadfunc2(void *arg)
 
 	j = (uintptr_t)arg;
 
-	ATF_REQUIRE(pthread_attr_get_np(pthread_self(), &attr) == 0);
+	ATF_REQUIRE(pthread_getattr_np(pthread_self(), &attr) == 0);
 	ATF_REQUIRE(pthread_attr_getstacksize(&attr, &stacksize) == 0);
 	ATF_REQUIRE(stacksize == STACKSIZE * (j + 1));
 	ATF_REQUIRE(pthread_attr_getguardsize(&attr, &guardsize) == 0);



CVS commit: src/tests/lib/libpthread

2019-03-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar  6 01:20:15 UTC 2019

Modified Files:
src/tests/lib/libpthread: h_resolv.c

Log Message:
add joins


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/h_resolv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/h_resolv.c
diff -u src/tests/lib/libpthread/h_resolv.c:1.2 src/tests/lib/libpthread/h_resolv.c:1.3
--- src/tests/lib/libpthread/h_resolv.c:1.2	Wed Nov  3 12:10:22 2010
+++ src/tests/lib/libpthread/h_resolv.c	Tue Mar  5 20:20:15 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: h_resolv.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
+/* $NetBSD: h_resolv.c,v 1.3 2019/03/06 01:20:15 christos Exp $ */
 
 /*-
  * Copyright (c) 2004, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: h_resolv.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
+__RCSID("$NetBSD: h_resolv.c,v 1.3 2019/03/06 01:20:15 christos Exp $");
 
 #include 
 #include 
@@ -56,7 +56,7 @@ static void usage(void)  __attribute__((
 static void load(const char *);
 static void resolvone(int);
 static void *resolvloop(void *);
-static void run(int *);
+static pthread_t run(int *);
 
 static pthread_mutex_t stats = PTHREAD_MUTEX_INITIALIZER;
 
@@ -77,7 +77,7 @@ load(const char *fname)
 	char *line;
 
 	if ((fp = fopen(fname, "r")) == NULL)
-		err(1, "Cannot open `%s'", fname);
+		err(EXIT_FAILURE, "Cannot open `%s'", fname);
 	while ((line = fgetln(fp, &len)) != NULL) {
 		char c = line[len];
 		char *ptr;
@@ -130,18 +130,20 @@ resolvloop(void *p)
 	return NULL;
 }
 
-static void
+static pthread_t
 run(int *nhosts)
 {
 	pthread_t self = pthread_self();
 	if (pthread_create(&self, NULL, resolvloop, nhosts) != 0)
-		err(1, "pthread_create");
+		err(EXIT_FAILURE, "pthread_create");
+	return self;
 }
 
 int
 main(int argc, char *argv[])
 {
 	int nthreads = NTHREADS;
+	pthread_t *threads;
 	int nhosts = NHOSTS;
 	int i, c, done, *nleft;
 	hosts = sl_init();
@@ -170,16 +172,18 @@ main(int argc, char *argv[])
 		usage();
 
 	if ((nleft = malloc(nthreads * sizeof(int))) == NULL)
-		err(1, "malloc");
+		err(EXIT_FAILURE, "malloc");
 	if ((ask = calloc(hosts->sl_cur, sizeof(int))) == NULL)
-		err(1, "calloc");
+		err(EXIT_FAILURE, "calloc");
 	if ((got = calloc(hosts->sl_cur, sizeof(int))) == NULL)
-		err(1, "calloc");
+		err(EXIT_FAILURE, "calloc");
+	if ((threads = malloc(nthreads * sizeof(pthread_t))) == NULL)
+		err(EXIT_FAILURE, "calloc");
 
 
 	for (i = 0; i < nthreads; i++) {
 		nleft[i] = nhosts;
-		run(&nleft[i]);
+		threads[i] = run(&nleft[i]);
 	}
 
 	for (done = 0; !done;) {
@@ -200,6 +204,9 @@ main(int argc, char *argv[])
 			c++;
 		}
 	}
+	for (i = 0; i < nthreads; i++)
+		pthread_join(threads[i], NULL);
+	free(threads);
 	free(nleft);
 	free(ask);
 	free(got);



CVS commit: src/tests/lib/libpthread

2018-02-28 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Feb 28 21:36:50 UTC 2018

Modified Files:
src/tests/lib/libpthread: t_swapcontext.c

Log Message:
Simplify - it's enough to set nctx.uc_link to &octx to restore old
context automatically when swapfunc() returns.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libpthread/t_swapcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_swapcontext.c
diff -u src/tests/lib/libpthread/t_swapcontext.c:1.8 src/tests/lib/libpthread/t_swapcontext.c:1.9
--- src/tests/lib/libpthread/t_swapcontext.c:1.8	Wed Feb 28 21:29:10 2018
+++ src/tests/lib/libpthread/t_swapcontext.c	Wed Feb 28 21:36:50 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.8 2018/02/28 21:29:10 uwe Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.9 2018/02/28 21:36:50 uwe Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_swapcontext.c,v 1.8 2018/02/28 21:29:10 uwe Exp $");
+__RCSID("$NetBSD: t_swapcontext.c,v 1.9 2018/02/28 21:36:50 uwe Exp $");
 
 #include 
 #include 
@@ -61,11 +61,6 @@ swapfunc(void)
 
 	ATF_REQUIRE_EQ(oself, nself);
 	printf("Test succeeded\n");
-	/* Go back in main */
-	ATF_REQUIRE(swapcontext(&nctx, &octx));
-
-	/* NOTREACHED */
-	return;
 }
 
 /* ARGSUSED0 */
@@ -74,6 +69,7 @@ threadfunc(void *arg)
 {
 	nctx.uc_stack.ss_sp = stack;
 	nctx.uc_stack.ss_size = sizeof(stack);
+	nctx.uc_link = &octx;
 
 	makecontext(&nctx, swapfunc, 0);
 



CVS commit: src/tests/lib/libpthread

2018-02-28 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Feb 28 21:29:11 UTC 2018

Modified Files:
src/tests/lib/libpthread: t_swapcontext.c

Log Message:
Add missing $ in the RCSID.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libpthread/t_swapcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_swapcontext.c
diff -u src/tests/lib/libpthread/t_swapcontext.c:1.7 src/tests/lib/libpthread/t_swapcontext.c:1.8
--- src/tests/lib/libpthread/t_swapcontext.c:1.7	Tue Feb 27 20:34:04 2018
+++ src/tests/lib/libpthread/t_swapcontext.c	Wed Feb 28 21:29:10 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.7 2018/02/27 20:34:04 uwe Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.8 2018/02/28 21:29:10 uwe Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD");
+__RCSID("$NetBSD: t_swapcontext.c,v 1.8 2018/02/28 21:29:10 uwe Exp $");
 
 #include 
 #include 



CVS commit: src/tests/lib/libpthread

2018-02-27 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Feb 27 20:34:04 UTC 2018

Modified Files:
src/tests/lib/libpthread: t_swapcontext.c

Log Message:
threadfunc - we do return from swapcontext() (since revision 1.2),
so drop the NOTREACHED comment.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libpthread/t_swapcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_swapcontext.c
diff -u src/tests/lib/libpthread/t_swapcontext.c:1.6 src/tests/lib/libpthread/t_swapcontext.c:1.7
--- src/tests/lib/libpthread/t_swapcontext.c:1.6	Tue Feb 27 20:31:35 2018
+++ src/tests/lib/libpthread/t_swapcontext.c	Tue Feb 27 20:34:04 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.6 2018/02/27 20:31:35 uwe Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.7 2018/02/27 20:34:04 uwe Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -82,7 +82,6 @@ threadfunc(void *arg)
 	ATF_REQUIRE_MSG(swapcontext(&octx, &nctx) != -1, "swapcontext failed: %s",
 	strerror(errno));
 
-	/* NOTREACHED */
 	return NULL;
 }
 



CVS commit: src/tests/lib/libpthread

2018-02-27 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Feb 27 20:31:35 UTC 2018

Modified Files:
src/tests/lib/libpthread: t_swapcontext.c

Log Message:
swapfunc() is not passed to pthread_create, there's no need for it to
have any arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libpthread/t_swapcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_swapcontext.c
diff -u src/tests/lib/libpthread/t_swapcontext.c:1.5 src/tests/lib/libpthread/t_swapcontext.c:1.6
--- src/tests/lib/libpthread/t_swapcontext.c:1.5	Tue Feb 27 20:24:50 2018
+++ src/tests/lib/libpthread/t_swapcontext.c	Tue Feb 27 20:31:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.5 2018/02/27 20:24:50 uwe Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.6 2018/02/27 20:31:35 uwe Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -49,9 +49,8 @@ void *oself;
 void *nself;
 int val1, val2;
 
-/* ARGSUSED0 */
 static void
-swapfunc(void *arg)
+swapfunc(void)
 {
 	/*
 	 * If the test fails, we are very likely to crash



CVS commit: src/tests/lib/libpthread

2018-02-27 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Feb 27 20:24:50 UTC 2018

Modified Files:
src/tests/lib/libpthread: t_swapcontext.c

Log Message:
Drop unnecessary cast to makecontext() argument.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libpthread/t_swapcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_swapcontext.c
diff -u src/tests/lib/libpthread/t_swapcontext.c:1.4 src/tests/lib/libpthread/t_swapcontext.c:1.5
--- src/tests/lib/libpthread/t_swapcontext.c:1.4	Tue Feb 27 20:22:31 2018
+++ src/tests/lib/libpthread/t_swapcontext.c	Tue Feb 27 20:24:50 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.4 2018/02/27 20:22:31 uwe Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.5 2018/02/27 20:24:50 uwe Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -76,7 +76,7 @@ threadfunc(void *arg)
 	nctx.uc_stack.ss_sp = stack;
 	nctx.uc_stack.ss_size = sizeof(stack);
 
-	makecontext(&nctx, (void *)*swapfunc, 0);
+	makecontext(&nctx, swapfunc, 0);
 
 	oself = (void *)pthread_self();
 	printf("before swapcontext self = %p\n", oself);



CVS commit: src/tests/lib/libpthread

2018-02-27 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Feb 27 20:22:31 UTC 2018

Modified Files:
src/tests/lib/libpthread: t_swapcontext.c

Log Message:
Cleanup trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libpthread/t_swapcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_swapcontext.c
diff -u src/tests/lib/libpthread/t_swapcontext.c:1.3 src/tests/lib/libpthread/t_swapcontext.c:1.4
--- src/tests/lib/libpthread/t_swapcontext.c:1.3	Mon Jan 16 16:27:06 2017
+++ src/tests/lib/libpthread/t_swapcontext.c	Tue Feb 27 20:22:31 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.3 2017/01/16 16:27:06 christos Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.4 2018/02/27 20:22:31 uwe Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -54,9 +54,9 @@ static void
 swapfunc(void *arg)
 {
 	/*
-	 * If the test fails, we are very likely to crash 
+	 * If the test fails, we are very likely to crash
 	 * without the opportunity to report
-	 */ 
+	 */
 	nself = (void *)pthread_self();
 	printf("after swapcontext self = %p\n", nself);
 
@@ -75,9 +75,9 @@ threadfunc(void *arg)
 {
 	nctx.uc_stack.ss_sp = stack;
 	nctx.uc_stack.ss_size = sizeof(stack);
-   
+
 	makecontext(&nctx, (void *)*swapfunc, 0);
-   
+
 	oself = (void *)pthread_self();
 	printf("before swapcontext self = %p\n", oself);
 	ATF_REQUIRE_MSG(swapcontext(&octx, &nctx) != -1, "swapcontext failed: %s",



CVS commit: src/tests/lib/libpthread

2017-12-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Dec  1 13:25:30 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
Since there has been no objection (or even comment) in response
to my message on tech-userlevel ...

Subject: tests/lib/libpthread/t_mutex:mutex6
Date: Thu, 23 Nov 2017 17:34:54 +0700
Message-ID: <28385.1511433...@andromeda.noi.kre.to>

which can be found at:
http://mail-index.netbsd.org/tech-userlevel/2017/11/23/msg011010.html

which analysed the mutex6 test case of this test, and concluded
that it was useless, nonsense, and broken (the whole test is just a
race - not even really using or testing mutexes), let it be henceforth
forever gone.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.18 src/tests/lib/libpthread/t_mutex.c:1.19
--- src/tests/lib/libpthread/t_mutex.c:1.18	Sat Apr  1 17:19:40 2017
+++ src/tests/lib/libpthread/t_mutex.c	Fri Dec  1 13:25:29 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.18 2017/04/01 17:19:40 martin Exp $ */
+/* $NetBSD: t_mutex.c,v 1.19 2017/12/01 13:25:29 kre Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.18 2017/04/01 17:19:40 martin Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.19 2017/12/01 13:25:29 kre Exp $");
 
 #include  /* For timespecadd */
 #include  /* For UINT16_MAX */
@@ -371,131 +371,6 @@ ATF_TC_BODY(mutex5, tc)
 	PTHREAD_REQUIRE(pthread_join(child, NULL));
 }
 
-static int start = 0;
-static uintmax_t high_cnt = 0, low_cnt = 0, MAX_LOOP = 1;
-
-static void *
-high_prio(void* arg)
-{
-	struct sched_param param;
-	int policy;
-	param.sched_priority = min_fifo_prio + 10;
-	pthread_t childid = pthread_self();
-
-	PTHREAD_REQUIRE(pthread_setschedparam(childid, 1, ¶m));
-	PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, ¶m));
-	printf("high protect = %d, prio = %d\n",
-	_sched_protect(-2), param.sched_priority);
-	ATF_REQUIRE_EQ(policy, 1);
-	printf("high prio = %d\n", param.sched_priority);
-	sleep(1);
-	long tmp = 0;
-	for (int i = 0; i < 20; i++) {
-		while (high_cnt < MAX_LOOP) {
-			tmp += (123456789 % 1234) * (987654321 % 54321);
-			high_cnt += 1;
-		}
-		high_cnt = 0;
-		sleep(1);
-	}
-	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
-	if (start == 0) start = 2;
-	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
-
-	return 0;
-}
-
-static void *
-low_prio(void* arg)
-{
-	struct sched_param param;
-	int policy;
-	param.sched_priority = min_fifo_prio;
-	pthread_t childid = pthread_self();
-	int res = _sched_protect(max_fifo_prio);
-	ATF_REQUIRE_EQ(res, 0);
-	PTHREAD_REQUIRE(pthread_setschedparam(childid, 1, ¶m));
-	PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, ¶m));
-	printf("low protect = %d, prio = %d\n", _sched_protect(-2),
-	param.sched_priority);
-	ATF_REQUIRE_EQ(policy, 1);
-	printf("low prio = %d\n", param.sched_priority);
-	sleep(1);
-	long tmp = 0;
-	for (int i = 0; i < 20; i++) {
-		while (low_cnt < MAX_LOOP) {
-			tmp += (123456789 % 1234) * (987654321 % 54321);
-			low_cnt += 1;
-		}
-		low_cnt = 0;
-		sleep(1);
-	}
-	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
-	if (start == 0)
-		start = 1;
-	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
-
-	return 0;
-}
-
-ATF_TC(mutex6);
-ATF_TC_HEAD(mutex6, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	"Checks scheduling for priority ceiling");
-	atf_tc_set_md_var(tc, "require.user", "root");
-}
-
-/*
- * 1. main thread sets itself to be a realtime task and launched two tasks,
- *one has higher priority and the other has lower priority.
- * 2. each child thread(low and high priority thread) sets its scheduler and
- *priority.
- * 3. each child thread did several rounds of computation, after each round it
- *sleep 1 second.
- * 4. the child thread with low priority will call _sched_protect to increase
- *its protect priority.
- * 5. We verify the thread with low priority runs first.
- *
- * Why does it work? From the main thread, we launched the high
- * priority thread first. This gives this thread the benefit of
- * starting first. The low priority thread did not call _sched_protect(2).
- * The high priority thread should finish the task first. After each
- * round of computation, we call sleep, to put the task into the
- * sleep queue, and wake up again after the timer expires. This
- * gives the scheduler the chance to decide which task to run. So,
- * the thread with real high priority will always block the thread
- * with real low priority.
- * 
- */
-ATF_TC_BODY(mutex6, tc)
-{
-	struct sched_param param;
-	int res;
-	pthread_t high, low;
-

CVS commit: src/tests/lib/libpthread

2017-08-25 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Fri Aug 25 22:59:47 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_once.c

Log Message:
PR/49003: Ngie Cooper: add 


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_once.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_once.c
diff -u src/tests/lib/libpthread/t_once.c:1.1 src/tests/lib/libpthread/t_once.c:1.2
--- src/tests/lib/libpthread/t_once.c:1.1	Fri Jul 16 15:42:53 2010
+++ src/tests/lib/libpthread/t_once.c	Fri Aug 25 22:59:47 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_once.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
+/* $NetBSD: t_once.c,v 1.2 2017/08/25 22:59:47 ginsbach Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,8 +29,9 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_once.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
+__RCSID("$NetBSD: t_once.c,v 1.2 2017/08/25 22:59:47 ginsbach Exp $");
 
+#include 
 #include 
 #include 
 #include 



CVS commit: src/tests/lib/libpthread

2017-04-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Apr  1 17:19:40 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
Make the mutex6 test (which fails every know and then, but too rarely
to actually debug it) print some debug info when failing.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.17 src/tests/lib/libpthread/t_mutex.c:1.18
--- src/tests/lib/libpthread/t_mutex.c:1.17	Thu Mar 23 08:31:00 2017
+++ src/tests/lib/libpthread/t_mutex.c	Sat Apr  1 17:19:40 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.17 2017/03/23 08:31:00 martin Exp $ */
+/* $NetBSD: t_mutex.c,v 1.18 2017/04/01 17:19:40 martin Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.17 2017/03/23 08:31:00 martin Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.18 2017/04/01 17:19:40 martin Exp $");
 
 #include  /* For timespecadd */
 #include  /* For UINT16_MAX */
@@ -492,7 +492,8 @@ ATF_TC_BODY(mutex6, tc)
 	PTHREAD_REQUIRE(pthread_join(low, NULL));
 	PTHREAD_REQUIRE(pthread_join(high, NULL));
 	
-	ATF_REQUIRE_EQ(start, 1);
+	ATF_REQUIRE_EQ_MSG(start, 1, "start = %d, low_cnt =%ju, "
+	"high_cnt = %ju\n", start, high_cnt, low_cnt);
 }
 
 ATF_TC(mutexattr1);



CVS commit: src/tests/lib/libpthread

2017-03-23 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Mar 23 08:31:00 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
Avoid using an uninitialized mutex.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.16 src/tests/lib/libpthread/t_mutex.c:1.17
--- src/tests/lib/libpthread/t_mutex.c:1.16	Sun Mar  5 16:08:23 2017
+++ src/tests/lib/libpthread/t_mutex.c	Thu Mar 23 08:31:00 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.16 2017/03/05 16:08:23 chs Exp $ */
+/* $NetBSD: t_mutex.c,v 1.17 2017/03/23 08:31:00 martin Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.16 2017/03/05 16:08:23 chs Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.17 2017/03/23 08:31:00 martin Exp $");
 
 #include  /* For timespecadd */
 #include  /* For UINT16_MAX */
@@ -371,7 +371,6 @@ ATF_TC_BODY(mutex5, tc)
 	PTHREAD_REQUIRE(pthread_join(child, NULL));
 }
 
-static pthread_mutex_t mutex6;
 static int start = 0;
 static uintmax_t high_cnt = 0, low_cnt = 0, MAX_LOOP = 1;
 
@@ -399,9 +398,9 @@ high_prio(void* arg)
 		high_cnt = 0;
 		sleep(1);
 	}
-	PTHREAD_REQUIRE(mutex_lock(&mutex6, &ts_lengthy));
+	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 	if (start == 0) start = 2;
-	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex6));
+	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
 
 	return 0;
 }
@@ -431,10 +430,10 @@ low_prio(void* arg)
 		low_cnt = 0;
 		sleep(1);
 	}
-	PTHREAD_REQUIRE(mutex_lock(&mutex6, &ts_lengthy));
+	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 	if (start == 0)
 		start = 1;
-	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex6));
+	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
 
 	return 0;
 }



CVS commit: src/tests/lib/libpthread

2017-03-05 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Mar  5 16:08:23 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
reenable mutex2 and mutex3 on powerpc now that PR 44387 is fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.15 src/tests/lib/libpthread/t_mutex.c:1.16
--- src/tests/lib/libpthread/t_mutex.c:1.15	Mon Jan 16 16:23:41 2017
+++ src/tests/lib/libpthread/t_mutex.c	Sun Mar  5 16:08:23 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $ */
+/* $NetBSD: t_mutex.c,v 1.16 2017/03/05 16:08:23 chs Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.16 2017/03/05 16:08:23 chs Exp $");
 
 #include  /* For timespecadd */
 #include  /* For UINT16_MAX */
@@ -148,9 +148,6 @@ ATF_TC(mutex2);
 ATF_TC_HEAD(mutex2, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes");
-#if defined(__powerpc__)
-	atf_tc_set_md_var(tc, "timeout", "40");
-#endif
 }
 ATF_TC_BODY(mutex2, tc)
 {
@@ -160,10 +157,6 @@ ATF_TC_BODY(mutex2, tc)
 
 	printf("1: Mutex-test 2\n");
 
-#if defined(__powerpc__)
-	atf_tc_expect_timeout("PR port-powerpc/44387");
-#endif
-
 	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
 	
 	global_x = 0;
@@ -188,14 +181,6 @@ ATF_TC_BODY(mutex2, tc)
 	printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
 		global_x, (long)joinval);
 	ATF_REQUIRE_EQ(global_x, 2000);
-
-#if defined(__powerpc__)
-	/* XXX force a timeout in ppc case since an un-triggered race
-	   otherwise looks like a "failure" */
-	/* We sleep for longer than the timeout to make ATF not
-	   complain about unexpected success */
-	sleep(41);
-#endif
 }
 
 static void *
@@ -219,9 +204,6 @@ ATF_TC_HEAD(mutex3, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes using a static "
 	"initializer");
-#if defined(__powerpc__)
-	atf_tc_set_md_var(tc, "timeout", "40");
-#endif
 }
 ATF_TC_BODY(mutex3, tc)
 {
@@ -231,10 +213,6 @@ ATF_TC_BODY(mutex3, tc)
 
 	printf("1: Mutex-test 3\n");
 
-#if defined(__powerpc__)
-	atf_tc_expect_timeout("PR port-powerpc/44387");
-#endif
-
 	global_x = 0;
 	count = count2 = 1000;
 
@@ -257,14 +235,6 @@ ATF_TC_BODY(mutex3, tc)
 	printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
 		global_x, (long)joinval);
 	ATF_REQUIRE_EQ(global_x, 2000);
-
-#if defined(__powerpc__)
-	/* XXX force a timeout in ppc case since an un-triggered race
-	   otherwise looks like a "failure" */
-	/* We sleep for longer than the timeout to make ATF not
-	   complain about unexpected success */
-	sleep(41);
-#endif
 }
 
 static void *



CVS commit: src/tests/lib/libpthread

2017-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 16 19:07:06 UTC 2017

Modified Files:
src/tests/lib/libpthread: h_common.h

Log Message:
beware of your shadow


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/h_common.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/h_common.h
diff -u src/tests/lib/libpthread/h_common.h:1.2 src/tests/lib/libpthread/h_common.h:1.3
--- src/tests/lib/libpthread/h_common.h:1.2	Sun Oct 30 12:17:16 2016
+++ src/tests/lib/libpthread/h_common.h	Mon Jan 16 14:07:06 2017
@@ -5,14 +5,14 @@
 
 #define PTHREAD_REQUIRE(x) \
 do { \
-int ret = (x); \
-ATF_REQUIRE_MSG(ret == 0, "%s: %s", #x, strerror(ret)); \
+int _ret = (x); \
+ATF_REQUIRE_MSG(_ret == 0, "%s: %s", #x, strerror(_ret)); \
 } while (0)
 
 #define PTHREAD_REQUIRE_STATUS(x, v) \
 do { \
-int ret = (x); \
-ATF_REQUIRE_MSG(ret == (v), "%s: %s", #x, strerror(ret)); \
+int _ret = (x); \
+ATF_REQUIRE_MSG(_ret == (v), "%s: %s", #x, strerror(_ret)); \
 } while (0)
 
 #endif // H_COMMON_H



CVS commit: src/tests/lib/libpthread

2017-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 16 16:29:54 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_detach.c

Log Message:
PR/51885: Ngie Cooper: Add delays to avoid races.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_detach.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_detach.c
diff -u src/tests/lib/libpthread/t_detach.c:1.1 src/tests/lib/libpthread/t_detach.c:1.2
--- src/tests/lib/libpthread/t_detach.c:1.1	Thu Mar 24 09:52:04 2011
+++ src/tests/lib/libpthread/t_detach.c	Mon Jan 16 11:29:54 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $ */
+/* $NetBSD: t_detach.c,v 1.2 2017/01/16 16:29:54 christos Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,10 +29,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_detach.c,v 1.1 2011/03/24 13:52:04 jruoho Exp $");
+__RCSID("$NetBSD: t_detach.c,v 1.2 2017/01/16 16:29:54 christos Exp $");
 
-#include 
 #include 
+#include 
+#include 
 
 #include 
 
@@ -43,6 +44,7 @@ static void	*func(void *);
 static void *
 func(void *arg)
 {
+	sleep(2);
 	return NULL;
 }
 
@@ -72,14 +74,17 @@ ATF_TC_BODY(pthread_detach, tc)
 	 */
 	PTHREAD_REQUIRE(pthread_detach(t));
 
+	sleep(1);
 	rv = pthread_join(t, NULL);
 	ATF_REQUIRE(rv == EINVAL);
 
+	sleep(3);
+
 	/*
 	 * As usual, ESRCH should follow if
 	 * we try to detach an invalid thread.
 	 */
-	rv = pthread_cancel(NULL);
+	rv = pthread_cancel(t);
 	ATF_REQUIRE(rv == ESRCH);
 }
 



CVS commit: src/tests/lib/libpthread

2017-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 16 16:29:19 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_condwait.c

Log Message:
PR/51884: Ngie Cooper: Include and message fixes


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libpthread/t_condwait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_condwait.c
diff -u src/tests/lib/libpthread/t_condwait.c:1.4 src/tests/lib/libpthread/t_condwait.c:1.5
--- src/tests/lib/libpthread/t_condwait.c:1.4	Fri Apr 12 13:18:11 2013
+++ src/tests/lib/libpthread/t_condwait.c	Mon Jan 16 11:29:19 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $ */
+/* $NetBSD: t_condwait.c,v 1.5 2017/01/16 16:29:19 christos Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -26,8 +26,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $");
+__RCSID("$NetBSD: t_condwait.c,v 1.5 2017/01/16 16:29:19 christos Exp $");
 
+#include 
 #include 
 #include 
 #include 
@@ -40,6 +41,8 @@ __RCSID("$NetBSD: t_condwait.c,v 1.4 201
 
 #include "isqemu.h"
 
+#include "h_common.h"
+
 #define WAITTIME 2	/* Timeout wait secound */
 
 static const int debug = 1;
@@ -56,8 +59,8 @@ run(void *param)
 
 
 	clck = *(clockid_t *)param;
-	pthread_condattr_init(&attr);
-	pthread_condattr_setclock(&attr, clck); /* MONOTONIC or MONOTONIC */
+	PTHREAD_REQUIRE(pthread_condattr_init(&attr));
+	PTHREAD_REQUIRE(pthread_condattr_setclock(&attr, clck));
 	pthread_cond_init(&cond, &attr);
 
 	ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0);



CVS commit: src/tests/lib/libpthread

2017-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 16 16:28:27 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_fork.c

Log Message:
PR/51886: Ngie Cooper: Use _exit instead of exit


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_fork.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_fork.c
diff -u src/tests/lib/libpthread/t_fork.c:1.1 src/tests/lib/libpthread/t_fork.c:1.2
--- src/tests/lib/libpthread/t_fork.c:1.1	Fri Jul 16 11:42:53 2010
+++ src/tests/lib/libpthread/t_fork.c	Mon Jan 16 11:28:27 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fork.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
+/* $NetBSD: t_fork.c,v 1.2 2017/01/16 16:28:27 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_fork.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
+__RCSID("$NetBSD: t_fork.c,v 1.2 2017/01/16 16:28:27 christos Exp $");
 
 /*
  * Written by Love Hörnquist Åstrand , March 2003.
@@ -61,7 +61,7 @@ print_pid(void *arg)
 
 	thread_survived = 1;
 	if (parent != getpid()) {
-		exit(1);
+		_exit(1);
 	}
 	return NULL;
 }
@@ -95,7 +95,7 @@ ATF_TC_BODY(fork, tc)
 		ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), 0, "thread survived in child");
 	} else {
 		sleep(5);
-		exit(thread_survived ? 1 : 0);
+		_exit(thread_survived ? 1 : 0);
 	}
 }
 



CVS commit: src/tests/lib/libpthread

2017-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 16 16:27:43 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_fpu.c

Log Message:
PR/51887: Ngie Cooper: Include and error message fixes


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/t_fpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_fpu.c
diff -u src/tests/lib/libpthread/t_fpu.c:1.2 src/tests/lib/libpthread/t_fpu.c:1.3
--- src/tests/lib/libpthread/t_fpu.c:1.2	Sun Jan 27 09:47:37 2013
+++ src/tests/lib/libpthread/t_fpu.c	Mon Jan 16 11:27:43 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $ */
+/* $NetBSD: t_fpu.c,v 1.3 2017/01/16 16:27:43 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/27 14:47:37 mbalmer Exp $");
+__RCSID("$NetBSD: t_fpu.c,v 1.3 2017/01/16 16:27:43 christos Exp $");
 
 /*
  * This is adapted from part of csw/cstest of the MPD implementation by
@@ -49,10 +49,12 @@ __RCSID("$NetBSD: t_fpu.c,v 1.2 2013/01/
  * .
  */
 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -77,14 +79,16 @@ stir(void *p)
 
 	for (;;) {
 		x = sin ((y = cos (x + y + .4)) - (z = cos (x + z + .6)));
-		PTHREAD_REQUIRE(sched_yield());
+		ATF_REQUIRE_MSG(sched_yield() == 0,
+		"sched_yield failed: %s", strerror(errno));
 	}
 }
 
 static double
 mul3(double x, double y, double z)
 {
-	PTHREAD_REQUIRE(sched_yield());
+	ATF_REQUIRE_MSG(sched_yield() == 0,
+	"sched_yield failed: %s", strerror(errno));
 
 	return x * y * z;
 }
@@ -114,7 +118,7 @@ bar(void *p)
 static void
 recurse(void) {
 	pthread_t s2;
-	pthread_create(&s2, 0, bar, 0);
+	PTHREAD_REQUIRE(pthread_create(&s2, 0, bar, 0));
 	sleep(20); /* XXX must be long enough for our slowest machine */
 }
 
@@ -134,7 +138,7 @@ ATF_TC_BODY(fpu, tc)
 
 	PTHREAD_REQUIRE(pthread_mutex_init(&recursion_depth_lock, 0));
 
-	pthread_create(&s5, 0, stir, stirseed);
+	PTHREAD_REQUIRE(pthread_create(&s5, 0, stir, stirseed));
 	recurse();
 
 	atf_tc_fail("exiting from main");



CVS commit: src/tests/lib/libpthread

2017-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 16 16:27:06 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_swapcontext.c

Log Message:
PR/51890: Ngie Cooper: include and error message fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/t_swapcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_swapcontext.c
diff -u src/tests/lib/libpthread/t_swapcontext.c:1.2 src/tests/lib/libpthread/t_swapcontext.c:1.3
--- src/tests/lib/libpthread/t_swapcontext.c:1.2	Mon Aug 25 12:31:15 2014
+++ src/tests/lib/libpthread/t_swapcontext.c	Mon Jan 16 11:27:06 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.2 2014/08/25 16:31:15 bouyer Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.3 2017/01/16 16:27:06 christos Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -28,10 +28,13 @@
 #include 
 __RCSID("$NetBSD");
 
+#include 
+#include 
 #include 
-#include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 
@@ -77,7 +80,8 @@ threadfunc(void *arg)

 	oself = (void *)pthread_self();
 	printf("before swapcontext self = %p\n", oself);
-	PTHREAD_REQUIRE(swapcontext(&octx, &nctx));
+	ATF_REQUIRE_MSG(swapcontext(&octx, &nctx) != -1, "swapcontext failed: %s",
+	strerror(errno));
 
 	/* NOTREACHED */
 	return NULL;
@@ -99,7 +103,8 @@ ATF_TC_BODY(swapcontext1, tc)
 
 	printf("Testing if swapcontext() alters pthread_self()\n");
 
-	PTHREAD_REQUIRE(getcontext(&nctx));
+	ATF_REQUIRE_MSG(getcontext(&nctx) != -1, "getcontext failed: %s",
+	strerror(errno));
 	PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL));
 	PTHREAD_REQUIRE(pthread_join(thread, NULL));
 }



CVS commit: src/tests/lib/libpthread

2017-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 16 16:23:41 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
PR/51888: Ngie Cooper: more error checking, missing includes


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.14 src/tests/lib/libpthread/t_mutex.c:1.15
--- src/tests/lib/libpthread/t_mutex.c:1.14	Mon Oct 31 19:51:20 2016
+++ src/tests/lib/libpthread/t_mutex.c	Mon Jan 16 11:23:41 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $ */
+/* $NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,8 +29,10 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $");
 
+#include  /* For timespecadd */
+#include  /* For UINT16_MAX */
 #include 
 #include 
 #include 
@@ -570,9 +572,16 @@ ATF_TC_BODY(mutexattr2, tc)
 	int min_prio = sched_get_priority_min(SCHED_FIFO);
 	for (int i = min_prio; i <= max_prio; i++) {
 		int prioceiling;
+		int protocol;
+
+		PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr,
+		&protocol));
+
+		printf("priority: %d\nprotocol: %d\n", i, protocol);
 		PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&mattr, i));
 		PTHREAD_REQUIRE(pthread_mutexattr_getprioceiling(&mattr,
 		&prioceiling));
+		printf("prioceiling: %d\n", prioceiling);
 		ATF_REQUIRE_EQ(i, prioceiling);
 	}
 }



CVS commit: src/tests/lib/libpthread

2017-01-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 16 16:22:22 UTC 2017

Modified Files:
src/tests/lib/libpthread: t_sem.c

Log Message:
PR/51889: Ngie Cooper: add sys/time.h


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libpthread/t_sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_sem.c
diff -u src/tests/lib/libpthread/t_sem.c:1.8 src/tests/lib/libpthread/t_sem.c:1.9
--- src/tests/lib/libpthread/t_sem.c:1.8	Mon Nov  3 19:20:19 2014
+++ src/tests/lib/libpthread/t_sem.c	Mon Jan 16 11:22:22 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sem.c,v 1.8 2014/11/04 00:20:19 justin Exp $ */
+/* $NetBSD: t_sem.c,v 1.9 2017/01/16 16:22:22 christos Exp $ */
 
 /*
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -86,8 +86,9 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sem.c,v 1.8 2014/11/04 00:20:19 justin Exp $");
+__RCSID("$NetBSD: t_sem.c,v 1.9 2017/01/16 16:22:22 christos Exp $");
 
+#include 
 #include 
 #include 
 #include 



CVS commit: src/tests/lib/libpthread

2016-10-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 31 23:51:20 UTC 2016

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
more tests from kamil


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.13 src/tests/lib/libpthread/t_mutex.c:1.14
--- src/tests/lib/libpthread/t_mutex.c:1.13	Mon Oct 31 12:23:03 2016
+++ src/tests/lib/libpthread/t_mutex.c	Mon Oct 31 19:51:20 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.13 2016/10/31 16:23:03 christos Exp $ */
+/* $NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.13 2016/10/31 16:23:03 christos Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $");
 
 #include 
 #include 
@@ -591,14 +591,14 @@ ATF_TC_BODY(timedmutex1, tc)
 
 	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
 
-	printf("Before acquiring regular mutex\n");
+	printf("Before acquiring mutex\n");
 	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
 
 	printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
 	PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
 	ETIMEDOUT);
 
-	printf("Unlocking timed-mutex\n");
+	printf("Unlocking mutex\n");
 	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
 }
 
@@ -616,14 +616,80 @@ ATF_TC_BODY(timedmutex2, tc)
 
 	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
 
-	printf("Before acquiring timed-mutex with timedlock\n");
+	printf("Before acquiring mutex with timedlock\n");
 	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 
 	printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
 	PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
 	ETIMEDOUT);
 
-	printf("Unlocking timed-mutex\n");
+	printf("Unlocking mutex\n");
+	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+}
+
+ATF_TC(timedmutex3);
+ATF_TC_HEAD(timedmutex3, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Checks timeout on selflock in a new thread");
+}
+
+static void *
+timedmtx_thrdfunc(void *arg)
+{
+	printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
+	PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
+	ETIMEDOUT);
+
+	return NULL;
+}
+
+ATF_TC_BODY(timedmutex3, tc)
+{
+	pthread_t new;
+
+	printf("Timed mutex-test 3\n");
+
+	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
+	printf("Before acquiring mutex with timedlock\n");
+	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+
+	printf("Before creating new thread\n");
+	PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL));
+
+	printf("Before joining the mutex\n");
+	PTHREAD_REQUIRE(pthread_join(new, NULL));
+
+	printf("Unlocking mutex\n");
+	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+}
+
+ATF_TC(timedmutex4);
+ATF_TC_HEAD(timedmutex4, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Checks timeout on selflock with timedlock in a new thread");
+}
+
+ATF_TC_BODY(timedmutex4, tc)
+{
+	pthread_t new;
+
+	printf("Timed mutex-test 4\n");
+
+	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
+	printf("Before acquiring mutex with timedlock\n");
+	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
+
+	printf("Before creating new thread\n");
+	PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL));
+
+	printf("Before joining the mutex\n");
+	PTHREAD_REQUIRE(pthread_join(new, NULL));
+
+	printf("Unlocking mutex\n");
 	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
 }
 #endif
@@ -642,6 +708,8 @@ ATF_TP_ADD_TCS(tp)
 #ifdef TIMEDMUTEX
 	ATF_TP_ADD_TC(tp, timedmutex1);
 	ATF_TP_ADD_TC(tp, timedmutex2);
+	ATF_TP_ADD_TC(tp, timedmutex3);
+	ATF_TP_ADD_TC(tp, timedmutex4);
 #endif
 
 	return atf_no_error();



CVS commit: src/tests/lib/libpthread

2016-10-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 31 16:23:04 UTC 2016

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
fix typos


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.12 src/tests/lib/libpthread/t_mutex.c:1.13
--- src/tests/lib/libpthread/t_mutex.c:1.12	Mon Oct 31 12:21:23 2016
+++ src/tests/lib/libpthread/t_mutex.c	Mon Oct 31 12:23:03 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.12 2016/10/31 16:21:23 christos Exp $ */
+/* $NetBSD: t_mutex.c,v 1.13 2016/10/31 16:23:03 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.12 2016/10/31 16:21:23 christos Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.13 2016/10/31 16:23:03 christos Exp $");
 
 #include 
 #include 
@@ -591,7 +591,7 @@ ATF_TC_BODY(timedmutex1, tc)
 
 	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
 
-	printf("Before acquiring timed-mutex\n");
+	printf("Before acquiring regular mutex\n");
 	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
 
 	printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
@@ -612,14 +612,14 @@ ATF_TC_HEAD(timedmutex2, tc)
 ATF_TC_BODY(timedmutex2, tc)
 {
 
-	printf("Timed mutex-test 1\n");
+	printf("Timed mutex-test 2\n");
 
 	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
 
 	printf("Before acquiring timed-mutex with timedlock\n");
 	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 
-	printf("Before endavor to reacquire timed-mutex (timeout expected)\n");
+	printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
 	PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
 	ETIMEDOUT);
 



CVS commit: src/tests/lib/libpthread

2016-10-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 31 16:21:23 UTC 2016

Modified Files:
src/tests/lib/libpthread: t_mutex.c t_timedmutex.c

Log Message:
Merge and fix the timed mutex tests to use absolute time.
NB: the new tests are broken?


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/lib/libpthread/t_mutex.c
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_timedmutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.11 src/tests/lib/libpthread/t_mutex.c:1.12
--- src/tests/lib/libpthread/t_mutex.c:1.11	Sun Oct 30 12:17:16 2016
+++ src/tests/lib/libpthread/t_mutex.c	Mon Oct 31 12:21:23 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.11 2016/10/30 16:17:16 kamil Exp $ */
+/* $NetBSD: t_mutex.c,v 1.12 2016/10/31 16:21:23 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -26,17 +26,16 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* Please sync code from this test with t_timedmutex.c */
-
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.11 2016/10/30 16:17:16 kamil Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.12 2016/10/31 16:21:23 christos Exp $");
 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -49,6 +48,31 @@ static pthread_mutex_t mutex;
 static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
 static int global_x;
 
+#ifdef TIMEDMUTEX
+/* This code is used for verifying non-timed specific code */
+static struct timespec ts_lengthy = {
+	.tv_sec = UINT16_MAX,
+	.tv_nsec = 0
+};
+/* This code is used for verifying timed-only specific code */
+static struct timespec ts_shortlived = {
+	.tv_sec = 0,
+	.tv_nsec = 120
+};
+
+static int
+mutex_lock(pthread_mutex_t *m, const struct timespec *ts)
+{
+	struct timespec ts_wait;
+	ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &ts_wait) != -1);
+	timespecadd(&ts_wait, ts, &ts_wait);
+
+	return pthread_mutex_timedlock(m, &ts_wait);
+}
+#else
+#define mutex_lock(a, b) pthread_mutex_lock(a)
+#endif
+
 static void *
 mutex1_threadfunc(void *arg)
 {
@@ -58,7 +82,7 @@ mutex1_threadfunc(void *arg)
 
 	param = arg;
 	printf("2: Locking mutex\n");
-	pthread_mutex_lock(&mutex);
+	mutex_lock(&mutex, &ts_lengthy);
 	printf("2: Got mutex. *param = %d\n", *param);
 	ATF_REQUIRE_EQ(*param, 20);
 	(*param)++;
@@ -83,7 +107,7 @@ ATF_TC_BODY(mutex1, tc)
 
 	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
 	x = 1;
-	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 	PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex1_threadfunc, &x));
 	printf("1: Before changing the value.\n");
 	sleep(2);
@@ -94,7 +118,7 @@ ATF_TC_BODY(mutex1, tc)
 	printf("1: After releasing the mutex.\n");
 	PTHREAD_REQUIRE(pthread_join(new, &joinval));
 
-	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 	printf("1: Thread joined. X was %d. Return value (int) was %d\n",
 		x, *(int *)joinval);
 	ATF_REQUIRE_EQ(x, 21);
@@ -110,7 +134,7 @@ mutex2_threadfunc(void *arg)
 	printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
 
 	while (count--) {
-		PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+		PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 		global_x++;
 		PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
 	}
@@ -143,7 +167,7 @@ ATF_TC_BODY(mutex2, tc)
 	global_x = 0;
 	count = count2 = 1000;
 
-	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 	PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex2_threadfunc, &count2));
 
 	printf("1: Thread %p\n", pthread_self());
@@ -151,14 +175,14 @@ ATF_TC_BODY(mutex2, tc)
 	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
 
 	while (count--) {
-		PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+		PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 		global_x++;
 		PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
 	}
 
 	PTHREAD_REQUIRE(pthread_join(new, &joinval));
 
-	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+	PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
 	printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
 		global_x, (long)joinval);
 	ATF_REQUIRE_EQ(global_x, 2000);
@@ -180,7 +204,7 @@ mutex3_threadfunc(void *arg)
 	printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
 
 	while (count--) {
-		PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
+		PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
 		global_x++;
 		PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
 	}
@@ -212,7 +236,7 @@ ATF_TC_BODY(mutex3, tc)
 	global_x = 0;
 	count = count2 = 1000;
 
-	PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
+	PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
 	PTHREAD_REQ

CVS commit: src/tests/lib/libpthread

2016-07-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul 31 13:01:29 UTC 2016

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
we require root for sched_fifo, and more verbose messages.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.9 src/tests/lib/libpthread/t_mutex.c:1.10
--- src/tests/lib/libpthread/t_mutex.c:1.9	Wed Jul  6 10:42:53 2016
+++ src/tests/lib/libpthread/t_mutex.c	Sun Jul 31 09:01:29 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.9 2016/07/06 14:42:53 christos Exp $ */
+/* $NetBSD: t_mutex.c,v 1.10 2016/07/31 13:01:29 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.9 2016/07/06 14:42:53 christos Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.10 2016/07/31 13:01:29 christos Exp $");
 
 #include 
 #include 
@@ -318,7 +318,7 @@ child_func(void* arg)
 
 	printf("child is waiting\n");
 	res = _sched_protect(-2);
-	ATF_REQUIRE_EQ(res, -1);
+	ATF_REQUIRE_EQ_MSG(res, -1, "sched_protect returned %d", res);
 	ATF_REQUIRE_EQ(errno, ENOENT);
 	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex5));
 	printf("child is owning resource\n");
@@ -334,6 +334,7 @@ ATF_TC(mutex5);
 ATF_TC_HEAD(mutex5, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes for priority setting");
+	atf_tc_set_md_var(tc, "require.user", "root");
 }
 
 ATF_TC_BODY(mutex5, tc)
@@ -352,7 +353,8 @@ ATF_TC_BODY(mutex5, tc)
 	printf("previous policy used = %d\n", res);
 
 	res = sched_getscheduler(getpid());
-	ATF_REQUIRE_EQ(res, 1);
+	ATF_REQUIRE_EQ_MSG(res, SCHED_FIFO, "sched %d != FIFO %d", res, 
+	SCHED_FIFO);
 
 	PTHREAD_REQUIRE(pthread_mutexattr_init(&attr5));
 	PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&attr5,
@@ -444,6 +446,7 @@ ATF_TC_HEAD(mutex6, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"Checks scheduling for priority ceiling");
+	atf_tc_set_md_var(tc, "require.user", "root");
 }
 
 /*



CVS commit: src/tests/lib/libpthread

2016-07-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul  6 14:42:53 UTC 2016

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
fix uninitialized var.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.8 src/tests/lib/libpthread/t_mutex.c:1.9
--- src/tests/lib/libpthread/t_mutex.c:1.8	Sun Jul  3 10:24:59 2016
+++ src/tests/lib/libpthread/t_mutex.c	Wed Jul  6 10:42:53 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.8 2016/07/03 14:24:59 christos Exp $ */
+/* $NetBSD: t_mutex.c,v 1.9 2016/07/06 14:42:53 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.8 2016/07/03 14:24:59 christos Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.9 2016/07/06 14:42:53 christos Exp $");
 
 #include 
 #include 
@@ -346,6 +346,7 @@ ATF_TC_BODY(mutex5, tc)
 	max_fifo_prio = sched_get_priority_max(SCHED_FIFO);
 	printf("min prio for FIFO = %d\n", min_fifo_prio);
 	param.sched_priority = min_fifo_prio;
+
 	/* = 0 OTHER, 1 FIFO, 2 RR, -1 NONE */
 	res = sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
 	printf("previous policy used = %d\n", res);
@@ -389,9 +390,8 @@ high_prio(void* arg)
 	ATF_REQUIRE_EQ(policy, 1);
 	printf("high prio = %d\n", param.sched_priority);
 	sleep(1);
-	int i;
 	long tmp = 0;
-	for (i = 0; i<20; i++) {
+	for (int i = 0; i < 20; i++) {
 		while (high_cnt < MAX_LOOP) {
 			tmp += (123456789 % 1234) * (987654321 % 54321);
 			high_cnt += 1;
@@ -422,9 +422,9 @@ low_prio(void* arg)
 	ATF_REQUIRE_EQ(policy, 1);
 	printf("low prio = %d\n", param.sched_priority);
 	sleep(1);
+	long tmp = 0;
 	for (int i = 0; i < 20; i++) {
 		while (low_cnt < MAX_LOOP) {
-			long tmp;
 			tmp += (123456789 % 1234) * (987654321 % 54321);
 			low_cnt += 1;
 		}
@@ -470,14 +470,16 @@ ATF_TC_HEAD(mutex6, tc)
  */
 ATF_TC_BODY(mutex6, tc)
 {
+	struct sched_param param;
 	int res;
 	pthread_t high, low;
+
 	min_fifo_prio = sched_get_priority_min(SCHED_FIFO);
 	max_fifo_prio = sched_get_priority_max(SCHED_FIFO);
 	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
 	printf("min_fifo_prio = %d, max_fifo_info = %d\n", min_fifo_prio,
 	max_fifo_prio);
-	struct sched_param param;
+
 	param.sched_priority = min_fifo_prio;
 	res = sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
 	printf("previous policy used = %d\n", res);



CVS commit: src/tests/lib/libpthread

2015-06-26 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Jun 26 11:07:20 UTC 2015

Modified Files:
src/tests/lib/libpthread: t_rwlock.c

Log Message:
Check that PTHREAD_RWLOCK_INITIALIZER works.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_rwlock.c
diff -u src/tests/lib/libpthread/t_rwlock.c:1.1 src/tests/lib/libpthread/t_rwlock.c:1.2
--- src/tests/lib/libpthread/t_rwlock.c:1.1	Fri Jul 16 15:42:53 2010
+++ src/tests/lib/libpthread/t_rwlock.c	Fri Jun 26 11:07:20 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_rwlock.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
+/* $NetBSD: t_rwlock.c,v 1.2 2015/06/26 11:07:20 pooka Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_rwlock.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
+__RCSID("$NetBSD: t_rwlock.c,v 1.2 2015/06/26 11:07:20 pooka Exp $");
 
 #include 
 #include 
@@ -70,6 +70,8 @@ pthread_rwlock_t lk;
 
 struct timespec to;
 
+static pthread_rwlock_t static_rwlock = PTHREAD_RWLOCK_INITIALIZER;
+
 /* ARGSUSED */
 static void *
 do_nothing(void *dummy)
@@ -117,9 +119,23 @@ ATF_TC_BODY(rwlock1, tc)
 		"%s", strerror(error));
 }
 
+ATF_TC(rwlock_static);
+ATF_TC_HEAD(rwlock_static, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "rwlock w/ static initializer");
+}
+ATF_TC_BODY(rwlock_static, tc)
+{
+
+	PTHREAD_REQUIRE(pthread_rwlock_rdlock(&static_rwlock));
+	PTHREAD_REQUIRE(pthread_rwlock_unlock(&static_rwlock));
+	PTHREAD_REQUIRE(pthread_rwlock_destroy(&static_rwlock));
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, rwlock1);
+	ATF_TP_ADD_TC(tp, rwlock_static);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libpthread

2014-09-03 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Wed Sep  3 16:23:25 UTC 2014

Modified Files:
src/tests/lib/libpthread: t_cond.c

Log Message:
The cond_timedwait_race test case is no longer expected to fail; it
has been consistently passing since CVS date 2014.01.31.19.22.00.
See also PR lib/44756.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libpthread/t_cond.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_cond.c
diff -u src/tests/lib/libpthread/t_cond.c:1.5 src/tests/lib/libpthread/t_cond.c:1.6
--- src/tests/lib/libpthread/t_cond.c:1.5	Sat Oct 19 17:45:01 2013
+++ src/tests/lib/libpthread/t_cond.c	Wed Sep  3 16:23:24 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cond.c,v 1.5 2013/10/19 17:45:01 christos Exp $ */
+/* $NetBSD: t_cond.c,v 1.6 2014/09/03 16:23:24 gson Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_cond.c,v 1.5 2013/10/19 17:45:01 christos Exp $");
+__RCSID("$NetBSD: t_cond.c,v 1.6 2014/09/03 16:23:24 gson Exp $");
 
 #include 
 
@@ -343,25 +343,17 @@ ATF_TC_HEAD(cond_timedwait_race, tc)
 ATF_TC_BODY(cond_timedwait_race, tc)
 {
 	pthread_t tid[64];
-	size_t i, j;
+	size_t i;
 
-	atf_tc_expect_fail("PR lib/44756");
-	/* This outer loop is to ensure that a false positive of this race
-	 * test does not report the test as broken (due to the test not
-	 * triggering the expected failure).  However, we want to make this
-	 * fail consistently when the race is resolved, and this approach
-	 * will have the desired effect. */
-	for (j = 0; j < 10; j++ ) {
-		for (i = 0; i < __arraycount(tid); i++) {
-
-			PTHREAD_REQUIRE(pthread_create(&tid[i], NULL,
-			pthread_cond_timedwait_func, NULL));
-		}
+	for (i = 0; i < __arraycount(tid); i++) {
 
-		for (i = 0; i < __arraycount(tid); i++) {
+		PTHREAD_REQUIRE(pthread_create(&tid[i], NULL,
+		pthread_cond_timedwait_func, NULL));
+	}
+
+	for (i = 0; i < __arraycount(tid); i++) {
 
-			PTHREAD_REQUIRE(pthread_join(tid[i], NULL));
-		}
+		PTHREAD_REQUIRE(pthread_join(tid[i], NULL));
 	}
 }
 



CVS commit: src/tests/lib/libpthread

2014-08-25 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Aug 25 16:31:15 UTC 2014

Modified Files:
src/tests/lib/libpthread: t_swapcontext.c

Log Message:
Go back to the initial context (as tests/lib/libc/sys/t_swapcontext.c does)
after checking pthread_self() didn't change. Otherwise the process exits
outside of atf context.
Should fix "Test case exited normally but failed to create the results file: 
Results file is empty" reports from atf-run.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_swapcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_swapcontext.c
diff -u src/tests/lib/libpthread/t_swapcontext.c:1.1 src/tests/lib/libpthread/t_swapcontext.c:1.2
--- src/tests/lib/libpthread/t_swapcontext.c:1.1	Wed Sep 12 02:00:55 2012
+++ src/tests/lib/libpthread/t_swapcontext.c	Mon Aug 25 16:31:15 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.1 2012/09/12 02:00:55 manu Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.2 2014/08/25 16:31:15 bouyer Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -59,6 +59,8 @@ swapfunc(void *arg)
 
 	ATF_REQUIRE_EQ(oself, nself);
 	printf("Test succeeded\n");
+	/* Go back in main */
+	ATF_REQUIRE(swapcontext(&nctx, &octx));
 
 	/* NOTREACHED */
 	return;
@@ -99,8 +101,7 @@ ATF_TC_BODY(swapcontext1, tc)
 
 	PTHREAD_REQUIRE(getcontext(&nctx));
 	PTHREAD_REQUIRE(pthread_create(&thread, NULL, threadfunc, NULL));
-	
-	return;
+	PTHREAD_REQUIRE(pthread_join(thread, NULL));
 }
 
 ATF_TP_ADD_TCS(tp)



CVS commit: src/tests/lib/libpthread

2013-04-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr 12 17:18:11 UTC 2013

Modified Files:
src/tests/lib/libpthread: Makefile t_condwait.c

Log Message:
loosen the test only for qemu.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libpthread/Makefile
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libpthread/t_condwait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/Makefile
diff -u src/tests/lib/libpthread/Makefile:1.10 src/tests/lib/libpthread/Makefile:1.11
--- src/tests/lib/libpthread/Makefile:1.10	Thu Mar 28 14:50:01 2013
+++ src/tests/lib/libpthread/Makefile	Fri Apr 12 13:18:11 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2013/03/28 18:50:01 christos Exp $
+# $NetBSD: Makefile,v 1.11 2013/04/12 17:18:11 christos Exp $
 
 NOMAN=		# defined
 
@@ -12,6 +12,7 @@ LDADD.t_fpu+=	-lm
 
 SRCS.t_join=	t_join.c ${SRCS_CHECK_STACK}
 CPPFLAGS.t_join.c+=	${CPPFLAGS_CHECK_STACK}
+CPPFLAGS.t_condwait.c+=	-I${.CURDIR}/../libc/gen
 
 TESTS_SH+=	t_atexit
 TESTS_C+=	t_barrier

Index: src/tests/lib/libpthread/t_condwait.c
diff -u src/tests/lib/libpthread/t_condwait.c:1.3 src/tests/lib/libpthread/t_condwait.c:1.4
--- src/tests/lib/libpthread/t_condwait.c:1.3	Fri Apr 12 10:21:52 2013
+++ src/tests/lib/libpthread/t_condwait.c	Fri Apr 12 13:18:11 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: t_condwait.c,v 1.3 2013/04/12 14:21:52 gson Exp $ */
+/* $NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_condwait.c,v 1.3 2013/04/12 14:21:52 gson Exp $");
+__RCSID("$NetBSD: t_condwait.c,v 1.4 2013/04/12 17:18:11 christos Exp $");
 
 #include 
 #include 
@@ -38,6 +38,8 @@ __RCSID("$NetBSD: t_condwait.c,v 1.3 201
 
 #include 
 
+#include "isqemu.h"
+
 #define WAITTIME 2	/* Timeout wait secound */
 
 static const int debug = 1;
@@ -46,7 +48,6 @@ static void *
 run(void *param)
 {
 	struct timespec ts, to, te;
-	double to_seconds;
 	clockid_t clck;
 	pthread_condattr_t attr;
 	pthread_cond_t cond;
@@ -75,16 +76,20 @@ run(void *param)
 		/* Timeout */
 		ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0);
 		timespecsub(&te, &to, &to);
-		to_seconds = to.tv_sec + 1e-9 * to.tv_nsec;
 		if (debug) {
 			printf("timeout: %lld.%09ld sec\n",
 			(long long)te.tv_sec, te.tv_nsec);
 			printf("elapsed: %lld.%09ld sec\n",
 			(long long)to.tv_sec, to.tv_nsec);
 		}
-		ATF_REQUIRE(to_seconds >= WAITTIME * 0.9);
-		/* Use a loose upper limit because of qemu timing bugs */
-		ATF_REQUIRE(to_seconds < WAITTIME * 2.5);
+		if (isQEMU()) {
+			double to_seconds = to.tv_sec + 1e-9 * to.tv_nsec;
+			ATF_REQUIRE(to_seconds >= WAITTIME * 0.9);
+			/* Loose upper limit because of qemu timing bugs */
+			ATF_REQUIRE(to_seconds < WAITTIME * 2.5);
+		} else {
+			ATF_REQUIRE_EQ(to.tv_sec, WAITTIME);
+		}
 		break;
 	default:
 		ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret));



CVS commit: src/tests/lib/libpthread

2013-04-12 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Fri Apr 12 14:21:52 UTC 2013

Modified Files:
src/tests/lib/libpthread: t_condwait.c

Log Message:
Make cond_wait_mono and cond_wait_real tests accept a wait time in the
range of 90% to 250% of nominal, to allow the test to pass under qemu
which has a known issue where timing can be off by a factor of two.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/t_condwait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_condwait.c
diff -u src/tests/lib/libpthread/t_condwait.c:1.2 src/tests/lib/libpthread/t_condwait.c:1.3
--- src/tests/lib/libpthread/t_condwait.c:1.2	Fri Mar 29 02:32:38 2013
+++ src/tests/lib/libpthread/t_condwait.c	Fri Apr 12 14:21:52 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: t_condwait.c,v 1.2 2013/03/29 02:32:38 christos Exp $ */
+/* $NetBSD: t_condwait.c,v 1.3 2013/04/12 14:21:52 gson Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_condwait.c,v 1.2 2013/03/29 02:32:38 christos Exp $");
+__RCSID("$NetBSD: t_condwait.c,v 1.3 2013/04/12 14:21:52 gson Exp $");
 
 #include 
 #include 
@@ -46,6 +46,7 @@ static void *
 run(void *param)
 {
 	struct timespec ts, to, te;
+	double to_seconds;
 	clockid_t clck;
 	pthread_condattr_t attr;
 	pthread_cond_t cond;
@@ -74,13 +75,16 @@ run(void *param)
 		/* Timeout */
 		ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0);
 		timespecsub(&te, &to, &to);
+		to_seconds = to.tv_sec + 1e-9 * to.tv_nsec;
 		if (debug) {
 			printf("timeout: %lld.%09ld sec\n",
 			(long long)te.tv_sec, te.tv_nsec);
 			printf("elapsed: %lld.%09ld sec\n",
 			(long long)to.tv_sec, to.tv_nsec);
 		}
-		ATF_REQUIRE_EQ(to.tv_sec, WAITTIME);
+		ATF_REQUIRE(to_seconds >= WAITTIME * 0.9);
+		/* Use a loose upper limit because of qemu timing bugs */
+		ATF_REQUIRE(to_seconds < WAITTIME * 2.5);
 		break;
 	default:
 		ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret));



CVS commit: src/tests/lib/libpthread

2013-03-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Mar 29 02:32:38 UTC 2013

Modified Files:
src/tests/lib/libpthread: t_condwait.c

Log Message:
fix printf formats


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_condwait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_condwait.c
diff -u src/tests/lib/libpthread/t_condwait.c:1.1 src/tests/lib/libpthread/t_condwait.c:1.2
--- src/tests/lib/libpthread/t_condwait.c:1.1	Thu Mar 28 14:50:01 2013
+++ src/tests/lib/libpthread/t_condwait.c	Thu Mar 28 22:32:38 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: t_condwait.c,v 1.1 2013/03/28 18:50:01 christos Exp $ */
+/* $NetBSD: t_condwait.c,v 1.2 2013/03/29 02:32:38 christos Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_condwait.c,v 1.1 2013/03/28 18:50:01 christos Exp $");
+__RCSID("$NetBSD: t_condwait.c,v 1.2 2013/03/29 02:32:38 christos Exp $");
 
 #include 
 #include 
@@ -64,7 +64,8 @@ run(void *param)
 	to = ts;
 
 	if (debug)
-		printf("started: %ld.%09ld sec\n", to.tv_sec, to.tv_nsec);
+		printf("started: %lld.%09ld sec\n", (long long)to.tv_sec,
+		to.tv_nsec);
 
 	ts.tv_sec += WAITTIME;	/* Timeout wait */
 
@@ -74,10 +75,10 @@ run(void *param)
 		ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0);
 		timespecsub(&te, &to, &to);
 		if (debug) {
-			printf("timeout: %ld.%09ld sec\n",
-			te.tv_sec, te.tv_nsec);
-			printf("elapsed: %ld.%09ld sec\n",
-			to.tv_sec, to.tv_nsec);
+			printf("timeout: %lld.%09ld sec\n",
+			(long long)te.tv_sec, te.tv_nsec);
+			printf("elapsed: %lld.%09ld sec\n",
+			(long long)to.tv_sec, to.tv_nsec);
 		}
 		ATF_REQUIRE_EQ(to.tv_sec, WAITTIME);
 		break;



CVS commit: src/tests/lib/libpthread

2013-03-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 28 18:50:02 UTC 2013

Modified Files:
src/tests/lib/libpthread: Makefile
Added Files:
src/tests/lib/libpthread: t_condwait.c

Log Message:
Add pthread_cond_timedwait(3) test from PR/47703


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libpthread/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libpthread/t_condwait.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/Makefile
diff -u src/tests/lib/libpthread/Makefile:1.9 src/tests/lib/libpthread/Makefile:1.10
--- src/tests/lib/libpthread/Makefile:1.9	Thu Mar 21 12:50:21 2013
+++ src/tests/lib/libpthread/Makefile	Thu Mar 28 14:50:01 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2013/03/21 16:50:21 christos Exp $
+# $NetBSD: Makefile,v 1.10 2013/03/28 18:50:01 christos Exp $
 
 NOMAN=		# defined
 
@@ -17,6 +17,7 @@ TESTS_SH+=	t_atexit
 TESTS_C+=	t_barrier
 TESTS_SH+=	t_cancel
 TESTS_C+=	t_cond
+TESTS_C+=	t_condwait
 TESTS_C+=	t_detach
 TESTS_C+=	t_equal
 TESTS_SH+=	t_exit

Added files:

Index: src/tests/lib/libpthread/t_condwait.c
diff -u /dev/null src/tests/lib/libpthread/t_condwait.c:1.1
--- /dev/null	Thu Mar 28 14:50:02 2013
+++ src/tests/lib/libpthread/t_condwait.c	Thu Mar 28 14:50:01 2013
@@ -0,0 +1,132 @@
+/* $NetBSD: t_condwait.c,v 1.1 2013/03/28 18:50:01 christos Exp $ */
+
+/*
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+#include 
+__RCSID("$NetBSD: t_condwait.c,v 1.1 2013/03/28 18:50:01 christos Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define WAITTIME 2	/* Timeout wait secound */
+
+static const int debug = 1;
+
+static void *
+run(void *param)
+{
+	struct timespec ts, to, te;
+	clockid_t clck;
+	pthread_condattr_t attr;
+	pthread_cond_t cond;
+	pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+	int ret = 0;
+
+
+	clck = *(clockid_t *)param;
+	pthread_condattr_init(&attr);
+	pthread_condattr_setclock(&attr, clck); /* MONOTONIC or MONOTONIC */
+	pthread_cond_init(&cond, &attr);
+
+	ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0);
+
+	ATF_REQUIRE_EQ(clock_gettime(clck, &ts), 0);
+	to = ts;
+
+	if (debug)
+		printf("started: %ld.%09ld sec\n", to.tv_sec, to.tv_nsec);
+
+	ts.tv_sec += WAITTIME;	/* Timeout wait */
+
+	switch (ret = pthread_cond_timedwait(&cond, &m, &ts)) {
+	case ETIMEDOUT:
+		/* Timeout */
+		ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0);
+		timespecsub(&te, &to, &to);
+		if (debug) {
+			printf("timeout: %ld.%09ld sec\n",
+			te.tv_sec, te.tv_nsec);
+			printf("elapsed: %ld.%09ld sec\n",
+			to.tv_sec, to.tv_nsec);
+		}
+		ATF_REQUIRE_EQ(to.tv_sec, WAITTIME);
+		break;
+	default:
+		ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret));
+	}
+
+	ATF_REQUIRE_MSG(!(ret = pthread_mutex_unlock(&m)),
+	"pthread_mutex_unlock: %s", strerror(ret));
+	pthread_exit(&ret);
+}
+
+static void
+cond_wait(clockid_t clck, const char *msg) {
+	pthread_t child;
+
+	if (debug)
+		printf( " %s clock wait starting\n", msg);
+	ATF_REQUIRE_EQ(pthread_create(&child, NULL, run, &clck), 0);
+	ATF_REQUIRE_EQ(pthread_join(child, NULL), 0); /* wait for terminate */
+	if (debug)
+		printf( " %s clock wait ended\n", msg);
+}
+
+ATF_TC(cond_wait_real);
+ATF_TC_HEAD(cond_wait_real, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Checks pthread_cond_timedwait "
+	"with CLOCK_REALTIME");
+}
+
+ATF_TC_BODY(cond_wait_real, tc) {
+	cond_wait(CLOCK_REALTIME, "CLOCK_REALTIME");
+}
+
+ATF_TC(cond_wait_mono);
+ATF_TC_HEAD(cond_wai

CVS commit: src/tests/lib/libpthread

2013-03-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 21 16:50:22 UTC 2013

Modified Files:
src/tests/lib/libpthread: Makefile
Added Files:
src/tests/lib/libpthread/dlopen: Makefile t_dlopen.c
t_dso_pthread_create.c t_main_pthread_create.c
src/tests/lib/libpthread/dlopen/dso: Makefile h_pthread_dlopen.c

Log Message:
new dlopen tests for libpthread from manu@


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libpthread/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libpthread/dlopen/Makefile \
src/tests/lib/libpthread/dlopen/t_dlopen.c \
src/tests/lib/libpthread/dlopen/t_dso_pthread_create.c \
src/tests/lib/libpthread/dlopen/t_main_pthread_create.c
cvs rdiff -u -r0 -r1.1 src/tests/lib/libpthread/dlopen/dso/Makefile \
src/tests/lib/libpthread/dlopen/dso/h_pthread_dlopen.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/Makefile
diff -u src/tests/lib/libpthread/Makefile:1.8 src/tests/lib/libpthread/Makefile:1.9
--- src/tests/lib/libpthread/Makefile:1.8	Tue Sep 11 22:00:55 2012
+++ src/tests/lib/libpthread/Makefile	Thu Mar 21 12:50:21 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.8 2012/09/12 02:00:55 manu Exp $
+# $NetBSD: Makefile,v 1.9 2013/03/21 16:50:21 christos Exp $
 
 NOMAN=		# defined
 
@@ -48,4 +48,6 @@ PROGS+=		h_resolv
 FILESDIR=	${TESTSDIR}
 FILES=		d_mach
 
+SUBDIR=		dlopen
+
 .include 

Added files:

Index: src/tests/lib/libpthread/dlopen/Makefile
diff -u /dev/null src/tests/lib/libpthread/dlopen/Makefile:1.1
--- /dev/null	Thu Mar 21 12:50:22 2013
+++ src/tests/lib/libpthread/dlopen/Makefile	Thu Mar 21 12:50:21 2013
@@ -0,0 +1,22 @@
+# $NetBSD: Makefile,v 1.1 2013/03/21 16:50:21 christos Exp $
+
+NOMAN=		# defined
+
+.include 
+
+TESTSDIR=	${TESTSBASE}/lib/libpthread/dlopen
+CPPFLAGS+=	-DTESTDIR=\"${TESTSDIR:Q}/\"
+RPATH=-Wl,-rpath=${TESTDIR}
+
+LDADD+=${RPATH}
+
+.if (${MKPIC:Uno} != "no")
+SUBDIR+=	dso
+TESTS_C+=	t_dlopen
+TESTS_C+=	t_main_pthread_create
+LDADD.t_main_pthread_create+=-lpthread 
+PDADD.t_main_pthread_create+=${LIBPTHREAD}
+TESTS_C+=	t_dso_pthread_create
+.endif
+
+.include 
Index: src/tests/lib/libpthread/dlopen/t_dlopen.c
diff -u /dev/null src/tests/lib/libpthread/dlopen/t_dlopen.c:1.1
--- /dev/null	Thu Mar 21 12:50:22 2013
+++ src/tests/lib/libpthread/dlopen/t_dlopen.c	Thu Mar 21 12:50:21 2013
@@ -0,0 +1,171 @@
+/*	$NetBSD: t_dlopen.c,v 1.1 2013/03/21 16:50:21 christos Exp $ */
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus
+ *
+ * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDERS 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.
+ */
+
+#include 
+__RCSID("$NetBSD: t_dlopen.c,v 1.1 2013/03/21 16:50:21 christos Exp $");
+
+#include 
+#include 
+#include 
+#include 
+
+ATF_TC(dlopen);
+
+ATF_TC_HEAD(dlopen, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Test if dlopen can load -lpthread DSO");
+}
+
+#define DSO TESTDIR "/h_pthread_dlopen.so"
+
+ATF_TC_BODY(dlopen, tc)
+{
+	void *handle;
+	int (*testf_dso_null)(void);
+	handle = dlopen(DSO, RTLD_NOW | RTLD_LOCAL);
+	ATF_REQUIRE_MSG(handle != NULL, "dlopen fails: %s", dlerror());
+
+	testf_dso_null = dlsym(handle, "testf_dso_null");
+	ATF_REQUIRE_MSG(testf_dso_null != NULL, "dlsym fails: %s", dlerror());
+
+	ATF_REQUIRE(testf_dso_null() == 0xcafe);
+
+	ATF_REQUIRE(dlclose(handle) == 0);
+}
+
+ATF_TC(dlopen_mutex);
+
+ATF_TC_HEAD(dlopen_mutex, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Test if dlopen can load -lpthread DSO without breaking mutex");
+}
+
+ATF_TC_BODY(dlopen_mu

CVS commit: src/tests/lib/libpthread

2013-03-16 Thread Julio Merino
Module Name:src
Committed By:   jmmv
Date:   Sun Mar 17 05:13:13 UTC 2013

Modified Files:
src/tests/lib/libpthread: t_cond.c

Log Message:
Try to trigger the cond_timedwait_race race several times.

Sometime this tests passes (after all, it's exercising a race condition) and
when it does it's reported as a failure.  By giving the test a few chances
to expose the problem, we prevent this noisy signal.  When the race is really
addressed, this will start failing consistently as expected.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libpthread/t_cond.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_cond.c
diff -u src/tests/lib/libpthread/t_cond.c:1.3 src/tests/lib/libpthread/t_cond.c:1.4
--- src/tests/lib/libpthread/t_cond.c:1.3	Sun Mar 27 16:45:15 2011
+++ src/tests/lib/libpthread/t_cond.c	Sun Mar 17 05:13:13 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cond.c,v 1.3 2011/03/27 16:45:15 jruoho Exp $ */
+/* $NetBSD: t_cond.c,v 1.4 2013/03/17 05:13:13 jmmv Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_cond.c,v 1.3 2011/03/27 16:45:15 jruoho Exp $");
+__RCSID("$NetBSD: t_cond.c,v 1.4 2013/03/17 05:13:13 jmmv Exp $");
 
 #include 
 
@@ -349,19 +349,25 @@ ATF_TC_HEAD(cond_timedwait_race, tc)
 ATF_TC_BODY(cond_timedwait_race, tc)
 {
 	pthread_t tid[64];
-	size_t i;
+	size_t i, j;
 
 	atf_tc_expect_fail("PR lib/44756");
+	/* This outer loop is to ensure that a false positive of this race
+	 * test does not report the test as broken (due to the test not
+	 * triggering the expected failure).  However, we want to make this
+	 * fail consistently when the race is resolved, and this approach
+	 * will have the desired effect. */
+	for (j = 0; j < 10; j++ ) {
+		for (i = 0; i < __arraycount(tid); i++) {
+
+			PTHREAD_REQUIRE(pthread_create(&tid[i], NULL,
+			pthread_cond_timedwait_func, NULL));
+		}
 
-	for (i = 0; i < __arraycount(tid); i++) {
+		for (i = 0; i < __arraycount(tid); i++) {
 
-		PTHREAD_REQUIRE(pthread_create(&tid[i], NULL,
-			pthread_cond_timedwait_func, NULL));
-	}
-
-	for (i = 0; i < __arraycount(tid); i++) {
-
-		PTHREAD_REQUIRE(pthread_join(tid[i], NULL));
+			PTHREAD_REQUIRE(pthread_join(tid[i], NULL));
+		}
 	}
 }
 



CVS commit: src/tests/lib/libpthread

2012-03-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Mar 12 20:17:16 UTC 2012

Modified Files:
src/tests/lib/libpthread: t_join.c

Log Message:
Also exercise pthread_attr_setstacksize.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libpthread/t_join.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_join.c
diff -u src/tests/lib/libpthread/t_join.c:1.7 src/tests/lib/libpthread/t_join.c:1.8
--- src/tests/lib/libpthread/t_join.c:1.7	Mon Dec 12 23:54:18 2011
+++ src/tests/lib/libpthread/t_join.c	Mon Mar 12 20:17:16 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.7 2011/12/12 23:54:18 joerg Exp $ */
+/* $NetBSD: t_join.c,v 1.8 2012/03/12 20:17:16 joerg Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_join.c,v 1.7 2011/12/12 23:54:18 joerg Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.8 2012/03/12 20:17:16 joerg Exp $");
 
 #include 
 #include 
@@ -43,6 +43,8 @@ __RCSID("$NetBSD: t_join.c,v 1.7 2011/12
 extern int check_stack_alignment(void);
 #endif
 
+#define STACKSIZE	65536
+
 static bool error;
 
 static void *threadfunc1(void *);
@@ -72,6 +74,7 @@ threadfunc1(void *arg)
 	void *val = NULL;
 	uintptr_t i;
 	int rv;
+	pthread_attr_t attr;
 
 	caller = pthread_self();
 
@@ -94,11 +97,15 @@ threadfunc1(void *arg)
 	ATF_REQUIRE(rv != 0);
 	ATF_REQUIRE_EQ(rv, EDEADLK);
 
+	ATF_REQUIRE(pthread_attr_init(&attr) == 0);
+
 	for (i = 0; i < __arraycount(thread); i++) {
 
 		error = true;
 
-		rv = pthread_create(&thread[i], NULL, threadfunc2, (void *)i);
+		ATF_REQUIRE(pthread_attr_setstacksize(&attr, STACKSIZE * (i + 1)) == 0);
+
+		rv = pthread_create(&thread[i], &attr, threadfunc2, (void *)i);
 
 		ATF_REQUIRE_EQ(rv, 0);
 
@@ -128,6 +135,8 @@ threadfunc1(void *arg)
 		ATF_REQUIRE(rv != 0);
 	}
 
+	ATF_REQUIRE(pthread_attr_destroy(&attr) == 0);
+
 	pthread_exit(NULL);
 
 	return NULL;
@@ -138,9 +147,16 @@ threadfunc2(void *arg)
 {
 	static uintptr_t i = 0;
 	uintptr_t j;
+	pthread_attr_t attr;
+	size_t stacksize;
 
 	j = (uintptr_t)arg;
 
+	ATF_REQUIRE(pthread_attr_get_np(pthread_self(), &attr) == 0);
+	ATF_REQUIRE(pthread_attr_getstacksize(&attr, &stacksize) == 0);
+	ATF_REQUIRE(stacksize == STACKSIZE * (j + 1));
+	ATF_REQUIRE(pthread_attr_destroy(&attr) == 0);
+
 	if (i++ == j)
 		error = false;
 



CVS commit: src/tests/lib/libpthread

2012-03-09 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Mar  9 19:46:38 UTC 2012

Modified Files:
src/tests/lib/libpthread: t_sem.c

Log Message:
It is perfectly valid for sem_wait to be interrupted, so loop on EINTR.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libpthread/t_sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_sem.c
diff -u src/tests/lib/libpthread/t_sem.c:1.6 src/tests/lib/libpthread/t_sem.c:1.7
--- src/tests/lib/libpthread/t_sem.c:1.6	Wed Mar  7 23:31:44 2012
+++ src/tests/lib/libpthread/t_sem.c	Fri Mar  9 19:46:37 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sem.c,v 1.6 2012/03/07 23:31:44 joerg Exp $ */
+/* $NetBSD: t_sem.c,v 1.7 2012/03/09 19:46:37 joerg Exp $ */
 
 /*
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sem.c,v 1.6 2012/03/07 23:31:44 joerg Exp $");
+__RCSID("$NetBSD: t_sem.c,v 1.7 2012/03/09 19:46:37 joerg Exp $");
 
 #include 
 #include 
@@ -230,14 +230,17 @@ alarm_ms(const int ms)
 static void *
 threadfunc(void *arg)
 {
-	int i;
+	int i, ret;
 
 	printf("Entering loop\n");
 	for (i = 0; i < 500; ) {
 		if ((i & 1) != 0) {
-			ATF_REQUIRE(sem_wait(&sem) != -1);
+			do {
+ret = sem_wait(&sem);
+			} while (ret == -1 && errno == EINTR);
+			ATF_REQUIRE(ret == 0);
 		} else {
-			const int ret = sem_trywait(&sem);
+			ret = sem_trywait(&sem);
 			if (ret == -1) {
 ATF_REQUIRE(errno == EAGAIN);
 continue;



CVS commit: src/tests/lib/libpthread

2011-12-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Dec 12 23:54:18 UTC 2011

Modified Files:
src/tests/lib/libpthread: t_join.c

Log Message:
Remove bogus check that (a) depends uninitialised memory (b) overflows a
buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libpthread/t_join.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_join.c
diff -u src/tests/lib/libpthread/t_join.c:1.6 src/tests/lib/libpthread/t_join.c:1.7
--- src/tests/lib/libpthread/t_join.c:1.6	Mon Aug 22 00:35:07 2011
+++ src/tests/lib/libpthread/t_join.c	Mon Dec 12 23:54:18 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.6 2011/08/22 00:35:07 dholland Exp $ */
+/* $NetBSD: t_join.c,v 1.7 2011/12/12 23:54:18 joerg Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_join.c,v 1.6 2011/08/22 00:35:07 dholland Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.7 2011/12/12 23:54:18 joerg Exp $");
 
 #include 
 #include 
@@ -103,13 +103,6 @@ threadfunc1(void *arg)
 		ATF_REQUIRE_EQ(rv, 0);
 
 		/*
-		 * Try to join an invalid thread.
-		 */
-		rv = pthread_join(thread[i + 1], NULL);
-
-		ATF_REQUIRE_EQ(rv, ESRCH);
-
-		/*
 		 * Check join and exit condition.
 		 */
 		PTHREAD_REQUIRE(pthread_join(thread[i], &val));



CVS commit: src/tests/lib/libpthread

2011-08-21 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Aug 22 00:35:08 UTC 2011

Modified Files:
src/tests/lib/libpthread: t_join.c

Log Message:
Requires stdint.h.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libpthread/t_join.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_join.c
diff -u src/tests/lib/libpthread/t_join.c:1.5 src/tests/lib/libpthread/t_join.c:1.6
--- src/tests/lib/libpthread/t_join.c:1.5	Tue Nov 30 18:38:54 2010
+++ src/tests/lib/libpthread/t_join.c	Mon Aug 22 00:35:07 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.5 2010/11/30 18:38:54 joerg Exp $ */
+/* $NetBSD: t_join.c,v 1.6 2011/08/22 00:35:07 dholland Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,10 +29,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_join.c,v 1.5 2010/11/30 18:38:54 joerg Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.6 2011/08/22 00:35:07 dholland Exp $");
 
 #include 
 #include 
+#include 
 
 #include 
 



CVS commit: src/tests/lib/libpthread

2011-04-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Apr  4 14:47:22 UTC 2011

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
Do only set a (lower than default) timeout value if we are on powerpc and
expect to run into a real deadrun ofter.
The (too short) timeout otherwise makes slower archs fail.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.4 src/tests/lib/libpthread/t_mutex.c:1.5
--- src/tests/lib/libpthread/t_mutex.c:1.4	Mon Feb 21 21:43:41 2011
+++ src/tests/lib/libpthread/t_mutex.c	Mon Apr  4 14:47:22 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.4 2011/02/21 21:43:41 riz Exp $ */
+/* $NetBSD: t_mutex.c,v 1.5 2011/04/04 14:47:22 martin Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.4 2011/02/21 21:43:41 riz Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.5 2011/04/04 14:47:22 martin Exp $");
 
 #include 
 #include 
@@ -118,7 +118,8 @@
 ATF_TC_HEAD(mutex2, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes");
-	atf_tc_set_md_var(tc, "timeout", "40");
+	if (strcmp(atf_config_get("atf_arch"), "powerpc") == 0)
+		atf_tc_set_md_var(tc, "timeout", "40");
 }
 ATF_TC_BODY(mutex2, tc)
 {
@@ -189,7 +190,8 @@
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes using a static "
 	"initializer");
-	atf_tc_set_md_var(tc, "timeout", "40");
+	if (strcmp(atf_config_get("atf_arch"), "powerpc") == 0)
+		atf_tc_set_md_var(tc, "timeout", "40");
 }
 ATF_TC_BODY(mutex3, tc)
 {



CVS commit: src/tests/lib/libpthread

2011-03-27 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Sun Mar 27 16:45:16 UTC 2011

Modified Files:
src/tests/lib/libpthread: t_cond.c

Log Message:
Add a test case for pthread_cond_timedwait(3) failures reported by
Sad Clouds in PR lib/44756. This was discussed also in:

http://mail-index.netbsd.org/tech-userlevel/2011/03/17/msg004689.html


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/t_cond.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_cond.c
diff -u src/tests/lib/libpthread/t_cond.c:1.2 src/tests/lib/libpthread/t_cond.c:1.3
--- src/tests/lib/libpthread/t_cond.c:1.2	Wed Nov  3 16:10:22 2010
+++ src/tests/lib/libpthread/t_cond.c	Sun Mar 27 16:45:15 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cond.c,v 1.2 2010/11/03 16:10:22 christos Exp $ */
+/* $NetBSD: t_cond.c,v 1.3 2011/03/27 16:45:15 jruoho Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_cond.c,v 1.2 2010/11/03 16:10:22 christos Exp $");
+__RCSID("$NetBSD: t_cond.c,v 1.3 2011/03/27 16:45:15 jruoho Exp $");
 
 #include 
 
@@ -306,6 +306,66 @@
 }
 
 static void *
+pthread_cond_timedwait_func(void *arg)
+{
+	struct timespec ts;
+	size_t i = 0;
+	int rv;
+
+	for (;;) {
+
+		if (i++ >= 1)
+			pthread_exit(NULL);
+
+		(void)memset(&ts, 0, sizeof(struct timespec));
+
+		ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &ts) == 0);
+
+		/*
+		 * Set to one second in the past:
+		 * pthread_cond_timedwait(3) should
+		 * return ETIMEDOUT immediately.
+		 */
+		ts.tv_sec = ts.tv_sec - 1;
+
+		PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
+		rv = pthread_cond_timedwait(&static_cond, &static_mutex, &ts);
+
+		/*
+		 * Sometimes we catch ESRCH.
+		 * This should never happen.
+		 */
+		ATF_REQUIRE(rv == ETIMEDOUT);
+		PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
+	}
+}
+
+ATF_TC(cond_timedwait_race);
+ATF_TC_HEAD(cond_timedwait_race, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test pthread_cond_timedwait(3)");
+
+}
+ATF_TC_BODY(cond_timedwait_race, tc)
+{
+	pthread_t tid[64];
+	size_t i;
+
+	atf_tc_expect_fail("PR lib/44756");
+
+	for (i = 0; i < __arraycount(tid); i++) {
+
+		PTHREAD_REQUIRE(pthread_create(&tid[i], NULL,
+			pthread_cond_timedwait_func, NULL));
+	}
+
+	for (i = 0; i < __arraycount(tid); i++) {
+
+		PTHREAD_REQUIRE(pthread_join(tid[i], NULL));
+	}
+}
+
+static void *
 broadcast_threadfunc(void *arg)
 {
 	printf("2: Second thread.\n");
@@ -502,6 +562,7 @@
 	ATF_TP_ADD_TC(tp, signal_before_unlock);
 	ATF_TP_ADD_TC(tp, signal_before_unlock_static_init);
 	ATF_TP_ADD_TC(tp, signal_wait_race);
+	ATF_TP_ADD_TC(tp, cond_timedwait_race);
 	ATF_TP_ADD_TC(tp, broadcast);
 	ATF_TP_ADD_TC(tp, bogus_timedwaits);
 	ATF_TP_ADD_TC(tp, destroy_after_cancel);



CVS commit: src/tests/lib/libpthread

2011-02-21 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Mon Feb 21 21:43:41 UTC 2011

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
mutex2/mutex3 are expected to fail on powerpc because of
PR port-powerpc/44387.

XXX the ugly sleep at the end is because ATF will mark an un-triggered
race condition (ie, the test passes unexpectedly) as a test failure otherwise.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.3 src/tests/lib/libpthread/t_mutex.c:1.4
--- src/tests/lib/libpthread/t_mutex.c:1.3	Sun Feb 20 14:37:44 2011
+++ src/tests/lib/libpthread/t_mutex.c	Mon Feb 21 21:43:41 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.3 2011/02/20 14:37:44 jmmv Exp $ */
+/* $NetBSD: t_mutex.c,v 1.4 2011/02/21 21:43:41 riz Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,13 +29,15 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.3 2011/02/20 14:37:44 jmmv Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.4 2011/02/21 21:43:41 riz Exp $");
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
+#include 
 
 #include "h_common.h"
 
@@ -116,17 +118,24 @@
 ATF_TC_HEAD(mutex2, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes");
+	atf_tc_set_md_var(tc, "timeout", "40");
 }
 ATF_TC_BODY(mutex2, tc)
 {
+	const char *m_arch;
 	int count, count2;
 	pthread_t new;
 	void *joinval;
 
 	printf("1: Mutex-test 2\n");
 
-	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+	m_arch = atf_config_get("atf_arch");
+	if (strcmp(m_arch, "powerpc") == 0) {
+		atf_tc_expect_timeout("PR port-powerpc/44387");
+	}
 
+	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+	
 	global_x = 0;
 	count = count2 = 1000;
 
@@ -149,6 +158,14 @@
 	printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
 		global_x, (long)joinval);
 	ATF_REQUIRE_EQ(global_x, 2000);
+
+	/* XXX force a timeout in ppc case since an un-triggered race
+	   otherwise looks like a "failure" */
+	if (strcmp(m_arch, "powerpc") == 0) {
+		/* We sleep for longer than the timeout to make ATF not
+		   complain about unexpected success */
+		sleep(41);
+	}
 }
 
 static void *
@@ -172,15 +189,22 @@
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes using a static "
 	"initializer");
+	atf_tc_set_md_var(tc, "timeout", "40");
 }
 ATF_TC_BODY(mutex3, tc)
 {
+	const char *m_arch;
 	int count, count2;
 	pthread_t new;
 	void *joinval;
 
 	printf("1: Mutex-test 3\n");
 
+	m_arch = atf_config_get("atf_arch");
+	if (strcmp(m_arch, "powerpc") == 0) {
+		atf_tc_expect_timeout("PR port-powerpc/44387");
+	}
+
 	global_x = 0;
 	count = count2 = 1000;
 
@@ -203,6 +227,14 @@
 	printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
 		global_x, (long)joinval);
 	ATF_REQUIRE_EQ(global_x, 2000);
+
+	/* XXX force a timeout in ppc case since an un-triggered race
+	   otherwise looks like a "failure" */
+	if (strcmp(m_arch, "powerpc") == 0) {
+		/* We sleep for longer than the timeout to make ATF not
+		   complain about unexpected success */
+		sleep(41);
+	}
 }
 
 static void *



CVS commit: src/tests/lib/libpthread

2011-02-20 Thread Julio Merino
Module Name:src
Committed By:   jmmv
Date:   Sun Feb 20 14:37:44 UTC 2011

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
The mutex3 test is supposed to use a static initializer so that it differs
to the mutex2 test.  This detail was lost during the atfification of these
tests.

Spotted by pooka@ and riz@.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.2 src/tests/lib/libpthread/t_mutex.c:1.3
--- src/tests/lib/libpthread/t_mutex.c:1.2	Fri Jul 16 18:16:43 2010
+++ src/tests/lib/libpthread/t_mutex.c	Sun Feb 20 14:37:44 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.2 2010/07/16 18:16:43 njoly Exp $ */
+/* $NetBSD: t_mutex.c,v 1.3 2011/02/20 14:37:44 jmmv Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.2 2010/07/16 18:16:43 njoly Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.3 2011/02/20 14:37:44 jmmv Exp $");
 
 #include 
 #include 
@@ -40,6 +40,7 @@
 #include "h_common.h"
 
 static pthread_mutex_t mutex;
+static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
 static int global_x;
 
 static void *
@@ -158,9 +159,9 @@
 	printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
 
 	while (count--) {
-		PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+		PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
 		global_x++;
-		PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+		PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
 	}
 
 	return (void *)count;
@@ -169,7 +170,8 @@
 ATF_TC(mutex3);
 ATF_TC_HEAD(mutex3, tc)
 {
-	atf_tc_set_md_var(tc, "descr", "Checks mutexes");
+	atf_tc_set_md_var(tc, "descr", "Checks mutexes using a static "
+	"initializer");
 }
 ATF_TC_BODY(mutex3, tc)
 {
@@ -179,26 +181,25 @@
 
 	printf("1: Mutex-test 3\n");
 
-	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
-
 	global_x = 0;
 	count = count2 = 1000;
 
-	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+	PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
 	PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex3_threadfunc, &count2));
 
 	printf("1: Thread %p\n", pthread_self());
-	PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+
+	PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
 
 	while (count--) {
-		PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+		PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
 		global_x++;
-		PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
+		PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
 	}
 
 	PTHREAD_REQUIRE(pthread_join(new, &joinval));
 
-	PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+	PTHREAD_REQUIRE(pthread_mutex_lock(&static_mutex));
 	printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
 		global_x, (long)joinval);
 	ATF_REQUIRE_EQ(global_x, 2000);



CVS commit: src/tests/lib/libpthread

2010-12-08 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Dec  8 23:50:14 UTC 2010

Modified Files:
src/tests/lib/libpthread: Makefile

Log Message:
Link t_fpu against libm if the compiler doesn't want to inline sin/cos.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libpthread/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/Makefile
diff -u src/tests/lib/libpthread/Makefile:1.3 src/tests/lib/libpthread/Makefile:1.4
--- src/tests/lib/libpthread/Makefile:1.3	Tue Nov 30 18:38:54 2010
+++ src/tests/lib/libpthread/Makefile	Wed Dec  8 23:50:14 2010
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2010/11/30 18:38:54 joerg Exp $
+# $NetBSD: Makefile,v 1.4 2010/12/08 23:50:14 joerg Exp $
 
 NOMAN=		# defined
 
@@ -6,6 +6,7 @@
 
 TESTSDIR=	${TESTSBASE}/lib/libpthread
 LDADD+=		-lpthread
+LDADD.t_fpu+=	-lm
 
 .include "${.PARSEDIR}/../csu/Makefile.check_stack"
 



CVS commit: src/tests/lib/libpthread

2010-07-29 Thread Hans Rosenfeld
Module Name:src
Committed By:   hans
Date:   Thu Jul 29 12:56:16 UTC 2010

Modified Files:
src/tests/lib/libpthread: t_join.c

Log Message:
Revert to 1.1 and fix the casts by using uintptr_t.  Ok jruoho.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libpthread/t_join.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_join.c
diff -u src/tests/lib/libpthread/t_join.c:1.3 src/tests/lib/libpthread/t_join.c:1.4
--- src/tests/lib/libpthread/t_join.c:1.3	Thu Jul 29 12:17:31 2010
+++ src/tests/lib/libpthread/t_join.c	Thu Jul 29 12:56:16 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.3 2010/07/29 12:17:31 jruoho Exp $ */
+/* $NetBSD: t_join.c,v 1.4 2010/07/29 12:56:16 hans Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_join.c,v 1.3 2010/07/29 12:17:31 jruoho Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.4 2010/07/29 12:56:16 hans Exp $");
 
 #include 
 #include 
@@ -64,8 +64,8 @@
 {
 	pthread_t thread[25];
 	pthread_t caller;
-	void *val;
-	size_t i;
+	void *val = NULL;
+	uintptr_t i;
 	int rv;
 
 	caller = pthread_self();
@@ -86,7 +86,7 @@
 
 		error = true;
 
-		rv = pthread_create(&thread[i], NULL, threadfunc2, NULL);
+		rv = pthread_create(&thread[i], NULL, threadfunc2, (void *)i);
 
 		ATF_REQUIRE_EQ(rv, 0);
 
@@ -102,9 +102,11 @@
 		 */
 		PTHREAD_REQUIRE(pthread_join(thread[i], &val));
 
-		ATF_REQUIRE(val == NULL);
 		ATF_REQUIRE_EQ(error, false);
 
+		ATF_REQUIRE(val != NULL);
+		ATF_REQUIRE(val == (void *)(i + 1));
+
 		/*
 		 * Once the thread has returned, ESRCH should
 		 * again follow if we try to join it again.
@@ -129,15 +131,15 @@
 static void *
 threadfunc2(void *arg)
 {
-	static int i = 0;
-	int j;
+	static uintptr_t i = 0;
+	uintptr_t j;
 
-	j = (int)arg;
+	j = (uintptr_t)arg;
 
 	if (i++ == j)
 		error = false;
 
-	pthread_exit(NULL);
+	pthread_exit((void *)i);
 
 	return NULL;
 }



CVS commit: src/tests/lib/libpthread

2010-07-29 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Thu Jul 29 12:17:31 UTC 2010

Modified Files:
src/tests/lib/libpthread: t_join.c

Log Message:
One more cast.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/t_join.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_join.c
diff -u src/tests/lib/libpthread/t_join.c:1.2 src/tests/lib/libpthread/t_join.c:1.3
--- src/tests/lib/libpthread/t_join.c:1.2	Thu Jul 29 12:03:10 2010
+++ src/tests/lib/libpthread/t_join.c	Thu Jul 29 12:17:31 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.2 2010/07/29 12:03:10 jruoho Exp $ */
+/* $NetBSD: t_join.c,v 1.3 2010/07/29 12:17:31 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_join.c,v 1.2 2010/07/29 12:03:10 jruoho Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.3 2010/07/29 12:17:31 jruoho Exp $");
 
 #include 
 #include 
@@ -86,7 +86,7 @@
 
 		error = true;
 
-		rv = pthread_create(&thread[i], NULL, threadfunc2, (void *)i);
+		rv = pthread_create(&thread[i], NULL, threadfunc2, NULL);
 
 		ATF_REQUIRE_EQ(rv, 0);
 



CVS commit: src/tests/lib/libpthread

2010-07-29 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Thu Jul 29 12:03:10 UTC 2010

Modified Files:
src/tests/lib/libpthread: t_join.c

Log Message:
Fix build failure on AMD64, noted by nj...@.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_join.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_join.c
diff -u src/tests/lib/libpthread/t_join.c:1.1 src/tests/lib/libpthread/t_join.c:1.2
--- src/tests/lib/libpthread/t_join.c:1.1	Wed Jul 28 21:29:15 2010
+++ src/tests/lib/libpthread/t_join.c	Thu Jul 29 12:03:10 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.1 2010/07/28 21:29:15 jruoho Exp $ */
+/* $NetBSD: t_join.c,v 1.2 2010/07/29 12:03:10 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_join.c,v 1.1 2010/07/28 21:29:15 jruoho Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.2 2010/07/29 12:03:10 jruoho Exp $");
 
 #include 
 #include 
@@ -64,7 +64,7 @@
 {
 	pthread_t thread[25];
 	pthread_t caller;
-	void *val = NULL;
+	void *val;
 	size_t i;
 	int rv;
 
@@ -102,11 +102,9 @@
 		 */
 		PTHREAD_REQUIRE(pthread_join(thread[i], &val));
 
+		ATF_REQUIRE(val == NULL);
 		ATF_REQUIRE_EQ(error, false);
 
-		ATF_REQUIRE(val != NULL);
-		ATF_REQUIRE(val == (void *)(i + 1));
-
 		/*
 		 * Once the thread has returned, ESRCH should
 		 * again follow if we try to join it again.
@@ -139,7 +137,7 @@
 	if (i++ == j)
 		error = false;
 
-	pthread_exit((void *)i);
+	pthread_exit(NULL);
 
 	return NULL;
 }



CVS commit: src/tests/lib/libpthread

2010-07-21 Thread Julio Merino
Module Name:src
Committed By:   jmmv
Date:   Wed Jul 21 17:23:08 UTC 2010

Modified Files:
src/tests/lib/libpthread: t_sem.c

Log Message:
before_start_one_thread is not racy only in amd64; my confusion.  Mark it
as an xfail everywhere and, while doing so, make the test longer so that
we trigger the failure all the time -- of course, being a race this may
still happen but the chances should be pretty low.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libpthread/t_sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_sem.c
diff -u src/tests/lib/libpthread/t_sem.c:1.3 src/tests/lib/libpthread/t_sem.c:1.4
--- src/tests/lib/libpthread/t_sem.c:1.3	Mon Jul 19 10:31:46 2010
+++ src/tests/lib/libpthread/t_sem.c	Wed Jul 21 17:23:08 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sem.c,v 1.3 2010/07/19 10:31:46 jmmv Exp $ */
+/* $NetBSD: t_sem.c,v 1.4 2010/07/21 17:23:08 jmmv Exp $ */
 
 /*
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sem.c,v 1.3 2010/07/19 10:31:46 jmmv Exp $");
+__RCSID("$NetBSD: t_sem.c,v 1.4 2010/07/21 17:23:08 jmmv Exp $");
 
 #include 
 #include 
@@ -233,7 +233,7 @@
 	int i;
 
 	printf("Entering loop\n");
-	for (i = 0; i < 10; ) {
+	for (i = 0; i < 500; ) {
 		if ((i & 1) != 0) {
 			ATF_REQUIRE(sem_wait(&sem) != -1);
 		} else {
@@ -244,7 +244,7 @@
 			}
 		}
 		printf("%s: %d\n", __func__, i);
-		alarm_ms(100);
+		alarm_ms(5);
 		i++;
 	}
 
@@ -259,7 +259,7 @@
 	SEM_REQUIRE(sem_init(&sem, 0, 0));
 	ATF_REQUIRE(SIG_ERR != signal(SIGALRM, sighandler));
 
-	alarm_ms(100);
+	alarm_ms(5);
 
 	if (use_pthread) {
 		PTHREAD_REQUIRE(pthread_create(&t, NULL, threadfunc, NULL));
@@ -274,7 +274,7 @@
 {
 	atf_tc_set_md_var(tc, "descr", "Checks using semaphores without any "
 	"thread running");
-	atf_tc_set_md_var(tc, "timeout", "20");
+	atf_tc_set_md_var(tc, "timeout", "40");
 }
 ATF_TC_BODY(before_start_no_threads, tc)
 {
@@ -286,18 +286,17 @@
 {
 	atf_tc_set_md_var(tc, "descr", "Checks using semaphores before "
 	"starting one thread");
-	atf_tc_set_md_var(tc, "timeout", "20");
+	atf_tc_set_md_var(tc, "timeout", "40");
 }
 ATF_TC_BODY(before_start_one_thread, tc)
 {
-	if (strcmp("amd64", atf_config_get("atf_arch")) == 0) {
-		/* TODO(jmmv): This really is a race condition test.  However,
-		 * we cannot yet mark it as such because ATF does not provide
-		 * such functionality.  Let's just mark it as an unconditional
-		 * expected timeout as I haven't got it to pass any single
-		 * time. */
-		atf_tc_expect_timeout("Race condition detected");
-	}
+	/* TODO(jmmv): This really is a race condition test.  However, we can't
+	 * yet mark it as such because ATF does not provide such functionality.
+	 * Let's just mark it as an unconditional expected timeout as I haven't
+	 * got it to pass any single time. */
+	atf_tc_expect_timeout("Race condition; it is probably unsafe to call "
+	"sem_post from a signal handler when using the pthread version");
+
 	before_start_test(true);
 }
 



CVS commit: src/tests/lib/libpthread

2010-07-19 Thread Julio Merino
Module Name:src
Committed By:   jmmv
Date:   Mon Jul 19 10:31:46 UTC 2010

Modified Files:
src/tests/lib/libpthread: t_sem.c

Log Message:
Split the before_start test in two: one that does not use threads and one
that does.  The former works all the time but the latter gets consistently
stuck on amd64.  Mark the latter as an expected timeout (should be a "race
condition" test, but atf does not have such a thing yet[1]).

This clears the test failures, at least, under anita running NetBSD/i386.

>From pooka@: this could well be because calling sem_post(3) from a signal
handler can't possibly do the right thing with the pthread implementation.
However, according to signal(7), sem_post(3) is signal-async safe...

While here, program alarms using a timeout shorter than 1 second to speed
up the execution of the tests.

1: Good thing is I finally understand what a "race condition" test looks
like, I believe.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/t_sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_sem.c
diff -u src/tests/lib/libpthread/t_sem.c:1.2 src/tests/lib/libpthread/t_sem.c:1.3
--- src/tests/lib/libpthread/t_sem.c:1.2	Sun Jul 18 22:30:55 2010
+++ src/tests/lib/libpthread/t_sem.c	Mon Jul 19 10:31:46 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sem.c,v 1.2 2010/07/18 22:30:55 pooka Exp $ */
+/* $NetBSD: t_sem.c,v 1.3 2010/07/19 10:31:46 jmmv Exp $ */
 
 /*
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sem.c,v 1.2 2010/07/18 22:30:55 pooka Exp $");
+__RCSID("$NetBSD: t_sem.c,v 1.3 2010/07/19 10:31:46 jmmv Exp $");
 
 #include 
 #include 
@@ -99,6 +99,7 @@
 #include 
 
 #include 
+#include 
 
 #include "h_common.h"
 
@@ -215,60 +216,97 @@
 	SEM_REQUIRE(sem_post(&sem));
 }
 
+static void
+alarm_ms(const int ms)
+{
+	struct itimerval timer;
+	timer.it_interval.tv_sec = 0;
+	timer.it_interval.tv_usec = 0;
+	timer.it_value.tv_sec = 0;
+	timer.it_value.tv_usec = ms * 1000;
+	ATF_REQUIRE(setitimer(ITIMER_REAL, &timer, NULL) == 0);
+}
+
 static void *
 threadfunc(void *arg)
 {
 	int i;
 
+	printf("Entering loop\n");
 	for (i = 0; i < 10; ) {
-		int ret;
-
-		if ((i & 1) != 0)
-			ret = sem_wait(&sem);
-		else
-			ret = sem_trywait(&sem);
-
-		if (ret) {
-			ATF_REQUIRE_MSG((i & 1) == 0 && errno == EAGAIN,
-"%s", strerror(errno));
-			continue;
+		if ((i & 1) != 0) {
+			ATF_REQUIRE(sem_wait(&sem) != -1);
+		} else {
+			const int ret = sem_trywait(&sem);
+			if (ret == -1) {
+ATF_REQUIRE(errno == EAGAIN);
+continue;
+			}
 		}
-
 		printf("%s: %d\n", __func__, i);
-		alarm(1);
+		alarm_ms(100);
 		i++;
 	}
 
 	return NULL;
 }
 
-ATF_TC(before_start);
-ATF_TC_HEAD(before_start, tc)
-{
-	atf_tc_set_md_var(tc, "descr", "Checks using semaphores before "
-	"starting pthread");
-	atf_tc_set_md_var(tc, "timeout", "20");
-}
-ATF_TC_BODY(before_start, tc)
+static void
+before_start_test(const bool use_pthread)
 {
 	pthread_t t;
 
-	alarm(1);
-
 	SEM_REQUIRE(sem_init(&sem, 0, 0));
+	ATF_REQUIRE(SIG_ERR != signal(SIGALRM, sighandler));
 
-	PTHREAD_REQUIRE(pthread_create(&t, NULL, threadfunc, NULL));
+	alarm_ms(100);
 
-	ATF_REQUIRE(SIG_ERR != signal(SIGALRM, sighandler));
+	if (use_pthread) {
+		PTHREAD_REQUIRE(pthread_create(&t, NULL, threadfunc, NULL));
+		PTHREAD_REQUIRE(pthread_join(t, NULL));
+	} else {
+		threadfunc(NULL);
+	}
+}
+
+ATF_TC(before_start_no_threads);
+ATF_TC_HEAD(before_start_no_threads, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Checks using semaphores without any "
+	"thread running");
+	atf_tc_set_md_var(tc, "timeout", "20");
+}
+ATF_TC_BODY(before_start_no_threads, tc)
+{
+	before_start_test(false);
+}
 
-	PTHREAD_REQUIRE(pthread_join(t, NULL));
+ATF_TC(before_start_one_thread);
+ATF_TC_HEAD(before_start_one_thread, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Checks using semaphores before "
+	"starting one thread");
+	atf_tc_set_md_var(tc, "timeout", "20");
+}
+ATF_TC_BODY(before_start_one_thread, tc)
+{
+	if (strcmp("amd64", atf_config_get("atf_arch")) == 0) {
+		/* TODO(jmmv): This really is a race condition test.  However,
+		 * we cannot yet mark it as such because ATF does not provide
+		 * such functionality.  Let's just mark it as an unconditional
+		 * expected timeout as I haven't got it to pass any single
+		 * time. */
+		atf_tc_expect_timeout("Race condition detected");
+	}
+	before_start_test(true);
 }
 
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, named);
 	ATF_TP_ADD_TC(tp, unnamed);
-	ATF_TP_ADD_TC(tp, before_start);
+	ATF_TP_ADD_TC(tp, before_start_no_threads);
+	ATF_TP_ADD_TC(tp, before_start_one_thread);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libpthread

2010-07-18 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Jul 18 22:30:55 UTC 2010

Modified Files:
src/tests/lib/libpthread: t_sem.c

Log Message:
Reduce sleep time for practically the same effect.  Until atf can
do parallel test execution, tests which spend 99.% of their
execution sleeping are not nice.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_sem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_sem.c
diff -u src/tests/lib/libpthread/t_sem.c:1.1 src/tests/lib/libpthread/t_sem.c:1.2
--- src/tests/lib/libpthread/t_sem.c:1.1	Fri Jul 16 15:42:53 2010
+++ src/tests/lib/libpthread/t_sem.c	Sun Jul 18 22:30:55 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sem.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
+/* $NetBSD: t_sem.c,v 1.2 2010/07/18 22:30:55 pooka Exp $ */
 
 /*
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sem.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
+__RCSID("$NetBSD: t_sem.c,v 1.2 2010/07/18 22:30:55 pooka Exp $");
 
 #include 
 #include 
@@ -191,7 +191,7 @@
 		}
 
 		for (i = 0; i < NTHREADS; i++) {
-			sleep(1);
+			usleep(1);
 			printf("main loop %u: posting...\n", j+1);
 			SEM_REQUIRE(sem_post(&sem_a));
 		}



CVS commit: src/tests/lib/libpthread

2010-07-16 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Fri Jul 16 18:16:43 UTC 2010

Modified Files:
src/tests/lib/libpthread: t_mutex.c

Log Message:
Add missing pthread_mutex_init call in mutex3 testcase.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libpthread/t_mutex.c
diff -u src/tests/lib/libpthread/t_mutex.c:1.1 src/tests/lib/libpthread/t_mutex.c:1.2
--- src/tests/lib/libpthread/t_mutex.c:1.1	Fri Jul 16 15:42:53 2010
+++ src/tests/lib/libpthread/t_mutex.c	Fri Jul 16 18:16:43 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
+/* $NetBSD: t_mutex.c,v 1.2 2010/07/16 18:16:43 njoly Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.2 2010/07/16 18:16:43 njoly Exp $");
 
 #include 
 #include 
@@ -179,6 +179,8 @@
 
 	printf("1: Mutex-test 3\n");
 
+	PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
 	global_x = 0;
 	count = count2 = 1000;