Deleted Added
full compact
pipe-reverse.c (225736) pipe-reverse.c (231832)
1/*
2Copyright (C) 2004 Michael J. Silbersack. All rights reserved.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions
6are met:
71. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
92. Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12
13THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23SUCH DAMAGE.
24*/
25
26#include <stdio.h>
27#include <unistd.h>
28#include <sys/stat.h>
29
30/*
1/*
2Copyright (C) 2004 Michael J. Silbersack. All rights reserved.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions
6are met:
71. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
92. Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12
13THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23SUCH DAMAGE.
24*/
25
26#include <stdio.h>
27#include <unistd.h>
28#include <sys/stat.h>
29
30/*
31 * $FreeBSD: stable/9/tools/regression/pipe/pipe-reverse.c 132524 2004-07-22 02:46:25Z silby $
31 * $FreeBSD: stable/9/tools/regression/pipe/pipe-reverse.c 231832 2012-02-16 19:39:49Z eadler $
32 * This program simply tests writing through the reverse direction of
33 * a pipe. Nothing too fancy, it's only needed because most pipe-using
34 * programs never touch the reverse direction (it doesn't exist on
35 * Linux.)
36 */
37
38int main (void)
39{
40char buffer[65535], buffer2[65535];
41int desc[2];
42int buggy, error, i, successes, total;
43struct stat status;
44pid_t new_pid;
45
46buggy = 0;
32 * This program simply tests writing through the reverse direction of
33 * a pipe. Nothing too fancy, it's only needed because most pipe-using
34 * programs never touch the reverse direction (it doesn't exist on
35 * Linux.)
36 */
37
38int main (void)
39{
40char buffer[65535], buffer2[65535];
41int desc[2];
42int buggy, error, i, successes, total;
43struct stat status;
44pid_t new_pid;
45
46buggy = 0;
47total = 0;
47
48error = pipe(desc);
49
50if (error)
51 err(0, "Couldn't allocate fds\n");
52
53buffer[0] = 'A';
54
48
49error = pipe(desc);
50
51if (error)
52 err(0, "Couldn't allocate fds\n");
53
54buffer[0] = 'A';
55
55for (i = 0; i < 65535; i++) {
56for (i = 1; i < 65535; i++) {
56 buffer[i] = buffer[i - 1] + 1;
57 if (buffer[i] > 'Z')
58 buffer[i] = 'A';
59 }
60
61new_pid = fork();
62
63if (new_pid == 0) {
64 error = write(desc[0], &buffer, 4096);
65 total += error;
66 error = write(desc[0], &buffer[total], 4096);
67 total += error;
68 error = write(desc[0], &buffer[total], 4096);
69 total += error;
70 error = write(desc[0], &buffer[total], 4096);
71 total += error;
72 error = write(desc[0], &buffer[total], 4096);
73 total += error;
74 error = write(desc[0], &buffer[total], 4096);
75 total += error;
76 error = write(desc[0], &buffer[total], 4096);
77 total += error;
78 error = write(desc[0], &buffer[total], 4096);
79 total += error;
80 printf("Wrote %d bytes, sleeping\n", total);
81 usleep(1000000);
82 error = write(desc[0], &buffer[total], 4096);
83 total += error;
84 error = write(desc[0], &buffer[total], 4096);
85 total += error;
86 printf("Wrote another 8192 bytes, %d total, done\n", total);
87} else {
88 usleep(500000);
89 error = read(desc[1], &buffer2, 32768);
90 total += error;
91 printf("Read %d bytes, going back to sleep\n", error);
92 usleep(1000000);
93 error = read(desc[1], &buffer2[total], 8192);
94 total += error;
95 printf("Read %d bytes, done\n", error);
96
97 for (i = 0; i < total; i++) {
98 if (buffer[i] != buffer2[i]) {
99 buggy = 1;
100 printf("Location %d input: %hhx output: %hhx\n",
101 i, buffer[i], buffer2[i]);
102 }
103 }
104
105if ((buggy == 1) || (total != 40960))
106 printf("FAILURE\n");
107else
108 printf("SUCCESS\n");
109
110}
111
112}
57 buffer[i] = buffer[i - 1] + 1;
58 if (buffer[i] > 'Z')
59 buffer[i] = 'A';
60 }
61
62new_pid = fork();
63
64if (new_pid == 0) {
65 error = write(desc[0], &buffer, 4096);
66 total += error;
67 error = write(desc[0], &buffer[total], 4096);
68 total += error;
69 error = write(desc[0], &buffer[total], 4096);
70 total += error;
71 error = write(desc[0], &buffer[total], 4096);
72 total += error;
73 error = write(desc[0], &buffer[total], 4096);
74 total += error;
75 error = write(desc[0], &buffer[total], 4096);
76 total += error;
77 error = write(desc[0], &buffer[total], 4096);
78 total += error;
79 error = write(desc[0], &buffer[total], 4096);
80 total += error;
81 printf("Wrote %d bytes, sleeping\n", total);
82 usleep(1000000);
83 error = write(desc[0], &buffer[total], 4096);
84 total += error;
85 error = write(desc[0], &buffer[total], 4096);
86 total += error;
87 printf("Wrote another 8192 bytes, %d total, done\n", total);
88} else {
89 usleep(500000);
90 error = read(desc[1], &buffer2, 32768);
91 total += error;
92 printf("Read %d bytes, going back to sleep\n", error);
93 usleep(1000000);
94 error = read(desc[1], &buffer2[total], 8192);
95 total += error;
96 printf("Read %d bytes, done\n", error);
97
98 for (i = 0; i < total; i++) {
99 if (buffer[i] != buffer2[i]) {
100 buggy = 1;
101 printf("Location %d input: %hhx output: %hhx\n",
102 i, buffer[i], buffer2[i]);
103 }
104 }
105
106if ((buggy == 1) || (total != 40960))
107 printf("FAILURE\n");
108else
109 printf("SUCCESS\n");
110
111}
112
113}