diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 0c1d671698be..3c6bd7e511d4 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -354,6 +354,8 @@ .. .. sys + file + .. kern .. kqueue diff --git a/tests/sys/Makefile b/tests/sys/Makefile index 7b07935a03f5..4e1bae5a70e7 100644 --- a/tests/sys/Makefile +++ b/tests/sys/Makefile @@ -4,6 +4,7 @@ TESTSDIR= ${TESTSBASE}/sys +TESTS_SUBDIRS+= file TESTS_SUBDIRS+= kern TESTS_SUBDIRS+= kqueue TESTS_SUBDIRS+= mqueue diff --git a/tools/regression/file/closefrom/closefrom.c b/tests/sys/file/closefrom_test.c similarity index 94% rename from tools/regression/file/closefrom/closefrom.c rename to tests/sys/file/closefrom_test.c index e119f20af48c..bd4acf60c2d4 100644 --- a/tools/regression/file/closefrom/closefrom.c +++ b/tests/sys/file/closefrom_test.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -132,37 +133,37 @@ devnull(void) { int fd; - fd = open("/dev/null", O_RDONLY); + fd = open(_PATH_DEVNULL, O_RDONLY); if (fd < 0) - fail_err("open(\"/dev/null\")"); + fail_err("open(\" "_PATH_DEVNULL" \")"); return (fd); } int -main(int __unused argc, char __unused *argv[]) +main(void) { struct shared_info *info; pid_t pid; - int fd, i; + int fd, i, start; printf("1..15\n"); /* We better start up with fd's 0, 1, and 2 open. */ - fd = devnull(); - if (fd != 3) - fail("open", "bad descriptor %d", fd); + start = devnull(); + if (start == -1) + fail("open", "bad descriptor %d", start); ok("open"); /* Make sure highest_fd() works. */ fd = highest_fd(); - if (fd != 3) - fail("highest_fd", "bad descriptor %d", 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(3); + closefrom(start + 1); fd = highest_fd(); - if (fd != 2) + if (fd != start) fail("closefrom", "highest fd %d", fd); ok("closefrom"); @@ -170,7 +171,7 @@ main(int __unused argc, char __unused *argv[]) for (i = 0; i < 16; i++) (void)devnull(); fd = highest_fd(); - if (fd != 18) + if (fd != start + 16) fail("open 16", "highest fd %d", fd); ok("open 16"); @@ -269,6 +270,6 @@ main(int __unused argc, char __unused *argv[]) 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 similarity index 100% rename from tools/regression/file/dup/dup.c rename to tests/sys/file/dup_test.c diff --git a/tools/regression/file/fcntlflags/fcntlflags.c b/tests/sys/file/fcntlflags_test.c similarity index 100% rename from tools/regression/file/fcntlflags/fcntlflags.c rename to tests/sys/file/fcntlflags_test.c diff --git a/tools/regression/file/flock/flock.c b/tests/sys/file/flock_helper.c similarity index 100% rename from tools/regression/file/flock/flock.c rename to 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 000000000000..ac3e79957329 --- /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 similarity index 90% rename from tools/regression/file/ftruncate/ftruncate.c rename to tests/sys/file/ftruncate_test.c index aebcdcd85b2c..7eaba14e2bfa 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 similarity index 100% rename from tools/regression/file/newfileops_on_fork/newfileops_on_fork.c rename to tests/sys/file/newfileops_on_fork_test.c diff --git a/tools/regression/file/closefrom/Makefile b/tools/regression/file/closefrom/Makefile deleted file mode 100644 index 4b8829c78484..000000000000 --- a/tools/regression/file/closefrom/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD$ - -PROG= closefrom -MAN= -WARNS?= 6 -DPADD= ${LIBUTIL} -LDADD= -lutil - -.include diff --git a/tools/regression/file/closefrom/closefrom.t b/tools/regression/file/closefrom/closefrom.t deleted file mode 100644 index 8bdfd03be81b..000000000000 --- a/tools/regression/file/closefrom/closefrom.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/dup/Makefile b/tools/regression/file/dup/Makefile deleted file mode 100644 index 225c2e270cbf..000000000000 --- a/tools/regression/file/dup/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $FreeBSD$ - -PROG= dup -MAN= -WARNS?= 6 - -.include diff --git a/tools/regression/file/dup/dup.t b/tools/regression/file/dup/dup.t deleted file mode 100644 index 8bdfd03be81b..000000000000 --- 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 9e7fc3e2ae6d..000000000000 --- a/tools/regression/file/fcntlflags/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $FreeBSD$ - -PROG= fcntlflags -MAN= -WARNS?= 6 - -.include diff --git a/tools/regression/file/fcntlflags/fcntlflags.t b/tools/regression/file/fcntlflags/fcntlflags.t deleted file mode 100644 index 8bdfd03be81b..000000000000 --- 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 cd1a46d8171b..000000000000 --- a/tools/regression/file/flock/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD$ - -PROG= flock -MAN= -WARNS?= 6 -DPADD= ${LIBPTHREAD} -LDADD= -lpthread - -.include diff --git a/tools/regression/file/ftruncate/Makefile b/tools/regression/file/ftruncate/Makefile deleted file mode 100644 index 40b753e2314d..000000000000 --- a/tools/regression/file/ftruncate/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $FreeBSD$ - -PROG= ftruncate -MAN= -WARNS?= 2 - -.include diff --git a/tools/regression/file/newfileops_on_fork/Makefile b/tools/regression/file/newfileops_on_fork/Makefile deleted file mode 100644 index be0c5feb0c42..000000000000 --- 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