Integrate tools/regression/file into the FreeBSD test suite as tests/sys/file

This commit is contained in:
ngie 2015-04-11 10:14:59 +00:00
parent 305b739a89
commit e2cd8e97c5
18 changed files with 86 additions and 102 deletions

View File

@ -354,6 +354,8 @@
..
..
sys
file
..
kern
..
kqueue

View File

@ -4,6 +4,7 @@
TESTSDIR= ${TESTSBASE}/sys
TESTS_SUBDIRS+= file
TESTS_SUBDIRS+= kern
TESTS_SUBDIRS+= kqueue
TESTS_SUBDIRS+= mqueue

View File

@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <libutil.h>
#include <paths.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@ -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);
}

57
tests/sys/file/flock_test.sh Executable file
View File

@ -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

View File

@ -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);

View File

@ -1,9 +0,0 @@
# $FreeBSD$
PROG= closefrom
MAN=
WARNS?= 6
DPADD= ${LIBUTIL}
LDADD= -lutil
.include <bsd.prog.mk>

View File

@ -1,10 +0,0 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
executable=`basename $0 .t`
make $executable 2>&1 > /dev/null
exec ./$executable

View File

@ -1,7 +0,0 @@
# $FreeBSD$
PROG= dup
MAN=
WARNS?= 6
.include <bsd.prog.mk>

View File

@ -1,10 +0,0 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
executable=`basename $0 .t`
make $executable 2>&1 > /dev/null
exec ./$executable

View File

@ -1,7 +0,0 @@
# $FreeBSD$
PROG= fcntlflags
MAN=
WARNS?= 6
.include <bsd.prog.mk>

View File

@ -1,10 +0,0 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
executable=`basename $0 .t`
make $executable 2>&1 > /dev/null
exec ./$executable

View File

@ -1,9 +0,0 @@
# $FreeBSD$
PROG= flock
MAN=
WARNS?= 6
DPADD= ${LIBPTHREAD}
LDADD= -lpthread
.include <bsd.prog.mk>

View File

@ -1,7 +0,0 @@
# $FreeBSD$
PROG= ftruncate
MAN=
WARNS?= 2
.include <bsd.prog.mk>

View File

@ -1,8 +0,0 @@
# $FreeBSD$
PROG= newfileops_on_fork
MAN=
WARNS?= 6
LDFLAGS= -lpthread
.include <bsd.prog.mk>