chiark / gitweb /
regress: fuzzraw: Call Tensuresetup in Q_vb, just in case
[adns.git] / regress / hfuzzraw.c.m4
index 0a23de69dac948ab047949de87b270d30f552eda..7cc1d30d0f9878413e437c134a34bcf86e0305ba 100644 (file)
@@ -53,29 +53,7 @@ static void Tflushstdout( void) {
   if (fflush(stdout)) Toutputerr();
 }
 
-void Q_vb(void) {
-  if (!adns__vbuf_append(&vb,"",1)) Tnomem();
-  if (fprintf(stdout," %s\n",vb.buf) == EOF) Toutputerr();
-  Tflushstdout();
-}
-
-static void Pformat(const char *what) {
-  fprintf(stderr,"adns test harness: format error in raw log input file: %s\n",what);
-  exit(-1);
-}
-
-extern void Tshutdown(void) {
-  int c= fgetc(Tinputfile);
-  if (c!=EOF) Pformat("unwanted additional syscall reply data");
-  if (ferror(Tinputfile)) Tfailed("read test log input (at end)");
-}
-
-static void Pcheckinput(void) {
-  if (ferror(Tinputfile)) Tfailed("read test log input file");
-  if (feof(Tinputfile)) Pformat("eof at syscall reply");
-}
-
-void Tensurerecordfile(void) {
+void Tensuresetup(void) {
   static int done;
 
   if (done) return;
@@ -97,6 +75,28 @@ void Tensurerecordfile(void) {
   if (proutstr) stdout_enable= atoi(proutstr);
 }
 
+void Q_vb(void) {
+  Tensuresetup();
+  if (!adns__vbuf_append(&vb,"",1)) Tnomem();
+  if (fprintf(stdout," %s\n",vb.buf) == EOF) Toutputerr();
+  Tflushstdout();
+}
+
+static void Pformat(const char *what) {
+  fprintf(stderr,"adns test harness: format error in raw log input file: %s\n",what);
+  exit(-1);
+}
+
+extern void Tshutdown(void) {
+  int c= fgetc(Tinputfile);
+  if (c!=EOF) Pformat("unwanted additional syscall reply data");
+  if (ferror(Tinputfile)) Tfailed("read test log input (at end)");
+}
+
+static void Pcheckinput(void) {
+  if (ferror(Tinputfile)) Tfailed("read test log input file");
+  if (feof(Tinputfile)) Pformat("eof at syscall reply");
+}
 
 static void P_read_dump(const unsigned char *p0, size_t count, ssize_t d) {
   fputs(" | ",stdout);
@@ -138,28 +138,28 @@ void T_gettimeofday_hook(void) {
 }
 
 static void Paddr(struct sockaddr *addr, int *lenr) {
-  int l, r;
+  int al, r;
   uint16_t port;
   char buf[512];
   socklen_t sl = *lenr;
 
-  P_READ(l);
-  if (l<0 || l>=sizeof(buf)-1) Pformat("bad addr len");
-  P_read(buf,l,"addrtext");
-  buf[l]= 0;
+  P_READ(al);
+  if (al<0 || al>=sizeof(buf)-1) Pformat("bad addr len");
+  P_read(buf,al,"addrtext");
+  buf[al]= 0;
   P_READ(port);
   r= adns_text2addr(buf,port, adns_qf_addrlit_scope_numeric, addr, &sl);
   if (r==EINVAL) Pformat("bad addr text");
-  assert(r==ENOSPC);
+  assert(r==0 || r==ENOSPC);
   *lenr = sl;
 }
 
 static int Pbytes(byte *buf, int maxlen) {
-  int l;
-  P_READ(l);
-  if (l<0 || l>maxlen) Pformat("bad byte block len");
-  P_read(buf, l, "bytes");
-  return l;
+  int bl;
+  P_READ(bl);
+  if (bl<0 || bl>maxlen) Pformat("bad byte block len");
+  P_read(buf, bl, "bytes");
+  return bl;
 }
 
 static void Pfdset(fd_set *set, int max, int *r_io) {
@@ -196,6 +196,13 @@ static void Psync(const char *exp, char *got, size_t sz, const char *what) {
   if (memcmp(exp,got,sz)) Pformat(what);
 }
 #endif
+m4_define(`syscall_sync',`
+#ifdef FUZZRAW_SYNC
+  hm_fr_syscall_ident($'`1)
+  static char sync_got[sizeof(sync_expect)];
+  Psync(sync_expect, sync_got, sizeof(sync_got), "sync lost: exp=$1");
+#endif
+')
 
 #ifdef HAVE_POLL
 static void Ppollfds(struct pollfd *fds, int nfds, int *r_io) {
@@ -213,10 +220,7 @@ static void Ppollfds(struct pollfd *fds, int nfds, int *r_io) {
 static int P_succfail(void) {
   int e;
   P_READ(e);
-  if (e<0 && -e<Tnerrnos) {
-    errno= Terrnos[-e].v;
-    return -1;
-  } else if (e>0 && e<=255) {
+  if (e>0) {
     errno= e;
     return -1;
   } else if (e) {
@@ -238,18 +242,14 @@ int H$1(hm_args_massage($3,void)) {
  hm_create_hqcall_init($1)
  $3
 
- Tensurerecordfile();
+ Tensuresetup();
 
  if (stdout_enable) {
    hm_create_hqcall_args
    Q$1(hm_args_massage($3));
  }
 
-#ifdef FUZZRAW_SYNC
-  hm_fr_syscall_ident($'`1)
-  static char sync_got[sizeof(sync_expect)];
-  Psync(sync_expect, sync_got, sizeof(sync_got), "sync lost: exp=$1");
-#endif
+  syscall_sync($'`1)
 
  m4_define(`hm_rv_succfail',`
   r= P_succfail();
@@ -264,8 +264,7 @@ int H$1(hm_args_massage($3,void)) {
   }
  ')
  m4_define(`hm_rv_len',`
-  hm_rv_any
-  if (r>($'`1)) Pformat("syscall length return is excessive");
+  hm_rv_succfail
  ')
  m4_define(`hm_rv_must',`
   r= 0;
@@ -331,6 +330,7 @@ m4_define(`hm_specsyscall', `')
 m4_include(`hsyscalls.i4')
 
 int Hclose(int fd) {
+  syscall_sync(close)
   P_fdf(fd);
   fdtab.buf[fd]= 0;
   return P_succfail();