Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests + rump_lwproc_newproc -> rump_lwproc_rfork()



details:   https://anonhg.NetBSD.org/src/rev/8f5b5202aeb4
branches:  trunk
changeset: 760316:8f5b5202aeb4
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Jan 02 12:58:17 2011 +0000

description:
+ rump_lwproc_newproc -> rump_lwproc_rfork()
+ add a tess for rump_lwproc_rfork()

diffstat:

 tests/fs/tmpfs/t_renamerace.c  |   4 +-
 tests/fs/vfs/t_renamerace.c    |   6 +-
 tests/rump/rumpkern/t_lwproc.c |  75 ++++++++++++++++++++++++++++++++++++++---
 tests/rump/rumpvfs/t_p2kifs.c  |   4 +-
 tests/syscall/t_cmsg.c         |   7 +--
 5 files changed, 78 insertions(+), 18 deletions(-)

diffs (227 lines):

diff -r c8c735110a7a -r 8f5b5202aeb4 tests/fs/tmpfs/t_renamerace.c
--- a/tests/fs/tmpfs/t_renamerace.c     Sun Jan 02 12:53:13 2011 +0000
+++ b/tests/fs/tmpfs/t_renamerace.c     Sun Jan 02 12:58:17 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_renamerace.c,v 1.9 2010/09/01 19:41:27 pooka Exp $   */
+/*     $NetBSD: t_renamerace.c,v 1.10 2011/01/02 12:58:17 pooka Exp $  */
 
 /*
  * Modified for rump and atf from a program supplied
@@ -105,7 +105,7 @@
        if (rump_sys_mkdir("/dir", 0777) == -1)
                atf_tc_fail_errno("cannot create directory");
 
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        RL(wrkpid = rump_sys_getpid());
        pthread_create(&pt[0], NULL, r2w1, NULL);
        pthread_create(&pt[1], NULL, r2w2, NULL);
diff -r c8c735110a7a -r 8f5b5202aeb4 tests/fs/vfs/t_renamerace.c
--- a/tests/fs/vfs/t_renamerace.c       Sun Jan 02 12:53:13 2011 +0000
+++ b/tests/fs/vfs/t_renamerace.c       Sun Jan 02 12:58:17 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_renamerace.c,v 1.14 2010/11/11 17:44:44 pooka Exp $  */
+/*     $NetBSD: t_renamerace.c,v 1.15 2011/01/02 12:58:17 pooka Exp $  */
 
 /*
  * Modified for rump and atf from a program supplied
@@ -90,7 +90,7 @@
        if (FSTYPE_RUMPFS(tc))
                atf_tc_skip("rename not supported by fs");
 
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        RL(wrkpid = rump_sys_getpid());
 
        RL(rump_sys_chdir(mp));
@@ -133,7 +133,7 @@
            FSTYPE_MSDOS(tc))
                atf_tc_expect_signal(-1, "PR kern/43626");
 
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        RL(wrkpid = rump_sys_getpid());
 
        RL(rump_sys_chdir(mp));
diff -r c8c735110a7a -r 8f5b5202aeb4 tests/rump/rumpkern/t_lwproc.c
--- a/tests/rump/rumpkern/t_lwproc.c    Sun Jan 02 12:53:13 2011 +0000
+++ b/tests/rump/rumpkern/t_lwproc.c    Sun Jan 02 12:58:17 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_lwproc.c,v 1.4 2010/10/29 15:32:51 pooka Exp $       */
+/*     $NetBSD: t_lwproc.c,v 1.5 2011/01/02 12:58:17 pooka Exp $       */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -36,6 +36,7 @@
 #include <atf-c.h>
 #include <err.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -62,7 +63,7 @@
        ATF_REQUIRE_EQ(rump_pub_lwproc_newlwp(37), ESRCH);
        l = rump_pub_lwproc_curlwp();
 
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        ATF_REQUIRE(rump_pub_lwproc_curlwp() != l);
        l = rump_pub_lwproc_curlwp();
 
@@ -85,10 +86,10 @@
        struct lwp *l1, *l2;
 
        rump_init();
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        l1 = rump_pub_lwproc_curlwp();
 
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        l2 = rump_pub_lwproc_curlwp();
 
        RL(rump_sys_setuid(22));
@@ -119,11 +120,11 @@
 
        rump_init();
 
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        RL(rump_sys_setuid(66));
        ATF_REQUIRE_EQ(rump_sys_getuid(), 66);
 
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        ATF_REQUIRE_EQ(rump_sys_getuid(), 66);
 
        /* release lwp and proc */
@@ -149,7 +150,7 @@
 
        rump_init();
 
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        mypid = rump_sys_getpid();
        RL(rump_sys_setuid(375));
 
@@ -240,6 +241,65 @@
        rump_pub_lwproc_switch(l);
 }
 
