summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/mtree/BSD.tests.dist4
-rw-r--r--tests/sys/Makefile2
-rw-r--r--tests/sys/fifo/Makefile13
-rw-r--r--tests/sys/fifo/fifo_create.c (renamed from tools/regression/fifo/fifo_create/fifo_create.c)17
-rw-r--r--tests/sys/fifo/fifo_io.c (renamed from tools/regression/fifo/fifo_io/fifo_io.c)48
-rw-r--r--tests/sys/fifo/fifo_misc.c (renamed from tools/regression/fifo/fifo_misc/fifo_misc.c)15
-rw-r--r--tests/sys/fifo/fifo_open.c (renamed from tools/regression/fifo/fifo_open/fifo_open.c)6
-rw-r--r--tests/sys/file/Makefile25
-rw-r--r--tests/sys/file/closefrom_test.c275
-rw-r--r--tests/sys/file/dup_test.c (renamed from tools/regression/file/dup/dup.c)0
-rw-r--r--tests/sys/file/fcntlflags_test.c (renamed from tools/regression/file/fcntlflags/fcntlflags.c)0
-rw-r--r--tests/sys/file/flock_helper.c (renamed from tools/regression/file/flock/flock.c)0
-rwxr-xr-xtests/sys/file/flock_test.sh57
-rw-r--r--tests/sys/file/ftruncate_test.c (renamed from tools/regression/file/ftruncate/ftruncate.c)24
-rw-r--r--tests/sys/file/newfileops_on_fork_test.c (renamed from tools/regression/file/newfileops_on_fork/newfileops_on_fork.c)0
-rw-r--r--tools/regression/fifo/fifo_create/Makefile7
-rw-r--r--tools/regression/fifo/fifo_io/Makefile7
-rw-r--r--tools/regression/fifo/fifo_misc/Makefile7
-rw-r--r--tools/regression/fifo/fifo_open/Makefile7
-rw-r--r--tools/regression/file/dup/Makefile7
-rw-r--r--tools/regression/file/dup/dup.t10
-rw-r--r--tools/regression/file/fcntlflags/Makefile7
-rw-r--r--tools/regression/file/fcntlflags/fcntlflags.t10
-rw-r--r--tools/regression/file/flock/Makefile9
-rw-r--r--tools/regression/file/ftruncate/Makefile7
-rw-r--r--tools/regression/file/newfileops_on_fork/Makefile8
26 files changed, 424 insertions, 148 deletions
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index 699dd45..be01551 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -178,6 +178,10 @@
..
..
sys
+ fifo
+ ..
+ file
+ ..
kern
..
kqueue
diff --git a/tests/sys/Makefile b/tests/sys/Makefile
index 4eb9a5e..5a345c4 100644
--- a/tests/sys/Makefile
+++ b/tests/sys/Makefile
@@ -4,6 +4,8 @@
TESTSDIR= ${TESTSBASE}/sys
+TESTS_SUBDIRS+= fifo
+TESTS_SUBDIRS+= file
TESTS_SUBDIRS+= kern
TESTS_SUBDIRS+= kqueue
TESTS_SUBDIRS+= netinet
diff --git a/tests/sys/fifo/Makefile b/tests/sys/fifo/Makefile
new file mode 100644
index 0000000..602bf1e
--- /dev/null
+++ b/tests/sys/fifo/Makefile
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/sys/fifo
+
+PLAIN_TESTS_C+= fifo_create
+PLAIN_TESTS_C+= fifo_io
+PLAIN_TESTS_C+= fifo_misc
+PLAIN_TESTS_C+= fifo_open
+
+TEST_METADATA.fifo_create+= required_user="root"
+TEST_METADATA.fifo_open+= required_user="root"
+
+.include <bsd.test.mk>
diff --git a/tools/regression/fifo/fifo_create/fifo_create.c b/tests/sys/fifo/fifo_create.c
index 4e8a8a4..2eb01e5 100644
--- a/tools/regression/fifo/fifo_create/fifo_create.c
+++ b/tests/sys/fifo/fifo_create.c
@@ -75,7 +75,7 @@
* All activity occurs within a temporary directory created early in the
* test.
*/
-char temp_dir[PATH_MAX];
+static char temp_dir[PATH_MAX];
static void __unused
atexit_temp_dir(void)
@@ -94,7 +94,7 @@ fifo_create_test(int use_mkfifo)
{
struct stat old_dirsb, dirsb, fifosb;
const char *testname;
- char path[PATH_MAX];
+ char path[] = "testfifo";
int error;
if (use_mkfifo)
@@ -106,14 +106,12 @@ fifo_create_test(int use_mkfifo)
* Sleep to make sure that the time stamp on the directory will be
* updated.
*/
- if (stat(temp_dir, &old_dirsb) < 0)
+ if (stat(".", &old_dirsb) < 0)
err(-1, "basic_create_test: %s: stat: %s", testname,
temp_dir);
sleep(2);
- snprintf(path, PATH_MAX, "%s/testfifo", temp_dir);
-
if (use_mkfifo) {
if (mkfifo(path, 0600) < 0)
err(-1, "basic_create_test: %s: %s", testname, path);
@@ -149,7 +147,7 @@ fifo_create_test(int use_mkfifo)
err(-1, "basic_create_test: dup %s unexpected error",
testname);
- if (stat(temp_dir, &dirsb) < 0) {
+ if (stat(".", &dirsb) < 0) {
error = errno;
(void)unlink(path);
errno = error;
@@ -205,7 +203,7 @@ fifo_permission_test(int use_mkfifo)
{
const struct permission_test *ptp;
mode_t __unused old_umask;
- char path[PATH_MAX];
+ char path[] = "testfifo";
const char *testname;
struct stat sb;
int error, i;
@@ -215,7 +213,6 @@ fifo_permission_test(int use_mkfifo)
else
testname = "mknod";
- snprintf(path, PATH_MAX, "%s/testfifo", temp_dir);
old_umask = umask(0022);
for (i = 0; i < permission_test_count; i++) {
ptp = &permission_test[i];
@@ -256,14 +253,14 @@ fifo_permission_test(int use_mkfifo)
}
int
-main(int argc, char *argv[])
+main(void)
{
int i;
if (geteuid() != 0)
errx(-1, "must be run as root");
- strcpy(temp_dir, "/tmp/fifo_create.XXXXXXXXXXX");
+ strcpy(temp_dir, "fifo_create.XXXXXXXXXXX");
if (mkdtemp(temp_dir) == NULL)
err(-1, "mkdtemp");
atexit(atexit_temp_dir);
diff --git a/tools/regression/fifo/fifo_io/fifo_io.c b/tests/sys/fifo/fifo_io.c
index 4d3c54e..93d4be7 100644
--- a/tools/regression/fifo/fifo_io/fifo_io.c
+++ b/tests/sys/fifo/fifo_io.c
@@ -88,7 +88,7 @@
* All activity occurs within a temporary directory created early in the
* test.
*/
-char temp_dir[PATH_MAX];
+static char temp_dir[PATH_MAX];
static void __unused
atexit_temp_dir(void)
@@ -130,8 +130,7 @@ cleanfifo3(const char *fifoname, int fd1, int fd2, int fd3)
* so using non-blocking opens in order to avoid deadlocking the process.
*/
static int
-openfifo(const char *fifoname, const char *testname, int *reader_fdp,
- int *writer_fdp)
+openfifo(const char *fifoname, int *reader_fdp, int *writer_fdp)
{
int error, fd1, fd2;
@@ -155,7 +154,7 @@ openfifo(const char *fifoname, const char *testname, int *reader_fdp,
* Open one file descriptor for the fifo, supporting both read and write.
*/
static int
-openfifo_rw(const char *fifoname, const char *testname, int *fdp)
+openfifo_rw(const char *fifoname, int *fdp)
{
int fd;
@@ -249,7 +248,7 @@ test_simpleio(void)
ssize_t len;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", "test_simpleio", &reader_fd, &writer_fd)
+ if (openfifo("testfifo", &reader_fd, &writer_fd)
< 0) {
warn("test_simpleio: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
@@ -296,12 +295,12 @@ test_simpleio(void)
cleanfifo2("testfifo", reader_fd, writer_fd);
}
-static int alarm_fired;
+static volatile int alarm_fired;
/*
* Non-destructive SIGALRM handler.
*/
static void
-sigalarm(int signum)
+sigalarm(int signum __unused)
{
alarm_fired = 1;
@@ -408,7 +407,7 @@ test_blocking_read_empty(void)
u_char ch;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
+ if (openfifo("testfifo", &reader_fd, &writer_fd)
< 0) {
warn("test_blocking_read_empty: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
@@ -477,8 +476,7 @@ test_blocking_one_byte(void)
u_char ch;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
- < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_blocking: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -544,8 +542,7 @@ test_nonblocking_one_byte(void)
u_char ch;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
- < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_nonblocking: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -609,8 +606,7 @@ test_blocking_partial_write(void)
ssize_t len;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
- < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_blocking_partial_write: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -668,8 +664,7 @@ test_nonblocking_partial_write(void)
ssize_t len;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
- < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_blocking_partial_write: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -736,8 +731,7 @@ test_coalesce_big_read(void)
ssize_t len;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
- < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_coalesce_big_read: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -808,8 +802,7 @@ test_coalesce_big_write(void)
ssize_t len;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
- < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_coalesce_big_write: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -1078,7 +1071,7 @@ test_events_outofbox(void)
int kqueue_fd, reader_fd, writer_fd;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd) < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_events_outofbox: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -1134,8 +1127,7 @@ test_events_write_read_byte(void)
u_char ch;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
- < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_events_write_read_byte: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -1227,8 +1219,7 @@ test_events_partial_write(void)
ssize_t len;
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd)
- < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("test_events_partial_write: openfifo: testfifo");
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -1313,8 +1304,7 @@ test_events_rdwr(void)
char ch;
makefifo("testfifo", __func__);
- if (openfifo_rw("testfifo", __func__, &fd)
- < 0) {
+ if (openfifo_rw("testfifo", &fd) < 0) {
warn("%s: openfifo_rw: testfifo", __func__);
cleanfifo2("testfifo", -1, -1);
exit(-1);
@@ -1381,10 +1371,10 @@ test_events_rdwr(void)
}
int
-main(int argc, char *argv[])
+main(void)
{
- strcpy(temp_dir, "/tmp/fifo_io.XXXXXXXXXXX");
+ strcpy(temp_dir, "fifo_io.XXXXXXXXXXX");
if (mkdtemp(temp_dir) == NULL)
err(-1, "mkdtemp");
atexit(atexit_temp_dir);
diff --git a/tools/regression/fifo/fifo_misc/fifo_misc.c b/tests/sys/fifo/fifo_misc.c
index 4215212..888547e 100644
--- a/tools/regression/fifo/fifo_misc/fifo_misc.c
+++ b/tests/sys/fifo/fifo_misc.c
@@ -50,7 +50,7 @@
* All activity occurs within a temporary directory created early in the
* test.
*/
-char temp_dir[PATH_MAX];
+static char temp_dir[PATH_MAX];
static void __unused
atexit_temp_dir(void)
@@ -79,8 +79,7 @@ cleanfifo(const char *fifoname, int fd1, int fd2)
}
static int
-openfifo(const char *fifoname, const char *testname, int *reader_fdp,
- int *writer_fdp)
+openfifo(const char *fifoname, int *reader_fdp, int *writer_fdp)
{
int error, fd1, fd2;
@@ -110,7 +109,7 @@ test_lseek(void)
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd) < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("%s: openfifo", __func__);
cleanfifo("testfifo", -1, -1);
exit(-1);
@@ -185,7 +184,7 @@ test_ioctl(void)
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd) < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("%s: openfifo", __func__);
cleanfifo("testfifo", -1, -1);
exit(-1);
@@ -237,7 +236,7 @@ test_chmodchown(void)
makefifo("testfifo", __func__);
- if (openfifo("testfifo", __func__, &reader_fd, &writer_fd) < 0) {
+ if (openfifo("testfifo", &reader_fd, &writer_fd) < 0) {
warn("%s: openfifo", __func__);
cleanfifo("testfifo", -1, -1);
exit(-1);
@@ -316,10 +315,10 @@ test_chmodchown(void)
}
int
-main(int argc, char *argv[])
+main(void)
{
- strcpy(temp_dir, "/tmp/fifo_misc.XXXXXXXXXXX");
+ strcpy(temp_dir, "fifo_misc.XXXXXXXXXXX");
if (mkdtemp(temp_dir) == NULL)
err(-1, "mkdtemp");
atexit(atexit_temp_dir);
diff --git a/tools/regression/fifo/fifo_open/fifo_open.c b/tests/sys/fifo/fifo_open.c
index 6899a3a..892f481 100644
--- a/tools/regression/fifo/fifo_open/fifo_open.c
+++ b/tests/sys/fifo/fifo_open.c
@@ -87,7 +87,7 @@
* All activity occurs within a temporary directory created early in the
* test.
*/
-char temp_dir[PATH_MAX];
+static char temp_dir[PATH_MAX];
static void __unused
atexit_temp_dir(void)
@@ -453,13 +453,13 @@ test_non_blocking_writer(void)
}
int
-main(int argc, char *argv[])
+main(void)
{
if (geteuid() != 0)
errx(-1, "must be run as root");
- strcpy(temp_dir, "/tmp/fifo_open.XXXXXXXXXXX");
+ strcpy(temp_dir, "fifo_open.XXXXXXXXXXX");
if (mkdtemp(temp_dir) == NULL)
err(-1, "mkdtemp");
if (chdir(temp_dir) < 0)
diff --git a/tests/sys/file/Makefile b/tests/sys/file/Makefile
new file mode 100644
index 0000000..6151c9f
--- /dev/null
+++ b/tests/sys/file/Makefile
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+TESTSDIR= ${TESTSBASE}/sys/file
+
+BINDIR= ${TESTSDIR}
+
+TAP_TESTS_C+= closefrom_test
+TAP_TESTS_C+= dup_test
+TAP_TESTS_C+= fcntlflags_test
+TAP_TESTS_SH+= flock_test
+PLAIN_TESTS_C+= ftruncate_test
+PLAIN_TESTS_C+= newfileops_on_fork_test
+
+PROGS+= flock_helper
+
+DPADD.closefrom_test= ${LIBUTIL}
+LDADD.closefrom_test= -lutil
+
+DPADD.flock_helper= ${LIBPTHREAD}
+LDADD.flock_helper= -lpthread
+
+DPADD.newfileops_on_fork_test= ${LIBPTHREAD}
+LDADD.newfileops_on_fork_test= -lpthread
+
+.include <bsd.test.mk>
diff --git a/tests/sys/file/closefrom_test.c b/tests/sys/file/closefrom_test.c
new file mode 100644
index 0000000..78cfeec
--- /dev/null
+++ b/tests/sys/file/closefrom_test.c
@@ -0,0 +1,275 @@
+/*-
+ * Copyright (c) 2009 Hudson River Trading LLC
+ * Written by: John H. Baldwin <jhb@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Regression tests for the closefrom(2) system call.
+ */
+
+#include <sys/param.h>
+#include <sys/mman.h>
+#include <sys/user.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libutil.h>
+#include <paths.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+struct shared_info {
+ int failed;
+ char tag[64];
+ char message[0];
+};
+
+static int test = 1;
+
+static void
+ok(const char *descr)
+{
+
+ printf("ok %d - %s\n", test, descr);
+ test++;
+}
+
+static void
+fail(const char *descr, const char *fmt, ...)
+{
+ va_list ap;
+
+ printf("not ok %d - %s", test, descr);
+ test++;
+ if (fmt) {
+ va_start(ap, fmt);
+ printf(" # ");
+ vprintf(fmt, ap);
+ va_end(ap);
+ }
+ printf("\n");
+ exit(1);
+}
+
+#define fail_err(descr) fail((descr), "%s", strerror(errno))
+
+static void
+cok(struct shared_info *info, const char *descr)
+{
+
+ info->failed = 0;
+ strlcpy(info->tag, descr, sizeof(info->tag));
+ exit(0);
+}
+
+static void
+cfail(struct shared_info *info, const char *descr, const char *fmt, ...)
+{
+ va_list ap;
+
+ info->failed = 1;
+ strlcpy(info->tag, descr, sizeof(info->tag));
+ if (fmt) {
+ va_start(ap, fmt);
+ vsprintf(info->message, fmt, ap);
+ va_end(ap);
+ }
+ exit(0);
+}
+
+#define cfail_err(info, descr) cfail((info), (descr), "%s", strerror(errno))
+
+/*
+ * Use kinfo_getfile() to fetch the list of file descriptors and figure out
+ * the highest open file descriptor.
+ */
+static int
+highest_fd(void)
+{
+ struct kinfo_file *kif;
+ int cnt, i, highest;
+
+ kif = kinfo_getfile(getpid(), &cnt);
+ if (kif == NULL)
+ fail_err("kinfo_getfile");
+ highest = INT_MIN;
+ for (i = 0; i < cnt; i++)
+ if (kif[i].kf_fd > highest)
+ highest = kif[i].kf_fd;
+ free(kif);
+ return (highest);
+}
+
+static int
+devnull(void)
+{
+ int fd;
+
+ fd = open(_PATH_DEVNULL, O_RDONLY);
+ if (fd < 0)
+ fail_err("open(\" "_PATH_DEVNULL" \")");
+ return (fd);
+}
+
+int
+main(void)
+{
+ struct shared_info *info;
+ pid_t pid;
+ int fd, i, start;
+
+ printf("1..15\n");
+
+ /* We better start up with fd's 0, 1, and 2 open. */
+ start = devnull();
+ if (start == -1)
+ fail("open", "bad descriptor %d", start);
+ ok("open");
+
+ /* Make sure highest_fd() works. */
+ fd = highest_fd();
+ if (start != fd)
+ fail("highest_fd", "bad descriptor %d != %d", start, fd);
+ ok("highest_fd");
+
+ /* Try to use closefrom() for just closing fd 3. */
+ closefrom(start + 1);
+ fd = highest_fd();
+ if (fd != start)
+ fail("closefrom", "highest fd %d", fd);
+ ok("closefrom");
+
+ /* Eat up 16 descriptors. */
+ for (i = 0; i < 16; i++)
+ (void)devnull();
+ fd = highest_fd();
+ if (fd != start + 16)
+ fail("open 16", "highest fd %d", fd);
+ ok("open 16");
+
+ /* Close half of them. */
+ closefrom(11);
+ fd = highest_fd();
+ if (fd != 10)
+ fail("closefrom", "highest fd %d", fd);
+ ok("closefrom");
+
+ /* Explicitly close descriptors 6 and 8 to create holes. */
+ if (close(6) < 0 || close(8) < 0)
+ fail_err("close2 ");
+ ok("close 2");
+
+ /* Verify that close on 6 and 8 fails with EBADF. */
+ if (close(6) == 0)
+ fail("close(6)", "did not fail");
+ if (errno != EBADF)
+ fail_err("close(6)");
+ ok("close(6)");
+ if (close(8) == 0)
+ fail("close(8)", "did not fail");
+ if (errno != EBADF)
+ fail_err("close(8)");
+ ok("close(8)");
+
+ /* Close from 4 on. */
+ closefrom(4);
+ fd = highest_fd();
+ if (fd != 3)
+ fail("closefrom", "highest fd %d", fd);
+ ok("closefrom");
+
+ /* Allocate a small SHM region for IPC with our child. */
+ info = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_ANON |
+ MAP_SHARED, -1, 0);
+ if (info == MAP_FAILED)
+ fail_err("mmap");
+ ok("mmap");
+
+ /* Fork a child process to test closefrom(0). */
+ pid = fork();
+ if (pid < 0)
+ fail_err("fork");
+ if (pid == 0) {
+ /* Child. */
+ closefrom(0);
+ fd = highest_fd();
+ if (fd >= 0)
+ cfail(info, "closefrom(0)", "highest fd %d", fd);
+ cok(info, "closefrom(0)");
+ }
+ if (wait(NULL) < 0)
+ fail_err("wait");
+ if (info->failed)
+ fail(info->tag, "%s", info->message);
+ ok(info->tag);
+
+ /* Fork a child process to test closefrom(-1). */
+ pid = fork();
+ if (pid < 0)
+ fail_err("fork");
+ if (pid == 0) {
+ /* Child. */
+ closefrom(-1);
+ fd = highest_fd();
+ if (fd >= 0)
+ cfail(info, "closefrom(-1)", "highest fd %d", fd);
+ cok(info, "closefrom(-1)");
+ }
+ if (wait(NULL) < 0)
+ fail_err("wait");
+ if (info->failed)
+ fail(info->tag, "%s", info->message);
+ ok(info->tag);
+
+ /* Dup stdout to 6. */
+ if (dup2(1, 6) < 0)
+ fail_err("dup2");
+ fd = highest_fd();
+ if (fd != 6)
+ fail("dup2", "highest fd %d", fd);
+ ok("dup2");
+
+ /* Do a closefrom() starting in a hole. */
+ closefrom(4);
+ fd = highest_fd();
+ if (fd != 3)
+ fail("closefrom", "highest fd %d", fd);
+ ok("closefrom");
+
+ /* Do a closefrom() beyond our highest open fd. */
+ closefrom(32);
+ fd = highest_fd();
+ if (fd != 3)
+ fail("closefrom", "highest fd %d", fd);
+ ok("closefrom");
+
+ return (0);
+}
diff --git a/tools/regression/file/dup/dup.c b/tests/sys/file/dup_test.c
index 8173818..8173818 100644
--- a/tools/regression/file/dup/dup.c
+++ b/tests/sys/file/dup_test.c
diff --git a/tools/regression/file/fcntlflags/fcntlflags.c b/tests/sys/file/fcntlflags_test.c
index bcb3b54..bcb3b54 100644
--- a/tools/regression/file/fcntlflags/fcntlflags.c
+++ b/tests/sys/file/fcntlflags_test.c
diff --git a/tools/regression/file/flock/flock.c b/tests/sys/file/flock_helper.c
index 49e47b8..49e47b8 100644
--- a/tools/regression/file/flock/flock.c
+++ b/tests/sys/file/flock_helper.c
diff --git a/tests/sys/file/flock_test.sh b/tests/sys/file/flock_test.sh
new file mode 100755
index 0000000..ac3e799
--- /dev/null
+++ b/tests/sys/file/flock_test.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# Copyright 2014 EMC Corp.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * 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.
+# * Neither the name of Google Inc. nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+# OWNER 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.
+#
+# $FreeBSD$
+
+# Testcase # 11 is racy; uses an undocumented kernel interface for testing
+# locking
+# Testcase # 16 is racy/doesn't handle EINTR properly
+last_testcase=16
+
+echo "1..$last_testcase"
+
+for n in `seq 1 $last_testcase`; do
+ todomsg=""
+
+ if [ $n -eq 11 ]; then
+ todomsg=" # TODO: racy testcase"
+ # Test 16 fails:
+ # F_SETLKW on locked region by two threads: FAIL ((uintptr_t)res != 0)
+ elif [ $n -eq 16 ]; then
+ todomsg=" # TODO: racy testcase (doesn't handle EINTR properly)"
+ fi
+
+ $(dirname $0)/flock_helper . $n | grep -q SUCCEED
+ if [ $? -eq 0 ]; then
+ echo "ok $n$todomsg"
+ else
+ echo "not ok $n$todomsg"
+ fi
+done
diff --git a/tools/regression/file/ftruncate/ftruncate.c b/tests/sys/file/ftruncate_test.c
index aebcdcd..7eaba14 100644
--- a/tools/regression/file/ftruncate/ftruncate.c
+++ b/tests/sys/file/ftruncate_test.c
@@ -62,7 +62,7 @@ main(int argc, char *argv[])
int error, fd, fds[2], i, read_only_fd;
char path[PATH_MAX];
struct stat sb;
- size_t size;
+ ssize_t size;
off_t len;
char ch;
@@ -78,7 +78,7 @@ main(int argc, char *argv[])
snprintf(path, PATH_MAX, "/tmp/ftruncate.XXXXXXXXXXXXX");
fd = mkstemp(path);
if (fd < 0)
- err(-1, "makestemp");
+ err(-1, "mkstemp");
read_only_fd = open(path, O_RDONLY);
if (read_only_fd < 0) {
error = errno;
@@ -96,34 +96,34 @@ main(int argc, char *argv[])
for (i = 0; i < lengths_count; i++) {
len = lengths[i];
if (ftruncate(fd, len) < 0)
- err(-1, "ftruncate(%llu) up", len);
+ err(-1, "ftruncate(%jd) up", (intmax_t)len);
if (fstat(fd, &sb) < 0)
err(-1, "stat");
if (sb.st_size != len)
- errx(-1, "fstat(%llu) returned len %llu up", len,
- sb.st_size);
+ errx(-1, "fstat with len=%jd returned len %jd up",
+ (intmax_t)len, (intmax_t)sb.st_size);
if (len != 0) {
size = pread(fd, &ch, sizeof(ch), len - 1);
if (size < 0)
- err(-1, "pread on len %llu up", len);
+ err(-1, "pread on len %jd up", (intmax_t)len);
if (size != sizeof(ch))
- errx(-1, "pread len %llu size %jd up",
- len, (intmax_t)size);
+ errx(-1, "pread len %jd size %jd up",
+ (intmax_t)len, (intmax_t)size);
if (ch != 0)
errx(-1,
- "pread length %llu size %jd ch %d up",
- len, (intmax_t)size, ch);
+ "pread length %jd size %jd ch %d up",
+ (intmax_t)len, (intmax_t)size, ch);
}
}
for (i = lengths_count - 1; i >= 0; i--) {
len = lengths[i];
if (ftruncate(fd, len) < 0)
- err(-1, "ftruncate(%llu) down", len);
+ err(-1, "ftruncate(%jd) down", (intmax_t)len);
if (fstat(fd, &sb) < 0)
err(-1, "stat");
if (sb.st_size != len)
- errx(-1, "fstat(%llu) returned %llu down", len,
+ errx(-1, "fstat(%jd) returned %jd down", (intmax_t)len,
sb.st_size);
}
close(fd);
diff --git a/tools/regression/file/newfileops_on_fork/newfileops_on_fork.c b/tests/sys/file/newfileops_on_fork_test.c
index 8713a82..8713a82 100644
--- a/tools/regression/file/newfileops_on_fork/newfileops_on_fork.c
+++ b/tests/sys/file/newfileops_on_fork_test.c
diff --git a/tools/regression/fifo/fifo_create/Makefile b/tools/regression/fifo/fifo_create/Makefile
deleted file mode 100644
index 10e2b14..0000000
--- a/tools/regression/fifo/fifo_create/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= fifo_create
-MAN=
-WARNS?= 3
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/fifo/fifo_io/Makefile b/tools/regression/fifo/fifo_io/Makefile
deleted file mode 100644
index 49bf5bd..0000000
--- a/tools/regression/fifo/fifo_io/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= fifo_io
-MAN=
-WARNS?= 3
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/fifo/fifo_misc/Makefile b/tools/regression/fifo/fifo_misc/Makefile
deleted file mode 100644
index 97f85ec..0000000
--- a/tools/regression/fifo/fifo_misc/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= fifo_misc
-MAN=
-WARNS?= 3
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/fifo/fifo_open/Makefile b/tools/regression/fifo/fifo_open/Makefile
deleted file mode 100644
index d90811c..0000000
--- a/tools/regression/fifo/fifo_open/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= fifo_open
-MAN=
-WARNS?= 3
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/file/dup/Makefile b/tools/regression/file/dup/Makefile
deleted file mode 100644
index 225c2e2..0000000
--- a/tools/regression/file/dup/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= dup
-MAN=
-WARNS?= 6
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/file/dup/dup.t b/tools/regression/file/dup/dup.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/file/dup/dup.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/file/fcntlflags/Makefile b/tools/regression/file/fcntlflags/Makefile
deleted file mode 100644
index 9e7fc3e..0000000
--- a/tools/regression/file/fcntlflags/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= fcntlflags
-MAN=
-WARNS?= 6
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/file/fcntlflags/fcntlflags.t b/tools/regression/file/fcntlflags/fcntlflags.t
deleted file mode 100644
index 8bdfd03..0000000
--- a/tools/regression/file/fcntlflags/fcntlflags.t
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# $FreeBSD$
-
-cd `dirname $0`
-
-executable=`basename $0 .t`
-
-make $executable 2>&1 > /dev/null
-
-exec ./$executable
diff --git a/tools/regression/file/flock/Makefile b/tools/regression/file/flock/Makefile
deleted file mode 100644
index cd1a46d..0000000
--- a/tools/regression/file/flock/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-# $FreeBSD$
-
-PROG= flock
-MAN=
-WARNS?= 6
-DPADD= ${LIBPTHREAD}
-LDADD= -lpthread
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/file/ftruncate/Makefile b/tools/regression/file/ftruncate/Makefile
deleted file mode 100644
index 40b753e..0000000
--- a/tools/regression/file/ftruncate/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= ftruncate
-MAN=
-WARNS?= 2
-
-.include <bsd.prog.mk>
diff --git a/tools/regression/file/newfileops_on_fork/Makefile b/tools/regression/file/newfileops_on_fork/Makefile
deleted file mode 100644
index be0c5fe..0000000
--- a/tools/regression/file/newfileops_on_fork/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-# $FreeBSD$
-
-PROG= newfileops_on_fork
-MAN=
-WARNS?= 6
-LDFLAGS= -lpthread
-
-.include <bsd.prog.mk>
OpenPOWER on IntegriCloud