CVS commit: src/tests/lib/libc/sys

2024-10-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Oct 18 16:39:41 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_select.c

Log Message:
tests/lib/libc/sys/t_select: Test select on bad file descriptors.

This should immediately fail, not hang, even if the bad fd is
high-numbered.

PR kern/57504: select with large enough bogus fd number set hangs
instead of failing with EBADF


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_select.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/libc/sys/t_select.c
diff -u src/tests/lib/libc/sys/t_select.c:1.4 src/tests/lib/libc/sys/t_select.c:1.5
--- src/tests/lib/libc/sys/t_select.c:1.4	Fri Jan 13 21:18:33 2017
+++ src/tests/lib/libc/sys/t_select.c	Fri Oct 18 16:39:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_select.c,v 1.4 2017/01/13 21:18:33 christos Exp $ */
+/*	$NetBSD: t_select.c,v 1.5 2024/10/18 16:39:41 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,18 +29,20 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include 
 #include 
+
 #include 
 #include 
+
+#include 
 #include 
-#include 
-#include 
+#include 
+#include 
 #include 
+#include 
 #include 
+#include 
 #include 
-#include 
-#include 
 
 #include 
 
@@ -207,11 +209,42 @@ ATF_TC_BODY(pselect_timeout, tc)
 	}
 }
 
+ATF_TC(select_badfd);
+ATF_TC_HEAD(select_badfd, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Checks select rejects bad fds");
+}
+
+ATF_TC_BODY(select_badfd, tc)
+{
+	int fd;
+
+	for (fd = 0; fd < FD_SETSIZE; fd++) {
+		fd_set readfds;
+		int ret, error;
+
+		if (fcntl(fd, F_GETFL) != -1 || errno != EBADF)
+			continue;
+
+		FD_ZERO(&readfds);
+		FD_SET(fd, &readfds);
+		alarm(5);
+		errno = 0;
+		ret = select(fd + 1, &readfds, NULL, NULL, NULL);
+		error = errno;
+		alarm(0);
+		errno = error;
+		ATF_CHECK_ERRNO(EBADF, ret == -1);
+	}
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
 	ATF_TP_ADD_TC(tp, pselect_sigmask);
 	ATF_TP_ADD_TC(tp, pselect_timeout);
+	ATF_TP_ADD_TC(tp, select_badfd);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libc/sys

2024-10-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Oct 18 16:39:41 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_select.c

Log Message:
tests/lib/libc/sys/t_select: Test select on bad file descriptors.

This should immediately fail, not hang, even if the bad fd is
high-numbered.

PR kern/57504: select with large enough bogus fd number set hangs
instead of failing with EBADF


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_select.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/libc/sys

2024-09-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Sep 27 18:50:01 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_clone.c

Log Message:
tests/lib/libc/sys/t_clone: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_clone.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/libc/sys/t_clone.c
diff -u src/tests/lib/libc/sys/t_clone.c:1.5 src/tests/lib/libc/sys/t_clone.c:1.6
--- src/tests/lib/libc/sys/t_clone.c:1.5	Wed Sep 25 19:24:15 2024
+++ src/tests/lib/libc/sys/t_clone.c	Fri Sep 27 18:50:01 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_clone.c,v 1.5 2024/09/25 19:24:15 christos Exp $ */
+/* $NetBSD: t_clone.c,v 1.6 2024/09/27 18:50:01 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_clone.c,v 1.5 2024/09/25 19:24:15 christos Exp $");
+__RCSID("$NetBSD: t_clone.c,v 1.6 2024/09/27 18:50:01 riastradh Exp $");
 
 #include 
 #include 
@@ -66,7 +66,7 @@ getstack(void)
 	return stack;
 }
 
-static void 
+static void
 putstack(void *stack)
 {
 #ifndef __MACHINE_STACK_GROWS_UP



CVS commit: src/tests/lib/libc/sys

2024-09-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Sep 27 18:50:01 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_clone.c

Log Message:
tests/lib/libc/sys/t_clone: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_clone.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/libc/sys

2024-09-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 25 19:24:15 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_clone.c

Log Message:
centralize stack allocation/freeing. The test that broke with the new jemalloc
had broken stack allocation.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_clone.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/libc/sys/t_clone.c
diff -u src/tests/lib/libc/sys/t_clone.c:1.4 src/tests/lib/libc/sys/t_clone.c:1.5
--- src/tests/lib/libc/sys/t_clone.c:1.4	Tue May 23 11:56:55 2017
+++ src/tests/lib/libc/sys/t_clone.c	Wed Sep 25 15:24:15 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_clone.c,v 1.4 2017/05/23 15:56:55 christos Exp $ */
+/* $NetBSD: t_clone.c,v 1.5 2024/09/25 19:24:15 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,11 +32,12 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_clone.c,v 1.4 2017/05/23 15:56:55 christos Exp $");
+__RCSID("$NetBSD: t_clone.c,v 1.5 2024/09/25 19:24:15 christos Exp $");
 
+#include 
+#include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -53,6 +54,27 @@ __RCSID("$NetBSD: t_clone.c,v 1.4 2017/0
 #define	FROBVAL		41973
 #define	CHILDEXIT	0xa5
 
+static void *
+getstack(void)
+{
+	void *stack = mmap(NULL, STACKSIZE, PROT_READ|PROT_WRITE,
+	MAP_PRIVATE|MAP_ANON, -1, (off_t) 0);
+	ATF_REQUIRE_ERRNO(errno, stack != MAP_FAILED);
+#ifndef __MACHINE_STACK_GROWS_UP
+	stack = (char *)stack + STACKSIZE;
+#endif
+	return stack;
+}
+
+static void 
+putstack(void *stack)
+{
+#ifndef __MACHINE_STACK_GROWS_UP
+	stack = (char *)stack - STACKSIZE;
+#endif
+	ATF_REQUIRE_ERRNO(errno, munmap(stack, STACKSIZE) != -1);
+}
+
 static int
 dummy(void *arg)
 {
@@ -94,21 +116,11 @@ ATF_TC_HEAD(clone_basic, tc)
 ATF_TC_BODY(clone_basic, tc)
 {
 	sigset_t mask;
-	void *allocstack, *stack;
+	void *stack = getstack();
 	pid_t pid;
 	volatile long frobme[2];
 	int stat;
 
-	allocstack = mmap(NULL, STACKSIZE, PROT_READ|PROT_WRITE,
-	MAP_PRIVATE|MAP_ANON, -1, (off_t) 0);
-
-	ATF_REQUIRE_ERRNO(errno, allocstack != MAP_FAILED);
-
-	stack = allocstack;
-#ifndef __MACHINE_STACK_GROWS_UP
-	stack = (char *)stack + STACKSIZE;
-#endif
-
 	printf("parent: stack = %p, frobme = %p\n", stack, frobme);
 	fflush(stdout);
 
@@ -158,7 +170,7 @@ ATF_TC_BODY(clone_basic, tc)
 		/*NOTREACHED*/
 	}
 
-	ATF_REQUIRE_ERRNO(errno, munmap(allocstack, STACKSIZE) != -1);
+	putstack(stack);
 }
 
 ATF_TC(clone_null_stack);
@@ -190,16 +202,9 @@ ATF_TC_HEAD(clone_null_func, tc)
 
 ATF_TC_BODY(clone_null_func, tc)
 {
-	void *allocstack, *stack;
+	void *stack = getstack();
 	int rv;
 
-	allocstack = mmap(NULL, STACKSIZE, PROT_READ|PROT_WRITE,
-	MAP_PRIVATE|MAP_ANON, -1, (off_t) 0);
-	ATF_REQUIRE_ERRNO(errno, allocstack != MAP_FAILED);
-	stack = allocstack;
-#ifndef __MACHINE_STACK_GROWS_UP
-	stack = (char *)stack + STACKSIZE;
-#endif
 
 	errno = 0;
 	rv = __clone(0, stack,
@@ -208,7 +213,7 @@ ATF_TC_BODY(clone_null_func, tc)
 	ATF_REQUIRE_EQ(rv, -1);
 	ATF_REQUIRE_EQ(errno, EINVAL);
 
-	ATF_REQUIRE_ERRNO(errno, munmap(allocstack, STACKSIZE) != -1);
+	putstack(stack);
 }
 
 ATF_TC(clone_out_of_proc);
@@ -222,6 +227,7 @@ ATF_TC_HEAD(clone_out_of_proc, tc)
 
 ATF_TC_BODY(clone_out_of_proc, tc)
 {
+	char *stack = getstack();
 	struct rlimit rl;
 	int rv;
 
@@ -233,11 +239,12 @@ ATF_TC_BODY(clone_out_of_proc, tc)
 	ATF_REQUIRE_ERRNO(errno, setrlimit(RLIMIT_NPROC, &rl) != -1);
 
 	errno = 0;
-	rv = __clone(dummy, malloc(10240),
+	rv = __clone(dummy, stack,
 	CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD, (void *)&rl);
 
 	ATF_REQUIRE_EQ(rv, -1);
 	ATF_REQUIRE_EQ(errno, EAGAIN);
+	putstack(stack);
 }
 
 ATF_TP_ADD_TCS(tp)



CVS commit: src/tests/lib/libc/sys

2024-09-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 25 19:24:15 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_clone.c

Log Message:
centralize stack allocation/freeing. The test that broke with the new jemalloc
had broken stack allocation.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_clone.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/libc/sys

2024-07-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jul 15 06:19:07 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_kill.c

Log Message:
tests/lib/libc/sys/t_kill: Test kill(INT_MIN, ...) fails with ESRCH.

PR kern/58425


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_kill.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/libc/sys/t_kill.c
diff -u src/tests/lib/libc/sys/t_kill.c:1.1 src/tests/lib/libc/sys/t_kill.c:1.2
--- src/tests/lib/libc/sys/t_kill.c:1.1	Thu Jul  7 06:57:53 2011
+++ src/tests/lib/libc/sys/t_kill.c	Mon Jul 15 06:19:07 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_kill.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $ */
+/* $NetBSD: t_kill.c,v 1.2 2024/07/15 06:19:07 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_kill.c,v 1.1 2011/07/07 06:57:53 jruoho Exp $");
+__RCSID("$NetBSD: t_kill.c,v 1.2 2024/07/15 06:19:07 riastradh Exp $");
 
 #include 
 
@@ -299,6 +299,18 @@ ATF_TC_BODY(kill_pgrp_zero, tc)
 		atf_tc_fail("failed to kill(2) a process group");
 }
 
+ATF_TC(kill_int_min);
+ATF_TC_HEAD(kill_int_min, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test kill(INT_MIN) fails with ESRCH");
+}
+
+ATF_TC_BODY(kill_int_min, tc)
+{
+
+	ATF_CHECK_ERRNO(ESRCH, kill(INT_MIN, 0));
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -307,6 +319,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, kill_perm);
 	ATF_TP_ADD_TC(tp, kill_pgrp_neg);
 	ATF_TP_ADD_TC(tp, kill_pgrp_zero);
+	ATF_TP_ADD_TC(tp, kill_int_min);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libc/sys

2024-07-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jul 15 06:19:07 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_kill.c

Log Message:
tests/lib/libc/sys/t_kill: Test kill(INT_MIN, ...) fails with ESRCH.

PR kern/58425


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_kill.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/libc/sys

2024-06-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Jun 29 07:10:27 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
core_dump_procinfo: Fix false positive for vax

Increment PC after trapped by `bpt`, as done for many other platforms.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys

2024-06-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Jun 29 07:10:27 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
core_dump_procinfo: Fix false positive for vax

Increment PC after trapped by `bpt`, as done for many other platforms.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys/t_ptrace_core_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.8 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.9
--- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.8	Thu Aug 24 05:55:25 2023
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h	Sat Jun 29 07:10:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_core_wait.h,v 1.8 2023/08/24 05:55:25 rin Exp $	*/
+/*	$NetBSD: t_ptrace_core_wait.h,v 1.9 2024/06/29 07:10:27 rin Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -210,7 +210,7 @@ ATF_TC_BODY(core_dump_procinfo, tc)
 
 #if defined(__aarch64__) || defined(__arm__) || defined(__hppa__) || \
 defined(__powerpc__) || defined(__riscv__) || defined(__sh3__) || \
-defined(sparc)
+defined(sparc) || defined(__vax__)
 	/*
 	 * For these archs, program counter is not automatically incremented
 	 * by a trap instruction. We cannot increment PC in the trap handler,



CVS commit: src/tests/lib/libc/sys

2024-05-27 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 27 22:03:21 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_swapcontext.c

Log Message:
Mark as expected-fail on VAX (PR port-vax/58290).


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/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/libc/sys/t_swapcontext.c
diff -u src/tests/lib/libc/sys/t_swapcontext.c:1.4 src/tests/lib/libc/sys/t_swapcontext.c:1.5
--- src/tests/lib/libc/sys/t_swapcontext.c:1.4	Tue Aug  1 20:09:12 2023
+++ src/tests/lib/libc/sys/t_swapcontext.c	Mon May 27 22:03:21 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_swapcontext.c,v 1.4 2023/08/01 20:09:12 andvar Exp $ */
+/* $NetBSD: t_swapcontext.c,v 1.5 2024/05/27 22:03:21 thorpej Exp $ */
 
 /*
  * Copyright (c) 2012 Emmanuel Dreyfus. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_swapcontext.c,v 1.4 2023/08/01 20:09:12 andvar Exp $");
+__RCSID("$NetBSD: t_swapcontext.c,v 1.5 2024/05/27 22:03:21 thorpej Exp $");
 
 #include 
 #include 
@@ -81,13 +81,9 @@ mainfunc(void)
 	nctx.uc_stack.ss_sp = stack;
 	nctx.uc_stack.ss_size = sizeof(stack);
 
-#ifndef _UC_TLSBASE
-	ATF_REQUIRE_MSG(0, "_UC_TLSBASE is not defined");
-#else /* _UC_TLSBASE */
 	ATF_REQUIRE(nctx.uc_flags & _UC_TLSBASE);
 	if (!alter_tlsbase)
 		nctx.uc_flags &= ~_UC_TLSBASE;
-#endif /* _UC_TLSBASE */
 
 	makecontext(&nctx, swapfunc, 0);
 
@@ -108,6 +104,9 @@ ATF_TC_HEAD(swapcontext1, tc)
 }
 ATF_TC_BODY(swapcontext1, tc)
 {
+#ifdef __vax__
+	atf_tc_expect_fail("PR port-vax/58290");
+#endif
 	alter_tlsbase = 0;
 	mainfunc();
 }
@@ -120,6 +119,9 @@ ATF_TC_HEAD(swapcontext2, tc)
 }
 ATF_TC_BODY(swapcontext2, tc)
 {
+#ifdef __vax__
+	atf_tc_expect_fail("PR port-vax/58290");
+#endif
 	alter_tlsbase = 1;
 	mainfunc();
 }



CVS commit: src/tests/lib/libc/sys

2024-05-27 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 27 22:03:21 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_swapcontext.c

Log Message:
Mark as expected-fail on VAX (PR port-vax/58290).


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/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/libc/sys

2024-05-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon May 20 00:27:53 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_dup.c

