CVS commit: src/tests/lib/libpthread

2023-11-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Nov 28 00:27:05 UTC 2023

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

Log Message:
libpthread/t_stack: Fix format string for size_t.

Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


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

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



CVS commit: src/tests/lib/libpthread

2023-11-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Nov 28 00:27:05 UTC 2023

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

Log Message:
libpthread/t_stack: Fix format string for size_t.

Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libpthread/t_stack.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_stack.c
diff -u src/tests/lib/libpthread/t_stack.c:1.4 src/tests/lib/libpthread/t_stack.c:1.5
--- src/tests/lib/libpthread/t_stack.c:1.4	Mon Nov 27 22:18:29 2023
+++ src/tests/lib/libpthread/t_stack.c	Tue Nov 28 00:27:05 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_stack.c,v 1.4 2023/11/27 22:18:29 riastradh Exp $	*/
+/*	$NetBSD: t_stack.c,v 1.5 2023/11/28 00:27:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #define	_KMEMUSER		/* __MACHINE_STACK_GROWS_UP */
 
 #include 
-__RCSID("$NetBSD: t_stack.c,v 1.4 2023/11/27 22:18:29 riastradh Exp $");
+__RCSID("$NetBSD: t_stack.c,v 1.5 2023/11/28 00:27:05 riastradh Exp $");
 
 #include 
 #include 
@@ -127,7 +127,7 @@ getdefaultguardsize(void)
 	 */
 	extern size_t pthread__guardsize; /* pthread_int.h */
 	ATF_CHECK_EQ_MSG(guardsize, pthread__guardsize,
-	"guardsize=%zu pthread__guardsize=%zu",
+	"guardsize=%u pthread__guardsize=%zu",
 	guardsize, pthread__guardsize);
 
 	return guardsize;



CVS commit: src/tests/lib/libpthread

2023-11-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov 27 22:18:29 UTC 2023

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

Log Message:
libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.

The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.

Noted by prlw1.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


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

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



CVS commit: src/tests/lib/libpthread

2023-11-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov 27 22:18:29 UTC 2023

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

Log Message:
libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.

The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.

Noted by prlw1.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libpthread/t_stack.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_stack.c
diff -u src/tests/lib/libpthread/t_stack.c:1.3 src/tests/lib/libpthread/t_stack.c:1.4
--- src/tests/lib/libpthread/t_stack.c:1.3	Mon Nov 27 22:17:41 2023
+++ src/tests/lib/libpthread/t_stack.c	Mon Nov 27 22:18:29 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_stack.c,v 1.3 2023/11/27 22:17:41 riastradh Exp $	*/
+/*	$NetBSD: t_stack.c,v 1.4 2023/11/27 22:18:29 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #define	_KMEMUSER		/* __MACHINE_STACK_GROWS_UP */
 
 #include 
-__RCSID("$NetBSD: t_stack.c,v 1.3 2023/11/27 22:17:41 riastradh Exp $");
+__RCSID("$NetBSD: t_stack.c,v 1.4 2023/11/27 22:18:29 riastradh Exp $");
 
 #include 
 #include 
@@ -216,8 +216,8 @@ checksigsegv(const char *p)
 	memset(, 0, sizeof(act));
 	act.sa_handler = _ok;
 
