Work on harness is progressing.
[adns] / src / hrecord.c
1 /*
2 * hrecord.c
3 * - complex test harness, recording routines
4 */
5 /*
6 * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson
7 *
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)
11 * any later version.
12 *
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.
17 *
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.
21 */
22
23 #include "harness.h"
24
25 static int begin_set;
26 static struct timeval begin;
27
28 int Hgettimeofday(struct timeval *tv, struct timezone *tz) {
29 int r;
30 struct timeval diff;
31
32 assert(tv); assert(!tz);
33
34 Qgettimeofday();
35
36 r= gettimeofday(tv,0); if (r) Tfailed("gettimeofday");
37
38 if (!begin_set) {
39 printf(" gettimeofday= %ld.%06ld",tv->tv_sec,tv->tv_usec);
40 begin= *tv;
41 begin_set= 1;
42 } else {
43 diff.tv_sec= tv->tv_sec - begin.tv_sec;
44 diff.tv_usec= tv->tv_usec - begin.tv_usec;
45 if (diff.tv_usec < 0) {
46 diff.tv_sec -= 1;
47 diff.tv_usec += 1000000;
48 }
49 assert(diff.tv_sec >= 0);
50 assert(diff.tv_usec >= 0);
51 Tprintf(" gettimeofday= +%ld.%06ld\n",diff.tv_sec,diff.tv_usec);
52 }
53 return 0;
54 }
55
56 int Hselect(int n, fd_set reads, fd_set writes, fd_set excepts, struct timeval *to) {
57 Qselect(n,reads,writes,excepts,to);
58
59 r= select(n,reads,writes,excepts,to);
60
61 if (r==-1) {
62 Terrorno("select");
63 } else {
64 Tprintf(" select= %d",r);
65 Tfdset(reads); Tfdset(writes); Tfdset(excepts);
66 Tprintf("\n");
67 }
68
69 if (to) memset(to,0x5a,sizeof(*to));
70 }
71
72 int Hsocket(int domain, int type, int protocol) {
73 assert(domain == AF_INET);
74
75 Qsocket(type);
76 r= socket(domain,type,protocol); if (r) Tfailed("socket");
77
78 Tprintf(" socket= %d\n",r);
79 return r;
80 }
81
82 int Hfcntl(int fd, int cmd, long arg) {
83 Qfcntl(fd,cmd,arg);
84
85 r= fcntl(fd, cmd, arg); if (r==-1) Tfailed("fcntl");
86
87 Tprintf(" fcntl= %d\n",r);
88 return r;
89 }
90
91 int Hconnect(int fd, struct sockaddr *addr, int addrlen) {
92 Qconnect(fd,addr,addrlen);
93
94 r= connect(fd, addr, addrlen);
95
96 if (r) {
97 Terrno("connect");
98 } else {
99 Tprintf(" connect= OK\n");
100 }
101 return r;
102 }
103
104 int Hclose(int fd) {
105 Qclose(fd);
106 return 0;
107 }
108
109 int Hsendto(int fd, const void *msg, int msglen, unsigned int flags,
110 const struct sockaddr *addr, int addrlen) {
111 assert(!flags)
112 Qsendto(fd,msg,msglen,addr,addrlen);
113
114 r= sendto(fd,msg,msglen,flags,addr,addrlen);
115 if (r==-1) {
116 Terrno("sendto");
117 } else {
118 Tprintf(" sendto= %d\n",r);
119 }
120 return r;
121 }
122
123 int Hrecvfrom(int fd, void *buf, int buflen, unsigned int flags,
124 struct sockaddr *addr, int *addrlen) {
125 assert(!flags)
126 Qrecvfrom(fd,buflen,addr,*addrlen);
127
128 r= recvfrom(fd,buf,buflen,flags,addr,addrlen);
129 if (r==-1) {
130 Terrno("recvfrom");
131 } else {
132 Tprintf(" recvfrom=",r);
133 Taddr(addr,addrlen);
134 Tbuf(buf,r);
135 Tprintf("\n");
136 }
137
138 return r;
139 }
140
141 int Hread(int fd, void *buf, size_t len) {
142 Qread(fd,len);
143
144 r= read(fd,buf,len);
145 if (r==-1) {
146 Terrno("read");
147 } else {
148 Tprintf(" read=");
149 Tbuf(buf,r);
150 Tprintf("\n");
151 }
152
153 return r;
154 }
155
156 int Hwrite(int fd, const void *buf, size_t len) {
157 Qwrite(fd,buf,len);
158
159 r= write(fd,buf,len);
160 if (r==-1) {
161 Terrno("write");
162 } else {
163 Tprintf(" write= %d\n",r);
164 }
165
166 return r;
167 }