Log Message:
Adjust to the new dup3 behavior for equal fds


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/sys/t_dup.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/libc/sys/t_dup.c
diff -u src/tests/lib/libc/sys/t_dup.c:1.9 src/tests/lib/libc/sys/t_dup.c:1.10
--- src/tests/lib/libc/sys/t_dup.c:1.9	Fri Jan 13 15:31:53 2017
+++ src/tests/lib/libc/sys/t_dup.c	Sun May 19 20:27:53 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_dup.c,v 1.9 2017/01/13 20:31:53 christos Exp $ */
+/* $NetBSD: t_dup.c,v 1.10 2024/05/20 00:27:53 christos Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_dup.c,v 1.9 2017/01/13 20:31:53 christos Exp $");
+__RCSID("$NetBSD: t_dup.c,v 1.10 2024/05/20 00:27:53 christos Exp $");
 
 #include 
 #include 
@@ -208,10 +208,10 @@ ATF_TC_BODY(dup3_err, tc)
 	ATF_REQUIRE(fd >= 0);
 
 	errno = 0;
-	ATF_REQUIRE(dup3(fd, fd, O_CLOEXEC) != -1);
+	ATF_REQUIRE_ERRNO(EINVAL, dup3(fd, fd, O_CLOEXEC) == -1);
 
 	errno = 0;
-	ATF_REQUIRE_ERRNO(EBADF, dup3(-1, -1, O_CLOEXEC) == -1);
+	ATF_REQUIRE_ERRNO(EINVAL, dup3(-1, -1, O_CLOEXEC) == -1);
 
 	errno = 0;
 	ATF_REQUIRE_ERRNO(EBADF, dup3(fd, -1, O_CLOEXEC) == -1);



CVS commit: src/tests/lib/libc/sys

2024-05-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon May 20 00:27:53 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_dup.c

Log Message:
Adjust to the new dup3 behavior for equal fds


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/sys/t_dup.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/libc/sys

2024-05-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue May 14 16:06:20 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.h

Log Message:
t_ptrace_wait: No FPU exception traps on RISC-V.

This macro is not named correctly -- RISC-V does implement
floating-point exceptions, but only via sticky status bits, not via
machine traps.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.35 src/tests/lib/libc/sys/t_ptrace_wait.h:1.36
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.35	Tue May 14 16:04:17 2024
+++ src/tests/lib/libc/sys/t_ptrace_wait.h	Tue May 14 16:06:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.h,v 1.35 2024/05/14 16:04:17 riastradh Exp $	*/
+/*	$NetBSD: t_ptrace_wait.h,v 1.36 2024/05/14 16:06:20 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -673,6 +673,8 @@ are_fpu_exceptions_supported(void)
 		return false;
 	return true;
 }
+#elif defined __riscv__
+#define are_fpu_exceptions_supported() 0
 #else
 #define are_fpu_exceptions_supported() 1
 #endif



CVS commit: src/tests/lib/libc/sys

2024-05-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue May 14 16:06:20 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.h

Log Message:
t_ptrace_wait: No FPU exception traps on RISC-V.

This macro is not named correctly -- RISC-V does implement
floating-point exceptions, but only via sticky status bits, not via
machine traps.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys

2024-05-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue May 14 16:04:18 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.h

Log Message:
t_ptrace_wait: Force result by write to volatile, not call to usleep.

This is causing each FPE-related test to time out because it's
actually passinga large number to usleep, which now respects large
numbers.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.34 src/tests/lib/libc/sys/t_ptrace_wait.h:1.35
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.34	Tue May 24 20:08:38 2022
+++ src/tests/lib/libc/sys/t_ptrace_wait.h	Tue May 14 16:04:17 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.h,v 1.34 2022/05/24 20:08:38 andvar Exp $	*/
+/*	$NetBSD: t_ptrace_wait.h,v 1.35 2024/05/14 16:04:17 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -677,6 +677,8 @@ are_fpu_exceptions_supported(void)
 #define are_fpu_exceptions_supported() 1
 #endif
 
+volatile double ignore_result;
+
 static void __used
 trigger_fpe(void)
 {
@@ -701,7 +703,7 @@ trigger_fpe(void)
 #endif
 
 	/* Division by zero causes CPU trap, translated to SIGFPE */
-	usleep((int)(a / b));
+	ignore_result = (int)(a / b);
 }
 
 static void __used



CVS commit: src/tests/lib/libc/sys

2024-05-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue May 14 16:04:18 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.h

Log Message:
t_ptrace_wait: Force result by write to volatile, not call to usleep.

This is causing each FPE-related test to time out because it's
actually passinga large number to usleep, which now respects large
numbers.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys

2024-04-12 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Fri Apr 12 07:16:50 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_getrusage.c

Log Message:
Require at least 64 MB RAM to run the getrusage_maxrss test case as it
allocates 40 MB and we should leave some for the system, too.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_getrusage.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/libc/sys/t_getrusage.c
diff -u src/tests/lib/libc/sys/t_getrusage.c:1.8 src/tests/lib/libc/sys/t_getrusage.c:1.9
--- src/tests/lib/libc/sys/t_getrusage.c:1.8	Wed May  9 08:45:03 2018
+++ src/tests/lib/libc/sys/t_getrusage.c	Fri Apr 12 07:16:50 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_getrusage.c,v 1.8 2018/05/09 08:45:03 mrg Exp $ */
+/* $NetBSD: t_getrusage.c,v 1.9 2024/04/12 07:16:50 gson Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_getrusage.c,v 1.8 2018/05/09 08:45:03 mrg Exp $");
+__RCSID("$NetBSD: t_getrusage.c,v 1.9 2024/04/12 07:16:50 gson Exp $");
 
 #include 
 #include 
@@ -126,6 +126,7 @@ ATF_TC(getrusage_maxrss);
 ATF_TC_HEAD(getrusage_maxrss, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Test maxrss growing with getrusage(2)");
+	atf_tc_set_md_var(tc, "require.memory", "64M");
 }
 
 ATF_TC_BODY(getrusage_maxrss, tc)



CVS commit: src/tests/lib/libc/sys

2024-04-12 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Fri Apr 12 07:16:50 UTC 2024

Modified Files:
src/tests/lib/libc/sys: t_getrusage.c

Log Message:
Require at least 64 MB RAM to run the getrusage_maxrss test case as it
allocates 40 MB and we should leave some for the system, too.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_getrusage.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/libc/sys

2023-12-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Dec  7 16:54:44 UTC 2023

Modified Files:
src/tests/lib/libc/sys: Makefile t_setrlimit.c

Log Message:
t_setrlimit: Narrow the scope of stack-protector warning suppression.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/sys/t_setrlimit.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/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.75 src/tests/lib/libc/sys/Makefile:1.76
--- src/tests/lib/libc/sys/Makefile:1.75	Fri Nov 24 17:19:55 2023
+++ src/tests/lib/libc/sys/Makefile	Thu Dec  7 16:54:44 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.75 2023/11/24 17:19:55 christos Exp $
+# $NetBSD: Makefile,v 1.76 2023/12/07 16:54:44 riastradh Exp $
 
 MKMAN=	no
 
@@ -158,6 +158,5 @@ CWARNFLAGS.gcc+=	${CC_WNO_ADDRESS_OF_PAC
 
 # Explicitly breaks this
 COPTS.t_wait.c+=	${CC_WNO_ARRAY_BOUNDS} ${CC_WNO_STRINGOP_OVERFLOW}
-COPTS.t_setrlimit.c+=	-Wno-error=stack-protector
 
 .include 

Index: src/tests/lib/libc/sys/t_setrlimit.c
diff -u src/tests/lib/libc/sys/t_setrlimit.c:1.10 src/tests/lib/libc/sys/t_setrlimit.c:1.11
--- src/tests/lib/libc/sys/t_setrlimit.c:1.10	Wed Nov 22 02:20:34 2023
+++ src/tests/lib/libc/sys/t_setrlimit.c	Thu Dec  7 16:54:44 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: t_setrlimit.c,v 1.10 2023/11/22 02:20:34 riastradh Exp $ */
+/* $NetBSD: t_setrlimit.c,v 1.11 2023/12/07 16:54:44 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_setrlimit.c,v 1.10 2023/11/22 02:20:34 riastradh Exp $");
+__RCSID("$NetBSD: t_setrlimit.c,v 1.11 2023/12/07 16:54:44 riastradh Exp $");
 
 #include 
 #include 
@@ -534,6 +534,26 @@ ATF_TC_HEAD(setrlimit_stack_growshrink, 
 }
 
 /*
+ * checkstackchild(n)
+ *
+ *	Allocate an array of size n on the stack, and verify it can be
+ *	used.  If it can't be used, this will crash with SIGSEGV,
+ *	deliberately.
+ */
+_Pragma("GCC diagnostic push")
+_Pragma("GCC diagnostic ignored \"-Wstack-protector\"")
+static void
+checkstackchild(size_t n)
+{
+	volatile char *const x = alloca(n);
+	size_t i;
+
+	for (i = 0; i < n; i++)
+		x[i] = 0x1a;
+}
+_Pragma("GCC diagnostic pop")
+
+/*
  * checkstack(n, expectsegv)
  *
  *	Check whether we can allocate an array of size n on the stack.
@@ -555,14 +575,11 @@ static void
 checkstack(size_t n, int expectsegv)
 {
 	pid_t forked, waited;
-	size_t i;
 	int status;
 
 	RL(forked = fork());
 	if (forked == 0) {	/* child */
-		volatile char *const x = alloca(n);
-		for (i = 0; i < n; i++)
-			x[i] = 0x1a;
+		checkstackchild(n);
 		_exit(expectsegv);
 	}
 



CVS commit: src/tests/lib/libc/sys

2023-12-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Dec  7 16:54:44 UTC 2023

Modified Files:
src/tests/lib/libc/sys: Makefile t_setrlimit.c

Log Message:
t_setrlimit: Narrow the scope of stack-protector warning suppression.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libc/sys/t_setrlimit.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/libc/sys

2023-11-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov 24 17:19:55 UTC 2023

Modified Files:
src/tests/lib/libc/sys: Makefile

Log Message:
t_setrlimit uses alloca now


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/tests/lib/libc/sys/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/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.74 src/tests/lib/libc/sys/Makefile:1.75
--- src/tests/lib/libc/sys/Makefile:1.74	Tue Aug  8 02:27:32 2023
+++ src/tests/lib/libc/sys/Makefile	Fri Nov 24 12:19:55 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.74 2023/08/08 06:27:32 mrg Exp $
+# $NetBSD: Makefile,v 1.75 2023/11/24 17:19:55 christos Exp $
 
 MKMAN=	no
 
