summaryrefslogtreecommitdiffstats
path: root/tests/sys
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-05-31 08:36:47 +0000
committerngie <ngie@FreeBSD.org>2017-05-31 08:36:47 +0000
commitd904a582e1d5d155f808ff6b51db862298bc609f (patch)
tree916d9a1f46e89f65ffd25b5d22f22676f921d336 /tests/sys
parent8455a35d0d93a18b5747adef66bbe5dbf7c5f9a8 (diff)
downloadFreeBSD-src-d904a582e1d5d155f808ff6b51db862298bc609f.zip
FreeBSD-src-d904a582e1d5d155f808ff6b51db862298bc609f.tar.gz
MFC r319056,r319058,r319059,r319060,r319061,r319078:
r319056: tests/sys/file/ftruncate_test: use an exit code of 1 instead of -1 with err*(3). An exit code of -1 is implementation defined -- it's best to stick with something well-defined (1). r319058: Create a deterministic file in the kyua sandbox, instead of a temporary file outside the kyua sandbox This helps ensure that the file is removed at test exit, and as a side effect, cures a warning about umasks with Coverity. r319059: Use an exit code of 1 instead of -1 for reasons noted in r319056 r319060: Use main(void) instead of main(argc __unused, argv __unused) r319061: Don't leak accept_fd on thread completion CID: 1296068 r319078: Tweak r319058 slightly - Specify an explicit mode when using O_CREAT per open(2). - Fix the error message (add missing enclosing parentheses). MFC with: r319058
Diffstat (limited to 'tests/sys')
-rw-r--r--tests/sys/file/ftruncate_test.c39
-rw-r--r--tests/sys/file/newfileops_on_fork_test.c23
2 files changed, 31 insertions, 31 deletions
diff --git a/tests/sys/file/ftruncate_test.c b/tests/sys/file/ftruncate_test.c
index b657aca..18bdb5a 100644
--- a/tests/sys/file/ftruncate_test.c
+++ b/tests/sys/file/ftruncate_test.c
@@ -60,14 +60,14 @@ int
main(void)
{
int error, fd, fds[2], i, read_only_fd;
- char path[PATH_MAX];
+ char path[] = "ftruncate_file";
struct stat sb;
ssize_t size;
off_t len;
char ch;
/*
- * Tests using a writable temporary file: grow and then shrink a file
+ * Tests using a writable file: grow and then shrink a file
* using ftruncate and various lengths. Make sure that a negative
* file length is rejected. Make sure that when we grow the file,
* bytes now in the range of the file size return 0.
@@ -75,37 +75,36 @@ main(void)
* Save a read-only reference to the file to use later for read-only
* descriptor tests.
*/
- snprintf(path, PATH_MAX, "/tmp/ftruncate.XXXXXXXXXXXXX");
- fd = mkstemp(path);
+ fd = open(path, O_RDWR|O_CREAT, 0600);
if (fd < 0)
- err(-1, "mkstemp");
+ err(1, "open(%s, O_RDWR|O_CREAT, 0600)", path);
read_only_fd = open(path, O_RDONLY);
if (read_only_fd < 0) {
error = errno;
(void)unlink(path);
errno = error;
- err(-1, "open(%s, O_RDONLY)", path);
+ err(1, "open(%s, O_RDONLY)", path);
}
(void)unlink(path);
if (ftruncate(fd, -1) == 0)
- errx(-1, "ftruncate(fd, -1) succeeded");
+ errx(1, "ftruncate(fd, -1) succeeded unexpectedly");
if (errno != EINVAL)
- err(-1, "ftruncate(fd, -1) returned wrong error");
+ err(1, "ftruncate(fd, -1) returned wrong error");
for (i = 0; i < lengths_count; i++) {
len = lengths[i];
if (ftruncate(fd, len) < 0)
- err(-1, "ftruncate(%jd) up", (intmax_t)len);
+ err(1, "ftruncate(%jd) up", (intmax_t)len);
if (fstat(fd, &sb) < 0)
- err(-1, "stat");
+ err(1, "stat");
if (sb.st_size != len)
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 %jd up", (intmax_t)len);
+ err(1, "pread on len %jd up", (intmax_t)len);
if (size != sizeof(ch))
errx(-1, "pread len %jd size %jd up",
(intmax_t)len, (intmax_t)size);
@@ -119,9 +118,9 @@ main(void)
for (i = lengths_count - 1; i >= 0; i--) {
len = lengths[i];
if (ftruncate(fd, len) < 0)
- err(-1, "ftruncate(%jd) down", (intmax_t)len);
+ err(1, "ftruncate(%jd) down", (intmax_t)len);
if (fstat(fd, &sb) < 0)
- err(-1, "stat");
+ err(1, "stat");
if (sb.st_size != len)
errx(-1, "fstat(%jd) returned %jd down", (intmax_t)len,
sb.st_size);
@@ -134,7 +133,7 @@ main(void)
if (ftruncate(read_only_fd, 0) == 0)
errx(-1, "ftruncate(read_only_fd) succeeded");
if (errno != EINVAL)
- err(-1, "ftruncate(read_only_fd) returned wrong error");
+ err(1, "ftruncate(read_only_fd) returned wrong error");
close(read_only_fd);
/*
@@ -142,22 +141,22 @@ main(void)
*/
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
- err(-1, "socket(PF_UNIX, SOCK_STREAM, 0)");
+ err(1, "socket(PF_UNIX, SOCK_STREAM, 0)");
if (ftruncate(fd, 0) == 0)
errx(-1, "ftruncate(socket) succeeded");
if (errno != EINVAL)
- err(-1, "ftruncate(socket) returned wrong error");
+ err(1, "ftruncate(socket) returned wrong error");
close(fd);
/*
* Make sure that ftruncate on pipes doesn't work.
*/
if (pipe(fds) < 0)
- err(-1, "pipe");
+ err(1, "pipe");
if (ftruncate(fds[0], 0) == 0)
errx(-1, "ftruncate(pipe) succeeded");
if (errno != EINVAL)
- err(-1, "ftruncate(pipe) returned wrong error");
+ err(1, "ftruncate(pipe) returned wrong error");
close(fds[0]);
close(fds[1]);
@@ -166,11 +165,11 @@ main(void)
*/
fd = kqueue();
if (fd < 0)
- err(-1, "kqueue");
+ err(1, "kqueue");
if (ftruncate(fds[0], 0) == 0)
errx(-1, "ftruncate(kqueue) succeeded");
if (errno != EINVAL)
- err(-1, "ftruncate(kqueue) returned wrong error");
+ err(1, "ftruncate(kqueue) returned wrong error");
close(fd);
return (0);
diff --git a/tests/sys/file/newfileops_on_fork_test.c b/tests/sys/file/newfileops_on_fork_test.c
index 85eea9d..d63bd4d 100644
--- a/tests/sys/file/newfileops_on_fork_test.c
+++ b/tests/sys/file/newfileops_on_fork_test.c
@@ -61,8 +61,9 @@ do_accept(__unused void *arg)
accept_fd = accept(listen_fd, NULL, NULL);
if (accept_fd < 0)
- err(-1, "accept");
+ err(1, "accept");
+ close(accept_fd);
return (NULL);
}
@@ -73,7 +74,7 @@ do_fork(void)
pid = fork();
if (pid < 0)
- err(-1, "fork");
+ err(1, "fork");
if (pid > 0) {
waitpid(pid, NULL, 0);
exit(0);
@@ -84,37 +85,37 @@ do_fork(void)
* listen_fd+1, and get back EBADF if it's not a valid descriptor,
* and EINVAL if it is. This (currently) works fine in practice.
*/
- if (ftruncate(listen_fd + 1, 0 < 0)) {
+ if (ftruncate(listen_fd + 1, 0) < 0) {
if (errno == EBADF)
exit(0);
else if (errno == EINVAL)
- errx(-1, "file descriptor still open in child");
+ errx(1, "file descriptor still open in child");
else
- err(-1, "unexpected error");
+ err(1, "unexpected error");
} else
- errx(-1, "ftruncate succeeded");
+ errx(1, "ftruncate succeeded");
}
int
-main(__unused int argc, __unused char *argv[])
+main(void)
{
struct sockaddr_in sin;
pthread_t accept_thread;
listen_fd = socket(PF_INET, SOCK_STREAM, 0);
if (listen_fd < 0)
- err(-1, "socket");
+ err(1, "socket");
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_len = sizeof(sin);
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
sin.sin_port = htons(PORT);
if (bind(listen_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0)
- err(-1, "bind");
+ err(1, "bind");
if (listen(listen_fd, -1) <0)
- err(-1, "listen");
+ err(1, "listen");
if (pthread_create(&accept_thread, NULL, do_accept, NULL) != 0)
- err(-1, "pthread_create");
+ err(1, "pthread_create");
sleep(1); /* Easier than using a CV. */
do_fork();
exit(0);
OpenPOWER on IntegriCloud