-	pthread_setspecific(C->jmp_key, );
 	if (setjmp(j.buf) == 0) {
+		pthread_setspecific(C->jmp_key, );
 		RL(sigaction(SIGSEGV, , ));
 		oactsave = oact;
 		v = *p;		/* trigger SIGSEGV */
@@ -249,8 +249,8 @@ checknosigsegv(const char *p)
 	memset(, 0, sizeof(act));
 	act.sa_handler = _ok;
 
-	pthread_setspecific(C->jmp_key, );
 	if (setjmp(j.buf) == 0) {
+		pthread_setspecific(C->jmp_key, );
 		RL(sigaction(SIGSEGV, , ));
 		oactsave = oact;
 		v = *p;		/* better not trigger SIGSEGV */



CVS commit: src/tests/lib/libpthread

2023-11-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov 27 22:17:41 UTC 2023

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

Log Message:
libpthread/t_stack: Omit needless cast in previous.

Arose from an earlier draft of the change.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/t_stack.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_stack.c
diff -u src/tests/lib/libpthread/t_stack.c:1.2 src/tests/lib/libpthread/t_stack.c:1.3
--- src/tests/lib/libpthread/t_stack.c:1.2	Mon Nov 27 22:15:08 2023
+++ src/tests/lib/libpthread/t_stack.c	Mon Nov 27 22:17:41 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_stack.c,v 1.2 2023/11/27 22:15:08 riastradh Exp $	*/
+/*	$NetBSD: t_stack.c,v 1.3 2023/11/27 22:17:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #define	_KMEMUSER		/* __MACHINE_STACK_GROWS_UP */
 
 #include 
-__RCSID("$NetBSD: t_stack.c,v 1.2 2023/11/27 22:15:08 riastradh Exp $");
+__RCSID("$NetBSD: t_stack.c,v 1.3 2023/11/27 22:17:41 riastradh Exp $");
 
 #include 
 #include 
@@ -169,7 +169,7 @@ init(size_t stacksize)
 
 	C->size = stacksize;
 	C->guardsize = getdefaultguardsize();
-	C->addr = (char *)alloc(C->size + C->guardsize);
+	C->addr = alloc(C->size + C->guardsize);
 	RZ(pthread_key_create(>jmp_key, NULL));
 }
 



CVS commit: src/tests/lib/libpthread

2023-11-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov 27 22:17:41 UTC 2023

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

Log Message:
libpthread/t_stack: Omit needless cast in previous.

Arose from an earlier draft of the change.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


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

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



CVS commit: src/tests/lib/libpthread

2023-11-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov 27 22:15:08 UTC 2023

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

Log Message:
libpthread/t_stack: Make this more robust to the guard size bug.

Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libpthread/t_stack.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_stack.c
diff -u src/tests/lib/libpthread/t_stack.c:1.1 src/tests/lib/libpthread/t_stack.c:1.2
--- src/tests/lib/libpthread/t_stack.c:1.1	Fri Nov 24 16:21:17 2023
+++ src/tests/lib/libpthread/t_stack.c	Mon Nov 27 22:15:08 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_stack.c,v 1.1 2023/11/24 16:21:17 riastradh Exp $	*/
+/*	$NetBSD: t_stack.c,v 1.2 2023/11/27 22:15:08 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,11 +29,15 @@
 #define	_KMEMUSER		/* __MACHINE_STACK_GROWS_UP */
 
 #include 
-__RCSID("$NetBSD: t_stack.c,v 1.1 2023/11/24 16:21:17 riastradh Exp $");
+__RCSID("$NetBSD: t_stack.c,v 1.2 2023/11/27 22:15:08 riastradh Exp $");
 
 #include 
+#include 
+#include 
 #include 
 
+#include 	/* VM_THREAD_GUARD_SIZE */
+
 #include 
 #include 
 #include 
@@ -52,6 +56,7 @@ struct jmp_ctx {
  */
 struct ctx {
 	size_t size;		/* default stack size */
+	size_t guardsize;	/* default guard size */
 	void *addr;		/* user-allocated stack */
 	pthread_key_t jmp_key;	/* jmp_ctx to return from SIGSEGV handler */
 } ctx, *C = 
@@ -101,6 +106,34 @@ getnondefaultstacksize(void)
 }
 
 /*
+ * getdefaultguardsize()
+ *
+ *	Return the default guard size for threads created with
+ *	pthread_create.
+ */
+static size_t
+getdefaultguardsize(void)
+{
+	const int mib[2] = { CTL_VM, VM_THREAD_GUARD_SIZE };
+	unsigned guardsize;
+	size_t len = sizeof(guardsize);
+
+	RL(sysctl(mib, __arraycount(mib), , , NULL, 0));
+	ATF_REQUIRE_EQ_MSG(len, sizeof(guardsize),
+	"len=%zu sizeof(guardsize)=%zu", len, sizeof(guardsize));
+
+	/*
+	 * Verify this matches what libpthread determined.
+	 */
+	extern size_t pthread__guardsize; /* pthread_int.h */
+	ATF_CHECK_EQ_MSG(guardsize, pthread__guardsize,
+	"guardsize=%zu pthread__guardsize=%zu",
+	guardsize, pthread__guardsize);
+
+	return guardsize;
+}
+
+/*
  * alloc(nbytes)
  *
  *	Allocate an nbytes-long page-aligned read/write region and
@@ -124,17 +157,35 @@ alloc(size_t nbytes)
  *
  *	Initialize state used by various tests with the specified
  *	stacksize.
+ *
+ *	Make sure to allocate enough space that even if there shouldn't
+ *	be a stack guard (i.e., it should be empty), adjusting the
+ *	requested bounds by the default stack guard size will leave us
+ *	inside allocated memory.
  */
 static void
 init(size_t stacksize)
 {
 
 	C->size = stacksize;
-	C->addr = alloc(C->size);
+	C->guardsize = getdefaultguardsize();
+	C->addr = (char *)alloc(C->size + C->guardsize);
 	RZ(pthread_key_create(>jmp_key, NULL));
 }
 
 /*
+ * stack_pointer()
+ *
+ *	Return the stack pointer.  This is used to verify whether the
+ *	stack pointer lie within a certain address range.
+ */
+static __noinline void *
+stack_pointer(void)
+{
+	return __builtin_frame_address(0);
+}
+
+/*
  * sigsegv_ok(signo)
  *
  *	Signal handler for SIGSEGV to return to the jmp ctx, to verify
@@ -276,10 +327,37 @@ checkaddraccessthread(void *cookie)
 {
 	pthread_t t = pthread_self();
 	pthread_attr_t attr;
+	void *sp;
 	void *addr;
 	size_t size, size0;
 
 	/*
+	 * Verify the stack pointer lies somewhere in the allocated
+	 * range.
+	 */
+	sp = stack_pointer();
+	ATF_CHECK_MSG(C->addr <= sp, "sp=%p not in [%p,%p + 0x%zu) = [%p,%p)",
+	sp, C->addr, C->addr, C->size, C->addr, (char *)C->addr + C->size);
+	ATF_CHECK_MSG(sp <= (void *)((char *)C->addr + C->size),
+	"sp=%p not in [%p,%p + 0x%zu) = [%p,%p)",
+	sp, C->addr, C->addr, C->size, C->addr, (char *)C->addr + C->size);
+
+	/*
+	 * Verify, if not that, then the stack pointer at least lies
+	 * within the extra buffer we allocated for slop to address a
+	 * bug NetBSD libpthread used to have of spuriously adding the
+	 * guard size to a user-allocated stack address.  This is
+	 * ATF_REQUIRE, not ATF_CHECK, because if this doesn't hold, we
+	 * might be clobbering some other memory like malloc pages,
+	 * causing the whole test to crash with useless diagnostics.
+	 */
+	ATF_REQUIRE_MSG(sp <= (void *)((char *)C->addr + C->size +
+		C->guardsize),
+	"sp=%p not even in buffer [%p,%p + 0x%zu + 0x%zu) = [%p,%p)",
+	sp, C->addr, C->addr, 

CVS commit: src/tests/lib/libpthread

2023-11-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov 27 22:15:08 UTC 2023

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

Log Message:
libpthread/t_stack: Make this more robust to the guard size bug.

Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


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

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



CVS commit: src/tests/lib/libpthread

2022-12-11 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Dec 11 10:02:53 UTC 2022

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

Log Message:
This test makes (made) a false assumption about the way that
process scheduling works.   That a process (or in this case,
a thread) is no longer blocked at time T does not mean that it
will resume execution at time T.   The OS is free to devote
resources to other processes/threads instead - all we should
normally be able to expect is that if it is not unblocked before
time T, that it will not start running before then.

In general though, the pthread_cond_*wait() functions don't guarantee
even that - but for this test, the possibility of something else
randomly signalling the condvar isn't believable, so don't worry about
that possibility (but do fail without calling strerror(0) on the off
chance it does happen).

Once we cease testing that the process resumed running before some
particular time, we can stop dealing with qemu timekeeping issues,
it might (seem to) take qemu twice as long as was requested before
the thread resumes, but that's OK - the same thing could happen on
a loaded system for other reasons.

Beyond that, the test also has (had) a race condition.   When using
CLOCK_REALTIME though that clock needed to have advanced to T before
the ETIMEDOUT should happen, there is no guarantee that it will stay >T
(CLOCK_REALTIME is allowed to be reset backwards).   So, only test
that the current time (after ETIMEDOUT) >= T when we're using
CLOCK_MONOTONIC - for CLOCK_REALTIME the time might have stepped
back between when the ETIMEDOUT happened and when the thread
obtains the current clock reading.  For that case, all we can test
is that the ETIMEDOUT actually happens.

With much of what was there now gone, the code can be simplified,
we no longer need to do timespec arithmetic, just one comparison
(simpler to test that Tend >= Tstart+period than Tend-Tstart > period
as we need Tstart+period for the abstime value for the timeout anyway).

Note that this still tests for the issue reported in PR lib/47703
which is where the test came from in the first place.

ps: we seem to be missing pthread_cond_clockwait() which is the same
as pthread_cond_timedwait() except that the clock to use is passed
as a parameter, rather than as an attribute of the condition variable.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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.9 src/tests/lib/libpthread/t_condwait.c:1.10
--- src/tests/lib/libpthread/t_condwait.c:1.9	Sat Apr 16 18:15:22 2022
+++ src/tests/lib/libpthread/t_condwait.c	Sun Dec 11 10:02:53 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_condwait.c,v 1.9 2022/04/16 18:15:22 andvar Exp $ */
+/* $NetBSD: t_condwait.c,v 1.10 2022/12/11 10:02:53 kre Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_condwait.c,v 1.9 2022/04/16 18:15:22 andvar Exp $");
+__RCSID("$NetBSD: t_condwait.c,v 1.10 2022/12/11 10:02:53 kre Exp $");
 
 #include 
 #include 
@@ -50,7 +50,7 @@ static const int debug = 1;
 static void *
 run(void *param)
 {
-	struct timespec ts, to, te, twmin, twmax;
+	struct timespec ts, to, te;
 	clockid_t clck;
 	pthread_condattr_t attr;
 	pthread_cond_t cond;
@@ -78,30 +78,18 @@ run(void *param)
 	case ETIMEDOUT:
 		/* Timeout */
 		ATF_REQUIRE_EQ(clock_gettime(clck, ), 0);
-		timespecsub(, , );
 		if (debug) {
 			printf("timeout: %lld.%09ld sec\n",
 			(long long)te.tv_sec, te.tv_nsec);
+			timespecsub(, , );
 			printf("elapsed: %lld.%09ld sec\n",
 			(long long)to.tv_sec, to.tv_nsec);
 		}
-		twmin.tv_sec = WAITTIME;
-		twmin.tv_nsec = 0;
-		if (isQEMU()) {
-			struct timespec td, t;
-			// td.tv_sec = 0;
-			// td.tv_nsec = 9;
-			t = twmin;
-			// timespecsub(, , );
-			td.tv_sec = 2;
-			td.tv_nsec = 5;
-			timespecadd(, , );
-		} else {
-			twmax = twmin;
-			twmax.tv_sec++;
-		}
-		ATF_REQUIRE(timespeccmp(, , >=));
-		ATF_REQUIRE(timespeccmp(, , <=));
+		if (clck == CLOCK_MONOTONIC)
+			ATF_REQUIRE(timespeccmp(, , >=));
+		break;
+	case 0:
+		atf_tc_fail("pthread_cond_timedwait returned before timeout");
 		break;
 	default:
 		ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret));



