ATF_TC_BODY(multilayer, tc) { struct union_args unionargs; rump_init(); if (rump_sys_mkdir("/Tunion", 0777) == -1) atf_tc_fail_errno("mkdir mp1"); if (rump_sys_mkdir("/Tunion2", 0777) == -1) atf_tc_fail_errno("mkdir mp2"); if (rump_sys_mkdir("/Tunion2/A", 0777) == -1) atf_tc_fail_errno("mkdir A"); if (rump_sys_mkdir("/Tunion2/B", 0777) == -1) atf_tc_fail_errno("mkdir B"); unionargs.target = __UNCONST("/Tunion2/A"); unionargs.mntflags = UNMNT_BELOW; if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0, &unionargs, sizeof(unionargs)) == -1) atf_tc_fail_errno("union mount"); unionargs.target = __UNCONST("/Tunion2/B"); unionargs.mntflags = UNMNT_BELOW; rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs)); }
ATF_TC_BODY(devnull2, tc) { struct union_args unionargs; int fd, res; rump_init(); if (rump_sys_mkdir("/mp", 0777) == -1) atf_tc_fail_errno("mkdir mp"); unionargs.target = __UNCONST("/dev"); unionargs.mntflags = UNMNT_BELOW; if (rump_sys_mount(MOUNT_UNION, "/mp", 0, &unionargs, sizeof(unionargs)) == -1) atf_tc_fail_errno("union mount"); fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND); if (fd == -1) atf_tc_fail_errno("open"); res = rump_sys_write(fd, &fd, sizeof(fd)); if (res != sizeof(fd)) atf_tc_fail("write"); }
static void dir_notempty(const atf_tc_t *tc, const char *mountpath) { char pb[MAXPATHLEN], pb2[MAXPATHLEN]; int fd, rv; USES_DIRS; /* check we can create directories */ sprintf(pb, "%s/dir", mountpath); if (rump_sys_mkdir(pb, 0777) == -1) atf_tc_fail_errno("mkdir"); sprintf(pb2, "%s/dir/file", mountpath); fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777); if (fd == -1) atf_tc_fail_errno("create file"); rump_sys_close(fd); rv = rump_sys_rmdir(pb); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rv != -1 || errno != ENOTEMPTY) atf_tc_fail("non-empty directory removed succesfully"); if (rump_sys_unlink(pb2) == -1) atf_tc_fail_errno("cannot remove dir/file"); if (rump_sys_rmdir(pb) == -1) atf_tc_fail_errno("remove directory"); }
ATF_TC_BODY(loopmtu_csum, tc) { struct sockaddr_in sin; char data[2000]; int s; setup(); ATF_CHECK(enable_locsums() == 0); /* open raw socket */ s = rump_sys_socket(PF_INET, SOCK_RAW, 0); if (s == -1) atf_tc_fail_errno("raw socket"); /* then, send data */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_len = sizeof(sin); sin.sin_port = htons(12345); sin.sin_addr.s_addr = inet_addr("127.0.0.1"); if (rump_sys_sendto(s, data, sizeof(data), 0, (struct sockaddr *)&sin, sizeof(sin)) == -1) atf_tc_fail_errno("sendto failed"); }
static void rename_dotdot(const atf_tc_t *tc, const char *mp) { if (FSTYPE_RUMPFS(tc)) atf_tc_skip("rename not supported by file system"); USES_DIRS; if (rump_sys_chdir(mp) == -1) atf_tc_fail_errno("chdir mountpoint"); if (rump_sys_mkdir("dir1", 0777) == -1) atf_tc_fail_errno("mkdir 1"); if (rump_sys_mkdir("dir2", 0777) == -1) atf_tc_fail_errno("mkdir 2"); if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL) atf_tc_fail_errno("self-dotdot to"); if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL) atf_tc_fail_errno("self-dotdot from"); if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL) atf_tc_fail("other-dotdot"); rump_sys_chdir("/"); }
static void lookup_complex(const atf_tc_t *tc, const char *mountpath) { char pb[MAXPATHLEN]; struct stat sb1, sb2; USES_DIRS; if (FSTYPE_UDF(tc)) atf_tc_expect_fail("PR kern/49033"); sprintf(pb, "%s/dir", mountpath); if (rump_sys_mkdir(pb, 0777) == -1) atf_tc_fail_errno("mkdir"); if (rump_sys_stat(pb, &sb1) == -1) atf_tc_fail_errno("stat 1"); sprintf(pb, "%s/./dir/../././dir/.", mountpath); if (rump_sys_stat(pb, &sb2) == -1) atf_tc_fail_errno("stat 2"); if (memcmp(&sb1, &sb2, sizeof(sb1)) != 0) { printf("what\tsb1\t\tsb2\n"); #define FIELD(FN) \ printf(#FN "\t%lld\t%lld\n", \ (long long)sb1.FN, (long long)sb2.FN) #define TIME(FN) \ printf(#FN "\t%lld.%ld\t%lld.%ld\n", \ (long long)sb1.FN.tv_sec, sb1.FN.tv_nsec, \ (long long)sb2.FN.tv_sec, sb2.FN.tv_nsec) FIELD(st_dev); FIELD(st_mode); FIELD(st_ino); FIELD(st_nlink); FIELD(st_uid); FIELD(st_gid); FIELD(st_rdev); TIME(st_atim); TIME(st_mtim); TIME(st_ctim); TIME(st_birthtim); FIELD(st_size); FIELD(st_blocks); FIELD(st_flags); FIELD(st_gen); #undef FIELD #undef TIME atf_tc_fail("stat results differ, see ouput for more details"); } if (FSTYPE_UDF(tc)) atf_tc_fail("random failure of PR kern/49033 " "did not happen this time"); }
ATF_TC_BODY(nullrevoke, tc) { char path[MAXPATHLEN]; struct ptmget ptg; int ptm; rump_init(); /* * mount /dev/pts */ mountptyfs("/dev/pts", 0); /* * null mount /dev/pts to /null/dev/pts */ if (rump_sys_mkdir("/null", 0777) == -1) { if (errno != EEXIST) atf_tc_fail_errno("null create /null"); } if (rump_sys_mkdir("/null/dev", 0777) == -1) { if (errno != EEXIST) atf_tc_fail_errno("null create /null/dev"); } mountnull("/dev/pts", "/null/dev/pts", 0); /* * get slave/master pair. */ ptm = rump_sys_open("/dev/ptm", O_RDWR); if (rump_sys_ioctl(ptm, TIOCPTMGET, &ptg) == -1) atf_tc_fail_errno("get pty"); /* * Build nullfs path to slave. */ strcpy(path, "/null"); strcat(path, ptg.sn); /* * Open slave tty via nullfs. */ if (rump_sys_open(path, O_RDWR) == -1) atf_tc_fail_errno("slave null open"); /* * Close slave opened with /dev/ptm. Need purely non-null refs to it. */ rump_sys_close(ptg.sfd); /* revoke slave tty. */ rump_sys_revoke(path); /* done */ }
/* * Prepare rump, configure interface and route to cause fragmentation */ static void setup(void) { char ifname[IFNAMSIZ]; struct { struct rt_msghdr m_rtm; struct sockaddr_in m_sin; } m_rtmsg; #define rtm m_rtmsg.m_rtm #define rsin m_rtmsg.m_sin struct ifreq ifr; int s; rump_init(); /* first, config lo0 & route */ strcpy(ifname, "lo0"); netcfg_rump_if(ifname, "127.0.0.1", "255.0.0.0"); netcfg_rump_route("127.0.0.1", "255.0.0.0", "127.0.0.1"); if ((s = rump_sys_socket(PF_ROUTE, SOCK_RAW, 0)) == -1) atf_tc_fail_errno("routing socket"); /* * set MTU for interface so that route MTU doesn't * get overridden by it. */ memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, "lo0"); ifr.ifr_mtu = 1300; if (rump_sys_ioctl(s, SIOCSIFMTU, &ifr) == -1) atf_tc_fail_errno("set mtu"); /* change route MTU to 100 */ memset(&m_rtmsg, 0, sizeof(m_rtmsg)); rtm.rtm_type = RTM_CHANGE; rtm.rtm_flags = RTF_STATIC; rtm.rtm_version = RTM_VERSION; rtm.rtm_seq = 3; rtm.rtm_inits = RTV_MTU; rtm.rtm_addrs = RTA_DST; rtm.rtm_rmx.rmx_mtu = 100; rtm.rtm_msglen = sizeof(m_rtmsg); memset(&rsin, 0, sizeof(rsin)); rsin.sin_family = AF_INET; rsin.sin_len = sizeof(rsin); rsin.sin_addr.s_addr = inet_addr("127.0.0.1"); if (rump_sys_write(s, &m_rtmsg, sizeof(m_rtmsg)) != sizeof(m_rtmsg)) atf_tc_fail_errno("set route mtu"); rump_sys_close(s); }
ATF_TC_BODY(unlink, tc) { sem_t *sem; rump_init(); sem = sem_open(SEM, O_CREAT, 0444, 0); ATF_REQUIRE(sem); if (sem_unlink(SEM) == -1) atf_tc_fail_errno("unlink"); if (sem_close(sem) == -1) atf_tc_fail_errno("close unlinked semaphore"); }
/* Adapted from example provided by Juho Salminen in the noted PR. */ ATF_TC_BODY(RNDADDDATA, tc) { rnddata_t rd; int fd; rump_init(); 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; if (rump_sys_ioctl(fd, RNDADDDATA, &rd) == -1) atf_tc_fail_errno("RNDADDDATA"); }
static void mountptyfs(const char *mp, int flags) { struct ptyfs_args args; if (rump_sys_mkdir(mp, 0777) == -1) { if (errno != EEXIST) atf_tc_fail_errno("null create %s", mp); } memset(&args, 0, sizeof(args)); args.version = PTYFS_ARGSVERSION; args.mode = 0777; if (rump_sys_mount(MOUNT_PTYFS, mp, flags, &args, sizeof(args)) == -1) atf_tc_fail_errno("could not mount ptyfs"); }
static void times(const atf_tc_t *tc, const char *mp) { const char *name = "file.test"; int fd; unsigned int i, j; struct timeval tmv[2]; static struct timeval tmvs[] = { { QUAD_MIN, 0 }, { 0, 0 }, { QUAD_MAX, 999999 } }; FSTEST_ENTER(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_utimes(name, NULL) != -1 || errno != EACCES) atf_tc_fail_errno("utimes"); rump_pub_lwproc_releaselwp(); if (rump_sys_utimes(name, NULL) == -1) atf_tc_fail_errno("utimes"); for (i = 0; i < sizeof(tmvs) / sizeof(tmvs[0]); i++) { for (j = 0; j < sizeof(tmvs) / sizeof(tmvs[0]); j++) { tmv[0] = tmvs[i]; tmv[1] = tmvs[j]; rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_utimes(name, tmv) != -1 || errno != EPERM) atf_tc_fail_errno("utimes"); rump_pub_lwproc_releaselwp(); if (rump_sys_utimes(name, tmv) == -1) atf_tc_fail_errno("utimes"); } } if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); FSTEST_EXIT(); }
ATF_TC_BODY(named, tc) { sem_t *sem1, *sem2; void *rv; rump_init(); sem1 = sem_open(SEM1, 0); ATF_REQUIRE_EQ(errno, ENOENT); ATF_REQUIRE_EQ(sem1, NULL); sem1 = sem_open(SEM1, O_CREAT, 0444, 1); if (sem1 == NULL) atf_tc_fail_errno("sem_open O_CREAT"); rv = sem_open(SEM1, O_CREAT | O_EXCL); ATF_REQUIRE_EQ(errno, EEXIST); ATF_REQUIRE_EQ(rv, NULL); sem2 = sem_open(SEM2, O_CREAT, 0444, 0); if (sem2 == NULL) atf_tc_fail_errno("sem_open O_CREAT"); /* check that semaphores are independent */ ATF_REQUIRE_EQ(sem_trywait(sem2), -1); ATF_REQUIRE_EQ(sem_trywait(sem1), 0); ATF_REQUIRE_EQ(sem_trywait(sem1), -1); /* check that unlinked remains valid */ sem_unlink(SEM2); ATF_REQUIRE_EQ(sem_post(sem2), 0); ATF_REQUIRE_EQ(sem_trywait(sem2), 0); ATF_REQUIRE_EQ(sem_trywait(sem2), -1); ATF_REQUIRE_EQ(errno, EAGAIN); #if 0 /* see unlink */ /* close it and check that it's gone */ if (sem_close(sem2) != 0) atf_tc_fail_errno("sem close"); ATF_REQUIRE_EQ(sem_trywait(sem2), -1); ATF_REQUIRE_EQ(errno, EINVAL); #endif /* check that we still have sem1 */ sem_post(sem1); ATF_REQUIRE_EQ(sem_trywait(sem1), 0); ATF_REQUIRE_EQ(sem_trywait(sem1), -1); ATF_REQUIRE_EQ(errno, EAGAIN); }
static void lookup_simple(const atf_tc_t *tc, const char *mountpath) { char pb[MAXPATHLEN], final[MAXPATHLEN]; struct stat sb1, sb2; strcpy(final, mountpath); sprintf(pb, "%s/../%s", mountpath, basename(final)); if (rump_sys_stat(pb, &sb1) == -1) atf_tc_fail_errno("stat 1"); sprintf(pb, "%s/./../%s", mountpath, basename(final)); if (rump_sys_stat(pb, &sb2) == -1) atf_tc_fail_errno("stat 2"); ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0); }
static void owner(const atf_tc_t *tc, const char *mp) { USES_OWNER; FSTEST_ENTER(); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_chown(".", 1, -1) != -1 || errno != EPERM) atf_tc_fail_errno("chown"); if (rump_sys_chmod(".", 0000) != -1 || errno != EPERM) atf_tc_fail_errno("chmod"); rump_pub_lwproc_releaselwp(); if (rump_sys_chown(".", 1, -1) == -1) atf_tc_fail_errno("chown"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_chown(".", 1, -1) == -1) atf_tc_fail_errno("chown"); if (rump_sys_chmod(".", 0000) == -1) atf_tc_fail_errno("chmod"); rump_pub_lwproc_releaselwp(); FSTEST_EXIT(); }
static void mountnull(const char *what, const char *mp, int flags) { struct null_args nargs; if (rump_sys_mkdir(what, 0777) == -1) { if (errno != EEXIST) atf_tc_fail_errno("null create %s", what); } if (rump_sys_mkdir(mp, 0777) == -1) { if (errno != EEXIST) atf_tc_fail_errno("null create %s", mp); } memset(&nargs, 0, sizeof(nargs)); nargs.nulla_target = __UNCONST(what); if (rump_sys_mount(MOUNT_NULL, mp, flags, &nargs, sizeof(nargs)) == -1) atf_tc_fail_errno("could not mount nullfs"); }
static void lookup_complex(const atf_tc_t *tc, const char *mountpath) { char pb[MAXPATHLEN]; struct stat sb1, sb2; USES_DIRS; sprintf(pb, "%s/dir", mountpath); if (rump_sys_mkdir(pb, 0777) == -1) atf_tc_fail_errno("mkdir"); if (rump_sys_stat(pb, &sb1) == -1) atf_tc_fail_errno("stat 1"); sprintf(pb, "%s/./dir/../././dir/.", mountpath); if (rump_sys_stat(pb, &sb2) == -1) atf_tc_fail_errno("stat 2"); ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0); }
static void flags(const atf_tc_t *tc, const char *mp) { const char *name = "file.test"; int fd, fflags; struct stat st; FSTEST_ENTER(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); if (rump_sys_stat(name, &st) == -1) atf_tc_fail_errno("stat"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_chflags(name, st.st_flags) == -1) { if (errno == EOPNOTSUPP) atf_tc_skip("file flags not supported by file system"); atf_tc_fail_errno("chflags"); } fflags = st.st_flags | UF_IMMUTABLE; rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); fflags |= UF_IMMUTABLE; if (rump_sys_chflags(name, fflags) != -1 || errno != EPERM) atf_tc_fail_errno("chflags"); rump_pub_lwproc_releaselwp(); if (rump_sys_chflags(name, fflags) == -1) atf_tc_fail_errno("chflags"); fflags &= ~UF_IMMUTABLE; if (rump_sys_chflags(name, fflags) == -1) atf_tc_fail_errno("chflags"); if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); FSTEST_EXIT(); }
static void dir_simple(const atf_tc_t *tc, const char *mountpath) { char pb[MAXPATHLEN]; struct stat sb; USES_DIRS; /* check we can create directories */ sprintf(pb, "%s/dir", mountpath); if (rump_sys_mkdir(pb, 0777) == -1) atf_tc_fail_errno("mkdir"); if (rump_sys_stat(pb, &sb) == -1) atf_tc_fail_errno("stat new directory"); /* check we can remove then and that it makes them unreachable */ if (rump_sys_rmdir(pb) == -1) atf_tc_fail_errno("rmdir"); if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT) atf_tc_fail("ENOENT expected from stat"); }
static void dirperms(const atf_tc_t *tc, const char *mp) { char name[] = "dir.test/file.test"; char *dir = dirname(name); int fd; if (FSTYPE_SYSVBFS(tc)) atf_tc_skip("directories not supported by file system"); FSTEST_ENTER(); if (rump_sys_mkdir(dir, 0777) == -1) atf_tc_fail_errno("mkdir"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_open(name, O_RDWR|O_CREAT, 0666) != -1 || errno != EACCES) atf_tc_fail_errno("open"); rump_pub_lwproc_releaselwp(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_unlink(name) != -1 || errno != EACCES) atf_tc_fail_errno("unlink"); rump_pub_lwproc_releaselwp(); if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); if (rump_sys_rmdir(dir) == -1) atf_tc_fail_errno("rmdir"); FSTEST_EXIT(); }
static void checkfile(const char *path, struct stat *refp) { char buf[MAXPATHLEN]; struct stat sb; static int n = 1; md(buf, path, "file"); if (rump_sys_stat(buf, &sb) == -1) atf_tc_fail_errno("cannot stat file %d (%s)", n, buf); if (memcmp(&sb, refp, sizeof(sb)) != 0) atf_tc_fail("stat mismatch %d", n); n++; }
static void rename_nametoolong(const atf_tc_t *tc, const char *mp) { char *name; int res, fd; long val; size_t len; if (FSTYPE_RUMPFS(tc)) atf_tc_skip("rename not supported by file system"); if (rump_sys_chdir(mp) == -1) atf_tc_fail_errno("chdir mountpoint"); val = rump_sys_pathconf(".", _PC_NAME_MAX); if (val == -1) atf_tc_fail_errno("pathconf"); len = val + 1; name = malloc(len+1); if (name == NULL) atf_tc_fail_errno("malloc"); memset(name, 'a', len); *(name+len) = '\0'; fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666); if (fd == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); val = rump_sys_pathconf(".", _PC_NO_TRUNC); if (val == -1) atf_tc_fail_errno("pathconf"); res = rump_sys_rename("dummy", name); if (val != 0 && (res != -1 || errno != ENAMETOOLONG)) atf_tc_fail_errno("rename"); if (val == 0 && rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); free(name); rump_sys_chdir("/"); }
ATF_TC_BODY(large_blk, tc) { char buf[128]; char cmpbuf[128]; ssize_t n; int rv, tfd; /* * mount mfs. it would be nice if this would not be required, * but a) tmpfs doesn't "support" sparse files b) we don't really * know what fs atf workdir is on anyway. */ if (mkdir("mfsdir", 0777) == -1) atf_tc_fail_errno("mkdir failed"); if (system("mount_mfs -s 64m -o nosuid,nodev mfs mfsdir") != 0) atf_tc_skip("could not mount mfs"); /* create a 8TB sparse file */ rv = system("dd if=/dev/zero of=" IMG_ON_MFS " bs=1 count=1 seek=8t"); ATF_REQUIRE_EQ(rv, 0); /* * map it and issue write at 6TB, then unmap+remap and check * we get the same stuff back */ rump_init(); ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH1, IMG_ON_MFS, RUMP_ETFS_BLK), 0); tfd = rump_sys_open(TESTPATH1, O_RDWR); ATF_REQUIRE(tfd != -1); memset(buf, 12, sizeof(buf)); n = rump_sys_pwrite(tfd, buf, sizeof(buf), 6*1024*1024*1024ULL*1024ULL); ATF_REQUIRE_EQ(n, sizeof(buf)); ATF_REQUIRE_EQ(rump_sys_close(tfd), 0); ATF_REQUIRE_EQ(rump_pub_etfs_remove(TESTPATH1), 0); ATF_REQUIRE_EQ(rump_pub_etfs_register(TESTPATH2, IMG_ON_MFS, RUMP_ETFS_BLK), 0); tfd = rump_sys_open(TESTPATH2, O_RDWR); ATF_REQUIRE(tfd != -1); memset(buf, 0, sizeof(buf)); n = rump_sys_pread(tfd, buf, sizeof(buf), 6*1024*1024*1024ULL*1024ULL); ATF_REQUIRE_EQ(n, sizeof(buf)); memset(cmpbuf, 12, sizeof(cmpbuf)); ATF_REQUIRE_EQ(memcmp(cmpbuf, buf, 128), 0); }
ATF_TC_BODY(nolwprelease, tc) { int status; switch (fork()) { case 0: rump_init(); rump_pub_lwproc_releaselwp(); atf_tc_fail("survived"); break; case -1: atf_tc_fail_errno("fork"); break; default: wait(&status); ATF_REQUIRE(WIFSIGNALED(status)); ATF_REQUIRE_EQ(WTERMSIG(status), SIGABRT); } }
ATF_TC_BODY(sigpanic, tc) { int status; rump_boot_setsigmodel(RUMP_SIGMODEL_PANIC); switch (fork()) { case 0: rump_init(); rump_schedule(); rumptest_localsig(SIGCONT); /* NOTREACHED */ exit(1); default: wait(&status); ATF_REQUIRE(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT); break; case -1: atf_tc_fail_errno("fork"); } }
static void create_nametoolong(const atf_tc_t *tc, const char *mp) { char *name; int fd; long val; size_t len; if (rump_sys_chdir(mp) == -1) atf_tc_fail_errno("chdir mountpoint"); val = rump_sys_pathconf(".", _PC_NAME_MAX); if (val == -1) atf_tc_fail_errno("pathconf"); len = val + 1; name = malloc(len+1); if (name == NULL) atf_tc_fail_errno("malloc"); memset(name, 'a', len); *(name+len) = '\0'; val = rump_sys_pathconf(".", _PC_NO_TRUNC); if (val == -1) atf_tc_fail_errno("pathconf"); fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666); if (val != 0 && (fd != -1 || errno != ENAMETOOLONG)) atf_tc_fail_errno("open"); if (val == 0 && rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); if (val == 0 && rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); free(name); rump_sys_chdir("/"); }
static void rename_dir(const atf_tc_t *tc, const char *mp) { char pb1[MAXPATHLEN], pb2[MAXPATHLEN], pb3[MAXPATHLEN]; struct stat ref, sb; if (FSTYPE_RUMPFS(tc)) atf_tc_skip("rename not supported by file system"); USES_DIRS; md(pb1, mp, "dir1"); if (rump_sys_mkdir(pb1, 0777) == -1) atf_tc_fail_errno("mkdir 1"); md(pb2, mp, "dir2"); if (rump_sys_mkdir(pb2, 0777) == -1) atf_tc_fail_errno("mkdir 2"); md(pb2, mp, "dir2/subdir"); if (rump_sys_mkdir(pb2, 0777) == -1) atf_tc_fail_errno("mkdir 3"); md(pb3, mp, "dir1/file"); if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1) atf_tc_fail_errno("create file"); if (rump_sys_stat(pb3, &ref) == -1) atf_tc_fail_errno("stat of file"); /* * First try ops which should succeed. */ /* rename within directory */ md(pb3, mp, "dir3"); if (rump_sys_rename(pb1, pb3) == -1) atf_tc_fail_errno("rename 1"); checkfile(pb3, &ref); /* rename directory onto itself (two ways, should fail) */ md(pb1, mp, "dir3/."); if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL) atf_tc_fail_errno("rename 2"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR) atf_tc_fail_errno("rename 3"); checkfile(pb3, &ref); /* rename father of directory into directory */ md(pb1, mp, "dir2/dir"); md(pb2, mp, "dir2"); if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL) atf_tc_fail_errno("rename 4"); /* same for grandfather */ md(pb1, mp, "dir2/subdir/dir2"); if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL) atf_tc_fail("rename 5"); checkfile(pb3, &ref); /* rename directory over a non-empty directory */ if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY) atf_tc_fail("rename 6"); /* cross-directory rename */ md(pb1, mp, "dir3"); md(pb2, mp, "dir2/somedir"); if (rump_sys_rename(pb1, pb2) == -1) atf_tc_fail_errno("rename 7"); checkfile(pb2, &ref); /* move to parent directory */ md(pb1, mp, "dir2/somedir/../../dir3"); if (rump_sys_rename(pb2, pb1) == -1) atf_tc_fail_errno("rename 8"); md(pb1, mp, "dir2/../dir3"); checkfile(pb1, &ref); /* atomic cross-directory rename */ md(pb3, mp, "dir2/subdir"); if (rump_sys_rename(pb1, pb3) == -1) atf_tc_fail_errno("rename 9"); checkfile(pb3, &ref); /* rename directory over an empty directory */ md(pb1, mp, "parent"); md(pb2, mp, "parent/dir1"); md(pb3, mp, "parent/dir2"); RL(rump_sys_mkdir(pb1, 0777)); RL(rump_sys_mkdir(pb2, 0777)); RL(rump_sys_mkdir(pb3, 0777)); RL(rump_sys_rename(pb2, pb3)); RL(rump_sys_stat(pb1, &sb)); if (! FSTYPE_MSDOS(tc)) ATF_CHECK_EQ(sb.st_nlink, 3); RL(rump_sys_rmdir(pb3)); RL(rump_sys_rmdir(pb1)); }
static void rename_reg_nodir(const atf_tc_t *tc, const char *mp) { bool haslinks; struct stat sb; ino_t f1ino, f2ino; if (FSTYPE_RUMPFS(tc)) atf_tc_skip("rename not supported by file system"); if (rump_sys_chdir(mp) == -1) atf_tc_fail_errno("chdir mountpoint"); if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc)) haslinks = false; else haslinks = true; if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1) atf_tc_fail_errno("create file"); if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1) atf_tc_fail_errno("create file"); if (rump_sys_stat("file1", &sb) == -1) atf_tc_fail_errno("stat"); f1ino = sb.st_ino; if (haslinks) { if (rump_sys_link("file1", "file_link") == -1) atf_tc_fail_errno("link"); if (rump_sys_stat("file_link", &sb) == -1) atf_tc_fail_errno("stat"); ATF_REQUIRE_EQ(sb.st_ino, f1ino); ATF_REQUIRE_EQ(sb.st_nlink, 2); } if (rump_sys_stat("file2", &sb) == -1) atf_tc_fail_errno("stat"); f2ino = sb.st_ino; if (rump_sys_rename("file1", "file3") == -1) atf_tc_fail_errno("rename 1"); if (rump_sys_stat("file3", &sb) == -1) atf_tc_fail_errno("stat 1"); if (haslinks) { ATF_REQUIRE_EQ(sb.st_ino, f1ino); } if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT) atf_tc_fail_errno("source 1"); if (rump_sys_rename("file3", "file2") == -1) atf_tc_fail_errno("rename 2"); if (rump_sys_stat("file2", &sb) == -1) atf_tc_fail_errno("stat 2"); if (haslinks) { ATF_REQUIRE_EQ(sb.st_ino, f1ino); } if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT) atf_tc_fail_errno("source 2"); if (haslinks) { if (rump_sys_rename("file2", "file_link") == -1) atf_tc_fail_errno("rename hardlink"); if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT) atf_tc_fail_errno("source 3"); if (rump_sys_stat("file_link", &sb) == -1) atf_tc_fail_errno("stat 2"); ATF_REQUIRE_EQ(sb.st_ino, f1ino); ATF_REQUIRE_EQ(sb.st_nlink, 1); } rump_sys_chdir("/"); }
ATF_TC_BODY(handover, tc) { char ifname[IFNAMSIZ]; pid_t mpid, cpid; int i, status; signal(SIGCHLD, sighnd); /* fork master */ switch (mpid = fork()) { case -1: atf_tc_fail_errno("fork failed"); /*NOTREACHED*/ case 0: child(true); /*NOTREACHED*/ default: break; } usleep(500000); /* fork backup */ switch (cpid = fork()) { case -1: kill(mpid, SIGKILL); atf_tc_fail_errno("fork failed"); /*NOTREACHED*/ case 0: child(false); /*NOTREACHED*/ default: break; } usleep(500000); rump_init(); netcfg_rump_makeshmif(THEBUS, ifname); netcfg_rump_if(ifname, "10.1.1.240", "255.255.255.0"); /* check that the primary addresses are up */ ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 1000), true); ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.2", 1000), true); /* give carp a while to croak */ sleep(4); /* check that the shared IP works */ ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.100", 500), true); /* KILLING SPREE */ oknow = true; kill(mpid, SIGKILL); wait(&status); usleep(10000); /* just in case */ oknow = false; /* check that primary is now dead */ ATF_REQUIRE_EQ(netcfg_rump_pingtest("10.1.1.1", 100), false); /* do it in installments. carp will cluck meanwhile */ for (i = 0; i < 5; i++) { if (netcfg_rump_pingtest("10.1.1.100", 1000) == true) break; } if (i == 5) atf_tc_fail("failed to failover"); /* to kill the child */ oknow = true; kill(cpid, SIGKILL); /* clean & done */ }