CVS commit: src/tests/kernel

2024-08-10 Thread Christoph Badura
Module Name:src
Committed By:   bad
Date:   Sat Aug 10 14:44:54 UTC 2024

Modified Files:
src/tests/kernel: t_unmount.c

Log Message:
tests/kernel/t_unmount.c: don't need rv any more

simplify as noticed by riastradh@.

NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_unmount.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/kernel/t_unmount.c
diff -u src/tests/kernel/t_unmount.c:1.1 src/tests/kernel/t_unmount.c:1.2
--- src/tests/kernel/t_unmount.c:1.1	Fri Aug  9 23:24:15 2024
+++ src/tests/kernel/t_unmount.c	Sat Aug 10 14:44:54 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unmount.c,v 1.1 2024/08/09 23:24:15 bad Exp $	*/
+/*	$NetBSD: t_unmount.c,v 1.2 2024/08/10 14:44:54 bad Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2024\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_unmount.c,v 1.1 2024/08/09 23:24:15 bad Exp $");
+__RCSID("$NetBSD: t_unmount.c,v 1.2 2024/08/10 14:44:54 bad Exp $");
 
 #include 
 #include 
@@ -61,7 +61,6 @@ ATF_TC_BODY(async, tc)
 	struct tmpfs_args args;
 	struct vnode *vp;
 	extern struct vnode *rumpns_rootvnode;
-	int rv;
 
 	RZ(rump_init());
 
@@ -80,9 +79,7 @@ ATF_TC_BODY(async, tc)
 	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
 
 	/* get vnode of MP, unlocked */
-	rv = rump_pub_namei(RUMP_NAMEI_LOOKUP, 0,
-	MP, NULL, &vp, NULL);
-	ATF_REQUIRE_MSG((rv == 0), "rump_pub_namei failed: %s", strerror(rv));
+	RZ(rump_pub_namei(RUMP_NAMEI_LOOKUP, 0, MP, NULL, &vp, NULL));
 
 	/* make sure we didn't just get the root vnode */
 	ATF_REQUIRE_MSG((rumpns_rootvnode != vp), "drat! got the root vnode");



CVS commit: src/tests/kernel

2024-08-10 Thread Christoph Badura
Module Name:src
Committed By:   bad
Date:   Sat Aug 10 14:44:54 UTC 2024

Modified Files:
src/tests/kernel: t_unmount.c

Log Message:
tests/kernel/t_unmount.c: don't need rv any more

simplify as noticed by riastradh@.

NFC.


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

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



CVS commit: src/tests/kernel/kqueue

2024-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jul 10 22:03:59 UTC 2024

Modified Files:
src/tests/kernel/kqueue: t_sig.c

Log Message:
tests/kqueue: fix mismatch between '=' and '=='


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/t_sig.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/kernel/kqueue/t_sig.c
diff -u src/tests/kernel/kqueue/t_sig.c:1.4 src/tests/kernel/kqueue/t_sig.c:1.5
--- src/tests/kernel/kqueue/t_sig.c:1.4	Sun Oct 10 18:11:31 2021
+++ src/tests/kernel/kqueue/t_sig.c	Wed Jul 10 22:03:59 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sig.c,v 1.4 2021/10/10 18:11:31 thorpej Exp $ */
+/* $NetBSD: t_sig.c,v 1.5 2024/07/10 22:03:59 rillig Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008, 2021 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sig.c,v 1.4 2021/10/10 18:11:31 thorpej Exp $");
+__RCSID("$NetBSD: t_sig.c,v 1.5 2024/07/10 22:03:59 rillig Exp $");
 
 #include 
 #include 
@@ -199,7 +199,7 @@ ATF_TC_BODY(sig_and_proc, tc)
 	ATF_REQUIRE(kevent(kq, NULL, 0, events, 1, NULL) == 1);
 	ATF_REQUIRE(events[0].filter == EVFILT_PROC);
 	ATF_REQUIRE(events[0].ident == (uintptr_t)pid);
-	ATF_REQUIRE(events[0].fflags = NOTE_EXIT);
+	ATF_REQUIRE(events[0].fflags == NOTE_EXIT);
 }
 
 ATF_TP_ADD_TCS(tp)



CVS commit: src/tests/kernel/kqueue

2024-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jul 10 22:03:59 UTC 2024

Modified Files:
src/tests/kernel/kqueue: t_sig.c

Log Message:
tests/kqueue: fix mismatch between '=' and '=='


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/t_sig.c

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



CVS commit: src/tests/kernel

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

Modified Files:
src/tests/kernel: h_segv.c

Log Message:
tests/kernel/h_segv: Disable SIGFPE test on RISC-V.

No floating-point exception traps on RISC-V.

Also don't pass the result of divide-by-zero converted to integer to
usleep.  Although the floating-point result of divide-by-zero is
well-defined by IEEE 754 (+/-infinity), the outcome of C conversion
to integer is not.  And while on some architectures this might return
zero, on RISC-V it looks like it'll return all bits set.  And as of
PR 58184, usleep now honours sleeps longer than 1sec, which means
this will be waiting at least two billion microseconds, or about half
an hour...

So instead, just write the result to a volatile variable.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/kernel/h_segv.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/kernel/h_segv.c
diff -u src/tests/kernel/h_segv.c:1.14 src/tests/kernel/h_segv.c:1.15
--- src/tests/kernel/h_segv.c:1.14	Thu Apr 25 19:37:09 2019
+++ src/tests/kernel/h_segv.c	Tue May 14 15:54:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $	*/
+/*	$NetBSD: h_segv.c,v 1.15 2024/05/14 15:54:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $");
+__RCSID("$NetBSD: h_segv.c,v 1.15 2024/05/14 15:54:16 riastradh Exp $");
 
 #define	__TEST_FENV
 
@@ -121,10 +121,15 @@ check_fpe(void)
 		printf("FPU does not implement traps on FP exceptions\n");
 		exit(EXIT_FAILURE);
 	}
+#elif defined __riscv__
+	printf("RISC-V does not support floating-point exception traps\n");
+	exit(EXIT_FAILURE);
 #endif
 	exit(EXIT_SUCCESS);
 }
 
+volatile int ignore_result;
+
 static void
 trigger_fpe(void)
 {
@@ -135,7 +140,13 @@ trigger_fpe(void)
 	feenableexcept(FE_ALL_EXCEPT);
 #endif
 
-	usleep((int)(a/b));
+	/*
+	 * Try to trigger SIGFPE either by dividing by zero (which is
+	 * defined to raise FE_DIVBYZERO, but may just return infinity
+	 * without trapping the exception) or by converting infinity to
+	 * integer.
+	 */
+	ignore_result = (int)(a/b);
 }
 
 static void



CVS commit: src/tests/kernel

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

Modified Files:
src/tests/kernel: h_segv.c

Log Message:
tests/kernel/h_segv: Disable SIGFPE test on RISC-V.

No floating-point exception traps on RISC-V.

Also don't pass the result of divide-by-zero converted to integer to
usleep.  Although the floating-point result of divide-by-zero is
well-defined by IEEE 754 (+/-infinity), the outcome of C conversion
to integer is not.  And while on some architectures this might return
zero, on RISC-V it looks like it'll return all bits set.  And as of
PR 58184, usleep now honours sleeps longer than 1sec, which means
this will be waiting at least two billion microseconds, or about half
an hour...

So instead, just write the result to a volatile variable.


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

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



CVS commit: src/tests/kernel

2023-11-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov 24 16:36:23 UTC 2023

Modified Files:
src/tests/kernel: t_rnd.c

Log Message:
t_rnd: Nix trailing whitespace.

No functional change intended.


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

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



CVS commit: src/tests/kernel

2023-11-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov 24 16:36:23 UTC 2023

Modified Files:
src/tests/kernel: t_rnd.c

Log Message:
t_rnd: Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/kernel/t_rnd.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/kernel/t_rnd.c
diff -u src/tests/kernel/t_rnd.c:1.12 src/tests/kernel/t_rnd.c:1.13
--- src/tests/kernel/t_rnd.c:1.12	Fri Nov 24 16:35:51 2023
+++ src/tests/kernel/t_rnd.c	Fri Nov 24 16:36:23 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_rnd.c,v 1.12 2023/11/24 16:35:51 riastradh Exp $	*/
+/*	$NetBSD: t_rnd.c,v 1.13 2023/11/24 16:36:23 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_rnd.c,v 1.12 2023/11/24 16:35:51 riastradh Exp $");
+__RCSID("$NetBSD: t_rnd.c,v 1.13 2023/11/24 16:36:23 riastradh Exp $");
 
 #include 
 #include 
@@ -81,7 +81,7 @@ ATF_TC_BODY(RNDADDDATA2, tc)
 	fd = rump_sys_open("/dev/random", O_RDWR, 0);
 	if (fd == -1)
 		atf_tc_fail_errno("cannot open /dev/random");
-		
+
 	rd.entropy = 1;
 	rd.len = -1;
 	ATF_REQUIRE_ERRNO(EINVAL, rump_sys_ioctl(fd, RNDADDDATA, &rd) == -1);



CVS commit: src/tests/kernel

2023-11-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov 24 16:35:51 UTC 2023

Modified Files:
src/tests/kernel: t_rnd.c

Log Message:
t_rnd: Fix misuse of RZ.

Not likely to matter, but in the unlikely event that rump_sys_close
fails, it will return -1 and set errno as RL expects, not return the
error code as RZ expects.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/kernel/t_rnd.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/kernel/t_rnd.c
diff -u src/tests/kernel/t_rnd.c:1.11 src/tests/kernel/t_rnd.c:1.12
--- src/tests/kernel/t_rnd.c:1.11	Sun Apr 16 18:24:23 2017
+++ src/tests/kernel/t_rnd.c	Fri Nov 24 16:35:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_rnd.c,v 1.11 2017/04/16 18:24:23 riastradh Exp $	*/
+/*	$NetBSD: t_rnd.c,v 1.12 2023/11/24 16:35:51 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_rnd.c,v 1.11 2017/04/16 18:24:23 riastradh Exp $");
+__RCSID("$NetBSD: t_rnd.c,v 1.12 2023/11/24 16:35:51 riastradh Exp $");
 
 #include 
 #include 
@@ -106,7 +106,7 @@ ATF_TC_BODY(read_random, tc)
 		alarm(2);
 		RL(fd = rump_sys_open("/dev/random", RUMP_O_RDONLY));
 		RL(rump_sys_read(fd, buf, sizeof(buf)));
-		RZ(rump_sys_close(fd));
+		RL(rump_sys_close(fd));
 	}
 }
 



CVS commit: src/tests/kernel

2023-11-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov 24 16:35:51 UTC 2023

Modified Files:
src/tests/kernel: t_rnd.c

Log Message:
t_rnd: Fix misuse of RZ.

Not likely to matter, but in the unlikely event that rump_sys_close
fails, it will return -1 and set errno as RL expects, not return the
error code as RZ expects.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/kernel/t_rnd.c

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



CVS commit: src/tests/kernel

2023-11-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 18 19:46:55 UTC 2023

Modified Files:
src/tests/kernel: t_fdrestart.c

Log Message:
t_fdrestart: Mark some tests no longer xfail.

Backing out ad's changes last month seemed to fix the symptoms
(although I'm pretty sure this logic is still broken, more to come).

PR kern/57659


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_fdrestart.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/kernel/t_fdrestart.c
diff -u src/tests/kernel/t_fdrestart.c:1.3 src/tests/kernel/t_fdrestart.c:1.4
--- src/tests/kernel/t_fdrestart.c:1.3	Sun Oct 15 15:18:17 2023
+++ src/tests/kernel/t_fdrestart.c	Sat Nov 18 19:46:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fdrestart.c,v 1.3 2023/10/15 15:18:17 riastradh Exp $	*/
+/*	$NetBSD: t_fdrestart.c,v 1.4 2023/11/18 19:46:55 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #define	_KMEMUSER		/* ERESTART */
 
 #include 
-__RCSID("$NetBSD: t_fdrestart.c,v 1.3 2023/10/15 15:18:17 riastradh Exp $");
+__RCSID("$NetBSD: t_fdrestart.c,v 1.4 2023/11/18 19:46:55 riastradh Exp $");
 
 #include 
 #include 
@@ -198,7 +198,6 @@ ATF_TC_BODY(pipe_read, tc)
 	memset(F, 0, sizeof(*F));
 	F->op = &doread;
 	F->fd = fd[0];
-	atf_tc_expect_fail("PR kern/57659");
 	testfdrestart(F);
 }
 
@@ -240,7 +239,6 @@ ATF_TC_BODY(socketpair_read, tc)
 	memset(F, 0, sizeof(*F));
 	F->op = &doread;
 	F->fd = fd[0];
-	atf_tc_expect_fail("PR kern/57659");
 	testfdrestart(F);
 }
 
@@ -261,7 +259,6 @@ ATF_TC_BODY(socketpair_write, tc)
 	memset(F, 0, sizeof(*F));
 	F->op = &dowrite;
 	F->fd = fd[0];
-	atf_tc_expect_fail("PR kern/57659");
 	testfdrestart(F);
 }
 



CVS commit: src/tests/kernel

2023-11-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov 18 19:46:55 UTC 2023

Modified Files:
src/tests/kernel: t_fdrestart.c

Log Message:
t_fdrestart: Mark some tests no longer xfail.

Backing out ad's changes last month seemed to fix the symptoms
(although I'm pretty sure this logic is still broken, more to come).

PR kern/57659


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

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



CVS commit: src/tests/kernel

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 15:18:17 UTC 2023

Modified Files:
src/tests/kernel: t_fdrestart.c

Log Message:
t_fdrestart: Rework this to be a little more robust.

For the write test, need to make sure the pipe's buffer is full first
before the write that blocks, so that it doesn't return partial
progress rather than ERESTART if woken.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_fdrestart.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/kernel/t_fdrestart.c
diff -u src/tests/kernel/t_fdrestart.c:1.2 src/tests/kernel/t_fdrestart.c:1.3
--- src/tests/kernel/t_fdrestart.c:1.2	Sun Oct 15 14:30:51 2023
+++ src/tests/kernel/t_fdrestart.c	Sun Oct 15 15:18:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fdrestart.c,v 1.2 2023/10/15 14:30:51 riastradh Exp $	*/
+/*	$NetBSD: t_fdrestart.c,v 1.3 2023/10/15 15:18:17 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,8 +29,9 @@
 #define	_KMEMUSER		/* ERESTART */
 
 #include 
-__RCSID("$NetBSD: t_fdrestart.c,v 1.2 2023/10/15 14:30:51 riastradh Exp $");
+__RCSID("$NetBSD: t_fdrestart.c,v 1.3 2023/10/15 15:18:17 riastradh Exp $");
 
+#include 
 #include 
 #include 
 
@@ -51,18 +52,47 @@ struct fdrestart {
 };
 
 static void
+waitforbarrier(struct fdrestart *F, const char *caller)
+{
+	int error;
+
+	error = pthread_barrier_wait(&F->barrier);
+	switch (error) {
+	case 0:
+	case PTHREAD_BARRIER_SERIAL_THREAD:
+		break;
+	default:
+		atf_tc_fail("%s: pthread_barrier_wait: %d, %s", caller, error,
+		strerror(error));
+	}
+}
+
+static void
 doread(struct fdrestart *F)
 {
 	char c;
 	ssize_t nread;
 	int error;
 
+	/*
+	 * Wait for the other thread to be ready.
+	 */
+	waitforbarrier(F, "reader");
+
+	/*
+	 * Start a read.  This should block, and then, when the other
+	 * thread closes the fd, should be woken to fail with ERESTART.
+	 */
 	nread = rump_sys_read(F->fd, &c, sizeof(c));
 	ATF_REQUIRE_EQ_MSG(nread, -1, "nread=%zd", nread);
 	error = errno;
 	ATF_REQUIRE_EQ_MSG(error, ERESTART, "errno=%d (%s)", error,
 	strerror(error));
 
+	/*
+	 * Now further attempts at I/O should fail with EBADF because
+	 * the fd has been closed.
+	 */
 	nread = rump_sys_read(F->fd, &c, sizeof(c));
 	ATF_REQUIRE_EQ_MSG(nread, -1, "nread=%zd", nread);
 	error = errno;
@@ -77,14 +107,38 @@ dowrite(struct fdrestart *F)
 	ssize_t nwrit;
 	int error;
 
+	/*
+	 * Make sure the pipe's buffer is full first.
+	 */
+	for (;;) {
+		int nspace;
+
+		RL(rump_sys_ioctl(F->fd, FIONSPACE, &nspace));
+		ATF_REQUIRE_MSG(nspace >= 0, "nspace=%d", nspace);
+		if (nspace == 0)
+			break;
+		RL(rump_sys_write(F->fd, buf, (size_t)nspace));
+	}
+
+	/*
+	 * Wait for the other thread to be ready.
+	 */
+	waitforbarrier(F, "writer");
+
+	/*
+	 * Start a write.  This should block, and then, when the other
+	 * thread closes the fd, should be woken to fail with ERESTART.
+	 */
 	nwrit = rump_sys_write(F->fd, buf, sizeof(buf));
-	if (nwrit != -1)	/* filled buffer, try again */
-		nwrit = rump_sys_write(F->fd, buf, sizeof(buf));
 	ATF_REQUIRE_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit);
 	error = errno;
 	ATF_REQUIRE_EQ_MSG(error, ERESTART, "errno=%d (%s)", error,
 	strerror(error));
 
+	/*
+	 * Now further attempts at I/O should fail with EBADF because
+	 * the fd has been closed.
+	 */
 	nwrit = rump_sys_write(F->fd, buf, sizeof(buf));
 	ATF_REQUIRE_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit);
 	error = errno;