@@ -158,5 +158,6 @@ CWARNFLAGS.gcc+=	${CC_WNO_ADDRESS_OF_PAC
 
 # Explicitly breaks this
 COPTS.t_wait.c+=	${CC_WNO_ARRAY_BOUNDS} ${CC_WNO_STRINGOP_OVERFLOW}
+COPTS.t_setrlimit.c+=	-Wno-error=stack-protector
 
 .include 



CVS commit: src/tests/lib/libc/sys

2023-11-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov 24 17:19:55 UTC 2023

Modified Files:
src/tests/lib/libc/sys: Makefile

Log Message:
t_setrlimit uses alloca now


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/tests/lib/libc/sys/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/libc/sys

2023-11-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Nov 22 02:20:34 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_setrlimit.c

Log Message:
t_setrlimit: Fix typos in comments and messages.

No substantive change intended.  Suggested by rillig@.

PR kern/57711

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


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/sys/t_setrlimit.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/libc/sys/t_setrlimit.c
diff -u src/tests/lib/libc/sys/t_setrlimit.c:1.9 src/tests/lib/libc/sys/t_setrlimit.c:1.10
--- src/tests/lib/libc/sys/t_setrlimit.c:1.9	Tue Nov 21 00:09:18 2023
+++ src/tests/lib/libc/sys/t_setrlimit.c	Wed Nov 22 02:20:34 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: t_setrlimit.c,v 1.9 2023/11/21 00:09:18 riastradh Exp $ */
+/* $NetBSD: t_setrlimit.c,v 1.10 2023/11/22 02:20:34 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_setrlimit.c,v 1.9 2023/11/21 00:09:18 riastradh Exp $");
+__RCSID("$NetBSD: t_setrlimit.c,v 1.10 2023/11/22 02:20:34 riastradh Exp $");
 
 #include 
 #include 
@@ -534,7 +534,7 @@ ATF_TC_HEAD(setrlimit_stack_growshrink, 
 }
 
 /*
- * checkstack(n, ok)
+ * checkstack(n, expectsegv)
  *
  *	Check whether we can allocate an array of size n on the stack.
  *
@@ -579,7 +579,7 @@ checkstack(size_t n, int expectsegv)
 		WTERMSIG(status));
 	} else {
 		ATF_REQUIRE_MSG(!WIFSIGNALED(status),
-		"expected normal exit but termintaed on signal %d",
+		"expected normal exit but terminated on signal %d",
 		WTERMSIG(status));
 		ATF_REQUIRE_MSG(WIFEXITED(status), "status=0x%x", status);
 		ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), 0, "exitstatus=%d",



CVS commit: src/tests/lib/libc/sys

2023-11-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Nov 22 02:20:34 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_setrlimit.c

Log Message:
t_setrlimit: Fix typos in comments and messages.

No substantive change intended.  Suggested by rillig@.

PR kern/57711

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


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/sys/t_setrlimit.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/libc/sys

2023-11-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov 20 13:05:17 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_setrlimit.c

Log Message:
t_setrlimit: Verify changing RLIMIT_STACK affects access to stack.

PR kern/57711

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


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_setrlimit.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/libc/sys

2023-11-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov 20 13:05:17 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_setrlimit.c

Log Message:
t_setrlimit: Verify changing RLIMIT_STACK affects access to stack.

PR kern/57711

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


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_setrlimit.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/libc/sys/t_setrlimit.c
diff -u src/tests/lib/libc/sys/t_setrlimit.c:1.7 src/tests/lib/libc/sys/t_setrlimit.c:1.8
--- src/tests/lib/libc/sys/t_setrlimit.c:1.7	Tue Oct 13 06:58:57 2020
+++ src/tests/lib/libc/sys/t_setrlimit.c	Mon Nov 20 13:05:17 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: t_setrlimit.c,v 1.7 2020/10/13 06:58:57 rin Exp $ */
+/* $NetBSD: t_setrlimit.c,v 1.8 2023/11/20 13:05:17 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_setrlimit.c,v 1.7 2020/10/13 06:58:57 rin Exp $");
+__RCSID("$NetBSD: t_setrlimit.c,v 1.8 2023/11/20 13:05:17 riastradh Exp $");
 
 #include 
 #include 
@@ -48,6 +48,8 @@ __RCSID("$NetBSD: t_setrlimit.c,v 1.7 20
 #include 
 #include 
 
+#include "h_macros.h"
+
 static void		 sighandler(int);
 static const char	 path[] = "setrlimit";
 
@@ -524,6 +526,134 @@ ATF_TC_BODY(setrlimit_stack, tc)
 
 }
 
+ATF_TC(setrlimit_stack_growshrink);
+ATF_TC_HEAD(setrlimit_stack_growshrink, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Test that setrlimit(2), RLIMIT_STACK, grows & shrinks the stack");
+}
+
+/*
+ * checkstack(n, ok)
+ *
+ *	Check whether we can allocate an array of size n on the stack.
+ *
+ *	- If expectsegv, verify that access fails with SIGSEGV.
+ *	- If not expectsegv, verify that access succeeds.
+ *
+ *	Do this in a subprocess rather than with a SIGSEGV handler,
+ *	because once we've allocated an array of size n on the stack,
+ *	in the case where the stack is inaccessible, we have just
+ *	trashed the stack pointer so badly we can't make function calls
+ *	like to a SIGSEGV handler.
+ *
+ *	(We could use an alternate signal stack, but I already wrote it
+ *	this way, and this is a little simpler and more robust than
+ *	juggling signals, setjmp/longjmp, and sigaltstack.)
+ */
+static void
+checkstack(size_t n, int expectsegv)
+{
+	pid_t forked, waited;
+	size_t i;
+	int status;
+
+	RL(forked = fork());
+	if (forked == 0) {	/* child */
+		volatile char *const x = alloca(n);
+		for (i = 0; i < n; i++)
+			x[i] = 0x1a;
+		_exit(expectsegv);
+	}
+
+	/* parent */
+	RL(waited = waitpid(forked, &status, 0));
+	ATF_REQUIRE_EQ_MSG(waited, forked, "waited=%jd forked=%jd",
+	(intmax_t)waited, (intmax_t)forked);
+	if (expectsegv) {
+		ATF_REQUIRE_MSG(!WIFEXITED(status),
+		"expected signal but exited normally with status %d",
+		WEXITSTATUS(status));
+		ATF_REQUIRE_MSG(WIFSIGNALED(status), "status=0x%x", status);
+		ATF_REQUIRE_EQ_MSG(WTERMSIG(status), SIGSEGV, "termsig=%d",
+		WTERMSIG(status));
+	} else {
+		ATF_REQUIRE_MSG(!WIFSIGNALED(status),
+		"expected normal exit but termintaed on signal %d",
+		WTERMSIG(status));
+		ATF_REQUIRE_MSG(WIFEXITED(status), "status=0x%x", status);
+		ATF_REQUIRE_EQ_MSG(WEXITSTATUS(status), 0, "exitstatus=%d",
+		WEXITSTATUS(status));
+	}
+}
+
+ATF_TC_BODY(setrlimit_stack_growshrink, tc)
+{
+	struct rlimit res;
+	size_t n;
+
+	/*
+	 * Disable core dumps -- we're going to deliberately cause
+	 * SIGSEGV to test stack accessibility (which breaks even
+	 * calling a function so we can't just use a SIGSEGV handler),
+	 * so let's not waste time dumping core.
+	 */
+	res = (struct rlimit){ .rlim_cur = 0, .rlim_max = 0 };
+	RL(setrlimit(RLIMIT_CORE, &res));
+
+	/*
+	 * Get the current stack size and hard limit.
+	 */
+	RL(getrlimit(RLIMIT_STACK, &res));
+	n = res.rlim_cur;
+
+	/*
+	 * Verify that we can't get at pages past the end of the stack
+	 * right now.
+	 */
+	checkstack(n, /*expectsegv*/1);
+
+	/*
+	 * Stop if the hard limit is too small to test.  Not sure
+	 * exactly how much more space we need to verify that setrlimit
+	 * actually expands the stack without examining the current
+	 * stack pointer relative to the process's stack base, so we'll
+	 * just double the stack size -- definitely enough to test
+	 * stack growth -- and hope the hard rlimit is big enough to
+	 * let us double it.
+	 */
+	if (n > res.rlim_max/2)
+		atf_tc_skip("hard stack rlimit is too small");
+
+	/*
+	 * Double the stack size.  This way we can allocate an array of
+	 * length equal to the current stack size and be guaranteed
+	 * that (a) it can be allocated, and (b) access to it requires
+	 * the stack to have grown.
+	 */
+	res.rlim_cur = 2*n;
+	RL(setrlimit(RLIMIT_STACK, &res));
+
+	atf_tc_expect_fail("PR kern/57711:"
+	" setrlimit(RLIMIT_STACK) fails to increase usable stack size");
+
+	/*
+	 

CVS commit: src/tests/lib/libc/sys

2023-08-23 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Aug 24 05:55:26 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
t_ptrace_core_wait.h: Increment PC after trap, also for riscv

Fix *:core_dump_procinfo tests for riscv64.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys/t_ptrace_core_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.7 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.8
--- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.7	Thu Jun  9 17:39:21 2022
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h	Thu Aug 24 05:55:25 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_core_wait.h,v 1.7 2022/06/09 17:39:21 skrll Exp $	*/
+/*	$NetBSD: t_ptrace_core_wait.h,v 1.8 2023/08/24 05:55:25 rin Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -209,7 +209,8 @@ ATF_TC_BODY(core_dump_procinfo, tc)
 	"without signal to be sent\n");
 
 #if defined(__aarch64__) || defined(__arm__) || defined(__hppa__) || \
-defined(__powerpc__) || defined(__sh3__) || defined(sparc)
+defined(__powerpc__) || defined(__riscv__) || defined(__sh3__) || \
+defined(sparc)
 	/*
 	 * For these archs, program counter is not automatically incremented
 	 * by a trap instruction. We cannot increment PC in the trap handler,



CVS commit: src/tests/lib/libc/sys

2023-08-23 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Aug 24 05:55:26 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
t_ptrace_core_wait.h: Increment PC after trap, also for riscv

Fix *:core_dump_procinfo tests for riscv64.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys

2023-08-02 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Aug  3 03:18:12 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_getrandom.c

Log Message:
t_getrandom: Fix false positives for short read(2)

This only affects really slow machines, 68030 for me :)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_getrandom.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/libc/sys/t_getrandom.c
diff -u src/tests/lib/libc/sys/t_getrandom.c:1.4 src/tests/lib/libc/sys/t_getrandom.c:1.5
--- src/tests/lib/libc/sys/t_getrandom.c:1.4	Fri Mar 18 23:35:37 2022
+++ src/tests/lib/libc/sys/t_getrandom.c	Thu Aug  3 03:18:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_getrandom.c,v 1.4 2022/03/18 23:35:37 riastradh Exp $	*/
+/*	$NetBSD: t_getrandom.c,v 1.5 2023/08/03 03:18:12 rin Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_getrandom.c,v 1.4 2022/03/18 23:35:37 riastradh Exp $");
+__RCSID("$NetBSD: t_getrandom.c,v 1.5 2023/08/03 03:18:12 rin Exp $");
 
 #include 
 
@@ -94,7 +94,7 @@ ATF_TC_BODY(getrandom_default, tc)
 		ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
 		ATF_CHECK((size_t)n <= sizeof buf);
 		ATF_CHECK(memcmp(buf, zero24, 24) != 0);
-		ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
+		ATF_CHECK(memcmp(buf + n - 24, zero24, 24) != 0);
 	}
 	alarm(0);
 }
@@ -117,7 +117,7 @@ ATF_TC_BODY(getrandom_nonblock, tc)
 		ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
 		ATF_CHECK((size_t)n <= sizeof buf);
 		ATF_CHECK(memcmp(buf, zero24, 24) != 0);
-		ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
+		ATF_CHECK(memcmp(buf + n - 24, zero24, 24) != 0);
 	}
 }
 
@@ -137,7 +137,7 @@ ATF_TC_BODY(getrandom_insecure, tc)
 	ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
 	ATF_CHECK((size_t)n <= sizeof buf);
 	ATF_CHECK(memcmp(buf, zero24, 24) != 0);
-	ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
+	ATF_CHECK(memcmp(buf + n - 24, zero24, 24) != 0);
 }
 
 ATF_TC(getrandom_insecure_nonblock);
@@ -157,7 +157,7 @@ ATF_TC_BODY(getrandom_insecure_nonblock,
 	ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
 	ATF_CHECK((size_t)n <= sizeof buf);
 	ATF_CHECK(memcmp(buf, zero24, 24) != 0);
-	ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
+	ATF_CHECK(memcmp(buf + n - 24, zero24, 24) != 0);
 }
 
 ATF_TC(getrandom_random);



CVS commit: src/tests/lib/libc/sys

2023-08-02 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Aug  3 03:18:12 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_getrandom.c

Log Message:
t_getrandom: Fix false positives for short read(2)

This only affects really slow machines, 68030 for me :)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_getrandom.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/libc/sys

2023-08-01 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Aug  1 23:41:55 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_pollts.c

Log Message:
t_pollts.c: fix typo in a description string (NFC)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_pollts.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/libc/sys/t_pollts.c
diff -u src/tests/lib/libc/sys/t_pollts.c:1.1 src/tests/lib/libc/sys/t_pollts.c:1.2
--- src/tests/lib/libc/sys/t_pollts.c:1.1	Fri Jul 17 15:34:17 2020
+++ src/tests/lib/libc/sys/t_pollts.c	Tue Aug  1 23:41:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_pollts.c,v 1.1 2020/07/17 15:34:17 kamil Exp $	*/
+/*	$NetBSD: t_pollts.c,v 1.2 2023/08/01 23:41:54 gutteridge Exp $	*/
 
 /*-
  * Copyright (c) 2011, 2020 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@ ATF_TC_HEAD(basic, tc)
 {
 	atf_tc_set_md_var(tc, "timeout", "10");
 	atf_tc_set_md_var(tc, "descr",
-	"Basis functionality test for ppoll(2)/pollts(2)");
+	"Basic functionality test for ppoll(2)/pollts(2)");
 }
 
 ATF_TC_BODY(basic, tc)



CVS commit: src/tests/lib/libc/sys

2023-08-01 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Aug  1 23:41:55 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_pollts.c

Log Message:
t_pollts.c: fix typo in a description string (NFC)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_pollts.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/libc/sys

2023-07-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul  9 19:19:40 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_clock_gettime.c

Log Message:
t_clock_gettime: Avoid signed/unsigned comparison.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_clock_gettime.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/libc/sys

2023-07-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul  9 19:19:40 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_clock_gettime.c

Log Message:
t_clock_gettime: Avoid signed/unsigned comparison.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_clock_gettime.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/libc/sys/t_clock_gettime.c
diff -u src/tests/lib/libc/sys/t_clock_gettime.c:1.5 src/tests/lib/libc/sys/t_clock_gettime.c:1.6
--- src/tests/lib/libc/sys/t_clock_gettime.c:1.5	Sat Jul  8 20:02:10 2023
+++ src/tests/lib/libc/sys/t_clock_gettime.c	Sun Jul  9 19:19:40 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: t_clock_gettime.c,v 1.5 2023/07/08 20:02:10 riastradh Exp $ */
+/* $NetBSD: t_clock_gettime.c,v 1.6 2023/07/09 19:19:40 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_clock_gettime.c,v 1.5 2023/07/08 20:02:10 riastradh Exp $");
+__RCSID("$NetBSD: t_clock_gettime.c,v 1.6 2023/07/09 19:19:40 riastradh Exp $");
 
 #include 
 
@@ -223,7 +223,7 @@ waste_system_time(void)
 
 	RL(pipe2(fd, O_NONBLOCK));
 	RL(n = ioctl(fd[1], FIONSPACE));
-	n = MIN(MAX(0, n), sizeof(buf));
+	n = MIN((unsigned)MAX(0, n), sizeof(buf));
 	for (i = 0; i < 16; i++) {
 		RL(write(fd[1], buf, n));
 		RL(read(fd[0], buf, n));



CVS commit: src/tests/lib/libc/sys

2023-07-08 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul  8 15:32:58 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_timerfd.c

Log Message:
t_timerfd: Sprinkle slightly more diagnostics.

Might help us to see if we're off by just a little bit (maybe a tiny
jitter between the hardclock timer and the monotonic clock), or if
something is seriously amiss when the timerfd_block test fails
sporadically.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_timerfd.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/libc/sys

2023-07-08 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul  8 15:32:58 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_timerfd.c

Log Message:
t_timerfd: Sprinkle slightly more diagnostics.

Might help us to see if we're off by just a little bit (maybe a tiny
jitter between the hardclock timer and the monotonic clock), or if
something is seriously amiss when the timerfd_block test fails
sporadically.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_timerfd.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/libc/sys/t_timerfd.c
diff -u src/tests/lib/libc/sys/t_timerfd.c:1.4 src/tests/lib/libc/sys/t_timerfd.c:1.5
--- src/tests/lib/libc/sys/t_timerfd.c:1.4	Sun Feb 20 15:21:14 2022
+++ src/tests/lib/libc/sys/t_timerfd.c	Sat Jul  8 15:32:58 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: t_timerfd.c,v 1.4 2022/02/20 15:21:14 thorpej Exp $ */
+/* $NetBSD: t_timerfd.c,v 1.5 2023/07/08 15:32:58 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2020\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_timerfd.c,v 1.4 2022/02/20 15:21:14 thorpej Exp $");
+__RCSID("$NetBSD: t_timerfd.c,v 1.5 2023/07/08 15:32:58 riastradh Exp $");
 
 #include 
 #include 
@@ -195,7 +195,11 @@ ATF_TC_BODY(timerfd_block, tc)
 	ATF_REQUIRE(check_value_against_bounds(val, 1, 1));
 
 	timespecsub(&now, &then, &delta);
-	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
+	ATF_REQUIRE_MSG(check_value_against_bounds(delta.tv_sec, 1, 1),
+	"then=%jd.%09lu now=%jd.%09lu delta=%jd.%09lu",
+	(intmax_t)then.tv_sec, then.tv_nsec,
+	(intmax_t)now.tv_sec, now.tv_nsec,
+	(intmax_t)delta.tv_sec, delta.tv_nsec);
 
 	(void) close(fd);
 }
@@ -230,7 +234,11 @@ ATF_TC_BODY(timerfd_repeating, tc)
 	ATF_REQUIRE(check_value_against_bounds(val, 3, 5));
 
 	timespecsub(&now, &then, &delta);
-	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
+	ATF_REQUIRE_MSG(check_value_against_bounds(delta.tv_sec, 1, 1),
+	"then=%jd.%09lu now=%jd.%09lu delta=%jd.%09lu",
+	(intmax_t)then.tv_sec, then.tv_nsec,
+	(intmax_t)now.tv_sec, now.tv_nsec,
+	(intmax_t)delta.tv_sec, delta.tv_nsec);
 
 	(void) close(fd);
 }
@@ -264,7 +272,11 @@ ATF_TC_BODY(timerfd_abstime, tc)
 	ATF_REQUIRE(check_value_against_bounds(val, 1, 1));
 
 	timespecsub(&now, &then, &delta);
-	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
+	ATF_REQUIRE_MSG(check_value_against_bounds(delta.tv_sec, 1, 1),
+	"then=%jd.%09lu now=%jd.%09lu delta=%jd.%09lu",
+	(intmax_t)then.tv_sec, then.tv_nsec,
+	(intmax_t)now.tv_sec, now.tv_nsec,
+	(intmax_t)delta.tv_sec, delta.tv_nsec);
 
 	(void) close(fd);
 }



CVS commit: src/tests/lib/libc/sys

2023-07-08 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul  8 14:05:51 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_clock_gettime.c

Log Message:
t_clock_gettime: Add test for PR kern/57512.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_clock_gettime.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/libc/sys/t_clock_gettime.c
diff -u src/tests/lib/libc/sys/t_clock_gettime.c:1.3 src/tests/lib/libc/sys/t_clock_gettime.c:1.4
--- src/tests/lib/libc/sys/t_clock_gettime.c:1.3	Fri Jan 13 21:30:41 2017
+++ src/tests/lib/libc/sys/t_clock_gettime.c	Sat Jul  8 14:05:51 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: t_clock_gettime.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */
+/* $NetBSD: t_clock_gettime.c,v 1.4 2023/07/08 14:05:51 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,17 +58,19 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_clock_gettime.c,v 1.3 2017/01/13 21:30:41 christos Exp $");
+__RCSID("$NetBSD: t_clock_gettime.c,v 1.4 2023/07/08 14:05:51 riastradh Exp $");
 
 #include 
-#include 
 
+#include 
+#include 
 
 #include 
 #include 
+#include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -204,10 +206,93 @@ ATF_TC_BODY(clock_gettime_real, tc)
 	RL(sysctlbyname(TC_HARDWARE, NULL, 0, save, strlen(save)));
 }
 
+static void
+waste_user_time(void)
+{
+	static char buf[4*4096];
+
+	arc4random_buf(buf, sizeof(buf));
+}
+
+static void __unused
+waste_system_time(void)
+{
+	static char buf[4*4096];
+	int fd[2];
+	int i, n;
+
+	RL(pipe2(fd, O_NONBLOCK));
+	RL(n = ioctl(fd[1], FIONSPACE));
+	n = MIN(MAX(0, n), sizeof(buf));
+	for (i = 0; i < 16; i++) {
+		RL(write(fd[1], buf, n));
+		RL(read(fd[0], buf, n));
+	}
+	RL(close(fd[0]));
+	RL(close(fd[1]));
+}
+
+static void
+check_monotonicity(const char *clockname, clockid_t clockid,
+void (*waste_time)(void))
+{
+	static const struct timespec maxtime = {5, 0};
+	struct timespec mono_t0, t0, mono_d;
+
+	RL(clock_gettime(CLOCK_MONOTONIC, &mono_t0));
+	RL(clock_gettime(clockid, &t0));
+
+	do {
+		struct timespec t1, mono_t1;
+
+		(*waste_time)();
+
+		RL(clock_gettime(clockid, &t1));
+		ATF_CHECK_MSG(timespeccmp(&t0, &t1, <=),
+		"clock %s=0x%jx went backwards t0=%jd.%09ld t1=%jd.%09ld",
+		clockname, (uintmax_t)clockid,
+		(intmax_t)t0.tv_sec, t0.tv_nsec,
+		(intmax_t)t1.tv_sec, t1.tv_nsec);
+
+		t0 = t1;
+
+		RL(clock_gettime(CLOCK_MONOTONIC, &mono_t1));
+		timespecsub(&mono_t1, &mono_t0, &mono_d);
+	} while (timespeccmp(&mono_d, &maxtime, <));
+}
+
+ATF_TC(clock_gettime_process_cputime_is_monotonic);
+ATF_TC_HEAD(clock_gettime_process_cputime_is_monotonic, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Checks that CLOCK_PROCESS_CPUTIME_ID is monotonic");
+}
+ATF_TC_BODY(clock_gettime_process_cputime_is_monotonic, tc)
+{
+	check_monotonicity("CLOCK_PROCESS_CPUTIME_ID",
+	CLOCK_PROCESS_CPUTIME_ID, &waste_user_time);
+}
+
+ATF_TC(clock_gettime_thread_cputime_is_monotonic);
+ATF_TC_HEAD(clock_gettime_thread_cputime_is_monotonic, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Checks that CLOCK_THREAD_CPUTIME_ID is monotonic");
+}
+ATF_TC_BODY(clock_gettime_thread_cputime_is_monotonic, tc)
+{
+	atf_tc_expect_fail("PR kern/57512: clock_gettime"
+	"(CLOCK_THREAD_CPUTIME_ID) sometimes goes backwards");
+	check_monotonicity("CLOCK_THREAD_CPUTIME_ID",
+	CLOCK_THREAD_CPUTIME_ID, &waste_user_time);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
 	ATF_TP_ADD_TC(tp, clock_gettime_real);
+	ATF_TP_ADD_TC(tp, clock_gettime_process_cputime_is_monotonic);
+	ATF_TP_ADD_TC(tp, clock_gettime_thread_cputime_is_monotonic);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libc/sys

2023-07-08 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul  8 14:05:51 UTC 2023

Modified Files:
src/tests/lib/libc/sys: t_clock_gettime.c

Log Message:
t_clock_gettime: Add test for PR kern/57512.


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

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



Re: CVS commit: src/tests/lib/libc/sys

2022-08-01 Thread Robert Elz
Date:Mon, 1 Aug 2022 18:55:15 +0300
From:Valery Ushakov 
Message-ID:  

  | The test uses __clone(), not clone() and a followup fix made __clone()
  | visible under plain _NETBSD_SOURCE again - which is the right thing,
  | IMO.  So this change is not necessary (the test only uses __clone()).

Yes, I saw, but the test really should be using clone() - that"s
the thing which needs to work (for those odd apps which use it).

kre


Re: CVS commit: src/tests/lib/libc/sys

2022-08-01 Thread Valery Ushakov
On Mon, Aug 01, 2022 at 15:48:40 +, Robert Elz wrote:

> Module Name:  src
> Committed By: kre
> Date: Mon Aug  1 15:48:40 UTC 2022
> 
> Modified Files:
>   src/tests/lib/libc/sys: Makefile
> 
> Log Message:
> Provide _GNU_SOURCE for t_clone now that is required to make clone()
> visible.

The test uses __clone(), not clone() and a followup fix made __clone()
visible under plain _NETBSD_SOURCE again - which is the right thing,
IMO.  So this change is not necessary (the test only uses __clone()).

-uwe


CVS commit: src/tests/lib/libc/sys

2022-08-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Aug  1 15:48:40 UTC 2022

Modified Files:
src/tests/lib/libc/sys: Makefile

Log Message:
Provide _GNU_SOURCE for t_clone now that is required to make clone()
visible.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/tests/lib/libc/sys/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/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.71 src/tests/lib/libc/sys/Makefile:1.72
--- src/tests/lib/libc/sys/Makefile:1.71	Wed Apr  6 10:02:55 2022
+++ src/tests/lib/libc/sys/Makefile	Mon Aug  1 15:48:39 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.71 2022/04/06 10:02:55 gson Exp $
+# $NetBSD: Makefile,v 1.72 2022/08/01 15:48:39 kre Exp $
 
 MKMAN=	no
 
@@ -120,6 +120,7 @@ CPPFLAGS.t_futex_robust.c	+= -I${.CURDIR
 
 CPPFLAGS.t_timerfd.c		+= -I${.CURDIR}/../gen
 
+CPPFLAGE.t_clone.c		+= -D_NETBSD_SOURCE -D_GNU_SOURCE
 CPPFLAGS.t_lwp_create.c		+= -D_KERNTYPES
 CPPFLAGS.t_ptrace_sigchld.c	+= -D__TEST_FENV
 CPPFLAGS.t_ptrace_wait.c	+= -D_KERNTYPES -D__TEST_FENV



CVS commit: src/tests/lib/libc/sys

2022-08-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Aug  1 15:48:40 UTC 2022

Modified Files:
src/tests/lib/libc/sys: Makefile

Log Message:
Provide _GNU_SOURCE for t_clone now that is required to make clone()
visible.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/tests/lib/libc/sys/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/libc/sys

2022-06-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun  9 17:39:21 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
There are two hard problems in computer science cache invalidation, naming
and off-by-one errors.

Fix a naming and off-by-one bug... Thanks to Tom Lane for spotting my typo.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys

2022-06-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jun  9 17:39:21 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
There are two hard problems in computer science cache invalidation, naming
and off-by-one errors.

Fix a naming and off-by-one bug... Thanks to Tom Lane for spotting my typo.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys/t_ptrace_core_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.6 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.7
--- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.6	Tue Jun  7 05:39:16 2022
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h	Thu Jun  9 17:39:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_core_wait.h,v 1.6 2022/06/07 05:39:16 skrll Exp $	*/
+/*	$NetBSD: t_ptrace_core_wait.h,v 1.7 2022/06/09 17:39:21 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -208,7 +208,7 @@ ATF_TC_BODY(core_dump_procinfo, tc)
 	DPRINTF("Before resuming the child process where it left off and "
 	"without signal to be sent\n");
 
-#if defined(__aarch64__) || defined(__arm__) || defined(__hppa___) || \
+#if defined(__aarch64__) || defined(__arm__) || defined(__hppa__) || \
 defined(__powerpc__) || defined(__sh3__) || defined(sparc)
 	/*
 	 * For these archs, program counter is not automatically incremented



CVS commit: src/tests/lib/libc/sys

2022-06-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jun  7 05:39:16 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
PR/56865: hppa: t_ptrace_core_wait test doesn't know it must advance PC after 
breakpoint

Add __hppa__ to the list of architectures that need to advance to the 
instruction
after the breakpoint

Thanks to Tom Lane for the fix.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys/t_ptrace_core_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.5 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.6
--- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.5	Sat Mar 26 16:22:50 2022
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h	Tue Jun  7 05:39:16 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_core_wait.h,v 1.5 2022/03/26 16:22:50 martin Exp $	*/
+/*	$NetBSD: t_ptrace_core_wait.h,v 1.6 2022/06/07 05:39:16 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -208,8 +208,8 @@ ATF_TC_BODY(core_dump_procinfo, tc)
 	DPRINTF("Before resuming the child process where it left off and "
 	"without signal to be sent\n");
 
-#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) || \
-defined(__sh3__) || defined(sparc)
+#if defined(__aarch64__) || defined(__arm__) || defined(__hppa___) || \
+defined(__powerpc__) || defined(__sh3__) || defined(sparc)
 	/*
 	 * For these archs, program counter is not automatically incremented
 	 * by a trap instruction. We cannot increment PC in the trap handler,



CVS commit: src/tests/lib/libc/sys

2022-06-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jun  7 05:39:16 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
PR/56865: hppa: t_ptrace_core_wait test doesn't know it must advance PC after 
breakpoint

Add __hppa__ to the list of architectures that need to advance to the 
instruction
after the breakpoint

Thanks to Tom Lane for the fix.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys

2022-06-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun  4 23:09:18 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
tests/lib/libc: Test mmap(2) with bad hints.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_mmap.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/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.17 src/tests/lib/libc/sys/t_mmap.c:1.18
--- src/tests/lib/libc/sys/t_mmap.c:1.17	Wed Apr  6 10:02:55 2022
+++ src/tests/lib/libc/sys/t_mmap.c	Sat Jun  4 23:09:18 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.17 2022/04/06 10:02:55 gson Exp $ */
+/* $NetBSD: t_mmap.c,v 1.18 2022/06/04 23:09:18 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_mmap.c,v 1.17 2022/04/06 10:02:55 gson Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.18 2022/06/04 23:09:18 riastradh Exp $");
 
 #include 
 #include 
@@ -619,6 +619,71 @@ ATF_TC_BODY(mmap_va0, tc)
 	map_check(map, val);
 }
 
+static void
+test_mmap_hint(uintptr_t hintaddr)
+{
+	void *hint = (void *)hintaddr;
+	void *map1 = MAP_FAILED, *map2 = MAP_FAILED, *map3 = MAP_FAILED;
+
+	map1 = mmap(hint, page, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
+	if (map1 == MAP_FAILED) {
+		atf_tc_fail_nonfatal("mmap1 hint=%p: errno=%d", hint, errno);
+		goto out;
+	}
+	map2 = mmap(map1, page, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
+	if (map2 == MAP_FAILED) {
+		atf_tc_fail_nonfatal("mmap2 hint=%p map1=%p failed: errno=%d",
+		hint, map1, errno);
+		goto out;
+	}
+	map3 = mmap(hint, page, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
+	if (map3 == MAP_FAILED) {
+		atf_tc_fail_nonfatal("mmap3 hint=%p map1=%p failed: errno=%d",
+		hint, map1, errno);
+		goto out;
+	}
+out:
+	if (map3 != MAP_FAILED) {
+		ATF_CHECK_MSG(munmap(map3, page) == 0, "munmap3 %p hint=%p",
+		map3, hint);
+	}
+	if (map2 != MAP_FAILED) {
+		ATF_CHECK_MSG(munmap(map2, page) == 0, "munmap2 %p hint=%p",
+		map2, hint);
+	}
+	if (map1 != MAP_FAILED) {
+		ATF_CHECK_MSG(munmap(map1, page) == 0, "munmap1 %p hint=%p",
+		map1, hint);
+	}
+}
+
+ATF_TC(mmap_hint);
+ATF_TC_HEAD(mmap_hint, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test mmap with hints");
+}
+ATF_TC_BODY(mmap_hint, tc)
+{
+	static const int minaddress_mib[] = { CTL_VM, VM_MINADDRESS };
+	static const int maxaddress_mib[] = { CTL_VM, VM_MAXADDRESS };
+	long minaddress, maxaddress;
+	size_t minaddresssz = sizeof(minaddress);
+	size_t maxaddresssz = sizeof(maxaddress);
+
+	ATF_REQUIRE_MSG(sysctl(minaddress_mib, __arraycount(minaddress_mib),
+		&minaddress, &minaddresssz, NULL, 0) == 0,
+	"sysctl vm.minaddress: errno=%d", errno);
+	ATF_REQUIRE_MSG(sysctl(maxaddress_mib, __arraycount(maxaddress_mib),
+		&maxaddress, &maxaddresssz, NULL, 0) == 0,
+	"sysctl vm.maxaddress: errno=%d", errno);
+
+	test_mmap_hint(0);
+	test_mmap_hint(-1);
+	test_mmap_hint(page);
+	test_mmap_hint(minaddress);
+	test_mmap_hint(maxaddress);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	page = sysconf(_SC_PAGESIZE);
@@ -634,6 +699,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, mmap_truncate);
 	ATF_TP_ADD_TC(tp, mmap_truncate_signal);
 	ATF_TP_ADD_TC(tp, mmap_va0);
+	ATF_TP_ADD_TC(tp, mmap_hint);
 
 	return atf_no_error();
 }



CVS commit: src/tests/lib/libc/sys

2022-06-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun  4 23:09:18 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
tests/lib/libc: Test mmap(2) with bad hints.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_mmap.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/libc/sys

2022-04-06 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Wed Apr  6 10:02:55 UTC 2022

Modified Files:
src/tests/lib/libc/sys: Makefile t_mmap.c

Log Message:
Add a regression test for PR kern/52239, "Changing protections of
already mmap'ed region can fail", based on the test program in the PR.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libc/sys/t_mmap.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/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.70 src/tests/lib/libc/sys/Makefile:1.71
--- src/tests/lib/libc/sys/Makefile:1.70	Mon Nov  1 14:33:41 2021
+++ src/tests/lib/libc/sys/Makefile	Wed Apr  6 10:02:55 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.70 2021/11/01 14:33:41 hannken Exp $
+# $NetBSD: Makefile,v 1.71 2022/04/06 10:02:55 gson Exp $
 
 MKMAN=	no
 
@@ -97,6 +97,7 @@ SRCS.t_mprotect=	t_mprotect.c ${SRCS_EXE
 
 LDADD.t_eventfd+=	-lpthread
 LDADD.t_getpid+=	-lpthread
+LDADD.t_mmap+=		-lpthread
 LDADD.t_timerfd+=	-lpthread
 
 LDADD.t_ptrace_sigchld+=	-pthread -lm

Index: src/tests/lib/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.16 src/tests/lib/libc/sys/t_mmap.c:1.17
--- src/tests/lib/libc/sys/t_mmap.c:1.16	Tue Apr  5 15:59:22 2022
+++ src/tests/lib/libc/sys/t_mmap.c	Wed Apr  6 10:02:55 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.16 2022/04/05 15:59:22 gson Exp $ */
+/* $NetBSD: t_mmap.c,v 1.17 2022/04/06 10:02:55 gson Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_mmap.c,v 1.16 2022/04/05 15:59:22 gson Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.17 2022/04/06 10:02:55 gson Exp $");
 
 #include 
 #include 
@@ -74,6 +74,7 @@ __RCSID("$NetBSD: t_mmap.c,v 1.16 2022/0
 #include 
 #include 
 #include 
+#include 
 
 static long	page = 0;
 static char	path[] = "mmap";
@@ -413,6 +414,65 @@ ATF_TC_CLEANUP(mmap_prot_3, tc)
 	(void)unlink(path);
 }
 
+ATF_TC(mmap_reprotect_race);
+
+ATF_TC_HEAD(mmap_reprotect_race, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test for the race condition of PR 52239");
+}
+
+const int mmap_reprotect_race_npages = 13;
+const int mmap_reprotect_iterations = 100;
+
+static void *
+mmap_reprotect_race_thread(void *arg)
+{
+	int i, r;
+	void *p;
+
+	for (i = 0; i < mmap_reprotect_iterations; i++) {
+		/* Get some unrelated memory */
+		p = mmap(0, mmap_reprotect_race_npages * page,
+			 PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
+		ATF_REQUIRE(p);
+		r = munmap(p, mmap_reprotect_race_npages * page);
+		ATF_REQUIRE(r == 0);
+	}
+	return 0;
+}
+
+ATF_TC_BODY(mmap_reprotect_race, tc)
+{
+	pthread_t thread;
+	void *p, *q;
+	int i, r;
+
+	r = pthread_create(&thread, 0, mmap_reprotect_race_thread, 0);
+	ATF_REQUIRE(r == 0);
+
+	for (i = 0; i < mmap_reprotect_iterations; i++) {
+		/* Get a placeholder region */
+		p = mmap(0, mmap_reprotect_race_npages * page,
+			 PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
+		if (p == MAP_FAILED)
+			atf_tc_fail("mmap: %s", strerror(errno));
+
+		/* Upgrade placeholder to read/write access */
+		q = mmap(p, mmap_reprotect_race_npages * page,
+			 PROT_READ|PROT_WRITE,
+			 MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
+		if (q == MAP_FAILED)
+			atf_tc_fail("update mmap: %s", strerror(errno));
+		ATF_REQUIRE(q == p);
+
+		/* Free it */
+		r = munmap(q, mmap_reprotect_race_npages * page);
+		if (r != 0)
+			atf_tc_fail("munmap: %s", strerror(errno));
+	}
+	pthread_join(thread, NULL);
+}
+
 ATF_TC_WITH_CLEANUP(mmap_truncate);
 ATF_TC_HEAD(mmap_truncate, tc)
 {
@@ -570,6 +630,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, mmap_prot_1);
 	ATF_TP_ADD_TC(tp, mmap_prot_2);
 	ATF_TP_ADD_TC(tp, mmap_prot_3);
+	ATF_TP_ADD_TC(tp, mmap_reprotect_race);
 	ATF_TP_ADD_TC(tp, mmap_truncate);
 	ATF_TP_ADD_TC(tp, mmap_truncate_signal);
 	ATF_TP_ADD_TC(tp, mmap_va0);



CVS commit: src/tests/lib/libc/sys

2022-04-06 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Wed Apr  6 10:02:55 UTC 2022

Modified Files:
src/tests/lib/libc/sys: Makefile t_mmap.c

Log Message:
Add a regression test for PR kern/52239, "Changing protections of
already mmap'ed region can fail", based on the test program in the PR.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libc/sys/t_mmap.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/libc/sys

2022-04-05 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Apr  5 15:59:22 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
In the mmap_err test case, mmap the address, not the address of the address.
Should fix PR kern/56780.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/sys/t_mmap.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/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.15 src/tests/lib/libc/sys/t_mmap.c:1.16
--- src/tests/lib/libc/sys/t_mmap.c:1.15	Tue Apr  5 13:09:54 2022
+++ src/tests/lib/libc/sys/t_mmap.c	Tue Apr  5 15:59:22 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.15 2022/04/05 13:09:54 gson Exp $ */
+/* $NetBSD: t_mmap.c,v 1.16 2022/04/05 15:59:22 gson Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_mmap.c,v 1.15 2022/04/05 13:09:54 gson Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.16 2022/04/05 15:59:22 gson Exp $");
 
 #include 
 #include 
@@ -215,7 +215,7 @@ ATF_TC_HEAD(mmap_err, tc)
 
 ATF_TC_BODY(mmap_err, tc)
 {
-	size_t addr = SIZE_MAX;
+	void *addr = (void *)-1;
 	void *map;
 
 	errno = 0;
@@ -225,7 +225,7 @@ ATF_TC_BODY(mmap_err, tc)
 	ATF_REQUIRE(errno == EBADF);
 
 	errno = 0;
-	map = mmap(&addr, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0);
+	map = mmap(addr, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0);
 
 	ATF_REQUIRE(map == MAP_FAILED);
 	ATF_REQUIRE_MSG(errno == EINVAL, "errno %d != EINVAL", errno);



CVS commit: src/tests/lib/libc/sys

2022-04-05 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Apr  5 15:59:22 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
In the mmap_err test case, mmap the address, not the address of the address.
Should fix PR kern/56780.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/sys/t_mmap.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/libc/sys

2022-04-05 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Apr  5 13:09:54 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
When the t_mmap:mmap_err test fails due to errno not having the expected
value of EINVAL, print the actual value.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_mmap.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/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.14 src/tests/lib/libc/sys/t_mmap.c:1.15
--- src/tests/lib/libc/sys/t_mmap.c:1.14	Fri Jun 26 07:50:11 2020
+++ src/tests/lib/libc/sys/t_mmap.c	Tue Apr  5 13:09:54 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.14 2020/06/26 07:50:11 jruoho Exp $ */
+/* $NetBSD: t_mmap.c,v 1.15 2022/04/05 13:09:54 gson Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_mmap.c,v 1.14 2020/06/26 07:50:11 jruoho Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.15 2022/04/05 13:09:54 gson Exp $");
 
 #include 
 #include 
@@ -228,7 +228,7 @@ ATF_TC_BODY(mmap_err, tc)
 	map = mmap(&addr, page, PROT_READ, MAP_FIXED|MAP_PRIVATE, -1, 0);
 
 	ATF_REQUIRE(map == MAP_FAILED);
-	ATF_REQUIRE(errno == EINVAL);
+	ATF_REQUIRE_MSG(errno == EINVAL, "errno %d != EINVAL", errno);
 
 	errno = 0;
 	map = mmap(NULL, page, PROT_READ, MAP_ANON|MAP_PRIVATE, INT_MAX, 0);



CVS commit: src/tests/lib/libc/sys

2022-04-05 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Apr  5 13:09:54 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_mmap.c

Log Message:
When the t_mmap:mmap_err test fails due to errno not having the expected
value of EINVAL, print the actual value.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/lib/libc/sys/t_mmap.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/libc/sys

2022-03-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 26 16:22:50 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
Add sparc* to the list of architectures that need an explicit address
with PT_CONTINUE in this test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys/t_ptrace_core_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.4 src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.5
--- src/tests/lib/libc/sys/t_ptrace_core_wait.h:1.4	Sat Jul 24 08:39:54 2021
+++ src/tests/lib/libc/sys/t_ptrace_core_wait.h	Sat Mar 26 16:22:50 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_core_wait.h,v 1.4 2021/07/24 08:39:54 rin Exp $	*/
+/*	$NetBSD: t_ptrace_core_wait.h,v 1.5 2022/03/26 16:22:50 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -209,7 +209,7 @@ ATF_TC_BODY(core_dump_procinfo, tc)
 	"without signal to be sent\n");
 
 #if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) || \
-defined(__sh3__)
+defined(__sh3__) || defined(sparc)
 	/*
 	 * For these archs, program counter is not automatically incremented
 	 * by a trap instruction. We cannot increment PC in the trap handler,



CVS commit: src/tests/lib/libc/sys

2022-03-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Mar 26 16:22:50 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_ptrace_core_wait.h

Log Message:
Add sparc* to the list of architectures that need an explicit address
with PT_CONTINUE in this test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_ptrace_core_wait.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/libc/sys

2022-03-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 18 23:35:37 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_getrandom.c

Log Message:
getrandom(2): Fix return value checks in automatic tests.

The syscall only guarantees up to 256 bytes in a single go -- if
interrupted, it might return short, but if the caller requested at
least 256 bytes it will definitely return 256 bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_getrandom.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/libc/sys/t_getrandom.c
diff -u src/tests/lib/libc/sys/t_getrandom.c:1.3 src/tests/lib/libc/sys/t_getrandom.c:1.4
--- src/tests/lib/libc/sys/t_getrandom.c:1.3	Tue Aug 25 01:37:38 2020
+++ src/tests/lib/libc/sys/t_getrandom.c	Fri Mar 18 23:35:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $	*/
+/*	$NetBSD: t_getrandom.c,v 1.4 2022/03/18 23:35:37 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,9 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_getrandom.c,v 1.3 2020/08/25 01:37:38 riastradh Exp $");
+__RCSID("$NetBSD: t_getrandom.c,v 1.4 2022/03/18 23:35:37 riastradh Exp $");
+
+#include 
 
 #include 
 
@@ -89,7 +91,8 @@ ATF_TC_BODY(getrandom_default, tc)
 	if (n == -1) {
 		ATF_CHECK_EQ(errno, EINTR);
 	} else {
-		ATF_CHECK_EQ((size_t)n, sizeof buf);
+		ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+		ATF_CHECK((size_t)n <= sizeof buf);
 		ATF_CHECK(memcmp(buf, zero24, 24) != 0);
 		ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
 	}
@@ -111,7 +114,8 @@ ATF_TC_BODY(getrandom_nonblock, tc)
 	if (n == -1) {
 		ATF_CHECK_EQ(errno, EAGAIN);
 	} else {
-		ATF_CHECK_EQ((size_t)n, sizeof buf);
+		ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+		ATF_CHECK((size_t)n <= sizeof buf);
 		ATF_CHECK(memcmp(buf, zero24, 24) != 0);
 		ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
 	}
@@ -130,7 +134,8 @@ ATF_TC_BODY(getrandom_insecure, tc)
 	memset(buf, 0, sizeof buf);
 	n = getrandom(buf, sizeof buf, GRND_INSECURE);
 	ATF_CHECK(n != -1);
-	ATF_CHECK_EQ((size_t)n, sizeof buf);
+	ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+	ATF_CHECK((size_t)n <= sizeof buf);
 	ATF_CHECK(memcmp(buf, zero24, 24) != 0);
 	ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
 }
@@ -149,7 +154,8 @@ ATF_TC_BODY(getrandom_insecure_nonblock,
 	memset(buf, 0, sizeof buf);
 	n = getrandom(buf, sizeof buf, GRND_INSECURE|GRND_NONBLOCK);
 	ATF_CHECK(n != -1);
-	ATF_CHECK_EQ((size_t)n, sizeof buf);
+	ATF_CHECK(n >= (ssize_t)MIN(256, sizeof buf));
+	ATF_CHECK((size_t)n <= sizeof buf);
 	ATF_CHECK(memcmp(buf, zero24, 24) != 0);
 	ATF_CHECK(memcmp(buf + sizeof buf - 24, zero24, 24) != 0);
 }



CVS commit: src/tests/lib/libc/sys

2022-03-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 18 23:35:37 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_getrandom.c

Log Message:
getrandom(2): Fix return value checks in automatic tests.

The syscall only guarantees up to 256 bytes in a single go -- if
interrupted, it might return short, but if the caller requested at
least 256 bytes it will definitely return 256 bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_getrandom.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/libc/sys

2022-02-20 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb 20 15:21:14 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_eventfd.c t_timerfd.c

Log Message:
Validate basic fcntl(2) behavior for eventfd and timerfd.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_eventfd.c
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_timerfd.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/libc/sys/t_eventfd.c
diff -u src/tests/lib/libc/sys/t_eventfd.c:1.2 src/tests/lib/libc/sys/t_eventfd.c:1.3
--- src/tests/lib/libc/sys/t_eventfd.c:1.2	Sun Sep 19 15:51:28 2021
+++ src/tests/lib/libc/sys/t_eventfd.c	Sun Feb 20 15:21:14 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_eventfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $ */
+/* $NetBSD: t_eventfd.c,v 1.3 2022/02/20 15:21:14 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,11 +29,12 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2020\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_eventfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $");
+__RCSID("$NetBSD: t_eventfd.c,v 1.3 2022/02/20 15:21:14 thorpej Exp $");
 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -776,6 +777,44 @@ ATF_TC_BODY(eventfd_bufsize, tc)
 
 /*/
 
+ATF_TC(eventfd_fcntl);
+ATF_TC_HEAD(eventfd_fcntl, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"validates fcntl behavior");
+}
+ATF_TC_BODY(eventfd_fcntl, tc)
+{
+	int efd;
+	int val;
+
+	ATF_REQUIRE((efd = eventfd(1, 0)) >= 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFL) & O_NONBLOCK) == 0);
+	ATF_REQUIRE(fcntl(efd, F_SETFL, O_NONBLOCK) == 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFL) & O_NONBLOCK) != 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) == 0);
+
+	ATF_REQUIRE(ioctl(efd, FIONREAD, &val) == 0);
+	ATF_REQUIRE(val == sizeof(eventfd_t));
+
+	ATF_REQUIRE(ioctl(efd, FIONWRITE, &val) == 0);
+	ATF_REQUIRE(val == 0);
+
+	ATF_REQUIRE_ERRNO(ENOTTY, ioctl(efd, FIONSPACE, &val) == -1);
+	(void)close(efd);
+
+	ATF_REQUIRE((efd = eventfd(1, EFD_NONBLOCK | EFD_CLOEXEC)) >= 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFL) & ~O_ACCMODE) == O_NONBLOCK);
+	ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) != 0);
+	ATF_REQUIRE(fcntl(efd, F_SETFD, 0) == 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) == 0);
+	ATF_REQUIRE(fcntl(efd, F_SETFD, FD_CLOEXEC) == 0);
+	ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) != 0);
+	(void)close(efd);
+}
+
+/*/
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, eventfd_normal);
@@ -785,6 +824,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, eventfd_select_poll_kevent_immed);
 	ATF_TP_ADD_TC(tp, eventfd_select_poll_kevent_block);
 	ATF_TP_ADD_TC(tp, eventfd_restart);
+	ATF_TP_ADD_TC(tp, eventfd_fcntl);
 
 	return atf_no_error();
 }

Index: src/tests/lib/libc/sys/t_timerfd.c
diff -u src/tests/lib/libc/sys/t_timerfd.c:1.3 src/tests/lib/libc/sys/t_timerfd.c:1.4
--- src/tests/lib/libc/sys/t_timerfd.c:1.3	Mon Nov  1 14:33:41 2021
+++ src/tests/lib/libc/sys/t_timerfd.c	Sun Feb 20 15:21:14 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $ */
+/* $NetBSD: t_timerfd.c,v 1.4 2022/02/20 15:21:14 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,10 +29,11 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2020\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $");
+__RCSID("$NetBSD: t_timerfd.c,v 1.4 2022/02/20 15:21:14 thorpej Exp $");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -608,6 +609,45 @@ ATF_TC_BODY(timerfd_restart, tc)
 
 /*/
 
