From a4f094dd69deb1053384e4015f1711c1200ffa0d Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 28 Nov 1998 18:44:56 +0000 Subject: [PATCH] Work on harness is progressing. --- src/Makefile | 16 +++-- src/Makefile.in | 16 +++-- src/harness.c | 0 src/harness.h | 69 ++++++++++++++++++++ src/hcommon.c | 77 ++++++++++++++++++++++ src/hrecord.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 331 insertions(+), 14 deletions(-) delete mode 100644 src/harness.c create mode 100644 src/harness.h create mode 100644 src/hcommon.c create mode 100644 src/hrecord.c diff --git a/src/Makefile b/src/Makefile index e4964af..39f49fa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -21,18 +21,20 @@ WARNS= -Wall -Wmissing-prototypes -Wwrite-strings -Wstrict-prototypes \ -Wcast-qual -Wpointer-arith WERROR=-Werror -HCPPFLAGS= \ - -Dsocket=Hsocket -Dfcntl=Hfcntl -Dgettimeofday=Hgettimeofday \ - -Dsendto=Hsendto -Drecvfrom=Hrecvfrom -Dselect=Hselect -Dconnect=Hconnect \ - -Dread=Hread -Dwrite=Hwrite -Dclose=Hclose +HCPPFLAGS:= $(foreach F, \ + gettimeofday select \ + socket fcntl connect close \ + sendto recvfrom read write \ +, -D$F=H$F) LIBOBJS= types.o event.o query.o reply.o general.o setup.o transmit.o parse.o HARNLOBJS= $(addsuffix _d.o, $(basename $(LIBOBJS))) -ALLOBJS= $(LIBOBJS) $(HARNLOBJS) dtest.o harness.o +ALLOBJS= $(LIBOBJS) $(HARNLOBJS) dtest.o hrecord.o hplayback.o hcommon.o -all: dtest +all: dtest hrecord +# hplayback -harness: harness.o $(HARNLOBJS) +hrecord: dtest.o hrecord.o hcommon.o $(HARNLOBJS) dtest: dtest.o $(LIBOBJS) diff --git a/src/Makefile.in b/src/Makefile.in index e4964af..39f49fa 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -21,18 +21,20 @@ WARNS= -Wall -Wmissing-prototypes -Wwrite-strings -Wstrict-prototypes \ -Wcast-qual -Wpointer-arith WERROR=-Werror -HCPPFLAGS= \ - -Dsocket=Hsocket -Dfcntl=Hfcntl -Dgettimeofday=Hgettimeofday \ - -Dsendto=Hsendto -Drecvfrom=Hrecvfrom -Dselect=Hselect -Dconnect=Hconnect \ - -Dread=Hread -Dwrite=Hwrite -Dclose=Hclose +HCPPFLAGS:= $(foreach F, \ + gettimeofday select \ + socket fcntl connect close \ + sendto recvfrom read write \ +, -D$F=H$F) LIBOBJS= types.o event.o query.o reply.o general.o setup.o transmit.o parse.o HARNLOBJS= $(addsuffix _d.o, $(basename $(LIBOBJS))) -ALLOBJS= $(LIBOBJS) $(HARNLOBJS) dtest.o harness.o +ALLOBJS= $(LIBOBJS) $(HARNLOBJS) dtest.o hrecord.o hplayback.o hcommon.o -all: dtest +all: dtest hrecord +# hplayback -harness: harness.o $(HARNLOBJS) +hrecord: dtest.o hrecord.o hcommon.o $(HARNLOBJS) dtest: dtest.o $(LIBOBJS) diff --git a/src/harness.c b/src/harness.c deleted file mode 100644 index e69de29..0000000 diff --git a/src/harness.h b/src/harness.h new file mode 100644 index 0000000..3fab1af --- /dev/null +++ b/src/harness.h @@ -0,0 +1,69 @@ +/* + * harness.h + * - complex test harness function declarations, not part of the library + */ +/* + * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef HARNESS_H_INCLUDED +#define HARNESS_H_INCLUDED + +#include +#include + +/* We override several system calls with #define's */ + +int Hgettimeofday(struct timeval *tv, struct timezone *tz); +int Hselect(int n, fd_set reads, fd_set writes, fd_set excepts, struct timeval *to); + +int Hsocket(int domain, int type, int protocol); +int Hfcntl(int fd, int cmd, long arg); +int Hconnect(int fd, struct sockaddr *addr, int addrlen); +int Hclose(int fd); + +int Hsendto(int fd, const void *msg, int msglen, unsigned int flags, + const struct sockaddr *addr, int addrlen); +int Hrecvfrom(int fd, void *buf, int buflen, unsigned int flags, + struct sockaddr *addr, int *addrlen); + +int Hread(int fd, void *buf, size_t len); +int Hwrite(int fd, const void *buf, size_t len); + +/* There is a Q function (Q for Question) for each such syscall; + * it constructs a string representing the call, and + * calls Tsyscall() on it. + */ + +void Tsyscall(const char *string); + +void Qgettimeofday(void); +void Qselect(int n, fd_set rfds, fd_set wfds, fd_set efds, const struct timeval *t); + +void Qsocket(int type); +void Qfcntl(int fd, int cmd, long arg); +void Qconnect(int fd, struct sockaddr *addr, int addrlen); +void Qclose(int fd); + +void Qsendto(int fd, const void *msg, int msglen, unsigned int flags, + const struct sockaddr *addr, int addrlen); +void Qrecvfrom(int fd, int buflen, unsigned int flags, int *addrlen); + +void Qread(int fd, size_t len); +void Qwrite(int fd, const void *buf, size_t len); + +#endif diff --git a/src/hcommon.c b/src/hcommon.c new file mode 100644 index 0000000..b62d275 --- /dev/null +++ b/src/hcommon.c @@ -0,0 +1,77 @@ +/* + * hcommon.c + * - complex test harness, routines used for both record and playback + */ +/* + * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "harness.h" +#include "internal.h" + +static vbuf vb; + +void Qgettimeofday(void) { + Tsyscall("gettimeofday()"); +} + +void Qselect(int n, fd_set rfds, fd_set wfds, fd_set efds, const struct timeval *t) { + char buf[100]; + + sprintf(buf,"select(%d, [",n); + vb.used= 0; + Tvba(&vb,buf); + Tvbfdset(&vb,n,rfds); + Tvba(&vb,"], ["); + Tvbfdset(&vb,n,wfds); + Tvba(&vb,"], ["); + Tvbfdset(&vb,n,efds); + if (t) { + sprintf(buf,"], %ld.%06ld)",t->tv_sec,t->tv_usec); + Tvba(&vb,buf); + } else { + Tvba(&vb,"], NULL)"); + } + Tvbfin(); + Tsyscall(vb.buf); +} + +void Qsocket(int type) { + switch (type) { + case SOCK_STREAM: Tsyscall("socket(,SOCK_STREAM,)"); break; + case SOCK_DGRAM: Tsyscall("socket(,SOCK_DGRAM,)"); break; + default: abort(); + } +} + +void Qfcntl(int fd, int cmd, long arg) { + static char buf[100]; + + switch (cmd) { + case F_GETFL: + sprintf(buf,"fcntl(%d, %s, %ld)", +} + +void Qconnect(int fd, struct sockaddr *addr, int addrlen); +void Qclose(int fd); + +void Qsendto(int fd, const void *msg, int msglen, unsigned int flags, + const struct sockaddr *addr, int addrlen); +void Qrecvfrom(int fd, int buflen, unsigned int flags, int *addrlen); + +void Qread(int fd, size_t len); +void Qwrite(int fd, const void *buf, size_t len); diff --git a/src/hrecord.c b/src/hrecord.c new file mode 100644 index 0000000..3851cc7 --- /dev/null +++ b/src/hrecord.c @@ -0,0 +1,167 @@ +/* + * hrecord.c + * - complex test harness, recording routines + */ +/* + * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "harness.h" + +static int begin_set; +static struct timeval begin; + +int Hgettimeofday(struct timeval *tv, struct timezone *tz) { + int r; + struct timeval diff; + + assert(tv); assert(!tz); + + Qgettimeofday(); + + r= gettimeofday(tv,0); if (r) Tfailed("gettimeofday"); + + if (!begin_set) { + printf(" gettimeofday= %ld.%06ld",tv->tv_sec,tv->tv_usec); + begin= *tv; + begin_set= 1; + } else { + diff.tv_sec= tv->tv_sec - begin.tv_sec; + diff.tv_usec= tv->tv_usec - begin.tv_usec; + if (diff.tv_usec < 0) { + diff.tv_sec -= 1; + diff.tv_usec += 1000000; + } + assert(diff.tv_sec >= 0); + assert(diff.tv_usec >= 0); + Tprintf(" gettimeofday= +%ld.%06ld\n",diff.tv_sec,diff.tv_usec); + } + return 0; +} + +int Hselect(int n, fd_set reads, fd_set writes, fd_set excepts, struct timeval *to) { + Qselect(n,reads,writes,excepts,to); + + r= select(n,reads,writes,excepts,to); + + if (r==-1) { + Terrorno("select"); + } else { + Tprintf(" select= %d",r); + Tfdset(reads); Tfdset(writes); Tfdset(excepts); + Tprintf("\n"); + } + + if (to) memset(to,0x5a,sizeof(*to)); +} + +int Hsocket(int domain, int type, int protocol) { + assert(domain == AF_INET); + + Qsocket(type); + r= socket(domain,type,protocol); if (r) Tfailed("socket"); + + Tprintf(" socket= %d\n",r); + return r; +} + +int Hfcntl(int fd, int cmd, long arg) { + Qfcntl(fd,cmd,arg); + + r= fcntl(fd, cmd, arg); if (r==-1) Tfailed("fcntl"); + + Tprintf(" fcntl= %d\n",r); + return r; +} + +int Hconnect(int fd, struct sockaddr *addr, int addrlen) { + Qconnect(fd,addr,addrlen); + + r= connect(fd, addr, addrlen); + + if (r) { + Terrno("connect"); + } else { + Tprintf(" connect= OK\n"); + } + return r; +} + +int Hclose(int fd) { + Qclose(fd); + return 0; +} + +int Hsendto(int fd, const void *msg, int msglen, unsigned int flags, + const struct sockaddr *addr, int addrlen) { + assert(!flags) + Qsendto(fd,msg,msglen,addr,addrlen); + + r= sendto(fd,msg,msglen,flags,addr,addrlen); + if (r==-1) { + Terrno("sendto"); + } else { + Tprintf(" sendto= %d\n",r); + } + return r; +} + +int Hrecvfrom(int fd, void *buf, int buflen, unsigned int flags, + struct sockaddr *addr, int *addrlen) { + assert(!flags) + Qrecvfrom(fd,buflen,addr,*addrlen); + + r= recvfrom(fd,buf,buflen,flags,addr,addrlen); + if (r==-1) { + Terrno("recvfrom"); + } else { + Tprintf(" recvfrom=",r); + Taddr(addr,addrlen); + Tbuf(buf,r); + Tprintf("\n"); + } + + return r; +} + +int Hread(int fd, void *buf, size_t len) { + Qread(fd,len); + + r= read(fd,buf,len); + if (r==-1) { + Terrno("read"); + } else { + Tprintf(" read="); + Tbuf(buf,r); + Tprintf("\n"); + } + + return r; +} + +int Hwrite(int fd, const void *buf, size_t len) { + Qwrite(fd,buf,len); + + r= write(fd,buf,len); + if (r==-1) { + Terrno("write"); + } else { + Tprintf(" write= %d\n",r); + } + + return r; +} -- 2.30.2