CVS commit: src/tests/lib/libpthread

2022-12-11 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Dec 11 10:02:53 UTC 2022

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

Log Message:
This test makes (made) a false assumption about the way that
process scheduling works.   That a process (or in this case,
a thread) is no longer blocked at time T does not mean that it
will resume execution at time T.   The OS is free to devote
resources to other processes/threads instead - all we should
normally be able to expect is that if it is not unblocked before
time T, that it will not start running before then.

In general though, the pthread_cond_*wait() functions don't guarantee
even that - but for this test, the possibility of something else
randomly signalling the condvar isn't believable, so don't worry about
that possibility (but do fail without calling strerror(0) on the off
chance it does happen).

Once we cease testing that the process resumed running before some
particular time, we can stop dealing with qemu timekeeping issues,
it might (seem to) take qemu twice as long as was requested before
the thread resumes, but that's OK - the same thing could happen on
a loaded system for other reasons.

Beyond that, the test also has (had) a race condition.   When using
CLOCK_REALTIME though that clock needed to have advanced to T before
the ETIMEDOUT should happen, there is no guarantee that it will stay >T
(CLOCK_REALTIME is allowed to be reset backwards).   So, only test
that the current time (after ETIMEDOUT) >= T when we're using
CLOCK_MONOTONIC - for CLOCK_REALTIME the time might have stepped
back between when the ETIMEDOUT happened and when the thread
obtains the current clock reading.  For that case, all we can test
is that the ETIMEDOUT actually happens.

