chiark / gitweb /
regress: Introduce FUZZRAW_SYNC
[adns.git] / regress / hplayback.c.m4
index 547dfe4efc43483ce137f776ab570c7b1fe8fcbd..96da8dfb37fa77e07af48b03a773002233d8de5f 100644 (file)
@@ -42,13 +42,9 @@ m4_include(hmacros.i4)
 
 #include "harness.h"
 
-static FILE *Tinputfile, *Treportfile;
+static FILE *Tinputfile, *Tfuzzrawfile, *Treportfile;
 static vbuf vb2;
 
-extern void Tshutdown(void) {
-  adns__vbuf_free(&vb2);
-}
-
 static void Tensurereportfile(void) {
   const char *fdstr;
   int fd;
@@ -60,6 +56,36 @@ static void Tensurereportfile(void) {
   Treportfile= fdopen(fd,"a"); if (!Treportfile) Tfailed("fdopen ADNS_TEST_REPORT_FD");
 }
 
+static void Tensurefuzzrawfile(void) {
+  static int done;
+
+  if (done) return;
+  done++;
+
+  const char *fdstr= getenv("ADNS_TEST_FUZZRAW_DUMP_FD");
+  if (!fdstr) return;
+
+  int fd= atoi(fdstr);
+  Tfuzzrawfile= fdopen(fd,"ab");
+  if (!Tfuzzrawfile) Tfailed("fdopen ADNS_TEST_FUZZRAW_DUMP_FD");
+}
+
+static void FR_write(const void *p, size_t sz) {
+  if (!Tfuzzrawfile) return;
+  ssize_t got = fwrite(p,1,sz,Tfuzzrawfile);
+  if (ferror(Tfuzzrawfile)) Tfailed("write fuzzraw output file");
+  assert(got==sz);
+}
+
+#define FR_WRITE(x) (FR_write(&(x), sizeof((x))))
+
+extern void Tshutdown(void) {
+  adns__vbuf_free(&vb2);
+  if (Tfuzzrawfile) {
+    if (fclose(Tfuzzrawfile)) Tfailed("close fuzzraw output file");
+  }
+}
+
 static void Psyntax(const char *where) {
   fprintf(stderr,"adns test harness: syntax error in test log input file: %s\n",where);
   exit(-1);
@@ -70,6 +96,15 @@ static void Pcheckinput(void) {
   if (feof(Tinputfile)) Psyntax("eof at syscall reply");
 }
 
+void T_gettimeofday_hook(void) {
+  static struct timeval previously;
+  struct timeval delta;
+  memset(&delta,0,sizeof(delta));
+  timersub(&currenttime, &previously, &delta);
+  previously = currenttime;
+  FR_WRITE(delta);
+}
+
 void Tensurerecordfile(void) {
   int fd;
   int chars;
@@ -171,6 +206,20 @@ static void Pfdset(fd_set *set, int max) {
     if (c == hm_squote]hm_squote) break;
     if (c != hm_squote,hm_squote) Psyntax("fd set separator not ,");
   }
+
+  uint16_t accum;
+  int inaccum=0, fd;
+  for (fd=0; ; fd++) {
+    if (fd>=max || inaccum==16) {
+      FR_WRITE(accum);
+      inaccum= 0;
+    }
+    if (fd>=max)
+      break;
+    accum <<= 1;
+    accum |= !!FD_ISSET(fd,set);
+    inaccum++;
+  }
 }
 
 #ifdef HAVE_POLL
@@ -305,12 +354,9 @@ m4_define(`hm_syscall', `
  hm_create_proto_h
 int H$1(hm_args_massage($3,void)) {
  int r, amtread;
+ hm_create_nothing
  m4_define(`hm_rv_fd',`char *ep;')
  m4_define(`hm_rv_any',`char *ep;')
- m4_define(`hm_rv_len',`')
- m4_define(`hm_rv_must',`')
- m4_define(`hm_rv_succfail',`')
- m4_define(`hm_rv_fcntl',`')
  $2
 
  hm_create_hqcall_vars
@@ -327,6 +373,7 @@ int H$1(hm_args_massage($3,void)) {
  fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
 
  Tensurereportfile();
+ Tensurefuzzrawfile();
  fprintf(Treportfile,"%s",vb2.buf);
  amtread= strlen(vb2.buf);
  if (amtread<=0 || vb2.buf[--amtread]!=hm_squote\nhm_squote)
@@ -334,22 +381,29 @@ int H$1(hm_args_massage($3,void)) {
  vb2.buf[amtread]= 0;
  if (memcmp(vb2.buf," $1=",hm_r_offset)) Psyntax("syscall reply mismatch");
 
+#ifdef FUZZRAW_SYNC
+ FR_WRITE("$1");
+#endif
+
+ m4_define(`hm_rv_check_errno',`
  if (vb2.buf[hm_r_offset] == hm_squoteEhm_squote) {
   int e;
   e= Perrno(vb2.buf+hm_r_offset);
   P_updatetime();
   errno= e;
+  FR_WRITE(e);
   return -1;
  }
-
- m4_define(`hm_rv_succfail',`
+ r= 0;
+ FR_WRITE(r);
+ ')
+ m4_define(`hm_rv_check_success',`
   if (memcmp(vb2.buf+hm_r_offset,"OK",2)) Psyntax("success/fail not E* or OK");
   vb2.used= hm_r_offset+2;
   r= 0;
  ')
- m4_define(`hm_rv_len',`hm_rv_succfail')
- m4_define(`hm_rv_must',`hm_rv_succfail')
- m4_define(`hm_rv_any',`
+ m4_define(`hm_rv_any_nowrite',`
+  hm_rv_check_errno
   unsigned long ul_r= strtoul(vb2.buf+hm_r_offset,&ep,10);
   if (ul_r < 0 || ul_r > INT_MAX ||
       (*ep && *ep!=hm_squote hm_squote))
@@ -357,7 +411,25 @@ int H$1(hm_args_massage($3,void)) {
   r= ul_r;
   vb2.used= ep - (char*)vb2.buf;
  ')
+
+ m4_define(`hm_rv_succfail',`
+  hm_rv_check_errno
+  hm_rv_check_success
+ ')
+ m4_define(`hm_rv_len',`
+  hm_rv_check_errno
+  hm_rv_check_success
+ ')
+ m4_define(`hm_rv_must',`
+  hm_rv_check_success
+ ')
+ m4_define(`hm_rv_any',`
+  hm_rv_any_nowrite
+  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) {
@@ -370,7 +442,7 @@ int H$1(hm_args_massage($3,void)) {
       Psyntax("fcntl flags not O_NONBLOCK|... or ~O_NONBLOCK&...");
     }
   } else if (cmd == F_SETFL) {
-    hm_rv_succfail
+    hm_rv_check_success
   } else {
     Psyntax("fcntl not F_GETFL or F_SETFL");
   }
@@ -386,7 +458,11 @@ int H$1(hm_args_massage($3,void)) {
  if (vb2.used != amtread) Psyntax("junk at end of line");
 
  hm_create_nothing
- m4_define(`hm_arg_bytes_out',`r= Pbytes($'`2,$'`4);')
+ m4_define(`hm_arg_bytes_out',`
+  r= Pbytes($'`2,$'`4);
+  FR_WRITE(r);
+  FR_write(buf,r);
+ ')
  $3
 
  P_updatetime();