nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /* source: xio-test.c */
2 /* Copyright Gerhard Rieger 2007-2009 */
3 /* Published under the GNU General Public License V.2, see file COPYING */
4  
5 /* this file contains the source for an intermediate test address that appends
6 '>' to every block transferred from right to left, and '<' in the other
7 direction */
8  
9 #include "xiosysincludes.h"
10 #include "xioopen.h"
11  
12 #include "xio-test.h"
13  
14  
15 #if WITH_TEST
16  
17 static int xioopen_test(int argc, const char *argv[], struct opt *opts,
18 int xioflags, xiofile_t *xxfd,
19 unsigned groups, int dummy1, int dummy2,
20 int dummy3);
21 static int xioopen_testuni(int argc, const char *argv[], struct opt *opts,
22 int xioflags, xiofile_t *xxfd,
23 unsigned groups, int dummy1, int dummy2,
24 int dummy3);
25 static int xioopen_testrev(int argc, const char *argv[], struct opt *opts,
26 int xioflags, xiofile_t *xxfd,
27 unsigned groups, int dummy1, int dummy2,
28 int dummy3);
29  
30 static const struct xioaddr_inter_desc xiointer_test0ro = { XIOADDR_PROT, "test", 0, XIOBIT_RDONLY, 0/*groups*/, XIOSHUT_UNSPEC, XIOCLOSE_UNSPEC, xioopen_test, 0, 0, 0, XIOBIT_WRONLY HELP("") };
31 static const struct xioaddr_inter_desc xiointer_test0wo = { XIOADDR_PROT, "test", 0, XIOBIT_WRONLY, 0/*groups*/, XIOSHUT_UNSPEC, XIOCLOSE_UNSPEC, xioopen_test, 0, 0, 0, XIOBIT_RDONLY HELP("") };
32 static const struct xioaddr_inter_desc xiointer_test0rw = { XIOADDR_PROT, "test", 0, XIOBIT_RDWR, 0/*groups*/, XIOSHUT_UNSPEC, XIOCLOSE_UNSPEC, xioopen_test, 0, 0, 0, XIOBIT_RDWR HELP("") };
33  
34 const union xioaddr_desc *xioaddrs_test[] = {
35 (union xioaddr_desc *)&xiointer_test0ro,
36 (union xioaddr_desc *)&xiointer_test0wo,
37 (union xioaddr_desc *)&xiointer_test0rw,
38 NULL };
39  
40  
41 static const struct xioaddr_inter_desc xiointer_testuni = { XIOADDR_PROT, "testuni", 0, XIOBIT_WRONLY, 0/*groups*/, XIOSHUT_CLOSE, XIOCLOSE_NONE, xioopen_testuni, 0, 0, 0, XIOBIT_RDONLY HELP("") };
42  
43 const union xioaddr_desc *xioaddrs_testuni[] = {
44 (union xioaddr_desc *)&xiointer_testuni,
45 NULL };
46  
47  
48 static const struct xioaddr_inter_desc xiointer_testrev = { XIOADDR_PROT, "testrev", 0, XIOBIT_WRONLY, 0/*groups*/, XIOSHUT_CLOSE, XIOCLOSE_NONE, xioopen_testrev, 0, 0, 0, XIOBIT_RDONLY HELP("") };
49  
50 const union xioaddr_desc *xioaddrs_testrev[] = {
51 (union xioaddr_desc *)&xiointer_testrev,
52 NULL };
53  
54 static int xioopen_test(int argc, const char *argv[], struct opt *opts,
55 int xioflags, xiofile_t *xxfd,
56 unsigned groups, int dummy, int dummy2,
57 int dummy3) {
58 struct single *xfd = &xxfd->stream;
59 int result;
60  
61 assert(argc == 1);
62 assert(!(xfd->rfd < 0 && xfd->wfd < 0)); /*!!!*/
63  
64 applyopts(-1, opts, PH_INIT);
65 if (applyopts_single(xfd, opts, PH_INIT) < 0) return -1;
66  
67 Notice("opening TEST");
68 xfd->dtype = XIODATA_TEST;
69 applyopts(xfd->rfd, opts, PH_ALL);
70 if ((result = _xio_openlate(xfd, opts)) < 0)
71 return result;
72 return 0;
73 }
74  
75 static int xioopen_testuni(int argc, const char *argv[], struct opt *opts,
76 int xioflags, xiofile_t *xxfd,
77 unsigned groups, int dummy, int dummy2,
78 int dummy3) {
79 struct single *xfd = &xxfd->stream;
80 int result;
81  
82 assert(argc == 1);
83 assert(!(xfd->rfd < 0 && xfd->wfd < 0)); /*!!!*/
84  
85 applyopts(-1, opts, PH_INIT);
86 if (applyopts_single(xfd, opts, PH_INIT) < 0) return -1;
87  
88 Notice("opening TESTUNI");
89 xfd->dtype = XIODATA_TESTUNI;
90 applyopts(xfd->rfd, opts, PH_ALL);
91 if ((result = _xio_openlate(xfd, opts)) < 0)
92 return result;
93 return 0;
94 }
95  
96 static int xioopen_testrev(int argc, const char *argv[], struct opt *opts,
97 int xioflags, xiofile_t *xxfd,
98 unsigned groups, int dummy, int dummy2,
99 int dummy3) {
100 struct single *xfd = &xxfd->stream;
101 int result;
102  
103 assert(argc == 1);
104 assert(!(xfd->rfd < 0 && xfd->wfd < 0)); /*!!!*/
105  
106 applyopts(-1, opts, PH_INIT);
107 if (applyopts_single(xfd, opts, PH_INIT) < 0) return -1;
108  
109 Notice("opening TESTREV");
110 xfd->dtype = XIODATA_TESTREV;
111 applyopts(xfd->rfd, opts, PH_ALL);
112 if ((result = _xio_openlate(xfd, opts)) < 0)
113 return result;
114 return 0;
115 }
116  
117 size_t xioread_test(struct single *sfd, void *buff, size_t bufsiz) {
118 int fd = sfd->rfd;
119 ssize_t bytes;
120 int _errno;
121  
122 do {
123 bytes = Read(fd, buff, bufsiz-1);
124 } while (bytes < 0 && errno == EINTR);
125 if (bytes < 0) {
126 _errno = errno;
127 switch (_errno) {
128 case EPIPE: case ECONNRESET:
129 Warn4("read(%d, %p, "F_Zu"): %s",
130 fd, buff, bufsiz-1, strerror(_errno));
131 break;
132 default:
133 Error4("read(%d, %p, "F_Zu"): %s",
134 fd, buff, bufsiz-1, strerror(_errno));
135 }
136 return -1;
137 }
138 if (bytes == 0) {
139 return 0;
140 }
141 ((char *)buff)[bytes] = '<';
142 return bytes+1;
143 }
144  
145 size_t xiowrite_test(struct single *sfd, const void *buff, size_t bytes) {
146 int fd = sfd->wfd;
147 void *buff1;
148 ssize_t writt;
149 int _errno;
150  
151 if ((buff1 = Malloc(bytes+1)) == NULL) {
152 return -1;
153 }
154 memcpy(buff1, buff, bytes);
155 ((char *)buff1)[bytes] = '>';
156 do {
157 writt = Write(fd, buff1, bytes+1);
158 } while (writt < 0 && errno == EINTR);
159 if (writt < 0) {
160 _errno = errno;
161 switch (_errno) {
162 case EPIPE:
163 case ECONNRESET:
164 if (sfd->cool_write) {
165 Notice4("write(%d, %p, "F_Zu"): %s",
166 fd, buff1, bytes+1, strerror(_errno));
167 break;
168 }
169 /*PASSTHROUGH*/
170 default:
171 Error4("write(%d, %p, "F_Zu"): %s",
172 fd, buff1, bytes+1, strerror(_errno));
173 }
174 errno = _errno;
175 free(buff1);
176 return -1;
177 }
178 if ((size_t)writt < bytes) {
179 Warn2("write() only wrote "F_Zu" of "F_Zu" bytes",
180 writt, bytes+1);
181 }
182 free(buff1);
183 return writt;
184 }
185  
186 size_t xiowrite_testrev(struct single *sfd, const void *buff, size_t bytes) {
187 int fd = sfd->wfd;
188 void *buff1;
189 ssize_t writt;
190 int _errno;
191  
192 if ((buff1 = Malloc(bytes+1)) == NULL) {
193 return -1;
194 }
195 memcpy(buff1, buff, bytes);
196 ((char *)buff1)[bytes] = '<';
197 do {
198 writt = Write(fd, buff1, bytes+1);
199 } while (writt < 0 && errno == EINTR);
200 if (writt < 0) {
201 _errno = errno;
202 switch (_errno) {
203 case EPIPE:
204 case ECONNRESET:
205 if (sfd->cool_write) {
206 Notice4("write(%d, %p, "F_Zu"): %s",
207 fd, buff1, bytes+1, strerror(_errno));
208 break;
209 }
210 /*PASSTHROUGH*/
211 default:
212 Error4("write(%d, %p, "F_Zu"): %s",
213 fd, buff1, bytes+1, strerror(_errno));
214 }
215 errno = _errno;
216 free(buff1);
217 return -1;
218 }
219 if ((size_t)writt < bytes) {
220 Warn2("write() only wrote "F_Zu" of "F_Zu" bytes",
221 writt, bytes+1);
222 }
223 free(buff1);
224 return writt;
225 }
226  
227 #endif /* WITH_TEST */
228