+ATF_TC(timerfd_fcntl);
+ATF_TC_HEAD(timerfd_fcntl, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"validates fcntl behavior");
+}
+
+ATF_TC_BODY(timerfd_fcntl, tc)
+{
+	int tfd;
+	int val;
+
+	ATF_REQUIRE((tfd = timerfd_create(CLOCK_MONOTONIC, 0)) >= 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFL) & O_NONBLOCK) == 0);
+	ATF_REQUIRE(fcntl(tfd, F_SETFL, O_NONBLOCK) == 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFL) & O_NONBLOCK) != 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFD) & FD_CLOEXEC) == 0);
+
+	/* If the timer hasn't fired, there is no readable data. */
+	ATF_REQUIRE(ioctl(tfd, FIONREAD, &val) == 0);
+	ATF_REQUIRE(val == 0);
+
+	ATF_REQUIRE_ERRNO(ENOTTY, ioctl(tfd, FIONWRITE, &val) == -1);
+	ATF_REQUIRE_ERRNO(ENOTTY, ioctl(tfd, FIONSPACE, &val) == -1);
+	(void)close(tfd);
+
+	ATF_REQUIRE((tfd = timerfd_create(CLOCK_MONOTONIC,
+	  TFD_NONBLOCK | TFD_CLOEXEC)) >= 0);
+	ATF_REQUIRE((fcntl(tfd, F_GETFL) & ~O_ACCMODE) == O_NONBLOCK);
+	ATF_REQUIRE((fcntl(tfd, F_GETFD) & FD_CLOEXEC) != 0);
+	ATF_REQUIRE(fcntl(tfd, F_SETFD, 0) == 0);
+	ATF_REQUIRE(

CVS commit: src/tests/lib/libc/sys

2022-02-20 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb 20 15:21:14 UTC 2022

Modified Files:
src/tests/lib/libc/sys: t_eventfd.c t_timerfd.c

Log Message:
Validate basic fcntl(2) behavior for eventfd and timerfd.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_eventfd.c
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_timerfd.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/libc/sys

2021-11-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Nov  1 14:33:42 UTC 2021

Modified Files:
src/tests/lib/libc/sys: Makefile t_timerfd.c

Log Message:
Test lib/libc/sys/t_timerfd often fails when run on QEMU because
QEMU misses clock interrupts.

Always check values against [ lower, upper ] bounds and use "4 * upper"
when run under QEMU.

Now becomes part of PR kern/43997 "Kernel timer discrepancies".


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_timerfd.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/libc/sys

2021-11-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Mon Nov  1 14:33:42 UTC 2021

Modified Files:
src/tests/lib/libc/sys: Makefile t_timerfd.c

Log Message:
Test lib/libc/sys/t_timerfd often fails when run on QEMU because
QEMU misses clock interrupts.

Always check values against [ lower, upper ] bounds and use "4 * upper"
when run under QEMU.

Now becomes part of PR kern/43997 "Kernel timer discrepancies".


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_timerfd.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/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.69 src/tests/lib/libc/sys/Makefile:1.70
--- src/tests/lib/libc/sys/Makefile:1.69	Sun Sep 19 15:51:28 2021
+++ src/tests/lib/libc/sys/Makefile	Mon Nov  1 14:33:41 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.69 2021/09/19 15:51:28 thorpej Exp $
+# $NetBSD: Makefile,v 1.70 2021/11/01 14:33:41 hannken Exp $
 
 MKMAN=	no
 
@@ -117,6 +117,8 @@ LDADD.t_posix_fadvise+= ${LIBRUMPBASE}
 CPPFLAGS.t_futex_ops.c		+= -I${.CURDIR}/../../../../lib
 CPPFLAGS.t_futex_robust.c	+= -I${.CURDIR}/../../../../lib
 
+CPPFLAGS.t_timerfd.c		+= -I${.CURDIR}/../gen
+
 CPPFLAGS.t_lwp_create.c		+= -D_KERNTYPES
 CPPFLAGS.t_ptrace_sigchld.c	+= -D__TEST_FENV
 CPPFLAGS.t_ptrace_wait.c	+= -D_KERNTYPES -D__TEST_FENV

Index: src/tests/lib/libc/sys/t_timerfd.c
diff -u src/tests/lib/libc/sys/t_timerfd.c:1.2 src/tests/lib/libc/sys/t_timerfd.c:1.3
--- src/tests/lib/libc/sys/t_timerfd.c:1.2	Sun Sep 19 15:51:28 2021
+++ src/tests/lib/libc/sys/t_timerfd.c	Mon Nov  1 14:33:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: t_timerfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $ */
+/* $NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $ */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2020\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_timerfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $");
+__RCSID("$NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $");
 
 #include 
 #include 
@@ -47,6 +47,8 @@ __RCSID("$NetBSD: t_timerfd.c,v 1.2 2021
 
 #include 
 
+#include "isqemu.h"
+
 struct helper_context {
 	int	fd;
 
@@ -70,6 +72,26 @@ wait_barrier(struct helper_context * con
 	return rv == 0 || rv == PTHREAD_BARRIER_SERIAL_THREAD;
 }
 
+static bool
+check_value_against_bounds(uint64_t value, uint64_t lower, uint64_t upper)
+{
+
+	/*
+	 * If running under QEMU make sure the upper bound is large
+	 * enough for the effect of kern/43997
+	 */
+	if (isQEMU()) {
+		upper *= 4;
+	}
+
+	if (value < lower || value > upper) {
+		printf("val %" PRIu64 " not in [ %" PRIu64 ", %" PRIu64 " ]\n",
+		value, lower, upper);
+	}
+
+	return value >= lower && value <= upper;
+}
+
 /*/
 
 static int
@@ -169,10 +191,10 @@ ATF_TC_BODY(timerfd_block, tc)
 	ATF_REQUIRE(timerfd_settime(fd, 0, &its, NULL) == 0);
 	ATF_REQUIRE(timerfd_read(fd, &val) == 0);
 	ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &now) == 0);
-	ATF_REQUIRE(val == 1);
+	ATF_REQUIRE(check_value_against_bounds(val, 1, 1));
 
 	timespecsub(&now, &then, &delta);
-	ATF_REQUIRE(delta.tv_sec == 1);
+	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
 
 	(void) close(fd);
 }
@@ -203,10 +225,11 @@ ATF_TC_BODY(timerfd_repeating, tc)
 	ATF_REQUIRE(sleep(1) == 0);
 	ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &now) == 0);
 	ATF_REQUIRE(timerfd_read(fd, &val) == 0);
-	ATF_REQUIRE(val >= 3 && val <= 5);	/* allow some slop */
+	/* allow some slop */
+	ATF_REQUIRE(check_value_against_bounds(val, 3, 5));
 
 	timespecsub(&now, &then, &delta);
-	ATF_REQUIRE(delta.tv_sec == 1);
+	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
 
 	(void) close(fd);
 }
@@ -237,10 +260,10 @@ ATF_TC_BODY(timerfd_abstime, tc)
 	ATF_REQUIRE(timerfd_settime(fd, TFD_TIMER_ABSTIME, &its, NULL) == 0);
 	ATF_REQUIRE(timerfd_read(fd, &val) == 0);
 	ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &now) == 0);
