From: ian Date: Sat, 15 Oct 2005 16:29:58 +0000 (+0000) Subject: + * Call Tensurerecordfile in Hgettimeofday (Tensurerecordfile was X-Git-Tag: before-srv-2006-04-04~11 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=adns.git;a=commitdiff_plain;h=87dd63455668503e4f929e741856a3cfc880d570 + * Call Tensurerecordfile in Hgettimeofday (Tensurerecordfile was @@ -11,6 +11,11 @@ updated). + * Call Tensurerecordfile in Hgettimeofday (Tensurerecordfile was + Tensureinputfile/Tensureoutputfile). + * Add bind(2) and listen(2) to test harness (for epithet's benefit, but + harmless in adns). + * Add missing ENOTSOCK to hcommon.c.m4 (was already in hcommon.c!) --- diff --git a/changelog b/changelog index 04f2bce..058436d 100644 --- a/changelog +++ b/changelog @@ -11,6 +11,11 @@ adns (1.2); urgency=medium updated). * Add documentation comment by definition of adns_r_ptr_raw type enum. * Add -Wno-pointer-sign if GCC has that option. + * Call Tensurerecordfile in Hgettimeofday (Tensurerecordfile was + Tensureinputfile/Tensureoutputfile). + * Add bind(2) and listen(2) to test harness (for epithet's benefit, but + harmless in adns). + * Add missing ENOTSOCK to hcommon.c.m4 (was already in hcommon.c!) -- diff --git a/regress/harness.h b/regress/harness.h index 2708e66..3bcccf9 100644 --- a/regress/harness.h +++ b/regress/harness.h @@ -13,6 +13,8 @@ void Qpoll( const struct pollfd *fds , int nfds , int timeout ); void Qsocket( int type ); void Qfcntl( int fd , int cmd , long arg ); void Qconnect( int fd , const struct sockaddr *addr , int addrlen ); +void Qbind( int fd , const struct sockaddr *addr , int addrlen ); +void Qlisten( int fd , int backlog ); void Qclose( int fd ); void Qsendto( int fd , const void *msg , int msglen , const struct sockaddr *addr , int addrlen ); void Qrecvfrom( int fd , int buflen , int addrlen ); @@ -25,7 +27,7 @@ void Tfailed(const char *why); void Toutputerr(void); void Tnomem(void); void Tfsyscallr(const char *fmt, ...) PRINTFFORMAT(1,2); -void Tensureoutputfile(void); +void Tensurerecordfile(void); void Tmust(const char *call, const char *arg, int cond); void Tvbf(const char *fmt, ...) PRINTFFORMAT(1,2); void Tvbvf(const char *fmt, va_list al); diff --git a/regress/harness.h.m4 b/regress/harness.h.m4 index a25bd37..fca588d 100644 --- a/regress/harness.h.m4 +++ b/regress/harness.h.m4 @@ -51,7 +51,7 @@ void Tfailed(const char *why); void Toutputerr(void); void Tnomem(void); void Tfsyscallr(const char *fmt, ...) PRINTFFORMAT(1,2); -void Tensureoutputfile(void); +void Tensurerecordfile(void); void Tmust(const char *call, const char *arg, int cond); void Tvbf(const char *fmt, ...) PRINTFFORMAT(1,2); diff --git a/regress/hcommon.c b/regress/hcommon.c index 4a6293a..3466ec9 100644 --- a/regress/hcommon.c +++ b/regress/hcommon.c @@ -34,6 +34,7 @@ const struct Terrno Terrnos[]= { }; static vbuf vbw; int Hgettimeofday(struct timeval *tv, struct timezone *tz) { + Tensurerecordfile(); Tmust("gettimeofday","tz",!tz); *tv= currenttime; return 0; @@ -92,6 +93,20 @@ void Qconnect( int fd , const struct sockaddr *addr , int addrlen ) { Tvba(" addr="); Tvbaddr(addr,addrlen); Q_vb(); } +void Qbind( int fd , const struct sockaddr *addr , int addrlen ) { + vb.used= 0; + Tvba("bind"); + Tvbf(" fd=%d",fd); + Tvba(" addr="); Tvbaddr(addr,addrlen); + Q_vb(); +} +void Qlisten( int fd , int backlog ) { + vb.used= 0; + Tvba("listen"); + Tvbf(" fd=%d",fd); + Tvbf(" backlog=%d",backlog); + Q_vb(); +} void Qclose( int fd ) { vb.used= 0; Tvba("close"); diff --git a/regress/hcommon.c.m4 b/regress/hcommon.c.m4 index 68127be..17f6955 100644 --- a/regress/hcommon.c.m4 +++ b/regress/hcommon.c.m4 @@ -61,12 +61,14 @@ const struct Terrno Terrnos[]= { { "ECONNRESET", ECONNRESET }, { "ECONNREFUSED", ECONNREFUSED }, { "EPIPE", EPIPE }, + { "ENOTSOCK", ENOTSOCK }, { 0, 0 } }; static vbuf vbw; int Hgettimeofday(struct timeval *tv, struct timezone *tz) { + Tensurerecordfile(); Tmust("gettimeofday","tz",!tz); *tv= currenttime; return 0; diff --git a/regress/hplayback.c b/regress/hplayback.c index fdb3a7d..594f7e6 100644 --- a/regress/hplayback.c +++ b/regress/hplayback.c @@ -32,7 +32,7 @@ static void Pcheckinput(void) { if (ferror(Tinputfile)) Tfailed("read test log input file"); if (feof(Tinputfile)) Psyntax("eof at syscall reply"); } -static void Tensureinputfile(void) { +void Tensurerecordfile(void) { const char *fdstr; int fd; int chars; @@ -196,7 +196,7 @@ static int Pbytes(byte *buf, int maxlen) { void Q_vb(void) { int r; const char *nl; - Tensureinputfile(); + Tensurerecordfile(); if (!adns__vbuf_ensure(&vb2,vb.used+2)) Tnomem(); r= fread(vb2.buf,1,vb.used+2,Tinputfile); if (feof(Tinputfile)) { @@ -385,6 +385,60 @@ int Hconnect( int fd , const struct sockaddr *addr , int addrlen ) { P_updatetime(); return r; } +int Hbind( int fd , const struct sockaddr *addr , int addrlen ) { + int r, amtread; + Qbind( fd , addr , addrlen ); + if (!adns__vbuf_ensure(&vb2,1000)) Tnomem(); + fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput(); + Tensurereportfile(); + fprintf(Treportfile,"%s",vb2.buf); + amtread= strlen(vb2.buf); + if (amtread<=0 || vb2.buf[--amtread]!='\n') + Psyntax("badly formed line"); + vb2.buf[amtread]= 0; + if (memcmp(vb2.buf," bind=",6)) Psyntax("syscall reply mismatch"); + if (vb2.buf[6] == 'E') { + int e; + e= Perrno(vb2.buf+6); + P_updatetime(); + errno= e; + return -1; + } + if (memcmp(vb2.buf+6,"OK",2)) Psyntax("success/fail not E* or OK"); + vb2.used= 6+2; + r= 0; + assert(vb2.used <= amtread); + if (vb2.used != amtread) Psyntax("junk at end of line"); + P_updatetime(); + return r; +} +int Hlisten( int fd , int backlog ) { + int r, amtread; + Qlisten( fd , backlog ); + if (!adns__vbuf_ensure(&vb2,1000)) Tnomem(); + fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput(); + Tensurereportfile(); + fprintf(Treportfile,"%s",vb2.buf); + amtread= strlen(vb2.buf); + if (amtread<=0 || vb2.buf[--amtread]!='\n') + Psyntax("badly formed line"); + vb2.buf[amtread]= 0; + if (memcmp(vb2.buf," listen=",8)) Psyntax("syscall reply mismatch"); + if (vb2.buf[8] == 'E') { + int e; + e= Perrno(vb2.buf+8); + P_updatetime(); + errno= e; + return -1; + } + if (memcmp(vb2.buf+8,"OK",2)) Psyntax("success/fail not E* or OK"); + vb2.used= 8+2; + r= 0; + assert(vb2.used <= amtread); + if (vb2.used != amtread) Psyntax("junk at end of line"); + P_updatetime(); + return r; +} int Hclose( int fd ) { int r, amtread; Qclose( fd ); diff --git a/regress/hplayback.c.m4 b/regress/hplayback.c.m4 index 3437293..9fd0780 100644 --- a/regress/hplayback.c.m4 +++ b/regress/hplayback.c.m4 @@ -69,7 +69,7 @@ static void Pcheckinput(void) { if (feof(Tinputfile)) Psyntax("eof at syscall reply"); } -static void Tensureinputfile(void) { +void Tensurerecordfile(void) { const char *fdstr; int fd; int chars; @@ -261,7 +261,7 @@ void Q_vb(void) { int r; const char *nl; - Tensureinputfile(); + Tensurerecordfile(); if (!adns__vbuf_ensure(&vb2,vb.used+2)) Tnomem(); r= fread(vb2.buf,1,vb.used+2,Tinputfile); if (feof(Tinputfile)) { diff --git a/regress/hrecord.c b/regress/hrecord.c index c60f93c..88e24a4 100644 --- a/regress/hrecord.c +++ b/regress/hrecord.c @@ -12,7 +12,7 @@ void Tshutdown(void) { static void R_recordtime(void) { int r; struct timeval tv, tvrel; - Tensureoutputfile(); + Tensurerecordfile(); r= gettimeofday(&tv,0); if (r) Tfailed("gettimeofday syscallbegin"); tvrel.tv_sec= tv.tv_sec - currenttime.tv_sec; tvrel.tv_usec= tv.tv_usec - currenttime.tv_usec; @@ -20,7 +20,7 @@ static void R_recordtime(void) { Tvbf("\n +%ld.%06ld",(long)tvrel.tv_sec,(long)tvrel.tv_usec); currenttime= tv; } -void Tensureoutputfile(void) { +void Tensurerecordfile(void) { const char *fdstr; int fd, r; if (Toutputfile) return; @@ -36,7 +36,7 @@ void Tensureoutputfile(void) { } void Q_vb(void) { if (!adns__vbuf_append(&vb,"",1)) Tnomem(); - Tensureoutputfile(); + Tensurerecordfile(); if (fprintf(Toutputfile," %s\n",vb.buf) == EOF) Toutputerr(); if (fflush(Toutputfile)) Toutputerr(); } @@ -142,6 +142,36 @@ int Hconnect( int fd , const struct sockaddr *addr , int addrlen ) { errno= e; return r; } +int Hbind( int fd , const struct sockaddr *addr , int addrlen ) { + int r, e; + Qbind( fd , addr , addrlen ); + r= bind( fd , addr , addrlen ); + e= errno; + vb.used= 0; + Tvba("bind="); + if (r) { Tvberrno(e); goto x_error; } + Tvba("OK"); + x_error: + R_recordtime(); + R_vb(); + errno= e; + return r; +} +int Hlisten( int fd , int backlog ) { + int r, e; + Qlisten( fd , backlog ); + r= listen( fd , backlog ); + e= errno; + vb.used= 0; + Tvba("listen="); + if (r) { Tvberrno(e); goto x_error; } + Tvba("OK"); + x_error: + R_recordtime(); + R_vb(); + errno= e; + return r; +} int Hclose( int fd ) { int r, e; Qclose( fd ); diff --git a/regress/hrecord.c.m4 b/regress/hrecord.c.m4 index e5287a0..033796c 100644 --- a/regress/hrecord.c.m4 +++ b/regress/hrecord.c.m4 @@ -45,7 +45,7 @@ static void R_recordtime(void) { int r; struct timeval tv, tvrel; - Tensureoutputfile(); + Tensurerecordfile(); r= gettimeofday(&tv,0); if (r) Tfailed("gettimeofday syscallbegin"); tvrel.tv_sec= tv.tv_sec - currenttime.tv_sec; tvrel.tv_usec= tv.tv_usec - currenttime.tv_usec; @@ -54,7 +54,7 @@ static void R_recordtime(void) { currenttime= tv; } -void Tensureoutputfile(void) { +void Tensurerecordfile(void) { const char *fdstr; int fd, r; @@ -74,7 +74,7 @@ void Tensureoutputfile(void) { void Q_vb(void) { if (!adns__vbuf_append(&vb,"",1)) Tnomem(); - Tensureoutputfile(); + Tensurerecordfile(); if (fprintf(Toutputfile," %s\n",vb.buf) == EOF) Toutputerr(); if (fflush(Toutputfile)) Toutputerr(); } diff --git a/regress/hredirect.h b/regress/hredirect.h index 7550687..fd2fa40 100644 --- a/regress/hredirect.h +++ b/regress/hredirect.h @@ -13,6 +13,10 @@ #define fcntl Hfcntl #undef connect #define connect Hconnect +#undef bind +#define bind Hbind +#undef listen +#define listen Hlisten #undef close #define close Hclose #undef sendto diff --git a/regress/hsyscalls.h b/regress/hsyscalls.h index 5d87442..3e886be 100644 --- a/regress/hsyscalls.h +++ b/regress/hsyscalls.h @@ -15,6 +15,8 @@ int Hpoll( struct pollfd *fds , int nfds , int timeout ); int Hsocket( int domain , int type , int protocol ); int Hfcntl( int fd , int cmd , ... ); int Hconnect( int fd , const struct sockaddr *addr , int addrlen ); +int Hbind( int fd , const struct sockaddr *addr , int addrlen ); +int Hlisten( int fd , int backlog ); 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 ); diff --git a/regress/hsyscalls.i4 b/regress/hsyscalls.i4 index d5a57b7..6be9556 100644 --- a/regress/hsyscalls.i4 +++ b/regress/hsyscalls.i4 @@ -88,6 +88,18 @@ hm_syscall( hm_arg_addr_in(addr,addrlen) hm_na ') +hm_syscall( + bind, `hm_rv_succfail', ` + hm_arg_fd(fd) hm_na + hm_arg_addr_in(addr,addrlen) hm_na +') + +hm_syscall( + listen, `hm_rv_succfail', ` + hm_arg_fd(fd) hm_na + hm_arg_int(backlog) hm_na +') + hm_syscall( close, `hm_rv_succfail', ` hm_arg_fd(fd) hm_na