With much of what was there now gone, the code can be simplified,
we no longer need to do timespec arithmetic, just one comparison
(simpler to test that Tend >= Tstart+period than Tend-Tstart > period
as we need Tstart+period for the abstime value for the timeout anyway).

Note that this still tests for the issue reported in PR lib/47703
which is where the test came from in the first place.

ps: we seem to be missing pthread_cond_clockwait() which is the same
as pthread_cond_timedwait() except that the clock to use is passed
as a parameter, rather than as an attribute of the condition variable.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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.



CVS commit: src/tests/lib/libpthread

2022-05-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat May  7 05:13:17 UTC 2022

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

Log Message:
Bump timeout for slow machines.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 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.19 src/tests/lib/libpthread/t_mutex.c:1.20
--- src/tests/lib/libpthread/t_mutex.c:1.19	Fri Dec  1 13:25:29 2017
+++ src/tests/lib/libpthread/t_mutex.c	Sat May  7 05:13:17 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.19 2017/12/01 13:25:29 kre Exp $ */
+/* $NetBSD: t_mutex.c,v 1.20 2022/05/07 05:13:17 rin 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.19 2017/12/01 13:25:29 kre Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.20 2022/05/07 05:13:17 rin Exp $");
 
 #include  /* For timespecadd */
 #include  /* For UINT16_MAX */