+ATF_TC(rfork);
+ATF_TC_HEAD(rfork, tc)
+{
+
+       atf_tc_set_md_var(tc, "descr", "check that fork shares fd's");
+}
+
+ATF_TC_BODY(rfork, tc)
+{
+       struct stat sb;
+       struct lwp *l, *l2;
+       int fd;
+
+       RZ(rump_init());
+
+       ATF_REQUIRE_EQ(rump_pub_lwproc_rfork(RUMP_RFFDG|RUMP_RFCFDG), EINVAL);
+
+       RZ(rump_pub_lwproc_rfork(0));
+       l = rump_pub_lwproc_curlwp();
+
+       RL(fd = rump_sys_open("/file", O_RDWR | O_CREAT, 0777));
+
+       /* ok, first check rfork(RUMP_RFCFDG) does *not* preserve fd's */
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
+       ATF_REQUIRE_ERRNO(EBADF, rump_sys_write(fd, &fd, sizeof(fd)) == -1);
+
+       /* then check that rfork(0) does */
+       rump_pub_lwproc_switch(l);
+       RZ(rump_pub_lwproc_rfork(0));
+       ATF_REQUIRE_EQ(rump_sys_write(fd, &fd, sizeof(fd)), sizeof(fd));
+       RL(rump_sys_fstat(fd, &sb));
+       l2 = rump_pub_lwproc_curlwp();
+
+       /*
+        * check that the shared fd table is really shared by
+        * closing fd in parent
+        */
+       rump_pub_lwproc_switch(l);
+       RL(rump_sys_close(fd));
+       rump_pub_lwproc_switch(l2);
+       ATF_REQUIRE_ERRNO(EBADF, rump_sys_fstat(fd, &sb) == -1);
+
+       /* redo, this time copying the fd table instead of sharing it */
+       rump_pub_lwproc_releaselwp();
+       rump_pub_lwproc_switch(l);
+       RL(fd = rump_sys_open("/file", O_RDWR, 0777));
+       RZ(rump_pub_lwproc_rfork(RUMP_RFFDG));
+       ATF_REQUIRE_EQ(rump_sys_write(fd, &fd, sizeof(fd)), sizeof(fd));
+       RL(rump_sys_fstat(fd, &sb));
+       l2 = rump_pub_lwproc_curlwp();
+
+       /* check that the fd table is copied */
+       rump_pub_lwproc_switch(l);
+       RL(rump_sys_close(fd));
+       rump_pub_lwproc_switch(l2);
+       RL(rump_sys_fstat(fd, &sb));
+       ATF_REQUIRE_EQ(sb.st_size, sizeof(fd));
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -250,6 +310,7 @@
        ATF_TP_ADD_TC(tp, nolwprelease);
        ATF_TP_ADD_TC(tp, nolwp);
        ATF_TP_ADD_TC(tp, nullswitch);
+       ATF_TP_ADD_TC(tp, rfork);
 
        return atf_no_error();
 }
diff -r c8c735110a7a -r 8f5b5202aeb4 tests/rump/rumpvfs/t_p2kifs.c
--- a/tests/rump/rumpvfs/t_p2kifs.c     Sun Jan 02 12:53:13 2011 +0000
+++ b/tests/rump/rumpvfs/t_p2kifs.c     Sun Jan 02 12:58:17 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_p2kifs.c,v 1.2 2010/12/14 20:09:43 pooka Exp $       */
+/*     $NetBSD: t_p2kifs.c,v 1.3 2011/01/02 12:58:17 pooka Exp $       */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
        RL(rump_sys_mkdir("/" TESTFILE, 0777));
 
        /* need stable lwp for componentname */
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
 
        /* try it once with the right path */
        cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
diff -r c8c735110a7a -r 8f5b5202aeb4 tests/syscall/t_cmsg.c
--- a/tests/syscall/t_cmsg.c    Sun Jan 02 12:53:13 2011 +0000
+++ b/tests/syscall/t_cmsg.c    Sun Jan 02 12:58:17 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_cmsg.c,v 1.15 2010/09/01 19:41:28 pooka Exp $        */
+/*     $NetBSD: t_cmsg.c,v 1.16 2011/01/02 12:58:17 pooka Exp $        */
 
 #include <sys/types.h>
 #include <sys/mount.h>
@@ -91,8 +91,7 @@
 
        rump_init();
 
-       /* create first (non-proc0) process to be used in test */
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        l1 = rump_pub_lwproc_curlwp();
 
        /* create unix socket and bind it to a path */
@@ -109,7 +108,7 @@
                atf_tc_fail_errno("socket 1 listen");
 
        /* create second process for test */
-       RZ(rump_pub_lwproc_newproc());
+       RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
        l2 = rump_pub_lwproc_curlwp();
 
        /* connect to unix domain socket */



Home | Main Index | Thread Index | Old Index