diff options
Diffstat (limited to 'tools/regression')
-rw-r--r-- | tools/regression/pipe/Makefile | 16 | ||||
-rw-r--r-- | tools/regression/pipe/bigpipetest.c | 82 | ||||
-rw-r--r-- | tools/regression/pipe/bigpipetest.t | 10 | ||||
-rw-r--r-- | tools/regression/pipe/pipe-fstatbug.c | 82 | ||||
-rw-r--r-- | tools/regression/pipe/pipe-ino.c | 66 | ||||
-rw-r--r-- | tools/regression/pipe/pipe-overcommit1.c | 47 | ||||
-rw-r--r-- | tools/regression/pipe/pipe-overcommit2.c | 69 | ||||
-rw-r--r-- | tools/regression/pipe/pipe-reverse.c | 113 | ||||
-rw-r--r-- | tools/regression/pipe/pipe-reverse2.c | 67 | ||||
-rw-r--r-- | tools/regression/pipe/pipe-wraparound.c | 103 |
10 files changed, 0 insertions, 655 deletions
diff --git a/tools/regression/pipe/Makefile b/tools/regression/pipe/Makefile deleted file mode 100644 index 8a5f83a..0000000 --- a/tools/regression/pipe/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# -# $FreeBSD$ -# -# "make" then "make regress". -# -PROG= bigpipetest -MAN= - -regress: - @if ./bigpipetest; then \ - echo "PASS"; \ - else \ - echo "FAIL"; \ - fi - -.include <bsd.prog.mk> diff --git a/tools/regression/pipe/bigpipetest.c b/tools/regression/pipe/bigpipetest.c deleted file mode 100644 index c5983fa..0000000 --- a/tools/regression/pipe/bigpipetest.c +++ /dev/null @@ -1,82 +0,0 @@ -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <stdlib.h> -#include <sys/select.h> -#include <string.h> -#include <errno.h> - -#define BIG_PIPE_SIZE 64*1024 /* From sys/pipe.h */ - -/* - * Test for the non-blocking big pipe bug (write(2) returning - * EAGAIN while select(2) returns the descriptor as ready for write). - * - * $FreeBSD$ - */ - -void write_frame(int fd, char *buf, unsigned long buflen) -{ - fd_set wfd; - int i; - - while (buflen) { - FD_ZERO(&wfd); - FD_SET(fd, &wfd); - i = select(fd+1, NULL, &wfd, NULL, NULL); - if (i < 0) { - perror("select"); - exit(1); - } - if (i != 1) { - fprintf(stderr, "select returned unexpected value %d\n", i); - exit(1); - } - i = write(fd, buf, buflen); - if (i < 0) { - if (errno != EAGAIN) - perror("write"); - exit(1); - } - buf += i; - buflen -= i; - } -} - -int main() -{ - char buf[BIG_PIPE_SIZE]; /* any value over PIPE_SIZE should do */ - int i, flags, fd[2]; - - printf("1..1\n"); - - if (pipe(fd) < 0) { perror("pipe"); exit(1); } - - flags = fcntl(fd[1], F_GETFL); - if (flags == -1 || fcntl(fd[1], F_SETFL, flags|O_NONBLOCK) == -1) { - perror("fcntl"); - exit(1); - } - - switch (fork()) { - case -1: - perror("fork"); - exit(1); - case 0: - close(fd[1]); - for (;;) { - i = read(fd[0], buf, 256); /* any small size should do */ - if (i == 0) break; - if (i < 0) { perror("read"); exit(1); } - } - exit(0); - default: - break; - } - - close(fd[0]); - memset(buf, 0, sizeof buf); - for (i = 0; i < 1000; i++) write_frame(fd[1], buf, sizeof buf); - printf("ok 1\n"); - exit(0); -} diff --git a/tools/regression/pipe/bigpipetest.t b/tools/regression/pipe/bigpipetest.t deleted file mode 100644 index 8bdfd03..0000000 --- a/tools/regression/pipe/bigpipetest.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/pipe/pipe-fstatbug.c b/tools/regression/pipe/pipe-fstatbug.c deleted file mode 100644 index 724c2d8..0000000 --- a/tools/regression/pipe/pipe-fstatbug.c +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright (C) 2004 Michael J. Silbersack. 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 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 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 <stdio.h> -#include <unistd.h> -#include <sys/stat.h> - -/* - * $FreeBSD$ - * The goal of this program is to see if fstat reports the correct - * data count for a pipe. Prior to revision 1.172 of sys_pipe.c, - * 0 would be returned once the pipe entered direct write mode. - * - * Linux (2.6) always returns zero, so it's not a valuable platform - * for comparison. - */ - -int main (void) -{ -char buffer[32768], buffer2[32768]; -int desc[2]; -int error, successes = 0; -struct stat status; -pid_t new_pid; - -error = pipe(desc); - -if (error) - err(0, "Couldn't allocate fds\n"); - -new_pid = fork(); - -if (new_pid == 0) { - write(desc[1], &buffer, 145); - usleep(1000000); - write(desc[1], &buffer, 2048); - usleep(1000000); - write(desc[1], &buffer, 4096); - usleep(1000000); - write(desc[1], &buffer, 8191); - usleep(1000000); - write(desc[1], &buffer, 8192); - usleep(1000000); -} else { - while (successes < 5) { - usleep(3000); - fstat(desc[0], &status); - error = read(desc[0], &buffer2, 32768); - if (status.st_size != error) - err(0, "FAILURE: stat size %d read size %d\n", (int)status.st_size, error); - if (error > 0) { - printf("SUCCESS at stat size %d read size %d\n", (int)status.st_size, error); - successes++; - /* Sleep to avoid the natural race in reading st_size. */ - usleep(1000000); - } - } -} - -} diff --git a/tools/regression/pipe/pipe-ino.c b/tools/regression/pipe/pipe-ino.c deleted file mode 100644 index f739cc9..0000000 --- a/tools/regression/pipe/pipe-ino.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2011 Giovanni Trematerra <giovanni.trematerra@gmail.com> - * 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. - */ - -/* - * $FreeBSD$ - * Test conformance to stat(2) SUSv4 description: - * "For all other file types defined in this volume of POSIX.1-2008, the - * structure members st_mode, st_ino, st_dev, st_uid, st_gid, st_atim, - * st_ctim, and st_mtim shall have meaningful values ...". - * Check that st_dev and st_ino are meaningful. - */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <err.h> -#include <stdio.h> -#include <unistd.h> - -int -main(int argc, char **argv) -{ - int pipefd[2]; - struct stat st1, st2; - - if (pipe(pipefd) == -1) - err(1, "FAIL: pipe"); - - if (fstat(pipefd[0], &st1) == -1) - err(1, "FAIL: fstat st1"); - if (fstat(pipefd[1], &st2) == -1) - err(1, "FAIL: fstat st2"); - if (st1.st_dev != st2.st_dev || st1.st_dev == 0 || st2.st_dev == 0) { - errx(1, "FAIL: wrong dev number %d %d", - st1.st_dev, st2.st_dev); - } - if (st1.st_ino == st2.st_ino) - errx(1, "FAIL: inode numbers are equal: %d", st1.st_ino); - close(pipefd[0]); - close(pipefd[1]); - printf("PASS\n"); - - return (0); -} diff --git a/tools/regression/pipe/pipe-overcommit1.c b/tools/regression/pipe/pipe-overcommit1.c deleted file mode 100644 index c468658..0000000 --- a/tools/regression/pipe/pipe-overcommit1.c +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (C) 2005 Michael J. Silbersack <silby@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(s), this list of conditions and the following disclaimer as - * the first lines of this file unmodified other than the possible - * addition of one or more copyright notices. - * 2. Redistributions in binary form must reproduce the above copyright - * notice(s), 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 COPYRIGHT HOLDER(S) ``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 HOLDER(S) 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 <stdio.h> -#include <stdlib.h> - -/* - * $FreeBSD$ - * This program just allocates as many pipes as it can to ensure - * that using up all pipe memory doesn't cause a panic. - */ - -int main (void) - -{ - int i, returnval; - int pipes[10000]; - for (i = 0; i < 10000; i++) { - returnval = pipe(&pipes[i]); - } - printf("PASS\n"); -} diff --git a/tools/regression/pipe/pipe-overcommit2.c b/tools/regression/pipe/pipe-overcommit2.c deleted file mode 100644 index 5979585..0000000 --- a/tools/regression/pipe/pipe-overcommit2.c +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * Copyright (C) 2005 Michael J. Silbersack <silby@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(s), this list of conditions and the following disclaimer as - * the first lines of this file unmodified other than the possible - * addition of one or more copyright notices. - * 2. Redistributions in binary form must reproduce the above copyright - * notice(s), 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 COPYRIGHT HOLDER(S) ``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 HOLDER(S) 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 <stdio.h> -#include <stdlib.h> -#include <fcntl.h> - -/* - * $FreeBSD$ - * This program tests how sys_pipe.c handles the case where there - * is ample memory to allocate a pipe, but the file descriptor - * limit for that user has been exceeded. - */ - -int main (int argc, void *argv[]) - -{ - int i, returnval, lastfd; - int pipes[10000]; - - for (i = 0; i < 100000; i++) { - returnval = open(argv[0], O_RDONLY); - if (returnval < 1) - break; /* All descriptors exhausted. */ - else - lastfd = returnval; - } - - /* First falloc failure case in sys_pipe.c:pipe() */ - for (i = 0; i < 1000; i++) { - returnval = pipe(&pipes[i]); - } - - /* - * Free just one FD so that the second falloc failure - * case will occur. - */ - close(lastfd); - - for (i = 0; i < 1000; i++) { - returnval = pipe(&pipes[i]); - } - printf("PASS\n"); -} diff --git a/tools/regression/pipe/pipe-reverse.c b/tools/regression/pipe/pipe-reverse.c deleted file mode 100644 index 702c516..0000000 --- a/tools/regression/pipe/pipe-reverse.c +++ /dev/null @@ -1,113 +0,0 @@ -/* -Copyright (C) 2004 Michael J. Silbersack. 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 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 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 <stdio.h> -#include <unistd.h> -#include <sys/stat.h> - -/* - * $FreeBSD$ - * This program simply tests writing through the reverse direction of - * a pipe. Nothing too fancy, it's only needed because most pipe-using - * programs never touch the reverse direction (it doesn't exist on - * Linux.) - */ - -int main (void) -{ -char buffer[65535], buffer2[65535]; -int desc[2]; -int buggy, error, i, successes, total; -struct stat status; -pid_t new_pid; - -buggy = 0; -total = 0; - -error = pipe(desc); - -if (error) - err(0, "Couldn't allocate fds\n"); - -buffer[0] = 'A'; - -for (i = 1; i < 65535; i++) { - buffer[i] = buffer[i - 1] + 1; - if (buffer[i] > 'Z') - buffer[i] = 'A'; - } - -new_pid = fork(); - -if (new_pid == 0) { - error = write(desc[0], &buffer, 4096); - total += error; - error = write(desc[0], &buffer[total], 4096); - total += error; - error = write(desc[0], &buffer[total], 4096); - total += error; - error = write(desc[0], &buffer[total], 4096); - total += error; - error = write(desc[0], &buffer[total], 4096); - total += error; - error = write(desc[0], &buffer[total], 4096); - total += error; - error = write(desc[0], &buffer[total], 4096); - total += error; - error = write(desc[0], &buffer[total], 4096); - total += error; - printf("Wrote %d bytes, sleeping\n", total); - usleep(1000000); - error = write(desc[0], &buffer[total], 4096); - total += error; - error = write(desc[0], &buffer[total], 4096); - total += error; - printf("Wrote another 8192 bytes, %d total, done\n", total); -} else { - usleep(500000); - error = read(desc[1], &buffer2, 32768); - total += error; - printf("Read %d bytes, going back to sleep\n", error); - usleep(1000000); - error = read(desc[1], &buffer2[total], 8192); - total += error; - printf("Read %d bytes, done\n", error); - - for (i = 0; i < total; i++) { - if (buffer[i] != buffer2[i]) { - buggy = 1; - printf("Location %d input: %hhx output: %hhx\n", - i, buffer[i], buffer2[i]); - } - } - -if ((buggy == 1) || (total != 40960)) - printf("FAILURE\n"); -else - printf("SUCCESS\n"); - -} - -} diff --git a/tools/regression/pipe/pipe-reverse2.c b/tools/regression/pipe/pipe-reverse2.c deleted file mode 100644 index cd54190..0000000 --- a/tools/regression/pipe/pipe-reverse2.c +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * Copyright (c) 2010 Jilles Tjoelker - * 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. - * - * $FreeBSD$ - */ - -#include <sys/select.h> - -#include <err.h> -#include <stdio.h> -#include <unistd.h> - -/* - * Check that pipes can be selected for writing in the reverse direction. - */ -int -main(int argc, char *argv[]) -{ - int pip[2]; - fd_set set; - int n; - - if (pipe(pip) == -1) - err(1, "FAIL: pipe"); - - FD_ZERO(&set); - FD_SET(pip[0], &set); - n = select(pip[1] + 1, NULL, &set, NULL, &(struct timeval){ 0, 0 }); - if (n != 1) - errx(1, "FAIL: select initial reverse direction"); - - n = write(pip[0], "x", 1); - if (n != 1) - err(1, "FAIL: write reverse direction"); - - FD_ZERO(&set); - FD_SET(pip[0], &set); - n = select(pip[1] + 1, NULL, &set, NULL, &(struct timeval){ 0, 0 }); - if (n != 1) - errx(1, "FAIL: select reverse direction after write"); - - printf("PASS\n"); - - return (0); -} diff --git a/tools/regression/pipe/pipe-wraparound.c b/tools/regression/pipe/pipe-wraparound.c deleted file mode 100644 index 5cf09fa..0000000 --- a/tools/regression/pipe/pipe-wraparound.c +++ /dev/null @@ -1,103 +0,0 @@ -/* -Copyright (C) 2004 Michael J. Silbersack. 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 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 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 <stdio.h> -#include <unistd.h> -#include <sys/stat.h> - -/* - * $FreeBSD$ - * This program tests to make sure that wraparound writes and reads - * are working, assuming that 16K socket buffers are used. In order - * to really stress the pipe code with this test, kernel modifications - * nay be necessary. - */ - -int main (void) -{ -char buffer[32768], buffer2[32768]; -int desc[2]; -int buggy, error, i, successes, total; -struct stat status; -pid_t new_pid; - -buggy = 0; -total = 0; - -error = pipe(desc); - -if (error) - err(0, "Couldn't allocate fds\n"); - -buffer[0] = 'A'; - -for (i = 1; i < 32768; i++) { - buffer[i] = buffer[i - 1] + 1; - if (buffer[i] > 'Z') - buffer[i] = 'A'; - } - -new_pid = fork(); - -if (new_pid == 0) { - error = write(desc[1], &buffer, 4096); - total += error; - error = write(desc[1], &buffer[total], 4096); - total += error; - error = write(desc[1], &buffer[total], 4000); - total += error; - printf("Wrote %d bytes, sleeping\n", total); - usleep(1000000); - error = write(desc[1], &buffer[total], 3000); - total += error; - error = write(desc[1], &buffer[total], 3000); - total += error; - printf("Wrote another 6000 bytes, %d total, done\n", total); -} else { - usleep(500000); - error = read(desc[0], &buffer2, 8192); - total += error; - printf("Read %d bytes, going back to sleep\n", error); - usleep(1000000); - error = read(desc[0], &buffer2[total], 16384); - total += error; - printf("Read %d bytes, done\n", error); - - for (i = 0; i < total; i++) { - if (buffer[i] != buffer2[i]) { - buggy = 1; - printf("Location %d input: %hhx output: %hhx\n", - i, buffer[i], buffer2[i]); - } - } - -if (buggy) - printf("FAILURE\n"); -else - printf("SUCCESS\n"); -} - - -} |