@@ -148,6 +148,7 @@ ATF_TC(mutex2);
 ATF_TC_HEAD(mutex2, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes");
+	atf_tc_set_md_var(tc, "timeout", "600");
 }
 ATF_TC_BODY(mutex2, tc)
 {
@@ -204,6 +205,7 @@ ATF_TC_HEAD(mutex3, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Checks mutexes using a static "
 	"initializer");
+	atf_tc_set_md_var(tc, "timeout", "600");
 }
 ATF_TC_BODY(mutex3, tc)
 {



CVS commit: src/tests/lib/libpthread

2022-05-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat May  7 05:13:17 UTC 2022

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

Log Message:
Bump timeout for slow machines.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 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.



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-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.



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();
 
 	ATF_REQUIRE_EQ(mtx_init(, mtx_recursive), thrd_error);
-	mtx_destroy();
 
 	ATF_REQUIRE_EQ(mtx_init(, mtx_plain | mtx_timed), thrd_error);
-	mtx_destroy();
 
 	ATF_REQUIRE_EQ(mtx_init(, -1), thrd_error);
-	mtx_destroy();
 }
 
 ATF_TC(mtx_lock);



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.



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.



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(_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(), ) == 0);
+	ATF_REQUIRE(pthread_getattr_np(pthread_self(), ) == 0);
 	ATF_REQUIRE(pthread_attr_getstacksize(, ) == 0);
 	ATF_REQUIRE(stacksize == STACKSIZE * (j + 1));
 	ATF_REQUIRE(pthread_attr_getguardsize(, ) == 0);



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.



CVS commit: src/tests/lib/libpthread

2019-08-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug 11 11:42:23 UTC 2019

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

Log Message:
Re-enable the QEMU specific timing limits, but only an increased upper
limit for now - let's see if that works on the test-bed.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.



CVS commit: src/tests/lib/libpthread

2019-08-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug 11 11:42:23 UTC 2019

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

Log Message:
Re-enable the QEMU specific timing limits, but only an increased upper
limit for now - let's see if that works on the test-bed.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.7 src/tests/lib/libpthread/t_condwait.c:1.8
--- src/tests/lib/libpthread/t_condwait.c:1.7	Sat Aug 10 07:36:15 2019
+++ src/tests/lib/libpthread/t_condwait.c	Sun Aug 11 11:42:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: t_condwait.c,v 1.7 2019/08/10 07:36:15 martin Exp $ */
+/* $NetBSD: t_condwait.c,v 1.8 2019/08/11 11:42:23 martin Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_condwait.c,v 1.7 2019/08/10 07:36:15 martin Exp $");
+__RCSID("$NetBSD: t_condwait.c,v 1.8 2019/08/11 11:42:23 martin Exp $");
 
 #include 
 #include 
@@ -87,12 +87,12 @@ run(void *param)
 		}
 		twmin.tv_sec = WAITTIME;
 		twmin.tv_nsec = 0;
-		if (0 /* XXX */ && isQEMU()) {
+		if (isQEMU()) {
 			struct timespec td, t;
-			td.tv_sec = 0;
-			td.tv_nsec = 9;
+			// td.tv_sec = 0;
+			// td.tv_nsec = 9;
 			t = twmin;
-			timespecsub(, , );
+			// timespecsub(, , );
 			td.tv_sec = 2;
 			td.tv_nsec = 5;
 			timespecadd(, , );



CVS commit: src/tests/lib/libpthread

2019-08-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Aug 10 07:36:15 UTC 2019

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

Log Message:
PR lib/54440: adapt the FreeBSD change to this test and calculate time
differences more exact, allowing between 0 and 1 s delay between the
expected wakeup and the actual event happening.
Also convert the QEMU special case code to the same scheme, but for now
disable it (with XXX mark) and see if the proper timing limits fix that
case too.
If not, we will re-enable the QEMU special case.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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.6 src/tests/lib/libpthread/t_condwait.c:1.7
--- src/tests/lib/libpthread/t_condwait.c:1.6	Tue Jul  9 16:24:01 2019
+++ src/tests/lib/libpthread/t_condwait.c	Sat Aug 10 07:36:15 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: t_condwait.c,v 1.6 2019/07/09 16:24:01 maya Exp $ */
+/* $NetBSD: t_condwait.c,v 1.7 2019/08/10 07:36:15 martin Exp $ */
 
 /*
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_condwait.c,v 1.6 2019/07/09 16:24:01 maya Exp $");
+__RCSID("$NetBSD: t_condwait.c,v 1.7 2019/08/10 07:36:15 martin Exp $");
 
 #include 
 #include 
@@ -50,7 +50,7 @@ static const int debug = 1;
 static void *
 run(void *param)
 {
-	struct timespec ts, to, te;
+	struct timespec ts, to, te, twmin, twmax;
 	clockid_t clck;
 	pthread_condattr_t attr;
 	pthread_cond_t cond;
@@ -85,14 +85,23 @@ run(void *param)
 			printf("elapsed: %lld.%09ld sec\n",
 			(long long)to.tv_sec, to.tv_nsec);
 		}
-		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);
+		twmin.tv_sec = WAITTIME;
+		twmin.tv_nsec = 0;
+		if (0 /* XXX */ && isQEMU()) {
+			struct timespec td, t;
+			td.tv_sec = 0;
+			td.tv_nsec = 9;
+			t = twmin;
+			timespecsub(, , );
+			td.tv_sec = 2;
+			td.tv_nsec = 5;
+			timespecadd(, , );
 		} else {
-			ATF_REQUIRE_EQ(to.tv_sec, WAITTIME);
+			twmax = twmin;
+			twmax.tv_sec++;
 		}
+		ATF_REQUIRE(timespeccmp(, , >=));
+		ATF_REQUIRE(timespeccmp(, , <=));
 		break;
 	default:
 		ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret));