@@ -92,28 +146,11 @@ dowrite(struct fdrestart *F)
 	strerror(error));
 }
 
-static void
-waitforbarrier(struct fdrestart *F, const char *caller)
-{
-	int error;
-
-	error = pthread_barrier_wait(&F->barrier);
-	switch (error) {
-	case 0:
-	case PTHREAD_BARRIER_SERIAL_THREAD:
-		break;
-	default:
-		atf_tc_fail("%s: pthread_barrier_wait: %d, %s", caller, error,
-		strerror(error));
-	}
-}
-
 static void *
 doit(void *cookie)
 {
 	struct fdrestart *F = cookie;
 
-	waitforbarrier(F, "user");
 	(*F->op)(F);
 
 	return NULL;
@@ -138,9 +175,10 @@ testfdrestart(struct fdrestart *F)
 	RZ(pthread_create(&t, NULL, &doit, F));
 	waitforbarrier(F, "closer");	/* wait for thread to start */
 	(void)sleep(1);			/* wait for op to start */
-	(void)alarm(1);
-	RL(rump_sys_close(F->fd));
-	RZ(pthread_join(t, NULL));
+	(void)alarm(1);			/* set a deadline */
+	RL(rump_sys_close(F->fd));	/* wake op in other thread */
+	RZ(pthread_join(t, NULL));	/* wait for op to wake and fail */
+	(void)alarm(0);			/* clear the deadline */
 }
 
 ATF_TC(pipe_read);



CVS commit: src/tests/kernel

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 15:18:17 UTC 2023

Modified Files:
src/tests/kernel: t_fdrestart.c

Log Message:
t_fdrestart: Rework this to be a little more robust.

For the write test, need to make sure the pipe's buffer is full first
before the write that blocks, so that it doesn't return partial
progress rather than ERESTART if woken.


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

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



CVS commit: src/tests/kernel

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 14:30:52 UTC 2023

Modified Files:
src/tests/kernel: t_fdrestart.c

Log Message:
t_fdrestart: Verify rump_sys_write failed second time around.

PR kern/57659


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fdrestart.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/kernel/t_fdrestart.c
diff -u src/tests/kernel/t_fdrestart.c:1.1 src/tests/kernel/t_fdrestart.c:1.2
--- src/tests/kernel/t_fdrestart.c:1.1	Sun Oct 15 13:22:52 2023
+++ src/tests/kernel/t_fdrestart.c	Sun Oct 15 14:30:51 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fdrestart.c,v 1.1 2023/10/15 13:22:52 riastradh Exp $	*/
+/*	$NetBSD: t_fdrestart.c,v 1.2 2023/10/15 14:30:51 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #define	_KMEMUSER		/* ERESTART */
 
 #include 
-__RCSID("$NetBSD: t_fdrestart.c,v 1.1 2023/10/15 13:22:52 riastradh Exp $");
+__RCSID("$NetBSD: t_fdrestart.c,v 1.2 2023/10/15 14:30:51 riastradh Exp $");
 
 #include 
 #include 
@@ -86,6 +86,7 @@ dowrite(struct fdrestart *F)
 	strerror(error));
 
 	nwrit = rump_sys_write(F->fd, buf, sizeof(buf));
+	ATF_REQUIRE_EQ_MSG(nwrit, -1, "nwrit=%zd", nwrit);
 	error = errno;
 	ATF_REQUIRE_EQ_MSG(error, EBADF, "errno=%d (%s)", error,
 	strerror(error));



CVS commit: src/tests/kernel

2023-10-15 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 15 14:30:52 UTC 2023

Modified Files:
src/tests/kernel: t_fdrestart.c

Log Message:
t_fdrestart: Verify rump_sys_write failed second time around.

PR kern/57659


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

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



CVS commit: src/tests/kernel

2023-08-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug  5 08:05:16 UTC 2023

Modified Files:
src/tests/kernel: t_fcntl.c

Log Message:
memfd(2): Run all tests; don't stop after the first failure.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_fcntl.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/kernel/t_fcntl.c
diff -u src/tests/kernel/t_fcntl.c:1.3 src/tests/kernel/t_fcntl.c:1.4
--- src/tests/kernel/t_fcntl.c:1.3	Sat Jul 29 12:16:34 2023
+++ src/tests/kernel/t_fcntl.c	Sat Aug  5 08:05:16 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fcntl.c,v 1.3 2023/07/29 12:16:34 christos Exp $	*/
+/*	$NetBSD: t_fcntl.c,v 1.4 2023/08/05 08:05:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -108,14 +108,18 @@ ATF_TC_BODY(getpath_memfd, tc)
 
 	for (size_t i = 0; i < __arraycount(memfd_names); i++) {
 		fd = memfd_create(memfd_names[i].bare, 0);
-		ATF_REQUIRE_MSG(fd != -1, "Failed to create memfd (%s)",
+		ATF_CHECK_MSG(fd != -1, "Failed to create memfd (%s)",
 		strerror(errno));
+		if (fd == -1)
+			continue;
 		rv = fcntl(fd, F_GETPATH, path);
-		ATF_REQUIRE_MSG(rv != -1, "Can't get path `%s' (%s)",
+		ATF_CHECK_MSG(rv != -1, "Can't get path `%s' (%s)",
 		memfd_names[i].bare, strerror(errno));
-		ATF_REQUIRE_MSG(strcmp(memfd_names[i].prefixed, path) == 0,
+		if (rv == -1)
+			goto next;
+		ATF_CHECK_MSG(strcmp(memfd_names[i].prefixed, path) == 0,
 		"Bad name `%s' != `%s'", path, memfd_names[i].prefixed);
-		close(fd);
+next:		close(fd);
 	}
 }
 



CVS commit: src/tests/kernel

2023-08-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug  5 08:05:16 UTC 2023

Modified Files:
src/tests/kernel: t_fcntl.c

Log Message:
memfd(2): Run all tests; don't stop after the first failure.


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

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



CVS commit: src/tests/kernel

2023-07-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Jul 29 16:24:36 UTC 2023

Modified Files:
src/tests/kernel: t_memfd_create.c

Log Message:
t_memfd_create: Fix printf-like format by using %zu for size_t, and
%jd for off_t with cast to intmax_t, respectively.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_memfd_create.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/kernel/t_memfd_create.c
diff -u src/tests/kernel/t_memfd_create.c:1.1 src/tests/kernel/t_memfd_create.c:1.2
--- src/tests/kernel/t_memfd_create.c:1.1	Sat Jul 29 12:16:34 2023
+++ src/tests/kernel/t_memfd_create.c	Sat Jul 29 16:24:35 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_memfd_create.c,v 1.1 2023/07/29 12:16:34 christos Exp $	*/
+/*	$NetBSD: t_memfd_create.c,v 1.2 2023/07/29 16:24:35 rin Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_memfd_create.c,v 1.1 2023/07/29 12:16:34 christos Exp $");
+__RCSID("$NetBSD: t_memfd_create.c,v 1.2 2023/07/29 16:24:35 rin Exp $");
 
 #include 
 #include 
@@ -106,7 +106,7 @@ ATF_TC_BODY(read_write, tc)
 	RL(write(fd, write_buf, sizeof(write_buf)));
 	offset = lseek(fd, 0, SEEK_CUR);
 	ATF_REQUIRE_EQ_MSG(offset, sizeof(write_buf),
-	"File offset not set after write (%ld != %ld)", offset,
+	"File offset not set after write (%jd != %zu)", (intmax_t)offset,
 	sizeof(write_buf));
 
 	RZ(lseek(fd, 0, SEEK_SET));
@@ -114,7 +114,7 @@ ATF_TC_BODY(read_write, tc)
 	RL(read(fd, read_buf, sizeof(read_buf)));
 	offset = lseek(fd, 0, SEEK_CUR);
 	ATF_REQUIRE_EQ_MSG(offset, sizeof(read_buf),
-	"File offset not set after read (%ld != %ld)", offset,
+	"File offset not set after read (%jd != %zu)", (intmax_t)offset,
 	sizeof(read_buf));
 
 	for (size_t i = 0; i < sizeof(read_buf); i++)
@@ -143,20 +143,20 @@ ATF_TC_BODY(truncate, tc)
 
 	RL(fstat(fd, &st));
 	ATF_REQUIRE_EQ_MSG(st.st_size, sizeof(write_buf),
-	"Write did not grow size to %ld (is %ld)", sizeof(write_buf),
-	st.st_size);
+	"Write did not grow size to %zu (is %jd)", sizeof(write_buf),
+	(intmax_t)st.st_size);
 
 	RL(ftruncate(fd, sizeof(write_buf)/2));
 	RL(fstat(fd, &st));
 	ATF_REQUIRE_EQ_MSG(st.st_size, sizeof(write_buf)/2,
-	"Truncate did not shrink size to %ld (is %ld)",
-	sizeof(write_buf)/2, st.st_size);
+	"Truncate did not shrink size to %zu (is %jd)",
+	sizeof(write_buf)/2, (intmax_t)st.st_size);
 
 	RL(ftruncate(fd, sizeof(read_buf)));
 	RL(fstat(fd, &st));
 	ATF_REQUIRE_EQ_MSG(st.st_size, sizeof(read_buf),
-	"Truncate did not grow size to %ld (is %ld)", sizeof(read_buf),
-	st.st_size);
+	"Truncate did not grow size to %zu (is %jd)", sizeof(read_buf),
+	(intmax_t)st.st_size);
 
 	RZ(lseek(fd, 0, SEEK_SET));
 	RL(read(fd, read_buf, sizeof(read_buf)));



CVS commit: src/tests/kernel

2023-07-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Jul 29 16:24:36 UTC 2023

Modified Files:
src/tests/kernel: t_memfd_create.c

Log Message:
t_memfd_create: Fix printf-like format by using %zu for size_t, and
%jd for off_t with cast to intmax_t, respectively.


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

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



CVS commit: src/tests/kernel

2023-07-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Jul 18 06:37:55 UTC 2023

Modified Files:
src/tests/kernel: gen_t_subr_prf

Log Message:
provide more things needed by new subr_prf.c.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/kernel/gen_t_subr_prf

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

Modified files:

Index: src/tests/kernel/gen_t_subr_prf
diff -u src/tests/kernel/gen_t_subr_prf:1.8 src/tests/kernel/gen_t_subr_prf:1.9
--- src/tests/kernel/gen_t_subr_prf:1.8	Tue May 21 04:10:20 2019
+++ src/tests/kernel/gen_t_subr_prf	Tue Jul 18 06:37:55 2023
@@ -25,6 +25,16 @@ cat << _EOF > $2
 
 #define kmem_alloc(n, f)	malloc(n)
 
+#define kprintf_lock()		__nothing
+#define kprintf_unlock()	__nothing
+
+/* Arbitrary */
+#define TOCONS	1
+#define TOLOG	2
+
+#define kprintf_internal(f, i1, i2, i3, ...) \
+	printf(f, __VA_ARGS__)
+
 static int putchar(char c, int foo, void *b)
 {
 	return fputc(c, stderr);



CVS commit: src/tests/kernel

2023-07-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Jul 18 06:37:55 UTC 2023

Modified Files:
src/tests/kernel: gen_t_subr_prf

Log Message:
provide more things needed by new subr_prf.c.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/kernel/gen_t_subr_prf

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



CVS commit: src/tests/kernel

2023-05-04 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Fri May  5 01:27:18 UTC 2023

Modified Files:
src/tests/kernel: t_trapsignal.sh

Log Message:
t_trapsignal.sh: fix head() function definitions of test cases


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/t_trapsignal.sh

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

Modified files:

Index: src/tests/kernel/t_trapsignal.sh
diff -u src/tests/kernel/t_trapsignal.sh:1.5 src/tests/kernel/t_trapsignal.sh:1.6
--- src/tests/kernel/t_trapsignal.sh:1.5	Sat Jan 26 16:44:30 2019
+++ src/tests/kernel/t_trapsignal.sh	Fri May  5 01:27:18 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_trapsignal.sh,v 1.5 2019/01/26 16:44:30 martin Exp $
+# $NetBSD: t_trapsignal.sh,v 1.6 2023/05/05 01:27:18 gutteridge Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -33,7 +33,7 @@ HELPER=$(atf_get_srcdir)/h_segv
 # SIGSEGV
 
 atf_test_case segv_simple
-segv_simple()
+segv_simple_head()
 {
 	atf_set "descr" "Test unhandled SIGSEGV with the right exit code"
 }
@@ -44,7 +44,7 @@ segv_simple_body()
 }
 
 atf_test_case segv_handle
-segv_handle()
+segv_handle_head()
 {
 	atf_set "descr" "Test handled SIGSEGV traps call the signal handler"
 }
@@ -55,7 +55,7 @@ segv_handle_body()
 }
 
 atf_test_case segv_mask
-segv_mask()
+segv_mask_head()
 {
 	atf_set "descr" "Test that masking SIGSEGV get reset"
 }
@@ -66,7 +66,7 @@ segv_mask_body()
 }
 
 atf_test_case segv_handle_mask
-segv_handle_mask()
+segv_handle_mask_head()
 {
 	atf_set "descr" "Test handled and masked SIGSEGV traps get reset"
 }
@@ -77,7 +77,7 @@ segv_handle_mask_body()
 }
 
 atf_test_case segv_handle_recurse
-segv_handle_recurse()
+segv_handle_recurse_head()
 {
 	atf_set "descr" "Test that receiving SIGSEGV in the handler resets"
 }
@@ -89,7 +89,7 @@ segv_handle_recurse_body()
 }
 
 atf_test_case segv_ignore
-segv_ignore()
+segv_ignore_head()
 {
 	atf_set "descr" "Test ignored SIGSEGV trap with right exit code"
 }
@@ -103,7 +103,7 @@ segv_ignore_body()
 # SIGTRAP
 
 atf_test_case trap_simple
-trap_simple()
+trap_simple_head()
 {
 	atf_set "descr" "Test unhandled SIGTRAP with the right exit code"
 }
@@ -114,7 +114,7 @@ trap_simple_body()
 }
 
 atf_test_case trap_handle
-trap_handle()
+trap_handle_head()
 {
 	atf_set "descr" "Test handled SIGTRAP traps call the signal handler"
 }
@@ -125,7 +125,7 @@ trap_handle_body()
 }
 
 atf_test_case trap_mask
-trap_mask()
+trap_mask_head()
 {
 	atf_set "descr" "Test that masking the trapped SIGTRAP signal get reset"
 }
@@ -136,7 +136,7 @@ trap_mask_body()
 }
 
 atf_test_case trap_handle_mask
-trap_handle_mask()
+trap_handle_mask_head()
 {
 	atf_set "descr" "Test handled and masked SIGTRAP traps get reset"
 }
@@ -147,7 +147,7 @@ trap_handle_mask_body()
 }
 
 atf_test_case trap_handle_recurse
-trap_handle_recurse()
+trap_handle_recurse_head()
 {
 	atf_set "descr" "Test that receiving SIGTRAP in the handler resets"
 }
@@ -159,7 +159,7 @@ trap_handle_recurse_body()
 }
 
 atf_test_case trap_ignore
-trap_ignore()
+trap_ignore_head()
 {
 	atf_set "descr" "Test ignored trap with right exit code"
 }
@@ -185,7 +185,7 @@ fpe_available()
 }
 
 atf_test_case fpe_simple
-fpe_simple()
+fpe_simple_head()
 {
 	atf_set "descr" "Test unhandled SIGFPE with the right exit code"
 }
