aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Holm <pho@FreeBSD.org>2021-09-20 07:36:27 +0000
committerPeter Holm <pho@FreeBSD.org>2021-09-20 07:36:27 +0000
commit9ac518adf03e371aa3e8499f84d995663bd4e0c1 (patch)
tree81bc8173ec0b6e36cd2b6eb1a46b6a3a33d0e817 /tools
parent7ba7bf48d5bd6ca89f4e81579456b74ee7aa9e4f (diff)
downloadsrc-9ac518adf03e371aa3e8499f84d995663bd4e0c1.tar.gz
src-9ac518adf03e371aa3e8499f84d995663bd4e0c1.zip
stress2: Update test to ensure propper cleanup of fifo files
Diffstat (limited to 'tools')
-rw-r--r--tools/test/stress2/testcases/mkfifo/mkfifo.c67
1 files changed, 25 insertions, 42 deletions
diff --git a/tools/test/stress2/testcases/mkfifo/mkfifo.c b/tools/test/stress2/testcases/mkfifo/mkfifo.c
index caeb5e45310b..fd4a68b7e0f2 100644
--- a/tools/test/stress2/testcases/mkfifo/mkfifo.c
+++ b/tools/test/stress2/testcases/mkfifo/mkfifo.c
@@ -26,82 +26,63 @@
*/
#include <sys/param.h>
-#include <sys/types.h>
#include <sys/stat.h>
-#include <stdio.h>
+#include <sys/wait.h>
+
+#include <err.h>
#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
#include <signal.h>
-#include <sys/wait.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <err.h>
+#include <unistd.h>
#include "stress.h"
static char path[MAXPATHLEN+1];
-#define NB (1 * 1024 * 1024)
-
-static int bufsize;
-static int freespace;
-
-static void
-handler2(int i __unused)
-{
- _exit(0);
-}
+static int bufsize, freespace;
static void
reader(void) {
- int fd;
- int i, n, *buf;
+ fd_set set;
+ struct timeval tv;
+ int *buf, fd, n;
setproctitle("reader");
- signal(SIGALRM, handler2);
- alarm(60);
- if ((fd = open(path, O_RDWR, 0600)) < 0) {
- unlink(path);
+ if ((fd = open(path, O_RDONLY | O_NONBLOCK)) < 0)
err(1, "open(%s)", path);
- }
if ((buf = malloc(bufsize)) == NULL)
err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__);
- for (i = 0; i < NB; i+= bufsize) {
+ n = 0;
+ FD_ZERO(&set);
+ FD_SET(fd, &set);
+ tv.tv_sec = 10;
+ tv.tv_usec = 0;
+ if (select(fd + 1, &set, NULL, NULL, &tv) == 1) {
if ((n = read(fd, buf, bufsize)) < 0)
err(1, "read(), %s:%d", __FILE__, __LINE__);
- if (n == 0) break;
}
close(fd);
free(buf);
- return;
}
static void
writer(void) {
- int i, *buf;
- int fd;
-
- signal(SIGALRM, handler2);
- alarm(60);
+ int *buf, fd;
setproctitle("writer");
- if ((fd = open(path, O_RDWR, 0600)) < 0) {
+ if ((fd = open(path, O_WRONLY)) < 0) {
unlink(path);
err(1, "open(%s)", path);
}
if ((buf = malloc(bufsize)) == NULL)
err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__);
- for (i = 0; i < bufsize / (int)sizeof(int); i++)
- buf[i] = i;
-
- for (i = 0; i < NB; i+= bufsize) {
- if (write(fd, buf, bufsize) < 0) {
- err(1, "write(%d), %s:%d", fd,
- __FILE__, __LINE__);
- }
- }
+ memset(buf, 0, bufsize);
+
+ if (write(fd, buf, bufsize) < 0)
+ err(1, "write(%d), %s:%d", fd, __FILE__, __LINE__);
close(fd);
free(buf);
- return;
}
int
@@ -134,6 +115,7 @@ setup(int nb)
if (!freespace)
_exit(0);
bufsize = 2 << random_int(2, 12);
+
return (0);
}
@@ -179,5 +161,6 @@ test(void)
err(1, "fork(), %s:%d", __FILE__, __LINE__);
unlink(path);
+
return (0);
}