Integrate tools/regression/fifo into the FreeBSD test suite as tests/sys/fifo
and tools/regression/file into the FreeBSD test suite as tests/sys/file MFC after: 1 week
This commit is contained in:
commit
64404803e0
@ -354,6 +354,10 @@
|
||||
..
|
||||
..
|
||||
sys
|
||||
fifo
|
||||
..
|
||||
file
|
||||
..
|
||||
kern
|
||||
execve
|
||||
..
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
TESTSDIR= ${TESTSBASE}/sys
|
||||
|
||||
TESTS_SUBDIRS+= fifo
|
||||
TESTS_SUBDIRS+= file
|
||||
TESTS_SUBDIRS+= kern
|
||||
TESTS_SUBDIRS+= kqueue
|
||||
TESTS_SUBDIRS+= netinet
|
||||
|
13
tests/sys/fifo/Makefile
Normal file
13
tests/sys/fifo/Makefile
Normal file
@ -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>
|
@ -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);
|
@ -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);
|
@ -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);
|
@ -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)
|
25
tests/sys/file/Makefile
Normal file
25
tests/sys/file/Makefile
Normal file
@ -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>
|
275
tests/sys/file/closefrom_test.c
Normal file
275
tests/sys/file/closefrom_test.c
Normal file
@ -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);
|
||||
}
|
57
tests/sys/file/flock_test.sh
Executable file
57
tests/sys/file/flock_test.sh
Executable 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
|
@ -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);
|
@ -1,7 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= fifo_create
|
||||
MAN=
|
||||
WARNS?= 3
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,7 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= fifo_io
|
||||
MAN=
|
||||
WARNS?= 3
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,7 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= fifo_misc
|
||||
MAN=
|
||||
WARNS?= 3
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,7 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= fifo_open
|
||||
MAN=
|
||||
WARNS?= 3
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,7 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= dup
|
||||
MAN=
|
||||
WARNS?= 6
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
# $FreeBSD$
|
||||
|
||||
cd `dirname $0`
|
||||
|
||||
executable=`basename $0 .t`
|
||||
|
||||
make $executable 2>&1 > /dev/null
|
||||
|
||||
exec ./$executable
|
@ -1,7 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= fcntlflags
|
||||
MAN=
|
||||
WARNS?= 6
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
# $FreeBSD$
|
||||
|
||||
cd `dirname $0`
|
||||
|
||||
executable=`basename $0 .t`
|
||||
|
||||
make $executable 2>&1 > /dev/null
|
||||
|
||||
exec ./$executable
|
@ -1,9 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= flock
|
||||
MAN=
|
||||
WARNS?= 6
|
||||
DPADD= ${LIBPTHREAD}
|
||||
LDADD= -lpthread
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,7 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= ftruncate
|
||||
MAN=
|
||||
WARNS?= 2
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,8 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= newfileops_on_fork
|
||||
MAN=
|
||||
WARNS?= 6
|
||||
LDFLAGS= -lpthread
|
||||
|
||||
.include <bsd.prog.mk>
|
Loading…
Reference in New Issue
Block a user