-	ATF_REQUIRE(val == 1);
+	ATF_REQUIRE(check_value_against_bounds(val, 1, 1));
 
 	timespecsub(&now, &then, &delta);
-	ATF_REQUIRE(delta.tv_sec == 1);
+	ATF_REQUIRE(check_value_against_bounds(delta.tv_sec, 1, 1));
 
 	(void) close(fd);
 }



CVS commit: src/tests/lib/libc/sys

2021-10-21 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Thu Oct 21 17:02:38 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_syscall_wait.h

Log Message:
Skip the lib/libc/sys/t_ptrace_waitid:syscall_signal_on_sce test case
with a reference to PR lib/55087.  Marking it as an expected failure
would be more appropriate, but that doesn't work for test cases that
fail by timing out.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_syscall_wait.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/libc/sys/t_ptrace_syscall_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_syscall_wait.h:1.1 src/tests/lib/libc/sys/t_ptrace_syscall_wait.h:1.2
--- src/tests/lib/libc/sys/t_ptrace_syscall_wait.h:1.1	Mon May  4 21:21:30 2020
+++ src/tests/lib/libc/sys/t_ptrace_syscall_wait.h	Thu Oct 21 17:02:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_syscall_wait.h,v 1.1 2020/05/04 21:21:30 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_syscall_wait.h,v 1.2 2021/10/21 17:02:37 gson Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -55,11 +55,13 @@ syscall_body(const char *op)
 
 	memset(&info, 0, sizeof(info));
 
