From 8b1171e6b5eb5524958f1876e2753f5b75a26cfd Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 11 Jul 1999 19:11:05 +0000 Subject: [PATCH] Regression for poll(2). --- regress/Makefile.in | 2 +- regress/case-poll.err | 0 regress/case-poll.out | 5 ++ regress/case-poll.sys | 34 +++++++++ regress/case-polltimeout.err | 0 regress/case-polltimeout.out | 4 ++ regress/case-polltimeout.sys | 135 +++++++++++++++++++++++++++++++++++ regress/harness.h.m4 | 2 + regress/hcommon.c.m4 | 28 ++++++++ regress/hmacros.i4 | 4 ++ regress/hplayback.c.m4 | 56 +++++++++++++++ regress/hrecord.c.m4 | 1 + regress/hsyscalls.i4 | 6 ++ regress/m1test | 13 ++-- regress/r1test | 4 +- src/event.c | 1 - 16 files changed, 287 insertions(+), 8 deletions(-) create mode 100644 regress/case-poll.err create mode 100644 regress/case-poll.out create mode 100644 regress/case-poll.sys create mode 100644 regress/case-polltimeout.err create mode 100644 regress/case-polltimeout.out create mode 100644 regress/case-polltimeout.sys diff --git a/regress/Makefile.in b/regress/Makefile.in index c67c682..606359a 100644 --- a/regress/Makefile.in +++ b/regress/Makefile.in @@ -27,7 +27,7 @@ include $(srcdir)/../src/adns.make DIRCFLAGS= -I$(srcdir)/../src HCPPFLAGS:= $(foreach F, \ - gettimeofday select \ + gettimeofday select poll \ socket fcntl connect close \ sendto recvfrom read write writev \ , -D$F=H$F) diff --git a/regress/case-poll.err b/regress/case-poll.err new file mode 100644 index 0000000..e69de29 diff --git a/regress/case-poll.out b/regress/case-poll.out new file mode 100644 index 0000000..6953cea --- /dev/null +++ b/regress/case-poll.out @@ -0,0 +1,5 @@ +adns debug: using nameserver 172.18.45.6 +chiark.greenend.org.uk flags 0 type 1 A(-) submitted +chiark.greenend.org.uk flags 0 type A(-): OK; nrrs=1; cname=$; owner=$; ttl=86400 + 195.224.76.132 +rc=0 diff --git a/regress/case-poll.sys b/regress/case-poll.sys new file mode 100644 index 0000000..ba05521 --- /dev/null +++ b/regress/case-poll.sys @@ -0,0 +1,34 @@ +default -,p +:1 chiark.greenend.org.uk + start 931719947.391142 + socket type=SOCK_DGRAM + socket=4 + +0.000208 + fcntl fd=4 cmd=F_GETFL + fcntl=~O_NONBLOCK&... + +0.000087 + fcntl fd=4 cmd=F_SETFL O_NONBLOCK|... + fcntl=OK + +0.000066 + sendto fd=4 addr=172.18.45.6:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000592 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=1 fds=[{fd=4, events=POLLIN, revents=POLLIN}] + +0.006530 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=OK addr=172.18.45.6:53 + 311f8580 00010001 00020002 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001 c00c0001 00010001 51800004 c3e04c84 08677265 656e656e + 64036f72 6702756b 00000200 01000151 80001103 6e73300a 72656c61 74697669 + 7479c038 c0380002 00010001 51800006 036e7331 c057c053 00010001 00015180 + 0004ac12 2d06c070 00010001 00015180 0004ac12 2d41. + +0.001044 + recvfrom fd=4 buflen=512 *addrlen=16 + recvfrom=EAGAIN + +0.000211 + close fd=4 + close=OK + +0.000248 diff --git a/regress/case-polltimeout.err b/regress/case-polltimeout.err new file mode 100644 index 0000000..e69de29 diff --git a/regress/case-polltimeout.out b/regress/case-polltimeout.out new file mode 100644 index 0000000..a3f7495 --- /dev/null +++ b/regress/case-polltimeout.out @@ -0,0 +1,4 @@ +adns debug: using nameserver 172.18.45.36 +chiark.greenend.org.uk flags 0 type 1 A(-) submitted +chiark.greenend.org.uk flags 0 type A(-): DNS query timed out; nrrs=0; cname=$; owner=$; ttl=604770 +rc=0 diff --git a/regress/case-polltimeout.sys b/regress/case-polltimeout.sys new file mode 100644 index 0000000..4e207f0 --- /dev/null +++ b/regress/case-polltimeout.sys @@ -0,0 +1,135 @@ +noserver -,p +:1 chiark.greenend.org.uk + start 931719968.733439 + socket type=SOCK_DGRAM + socket=4 + +0.000199 + fcntl fd=4 cmd=F_GETFL + fcntl=~O_NONBLOCK&... + +0.000087 + fcntl fd=4 cmd=F_SETFL O_NONBLOCK|... + fcntl=OK + +0.000067 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000790 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009031 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000436 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009093 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000519 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.008993 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000500 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009010 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000486 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009050 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000485 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009014 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000485 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009045 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000451 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009050 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000483 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009042 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000433 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009083 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000521 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009017 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000442 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009058 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000510 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009012 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000436 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.009085 + sendto fd=4 addr=172.18.45.36:53 + 311f0100 00010000 00000000 06636869 61726b08 67726565 6e656e64 036f7267 + 02756b00 00010001. + sendto=40 + +0.000514 + poll fds=[{fd=4, events=POLLIN, revents=0}] timeout=2000 + poll=0 fds=[{fd=4, events=POLLIN, revents=0}] + +2.008998 + close fd=4 + close=OK + +0.000302 diff --git a/regress/harness.h.m4 b/regress/harness.h.m4 index b9fddb3..de29194 100644 --- a/regress/harness.h.m4 +++ b/regress/harness.h.m4 @@ -27,6 +27,7 @@ m4_include(hmacros.i4) #include #include #include +#include #include "internal.h" @@ -62,6 +63,7 @@ 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); void Tvbfdset(int max, const fd_set *set); +void Tvbpollfds(const struct pollfd *fds, int nfds); void Tvbaddr(const struct sockaddr *addr, int addrlen); void Tvbbytes(const void *buf, int len); void Tvberrno(int e); diff --git a/regress/hcommon.c.m4 b/regress/hcommon.c.m4 index d1f72b7..19c7ba4 100644 --- a/regress/hcommon.c.m4 +++ b/regress/hcommon.c.m4 @@ -77,6 +77,7 @@ void Q$1(hm_args_massage($3,void)) { m4_define(`hm_arg_nullptr',`') m4_define(`hm_arg_int', `Tvbf(" $'`1=%d",$'`1);') m4_define(`hm_arg_fdset_io', `Tvbf(" $'`1="); Tvbfdset($'`2,$'`1);') + m4_define(`hm_arg_pollfds_io', `Tvbf(" $'`1="); Tvbpollfds($'`1,$'`2);') m4_define(`hm_arg_timeval_in_rel_null', ` if ($'`1) Tvbf(" $'`1=%ld.%06ld",(long)$'`1->tv_sec,(long)$'`1->tv_usec); else Tvba(" $'`1=null");') @@ -145,6 +146,33 @@ void Tvbfdset(int max, const fd_set *fds) { Tvba("]"); } +static void Tvbpollevents(int events) { + const char *delim= ""; + + events &= (POLLIN|POLLOUT|POLLPRI); + if (!events) { Tvba("0"); return; } + if (events & POLLIN) { Tvba("POLLIN"); delim= "|"; } + if (events & POLLOUT) { Tvba(delim); Tvba("POLLOUT"); delim= "|"; } + if (events & POLLPRI) { Tvba(delim); Tvba("POLLPRI"); } +} + +void Tvbpollfds(const struct pollfd *fds, int nfds) { + const char *comma= ""; + + Tvba("["); + while (nfds>0) { + Tvba(comma); + Tvbf("{fd=%d, events=",fds->fd); + Tvbpollevents(fds->events); + Tvba(", revents="); + Tvbpollevents(fds->revents); + Tvba("}"); + comma= ", "; + nfds--; fds++; + } + Tvba("]"); +} + void Tvberrno(int e) { const struct Terrno *te; diff --git a/regress/hmacros.i4 b/regress/hmacros.i4 index 3194e03..9433b18 100644 --- a/regress/hmacros.i4 +++ b/regress/hmacros.i4 @@ -38,6 +38,7 @@ m4_define(`hm_create_nothing', ` m4_define(`hm_arg_nullptr', `') m4_define(`hm_arg_int', `') m4_define(`hm_arg_fdset_io', `') + m4_define(`hm_arg_pollfds_io', `') m4_define(`hm_arg_timeval_in_rel_null',`') m4_define(`hm_arg_must', `') m4_define(`hm_arg_socktype',`') @@ -55,6 +56,7 @@ m4_define(`hm_create_proto_h',` m4_define(`hm_arg_nullptr', `$'`1 $'`2') m4_define(`hm_arg_int', `int $'`1') m4_define(`hm_arg_fdset_io', `fd_set *$'`1') + m4_define(`hm_arg_pollfds_io', `struct pollfd *$'`1 hm_comma int $'`2') m4_define(`hm_arg_timeval_in_rel_null', `struct timeval *$'`1') m4_define(`hm_arg_must', `$'`1 $'`2') m4_define(`hm_arg_socktype', `int $'`1') @@ -71,6 +73,7 @@ m4_define(`hm_create_proto_q',` hm_create_proto_h m4_define(`hm_arg_nullptr', `') m4_define(`hm_arg_fdset_io', `const fd_set *$'`1') + m4_define(`hm_arg_pollfds_io', `const struct pollfd *$'`1 hm_comma int $'`2') m4_define(`hm_arg_must', `') m4_define(`hm_arg_ign', `') m4_define(`hm_arg_fcntl_cmd_arg', `int $'`1 hm_comma long $'`2') @@ -104,6 +107,7 @@ m4_define(`hm_create_realcall_args',` m4_define(`hm_arg_nullptr', `0') m4_define(`hm_arg_int', `$'`1') m4_define(`hm_arg_fdset_io', `$'`1') + m4_define(`hm_arg_pollfds_io', `$'`1 hm_comma $'`2') m4_define(`hm_arg_timeval_in_rel_null', `$'`1') m4_define(`hm_arg_must', `$'`2') m4_define(`hm_arg_socktype', `$'`1') diff --git a/regress/hplayback.c.m4 b/regress/hplayback.c.m4 index 5f8b456..ce295d0 100644 --- a/regress/hplayback.c.m4 +++ b/regress/hplayback.c.m4 @@ -89,6 +89,20 @@ static void Parg(const char *argname) { if (vb2.buf[vb2.used++] != hm_squote=hm_squote) Psyntax("not = after argument name"); } +static int Pstring_maybe(const char *string) { + int l; + + l= strlen(string); + if (memcmp(vb2.buf+vb2.used,string,l)) return 0; + vb2.used+= l; + return 1; +} + +static void Pstring(const char *string, const char *emsg) { + if (Pstring_maybe(string)) return; + Psyntax(emsg); +} + static int Perrno(const char *stuff) { const struct Terrno *te; int r; @@ -136,6 +150,47 @@ static void Pfdset(fd_set *set, int max) { } } +static int Ppollfdevents(void) { + int events; + + if (Pstring_maybe("0")) return 0; + events= 0; + + if (Pstring_maybe("POLLIN")) { + events |= POLLIN; + if (!Pstring_maybe("|")) return events; + } + + if (Pstring_maybe("POLLOUT")) { + events |= POLLOUT; + if (!Pstring_maybe("|")) return events; + } + + Pstring("POLLPRI","pollfdevents PRI?"); + return events; +} + +static void Ppollfds(struct pollfd *fds, int nfds) { + int i; + char *ep; + const char *comma= ""; + + if (vb2.buf[vb2.used++] != hm_squote[hm_squote) Psyntax("pollfds start not ["); + for (i=0; ifd= strtoul(vb2.buf+vb2.used,&ep,10); + vb2.used= ep - (char*)vb2.buf; + Pstring(", events=",", events= in pollfds"); + fds->events= Ppollfdevents(); + Pstring(", revents=",", revents= in pollfds"); + fds->revents= Ppollfdevents(); + Pstring("}","} in pollfds"); + Pstring(comma,"separator in pollfds"); + comma= ", "; + } + if (vb2.buf[vb2.used++] != hm_squote]hm_squote) Psyntax("pollfds end not ]"); +} + static void Paddr(struct sockaddr *addr, int *lenr) { struct sockaddr_in *sa= (struct sockaddr_in*)addr; char *p, *ep; @@ -281,6 +336,7 @@ int H$1(hm_args_massage($3,void)) { hm_create_nothing m4_define(`hm_arg_fdset_io',`Parg("$'`1"); Pfdset($'`1,$'`2);') + m4_define(`hm_arg_pollfds_io',`Parg("$'`1"); Ppollfds($'`1,$'`2);') m4_define(`hm_arg_addr_out',`Parg("$'`1"); Paddr($'`1,$'`2);') $3 if (vb2.used != vb2.avail) Psyntax("junk at end of line"); diff --git a/regress/hrecord.c.m4 b/regress/hrecord.c.m4 index 98a24b7..4344146 100644 --- a/regress/hrecord.c.m4 +++ b/regress/hrecord.c.m4 @@ -120,6 +120,7 @@ int H$1(hm_args_massage($3,void)) { hm_create_nothing m4_define(`hm_arg_fdset_io',`Tvba(" $'`1="); Tvbfdset($'`2,$'`1);') + m4_define(`hm_arg_pollfds_io',`Tvba(" $'`1="); Tvbpollfds($'`1,$'`2);') m4_define(`hm_arg_addr_out',`Tvba(" $'`1="); Tvbaddr($'`1,*$'`2);') $3 diff --git a/regress/hsyscalls.i4 b/regress/hsyscalls.i4 index e81072a..ec4b630 100644 --- a/regress/hsyscalls.i4 +++ b/regress/hsyscalls.i4 @@ -56,6 +56,12 @@ hm_syscall( hm_arg_timeval_in_rel_null(to) hm_na ') +hm_syscall( + poll, `hm_rv_any', ` + hm_arg_pollfds_io(fds,nfds) hm_na + hm_arg_int(timeout) hm_na +') + hm_syscall( socket, `hm_rv_fd', ` hm_arg_must(int,domain,AF_INET) hm_na diff --git a/regress/m1test b/regress/m1test index 81cd024..82e94ca 100755 --- a/regress/m1test +++ b/regress/m1test @@ -4,23 +4,28 @@ set -e if [ $# -lt 3 ] then - echo >&2 'usage: m1test ' + echo >&2 'usage: m1test [] ' exit 1 fi case="case-$1"; shift initfile="$1"; shift + +case "$1" in +-*) initflags="$1"; shift +esac + queryargs="$*" initstring="`cat init-$initfile.text`" -echo "$initfile" >"$case.sys" +echo $initfile $initflags >"$case.sys" echo "$queryargs" >>"$case.sys" -echo running "hrecord /... $queryargs" +echo running hrecord $initflags "/... $queryargs" set +e ADNS_TEST_OUT_FD=3 3>>"$case.sys" >"$case.out" 2>"$case.err" >"$ocase.report" >"$ocase.out" 2>"$ocase.err" \ - ./hplayback "/$initstring" $queryargs + ./hplayback $initflags "/$initstring" $queryargs rc=$? set -e diff --git a/src/event.c b/src/event.c index 1b527a2..0115e07 100644 --- a/src/event.c +++ b/src/event.c @@ -228,7 +228,6 @@ int adns__pollfds(adns_state ads, struct pollfd pollfds_buf[MAX_POLLFDS]) { abort(); } pollfds_buf[1].fd= ads->tcpsocket; - pollfds_buf[1].revents= 0; return 2; } -- 2.30.2