CVS commit: src/tests/lib/libpthread

2019-08-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Aug 10 07:36:15 UTC 2019

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

Log Message:
PR lib/54440: adapt the FreeBSD change to this test and calculate time
differences more exact, allowing between 0 and 1 s delay between the
expected wakeup and the actual event happening.
Also convert the QEMU special case code to the same scheme, but for now
disable it (with XXX mark) and see if the proper timing limits fix that
case too.
If not, we will re-enable the QEMU special case.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 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.



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.



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, )) != 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(, 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([i]);
+		threads[i] = run([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  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(, ));
-
-	/* 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 = 
 
 	makecontext(, 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: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  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.



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-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.



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(, ) != -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: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.



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: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.



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(, (void *)*swapfunc, 0);
+	makecontext(, 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: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.



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.



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(, (void *)*swapfunc, 0);
-   
+
 	oself = (void *)pthread_self();
 	printf("before swapcontext self = %p\n", oself);
 	ATF_REQUIRE_MSG(swapcontext(, ) != -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, ));
-	PTHREAD_REQUIRE(pthread_getschedparam(childid, , ));
-	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(, _lengthy));
-	if (start == 0) start = 2;
-	PTHREAD_REQUIRE(pthread_mutex_unlock());
-
-	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, ));
-	PTHREAD_REQUIRE(pthread_getschedparam(childid, , ));
-	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(, _lengthy));
-	if (start == 0)
-		start = 1;
-	PTHREAD_REQUIRE(pthread_mutex_unlock());
-
-	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;
-
-	min_fifo_prio = 

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.



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-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.



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-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.



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(, _lengthy));
+	PTHREAD_REQUIRE(mutex_lock(, _lengthy));
 	if (start == 0) start = 2;
-	PTHREAD_REQUIRE(pthread_mutex_unlock());
+	PTHREAD_REQUIRE(pthread_mutex_unlock());
 
 	return 0;
 }
@@ -431,10 +430,10 @@ low_prio(void* arg)
 		low_cnt = 0;
 		sleep(1);
 	}
-	PTHREAD_REQUIRE(mutex_lock(, _lengthy));
+	PTHREAD_REQUIRE(mutex_lock(, _lengthy));
 	if (start == 0)
 		start = 1;
-	PTHREAD_REQUIRE(pthread_mutex_unlock());
+	PTHREAD_REQUIRE(pthread_mutex_unlock());
 
 	return 0;
 }



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.



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(, 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-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.



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 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.



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: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.



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();
-	pthread_condattr_setclock(, clck); /* MONOTONIC or MONOTONIC */
+	PTHREAD_REQUIRE(pthread_condattr_init());
+	PTHREAD_REQUIRE(pthread_condattr_setclock(, clck));
 	pthread_cond_init(, );
 
 	ATF_REQUIRE_EQ((ret = pthread_mutex_lock()), 0);



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.



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: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.



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(, 0, bar, 0);
+	PTHREAD_REQUIRE(pthread_create(, 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(_depth_lock, 0));
 
-	pthread_create(, 0, stir, stirseed);
+	PTHREAD_REQUIRE(pthread_create(, 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(, ));
+	ATF_REQUIRE_MSG(swapcontext(, ) != -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());
+	ATF_REQUIRE_MSG(getcontext() != -1, "getcontext failed: %s",
+	strerror(errno));
 	PTHREAD_REQUIRE(pthread_create(, 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: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.



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.



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(,
+		));
+
+		printf("priority: %d\nprotocol: %d\n", i, protocol);
 		PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(, i));
 		PTHREAD_REQUIRE(pthread_mutexattr_getprioceiling(,
 		));
+		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: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.



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

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.



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.



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(, NULL));
 
-	printf("Before acquiring regular mutex\n");
+	printf("Before acquiring mutex\n");
 	PTHREAD_REQUIRE(pthread_mutex_lock());
 
 	printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
 	PTHREAD_REQUIRE_STATUS(mutex_lock(, _shortlived),
 	ETIMEDOUT);
 
-	printf("Unlocking timed-mutex\n");
+	printf("Unlocking mutex\n");
 	PTHREAD_REQUIRE(pthread_mutex_unlock());
 }
 
@@ -616,14 +616,80 @@ ATF_TC_BODY(timedmutex2, tc)
 
 	PTHREAD_REQUIRE(pthread_mutex_init(, NULL));
 
-	printf("Before acquiring timed-mutex with timedlock\n");
+	printf("Before acquiring mutex with timedlock\n");
 	PTHREAD_REQUIRE(mutex_lock(, _lengthy));
 
 	printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
 	PTHREAD_REQUIRE_STATUS(mutex_lock(, _shortlived),
 	ETIMEDOUT);
 
-	printf("Unlocking timed-mutex\n");
+	printf("Unlocking mutex\n");
+	PTHREAD_REQUIRE(pthread_mutex_unlock());
+}
+
+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(, _shortlived),
+	ETIMEDOUT);
+
+	return NULL;
+}
+
+ATF_TC_BODY(timedmutex3, tc)
+{
+	pthread_t new;
+
+	printf("Timed mutex-test 3\n");
+
+	PTHREAD_REQUIRE(pthread_mutex_init(, NULL));
+
+	printf("Before acquiring mutex with timedlock\n");
+	PTHREAD_REQUIRE(pthread_mutex_lock());
+
+	printf("Before creating new thread\n");
+	PTHREAD_REQUIRE(pthread_create(, 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());
+}
+
+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(, NULL));
+
+	printf("Before acquiring mutex with timedlock\n");
+	PTHREAD_REQUIRE(mutex_lock(, _lengthy));
+
+	printf("Before creating new thread\n");
+	PTHREAD_REQUIRE(pthread_create(, 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());
 }
 #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();