-#if defined(TWAIT_HAVE_STATUS)
 	if (strstr(op, "signal") != NULL) {
+#if defined(TWAIT_HAVE_STATUS)
 		atf_tc_expect_fail("XXX: behavior under investigation");
-	}
+#else
+		atf_tc_skip("PR lib/55087");
 #endif
+	}
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);



CVS commit: src/tests/lib/libc/sys

2021-10-21 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Thu Oct 21 17:02:38 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_syscall_wait.h

Log Message:
Skip the lib/libc/sys/t_ptrace_waitid:syscall_signal_on_sce test case
with a reference to PR lib/55087.  Marking it as an expected failure
would be more appropriate, but that doesn't work for test cases that
fail by timing out.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_ptrace_syscall_wait.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/libc/sys

2021-10-14 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Thu Oct 14 13:50:36 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_register_wait.h

Log Message:
Remove trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_register_wait.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/libc/sys/t_ptrace_register_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.3 src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.4
--- src/tests/lib/libc/sys/t_ptrace_register_wait.h:1.3	Mon May 11 12:17:57 2020
+++ src/tests/lib/libc/sys/t_ptrace_register_wait.h	Thu Oct 14 13:50:36 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: t_ptrace_register_wait.h,v 1.3 2020/05/11 12:17:57 kamil Exp $   */
+/*  $NetBSD: t_ptrace_register_wait.h,v 1.4 2021/10/14 13:50:36 gson Exp $   */
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@ access_regs(const char *regset, const ch
 #if defined(HAVE_FPREGS)
 	struct fpreg fpr;
 #endif
-	
+
 #if !defined(HAVE_GPREGS)
 	if (strcmp(regset, "regs") == 0)
 		atf_tc_fail("Impossible test scenario!");



CVS commit: src/tests/lib/libc/sys

2021-10-14 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Thu Oct 14 13:50:36 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_ptrace_register_wait.h

Log Message:
Remove trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_ptrace_register_wait.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/libc/sys

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 15:50:06 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_poll.c

Log Message:
Add a fifo_inout test case that validates the expected POLLIN / POLLOUT
behavior for FIFOs:
- A FIFO is readable so long as at least 1 byte is available.
- A FIFO is writable so long as at least PIPE_BUF (obtained with _PC_PIPE_BUF)
  space is avaiable.

This will be cloned for a forthcoming kevent test case.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_poll.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/libc/sys/t_poll.c
diff -u src/tests/lib/libc/sys/t_poll.c:1.6 src/tests/lib/libc/sys/t_poll.c:1.7
--- src/tests/lib/libc/sys/t_poll.c:1.6	Sat Oct  2 14:41:36 2021
+++ src/tests/lib/libc/sys/t_poll.c	Sat Oct  2 15:50:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_poll.c,v 1.6 2021/10/02 14:41:36 thorpej Exp $	*/
+/*	$NetBSD: t_poll.c,v 1.7 2021/10/02 15:50:06 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -252,6 +253,104 @@ fifo_support(void)
 	}
 }
 
+ATF_TC_WITH_CLEANUP(fifo_inout);
+ATF_TC_HEAD(fifo_inout, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Check POLLIN/POLLOUT behavior with fifos");
+}
+
+ATF_TC_BODY(fifo_inout, tc)
+{
+	struct pollfd pfd[2];
+	char *buf;
+	int rfd, wfd;
+	long pipe_buf;
+
+	fifo_support();
+
+	ATF_REQUIRE(mkfifo(fifo_path, 0600) == 0);
+	ATF_REQUIRE((rfd = open(fifo_path, O_RDONLY | O_NONBLOCK)) >= 0);
+	ATF_REQUIRE((wfd = open(fifo_path, O_WRONLY | O_NONBLOCK)) >= 0);
+
+	/* Get the maximum atomic pipe write size. */
+	pipe_buf = fpathconf(wfd, _PC_PIPE_BUF);
+	ATF_REQUIRE(pipe_buf > 1);
+
+	buf = malloc(pipe_buf);
+	ATF_REQUIRE(buf != NULL);
+
+	memset(&pfd, 0, sizeof(pfd));
+	pfd[0].fd = rfd;
+	pfd[0].events = POLLIN | POLLRDNORM;
+	pfd[1].fd = wfd;
+	pfd[1].events = POLLOUT | POLLWRNORM;
+
+	/* We expect the FIFO to be writable but not readable. */
+	ATF_REQUIRE(poll(pfd, 2, 0) == 1);
+	ATF_REQUIRE(pfd[0].revents == 0);
+	ATF_REQUIRE(pfd[1].revents == (POLLOUT | POLLWRNORM));
+
+	/* Write a single byte of data into the FIFO. */
+	ATF_REQUIRE(write(wfd, buf, 1) == 1);
+
+	/* We expect the FIFO to be readable and writable. */
+	ATF_REQUIRE(poll(pfd, 2, 0) == 2);
+	ATF_REQUIRE(pfd[0].revents == (POLLIN | POLLRDNORM));
+	ATF_REQUIRE(pfd[1].revents == (POLLOUT | POLLWRNORM));
+
+	/* Read that single byte back out. */
+	ATF_REQUIRE(read(rfd, buf, 1) == 1);
+
+	/*
+	 * Write data into the FIFO until it is full, which is
+	 * defined as insufficient buffer space to hold a the
+	 * maximum atomic pipe write size.
+	 */
+	while (write(wfd, buf, pipe_buf) != -1) {
+		continue;
+	}
+	ATF_REQUIRE(errno == EAGAIN);
+
+	/* We expect the FIFO to be readble but not writable. */
+	ATF_REQUIRE(poll(pfd, 2, 0) == 1);
+	ATF_REQUIRE(pfd[0].revents == (POLLIN | POLLRDNORM));
+	ATF_REQUIRE(pfd[1].revents == 0);
+
+	/* Read a single byte of data from the FIFO. */
+	ATF_REQUIRE(read(rfd, buf, 1) == 1);
+
+	/*
+	 * Because we have read only a single byte out, there will
+	 * be insufficient space for a pipe_buf-sized message, so
+	 * the FIFO should still not be writable.
+	 */
+	ATF_REQUIRE(poll(pfd, 2, 0) == 1);
+	ATF_REQUIRE(pfd[0].revents == (POLLIN | POLLRDNORM));
+	ATF_REQUIRE(pfd[1].revents == 0);
+
+	/*
+	 * Now read all of the data out of the FIFO and ensure that
+	 * we get back to the initial state.
+	 */
+	while (read(rfd, buf, pipe_buf) != -1) {
+		continue;
+	}
+	ATF_REQUIRE(errno == EAGAIN);
+
+	ATF_REQUIRE(poll(pfd, 2, 0) == 1);
+	ATF_REQUIRE(pfd[0].revents == 0);
+	ATF_REQUIRE(pfd[1].revents == (POLLOUT | POLLWRNORM));
+
+	(void)close(wfd);
+	(void)close(rfd);
+}
+
+ATF_TC_CLEANUP(fifo_inout, tc)
+{
+	(void)unlink(fifo_path);
+}
+
 ATF_TC_WITH_CLEANUP(fifo_hup1);
 ATF_TC_HEAD(fifo_hup1, tc)
 {
@@ -354,6 +453,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, basic);
 	ATF_TP_ADD_TC(tp, err);
 
+	ATF_TP_ADD_TC(tp, fifo_inout);
 	ATF_TP_ADD_TC(tp, fifo_hup1);
 	ATF_TP_ADD_TC(tp, fifo_hup2);
 



CVS commit: src/tests/lib/libc/sys

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 15:50:06 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_poll.c

Log Message:
Add a fifo_inout test case that validates the expected POLLIN / POLLOUT
behavior for FIFOs:
- A FIFO is readable so long as at least 1 byte is available.
- A FIFO is writable so long as at least PIPE_BUF (obtained with _PC_PIPE_BUF)
  space is avaiable.

This will be cloned for a forthcoming kevent test case.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_poll.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/libc/sys

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 14:41:36 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_poll.c

Log Message:
In the fifo_hup1 test, also ensure that POLLHUP is de-asserted when a
new writer appears.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_poll.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/libc/sys/t_poll.c
diff -u src/tests/lib/libc/sys/t_poll.c:1.5 src/tests/lib/libc/sys/t_poll.c:1.6
--- src/tests/lib/libc/sys/t_poll.c:1.5	Sat Oct  2 02:07:41 2021
+++ src/tests/lib/libc/sys/t_poll.c	Sat Oct  2 14:41:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_poll.c,v 1.5 2021/10/02 02:07:41 thorpej Exp $	*/
+/*	$NetBSD: t_poll.c,v 1.6 2021/10/02 14:41:36 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -278,6 +278,18 @@ ATF_TC_BODY(fifo_hup1, tc)
 
 	ATF_REQUIRE(poll(&pfd, 1, 0) == 1);
 	ATF_REQUIRE((pfd.revents & POLLHUP) != 0);
+
+	/*
+	 * Check that POLLHUP is cleared when a writer re-connects.
+	 * Since the writer will not put any data into the FIFO, we
+	 * expect no events.
+	 */
+	memset(&pfd, 0, sizeof(pfd));
+	pfd.fd = rfd;
+	pfd.events = POLLIN;
+
+	ATF_REQUIRE((wfd = open(fifo_path, O_WRONLY)) >= 0);
+	ATF_REQUIRE(poll(&pfd, 1, 0) == 0);
 }
 
 ATF_TC_CLEANUP(fifo_hup1, tc)



CVS commit: src/tests/lib/libc/sys

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 14:41:36 UTC 2021

Modified Files:
src/tests/lib/libc/sys: t_poll.c

Log Message:
In the fifo_hup1 test, also ensure that POLLHUP is de-asserted when a
new writer appears.


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

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



Re: CVS commit: src/tests/lib/libc/sys

2020-06-22 Thread Rin Okuyama

Committed. Thank you for your comment!

rin

On 2020/06/22 20:09, Kamil Rytarowski wrote:

On 22.06.2020 04:51, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Mon Jun 22 02:51:07 UTC 2020

Modified Files:
src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h

Log Message:
Turn trigger_fpe() back to integer division by zero for a while
until QEMU bug #1668041 is fixed:

https://bugs.launchpad.net/qemu/+bug/1668041

by which floating-point division by zero is not trapped correctly
both on amd64 and i386.

Skip *_crash_fpe tests on powerpc, where integer division by zero
is never trapped.




The intention of this test is just detecting SIGFPE. If the si_code
value is various on different architectures (like one traps on integers
other one on floats), we shall just drop the asserts for si_code and
adapt the trigger_fpe() function to cover promptly more ports.

The qemu bug should be fixed nonetheless.




Re: CVS commit: src/tests/lib/libc/sys

