Mercurial > gnulib
annotate tests/test-nonblocking-reader.h @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
14589
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* The reader part of a test program for non-blocking communication. |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
3 Copyright (C) 2011-2019 Free Software Foundation, Inc. |
14589
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 (at your option) any later version. |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 GNU General Public License for more details. |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
14589
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 /* This program implements 4 tests: |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 test == 0: |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 Test blocking write() with blocking read(). |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 Timeline Main process Child process |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 0 s Start Start, read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 1 s write(20000) Return from read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 2 s Next read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 2 s Return from write(20000) Return from read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 test == 1: |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 Test non-blocking write() with blocking read(). |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 Timeline Main process Child process |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 0 s Start Start, read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 1 s write(20000) Return from read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 Return with at least 10000, |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 Repeatedly continue |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 write() of the rest |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 2 s Next read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 2 s Return from write(10000) Return from read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 test == 2: |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 Test blocking write() with non-blocking read(). |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 Timeline Main process Child process |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 0 s Start Start, read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 repeatedly polling |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 1 s write(20000) Return from read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 2 s Next read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 2 s Return from write(20000) Return from read(10000) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 test == 3: |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 Test non-blocking write() with non-blocking read(). |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 #include "test-nonblocking-misc.h" |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 static ssize_t |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 full_read (size_t fd, void *buf, size_t count) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 { |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 size_t bytes_read; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 bytes_read = 0; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 while (bytes_read < count) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 { |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 TIMING_DECLS |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 ssize_t ret; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 int saved_errno; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 dbgfprintf (stderr, "%s: >> read (%lu)\n", PROG_ROLE, |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 (unsigned long) (count - bytes_read)); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 START_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 ret = read (fd, (char *) buf + bytes_read, count - bytes_read); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 saved_errno = errno; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 END_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 dbgfprintf (stderr, "%s: << read -> %ld%s\n", PROG_ROLE, |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 (long) ret, dbgstrerror (ret < 0, saved_errno)); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 if (ret < 0) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 return -1; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 else |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 { |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 ASSERT (ret > 0); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 bytes_read += ret; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 } |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 } |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
85 return bytes_read; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 } |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 static ssize_t |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 full_read_from_nonblocking_fd (size_t fd, void *buf, size_t count) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 { |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 size_t bytes_read; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 bytes_read = 0; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 while (bytes_read < count) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 { |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 TIMING_DECLS |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 ssize_t ret; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 int saved_errno; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 dbgfprintf (stderr, "%s: >> read (%lu)\n", PROG_ROLE, |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 (unsigned long) (count - bytes_read)); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 START_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 ret = read (fd, (char *) buf + bytes_read, count - bytes_read); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 saved_errno = errno; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 END_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 dbgfprintf (stderr, "%s: << read -> %ld%s\n", PROG_ROLE, |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 (long) ret, dbgstrerror (ret < 0, saved_errno)); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 /* This assertion fails if the non-blocking flag is effectively not set |
14593
506583b3e66a
nonblocking tests: Tweak comment.
Bruno Haible <bruno@clisp.org>
parents:
14589
diff
changeset
|
109 on fd. */ |
14589
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 ASSERT (spent_time < 0.5); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 if (ret < 0) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 { |
18373
ba7c2fe347c8
maint: port tests to z/OS errno behavior
Daniel Richard G <skunk@iSKUNK.ORG>
parents:
18189
diff
changeset
|
113 ASSERT (saved_errno == EAGAIN || saved_errno == EWOULDBLOCK); |
14589
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 usleep (SMALL_DELAY); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 } |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 else |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 { |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 ASSERT (ret > 0); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
119 bytes_read += ret; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 } |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 } |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 return bytes_read; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 } |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 /* Execute the reader loop. */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 static void |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 main_reader_loop (int test, size_t data_block_size, int fd) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
128 { |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 unsigned char *expected; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 unsigned char *data; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
131 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 /* Set up the expected data. */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 expected = init_data (data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 data = (unsigned char *) malloc (2 * data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 ASSERT (data != NULL); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 switch (test) |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 { |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
140 TIMING_DECLS |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 ssize_t ret; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 case 0: /* Test blocking write() with blocking read(). */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 case 1: /* Test non-blocking write() with blocking read(). */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 START_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 ret = full_read (fd, data, data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 END_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 ASSERT (ret == data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 ASSERT (memcmp (data, expected, data_block_size) == 0); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
150 ASSERT (spent_time > 0.5); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 /* This assertion fails if data_block_size is very large and |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 ENABLE_DEBUGGING is 1. */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 ASSERT (spent_time < 1.5); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 usleep (1000000); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 START_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 ret = full_read (fd, data, data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 END_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 ASSERT (ret == data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 ASSERT (memcmp (data, expected + data_block_size, data_block_size) == 0); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 /* This assertion fails if data_block_size is much larger than needed |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 and SMALL_DELAY is too large. */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 ASSERT (spent_time < 0.5); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 break; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 case 2: /* Test blocking write() with non-blocking read(). */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 case 3: /* Test non-blocking write() with non-blocking read(). */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
170 START_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 ret = full_read_from_nonblocking_fd (fd, data, data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 END_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 ASSERT (ret == data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
174 ASSERT (memcmp (data, expected, data_block_size) == 0); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
175 ASSERT (spent_time > 0.5); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
176 /* This assertion fails if data_block_size is much larger than needed |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
177 and SMALL_DELAY is too large, or if data_block_size is very large and |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
178 ENABLE_DEBUGGING is 1. */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 ASSERT (spent_time < 1.5); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
181 usleep (1000000); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
183 START_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 ret = full_read_from_nonblocking_fd (fd, data, data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
185 END_TIMING |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
186 ASSERT (ret == data_block_size); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 ASSERT (memcmp (data, expected + data_block_size, data_block_size) == 0); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 /* This assertion fails if data_block_size is much larger than needed |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 and SMALL_DELAY is too large. */ |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 ASSERT (spent_time < 0.5); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 break; |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 default: |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 abort (); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
196 } |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 free (data); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
199 free (expected); |
e34e9b75f470
nonblocking: Add tests for pipes.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
200 } |