Re: CVS commit: src/tests/lib/libpthread

2016-10-31 Thread Christos Zoulas
In article <0c9230c6-d206-5332-d89c-e0b93d3de...@gmx.com>,
Kamil Rytarowski   wrote:
>-=-=-=-=-=-
>-=-=-=-=-=-
>
>
>
>On 31.10.2016 21:23, Taylor R Campbell wrote:
>>Date: Mon, 31 Oct 2016 18:29:56 +0100
>>From: Kamil Rytarowski 
>> 
>>pthread_mutex_timedlock(3) is broken and it does not work at all for me,
>>not as a standard mutex (like pthread_mutex_lock(3), sufficiently
>>lengthy timeout makes it a good approximation) neither as a timed variant.
>> 
>> If the test is expected to fail, you should mark it xfail with a
>> reference to a PR so that it doesn't draw needless attention to
>> itself.
>> 
>> The autobuild system is designed to detect and flag unexpected
>> failures; expected ones should be documented in the PR database
>> instead.
>> 
>
>You are right, thank you.
>
>The problem is under investigation right now and is "hot".

I have a patch for it:

http://www.netbsd.org/~christos/deadlock.diff
And a standalone program that reproduces it (from the test):
http://www.netbsd.org/~christos/deadlock.c

christos



Re: CVS commit: src/tests/lib/libpthread

2016-10-31 Thread Kamil Rytarowski


On 31.10.2016 21:23, Taylor R Campbell wrote:
>Date: Mon, 31 Oct 2016 18:29:56 +0100
>From: Kamil Rytarowski 
> 
>pthread_mutex_timedlock(3) is broken and it does not work at all for me,
>not as a standard mutex (like pthread_mutex_lock(3), sufficiently
>lengthy timeout makes it a good approximation) neither as a timed variant.
> 
> If the test is expected to fail, you should mark it xfail with a
> reference to a PR so that it doesn't draw needless attention to
> itself.
> 
> The autobuild system is designed to detect and flag unexpected
> failures; expected ones should be documented in the PR database
> instead.
> 

You are right, thank you.

The problem is under investigation right now and is "hot".



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libpthread

2016-10-31 Thread Taylor R Campbell
   Date: Mon, 31 Oct 2016 18:29:56 +0100
   From: Kamil Rytarowski 

   pthread_mutex_timedlock(3) is broken and it does not work at all for me,
   not as a standard mutex (like pthread_mutex_lock(3), sufficiently
   lengthy timeout makes it a good approximation) neither as a timed variant.

If the test is expected to fail, you should mark it xfail with a
reference to a PR so that it doesn't draw needless attention to
itself.

The autobuild system is designed to detect and flag unexpected
failures; expected ones should be documented in the PR database
instead.


Re: CVS commit: src/tests/lib/libpthread

2016-10-31 Thread Kamil Rytarowski


On 31.10.2016 17:21, Christos Zoulas wrote:
> 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?
> 
> 

Tests are good.

pthread_mutex_timedlock(3) is broken and it does not work at all for me,
not as a standard mutex (like pthread_mutex_lock(3), sufficiently
lengthy timeout makes it a good approximation) neither as a timed variant.



signature.asc
Description: OpenPGP digital signature


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.



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(, NULL));
 