@@ -197,7 +197,7 @@ fpe_simple_body()
 }
 
 atf_test_case fpe_handle
-fpe_handle()
+fpe_handle_head()
 {
 	atf_set "descr" "Test handled SIGFPE traps call the signal handler"
 }
@@ -209,7 +209,7 @@ fpe_handle_body()
 }
 
 atf_test_case fpe_mask
-fpe_mask()
+fpe_mask_head()
 {
 	atf_set "descr" "Test that masking the trapped SIGFPE signal get reset"
 }
@@ -221,7 +221,7 @@ fpe_mask_body()
 }
 
 atf_test_case fpe_handle_mask
-fpe_handle_mask()
+fpe_handle_mask_head()
 {
 	atf_set "descr" "Test handled and masked SIGFPE traps get reset"
 }
@@ -233,7 +233,7 @@ fpe_handle_mask_body()
 }
 
 atf_test_case fpe_handle_recurse
-fpe_handle_recurse()
+fpe_handle_recurse_head()
 {
 	atf_set "descr" "Test that receiving SIGFPE in the handler resets"
 }
@@ -246,7 +246,7 @@ fpe_handle_recurse_body()
 }
 
 atf_test_case fpe_ignore
-fpe_ignore()
+fpe_ignore_head()
 {
 	atf_set "descr" "Test ignored trap with right exit code"
 }
@@ -261,7 +261,7 @@ fpe_ignore_body()
 # SIGBUS
 
 atf_test_case bus_simple
-bus_simple()
+bus_simple_head()
 {
 	atf_set "descr" "Test unhandled SIGBUS with the right exit code"
 }
@@ -272,7 +272,7 @@ bus_simple_body()
 }
 
 atf_test_case bus_handle
-bus_handle()
+bus_handle_head()
 {
 	atf_set "descr" "Test handled SIGBUS traps call the signal handler"
 }
@@ -283,7 +283,7 @@ bus_handle_body()
 }
 
 atf_test_case bus_mask
-bus_mask()
+bus_mask_head()
 {
 	atf_set "descr" "Test that masking the trapped SIGBUS signal get reset"
 }
@@ -294,7 +294,7 @@ bus_mask_body()
 }
 
 atf_test_case bus_handle_mask
-bus_handle_mask()
+bus_handle_mask_head()
 {
 	atf_set "descr" "Test handled and masked SIGBUS traps

CVS commit: src/tests/kernel

2023-05-04 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Fri May  5 01:27:18 UTC 2023

Modified Files:
src/tests/kernel: t_trapsignal.sh

Log Message:
t_trapsignal.sh: fix head() function definitions of test cases


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/t_trapsignal.sh

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



CVS commit: src/tests/kernel

2023-05-03 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Thu May  4 00:02:10 UTC 2023

Modified Files:
src/tests/kernel: t_fexecve.sh

Log Message:
t_fexecve.sh: fix head() function definitions of test cases


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fexecve.sh

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

Modified files:

Index: src/tests/kernel/t_fexecve.sh
diff -u src/tests/kernel/t_fexecve.sh:1.1 src/tests/kernel/t_fexecve.sh:1.2
--- src/tests/kernel/t_fexecve.sh:1.1	Sun Sep 15 16:53:58 2019
+++ src/tests/kernel/t_fexecve.sh	Thu May  4 00:02:10 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_fexecve.sh,v 1.1 2019/09/15 16:53:58 christos Exp $
+# $NetBSD: t_fexecve.sh,v 1.2 2023/05/04 00:02:10 gutteridge Exp $
 #
 # Copyright (c) 2019 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -31,7 +31,7 @@
 HELPER=$(atf_get_srcdir)/h_fexecve
 
 atf_test_case fexecve_elf
-fexecve_elf()
+fexecve_elf_head()
 {
 	atf_set "descr" "Test fexecve with ELF executables"
 }
@@ -50,7 +50,7 @@ EOF
 }
 
 atf_test_case fexecve_script
-fexecve_script()
+fexecve_script_head()
 {
 	atf_set "descr" "Test fexecve with a shell script"
 }



CVS commit: src/tests/kernel

2023-05-03 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Thu May  4 00:02:10 UTC 2023

Modified Files:
src/tests/kernel: t_fexecve.sh

Log Message:
t_fexecve.sh: fix head() function definitions of test cases


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fexecve.sh

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



CVS commit: src/tests/kernel

2023-04-22 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Sun Apr 23 00:46:46 UTC 2023

Modified Files:
src/tests/kernel: t_open_pr_57260.c

Log Message:
t_open_pr_57260.c: KNF a block (spaces to tabs)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_open_pr_57260.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/kernel/t_open_pr_57260.c
diff -u src/tests/kernel/t_open_pr_57260.c:1.1 src/tests/kernel/t_open_pr_57260.c:1.2
--- src/tests/kernel/t_open_pr_57260.c:1.1	Fri Apr 21 21:50:05 2023
+++ src/tests/kernel/t_open_pr_57260.c	Sun Apr 23 00:46:46 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_open_pr_57260.c,v 1.1 2023/04/21 21:50:05 gutteridge Exp $	*/
+/*	$NetBSD: t_open_pr_57260.c,v 1.2 2023/04/23 00:46:46 gutteridge Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_open_pr_57260.c,v 1.1 2023/04/21 21:50:05 gutteridge Exp $");
+__RCSID("$NetBSD: t_open_pr_57260.c,v 1.2 2023/04/23 00:46:46 gutteridge Exp $");
 
 #include 
 
@@ -49,12 +49,12 @@ static void
 on_alarm(int sig)
 {
 
-if (!alarmed) {
-alarmed = 1;
-alarm(1);
-} else {
-longjmp(env, 1);
-}
+	if (!alarmed) {
+		alarmed = 1;
+		alarm(1);
+	} else {
+		longjmp(env, 1);
+	}
 }
 
 ATF_TC(openrestartsignal);



CVS commit: src/tests/kernel

2023-04-22 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Sun Apr 23 00:46:46 UTC 2023

Modified Files:
src/tests/kernel: t_open_pr_57260.c

Log Message:
t_open_pr_57260.c: KNF a block (spaces to tabs)


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

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



CVS commit: src/tests/kernel

2023-04-03 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Apr  3 21:35:59 UTC 2023

Modified Files:
src/tests/kernel: t_magic_symlinks.sh

Log Message:
t_magic_symlinks.sh: fix line continuation in realpath head()

This wasn't noticed before because the name of the head() itself was
wrong, and was being ignored.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_magic_symlinks.sh

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

Modified files:

Index: src/tests/kernel/t_magic_symlinks.sh
diff -u src/tests/kernel/t_magic_symlinks.sh:1.3 src/tests/kernel/t_magic_symlinks.sh:1.4
--- src/tests/kernel/t_magic_symlinks.sh:1.3	Mon Apr  3 20:08:38 2023
+++ src/tests/kernel/t_magic_symlinks.sh	Mon Apr  3 21:35:59 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_magic_symlinks.sh,v 1.3 2023/04/03 20:08:38 gutteridge Exp $
+# $NetBSD: t_magic_symlinks.sh,v 1.4 2023/04/03 21:35:59 gutteridge Exp $
 #
 # Copyright (c) 2020 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -221,7 +221,7 @@ gid_cleanup() {
 atf_test_case realpath cleanup
 realpath_head() {
 	atf_set "require.user" "root"
-	atf_set "descr" "Check that realpath(1) agrees with the "
+	atf_set "descr" "Check that realpath(1) agrees with the " \
 		"kernel on magic symlink(7)'s (PR lib/55361)"
 }
 



CVS commit: src/tests/kernel

2023-04-03 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Apr  3 21:35:59 UTC 2023

Modified Files:
src/tests/kernel: t_magic_symlinks.sh

Log Message:
t_magic_symlinks.sh: fix line continuation in realpath head()

This wasn't noticed before because the name of the head() itself was
wrong, and was being ignored.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_magic_symlinks.sh

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



CVS commit: src/tests/kernel

2023-04-03 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Apr  3 20:08:38 UTC 2023

Modified Files:
src/tests/kernel: t_magic_symlinks.sh

Log Message:
t_magic_symlinks.sh: fix naming of head() of realpath test case

Addresses part of PR kern/57319 from Jim Spath.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_magic_symlinks.sh

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



CVS commit: src/tests/kernel

2023-04-03 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Apr  3 20:08:38 UTC 2023

Modified Files:
src/tests/kernel: t_magic_symlinks.sh

Log Message:
t_magic_symlinks.sh: fix naming of head() of realpath test case

Addresses part of PR kern/57319 from Jim Spath.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_magic_symlinks.sh

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

Modified files:

Index: src/tests/kernel/t_magic_symlinks.sh
diff -u src/tests/kernel/t_magic_symlinks.sh:1.2 src/tests/kernel/t_magic_symlinks.sh:1.3
--- src/tests/kernel/t_magic_symlinks.sh:1.2	Thu Dec  9 06:38:23 2021
+++ src/tests/kernel/t_magic_symlinks.sh	Mon Apr  3 20:08:38 2023
@@ -1,4 +1,4 @@
-# $NetBSD: t_magic_symlinks.sh,v 1.2 2021/12/09 06:38:23 rillig Exp $
+# $NetBSD: t_magic_symlinks.sh,v 1.3 2023/04/03 20:08:38 gutteridge Exp $
 #
 # Copyright (c) 2020 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -219,7 +219,7 @@ gid_cleanup() {
 # realpath(1)
 #
 atf_test_case realpath cleanup
-nointerpreter_head() {
+realpath_head() {
 	atf_set "require.user" "root"
 	atf_set "descr" "Check that realpath(1) agrees with the "
 		"kernel on magic symlink(7)'s (PR lib/55361)"



CVS commit: src/tests/kernel

2022-05-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat May 14 14:02:03 UTC 2022

Modified Files:
src/tests/kernel: t_sysv.c

Log Message:
PR/56831: Eric van Gyzen: race condition in tests/kernel/t_sysv.c
https://cgit.freebsd.org/src/commit/?id=20917cac7bcf216225a7b66f7b3a56f3764c5acc


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/t_sysv.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/kernel/t_sysv.c
diff -u src/tests/kernel/t_sysv.c:1.5 src/tests/kernel/t_sysv.c:1.6
--- src/tests/kernel/t_sysv.c:1.5	Fri Feb  2 21:57:15 2018
+++ src/tests/kernel/t_sysv.c	Sat May 14 10:02:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_sysv.c,v 1.5 2018/02/03 02:57:15 pgoyette Exp $	*/
+/*	$NetBSD: t_sysv.c,v 1.6 2022/05/14 14:02:03 christos Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -53,11 +53,9 @@
 #include 
 #include 
 
-volatile int did_sigsys, did_sigchild;
-volatile int child_status, child_count;
+volatile int did_sigsys;
 
 void	sigsys_handler(int);
-void	sigchld_handler(int);
 
 key_t	get_ftok(int);
 
@@ -120,16 +118,14 @@ write_int(const char *path, const int va
 static int
 read_int(const char *path)
 {
-	int input;
+	int input, value;
 
 	input = open(path, O_RDONLY);
 	if (input == -1)
 		return -1;
-	else {
-		int value;
-		read(input, &value, sizeof(value));
-		return value;
-	}
+
+	read(input, &value, sizeof(value));
+	return value;
 }
 
 
@@ -140,23 +136,6 @@ sigsys_handler(int signo)
 	did_sigsys = 1;
 }
 
-void
-sigchld_handler(int signo)
-{
-	int c_status;
-
-	did_sigchild = 1;
-	/*
-	 * Reap the child and return its status
-	 */
-	if (wait(&c_status) == -1)
-		child_status = -errno;
-	else
-		child_status = c_status;
-
-	child_count--;
-}
-
 key_t get_ftok(int id)
 {
 	int fd;
@@ -179,8 +158,9 @@ key_t get_ftok(int id)
 		rmdir(tmpdir);
 		atf_tc_fail("open() of temp file failed: %d", errno);
 		return (key_t)-1;
-	} else
-		close(fd);
+	}
+
+	close(fd);
 
 	key = ftok(token_key, id);
 	ATF_REQUIRE_MSG(key != (key_t)-1, "ftok() failed");
@@ -204,10 +184,10 @@ ATF_TC_BODY(msg, tc)
 	struct sigaction sa;
 	struct msqid_ds m_ds;
 	struct testmsg m;
-	sigset_t sigmask;
 	int sender_msqid;
 	int loop;
 	int c_status;
+	pid_t wait_result;
 
 	/*
 	 * Install a SIGSYS handler so that we can exit gracefully if
@@ -220,18 +200,6 @@ ATF_TC_BODY(msg, tc)
 	ATF_REQUIRE_MSG(sigaction(SIGSYS, &sa, NULL) != -1,
 	"sigaction SIGSYS: %d", errno);
 
-	/*
-	 * Install a SIGCHLD handler to deal with all possible exit
-	 * conditions of the receiver.
-	 */
-	did_sigchild = 0;
-	child_count = 0;
-	sa.sa_handler = sigchld_handler;
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags = 0;
-	ATF_REQUIRE_MSG(sigaction(SIGCHLD, &sa, NULL) != -1,
-	"sigaction SIGCHLD: %d", errno);
-
 	msgkey = get_ftok(4160);
 	ATF_REQUIRE_MSG(msgkey != (key_t)-1, "get_ftok failed");
 
@@ -264,13 +232,14 @@ ATF_TC_BODY(msg, tc)
 
 	print_msqid_ds(&m_ds, 0600);
 
+	fflush(stdout);
+
 	switch ((child_pid = fork())) {
 	case -1:
 		atf_tc_fail("fork: %d", errno);
 		return;
 
 	case 0:
-		child_count++;
 		receiver();
 		break;
 
@@ -288,7 +257,7 @@ ATF_TC_BODY(msg, tc)
 		0) != -1, "sender: msgsnd 1: %d", errno);
 
 		ATF_REQUIRE_MSG(msgrcv(sender_msqid, &m, MESSAGE_TEXT_LEN,
-   MTYPE_1_ACK, 0) == MESSAGE_TEXT_LEN,
+		MTYPE_1_ACK, 0) == MESSAGE_TEXT_LEN,
 		"sender: msgrcv 1 ack: %d", errno);
 
 		print_msqid_ds(&m_ds, 0600);
@@ -298,40 +267,29 @@ ATF_TC_BODY(msg, tc)
 		 */
 		m.mtype = MTYPE_2;
 		strcpy(m.mtext, m2_str);
-		ATF_REQUIRE_MSG(msgsnd(sender_msqid, &m, MESSAGE_TEXT_LEN, 0) != -1,
-		"sender: msgsnd 2: %d", errno);
+		ATF_REQUIRE_MSG(msgsnd(sender_msqid, &m, MESSAGE_TEXT_LEN, 0)
+		!= -1, "sender: msgsnd 2: %d", errno);
 
 		ATF_REQUIRE_MSG(msgrcv(sender_msqid, &m, MESSAGE_TEXT_LEN,
-   MTYPE_2_ACK, 0) == MESSAGE_TEXT_LEN,
+		MTYPE_2_ACK, 0) == MESSAGE_TEXT_LEN,
 		"sender: msgrcv 2 ack: %d", errno);
 	}
 
 	/*
 	 * Wait for child to finish
 	 */
-	sigemptyset(&sigmask);
-	(void) sigsuspend(&sigmask);
+	wait_result = wait(&c_status);
+	ATF_REQUIRE_EQ_MSG(wait_result, child_pid, "wait returned %d (%s)",
+	wait_result, wait_result == -1 ? strerror(errno) : "");
+	ATF_REQUIRE_MSG(WIFEXITED(c_status), "child abnormal exit: %d (sig %d)",
+	c_status, WTERMSIG(c_status));
+	ATF_REQUIRE_EQ_MSG(WEXITSTATUS(c_status), 0, "child status: %d",
+	WEXITSTATUS(c_status));
 
