chiark / gitweb /
regress: fuzzraw: Handle select and poll return value specially
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Nov 2016 17:54:02 +0000 (17:54 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Jun 2020 15:13:02 +0000 (16:13 +0100)
Don't read or write it to the fuzzraw stream.  Instead, in hfuzzraw,
calculate it from the returned fd set (and check it's consistent with
the timeout).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
regress/hfuzzraw.c.m4
regress/hplayback.c.m4

index 6984c8b1c1ccc3f42718804b7b517addeed403e6..3dad0879f40f52f450929df8bee0a170aa7a974e 100644 (file)
@@ -137,7 +137,7 @@ static int Pbytes(byte *buf, int maxlen) {
   return l;
 }
 
-static void Pfdset(fd_set *set, int max) {
+static void Pfdset(fd_set *set, int max, int *r_io) {
   uint16_t got;
   int fd, ngot=0;
 
@@ -148,7 +148,9 @@ static void Pfdset(fd_set *set, int max) {
       P_READ(got);
       ngot= 16;
     }
-    if (!(got & 1u)) {
+    if (got & 1u) {
+      (*r_io)++;
+    } else {
       FD_CLR(fd,set);
     }
     got >>= 1;
@@ -157,12 +159,14 @@ static void Pfdset(fd_set *set, int max) {
 }
 
 #ifdef HAVE_POLL
-static void Ppollfds(struct pollfd *fds, int nfds) {
-int fd;
+static void Ppollfds(struct pollfd *fds, int nfds, int *r_io) {
+  int fd;
   for (fd=0; fd<nfds; fd++) {
     if (!fds[fd].events) continue;
     P_fdf(fd);
     P_READ(fds[fd].revents);
+    if (fds[fd].revents)
+      (*r_io)++;
   }
 }
 #endif
@@ -221,6 +225,8 @@ int H$1(hm_args_massage($3,void)) {
  m4_define(`hm_rv_must',`
   r= 0;
  ')
+ m4_define(`hm_rv_select',`hm_rv_succfail')
+ m4_define(`hm_rv_poll',`hm_rv_succfail')
  m4_define(`hm_rv_fcntl',`
   unsigned flg = P_fdf(fd);
   if (cmd == F_GETFL) {
@@ -254,8 +260,8 @@ int H$1(hm_args_massage($3,void)) {
  $2
 
  hm_create_nothing
- m4_define(`hm_arg_fdset_io',`Pfdset($'`1,$'`2);')
- m4_define(`hm_arg_pollfds_io',`Ppollfds($'`1,$'`2);')
+ m4_define(`hm_arg_fdset_io',`Pfdset($'`1,$'`2,&r);')
+ m4_define(`hm_arg_pollfds_io',`Ppollfds($'`1,$'`2,&r);')
  m4_define(`hm_arg_addr_out',`Paddr($'`1,$'`2);')
  $3
 
@@ -263,6 +269,14 @@ int H$1(hm_args_massage($3,void)) {
  m4_define(`hm_arg_bytes_out',`r= Pbytes($'`2,$'`4);')
  $3
 
+ hm_create_nothing
+ m4_define(`hm_rv_selectpoll',`
+  if (($'`1) && !r) Pformat("select/poll returning 0 but infinite timeout");
+ ')
+ m4_define(`hm_rv_select',`hm_rv_selectpoll(!to)')
+ m4_define(`hm_rv_poll',`hm_rv_selectpoll(timeout<0)')
+ $2
+
  return r;
 }
 ')
index db50e4d012d6d6749731dfb02248c17119d8c8ce..f6034cb9fd9c5cec04fb88537637a3cbd10e174f 100644 (file)
@@ -409,6 +409,8 @@ int H$1(hm_args_massage($3,void)) {
   FR_WRITE(r);
  ')
  m4_define(`hm_rv_fd',`hm_rv_any')
+ m4_define(`hm_rv_select',`hm_rv_any_nowrite')
+ m4_define(`hm_rv_poll',`hm_rv_any_nowrite')
  m4_define(`hm_rv_fcntl',`
   r= 0;
   if (cmd == F_GETFL) {