chiark / gitweb /
regress: Improve debug stdout from fuzzraw
[adns.git] / regress / hfuzzraw.c.m4
index c2c44cb186bdcd19c124fc6712d2f1610709b2be..00d7030f6b447e8cbbca2a0b73fd25c00b54dc3d 100644 (file)
@@ -108,11 +108,12 @@ static void P_read_dump(const unsigned char *p0, size_t count, ssize_t d) {
 }
     
 static void P_read(void *p, size_t sz, const char *what) {
+  long pos = ftell(Tinputfile);
   ssize_t got = fread(p,1,sz,Tinputfile);
   Pcheckinput();
   assert(got==sz);
   if (stdout_enable && sz) {
-    fprintf(stdout,"%s:",what);
+    fprintf(stdout,"%8lx %8s:",pos,what);
     P_read_dump(p, sz, +1);
     if (sz<=16) {
       P_read_dump((const unsigned char *)p+sz-1, sz, -1);
@@ -188,6 +189,13 @@ static void Pfdset(fd_set *set, int max, int *r_io) {
   }
 }
 
+#ifdef FUZZRAW_SYNC
+static void Psync(const char *exp, char *got, size_t sz, const char *what) {
+  P_read(got,sz,"syscall");
+  if (memcmp(exp,got,sz)) Pformat(what);
+}
+#endif
+
 #ifdef HAVE_POLL
 static void Ppollfds(struct pollfd *fds, int nfds, int *r_io) {
   int fd;
@@ -236,6 +244,12 @@ int H$1(hm_args_massage($3,void)) {
    Q$1(hm_args_massage($3));
  }
 
+#ifdef FUZZRAW_SYNC
+  static const char sync_expect[]= "$1";
+  static char sync_got[sizeof(sync_expect)];
+  Psync(sync_expect, sync_got, sizeof(sync_got), "sync lost: exp=$1");
+#endif
+
  m4_define(`hm_rv_succfail',`
   r= P_succfail();
   if (r<0) return r;