+ rump_lwproc_newproc -> rump_lwproc_rfork()

+ add a tess for rump_lwproc_rfork()
This commit is contained in:
pooka 2011-01-02 12:58:17 +00:00
parent afa6c20325
commit 5c3365ce93
5 changed files with 78 additions and 18 deletions

View File

@ -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 @@ ATF_TC_BODY(renamerace2, tc)
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);

View File

@ -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 @@ renamerace(const atf_tc_t *tc, const char *mp)
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 @@ renamerace_dirs(const atf_tc_t *tc, const char *mp)
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));

View File

@ -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_TC_BODY(makelwp, tc)
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 @@ ATF_TC_BODY(proccreds, tc)
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 @@ ATF_TC_BODY(inherit, tc)
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 @@ ATF_TC_BODY(lwps, tc)
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 @@ ATF_TC_BODY(nullswitch, tc)
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_TCS(tp)
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();
}

View File

@ -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 @@ ATF_TC_BODY(makecn, tc)
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),

View File

@ -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 @@ ATF_TC_BODY(cmsg_sendfd, tc)
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_BODY(cmsg_sendfd, tc)
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 */