-	/*
-	 * ...and any other signal is an unexpected error.
-	 */
-	if (did_sigchild) {
-		c_status = child_status;
-		if (c_status < 0)
-			atf_tc_fail("waitpid: %d", -c_status);
-		else if (WIFEXITED(c_status) == 0)
-			atf_tc_fail("child abnormal exit: %d", c_status);
-		else if (WEXITSTATUS(c_status) != 0)
-			atf_tc_fail("c status: %d", WEXITSTATUS(c_status));
-		else {
-			ATF_REQUIRE_MSG(msgctl(sender_msqid, IPC_STAT, &m_ds)
-			!= -1, "msgctl IPC_ST

CVS commit: src/tests/kernel

2022-05-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat May 14 14:02:03 UTC 2022

Modified Files:
src/tests/kernel: t_sysv.c

Log Message:
PR/56831: Eric van Gyzen: race condition in tests/kernel/t_sysv.c
https://cgit.freebsd.org/src/commit/?id=20917cac7bcf216225a7b66f7b3a56f3764c5acc


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

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



CVS commit: src/tests/kernel

2021-12-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Dec  9 06:38:23 UTC 2021

Modified Files:
src/tests/kernel: t_magic_symlinks.sh

Log Message:
tests/t_magic_symlinks: remove duplicate word in test description


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_magic_symlinks.sh

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

Modified files:

Index: src/tests/kernel/t_magic_symlinks.sh
diff -u src/tests/kernel/t_magic_symlinks.sh:1.1 src/tests/kernel/t_magic_symlinks.sh:1.2
--- src/tests/kernel/t_magic_symlinks.sh:1.1	Wed Jul  1 13:49:26 2020
+++ src/tests/kernel/t_magic_symlinks.sh	Thu Dec  9 06:38:23 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_magic_symlinks.sh,v 1.1 2020/07/01 13:49:26 jruoho Exp $
+# $NetBSD: t_magic_symlinks.sh,v 1.2 2021/12/09 06:38:23 rillig Exp $
 #
 # Copyright (c) 2020 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -222,7 +222,7 @@ atf_test_case realpath cleanup
 nointerpreter_head() {
 	atf_set "require.user" "root"
 	atf_set "descr" "Check that realpath(1) agrees with the "
-		"the kernel on magic symlink(7)'s (PR lib/55361)"
+		"kernel on magic symlink(7)'s (PR lib/55361)"
 }
 
 realpath_body() {



CVS commit: src/tests/kernel

2021-12-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Dec  9 06:38:23 UTC 2021

Modified Files:
src/tests/kernel: t_magic_symlinks.sh

Log Message:
tests/t_magic_symlinks: remove duplicate word in test description


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_magic_symlinks.sh

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



CVS commit: src/tests/kernel/kqueue

2021-11-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Nov 21 09:35:39 UTC 2021

Modified Files:
src/tests/kernel/kqueue: Makefile t_timer.c

Log Message:
Test kernel/kqueue/t_timer, subtests abstime, basic_timer and timer_units
often fail when run on QEMU because QEMU misses clock interrupts.

Always check timespec against expected "tv_sec" and use an "4 * tv_sec"
upper bound 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.9 -r1.10 src/tests/kernel/kqueue/Makefile
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_timer.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/kernel/kqueue/Makefile
diff -u src/tests/kernel/kqueue/Makefile:1.9 src/tests/kernel/kqueue/Makefile:1.10
--- src/tests/kernel/kqueue/Makefile:1.9	Sat Oct 23 18:46:26 2021
+++ src/tests/kernel/kqueue/Makefile	Sun Nov 21 09:35:39 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2021/10/23 18:46:26 thorpej Exp $
+# $NetBSD: Makefile,v 1.10 2021/11/21 09:35:39 hannken Exp $
 
 WARNS?=6
 NOMAN=		# defined
@@ -24,4 +24,6 @@ TESTS_C+=	t_vnode
 
 LDADD.t_scan+=	-lpthread
 
+CPPFLAGS.t_timer.c+=	-I${.CURDIR}/../../lib/libc/gen
+
 .include 

Index: src/tests/kernel/kqueue/t_timer.c
diff -u src/tests/kernel/kqueue/t_timer.c:1.3 src/tests/kernel/kqueue/t_timer.c:1.4
--- src/tests/kernel/kqueue/t_timer.c:1.3	Fri Oct 22 13:53:20 2021
+++ src/tests/kernel/kqueue/t_timer.c	Sun Nov 21 09:35:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: t_timer.c,v 1.3 2021/10/22 13:53:20 thorpej Exp $ */
+/* $NetBSD: t_timer.c,v 1.4 2021/11/21 09:35:39 hannken Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_timer.c,v 1.3 2021/10/22 13:53:20 thorpej Exp $");
+__RCSID("$NetBSD: t_timer.c,v 1.4 2021/11/21 09:35:39 hannken Exp $");
 
 #include 
 #include 
@@ -39,6 +39,36 @@ __RCSID("$NetBSD: t_timer.c,v 1.3 2021/1
 
 #include 
 
+#include "isqemu.h"
+
+static bool
+check_timespec(struct timespec *ts, time_t seconds)
+{
+	time_t upper = seconds;
+	bool result = true;
+
+	/*
+	 * If running under QEMU make sure the upper bound is large
+	 * enough for the effect of kern/43997
+	 */
+	if (isQEMU()) {
+		upper *= 4;
+	}
+
+	if (ts->tv_sec < seconds - 1 ||
+	(ts->tv_sec == seconds - 1 && ts->tv_nsec < 5))
+		result = false;
+	else if (ts->tv_sec > upper ||
+	(ts->tv_sec == upper && ts->tv_nsec >= 5))
+		result = false;
+
+	printf("time %" PRId64 ".%09ld %sin [ %" PRId64 ".5, %" PRId64 ".5 )\n",
+		ts->tv_sec, ts->tv_nsec, (result ? "" : "not "),
+		seconds - 1, upper);
+
+	return result;
+}
+
 ATF_TC(basic_timer);
 ATF_TC_HEAD(basic_timer, tc)
 {
@@ -83,13 +113,8 @@ ATF_TC_BODY(basic_timer, tc)
 ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC,
 &ts) == 0);
 timespecsub(&ts, &ots, &ts);
-ATF_REQUIRE(ts.tv_sec ==
-	(TIME1_TOTAL_SEC - 1) ||
-ts.tv_sec == TIME1_TOTAL_SEC);
-if (ts.tv_sec == TIME1_TOTAL_SEC - 1) {
-	ATF_REQUIRE(ts.tv_nsec >=
-	9);
-}
+ATF_REQUIRE(check_timespec(&ts,
+TIME1_TOTAL_SEC));
 EV_SET(&event[0], 1, EVFILT_TIMER, EV_DELETE,
 0, 0, NULL);
 ATF_REQUIRE(kevent(kq, event, 1, NULL, 0,
@@ -106,12 +131,7 @@ ATF_TC_BODY(basic_timer, tc)
 			ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC,
 			&ts) == 0);
 			timespecsub(&ts, &ots, &ts);
-			ATF_REQUIRE(ts.tv_sec ==
-(TIME2_TOTAL_SEC - 1) ||
-			ts.tv_sec == TIME2_TOTAL_SEC);
-			if (ts.tv_sec == TIME2_TOTAL_SEC - 1) {
-ATF_REQUIRE(ts.tv_nsec >= 9);
-			}
+			ATF_REQUIRE(check_timespec(&ts, TIME2_TOTAL_SEC));
 			EV_SET(&event[0], 2, EVFILT_TIMER, EV_DELETE,
 			0, 0, NULL);
 			ATF_REQUIRE_ERRNO(ENOENT,
@@ -130,14 +150,7 @@ ATF_TC_BODY(basic_timer, tc)
 	ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, &ts) == 0);
 	ATF_REQUIRE(clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
 	timespecsub(&ts, &ots, &ts);
-	ATF_REQUIRE(ts.tv_sec == (TIME2_TOTAL_SEC - 1) ||
-	ts.tv_sec == TIME2_TOTAL_SEC ||
-	ts.tv_sec == (TIME2_TOTAL_SEC + 1));
-	if (ts.tv_sec == TIME2_TOTAL_SEC - 1) {
-		ATF_REQUIRE(ts.tv_nsec >= 9);
-	} else if (ts.tv_sec == TIME2_TOTAL_SEC + 1) {
-		ATF_REQUIRE(ts.tv_nsec < 5);
-	}
+	ATF_REQUIRE(check_timespec(&ts, TIME2_TOTAL_SEC));
 }
 
 ATF_TC(count_expirations);
@@ -272,9 +285,6 @@ ATF_TC_BODY(abstime, tc)
 	ATF_REQUIRE(ots.tv_sec < INTPTR_MAX - TIME1_TOTAL_SEC);
 
 	seconds = ots.tv_sec + TIME1_TOTAL_SEC;
-	if (ots.tv_nsec >= 5) {
-		seconds++;
-	}
 
 	EV_SET(&event[0], 1, EVFILT_TIMER, EV_ADD,
 	NOTE_ABSTIME | NOTE_SECONDS, seconds, NULL);
@@ -287,10 +297,7 @@ ATF_TC_BODY(abstime, tc)
 	 * We're not going for precision here; just verify that it was
 	 * delivered anywhere between 4.5-6.whatever seconds later.
 	 */
-	ATF_REQUIRE(ts.tv_sec >= 4 && ts.tv_sec <= 6);
-	if (ts.tv_sec == 4) 

CVS commit: src/tests/kernel/kqueue

2021-11-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Nov 21 09:35:39 UTC 2021

Modified Files:
src/tests/kernel/kqueue: Makefile t_timer.c

Log Message:
Test kernel/kqueue/t_timer, subtests abstime, basic_timer and timer_units
often fail when run on QEMU because QEMU misses clock interrupts.

Always check timespec against expected "tv_sec" and use an "4 * tv_sec"
upper bound 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.9 -r1.10 src/tests/kernel/kqueue/Makefile
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_timer.c

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



CVS commit: src/tests/kernel/kqueue

2021-10-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Oct 22 13:53:20 UTC 2021

Modified Files:
src/tests/kernel/kqueue: t_timer.c

Log Message:
In the "modify" test case, immediately after modifying the timer, validate
that its associated knote in the kernel has actually been deactivated.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/kqueue/t_timer.c

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



CVS commit: src/tests/kernel/kqueue

2021-10-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Oct 22 13:53:20 UTC 2021

Modified Files:
src/tests/kernel/kqueue: t_timer.c

Log Message:
In the "modify" test case, immediately after modifying the timer, validate
that its associated knote in the kernel has actually been deactivated.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/kqueue/t_timer.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/kernel/kqueue/t_timer.c
diff -u src/tests/kernel/kqueue/t_timer.c:1.2 src/tests/kernel/kqueue/t_timer.c:1.3
--- src/tests/kernel/kqueue/t_timer.c:1.2	Fri Oct 22 04:49:24 2021
+++ src/tests/kernel/kqueue/t_timer.c	Fri Oct 22 13:53:20 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: t_timer.c,v 1.2 2021/10/22 04:49:24 thorpej Exp $ */
+/* $NetBSD: t_timer.c,v 1.3 2021/10/22 13:53:20 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_timer.c,v 1.2 2021/10/22 04:49:24 thorpej Exp $");
+__RCSID("$NetBSD: t_timer.c,v 1.3 2021/10/22 13:53:20 thorpej Exp $");
 
 #include 
 #include 
@@ -208,6 +208,12 @@ ATF_TC_BODY(modify, tc)
 	EV_SET(&event[0], 1, EVFILT_TIMER, EV_ADD, 0, 4000, NULL);
 	ATF_REQUIRE(kevent(kq, event, 1, NULL, 0, NULL) == 0);
 
+	/*
+	 * Before we sleep, verify that the knote for this timer is
+	 * no longer activated.
+	 */
+	ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, &ts) == 0);
+
 	sleepts.tv_sec = 5;
 	sleepts.tv_nsec = 0;
 	ATF_REQUIRE(nanosleep(&sleepts, NULL) == 0);



CVS commit: src/tests/kernel/kqueue

2021-10-20 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Oct 20 14:33:14 UTC 2021

Modified Files:
src/tests/kernel/kqueue: t_vnode.c

Log Message:
Add a test case for PR kern/56460.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/kqueue/t_vnode.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/kernel/kqueue/t_vnode.c
diff -u src/tests/kernel/kqueue/t_vnode.c:1.2 src/tests/kernel/kqueue/t_vnode.c:1.3
--- src/tests/kernel/kqueue/t_vnode.c:1.2	Wed Oct 20 03:08:19 2021
+++ src/tests/kernel/kqueue/t_vnode.c	Wed Oct 20 14:33:14 2021
@@ -671,6 +671,53 @@ ATF_TC_CLEANUP(interest, tc)
 	(void)unlink(testfile);
 }
 
+ATF_TC_WITH_CLEANUP(rename_over_self_hardlink);
+ATF_TC_HEAD(rename_over_self_hardlink, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "This test case tests "
+		"renaming a file over a hard-link to itself");
+}
+ATF_TC_BODY(rename_over_self_hardlink, tc)
+{
+	struct kevent event[2], *dir_ev, *file_ev;
+	int dir_fd, file_fd;
+
+	ATF_REQUIRE((kq = kqueue()) != -1);
+
+	ATF_REQUIRE((mkdir(dir_target, 0700)) == 0);
+	ATF_REQUIRE((dir_fd = open(dir_target, O_RDONLY)) != -1);
+
+	ATF_REQUIRE((file_fd = open(file_inside1, O_RDONLY | O_CREAT,
+	0600)) != -1);
+	ATF_REQUIRE(link(file_inside1, file_inside2) == 0);
+
+	EV_SET(&event[0], dir_fd, EVFILT_VNODE, EV_ADD,
+	NOTE_WRITE | NOTE_EXTEND | NOTE_LINK, 0, NULL);
+	EV_SET(&event[1], file_fd, EVFILT_VNODE, EV_ADD,
+	NOTE_LINK | NOTE_DELETE, 0, NULL);
+	ATF_REQUIRE(kevent(kq, event, 2, NULL, 0, NULL) == 0);
+
+	ATF_REQUIRE(rename(file_inside1, file_inside2) == 0);
+
+	ATF_REQUIRE(kevent(kq, NULL, 0, event, 2, &ts) == 2);
+	ATF_REQUIRE(event[0].ident == (uintptr_t)dir_fd ||
+		event[0].ident == (uintptr_t)file_fd);
+	ATF_REQUIRE(event[1].ident == (uintptr_t)dir_fd ||
+		event[1].ident == (uintptr_t)file_fd);
+	if (event[0].ident == (uintptr_t)dir_fd) {
+		dir_ev = &event[0];
+		file_ev = &event[1];
+	} else {
+		dir_ev = &event[1];
+		file_ev = &event[0];
+	}
+	ATF_REQUIRE(dir_ev->fflags == NOTE_WRITE);
+	ATF_REQUIRE(file_ev->fflags == NOTE_LINK);
+}
+ATF_TC_CLEANUP(rename_over_self_hardlink, tc)
+{
+	cleanup();
+}
 
 ATF_TP_ADD_TCS(tp)
 {
@@ -699,6 +746,8 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, dir_note_write_mv_file_out);
 	ATF_TP_ADD_TC(tp, dir_note_write_mv_file_within);
 
+	ATF_TP_ADD_TC(tp, rename_over_self_hardlink);
+
 	ATF_TP_ADD_TC(tp, open_write_read_close);
 	ATF_TP_ADD_TC(tp, interest);
 



CVS commit: src/tests/kernel/kqueue

2021-10-20 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Oct 20 14:33:14 UTC 2021

Modified Files:
src/tests/kernel/kqueue: t_vnode.c

Log Message:
Add a test case for PR kern/56460.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/kqueue/t_vnode.c

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



CVS commit: src/tests/kernel/kqueue

2021-10-10 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Oct 10 19:17:32 UTC 2021

Modified Files:
src/tests/kernel/kqueue: t_scan.c

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/kqueue/t_scan.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/kernel/kqueue/t_scan.c
diff -u src/tests/kernel/kqueue/t_scan.c:1.1 src/tests/kernel/kqueue/t_scan.c:1.2
--- src/tests/kernel/kqueue/t_scan.c:1.1	Sun Oct 10 17:47:39 2021
+++ src/tests/kernel/kqueue/t_scan.c	Sun Oct 10 19:17:31 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: t_scan.c,v 1.1 2021/10/10 17:47:39 thorpej Exp $ */
+/* $NetBSD: t_scan.c,v 1.2 2021/10/10 19:17:31 wiz Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_scan.c,v 1.1 2021/10/10 17:47:39 thorpej Exp $");
+__RCSID("$NetBSD: t_scan.c,v 1.2 2021/10/10 19:17:31 wiz Exp $");
 
 #include 
 #include 
@@ -44,7 +44,7 @@ __RCSID("$NetBSD: t_scan.c,v 1.1 2021/10
 /*
  * Each kevent thread will make this many kevent() calls, and if it
  * achieves this mark, we assume the race condition has not occurred
- * the delcare the test passes.
+ * the declare the test passes.
  */
 #define	NKEVENT_CALLS		1
 