-	printf("Before acquiring timed-mutex\n");
+	printf("Before acquiring regular mutex\n");
 	PTHREAD_REQUIRE(pthread_mutex_lock());
 
 	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(, NULL));
 
 	printf("Before acquiring timed-mutex with timedlock\n");
 	PTHREAD_REQUIRE(mutex_lock(, _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(, _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, _wait) != -1);
+	timespecadd(_wait, ts, _wait);
+
+	return pthread_mutex_timedlock(m, _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_lock(, _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(, NULL));
 	x = 1;
-	PTHREAD_REQUIRE(pthread_mutex_lock());
+	PTHREAD_REQUIRE(mutex_lock(, _lengthy));
 	PTHREAD_REQUIRE(pthread_create(, NULL, mutex1_threadfunc, ));
 	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, ));
 
-	PTHREAD_REQUIRE(pthread_mutex_lock());
+	PTHREAD_REQUIRE(mutex_lock(, _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());
+		PTHREAD_REQUIRE(mutex_lock(, _lengthy));
 		global_x++;
 		PTHREAD_REQUIRE(pthread_mutex_unlock());
 	}
@@ -143,7 +167,7 @@ ATF_TC_BODY(mutex2, tc)
 	global_x = 0;
 	count = count2 = 1000;
 
-	PTHREAD_REQUIRE(pthread_mutex_lock());
+	PTHREAD_REQUIRE(mutex_lock(, _lengthy));
 	PTHREAD_REQUIRE(pthread_create(, NULL, mutex2_threadfunc, ));
 
 	printf("1: Thread %p\n", pthread_self());
@@ -151,14 +175,14 @@ ATF_TC_BODY(mutex2, tc)
 	PTHREAD_REQUIRE(pthread_mutex_unlock());
 
 	while (count--) {
-		PTHREAD_REQUIRE(pthread_mutex_lock());
+		PTHREAD_REQUIRE(mutex_lock(, _lengthy));
 		global_x++;
 		PTHREAD_REQUIRE(pthread_mutex_unlock());
 	}
 
 	PTHREAD_REQUIRE(pthread_join(new, ));
 
-	PTHREAD_REQUIRE(pthread_mutex_lock());
+	PTHREAD_REQUIRE(mutex_lock(, _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(_mutex));
+		PTHREAD_REQUIRE(mutex_lock(_mutex, _lengthy));
 		global_x++;
 		PTHREAD_REQUIRE(pthread_mutex_unlock(_mutex));
 	}
@@ -212,7 +236,7 @@ ATF_TC_BODY(mutex3, tc)
 	global_x = 0;
 	count = count2 = 1000;
 
-	PTHREAD_REQUIRE(pthread_mutex_lock(_mutex));
+	PTHREAD_REQUIRE(mutex_lock(_mutex, _lengthy));
 	PTHREAD_REQUIRE(pthread_create(, NULL, mutex3_threadfunc, ));
 
 	printf("1: Thread %p\n", pthread_self());
@@ -220,14 +244,14 @@ ATF_TC_BODY(mutex3, tc)
 	PTHREAD_REQUIRE(pthread_mutex_unlock(_mutex));
 
 	while (count--) {

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.



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());
 	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());
 	PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(,
@@ -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-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.



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, );
 	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(, 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, );
 	printf("previous policy used = %d\n", res);



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.



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 sys/cdefs.h
 __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 errno.h
 #include pthread.h
@@ -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

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.



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 sys/cdefs.h
 __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 sys/time.h
 
@@ -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-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.



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

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.



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 sys/cdefs.h
-__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 errno.h
 #include pthread.h
@@ -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-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 sys/cdefs.h
-__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 errno.h
 #include pthread.h
@@ -38,6 +38,8 @@ __RCSID($NetBSD: t_condwait.c,v 1.3 201
 
 #include atf-c.h
 
+#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.



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.



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 sys/cdefs.h
+__RCSID($NetBSD: t_condwait.c,v 1.1 2013/03/28 18:50:01 christos Exp $);
+
+#include errno.h
+#include pthread.h
+#include stdio.h
+#include stdlib.h
+#include string.h
+#include time.h
+#include unistd.h
+
+#include atf-c.h
+
+#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);
+}
+

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 sys/cdefs.h
-__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 errno.h
 #include pthread.h
@@ -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.



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.



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 bsd.test.mk

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 bsd.own.mk
+
+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 bsd.test.mk
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 sys/cdefs.h
+__RCSID($NetBSD: t_dlopen.c,v 1.1 2013/03/21 16:50:21 christos Exp $);
+
+#include atf-c.h
+#include dlfcn.h
+#include pthread.h
+#include unistd.h
+
+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 

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.



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 sys/cdefs.h
 __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 sys/time.h
 
@@ -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

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.



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 sys/cdefs.h
-__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 errno.h
 #include pthread.h
@@ -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-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.



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 sys/cdefs.h
 __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 errno.h
 #include fcntl.h
@@ -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

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.



  1   2   >