ATF_TC_BODY(fail_and_fail_check, tc) { atf_tc_expect_fail("Fail first"); atf_tc_fail_nonfatal("abc"); atf_tc_expect_pass(); atf_tc_expect_fail("And fail again"); atf_tc_fail_nonfatal("def"); atf_tc_expect_pass(); }
ATF_TC_BODY(fail_but_pass, tc) { atf_tc_expect_fail("Fail first"); atf_tc_fail_nonfatal("abc"); atf_tc_expect_pass(); atf_tc_expect_fail("Will not fail"); atf_tc_expect_pass(); atf_tc_expect_fail("And fail again"); atf_tc_fail_nonfatal("def"); atf_tc_expect_pass(); }
ATF_TC_BODY(pthread_detach, tc) { const int state = PTHREAD_CREATE_JOINABLE; pthread_attr_t attr; pthread_t t; int rv; /* * Create a joinable thread. */ PTHREAD_REQUIRE(pthread_attr_init(&attr)); PTHREAD_REQUIRE(pthread_attr_setdetachstate(&attr, state)); PTHREAD_REQUIRE(pthread_create(&t, &attr, func, NULL)); /* * Detach the thread and try to * join it; EINVAL should follow. */ PTHREAD_REQUIRE(pthread_detach(t)); rv = pthread_join(t, NULL); ATF_REQUIRE(rv == EINVAL); #ifdef __FreeBSD__ atf_tc_expect_fail("PR # 191906: fails with EINVAL, not ESRCH"); #endif /* * As usual, ESRCH should follow if * we try to detach an invalid thread. */ rv = pthread_cancel(NULL); ATF_REQUIRE(rv == ESRCH); }
ATF_TC_BODY(mountdhup, tc) { pthread_t pt; struct nfstestargs *nfsargs; void *voidargs; int attempts; void *fail; FSTEST_CONSTRUCTOR(tc, nfs, voidargs); nfsargs = voidargs; pthread_create(&pt, NULL, wrkwrkwrk, NULL); for (attempts = 100; attempts && !quit; attempts--) { usleep(100000); kill(nfsargs->ta_childpid, SIGHUP); } quit = 1; pthread_join(pt, &fail); FSTEST_DESTRUCTOR(tc, nfs, voidargs); atf_tc_expect_fail("PR kern/5844"); if (fail) atf_tc_fail("op failed with EACCES"); else atf_tc_fail("race did not trigger this time"); }
ATF_TC_BODY(powf_inf_neg_x, tc) { const float x = -1.0L / 0.0L; float z; /* * If y is odd, y > 0, and x is -Inf, -Inf is returned. * If y is even, y > 0, and x is -Inf, +Inf is returned. */ z = powf(x, 3.0); if (isinff(z) == 0 || signbit(z) == 0) atf_tc_fail_nonfatal("powf(-Inf, 3.0) != -Inf"); z = powf(x, 4.0); if (isinff(z) == 0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(-Inf, 4.0) != +Inf"); /* * If y is odd, y < 0, and x is -Inf, -0.0 is returned. * If y is even, y < 0, and x is -Inf, +0.0 is returned. */ z = powf(x, -3.0); if (fabsf(z) > 0.0 || signbit(z) == 0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("powf(-Inf, -3.0) != -0.0"); } z = powf(x, -4.0); if (fabsf(z) > 0.0 || signbit(z) != 0) atf_tc_fail_nonfatal("powf(-Inf -4.0) != +0.0"); }
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(strtod_round, tc) { #ifdef HAVE_FENV /* * Test that strtod(3) honors the current rounding mode. * The used value is somewhere near 1 + DBL_EPSILON + FLT_EPSILON. */ const char *val = "1.00000011920928977282585492503130808472633361816406"; (void)fesetround(FE_UPWARD); volatile double d1 = strtod(val, NULL); (void)fesetround(FE_DOWNWARD); volatile double d2 = strtod(val, NULL); if (fabs(d1 - d2) > 0.0) return; else { atf_tc_expect_fail("PR misc/44767"); atf_tc_fail("strtod(3) did not honor fesetround(3)"); } #else atf_tc_skip("Requires <fenv.h> support"); #endif }
static void lstat_symlink(const atf_tc_t *tc, const char *mp) { const char *src, *dst; int res; struct stat st; USES_SYMLINKS; if (FSTYPE_V7FS(tc)) atf_tc_expect_fail("PR kern/48864"); FSTEST_ENTER(); src = "source"; dst = "destination"; res = rump_sys_symlink(src, dst); ATF_REQUIRE(res != -1); res = rump_sys_lstat(dst, &st); ATF_REQUIRE(res != -1); ATF_CHECK(S_ISLNK(st.st_mode) != 0); ATF_CHECK(st.st_size == (off_t)strlen(src)); FSTEST_EXIT(); }
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(mbrtowc_internal, tc) { struct test *t; #if defined(__FreeBSD__) atf_tc_expect_fail("ja_* locale fails"); #endif for (t = &tests[0]; t->data != NULL; ++t) h_ctype2(t, false); }
static void attrs(const atf_tc_t *tc, const char *mp) { struct stat sb, sb2; struct timeval tv[2]; int fd; FSTEST_ENTER(); RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755)); RL(rump_sys_close(fd)); RL(rump_sys_stat(TESTFILE, &sb)); if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { RL(rump_sys_chown(TESTFILE, 1, 2)); sb.st_uid = 1; sb.st_gid = 2; RL(rump_sys_chmod(TESTFILE, 0123)); sb.st_mode = (sb.st_mode & ~ACCESSPERMS) | 0123; } tv[0].tv_sec = 1000000000; /* need something >1980 for msdosfs */ tv[0].tv_usec = 1; tv[1].tv_sec = 1000000002; /* need even seconds for msdosfs */ tv[1].tv_usec = 3; RL(rump_sys_utimes(TESTFILE, tv)); RL(rump_sys_utimes(TESTFILE, tv)); /* XXX: utimes & birthtime */ sb.st_atimespec.tv_sec = 1000000000; sb.st_atimespec.tv_nsec = 1000; sb.st_mtimespec.tv_sec = 1000000002; sb.st_mtimespec.tv_nsec = 3000; RL(rump_sys_stat(TESTFILE, &sb2)); #define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a) if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { CHECK(st_uid); CHECK(st_gid); CHECK(st_mode); } if (!FSTYPE_MSDOS(tc)) { /* msdosfs has only access date, not time */ CHECK(st_atimespec.tv_sec); } CHECK(st_mtimespec.tv_sec); if (!(FSTYPE_EXT2FS(tc) || FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc) || FSTYPE_V7FS(tc))) { CHECK(st_atimespec.tv_nsec); CHECK(st_mtimespec.tv_nsec); } #undef CHECK FSTEST_EXIT(); }
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(mmap_truncate_signal, tc) { char *map; long i; int fd, sta; pid_t pid; #ifdef __FreeBSD__ atf_tc_expect_fail("testcase fails with SIGSEGV on FreeBSD; bug # 211924"); #endif fd = open(path, O_RDWR | O_CREAT, 0700); if (fd < 0) return; ATF_REQUIRE(write(fd, "foo\n", 5) == 5); map = mmap(NULL, page, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0); ATF_REQUIRE(map != MAP_FAILED); sta = 0; for (i = 0; i < 5; i++) sta += map[i]; ATF_REQUIRE(sta == 334); ATF_REQUIRE(ftruncate(fd, 0) == 0); pid = fork(); ATF_REQUIRE(pid >= 0); if (pid == 0) { ATF_REQUIRE(signal(SIGBUS, map_sighandler) != SIG_ERR); ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR); sta = 0; for (i = 0; i < page; i++) sta += map[i]; /* child never will get this far, but the compiler will not know, so better use the values calculated to prevent the access to be optimized out */ ATF_REQUIRE(i == 0); ATF_REQUIRE(sta == 0); return; } (void)wait(&sta); ATF_REQUIRE(WIFEXITED(sta) != 0); if (WEXITSTATUS(sta) == SIGSEGV) atf_tc_fail("child process got SIGSEGV instead of SIGBUS"); ATF_REQUIRE(WEXITSTATUS(sta) == SIGBUS); ATF_REQUIRE(munmap(map, page) == 0); ATF_REQUIRE(close(fd) == 0); }
ATF_TC_BODY(access_inval, tc) { #if defined(__FreeBSD__) && __FreeBSD_version < 1100033 atf_tc_expect_fail("arguments to access aren't validated; see " "bug # 181155 for more details"); #endif errno = 0; ATF_REQUIRE(access("/usr", -1) != 0); ATF_REQUIRE(errno == EINVAL); }
ATF_TC_BODY(powf_one_neg_x, tc) { const float infp = 1.0L / 0.0L; const float infn = -1.0L / 0.0L; /* * If x is -1.0, and y is +-Inf, 1.0 shall be returned. */ ATF_REQUIRE(isinff(infp) != 0); ATF_REQUIRE(isinff(infn) != 0); if (powf(-1.0, infp) != 1.0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("powf(-1.0, +Inf) != 1.0"); } if (powf(-1.0, infn) != 1.0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("powf(-1.0, -Inf) != 1.0"); } }
ATF_TC_BODY(pow_one_neg_x, tc) { #ifndef __vax__ const double infp = 1.0L / 0.0L; const double infn = -1.0L / 0.0L; /* * If x is -1.0, and y is +-Inf, 1.0 shall be returned. */ ATF_REQUIRE(isinf(infp) != 0); ATF_REQUIRE(isinf(infn) != 0); if (pow(-1.0, infp) != 1.0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("pow(-1.0, +Inf) != 1.0"); } if (pow(-1.0, infn) != 1.0) { atf_tc_expect_fail("PR lib/45372"); atf_tc_fail_nonfatal("pow(-1.0, -Inf) != 1.0"); } #endif }
ATF_TC_BODY(pipe_128k_8k, tc) { /* * kern/185812 causes this test case to both fail and timeout. The * atf-c-api(3) doesn't have a way to set such an expectation. * If you use atf_tc_expect_fail, then it will timeout. If you use * atf_tc_expect_timeout, then it will fail. If you use both, then it * will show up as an unexpected pass, which is much worse * * https://code.google.com/p/kyua/issues/detail?id=76 */ atf_tc_expect_fail("PR kern/185812 send(2) on a UNIX domain SEQPACKET socket returns EMSGSIZE instead of EAGAIN"); test_pipe(131072, 8192); }
ATF_TC_BODY(cleanup__subdir__links, tc) { ATF_REQUIRE(mkdir("root", 0755) != -1); ATF_REQUIRE(mkdir("root/dir1", 0755) != -1); ATF_REQUIRE(symlink("../../root", "root/dir1/loop") != -1); ATF_REQUIRE(symlink("non-existent", "root/missing") != -1); ATF_REQUIRE(lookup(".", "root", DT_DIR)); kyua_error_t error = kyua_fs_cleanup("root"); if (kyua_error_is_set(error)) { if (lchmod_fails()) atf_tc_expect_fail("lchmod(2) is not implemented in your system"); kyua_error_free(error); atf_tc_fail("kyua_fs_cleanup returned an error"); } ATF_REQUIRE(!lookup(".", "root", DT_DIR)); }
ATF_TC_BODY(mbtowc, tc) { h_mbtowc("en_US.UTF-8", "\240", "\302\240"); h_mbtowc("ja_JP.ISO2022-JP", "\033$B", "\033$B$\"\033(B"); h_mbtowc("ja_JP.SJIS", "\202", "\202\240"); h_mbtowc("ja_JP.eucJP", "\244", "\244\242"); #if !defined(__FreeBSD__) /* Moved last as it fails */ h_mbtowc("zh_CN.GB18030", "\241", "\241\241"); #endif h_mbtowc("zh_TW.Big5", "\241", "\241@"); h_mbtowc("zh_TW.eucTW", "\241", "\241\241"); #if defined(__FreeBSD__) atf_tc_expect_fail("zh_CN.GB18030"); h_mbtowc("zh_CN.GB18030", "\241", "\241\241"); #endif }
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 fcntl_lock(const atf_tc_t *tc, const char *mp) { int fd, fd2; struct flock l; struct lwp *lwp1, *lwp2; FSTEST_ENTER(); l.l_pid = 0; l.l_start = l.l_len = 1024; l.l_type = F_RDLCK | F_WRLCK; l.l_whence = SEEK_END; lwp1 = rump_pub_lwproc_curlwp(); RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755)); RL(rump_sys_ftruncate(fd, 8192)); /* PR kern/43321 */ if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); RL(rump_sys_fcntl(fd, F_SETLK, &l)); /* Next, we fork and try to lock the same area */ RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); lwp2 = rump_pub_lwproc_curlwp(); RL(fd2 = rump_sys_open(TESTFILE, O_RDWR, 0)); ATF_REQUIRE_ERRNO(EAGAIN, rump_sys_fcntl(fd2, F_SETLK, &l)); /* Switch back and unlock... */ rump_pub_lwproc_switch(lwp1); l.l_type = F_UNLCK; RL(rump_sys_fcntl(fd, F_SETLK, &l)); /* ... and try to lock again */ rump_pub_lwproc_switch(lwp2); l.l_type = F_RDLCK | F_WRLCK; RL(rump_sys_fcntl(fd2, F_SETLK, &l)); RL(rump_sys_close(fd2)); rump_pub_lwproc_releaselwp(); RL(rump_sys_close(fd)); FSTEST_EXIT(); }
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(); }
ATF_TC_BODY(faccessat_fdlink, tc) { int dfd; ATF_REQUIRE(mkdir(DIR, 0755) == 0); ATF_REQUIRE(symlink(FILE, LINK) == 0); /* NB: FILE does not exists */ ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1); ATF_REQUIRE(faccessat(dfd, BASELINK, F_OK, 0) == -1); ATF_REQUIRE(errno == ENOENT); #ifdef __FreeBSD__ atf_tc_expect_fail("Depends on non-standard behavior not mentioned in POSIX.1-2008"); #endif ATF_REQUIRE(faccessat(dfd, BASELINK, F_OK, AT_SYMLINK_NOFOLLOW) == 0); ATF_REQUIRE(close(dfd) == 0); }
ATF_TC_BODY(sigbus_adraln, tc) { const char *arch = atf_config_get("atf_arch"); struct sigaction sa; if (strcmp(arch, "alpha") == 0) { int rv, val; size_t len = sizeof(val); rv = sysctlbyname("machdep.unaligned_sigbus", &val, &len, NULL, 0); ATF_REQUIRE(rv == 0); if (val == 0) atf_tc_skip("SIGBUS signal not enabled for" " unaligned accesses"); } sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = sigbus_action; sigemptyset(&sa.sa_mask); sigaction(SIGBUS, &sa, NULL); /* Enable alignement checks for x86. 0x40000 is PSL_AC. */ #if defined(__i386__) __asm__("pushf; orl $0x40000, (%esp); popf"); #elif defined(__amd64__) __asm__("pushf; orl $0x40000, (%rsp); popf"); #endif addr = calloc(2, sizeof(int)); ATF_REQUIRE(addr != NULL); if (isQEMU()) atf_tc_expect_fail("QEMU fails to trap unaligned accesses"); /* Force an unaligned access */ addr++; printf("now trying to access unaligned address %p\n", addr); ATF_REQUIRE_EQ(*(volatile int *)addr, 0); atf_tc_fail("Test did not fault as expected"); }
ATF_TC_BODY(common, tc) { #ifdef __FreeBSD__ atf_tc_expect_fail("There are various issues with strptime on FreeBSD"); #endif h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %T %Y", 24, 46, 27, 23, 20, 0, 98, 2, 19); h_pass("Tue Jan 20 23:27:46 1998", "%a %b %d %H:%M:%S %Y", 24, 46, 27, 23, 20, 0, 98, 2, 19); h_pass("Tue Jan 20 23:27:46 1998", "%c", 24, 46, 27, 23, 20, 0, 98, 2, 19); h_pass("Fri Mar 4 20:05:34 2005", "%a %b %e %H:%M:%S %Y", 24, 34, 5, 20, 4, 2, 105, 5, 62); h_pass("5\t3 4 8pm:05:34 2005", "%w%n%m%t%d%n%k%p:%M:%S %Y", 21, 34, 5, 20, 4, 2, 105, 5, 62); h_pass("Fri Mar 4 20:05:34 2005", "%c", 24, 34, 5, 20, 4, 2, 105, 5, 62); }
ATF_TC_BODY(int_within_limits, tc) { ATF_REQUIRE(setlocale(LC_NUMERIC, "C")); /* The test requires these to be true. */ ATF_REQUIRE(UINTMAX_MAX == UINT64_MAX); ATF_REQUIRE(UINT_MAX == UINT32_MAX); ATF_REQUIRE(USHRT_MAX == 0xffff); ATF_REQUIRE(UCHAR_MAX == 0xff); /* Make sure we handle signed vs. unsigned args correctly. */ testfmt("-1", "%jd", (intmax_t)-1); testfmt(S_UINT64MAX, "%ju", UINT64_MAX); if (sizeof(ptrdiff_t) != sizeof(uintmax_t)) atf_tc_expect_fail("the %%t qualifier is broken on 32-bit " "platforms where there's a mismatch between ptrdiff_t and " "uintmax_t's type width; bug # 191674"); testfmt("-1", "%td", (ptrdiff_t)-1); testfmt(S_SIZEMAX, "%tu", (size_t)-1); testfmt("-1", "%zd", (ssize_t)-1); testfmt(S_SIZEMAX, "%zu", (ssize_t)-1); testfmt("-1", "%ld", (long)-1); testfmt(S_ULONGMAX, "%lu", ULONG_MAX); testfmt("-1", "%lld", (long long)-1); testfmt(S_ULLONGMAX, "%llu", ULLONG_MAX); testfmt("-1", "%d", -1); testfmt(S_UINT32MAX, "%u", UINT32_MAX); testfmt("-1", "%hd", -1); testfmt("65535", "%hu", USHRT_MAX); testfmt("-1", "%hhd", -1); testfmt("255", "%hhu", UCHAR_MAX); }
ATF_TC_BODY(nice_err, tc) { int i; #ifdef __FreeBSD__ atf_tc_expect_fail("nice(incr) with incr < 0 fails with unprivileged " "users and sets errno == EPERM; see PR # 189821 for more details"); #endif /* * The call should fail with EPERM if the * supplied parameter is negative and the * caller does not have privileges. */ for (i = -20; i < 0; i++) { errno = 0; ATF_REQUIRE_ERRNO(EPERM, nice(i) == -1); } }
static void sigbus_action(int signo, siginfo_t *info, void *ptr) { printf("si_addr = %p\n", info->si_addr); sig_debug(signo, info, (ucontext_t *)ptr); ATF_REQUIRE_EQ(info->si_signo, SIGBUS); ATF_REQUIRE_EQ(info->si_errno, 0); ATF_REQUIRE_EQ(info->si_code, BUS_ADRALN); if (strcmp(atf_config_get("atf_arch"), "i386") == 0 || strcmp(atf_config_get("atf_arch"), "x86_64") == 0) { atf_tc_expect_fail("x86 architecture does not correctly " "report the address where the unaligned access occured"); } ATF_REQUIRE_EQ(info->si_addr, (volatile void *)addr); atf_tc_pass(); /* NOTREACHED */ }
ATF_TC_BODY(fexecve, tc) { int status; pid_t pid; const char *const argv[] = { "touch", "test", NULL }; const char *const envp[] = { NULL }; ATF_REQUIRE((pid = fork()) != -1); if (pid == 0) { int fd; if ((fd = open("/usr/bin/touch", O_RDONLY, 0)) == -1) err(EXIT_FAILURE, "open /usr/bin/touch"); if (fexecve(fd, __UNCONST(argv), __UNCONST(envp)) == -1) { int error; if (errno == ENOSYS) error = 76; else error = EXIT_FAILURE; #ifdef __FreeBSD__ (void)close(fd); #endif err(error, "fexecve"); } } ATF_REQUIRE(waitpid(pid, &status, 0) != -1); if (!WIFEXITED(status)) atf_tc_fail("child process did not exit cleanly"); if (WEXITSTATUS(status) == 76) atf_tc_expect_fail("fexecve not implemented"); else ATF_REQUIRE(WEXITSTATUS(status) == EXIT_SUCCESS); ATF_REQUIRE(access("test", F_OK) == 0); }
ATF_TC_BODY(mknod_stat, tc) { struct stat st; (void)memset(&st, 0, sizeof(struct stat)); ATF_REQUIRE(mknod(path, S_IFCHR, 0) == 0); ATF_REQUIRE(stat(path, &st) == 0); if (S_ISCHR(st.st_mode) == 0) atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFCHR)"); ATF_REQUIRE(unlink(path) == 0); (void)memset(&st, 0, sizeof(struct stat)); ATF_REQUIRE(mknod(path, S_IFBLK, 0) == 0); ATF_REQUIRE(stat(path, &st) == 0); if (S_ISBLK(st.st_mode) == 0) atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFBLK)"); ATF_REQUIRE(unlink(path) == 0); (void)memset(&st, 0, sizeof(struct stat)); #ifdef __FreeBSD__ atf_tc_expect_fail("mknod does not allow S_IFREG"); #endif ATF_REQUIRE(mknod(path, S_IFREG, 0) == 0); ATF_REQUIRE(stat(path, &st) == 0); if (S_ISREG(st.st_mode) == 0) atf_tc_fail_nonfatal("invalid mode from mknod(2) (S_IFREG)"); ATF_REQUIRE(unlink(path) == 0); }