chiark / gitweb /
New m4-based test harness stuff.
[adns.git] / regress / hcommon.c.m4
similarity index 50%
rename from src/hcommon.c
rename to regress/hcommon.c.m4
index e7e2c55a203db87500340e1bca64d61fcaf3a0a1..4c1af7c1141539f0d33df5e2a86ea3b4a37e2247 100644 (file)
@@ -1,24 +1,24 @@
-/*
- * hcommon.c
- * - complex test harness, routines used for both record and playback
- */
-/*
- *  This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson
- *  
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2, or (at your option)
- *  any later version.
- *  
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *  
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
- */
+m4_dnl hcommon.c
+m4_dnl (part of complex test harness, not of the library)
+m4_dnl - routines used for both record and playback
+
+m4_dnl  This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson
+m4_dnl  
+m4_dnl  This program is free software; you can redistribute it and/or modify
+m4_dnl  it under the terms of the GNU General Public License as published by
+m4_dnl  the Free Software Foundation; either version 2, or (at your option)
+m4_dnl  any later version.
+m4_dnl  
+m4_dnl  This program is distributed in the hope that it will be useful,
+m4_dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
+m4_dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+m4_dnl  GNU General Public License for more details.
+m4_dnl  
+m4_dnl  You should have received a copy of the GNU General Public License
+m4_dnl  along with this program; if not, write to the Free Software Foundation,
+m4_dnl  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+
+m4_include(hmacros.i4)
 
 #include <fcntl.h>
 #include <string.h>
@@ -48,90 +48,44 @@ const struct Terrno Terrnos[]= {
   {  0,                          0                            }
 };
 
-void Qgettimeofday(void) {
-  Q_str("gettimeofday()");
-}
-
-void Qselect(int n, const fd_set *rfds, const fd_set *wfds, const fd_set *efds,
-            const struct timeval *to) {
-  vb.used= 0;
-  Tvbf("select(%d,",n);
-  Tvbfdset(n,rfds);
-  Tvba(",");
-  Tvbfdset(n,wfds);
-  Tvba(",");
-  Tvbfdset(n,efds);
-  if (to) {
-    Tvbf(", %ld.%06ld)",to->tv_sec,to->tv_usec);
-  } else {
-    Tvba(", NULL)");
-  }
-  Q_vb();
-}
-
-void Qsocket(int type) {
-  switch (type) {
-  case SOCK_STREAM: Q_str("socket(,SOCK_STREAM,)"); break;
-  case SOCK_DGRAM:  Q_str("socket(,SOCK_DGRAM,)");  break;
-  default: abort();
-  }
-}
-
-void Qfcntl_setfl(int fd, int cmd, long arg) {
-  vb.used= 0;
-  Tvbf("fcntl(%d, F_SETFL, %ld)",fd,arg);
-  Q_vb();
-}
-
-void Qfcntl_other(int fd, int cmd) {
-  assert(cmd==F_GETFL);
-  vb.used= 0;
-  Tvbf("fcntl(%d, F_GETFL)",fd);
-  Q_vb();
-}
 
-void Qconnect(int fd, struct sockaddr *addr, int addrlen) {
-  vb.used= 0;
-  Tvbf("connect(%d, ",fd);
-  Tvbaddr(addr,addrlen);
-  Tvba(")");
-  Q_vb();
-}
 
-void Qclose(int fd) {
-  vb.used= 0;
-  Tvbf("close(%d)",fd);
-  Q_vb();
-}
 
-void Qsendto(int fd, const void *msg, int msglen,
-            const struct sockaddr *addr, int addrlen) {
-  vb.used= 0;
-  Tvbf("sendto(%d,,,, ",fd);
-  Tvbaddr(addr,addrlen);
-  Tvba(")");
-  Tvbbytes(msg,msglen);
-  Q_vb();
-}
+m4_define(`hm_syscall', `
+ hm_create_proto_q
+void Q$1(hm_args_massage($3,void)) {
+
+ vb.used= 0;
+ Tvba("$1");
+ m4_define(`hm_na',`')
+ 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_timeval_in_rel_null', `
+  if ($'`1) Tvbf(" $'`1=%ld.%06ld",(long)$'`1->tv_sec,(long)$'`1->tv_usec);
+  else Tvba(" $'`1=null");')
+ m4_define(`hm_arg_must', `')
+ m4_define(`hm_arg_socktype', `
+  Tvbf($'`1==SOCK_STREAM ? " $'`1=SOCK_STREAM" : " $'`1=SOCK_DGRAM");')
+ m4_define(`hm_arg_ign', `')
+ m4_define(`hm_arg_fd', `Tvbf(" $'`1=%d",$'`1);')
+ m4_define(`hm_arg_fcntl_cmd_arg', `
+  if ($'`1 == F_SETFL) {
+   Tvbf(" $'`1=F_SETFL %ld",arg);
+  } else {
+   Tvba(" $'`1=F_GETFL");
+  }')
+ m4_define(`hm_arg_addr_in', `Tvbaddr($'`1,$'`2);')
+ m4_define(`hm_arg_bytes_in', `Tvbbytes($'`2,$'`4);')
+ m4_define(`hm_arg_bytes_out', `Tvbf(" $'`4=%lu",(unsigned long)$'`4);')
+ m4_define(`hm_arg_addr_out', `Tvbf(" *$'`2=%d",$'`2);')
+  $3
 
-void Qrecvfrom(int fd, int buflen, int addrlen) {
-  vb.used= 0;
-  Tvbf("recvfrom(%d,,%d,,,%d)",fd,buflen,addrlen);
   Q_vb();
 }
+')
 
-void Qread(int fd, size_t len) {
-  vb.used= 0;
-  Tvbf("read(%d,,%lu)",fd,(unsigned long)len);
-  Q_vb();
-}
-  
-void Qwrite(int fd, const void *buf, size_t len) {
-  vb.used= 0;
-  Tvbf("write(%d,,)",fd);
-  Tvbbytes(buf,len);
-  Q_vb();
-}
+m4_include(`hsyscalls.i4')
 
 
 void Tvbaddr(const struct sockaddr *addr, int len) {
@@ -139,7 +93,7 @@ void Tvbaddr(const struct sockaddr *addr, int len) {
   
   assert(len==sizeof(struct sockaddr_in));
   assert(ai->sin_family==AF_INET);
-  Tvbf(" %s:%u",inet_ntoa(ai->sin_addr),htons(ai->sin_port));
+  Tvbf("%s:%u",inet_ntoa(ai->sin_addr),htons(ai->sin_port));
 }
 
 void Tvbbytes(const void *buf, int len) {
@@ -158,7 +112,7 @@ void Tvbfdset(int max, const fd_set *fds) {
   int i;
   const char *comma= "";
   
-  Tvba(" [");
+  Tvba("[");
   for (i=0; i<max; i++) {
     if (!FD_ISSET(i,fds)) continue;
     Tvba(comma);
@@ -197,6 +151,12 @@ void Tvbf(const char *fmt, ...) {
 }
 
 
+void Tmust(const char *call, const char *arg, int cond) {
+  if (cond) return;
+  fprintf(stderr,"adns test harness: case not handled: system call %s, arg %s",call,arg);
+  exit(-1);
+}
+
 void Tfailed(const char *why) {
   fprintf(stderr,"adns test harness: failure: %s: %s\n",why,strerror(errno));
   exit(-1);