CVS commit: src/tests/kernel/kqueue

2021-10-10 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Oct 10 19:17:32 UTC 2021

Modified Files:
src/tests/kernel/kqueue: t_scan.c

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/kqueue/t_scan.c

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



CVS commit: src/tests/kernel/kqueue

2021-10-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Oct 10 18:11:31 UTC 2021

Modified Files:
src/tests/kernel/kqueue: t_sig.c

Log Message:
The knotes for EVFILT_SIGNAL and EVFILT_PROC are maintained on a single
per-process list, and kern_event.c,v 1.129 has several KASSERT()s in
various code paths that process this list related to the mixing of these
two knote types.  This new unit test is designed specifically to exercise
those KASSERT()s and thus validate their assumptions.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_sig.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/kernel/kqueue/t_sig.c
diff -u src/tests/kernel/kqueue/t_sig.c:1.3 src/tests/kernel/kqueue/t_sig.c:1.4
--- src/tests/kernel/kqueue/t_sig.c:1.3	Fri Jan 13 21:30:41 2017
+++ src/tests/kernel/kqueue/t_sig.c	Sun Oct 10 18:11:31 2021
@@ -1,7 +1,7 @@
-/* $NetBSD: t_sig.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */
+/* $NetBSD: t_sig.c,v 1.4 2021/10/10 18:11:31 thorpej Exp $ */
 
 /*-
- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002, 2008, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sig.c,v 1.3 2017/01/13 21:30:41 christos Exp $");
+__RCSID("$NetBSD: t_sig.c,v 1.4 2021/10/10 18:11:31 thorpej Exp $");
 
 #include 
 #include 
@@ -125,9 +125,87 @@ ATF_TC_BODY(sig, tc)
 	(void)printf("sig: finished successfully\n");
 }
 
+/*
+ * This test case exercises code paths in the kernel that KASSERT()
+ * some assumptions about EVFILT_SIGNAL and EVFILT_PROC implementation
+ * details.
+ */
+ATF_TC(sig_and_proc);
+ATF_TC_HEAD(sig_and_proc, tc)
+{
+	atf_tc_set_md_var(tc, "descr",
+	"Validates implementation detail assumptions about "
+	"EVFILT_SIGNAL and EVFILT_PROC");
+}
+ATF_TC_BODY(sig_and_proc, tc)
+{
+	struct kevent events[3];
+	pid_t pid;
+	int kq;
+
+	pid = fork();
+	ATF_REQUIRE(pid != -1);
+
+	if (pid == 0) {
+		/*
+		 * Child: create a kqueue and attach signal knotes
+		 * to curproc->p_klist.
+		 */
+		kq = kqueue();
+		ATF_REQUIRE(kq >= 0);
+
+		ATF_REQUIRE(signal(SIGUSR1, SIG_IGN) != SIG_ERR);
+		ATF_REQUIRE(signal(SIGUSR2, SIG_IGN) != SIG_ERR);
+
+		EV_SET(&events[0], SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
+		EV_SET(&events[1], SIGUSR2, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
+
+		ATF_REQUIRE(kevent(kq, events, 2, &events[2], 1, NULL) == 1);
+		ATF_REQUIRE(events[2].filter == EVFILT_SIGNAL);
+		ATF_REQUIRE(events[2].ident == SIGUSR1);
+
+		/*
+		 * When we exit here, the kernel will close all of
+		 * its file descriptors (including our kq), which
+		 * will in turn remove the signal notes from
+		 * curproc->p_klist.
+		 *
+		 * Then, later on, the kernel will post a NOTE_EXIT
+		 * on our parent's kqueue using the proc note that
+		 * our parent attached to (our) curproc->p_klist.
+		 * That code path KASSERT()s that the signal knotes
+		 * have already been removed.
+		 */
+		_exit(0);
+	}
+
+	/*
+	 * Parent: create a kqueue and attach a proc note to
+	 * child->p_klist.
+	 */
+	kq = kqueue();
+	ATF_REQUIRE(kq >= 0);
+
+	EV_SET(&events[0], pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
+
+	ATF_REQUIRE(kevent(kq, events, 1, NULL, 0, NULL) == 0);
+
+	/* Ensure we never see stale data. */
+	memset(events, 0, sizeof(events));
+
+	/* Signal child to exit. */
+	ATF_REQUIRE(kill(pid, SIGUSR1) == 0);
+
+	ATF_REQUIRE(kevent(kq, NULL, 0, events, 1, NULL) == 1);
+	ATF_REQUIRE(events[0].filter == EVFILT_PROC);
+	ATF_REQUIRE(events[0].ident == (uintptr_t)pid);
+	ATF_REQUIRE(events[0].fflags = NOTE_EXIT);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, sig);
+	ATF_TP_ADD_TC(tp, sig_and_proc);
 
 	return atf_no_error();
 }



CVS commit: src/tests/kernel/kqueue

2021-10-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Oct 10 18:11:31 UTC 2021

Modified Files:
src/tests/kernel/kqueue: t_sig.c

Log Message:
The knotes for EVFILT_SIGNAL and EVFILT_PROC are maintained on a single
per-process list, and kern_event.c,v 1.129 has several KASSERT()s in
various code paths that process this list related to the mixing of these
two knote types.  This new unit test is designed specifically to exercise
those KASSERT()s and thus validate their assumptions.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_sig.c

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



CVS commit: src/tests/kernel/kqueue/read

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 18:21:05 UTC 2021

Modified Files:
src/tests/kernel/kqueue/read: t_fifo.c

Log Message:
New EVFILT_READ test case for FIFOs; validates readability threshold and
EV_EOF behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/read/t_fifo.c

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



CVS commit: src/tests/kernel/kqueue/read

2021-10-02 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct  2 18:21:05 UTC 2021

Modified Files:
src/tests/kernel/kqueue/read: t_fifo.c

Log Message:
New EVFILT_READ test case for FIFOs; validates readability threshold and
EV_EOF behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/read/t_fifo.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/kernel/kqueue/read/t_fifo.c
diff -u src/tests/kernel/kqueue/read/t_fifo.c:1.4 src/tests/kernel/kqueue/read/t_fifo.c:1.5
--- src/tests/kernel/kqueue/read/t_fifo.c:1.4	Fri Jan 13 21:30:41 2017
+++ src/tests/kernel/kqueue/read/t_fifo.c	Sat Oct  2 18:21:05 2021
@@ -1,11 +1,11 @@
-/* $NetBSD: t_fifo.c,v 1.4 2017/01/13 21:30:41 christos Exp $ */
+/* $NetBSD: t_fifo.c,v 1.5 2021/10/02 18:21:05 thorpej Exp $ */
 
 /*-
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Luke Mewburn and Jaromir Dolecek.
+ * by Jason R. Thorpe.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,13 +30,14 @@
  */
 
 #include 
-__COPYRIGHT("@(#) Copyright (c) 2008\
+__COPYRIGHT("@(#) Copyright (c) 2021\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_fifo.c,v 1.4 2017/01/13 21:30:41 christos Exp $");
+__RCSID("$NetBSD: t_fifo.c,v 1.5 2021/10/02 18:21:05 thorpej Exp $");
 
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -46,48 +47,94 @@ __RCSID("$NetBSD: t_fifo.c,v 1.4 2017/01
 
 #include 
 
-#include "h_macros.h"
+static const char	fifo_path[] = "fifo";
 
-#define FIFONAME "fifo"
+static void
+fifo_support(void)
+{
+	errno = 0;
+	if (mkfifo(fifo_path, 0600) == 0) {
+		ATF_REQUIRE(unlink(fifo_path) == 0);
+		return;
+	}
+
+	if (errno == EOPNOTSUPP) {
+		atf_tc_skip("the kernel does not support FIFOs");
+	} else {
+		atf_tc_fail("mkfifo(2) failed");
+	}
+}
 
-ATF_TC(fifo);
+ATF_TC_WITH_CLEANUP(fifo);
 ATF_TC_HEAD(fifo, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "Checks EVFILT_READ on fifo");
 }
 ATF_TC_BODY(fifo, tc)
 {
-	int kq, n, fd;
+	const struct timespec to = { 0, 0 };
 	struct kevent event[1];
-	char buffer[128];
-
-	RL(mkfifo(FIFONAME, 0644));
-	RL(fd = open(FIFONAME, O_RDWR, 0644));
-
-	RL(kq = kqueue());
-
-	EV_SET(&event[0], fd, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
-	RL(kevent(kq, event, 1, NULL, 0, NULL));
-
-	/* make sure there is something in the fifo */
-	RL(write(fd, "foo", 3));
-	(void)printf("fifo: wrote 'foo'\n");
-
-	(void)memset(event, 0, sizeof(event));
-
-	RL(n = kevent(kq, NULL, 0, event, 1, NULL));
-
-	(void)printf("kevent num %d filt %d flags: %#x, fflags: %#x, "
-	"data: %" PRId64 "\n", n, event[0].filter, event[0].flags,
-	event[0].fflags, event[0].data);
-
-	ATF_REQUIRE_EQ(event[0].filter, EVFILT_READ);
-
-	RL(n = read(fd, buffer, event[0].data));
-	buffer[n] = '\0';
-	(void)printf("fifo: read '%s'\n", buffer);
+	char *buf;
+	int rfd, wfd, kq;
+	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);
+	ATF_REQUIRE((kq = kqueue()) >= 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);
+
+	EV_SET(&event[0], rfd, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
+	ATF_REQUIRE(kevent(kq, event, 1, NULL, 0, NULL) == 0);
+
+	/* We expect the FIFO to not be readable. */
+	ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, &to) == 0);
+
+	/* Write a single byte of data into the FIFO. */
+	ATF_REQUIRE(write(wfd, buf, 1) == 1);
+
+	/* We expect the FIFO to be readable. */
+	ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, &to) == 1);
+	ATF_REQUIRE(event[0].ident == (uintptr_t)rfd);
+	ATF_REQUIRE(event[0].filter == EVFILT_READ);
+	ATF_REQUIRE((event[0].flags & EV_EOF) == 0);
+
+	/* Read that single byte back out. */
+	ATF_REQUIRE(read(rfd, buf, 1) == 1);
+
+	/* We expect the FIFO to not be readable. */
+	ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, &to) == 0); 
+
+	/* Close the writer.  We expect to get EV_EOF. */
+	(void)close(wfd);
+	ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, &to) == 1);
+	ATF_REQUIRE(event[0].ident == (uintptr_t)rfd);
+	ATF_REQUIRE(event[0].filter == EVFILT_READ);
+	ATF_REQUIRE((event[0].flags & EV_EOF) != 0);
+
+	/*
+	 * Reconect the writer.  We expect EV_EOF to be cleared and
+	 * for the FIFO to no longer be readable once again.
+	 */
+	ATF_REQUIRE((wfd = open(fifo_path, O_WRONLY | O_NONBLOCK)) >= 0);
+	ATF_REQUIRE(kevent(kq, NULL, 0, event, 1, &to) == 0);
+
+	(void)close(wfd);
+	(void)close(rfd);
+	(void)close(kq);
+}
 
