3 * - complex test harness, routines used for both record and playback
6 * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
37 const struct Terrno Terrnos
[]= {
39 { "EINPROGRESS", EINPROGRESS
},
42 { "EMSGSIZE", EMSGSIZE
},
43 { "ENOBUFS", ENOBUFS
},
45 { "ENOPROTOOPT", ENOPROTOOPT
},
47 { "EWOULDBLOCK", EWOULDBLOCK
},
51 void Qgettimeofday(void) {
52 Q_str("gettimeofday()");
55 void Qselect(int n
, const fd_set
*rfds
, const fd_set
*wfds
, const fd_set
*efds
,
56 const struct timeval
*to
) {
65 Tvbf(", %ld.%06ld)",to
->tv_sec
,to
->tv_usec
);
72 void Qsocket(int type
) {
74 case SOCK_STREAM
: Q_str("socket(,SOCK_STREAM,)"); break;
75 case SOCK_DGRAM
: Q_str("socket(,SOCK_DGRAM,)"); break;
80 void Qfcntl_setfl(int fd
, int cmd
, long arg
) {
82 Tvbf("fcntl(%d, F_SETFL, %ld)",fd
,arg
);
86 void Qfcntl_other(int fd
, int cmd
) {
89 Tvbf("fcntl(%d, F_GETFL)",fd
);
93 void Qconnect(int fd
, struct sockaddr
*addr
, int addrlen
) {
95 Tvbf("connect(%d, ",fd
);
96 Tvbaddr(addr
,addrlen
);
101 void Qclose(int fd
) {
103 Tvbf("close(%d)",fd
);
107 void Qsendto(int fd
, const void *msg
, int msglen
,
108 const struct sockaddr
*addr
, int addrlen
) {
110 Tvbf("sendto(%d,,,, ",fd
);
111 Tvbaddr(addr
,addrlen
);
113 Tvbbytes(msg
,msglen
);
117 void Qrecvfrom(int fd
, int buflen
, int addrlen
) {
119 Tvbf("recvfrom(%d,,%d,,,%d)",fd
,buflen
,addrlen
);
123 void Qread(int fd
, size_t len
) {
125 Tvbf("read(%d,,%lu)",fd
,(unsigned long)len
);
129 void Qwrite(int fd
, const void *buf
, size_t len
) {
131 Tvbf("write(%d,,)",fd
);
137 void Tvbaddr(const struct sockaddr
*addr
, int len
) {
138 const struct sockaddr_in
*ai
= (const struct sockaddr_in
*)addr
;
140 assert(len
==sizeof(struct sockaddr_in
));
141 assert(ai
->sin_family
==AF_INET
);
142 Tvbf(" %s:%u",inet_ntoa(ai
->sin_addr
),htons(ai
->sin_port
));
145 void Tvbbytes(const void *buf
, int len
) {
149 if (!len
) { Tvba(" empty"); return; }
150 for (i
=0, bp
=buf
; i
<len
; i
++, bp
++) {
151 if (!(i
&31)) Tvba("\n ");
152 else if (!(i
&3)) Tvba(" ");
157 void Tvbfdset(int max
, const fd_set
*fds
) {
159 const char *comma
= "";
162 for (i
=0; i
<max
; i
++) {
163 if (!FD_ISSET(i
,fds
)) continue;
171 void Tvberrno(int e
) {
172 const struct Terrno
*te
;
174 for (te
= Terrnos
; te
->n
&& te
->v
!= e
; te
++);
175 if (te
->n
) Tvba(te
->n
);
179 void Tvba(const char *str
) {
180 if (!adns__vbuf_appendstr(&vb
,str
)) Tnomem();
183 void Tvbvf(const char *fmt
, va_list al
) {
185 buf
[sizeof(buf
)-2]= '\t';
186 vsnprintf(buf
,sizeof(buf
),fmt
,al
);
187 assert(buf
[sizeof(buf
)-2] == '\t');
192 void Tvbf(const char *fmt
, ...) {
200 void Tfailed(const char *why
) {
201 fprintf(stderr
,"adns test harness: failure: %s: %s\n",why
,strerror(errno
));
206 Tfailed("unable to malloc/realloc");
209 void Toutputerr(void) {
210 Tfailed("write error on test harness output");
213 void Tensureoutputfile(void) {
214 /* fixme: allow sending it elsewhere */