2020-06-22 Thread Kamil Rytarowski
On 22.06.2020 04:51, Rin Okuyama wrote:
> Module Name:  src
> Committed By: rin
> Date: Mon Jun 22 02:51:07 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h
> 
> Log Message:
> Turn trigger_fpe() back to integer division by zero for a while
> until QEMU bug #1668041 is fixed:
> 
> https://bugs.launchpad.net/qemu/+bug/1668041
> 
> by which floating-point division by zero is not trapped correctly
> both on amd64 and i386.
> 
> Skip *_crash_fpe tests on powerpc, where integer division by zero
> is never trapped.
> 


The intention of this test is just detecting SIGFPE. If the si_code
value is various on different architectures (like one traps on integers
other one on floats), we shall just drop the asserts for si_code and
adapt the trigger_fpe() function to cover promptly more ports.

The qemu bug should be fixed nonetheless.




signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-06-17 Thread Rin Okuyama

On 2020/06/17 17:42, Rin Okuyama wrote:

Now, all *_crash_fpe tests pass for powerpc, and nothing changes for amd64
at least.


Here, powerpc means powerpc/oea, more specifically Mac mini G4.

At the moment, fenv.h doesn't work correctly on booke and ibm4xx, where FPU
is emulated in software. For some processors of oea, m[ft]msr instructions
used in fenv.h may be privileged, and need similar care as booke/ibm4xx.

Thanks,
rin


Re: CVS commit: src/tests/lib/libc/sys

2020-06-06 Thread Andrew Doran
On Sat, Jun 06, 2020 at 06:11:21PM +, Jason R Thorpe wrote:

> Module Name:  src
> Committed By: thorpej
> Date: Sat Jun  6 18:11:21 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_lwp_create.c
> 
> Log Message:
> Add a test case to ensure that _lwp_create() fails with the
> expected error code when a bad new-lwp-id pointer is passed.

Was thinking of just this yesterday - thanks!  It's a fragile bit of code
and has been fixed 3x already this year.

Andrew


Re: CVS commit: src/tests/lib/libc/sys

2020-05-15 Thread Kamil Rytarowski
On 15.05.2020 00:43, Taylor R Campbell wrote:
>> Date: Thu, 14 May 2020 23:36:28 +0200
>> From: Kamil Rytarowski 
>>
>> If a signal would not reach the child process (as it is ignored or
>> masked+SA_IGNOREd) and it is not a crash signal, it is dropped. As I
>> checked, it's the design in UNIX to overlook SIGCHLD signals in UNIX.
>> Race free signals could be maybe possible, but with some design rethinking.
> 
> I don't understand -- are you saying that if I mask SIGCHLD, e.g. with
> sigprocmask(SIG_BLOCK), then because sigprop[SIGCHLD] has SA_IGNORE
> set, any SIGCHLD signals will be discarded while I have it masked?
> 

That's it. But it will be discarded only when there is no SIGCHLD signal
handler installed. That's the case in the test.

A debugger catches regular signals only (except crash related ones) when
they reach the debuggee,

> This can't be right, so either I misunderstood what you're saying, or
> something else is afoot with the test that is making it flaky, or
> there's a bug in the kernel.
> 

It's a design.

If we install a signal handler for SIGCHLD in the traced the test is
very stable and we note SIGCHLD always, so there is no bug.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-05-14 Thread Taylor R Campbell
> Date: Thu, 14 May 2020 23:36:28 +0200
> From: Kamil Rytarowski 
> 
> If a signal would not reach the child process (as it is ignored or
> masked+SA_IGNOREd) and it is not a crash signal, it is dropped. As I
> checked, it's the design in UNIX to overlook SIGCHLD signals in UNIX.
> Race free signals could be maybe possible, but with some design rethinking.

I don't understand -- are you saying that if I mask SIGCHLD, e.g. with
sigprocmask(SIG_BLOCK), then because sigprop[SIGCHLD] has SA_IGNORE
set, any SIGCHLD signals will be discarded while I have it masked?

This can't be right, so either I misunderstood what you're saying, or
something else is afoot with the test that is making it flaky, or
there's a bug in the kernel.


Re: CVS commit: src/tests/lib/libc/sys

2020-05-14 Thread Joerg Sonnenberger
On Thu, May 14, 2020 at 11:36:28PM +0200, Kamil Rytarowski wrote:
> On 14.05.2020 23:02, Joerg Sonnenberger wrote:
> > On Thu, May 14, 2020 at 07:21:35PM +, Kamil Rytarowski wrote:
> >> Module Name:   src
> >> Committed By:  kamil
> >> Date:  Thu May 14 19:21:35 UTC 2020
> >>
> >> Modified Files:
> >>src/tests/lib/libc/sys: t_ptrace_fork_wait.h
> >>
> >> Log Message:
> >> Ignore interception of the SIGCHLD signals.
> >>
> >> SIGCHLD once blocked is discarded by the kernel as it has the
> >> SA_IGNORE property. During the fork(2) operation all signals can be
> >> shortly blocked and missed (unless there is a registered signal
> >> handler in the traced child). This leads to a race in this test if
> >> there would be an intention to catch SIGCHLD.
> > 
> > This doesn't sound right. sigprocmask and pthread_sigmask shouldn't
> > affect whether the signal handler is called, only when. Temporarily
> > masking a signal is different from setting it to SIG_IGN.
> > 
> > Joerg
> > 
> 
> I was looking into it and as there is no signal handler for SIGCHLD, the
> signal is discarded.

Sure, but that doesn't really have anything to do with signal blocking.
That's the part that is confusing.

Joerg


Re: CVS commit: src/tests/lib/libc/sys

2020-05-14 Thread Kamil Rytarowski
On 14.05.2020 23:02, Joerg Sonnenberger wrote:
> On Thu, May 14, 2020 at 07:21:35PM +, Kamil Rytarowski wrote:
>> Module Name: src
>> Committed By:kamil
>> Date:Thu May 14 19:21:35 UTC 2020
>>
>> Modified Files:
>>  src/tests/lib/libc/sys: t_ptrace_fork_wait.h
>>
>> Log Message:
>> Ignore interception of the SIGCHLD signals.
>>
>> SIGCHLD once blocked is discarded by the kernel as it has the
>> SA_IGNORE property. During the fork(2) operation all signals can be
>> shortly blocked and missed (unless there is a registered signal
>> handler in the traced child). This leads to a race in this test if
>> there would be an intention to catch SIGCHLD.
> 
> This doesn't sound right. sigprocmask and pthread_sigmask shouldn't
> affect whether the signal handler is called, only when. Temporarily
> masking a signal is different from setting it to SIG_IGN.
> 
> Joerg
> 

I was looking into it and as there is no signal handler for SIGCHLD, the
signal is discarded.

Another approach to fix the race would be to:

1. Add SIGCHLD signal handler in the traced child.
2. Explicitly masking SIGCHLD in the traced child.

If a signal would not reach the child process (as it is ignored or
masked+SA_IGNOREd) and it is not a crash signal, it is dropped. As I
checked, it's the design in UNIX to overlook SIGCHLD signals in UNIX.
Race free signals could be maybe possible, but with some design rethinking.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-05-14 Thread Joerg Sonnenberger
On Thu, May 14, 2020 at 07:21:35PM +, Kamil Rytarowski wrote:
> Module Name:  src
> Committed By: kamil
> Date: Thu May 14 19:21:35 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_fork_wait.h
> 
> Log Message:
> Ignore interception of the SIGCHLD signals.
> 
> SIGCHLD once blocked is discarded by the kernel as it has the
> SA_IGNORE property. During the fork(2) operation all signals can be
> shortly blocked and missed (unless there is a registered signal
> handler in the traced child). This leads to a race in this test if
> there would be an intention to catch SIGCHLD.

This doesn't sound right. sigprocmask and pthread_sigmask shouldn't
affect whether the signal handler is called, only when. Temporarily
masking a signal is different from setting it to SIG_IGN.

Joerg


Re: CVS commit: src/tests/lib/libc/sys

2020-05-11 Thread Robert Elz
Date:Mon, 11 May 2020 13:47:45 +0200
From:Kamil Rytarowski 
Message-ID:  <54178983-82d1-df3d-fd54-549a6c73f...@gmx.com>

  | The only purpose of the test is to check whether misaligned program
  | counter can crash the kernel (it can for NetBSD/sparc). Later, if a
  | process dies or runs is not important, thus it is being killed.

That's all fine.

  | A process can disappear after dying and before reappearing as a zombie.

There's a state between running and dead (zombie), that's correct - but
it really doesn't matter, once the process ceases to be alive, it is beyond
killing any more.

  | This is not a bug, but a predicted race.

Yes, that's what I said, and that's fine too.

  | Doing the kill once (and missing the process) is still possibly enough,
  | but correcting it with SIGKILL does not cost.

No, there is no problem with doing the SIGKILL, but if fails for the
above reason, there's absolutely no point trying again.  The process is
gone, it isn't coming back.   It doesn't need killing.