-	RL(c

CVS commit: src/tests/kernel

2021-10-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Oct  1 18:18:32 UTC 2021

Modified Files:
src/tests/kernel: Makefile

Log Message:
t_simplehook requires RUMP


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/tests/kernel/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/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.69 src/tests/kernel/Makefile:1.70
--- src/tests/kernel/Makefile:1.69	Thu Sep 30 02:00:20 2021
+++ src/tests/kernel/Makefile	Fri Oct  1 18:18:32 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.69 2021/09/30 02:00:20 yamaguchi Exp $
+# $NetBSD: Makefile,v 1.70 2021/10/01 18:18:32 martin Exp $
 
 NOMAN=		# defined
 
@@ -32,7 +32,9 @@ TESTS_SH+=	t_origin
 TESTS_SH+=	t_procpath
 TESTS_SH+=	t_fexecve
 TESTS_SH+=	t_fpufork
+.if ${MKRUMP} != "no"
 TESTS_SH+=	t_simplehook
+.endif
 
 BINDIR=		${TESTSDIR}
 PROGS=		h_fexecve



CVS commit: src/tests/kernel

2021-10-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Oct  1 18:18:32 UTC 2021

Modified Files:
src/tests/kernel: Makefile

Log Message:
t_simplehook requires RUMP


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/tests/kernel/Makefile

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



CVS commit: src/tests/kernel

2019-10-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 20 16:02:11 UTC 2019

Modified Files:
src/tests/kernel: t_fcntl.c

Log Message:
opening a symlink with O_NOFOLLOW is expected to fail.


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

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



CVS commit: src/tests/kernel

2019-10-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 20 16:02:11 UTC 2019

Modified Files:
src/tests/kernel: t_fcntl.c

Log Message:
opening a symlink with O_NOFOLLOW is expected to fail.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_fcntl.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/kernel/t_fcntl.c
diff -u src/tests/kernel/t_fcntl.c:1.1 src/tests/kernel/t_fcntl.c:1.2
--- src/tests/kernel/t_fcntl.c:1.1	Sun Sep 15 12:25:58 2019
+++ src/tests/kernel/t_fcntl.c	Sun Oct 20 12:02:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fcntl.c,v 1.1 2019/09/15 16:25:58 christos Exp $	*/
+/*	$NetBSD: t_fcntl.c,v 1.2 2019/10/20 16:02:11 christos Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@ static const struct {
 	{ "/bin/sh", 0 },
 	{ "/dev/zero", 0 },
 	{ "/dev/null", 0 },
-	{ "/bin/chgrp", 0 },
+	{ "/sbin/chown", 0 },
 	{ "/", ENOENT },
 };
 
@@ -64,7 +64,7 @@ ATF_TC_BODY(getpath, tc)
 
 	for (size_t i = 0; i < __arraycount(files); i++) {
 		fd = open(files[i].name, O_RDONLY|O_NOFOLLOW);
-		ATF_REQUIRE(fd != -1);
+		ATF_REQUIRE_MSG(fd != -1, "Cannot open `%s'", files[i].name);
 		rv = fcntl(fd, F_GETPATH, path);
 		if (files[i].rv) {
 			ATF_REQUIRE_MSG(errno == files[i].rv,



Re: CVS commit: src/tests/kernel

2019-09-15 Thread Kamil Rytarowski
While there, it does not build for me:

/usr/src/tests/kernel/h_fexecve.c: In function 'main':
/usr/src/tests/kernel/h_fexecve.c:48:6: error: implicit declaration of
function 'fexecve'; did you mean 'execve'?
[-Werror=implicit-function-declaration]
  if (fexecve(fd, args, NULL) == -1)
  ^~~
  execve
cc1: all warnings being treated as errors


On 15.09.2019 22:37, Kamil Rytarowski wrote:
> I have got no opinion, but merging them is good. Personally I prefer
> src/libc/* path as fexecve(2) is a libc public symbol.
> 
> On 15.09.2019 20:06, Christos Zoulas wrote:
>> The tests are a different. Should we keep them both, or try to merge them?
>> I think that merging them is probably better. It is also the case that 
>> perhaps
>> we need to get rid of the kernel tests directory and move them to the
>> respective bin and lib directories to avoid confusion?
>>
>> christos
>>
>>> On Sep 15, 2019, at 1:02 PM, Kamil Rytarowski  wrote:
>>>
>>> Signed PGP part
>>> On 15.09.2019 18:53, Christos Zoulas wrote:
 Module Name:   src
 Committed By:  christos
 Date:  Sun Sep 15 16:53:58 UTC 2019

 Modified Files:
src/tests/kernel: Makefile
 Added Files:
src/tests/kernel: h_fexecve.c t_fexecve.sh

 Log Message:
 Add tests for fexecve(2)
>>>
>>> For the reference, there were already tests in:
>>>
>>> ./lib/libc/c063/t_fexecve
>>>
>>>
>>> 
>>
> 
> 




signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2019-09-15 Thread Kamil Rytarowski
I have got no opinion, but merging them is good. Personally I prefer
src/libc/* path as fexecve(2) is a libc public symbol.

On 15.09.2019 20:06, Christos Zoulas wrote:
> The tests are a different. Should we keep them both, or try to merge them?
> I think that merging them is probably better. It is also the case that perhaps
> we need to get rid of the kernel tests directory and move them to the
> respective bin and lib directories to avoid confusion?
> 
> christos
> 
>> On Sep 15, 2019, at 1:02 PM, Kamil Rytarowski  wrote:
>>
>> Signed PGP part
>> On 15.09.2019 18:53, Christos Zoulas wrote:
>>> Module Name:src
>>> Committed By:   christos
>>> Date:   Sun Sep 15 16:53:58 UTC 2019
>>>
>>> Modified Files:
>>> src/tests/kernel: Makefile
>>> Added Files:
>>> src/tests/kernel: h_fexecve.c t_fexecve.sh
>>>
>>> Log Message:
>>> Add tests for fexecve(2)
>>
>> For the reference, there were already tests in:
>>
>> ./lib/libc/c063/t_fexecve
>>
>>
>> 
> 




signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2019-09-15 Thread Christos Zoulas
The tests are a different. Should we keep them both, or try to merge them?
I think that merging them is probably better. It is also the case that perhaps
we need to get rid of the kernel tests directory and move them to the
respective bin and lib directories to avoid confusion?

christos

> On Sep 15, 2019, at 1:02 PM, Kamil Rytarowski  wrote:
> 
> Signed PGP part
> On 15.09.2019 18:53, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Sun Sep 15 16:53:58 UTC 2019
>> 
>> Modified Files:
>>  src/tests/kernel: Makefile
>> Added Files:
>>  src/tests/kernel: h_fexecve.c t_fexecve.sh
>> 
>> Log Message:
>> Add tests for fexecve(2)
> 
> For the reference, there were already tests in:
> 
> ./lib/libc/c063/t_fexecve
> 
> 
> 



Re: CVS commit: src/tests/kernel

2019-09-15 Thread Kamil Rytarowski
On 15.09.2019 18:53, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Sun Sep 15 16:53:58 UTC 2019
> 
> Modified Files:
>   src/tests/kernel: Makefile
> Added Files:
>   src/tests/kernel: h_fexecve.c t_fexecve.sh
> 
> Log Message:
> Add tests for fexecve(2)

For the reference, there were already tests in:

./lib/libc/c063/t_fexecve



signature.asc
Description: OpenPGP digital signature


CVS commit: src/tests/kernel

2019-09-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Sep 15 16:53:58 UTC 2019

Modified Files:
src/tests/kernel: Makefile
Added Files:
src/tests/kernel: h_fexecve.c t_fexecve.sh

Log Message:
Add tests for fexecve(2)


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/tests/kernel/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/kernel/h_fexecve.c \
src/tests/kernel/t_fexecve.sh

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



CVS commit: src/tests/kernel

2019-09-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Sep 15 16:53:58 UTC 2019

Modified Files:
src/tests/kernel: Makefile
Added Files:
src/tests/kernel: h_fexecve.c t_fexecve.sh

Log Message:
Add tests for fexecve(2)


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/tests/kernel/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/kernel/h_fexecve.c \
src/tests/kernel/t_fexecve.sh

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

Modified files:

Index: src/tests/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.62 src/tests/kernel/Makefile:1.63
--- src/tests/kernel/Makefile:1.62	Sun Sep 15 12:25:58 2019
+++ src/tests/kernel/Makefile	Sun Sep 15 12:53:58 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.62 2019/09/15 16:25:58 christos Exp $
+# $NetBSD: Makefile,v 1.63 2019/09/15 16:53:58 christos Exp $
 
 NOMAN=		# defined
 
@@ -28,9 +28,11 @@ TESTS_SH+=	t_trapsignal
 TESTS_SH+=	t_interp
 TESTS_SH+=	t_origin
 TESTS_SH+=	t_procpath
+TESTS_SH+=	t_fexecve
 
 BINDIR=		${TESTSDIR}
-PROGS=		h_ps_strings1
+PROGS=		h_fexecve
+PROGS+=		h_ps_strings1
 PROGS+=		h_ps_strings2
 PROGS+=		h_segv
 PROGS+=		h_getprocpath

Added files:

Index: src/tests/kernel/h_fexecve.c
diff -u /dev/null src/tests/kernel/h_fexecve.c:1.1
--- /dev/null	Sun Sep 15 12:53:58 2019
+++ src/tests/kernel/h_fexecve.c	Sun Sep 15 12:53:58 2019
@@ -0,0 +1,51 @@
+/*	$NetBSD: h_fexecve.c,v 1.1 2019/09/15 16:53:58 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include 
+__RCSID("$NetBSD: h_fexecve.c,v 1.1 2019/09/15 16:53:58 christos Exp $");
+
+#include 
+#include 
+#include 
+#include 
+
+int
+main(int argc, char *argv[])
+{
+	char *args[] = { argv[1], NULL };
+	int fd = open(args[0], O_RDONLY);
+	if (fd == -1)
+		err(EXIT_FAILURE, "open %s", args[0]);
+	if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
+		err(EXIT_FAILURE, "fcntl");
+	if (fexecve(fd, args, NULL) == -1)
+		err(EXIT_FAILURE, "fexecve");
+	return EXIT_SUCCESS;
+}
Index: src/tests/kernel/t_fexecve.sh
diff -u /dev/null src/tests/kernel/t_fexecve.sh:1.1
--- /dev/null	Sun Sep 15 12:53:58 2019
+++ src/tests/kernel/t_fexecve.sh	Sun Sep 15 12:53:58 2019
@@ -0,0 +1,72 @@
+# $NetBSD: t_fexecve.sh,v 1.1 2019/09/15 16:53:58 christos Exp $
+#
+# Copyright (c) 2019 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Christos Zoulas.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#

CVS commit: src/tests/kernel

2019-08-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Aug 15 08:46:09 UTC 2019

Modified Files:
src/tests/kernel: Makefile

Log Message:
Adapt tests/kernel/t_subr_prf for MKSANITIZER

Allow to rename snprintf-like functions to avoid clashes with a sanitizer.

This tests needs a fixup to remove 'undef symbol' from the test code
generator.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/tests/kernel/Makefile

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



CVS commit: src/tests/kernel

2019-08-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Aug 15 08:46:09 UTC 2019

Modified Files:
src/tests/kernel: Makefile

Log Message:
Adapt tests/kernel/t_subr_prf for MKSANITIZER

Allow to rename snprintf-like functions to avoid clashes with a sanitizer.

This tests needs a fixup to remove 'undef symbol' from the test code
generator.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/tests/kernel/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/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.60 src/tests/kernel/Makefile:1.61
--- src/tests/kernel/Makefile:1.60	Fri Jun  7 21:18:16 2019
+++ src/tests/kernel/Makefile	Thu Aug 15 08:46:09 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.60 2019/06/07 21:18:16 christos Exp $
+# $NetBSD: Makefile,v 1.61 2019/08/15 08:46:09 kamil Exp $
 
 NOMAN=		# defined
 
@@ -66,6 +66,11 @@ CPPFLAGS.subr_extent.c=	-D_EXTENT_TESTIN
 
 t_subr_prf.c: gen_t_subr_prf ${NETBSDSRCDIR}/sys/kern/subr_prf.c
 	${HOST_SH} ${.ALLSRC} ${.TARGET}
+.if ${MKSANITIZER:Uno} == "yes"
+	# These symbols will be redefined by MKSANITIZER
+	${TOOL_SED} -i '/undef .*printf/d' ${.TARGET}
+.endif
+
 CPPFLAGS.t_subr_prf.c=	-Wno-pointer-sign	# XXX platform vs kernel SHA2
 
 .if defined(HAVE_GCC) && ${HAVE_GCC} == 7 && ${ACTIVE_CC} == "gcc"
@@ -73,6 +78,14 @@ CPPFLAGS.t_subr_prf.c=	-Wno-pointer-sign
 CPPFLAGS.t_subr_prf.c+=	-Wno-error=format-truncation
 .endif
 
+SANITIZER_RENAME_CLASSES+=		t_subr_prf
+SANITIZER_RENAME_FILES.t_subr_prf+=	t_subr_prf.c
+SANITIZER_RENAME_SYMBOL.t_subr_prf+=	snprintf
+SANITIZER_RENAME_SYMBOL.t_subr_prf+=	vsnprintf
+SANITIZER_RENAME_SYMBOL.t_subr_prf+=	sprintf
+SANITIZER_RENAME_SYMBOL.t_subr_prf+=	vsnprintf
+SANITIZER_RENAME_SYMBOL.t_subr_prf+=	vasprintf
+
 CLEANFILES+=	t_subr_prf.c
 
 LDADD.h_segv+=	-lm



CVS commit: src/tests/kernel

2019-06-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jun  7 21:18:16 UTC 2019

Modified Files:
src/tests/kernel: Makefile
Added Files:
src/tests/kernel: t_origin.sh

Log Message:
Add a $ORIGIN test


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/tests/kernel/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/kernel/t_origin.sh

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

Modified files:

Index: src/tests/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.59 src/tests/kernel/Makefile:1.60
--- src/tests/kernel/Makefile:1.59	Sat Jun  1 15:49:02 2019
+++ src/tests/kernel/Makefile	Fri Jun  7 17:18:16 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.59 2019/06/01 19:49:02 kamil Exp $
+# $NetBSD: Makefile,v 1.60 2019/06/07 21:18:16 christos Exp $
 
 NOMAN=		# defined
 
@@ -25,6 +25,7 @@ TESTS_SH+=	t_umountstress
 TESTS_SH+=	t_ps_strings
 TESTS_SH+=	t_trapsignal
 TESTS_SH+=	t_interp
+TESTS_SH+=	t_origin
 TESTS_SH+=	t_procpath
 
 BINDIR=		${TESTSDIR}

Added files:

Index: src/tests/kernel/t_origin.sh
diff -u /dev/null src/tests/kernel/t_origin.sh:1.1
--- /dev/null	Fri Jun  7 17:18:16 2019
+++ src/tests/kernel/t_origin.sh	Fri Jun  7 17:18:16 2019
@@ -0,0 +1,122 @@
+#	$NetBSD: t_origin.sh,v 1.1 2019/06/07 21:18:16 christos Exp $
+#
+# Copyright (c) 2019 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Christos Zoulas.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+atf_test_case origin_simple
+origin_simple_head() {
+	atf_set "descr" 'test native $ORIGIN support'
+	atf_set "require.progs" "cc"
+}
+
+atf_test_case origin_simple_32
+origin_simple_32_head() {
+	atf_set "descr" 'test $ORIGIN support in 32 bit mode'
+	atf_set "require.progs" "cc"
+}
+
+make_code() {
+	cat > origin$1.c << _EOF
+#include 
+#include 
+#include 
+#include 
+
+static const char lib[] = "libfoo$1.so";
+int
+main(void)
+{
+	void *h = dlopen(lib, RTLD_NOW);
+	if (h == NULL)
+		errx(EXIT_FAILURE, "dlopen: %s", dlerror());
+	dlclose(h);
+	return EXIT_SUCCESS;
+}
+_EOF
+
+cat > libfoo$1.c << EOF
+void foo(void);
+void foo(void)
+{
+}
+EOF
+}
+
+test_code() {
+	local m32
+	if [ -z "$1" ]; then
+		m32=
+	else
+		m32=-m32
+	fi
+	atf_check -s exit:0 -o empty -e empty \
+	cc -fPIC $m32 -o origin$1 origin$1.c -Wl,-R'$ORIGIN'
+	atf_check -s exit:0 -o empty -e empty \
+	cc -shared -fPIC $m32 -o libfoo$1.so libfoo$1.c 
+	atf_check -s exit:0 -o empty -e empty ./origin$1
+}
+
+check32() {
+	# check whether this arch is 64bit
+	if ! cc -dM -E - < /dev/null | fgrep -q _LP64; then
+		atf_skip "this is not a 64 bit architecture"
+		return 1
+	fi
+	if ! cc -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
+		atf_skip "c++ -m32 not supported on this architecture"
+		return 1
+	else
+		if fgrep -q _LP64 ./def32; then
+			atf_fail "c++ -m32 does not generate netbsd32 binaries"
+			return 1
+		fi
+		return 0
+	fi
+}
+
+origin_simple_body() {
+	make_code ""
+	test_code ""
+
+}
+
+origin_simple_32_body() {
+	if ! check32; then
+		return
+	fi
+	make_code "32"
+	test_code "32"
+}
+
+
+atf_init_test_cases()
+{
+
+	atf_add_test_case origin_simple
+	atf_add_test_case origin_simple_32
+}



CVS commit: src/tests/kernel

2019-06-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jun  7 21:18:16 UTC 2019

Modified Files:
src/tests/kernel: Makefile
Added Files:
src/tests/kernel: t_origin.sh

Log Message:
Add a $ORIGIN test


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/tests/kernel/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/kernel/t_origin.sh

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



CVS commit: src/tests/kernel

2019-06-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Jun  1 22:18:23 UTC 2019

Modified Files:
src/tests/kernel: t_proccwd.c

Log Message:
Fix a mistake in a test for KERN_PROC_CWD

Emit properly ENOENT scenario in chroot. For some reason the final patch
did not hit the tree.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/t_proccwd.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/kernel/t_proccwd.c
diff -u src/tests/kernel/t_proccwd.c:1.1 src/tests/kernel/t_proccwd.c:1.2
--- src/tests/kernel/t_proccwd.c:1.1	Sat Jun  1 19:49:02 2019
+++ src/tests/kernel/t_proccwd.c	Sat Jun  1 22:18:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_proccwd.c,v 1.1 2019/06/01 19:49:02 kamil Exp $	*/
+/*	$NetBSD: t_proccwd.c,v 1.2 2019/06/01 22:18:23 kamil Exp $	*/
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -28,7 +28,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2019\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_proccwd.c,v 1.1 2019/06/01 19:49:02 kamil Exp $");
+__RCSID("$NetBSD: t_proccwd.c,v 1.2 2019/06/01 22:18:23 kamil Exp $");
 
 #include 
 #include 
@@ -84,7 +84,7 @@ ATF_TC_BODY(prompt_pid, tc)
 		ATF_REQUIRE_EQ(strlen(buf) + 1, prompted_len);
 		ATF_REQUIRE(strlen(buf) > 0);
 
-		if (t[i] == -1 || t[i] == getpid() || t[i] == getppid()) {
+		if (t[i] == -1 || t[i] == getpid()) {
 			getcwd(cwdbuf, MAXPATHLEN);
 			ATF_REQUIRE_EQ(strcmp(buf, cwdbuf), 0);
 			ATF_REQUIRE(strlen(buf) > strlen("/"));
@@ -133,7 +133,7 @@ ATF_TC_BODY(chroot, tc)
 		ASSERT(chroot(buf) == 0);
 
 		errno = 0;
-		rv = getproccwd(NULL, &len, pid_one);
+		rv = getproccwd(buf, &len, pid_one);
 		ASSERT(rv == -1);
 		ASSERT(errno == ENOENT);
 



CVS commit: src/tests/kernel

2019-06-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Jun  1 22:18:23 UTC 2019

Modified Files:
src/tests/kernel: t_proccwd.c

Log Message:
Fix a mistake in a test for KERN_PROC_CWD

Emit properly ENOENT scenario in chroot. For some reason the final patch
did not hit the tree.


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

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



CVS commit: src/tests/kernel

2019-05-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 21 04:09:46 UTC 2019

Modified Files:
src/tests/kernel: gen_t_subr_prf

Log Message:
add printf attribute


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/kernel/gen_t_subr_prf

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



CVS commit: src/tests/kernel

2019-05-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 21 04:10:20 UTC 2019

Modified Files:
src/tests/kernel: gen_t_subr_prf

Log Message:
unexpand


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/gen_t_subr_prf

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



CVS commit: src/tests/kernel

2019-05-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 21 04:09:46 UTC 2019

Modified Files:
src/tests/kernel: gen_t_subr_prf

Log Message:
add printf attribute


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/kernel/gen_t_subr_prf

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

Modified files:

Index: src/tests/kernel/gen_t_subr_prf
diff -u src/tests/kernel/gen_t_subr_prf:1.6 src/tests/kernel/gen_t_subr_prf:1.7
--- src/tests/kernel/gen_t_subr_prf:1.6	Mon May 20 23:46:45 2019
+++ src/tests/kernel/gen_t_subr_prf	Tue May 21 00:09:46 2019
@@ -122,9 +122,7 @@ ATF_TC_HEAD(vasprintf_print, tc)
 atf_tc_set_md_var(tc, "descr", "checks vasprintf works");
 }
 
-int vasp_helper(char **, const char *, ...);
-
-int
+static int __printflike(2, 3)
 vasp_helper(char **buf, const char *fmt, ...)
 {
 	va_list ap;



CVS commit: src/tests/kernel

2019-05-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 21 04:10:20 UTC 2019

Modified Files:
src/tests/kernel: gen_t_subr_prf

Log Message:
unexpand


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/gen_t_subr_prf

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

Modified files:

Index: src/tests/kernel/gen_t_subr_prf
diff -u src/tests/kernel/gen_t_subr_prf:1.7 src/tests/kernel/gen_t_subr_prf:1.8
--- src/tests/kernel/gen_t_subr_prf:1.7	Tue May 21 00:09:46 2019
+++ src/tests/kernel/gen_t_subr_prf	Tue May 21 00:10:20 2019
@@ -23,7 +23,7 @@ cat << _EOF > $2
 #undef putchar
 #define putchar xputchar
 
-#define	kmem_alloc(n, f)	malloc(n)
+#define kmem_alloc(n, f)	malloc(n)
 
 static int putchar(char c, int foo, void *b)
 {
@@ -57,7 +57,7 @@ static void (*v_flush)(void) = empty;
 ATF_TC(snprintf_print);
 ATF_TC_HEAD(snprintf_print, tc)
 {
-atf_tc_set_md_var(tc, "descr", "checks snprintf print");
+	atf_tc_set_md_var(tc, "descr", "checks snprintf print");
 }
  
 ATF_TC_BODY(snprintf_print, tc)
@@ -74,7 +74,7 @@ ATF_TC_BODY(snprintf_print, tc)
 ATF_TC(snprintf_print_overflow);
 ATF_TC_HEAD(snprintf_print_overflow, tc)
 {
-atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow");
+	atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow");
 }
  
 ATF_TC_BODY(snprintf_print_overflow, tc)
@@ -91,7 +91,7 @@ ATF_TC_BODY(snprintf_print_overflow, tc)
 ATF_TC(snprintf_count);
 ATF_TC_HEAD(snprintf_count, tc)
 {
-atf_tc_set_md_var(tc, "descr", "checks snprintf count");
+	atf_tc_set_md_var(tc, "descr", "checks snprintf count");
 }
  
 ATF_TC_BODY(snprintf_count, tc)
@@ -105,7 +105,7 @@ ATF_TC_BODY(snprintf_count, tc)
 ATF_TC(snprintf_count_overflow);
 ATF_TC_HEAD(snprintf_count_overflow, tc)
 {
-atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow");
+	atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow");
 }
  
 ATF_TC_BODY(snprintf_count_overflow, tc)
@@ -119,7 +119,7 @@ ATF_TC_BODY(snprintf_count_overflow, tc)
 ATF_TC(vasprintf_print);
 ATF_TC_HEAD(vasprintf_print, tc)
 {
-atf_tc_set_md_var(tc, "descr", "checks vasprintf works");
+	atf_tc_set_md_var(tc, "descr", "checks vasprintf works");
 }
 
 static int __printflike(2, 3)
@@ -149,13 +149,13 @@ ATF_TC_BODY(vasprintf_print, tc)
 
 ATF_TP_ADD_TCS(tp)
 {
-ATF_TP_ADD_TC(tp, snprintf_print);
-ATF_TP_ADD_TC(tp, snprintf_print_overflow);
-ATF_TP_ADD_TC(tp, snprintf_count);
-ATF_TP_ADD_TC(tp, snprintf_count_overflow);
+	ATF_TP_ADD_TC(tp, snprintf_print);
+	ATF_TP_ADD_TC(tp, snprintf_print_overflow);
+	ATF_TP_ADD_TC(tp, snprintf_count);
+	ATF_TP_ADD_TC(tp, snprintf_count_overflow);
 	ATF_TP_ADD_TC(tp, vasprintf_print);
 
-return atf_no_error();
+	return atf_no_error();
 }
 _EOF
 



CVS commit: src/tests/kernel

2019-05-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue May 21 03:46:45 UTC 2019

Modified Files:
src/tests/kernel: gen_t_subr_prf

Log Message:
Make the t_subr_prf test build after changes to sys/kern/subr_prf.c
and while here add a simple test for the new kernel vasprintf().


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/gen_t_subr_prf

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



CVS commit: src/tests/kernel

2019-05-20 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue May 21 03:46:45 UTC 2019

Modified Files:
src/tests/kernel: gen_t_subr_prf

Log Message:
Make the t_subr_prf test build after changes to sys/kern/subr_prf.c
and while here add a simple test for the new kernel vasprintf().


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/gen_t_subr_prf

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

Modified files:

Index: src/tests/kernel/gen_t_subr_prf
diff -u src/tests/kernel/gen_t_subr_prf:1.5 src/tests/kernel/gen_t_subr_prf:1.6
--- src/tests/kernel/gen_t_subr_prf:1.5	Sun Feb  3 10:48:47 2019
+++ src/tests/kernel/gen_t_subr_prf	Tue May 21 03:46:45 2019
@@ -6,6 +6,7 @@ cat << _EOF > $2
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -16,11 +17,14 @@ cat << _EOF > $2
 #undef vsnprintf
 #undef sprintf
 #undef vsprintf
+#undef vasprintf
 
 #define KPRINTF_BUFSIZE 1024
 #undef putchar
 #define putchar xputchar
 
+#define	kmem_alloc(n, f)	malloc(n)
+
 static int putchar(char c, int foo, void *b)
 {
 	return fputc(c, stderr);
@@ -112,12 +116,46 @@ ATF_TC_BODY(snprintf_count_overflow, tc)
 	ATF_CHECK_EQ(i, 16);
 }
 
+ATF_TC(vasprintf_print);
+ATF_TC_HEAD(vasprintf_print, tc)
+{
+atf_tc_set_md_var(tc, "descr", "checks vasprintf works");
+}
+
+int vasp_helper(char **, const char *, ...);
+
+int
+vasp_helper(char **buf, const char *fmt, ...)
+{
+	va_list ap;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vasprintf(buf, fmt, ap);
+	va_end(ap);
+	return ret;
+}
+
+ATF_TC_BODY(vasprintf_print, tc)
+{
+	int i;
+	char *buf;
+
+	buf = NULL;
+	i =  vasp_helper(&buf, "N=%d C=%c S=%s", 7, 'x', "abc");
+	ATF_CHECK_EQ(i, 13);
+	ATF_CHECK(buf != NULL);
+	ATF_CHECK_STREQ(buf, "N=7 C=x S=abc");
+	free(buf);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 ATF_TP_ADD_TC(tp, snprintf_print);
 ATF_TP_ADD_TC(tp, snprintf_print_overflow);
 ATF_TP_ADD_TC(tp, snprintf_count);
 ATF_TP_ADD_TC(tp, snprintf_count_overflow);
+	ATF_TP_ADD_TC(tp, vasprintf_print);
 
 return atf_no_error();
 }



re: CVS commit: src/tests/kernel

2019-01-13 Thread matthew green
> Modified Files:
>   src/tests/kernel: t_timeleft.c
> 
> Log Message:
> add call error checks, requested by mrg@

thanks!


re: CVS commit: src/tests/kernel

2019-01-13 Thread Christos Zoulas
On Jan 14,  9:29am, m...@eterna.com.au (matthew green) wrote:
-- Subject: re: CVS commit: src/tests/kernel

| "Christos Zoulas" writes:
| > Module Name:src
| > Committed By:   christos
| > Date:   Sun Jan 13 15:36:57 UTC 2019
| > 
| > Modified Files:
| > src/tests/kernel: t_timeleft.c
| > 
| > Log Message:
| > Increase the timeout a bit, and make sure we join so that there is no
| > race.
| 
| i notice both pthread_kill() and pthread_join() calls here do 
| not have their return value checked.
| 
| any particular reason?  shouldn't their failiure also be a
| test failure?

Nope, I will add them.

christos


re: CVS commit: src/tests/kernel

2019-01-13 Thread matthew green
"Christos Zoulas" writes:
> Module Name:  src
> Committed By: christos
> Date: Sun Jan 13 15:36:57 UTC 2019
> 
> Modified Files:
>   src/tests/kernel: t_timeleft.c
> 
> Log Message:
> Increase the timeout a bit, and make sure we join so that there is no
> race.

i notice both pthread_kill() and pthread_join() calls here do 
not have their return value checked.

any particular reason?  shouldn't their failiure also be a
test failure?


.mrg.


Re: CVS commit: src/tests/kernel

2016-12-06 Thread Kamil Rytarowski


On 07.12.2016 01:08, Christos Zoulas wrote:
> In article <0a6e53d7-4f6e-6e25-cd61-2342e1c4e...@gmx.com>,
> Kamil Rytarowski   wrote:
>> -=-=-=-=-=-
>> -=-=-=-=-=-
>>
>> On 06.12.2016 19:59, Christos Zoulas wrote:
>>> Module Name:src
>>> Committed By:   christos
>>> Date:   Tue Dec  6 18:59:00 UTC 2016
>>>
>>> Modified Files:
>>> src/tests/kernel: t_ptrace_wait.c
>>>
>>> Log Message:
>>> switch to using fork so we can see the child output.
>>>
>>
>> atf_utils_fork() still works however... it outputs to .txt files, one
>> file is saved from stdout and the other from stderr.
> 
> No, because it overwrites files on multiuple forks and you lose the
> order of printing.
> 
>> Maybe we should rework atf_utils_fork() in ATF to just work like
>> fork(2), with setup for buffering and exit on failure?
> 
> Well, I was thinking of enhancing it but then I decided against it.
> (too much work for little benefit).
> 
> christos
> 

I see, I will adapt tests/kernel/arch/amd64 to follow this change.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2016-12-06 Thread Christos Zoulas
In article <0a6e53d7-4f6e-6e25-cd61-2342e1c4e...@gmx.com>,
Kamil Rytarowski   wrote:
>-=-=-=-=-=-
>-=-=-=-=-=-
>
>On 06.12.2016 19:59, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Tue Dec  6 18:59:00 UTC 2016
>> 
>> Modified Files:
>>  src/tests/kernel: t_ptrace_wait.c
>> 
>> Log Message:
>> switch to using fork so we can see the child output.
>> 
>
>atf_utils_fork() still works however... it outputs to .txt files, one
>file is saved from stdout and the other from stderr.

No, because it overwrites files on multiuple forks and you lose the
order of printing.

>Maybe we should rework atf_utils_fork() in ATF to just work like
>fork(2), with setup for buffering and exit on failure?

Well, I was thinking of enhancing it but then I decided against it.
(too much work for little benefit).

christos



Re: CVS commit: src/tests/kernel

2016-12-06 Thread Kamil Rytarowski
On 06.12.2016 19:59, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Tue Dec  6 18:59:00 UTC 2016
> 
> Modified Files:
>   src/tests/kernel: t_ptrace_wait.c
> 
> Log Message:
> switch to using fork so we can see the child output.
> 

atf_utils_fork() still works however... it outputs to .txt files, one
file is saved from stdout and the other from stderr.

Maybe we should rework atf_utils_fork() in ATF to just work like
fork(2), with setup for buffering and exit on failure?



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2016-11-25 Thread Christos Zoulas
On Nov 26,  3:24am, n...@gmx.com (Kamil Rytarowski) wrote:
-- Subject: Re: CVS commit: src/tests/kernel

| PT_READ_D and PT_READ_I read single int according to documentation.
| 
| In tests io_read_d* io_read_i* data blocks are printed with appropriate
| PRIxN.
| 
| I cannot spot a mistake in the tests.
| 
| I'm going to replace %x with %#x.

Ok, so the minimum unit of reading is an int. Then the code is correct.

christos


Re: CVS commit: src/tests/kernel

2016-11-25 Thread Kamil Rytarowski
On 25.11.2016 23:41, Christos Zoulas wrote:
> In article ,
> Christos Zoulas  wrote:
>> In article <20161125200105.5dbb4f...@cvs.netbsd.org>,
>> Kamil Rytarowski  wrote:
>>> -=-=-=-=-=-
>>>
>>> Module Name:src
>>> Committed By:   kamil
>>> Date:   Fri Nov 25 20:01:05 UTC 2016
>>>
>>> Modified Files:
>>> src/tests/kernel: t_ptrace_wait.c
>>>
>>> Log Message:
>>> Fix several printf(3)-like functions usage with printing integers
>>>
>>> Integers as hex shall no be printed with PRIx8, but with plain "x".
>>
>> I would use %#x...
> 
> And I am not sure that passing 'int x; ptrace(.., &x, ...);' is right when
> reading/writing 1 byte. It works on x86 if you initialize x = 0, but
> it will will not work on sparc64, I think. Perhaps you need to pass
> 'uint8_t x; ptrace(, ..., &x, ...);' Then the printf format is right :-)
> 
> christos
> 

PT_READ_D and PT_READ_I read single int according to documentation.

In tests io_read_d* io_read_i* data blocks are printed with appropriate
PRIxN.

I cannot spot a mistake in the tests.

I'm going to replace %x with %#x.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2016-11-25 Thread Christos Zoulas
In article ,
Christos Zoulas  wrote:
>In article <20161125200105.5dbb4f...@cvs.netbsd.org>,
>Kamil Rytarowski  wrote:
>>-=-=-=-=-=-
>>
>>Module Name:  src
>>Committed By: kamil
>>Date: Fri Nov 25 20:01:05 UTC 2016
>>
>>Modified Files:
>>  src/tests/kernel: t_ptrace_wait.c
>>
>>Log Message:
>>Fix several printf(3)-like functions usage with printing integers
>>
>>Integers as hex shall no be printed with PRIx8, but with plain "x".
>
>I would use %#x...

And I am not sure that passing 'int x; ptrace(.., &x, ...);' is right when
reading/writing 1 byte. It works on x86 if you initialize x = 0, but
it will will not work on sparc64, I think. Perhaps you need to pass
'uint8_t x; ptrace(, ..., &x, ...);' Then the printf format is right :-)

christos



Re: CVS commit: src/tests/kernel

2016-11-25 Thread Christos Zoulas
In article <20161125200105.5dbb4f...@cvs.netbsd.org>,
Kamil Rytarowski  wrote:
>-=-=-=-=-=-
>
>Module Name:   src
>Committed By:  kamil
>Date:  Fri Nov 25 20:01:05 UTC 2016
>
>Modified Files:
>   src/tests/kernel: t_ptrace_wait.c
>
>Log Message:
>Fix several printf(3)-like functions usage with printing integers
>
>Integers as hex shall no be printed with PRIx8, but with plain "x".

I would use %#x...

christos



Re: CVS commit: src/tests/kernel

2016-11-09 Thread Kamil Rytarowski


On 10.11.2016 03:44, matthew green wrote:
> it would actually be useful to have a testcase that ran iff
> root *and* securelevel >= 0 and tests it is unable to attach
> to pid 1.
> 
> thanks.
> 
> 
> .mrg.
> 

OK, I will have a look at it.



signature.asc
Description: OpenPGP digital signature


re: CVS commit: src/tests/kernel

2016-11-09 Thread matthew green
it would actually be useful to have a testcase that ran iff
root *and* securelevel >= 0 and tests it is unable to attach
to pid 1.

thanks.


.mrg.


Re: CVS commit: src/tests/kernel

2016-11-09 Thread Kamil Rytarowski


On 10.11.2016 03:28, Paul Goyette wrote:
> On Thu, 10 Nov 2016, matthew green wrote:
> 
 also, root can't attach to pid1 if securelevel is >= 0.
>>>
>>> To adjust securelevel this test would need to be modified to run under
>>> rump ...  We wouldn't want the test to manipulate securelevel of the
>>> running system.
>>
>> s/wouldn't want/*can't* by design have/.
>>
>> i don't know that running under rump is useful here.  i certainly
>> would not trust ptrace tests in a rump to cover it properly.  this
>> test should just be skipped if securelevel >= 0.  fact is that
>> very few systems run with securelevel these days, so it's a small
>> portion of systems that won't have it.
> 
> Yeah, rump probably doesn't make much sense here.  Skipping the test
> (with atf_tc_skip(...) of course) is likely the best solution.
> 
> 

This test is already enforcing unprivileged user. For now, I leave all
other rump and securelevel use-cases.



signature.asc
Description: OpenPGP digital signature


re: CVS commit: src/tests/kernel

2016-11-09 Thread Paul Goyette

On Thu, 10 Nov 2016, matthew green wrote:


also, root can't attach to pid1 if securelevel is >= 0.


To adjust securelevel this test would need to be modified to run under
rump ...  We wouldn't want the test to manipulate securelevel of the
running system.


s/wouldn't want/*can't* by design have/.

i don't know that running under rump is useful here.  i certainly
would not trust ptrace tests in a rump to cover it properly.  this
test should just be skipped if securelevel >= 0.  fact is that
very few systems run with securelevel these days, so it's a small
portion of systems that won't have it.


Yeah, rump probably doesn't make much sense here.  Skipping the test 
(with atf_tc_skip(...) of course) is likely the best solution.



+--+--++
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:  |
| (Retired)| FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+--+--++


re: CVS commit: src/tests/kernel

2016-11-09 Thread matthew green
> >> Log Message:
> >> Add new tests attach_pid0 and attach_pid1 to t_ptrace
> >>
> >> attach_pid0 asserts that it is not valid to attach PID 0 as it is a special
> >> kernel process.
> >>
> >> assert_pid1 asserts that non-root user cannot attach to PID 1 as it is the
> >> /dev/init process. This tests is skipped if run as root.
> >
> > also, root can't attach to pid1 if securelevel is >= 0.
> 
> To adjust securelevel this test would need to be modified to run under 
> rump ...  We wouldn't want the test to manipulate securelevel of the 
> running system.

s/wouldn't want/*can't* by design have/.

i don't know that running under rump is useful here.  i certainly
would not trust ptrace tests in a rump to cover it properly.  this
test should just be skipped if securelevel >= 0.  fact is that
very few systems run with securelevel these days, so it's a small
portion of systems that won't have it.


.mrg.



re: CVS commit: src/tests/kernel

2016-11-09 Thread Paul Goyette

On Thu, 10 Nov 2016, matthew green wrote:


"Kamil Rytarowski" writes:

Module Name:src
Committed By:   kamil
Date:   Sun Nov  6 16:24:16 UTC 2016

Modified Files:
src/tests/kernel: t_ptrace.c

Log Message:
Add new tests attach_pid0 and attach_pid1 to t_ptrace

attach_pid0 asserts that it is not valid to attach PID 0 as it is a special
kernel process.

assert_pid1 asserts that non-root user cannot attach to PID 1 as it is the
/dev/init process. This tests is skipped if run as root.


also, root can't attach to pid1 if securelevel is >= 0.


To adjust securelevel this test would need to be modified to run under 
rump ...  We wouldn't want the test to manipulate securelevel of the 
running system.



I'm wondering how many of the other test cases would be better if 
running under rump?



+--+--++
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:  |
| (Retired)| FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+--+--++


re: CVS commit: src/tests/kernel

2016-11-09 Thread matthew green
"Kamil Rytarowski" writes:
> Module Name:  src
> Committed By: kamil
> Date: Sun Nov  6 16:24:16 UTC 2016
> 
> Modified Files:
>   src/tests/kernel: t_ptrace.c
> 
> Log Message:
> Add new tests attach_pid0 and attach_pid1 to t_ptrace
> 
> attach_pid0 asserts that it is not valid to attach PID 0 as it is a special
> kernel process.
> 
> assert_pid1 asserts that non-root user cannot attach to PID 1 as it is the
> /dev/init process. This tests is skipped if run as root.

also, root can't attach to pid1 if securelevel is >= 0.


.mrg.


Re: CVS commit: src/tests/kernel

2016-11-06 Thread Kamil Rytarowski


On 06.11.2016 18:26, Nicolas Joly wrote:
> On Sun, Nov 06, 2016 at 11:56:31PM +0700, Robert Elz wrote:
>> Date:Sun, 6 Nov 2016 16:24:16 +
>> From:"Kamil Rytarowski" 
>> Message-ID:  <20161106162416.95d77f...@cvs.netbsd.org>
>>
>>   | assert_pid1 asserts that non-root user cannot attach to PID 1 as it is 
>> the
>>   | /dev/init process. This tests is skipped if run as root.
>>
>> There's no need to skip it, just
>>
>>  child=fork();   /* err if -1 */
>>  if (child == 0) {
>>  (void)setuid(10);
>>  if (ptrace(.) < 0)
>>  _exit(errno);
>>  else
>>  _exit(0);
>>  }
>>  waitpid(child, &status, 0);
>>  /* and check status */
>>
>> If you're root, the setuid() works, and the child isn't root any more.
>> if you happened to be uid(10), the setuid() is a no-op, if you were some
>> other user the setuid() fails, but you don't care.
> 
> Or use dedicated ATF properties :
> 
>   atf_tc_set_md_var(tc, "require.user", "unprivileged");
> 
> Documented in atf-test-case(4).
> 

It worked, thanks!



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2016-11-06 Thread Nicolas Joly
On Sun, Nov 06, 2016 at 11:56:31PM +0700, Robert Elz wrote:
> Date:Sun, 6 Nov 2016 16:24:16 +
> From:"Kamil Rytarowski" 
> Message-ID:  <20161106162416.95d77f...@cvs.netbsd.org>
> 
>   | assert_pid1 asserts that non-root user cannot attach to PID 1 as it is the
>   | /dev/init process. This tests is skipped if run as root.
> 
> There's no need to skip it, just
> 
>   child=fork();   /* err if -1 */
>   if (child == 0) {
>   (void)setuid(10);
>   if (ptrace(.) < 0)
>   _exit(errno);
>   else
>   _exit(0);
>   }
>   waitpid(child, &status, 0);
>   /* and check status */
> 
> If you're root, the setuid() works, and the child isn't root any more.
> if you happened to be uid(10), the setuid() is a no-op, if you were some
> other user the setuid() fails, but you don't care.

Or use dedicated ATF properties :

  atf_tc_set_md_var(tc, "require.user", "unprivileged");

Documented in atf-test-case(4).

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.


Re: CVS commit: src/tests/kernel

2016-11-06 Thread Kamil Rytarowski


On 06.11.2016 17:56, Robert Elz wrote:
> Date:Sun, 6 Nov 2016 16:24:16 +
> From:"Kamil Rytarowski" 
> Message-ID:  <20161106162416.95d77f...@cvs.netbsd.org>
> 
>   | assert_pid1 asserts that non-root user cannot attach to PID 1 as it is the
>   | /dev/init process. This tests is skipped if run as root.
> 
> There's no need to skip it, just
> 
>   child=fork();   /* err if -1 */
>   if (child == 0) {
>   (void)setuid(10);
>   if (ptrace(.) < 0)
>   _exit(errno);
>   else
>   _exit(0);
>   }
>   waitpid(child, &status, 0);
>   /* and check status */
> 
> If you're root, the setuid() works, and the child isn't root any more.
> if you happened to be uid(10), the setuid() is a no-op, if you were some
> other user the setuid() fails, but you don't care.
> 
> kre
> 

Good point.

I noted a sequence in other tests like:

struct passwd *pw;
pw = getpwnam("nobody");
if (pid == 0) {
(void)setuid(pw->pw_uid);
}

I will make use of something similar.

I was evaluating whether it's possible to PT_ATTACH to getpid() [I will
check documentation later]. It doesn't make sense but we shouldn't hang.
I will test it and add an entry for it in the t_ptrace code.

Another idea is to test chroot(8) attach failure.

I'm inventing potential tests without the usage of wait(2)-like
functions, and without help of hacks like sleep(3) - such test would be
waste of precious time of execution of the ATF framework and the
behavior would not be practical.

My intention is to move all other tests to ptrace_wait* files.

Thank you for your suggestions!



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2016-11-06 Thread Robert Elz
Date:Sun, 6 Nov 2016 16:24:16 +
From:"Kamil Rytarowski" 
Message-ID:  <20161106162416.95d77f...@cvs.netbsd.org>

  | assert_pid1 asserts that non-root user cannot attach to PID 1 as it is the
  | /dev/init process. This tests is skipped if run as root.

There's no need to skip it, just

child=fork();   /* err if -1 */
if (child == 0) {
(void)setuid(10);
if (ptrace(.) < 0)
_exit(errno);
else
_exit(0);
}
waitpid(child, &status, 0);
/* and check status */

If you're root, the setuid() works, and the child isn't root any more.
if you happened to be uid(10), the setuid() is a no-op, if you were some
other user the setuid() fails, but you don't care.

kre



Re: CVS commit: src/tests/kernel

2016-11-06 Thread Christos Zoulas
On Nov 6,  1:48pm, n...@gmx.com (Kamil Rytarowski) wrote:
-- Subject: Re: CVS commit: src/tests/kernel

| My plan is to split t_ptrace into t_ptrace_wait, t_ptrace_waitpid etc. I
| will try to avoid duplication of the code and prepare something like the
| t_mutex and t_timedmutex pair.
| 
| To keep the t_ptrace file there, I will add a new test not using any of
| the wait(2) functions.

Ok, sounds good.

christos


Re: CVS commit: src/tests/kernel

2016-11-06 Thread Kamil Rytarowski
On 03.11.2016 18:08, Kamil Rytarowski wrote:
> 
> For now I'm focusing on functional tests, which are equivalent to
> FreeBSD capabilities. This is why I will reschedule combination of
> wait(2) usage functions for later and move to on other ptrace(2) use-cases.
> 

With recent reported issues I'm convinced to cover the whole
wait(2)-family of interfaces in t_ptrace.

There is a need to sort out all possible issues.

My plan is to split t_ptrace into t_ptrace_wait, t_ptrace_waitpid etc. I
will try to avoid duplication of the code and prepare something like the
t_mutex and t_timedmutex pair.

To keep the t_ptrace file there, I will add a new test not using any of
the wait(2) functions.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2016-11-03 Thread Kamil Rytarowski
On 03.11.2016 15:24, Christos Zoulas wrote:
> In article <19801.1478175...@andromeda.noi.kre.to>,
> Robert Elz   wrote:
>>
>> Which is actually correct?   (That is, which makes more sense, if it is
>> not actually specified somewhere.)
>>
>> Please make the tests test correct behaviour, not just what NetBSD happens
>> to do today.   If NetBSD is doing something that is not correct, file a PR
>> and use atf_expect_fail() referencing the PR so it can get fixed, someday.
>>
>> Of course, it is also possible that the linux behaviour is the one that's
>> wrong.
>>
>>  | This code covers (uncovers issues?) WIFCONTINUED() and is the last planned
>>  | test in the ptraceme category.
>>
>> It would be kind of nice to have some (similar) tests that use waitid()
>> (or wait6()) instead of waitpid() given that waitid() is the more modern
>> (and more flexible) interface.
> 
> Well, having both WIFSTOPPED and WIFCONTINUED set does not make a lot of 
> sense.
> It would seem that the right behavior is that WIFCONTINUED should be set
> and WIFSTOPPED not set after PT_CONTINUE (unless the child stopped again).
> 
> Anyway, for FreeBSD WIFSTOPPED is set and WIFCONTINUED is not, so my guess
> is that the child is stopped again and we are wrong somewhere forgetting
> to clear the continued flag.
> 
> christos
> 

I will file a bug for it assuming that Linux (and apparently FreeBSD) is
correct here and adjust it in the test-case.

For now I'm focusing on functional tests, which are equivalent to
FreeBSD capabilities. This is why I will reschedule combination of
wait(2) usage functions for later and move to on other ptrace(2) use-cases.

I will replace sys_errlist(3) with strerror(3).



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/tests/kernel

2016-11-03 Thread Christos Zoulas
In article <19801.1478175...@andromeda.noi.kre.to>,
Robert Elz   wrote:
>
>Which is actually correct?   (That is, which makes more sense, if it is
>not actually specified somewhere.)
>
>Please make the tests test correct behaviour, not just what NetBSD happens
>to do today.   If NetBSD is doing something that is not correct, file a PR
>and use atf_expect_fail() referencing the PR so it can get fixed, someday.
>
>Of course, it is also possible that the linux behaviour is the one that's
>wrong.
>
>  | This code covers (uncovers issues?) WIFCONTINUED() and is the last planned
>  | test in the ptraceme category.
>
>It would be kind of nice to have some (similar) tests that use waitid()
>(or wait6()) instead of waitpid() given that waitid() is the more modern
>(and more flexible) interface.

Well, having both WIFSTOPPED and WIFCONTINUED set does not make a lot of sense.
It would seem that the right behavior is that WIFCONTINUED should be set
and WIFSTOPPED not set after PT_CONTINUE (unless the child stopped again).

Anyway, for FreeBSD WIFSTOPPED is set and WIFCONTINUED is not, so my guess
is that the child is stopped again and we are wrong somewhere forgetting
to clear the continued flag.

christos



Re: CVS commit: src/tests/kernel

2016-11-03 Thread Robert Elz
Date:Thu, 3 Nov 2016 11:20:45 +
From:"Kamil Rytarowski" 
Message-ID:  <20161103112045.a48aaf...@cvs.netbsd.org>

  | This test verifies calling raise(2) with the SIGCONT argument in the child.
  | The parent is notified with it and asserts that WIFCONTINUED() and
  | WIFSTOPPED() are both set.
  | 
  | XXX: This behavior is surprising. Linux for the same code-path returns false
  | for WIFCONTINUED() and true for WIFSTOPPED().

Which is actually correct?   (That is, which makes more sense, if it is
not actually specified somewhere.)

Please make the tests test correct behaviour, not just what NetBSD happens
to do today.   If NetBSD is doing something that is not correct, file a PR
and use atf_expect_fail() referencing the PR so it can get fixed, someday.

Of course, it is also possible that the linux behaviour is the one that's
wrong.

  | This code covers (uncovers issues?) WIFCONTINUED() and is the last planned
  | test in the ptraceme category.

It would be kind of nice to have some (similar) tests that use waitid()
(or wait6()) instead of waitpid() given that waitid() is the more modern
(and more flexible) interface.

kre

ps: I notice that the code you included in the commit log references
sys_errlist[] explicitly - please don't do that, use strerror() instead.



Re: CVS commit: src/tests/kernel

2013-02-19 Thread Christos Zoulas
In article <20130219224428.5dd5717...@cvs.netbsd.org>,
Paul Goyette  wrote:
>-=-=-=-=-=-
>
>+  const char *pipe_errmsg = "child: pipe write failed\n";
> 
>   (void)unlink(lockfile);
> 
>@@ -145,8 +146,8 @@ ATF_TC_BODY(randlock, tc)
>   switch (pid[i]) {
>   case 0:
>   if (write(pipe_fd[1], &pipe_out, 1) != 1)
>-  printf("write_pipe(%i): %s", i,
>-  strerror(errno));
>+  write(STDERR_FILENO, pipe_errmsg,
>+  __arraycount(pipe_errmsg));

foo is a pointer so this will print the first sizeof(char *) characters.
Even if you correct it to be char foo[] you need arraycount() - 1 so you
don't print the NUL.

christos



Re: CVS commit: src/tests/kernel

2013-02-19 Thread Joerg Sonnenberger
On Tue, Feb 19, 2013 at 02:45:43PM -0500, Julio Merino wrote:
> On Tue, Feb 19, 2013 at 2:43 PM, Joerg Sonnenberger
>  wrote:
> > On Tue, Feb 19, 2013 at 11:40:22AM -0800, Paul Goyette wrote:
> >> Most of the printf's were already there before this round of
> >> updates, and there's enough differentiation in them to figure out
> >> which process is responsible.  In any case, the printf's aren't
> >> critical to the test (until you need to debug it!).
> >
> > I am talking about the *new* printf in the child process.
> > That should just be a plain write to STDERR_FILENO, it doesn't even have
> > to include any more error details.
> 
> This is pure curiosity: isn't a fflush(stderr) right before the fork()
> enough to make printf() safe in the child? If not, why not?

Depends on the buffering mode it is in. Basically, I consider it a bad
style that should be avoided.

Joerg


Re: CVS commit: src/tests/kernel

2013-02-19 Thread Julio Merino
On Tue, Feb 19, 2013 at 2:43 PM, Joerg Sonnenberger
 wrote:
> On Tue, Feb 19, 2013 at 11:40:22AM -0800, Paul Goyette wrote:
>> Most of the printf's were already there before this round of
>> updates, and there's enough differentiation in them to figure out
>> which process is responsible.  In any case, the printf's aren't
>> critical to the test (until you need to debug it!).
>
> I am talking about the *new* printf in the child process.
> That should just be a plain write to STDERR_FILENO, it doesn't even have
> to include any more error details.

This is pure curiosity: isn't a fflush(stderr) right before the fork()
enough to make printf() safe in the child? If not, why not?

-- 
Julio Merino / @jmmv


Re: CVS commit: src/tests/kernel

2013-02-19 Thread Joerg Sonnenberger
On Tue, Feb 19, 2013 at 11:40:22AM -0800, Paul Goyette wrote:
> Most of the printf's were already there before this round of
> updates, and there's enough differentiation in them to figure out
> which process is responsible.  In any case, the printf's aren't
> critical to the test (until you need to debug it!).

I am talking about the *new* printf in the child process.
That should just be a plain write to STDERR_FILENO, it doesn't even have
to include any more error details.

Joerg


  1   2   >