But even if there was a reason to try again (there isn't), one more
attempt would do - inserting an infinite loop is folly.

But I see that you have fixed it, that's good, what's there now looks
much better.   Thanks.

kre




Re: CVS commit: src/tests/lib/libc/sys

2020-05-11 Thread Kamil Rytarowski
On 11.05.2020 13:35, Robert Elz wrote:
> Date:Mon, 11 May 2020 11:03:15 +
> From:"Kamil Rytarowski" 
> Message-ID:  <2020050315.54b13f...@cvs.netbsd.org>
> 
>   | Do not fail when trying to kill a dying process
>   |
>   | A dying process can disappear for a while. Rather than aborting, retry
>   | sending SIGKILL to it.
> 
> I don't understand this ... a process should never be able to
> disappear and then reappear (not in any way).   If a SIGKILL (or
> ptrace(PT_KILL) fails with a "no such process" error, then repeating
> it won't (or shouldn't) help - if it does, there's a kernel bug that
> needs fixing (and it is OK for the test to fail until that happens.)
> 
> Further, if the reason for this failure is that the process is
> dying, you probably never needed the kill in the first place (and
> no, I don't mean it should be deleted - the parent is unlikely to
> know the state of the child, so killing it, if that is what is needed
> is the right thing to do ... just that if the kill fails because you
> were too late issuing it, it isn't an error, just a race that you lost,
> and certainly shouldn't be repeated).
> 
> But more than that, adding an infinite loop to the test, where you keep
> doing the kill forever until it succeeds, or errno somehow stops being
> ESRCH looks like a recipe for disaster.
> 
> Just do the kill once, ignore the error if it is ESRCH (and probably
> also ECHILD) report other errors as failures.
> 
> kre
> 

The only purpose of the test is to check whether misaligned program
counter can crash the kernel (it can for NetBSD/sparc). Later, if a
process dies or runs is not important, thus it is being killed.

A process can disappear after dying and before reappearing as a zombie.
This is not a bug, but a predicted race. We already discussed it in the
past, whether to return the same process multiple times or overlook it
for a while during the transition dying->zombie. Once an entity died it
disappeared so the same is true for a process.

Doing the kill once (and missing the process) is still possibly enough,
but correcting it with SIGKILL does not cost.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-05-11 Thread Robert Elz
Date:Mon, 11 May 2020 11:03:15 +
From:"Kamil Rytarowski" 
Message-ID:  <2020050315.54b13f...@cvs.netbsd.org>

  | Do not fail when trying to kill a dying process
  |
  | A dying process can disappear for a while. Rather than aborting, retry
  | sending SIGKILL to it.

I don't understand this ... a process should never be able to
disappear and then reappear (not in any way).   If a SIGKILL (or
ptrace(PT_KILL) fails with a "no such process" error, then repeating
it won't (or shouldn't) help - if it does, there's a kernel bug that
needs fixing (and it is OK for the test to fail until that happens.)

Further, if the reason for this failure is that the process is
dying, you probably never needed the kill in the first place (and
no, I don't mean it should be deleted - the parent is unlikely to
know the state of the child, so killing it, if that is what is needed
is the right thing to do ... just that if the kill fails because you
were too late issuing it, it isn't an error, just a race that you lost,
and certainly shouldn't be repeated).

But more than that, adding an infinite loop to the test, where you keep
doing the kill forever until it succeeds, or errno somehow stops being
ESRCH looks like a recipe for disaster.

Just do the kill once, ignore the error if it is ESRCH (and probably
also ECHILD) report other errors as failures.

kre



Re: CVS commit: src/tests/lib/libc/sys

2020-04-24 Thread Kamil Rytarowski
On 24.04.2020 05:25, Jason R Thorpe wrote:
> Module Name:  src
> Committed By: thorpej
> Date: Fri Apr 24 03:25:20 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_x86_wait.h
> 
> Log Message:
> Update for new LWP behavior -- as of 9.99.59, the LWP ID of a single-LWP
> process is the PID, not 1.
> 

Thanks. These tests shall not rely on specific LWP numbers and I will
remove the asserts.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-03-07 Thread Christos Zoulas
In article <5e528f7a-147a-23e7-46da-6b02d76e5...@gmx.com>,
Kamil Rytarowski   wrote:
>-=-=-=-=-=-
>-=-=-=-=-=-
>
>On 07.03.2020 15:53, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Sat Mar  7 14:53:14 UTC 2020
>> 
>> Modified Files:
>>  src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h
>> 
>> Log Message:
>> Try to fix the build. This is why all those inlines should really be in a
>> separate file as regular function. The code is too large and hard to manage
>> this way, and only increases in complexity as time goes by.
>> 
>> 
>
>What build configuration was broken?

All of the evbarm ones since t_ptrace_sigchld.c was not including ieefp.h
http://releng.netbsd.org/builds/HEAD/202003070040Z/evbarm-earmhfeb.build.failed

christos



Re: CVS commit: src/tests/lib/libc/sys

2020-03-07 Thread Kamil Rytarowski
On 07.03.2020 15:53, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Sat Mar  7 14:53:14 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h
> 
> Log Message:
> Try to fix the build. This is why all those inlines should really be in a
> separate file as regular function. The code is too large and hard to manage
> this way, and only increases in complexity as time goes by.
> 
> 

What build configuration was broken?



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-02-18 Thread Kamil Rytarowski
On 18.02.2020 16:57, Christos Zoulas wrote:
> In article <20200213152742.081a9f...@cvs.netbsd.org>,
> MichaŠ Górny   wrote:
>> -=-=-=-=-=-
>>
>> Module Name: src
>> Committed By:mgorny
>> Date:Thu Feb 13 15:27:41 UTC 2020
>>
>> Modified Files:
>>  src/tests/lib/libc/sys: t_ptrace_wait.c
>>
>> Log Message:
>> Enable combined breakpoint, watchpoint and signal tests
> 
> Let's split this file up. The name does not reflect anymore what this
> is testing and it has become more than 9000 lines long. Because of the
> complexity it keeps breaking the build and because of the size it makes
> fixing it awkward. Kamil/Michal, can you please work on this?
> [ for example the llvm builds are currently broken ]
> 
> Thanks,
> 
> christos
> 

I will do it.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/lib/libc/sys

2020-02-18 Thread Christos Zoulas
In article <20200213152742.081a9f...@cvs.netbsd.org>,
MichaŠ Górny   wrote:
>-=-=-=-=-=-
>
>Module Name:   src
>Committed By:  mgorny
>Date:  Thu Feb 13 15:27:41 UTC 2020
>
>Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_wait.c
>
>Log Message:
>Enable combined breakpoint, watchpoint and signal tests

Let's split this file up. The name does not reflect anymore what this
is testing and it has become more than 9000 lines long. Because of the
complexity it keeps breaking the build and because of the size it makes
fixing it awkward. Kamil/Michal, can you please work on this?
[ for example the llvm builds are currently broken ]

Thanks,

christos



Re: CVS commit: src/tests/lib/libc/sys

2020-02-13 Thread Christos Zoulas
In article <20200213114904.ga30...@bec.de>,
Joerg Sonnenberger   wrote:
>On Thu, Feb 13, 2020 at 10:50:19AM +0100, Joerg Sonnenberger wrote:
>> On Wed, Feb 12, 2020 at 09:53:46PM -0500, Christos Zoulas wrote:
>> > Module Name:   src
>> > Committed By:  christos
>> > Date:  Thu Feb 13 02:53:46 UTC 2020
>> > 
>> > Modified Files:
>> >src/tests/lib/libc/sys: t_ptrace_x86_wait.h
>> > 
>> > Log Message:
>> > Turn off optimization on a function which contains constant labels.
>> > The optimizer splits it and we end up with 2 copies and duplicate symbols.
>> 
>> Why not just turn them into local labels instead?
>
>Alternatively, suffixing them with %= would create unique labels.

I was looking for that :-)

christos



Re: CVS commit: src/tests/lib/libc/sys

2020-02-13 Thread Christos Zoulas
In article <20200213095019.ga28...@bec.de>,
Joerg Sonnenberger   wrote:
>On Wed, Feb 12, 2020 at 09:53:46PM -0500, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Thu Feb 13 02:53:46 UTC 2020
>> 
>> Modified Files:
>>  src/tests/lib/libc/sys: t_ptrace_x86_wait.h
>> 
>> Log Message:
>> Turn off optimization on a function which contains constant labels.
>> The optimizer splits it and we end up with 2 copies and duplicate symbols.
>
>Why not just turn them into local labels instead?

You mean 1f etc? I was not sure if that would work in the symbol defined case.

christos



Re: CVS commit: src/tests/lib/libc/sys

2020-02-13 Thread Joerg Sonnenberger
On Thu, Feb 13, 2020 at 10:50:19AM +0100, Joerg Sonnenberger wrote:
> On Wed, Feb 12, 2020 at 09:53:46PM -0500, Christos Zoulas wrote:
> > Module Name:src
> > Committed By:   christos
> > Date:   Thu Feb 13 02:53:46 UTC 2020
> > 
> > Modified Files:
> > src/tests/lib/libc/sys: t_ptrace_x86_wait.h
> > 
> > Log Message:
> > Turn off optimization on a function which contains constant labels.
> > The optimizer splits it and we end up with 2 copies and duplicate symbols.
> 
> Why not just turn them into local labels instead?

Alternatively, suffixing them with %= would create unique labels.

Joerg


Re: CVS commit: src/tests/lib/libc/sys

2020-02-13 Thread Joerg Sonnenberger
On Wed, Feb 12, 2020 at 09:53:46PM -0500, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Thu Feb 13 02:53:46 UTC 2020
> 
> Modified Files:
>   src/tests/lib/libc/sys: t_ptrace_x86_wait.h
> 
> Log Message:
> Turn off optimization on a function which contains constant labels.
> The optimizer splits it and we end up with 2 copies and duplicate symbols.

Why not just turn them into local labels instead?

Joerg


CVS commit: src/tests/lib/libc/sys

2019-11-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Nov 12 18:18:04 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h

Log Message:
Rework thread_concurrent_signals and trace_thread_lwpcreate_and_exit

Change the code to remove the LWP id assumptions that broke after
src/sys/kern/kern_lwp.c r. 1.206.

Original code by , tested and tweaked by myself.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/tests/lib/libc/sys/t_ptrace_wait.c
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys

2019-11-12 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Nov 12 18:18:04 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c t_ptrace_wait.h

Log Message:
Rework thread_concurrent_signals and trace_thread_lwpcreate_and_exit

Change the code to remove the LWP id assumptions that broke after
src/sys/kern/kern_lwp.c r. 1.206.

Original code by , tested and tweaked by myself.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/tests/lib/libc/sys/t_ptrace_wait.c
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.140 src/tests/lib/libc/sys/t_ptrace_wait.c:1.141
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.140	Mon Oct 21 18:36:08 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Tue Nov 12 18:18:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.140 2019/10/21 18:36:08 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.141 2019/11/12 18:18:04 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.140 2019/10/21 18:36:08 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.141 2019/11/12 18:18:04 kamil Exp $");
 
 #include 
 #include 
@@ -5478,7 +5478,7 @@ trace_threads(bool trace_create, bool tr
 	lwpid_t lid;
 
 	/* Track created and exited threads */
-	bool traced_lwps[__arraycount(t)];
+	struct lwp_event_count traced_lwps[__arraycount(t)] = {{0, 0}};
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
@@ -5541,8 +5541,6 @@ trace_threads(bool trace_create, bool tr
 	"without signal to be sent\n");
 	SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 
-	memset(traced_lwps, 0, sizeof(traced_lwps));
-
 	for (n = 0; n < (trace_create ? __arraycount(t) : 0); n++) {
 		DPRINTF("Before calling %s() for the child - expected stopped "
 		"SIGTRAP\n", TWAIT_FNAME);
@@ -5574,7 +5572,7 @@ trace_threads(bool trace_create, bool tr
 		lid = state.pe_lwp;
 		DPRINTF("Reported PTRACE_LWP_CREATE event with lid %d\n", lid);
 
-		traced_lwps[lid - 1] = true;
+		*FIND_EVENT_COUNT(traced_lwps, lid) += 1;
 
 		DPRINTF("Before resuming the child process where it left off "
 		"and without signal to be sent\n");
@@ -5613,8 +5611,9 @@ trace_threads(bool trace_create, bool tr
 		DPRINTF("Reported PTRACE_LWP_EXIT event with lid %d\n", lid);
 
 		if (trace_create) {
-			ATF_REQUIRE(traced_lwps[lid - 1] == true);
-			traced_lwps[lid - 1] = false;
+			int *count = FIND_EVENT_COUNT(traced_lwps, lid);
+			ATF_REQUIRE_EQ(*count, 1);
+			*count = 0;
 		}
 
 		DPRINTF("Before resuming the child process where it left off "
@@ -7738,7 +7737,8 @@ ATF_TC_BODY(thread_concurrent_signals, t
 	const int sigval = SIGSTOP;
 	pid_t child, wpid;
 	int status;
-	int signal_counts[THREAD_CONCURRENT_SIGNALS_NUM] = {0};
+	struct lwp_event_count signal_counts[THREAD_CONCURRENT_SIGNALS_NUM]
+	= {{0, 0}};
 	unsigned int i;
 
 	DPRINTF("Before forking process PID=%d\n", getpid());
@@ -7816,21 +7816,16 @@ ATF_TC_BODY(thread_concurrent_signals, t
 		"lwp=%d, expected %d, got %d", info.psi_lwpid,
 		expected_sig, WSTOPSIG(status));
 
-		/* We assume that LWPs will be given successive numbers starting
-		 * from 2.
-		 */
-		ATF_REQUIRE(info.psi_lwpid >= 2);
-		ATF_REQUIRE((unsigned int)info.psi_lwpid <
-		__arraycount(signal_counts)+2);
-		signal_counts[info.psi_lwpid-2]++;
+		*FIND_EVENT_COUNT(signal_counts, info.psi_lwpid) += 1;
 
 		DPRINTF("Before resuming the child process\n");
 		SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
 	}
 
 	for (i = 0; i < __arraycount(signal_counts); i++)
-		ATF_CHECK_EQ_MSG(signal_counts[i], 1, "signal_counts[%d]=%d",
-		i, signal_counts[i]);
+		ATF_CHECK_EQ_MSG(signal_counts[i].lec_count, 1,
+		"signal_counts[%d].lec_count=%d; lec_lwp=%d",
+		i, signal_counts[i].lec_count, signal_counts[i].lec_lwp);
 
 	validate_status_exited(status, exitval);
 }

Index: src/tests/lib/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.17 src/tests/lib/libc/sys/t_ptrace_wait.h:1.18
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.17	Sat May 25 03:22:53 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.h	Tue Nov 12 18:18:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.h,v 1.17 2019/05/25 03:22:53 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.h,v 1.18 2019/11/12 18:18:04 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -674,6 +674,30 @@ trigger_bus(void)
 	*p = 'a';
 }
 
+struct lwp_event_count {
+	lwpid_t lec_lwp;
+	int lec_count;
+};
+
+static int *
+find_event_count(struct lwp_event_count list[], lwpid_t lwp, size_t max_lwps)
+{
+	size_t i;
+
+	for (i = 0; i < max_lwps; i++) {
+		if

CVS commit: src/tests/lib/libc/sys

2019-10-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Oct 21 18:36:08 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove preprocessor switch TEST_LWP_ENABLED in t_ptrace_wait*

LWP tests are now enabled always and confirmed to be stable.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.139 src/tests/lib/libc/sys/t_ptrace_wait.c:1.140
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.139	Mon Oct 21 18:31:40 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Mon Oct 21 18:36:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.139 2019/10/21 18:31:40 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.140 2019/10/21 18:36:08 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.139 2019/10/21 18:31:40 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.140 2019/10/21 18:36:08 kamil Exp $");
 
 #include 
 #include 
@@ -121,10 +121,6 @@ static int debug = 0;
 	printf("%s() %s:%d " a, __func__, __FILE__, __LINE__,  ##__VA_ARGS__); \
 while (/*CONSTCOND*/0)
 
-#ifndef TEST_LWP_ENABLED
-#define TEST_LWP_ENABLED 1
-#endif
-
 /// 
 
 static void
@@ -5484,11 +5480,6 @@ trace_threads(bool trace_create, bool tr
 	/* Track created and exited threads */
 	bool traced_lwps[__arraycount(t)];
 
-#if !TEST_LWP_ENABLED
-	if (trace_create || trace_exit)
-		atf_tc_skip("PR kern/51995");
-#endif
-
 	DPRINTF("Before forking process PID=%d\n", getpid());
 	SYSCALL_REQUIRE((child = fork()) != -1);
 	if (child == 0) {



CVS commit: src/tests/lib/libc/sys

2019-10-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Oct 21 18:36:08 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove preprocessor switch TEST_LWP_ENABLED in t_ptrace_wait*

LWP tests are now enabled always and confirmed to be stable.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys

2019-10-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Oct 21 18:31:40 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove preprocessor switch TEST_VFORK_ENABLED in t_ptrace_wait*

vfork(2) tests are now enabled always and confirmed to be stable.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys

2019-10-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Oct 21 18:31:40 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Remove preprocessor switch TEST_VFORK_ENABLED in t_ptrace_wait*

vfork(2) tests are now enabled always and confirmed to be stable.


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/tests/lib/libc/sys/t_ptrace_wait.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/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.138 src/tests/lib/libc/sys/t_ptrace_wait.c:1.139
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.138	Mon Oct 21 17:07:00 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Mon Oct 21 18:31:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.138 2019/10/21 17:07:00 mgorny Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.139 2019/10/21 18:31:40 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.138 2019/10/21 17:07:00 mgorny Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.139 2019/10/21 18:31:40 kamil Exp $");
 
 #include 
 #include 
@@ -121,10 +121,6 @@ static int debug = 0;
 	printf("%s() %s:%d " a, __func__, __FILE__, __LINE__,  ##__VA_ARGS__); \
 while (/*CONSTCOND*/0)
 
-#ifndef TEST_VFORK_ENABLED
-#define TEST_VFORK_ENABLED 1
-#endif
-
 #ifndef TEST_LWP_ENABLED
 #define TEST_LWP_ENABLED 1
 #endif
@@ -3269,7 +3265,6 @@ FORK_TEST(fork15, "fork", true, false, t
 FORK_TEST(fork16, "fork", true, true, true, true)
 #endif
 
-#if TEST_VFORK_ENABLED
 FORK_TEST(vfork1, "vfork", false, false, false, false)
 #if defined(TWAIT_HAVE_PID)
 FORK_TEST(vfork2, "vfork", false, true, false, false)
@@ -3294,7 +3289,6 @@ FORK_TEST(vfork14, "vfork", true, true, 
 FORK_TEST(vfork15, "vfork", true, false, true, true)
 FORK_TEST(vfork16, "vfork", true, true, true, true)
 #endif
-#endif
 
 FORK_TEST(posix_spawn1, "spawn", false, false, false, false)
 FORK_TEST(posix_spawn2, "spawn", false, true, false, false)
@@ -3497,22 +3491,17 @@ ATF_TC_BODY(name, tc)			\
 
 FORK_DETACH_FORKER(posix_spawn_detach_spawner, "spawn", false)
 FORK_DETACH_FORKER(fork_detach_forker, "fork", false)
-#if TEST_VFORK_ENABLED
 FORK_DETACH_FORKER(vfork_detach_vforker, "vfork", false)
 FORK_DETACH_FORKER(vfork_detach_vforkerdone, "vforkdone", false)
-#endif
 
 FORK_DETACH_FORKER(posix_spawn_kill_spawner, "spawn", true)
 FORK_DETACH_FORKER(fork_kill_forker, "fork", true)
-#if TEST_VFORK_ENABLED
 FORK_DETACH_FORKER(vfork_kill_vforker, "vfork", true)
 FORK_DETACH_FORKER(vfork_kill_vforkerdone, "vforkdone", true)
 #endif
-#endif
 
 /// 
 
-#if TEST_VFORK_ENABLED
 static void
 traceme_vfork_fork_body(pid_t (*fn)(void))
 {
@@ -3571,7 +3560,6 @@ ATF_TC_BODY(name, tc)			\
 
 TRACEME_VFORK_FORK_TEST(traceme_vfork_fork, fork)
 TRACEME_VFORK_FORK_TEST(traceme_vfork_vfork, vfork)
-#endif
 
 /// 
 
@@ -6126,13 +6114,11 @@ FORK2_TEST(posix_spawn_singalmasked, "sp
 FORK2_TEST(posix_spawn_singalignored, "spawn", false, true)
 FORK2_TEST(fork_singalmasked, "fork", true, false)
 FORK2_TEST(fork_singalignored, "fork", false, true)
-#if TEST_VFORK_ENABLED
 FORK2_TEST(vfork_singalmasked, "vfork", true, false)
 FORK2_TEST(vfork_singalignored, "vfork", false, true)
 FORK2_TEST(vforkdone_singalmasked, "vforkdone", true, false)
 FORK2_TEST(vforkdone_singalignored, "vforkdone", false, true)
 #endif
-#endif
 
 /// 
 
@@ -6991,7 +6977,6 @@ CLONE_TEST(clone_files8, CLONE_FILES, tr
 //CLONE_TEST(clone_sighand8, CLONE_SIGHAND, true, true, true)
 #endif
 
-#if TEST_VFORK_ENABLED
 CLONE_TEST(clone_vfork1, CLONE_VFORK, false, false, false)
 #if defined(TWAIT_HAVE_PID)
 CLONE_TEST(clone_vfork2, CLONE_VFORK, true, false, false)
@@ -7004,7 +6989,6 @@ CLONE_TEST(clone_vfork6, CLONE_VFORK, tr
 CLONE_TEST(clone_vfork7, CLONE_VFORK, false, true, true)
 CLONE_TEST(clone_vfork8, CLONE_VFORK, true, true, true)
 #endif
-#endif
 
 /// 
 
@@ -7367,15 +7351,12 @@ CLONE_TEST2(clone_files_signalignored, C
 CLONE_TEST2(clone_files_signalmasked, CLONE_FILES, false, true)
 //CLONE_TEST2(clone_sighand_signalignored, CLONE_SIGHAND, true, false) // XXX
 //CLONE_TEST2(clone_sighand_signalmasked, CLONE_SIGHAND, false, true)  // XXX
-#if TEST_VFORK_ENABLED
 CLONE_TEST2(clone_vfork_signalignored, CLONE_VFORK, true, false)
 CLONE_TEST2(clone_vfork_signalmasked, CLONE_VFORK, false, true)
 #endif
-#endif
 
 /// 
 
-#if TEST_VFORK_ENABLED
 #if defined(TWAIT_HAVE_PID)
 static void
 traceme_vfork_clone_body(int flag

CVS commit: src/tests/lib/libc/sys

2019-10-13 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Oct 13 09:42:15 UTC 2019

Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Fix race in t_ptrace_wait* LWP tests

Increment the done variable under a mutex. This variable was updated
non-atomically and sometimes not reaching the expected treshold.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/tests/lib/libc/sys/t_ptrace_wait.c

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



  1   2   >