chiark / gitweb /
Fix typo in changelog entry for 1.6.1
[adns.git] / regress / hcommon.c.m4
index 330da4d2e9d27a4dcbebe342b15c7ae2a06ccb7d..3fd2a103865b56bdc837faa4e6b76cb8a52d7166 100644 (file)
@@ -2,12 +2,8 @@ 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
-m4_dnl    Copyright (C) 1997-2000,2003,2006,2014  Ian Jackson
-m4_dnl    Copyright (C) 2014  Mark Wooding
-m4_dnl    Copyright (C) 1999-2000,2003,2006  Tony Finch
-m4_dnl    Copyright (C) 1991 Massachusetts Institute of Technology
-m4_dnl  (See the file INSTALL for full details.)
+m4_dnl  This file is part of adns, which is Copyright Ian Jackson
+m4_dnl  and contributors (see the file INSTALL for full details).
 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
@@ -36,6 +32,7 @@ m4_include(hmacros.i4)
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <time.h>
 
 #include "harness.h"
 #include "internal.h"
@@ -64,14 +61,28 @@ const struct Terrno Terrnos[]= {
   {  0,                          0                            }
 };
 
+const int Tnerrnos= sizeof(Terrnos)/sizeof(Terrnos[0]) - 1;
+
 static vbuf vbw;
 
 int Hgettimeofday(struct timeval *tv, struct timezone *tz) {
-  Tensurerecordfile();
+  Tensuresetup();
   Tmust("gettimeofday","tz",!tz);
+  T_gettimeofday_hook();
   *tv= currenttime;
   return 0;
 }
+int Hclock_gettime(clockid_t clk, struct timespec *ts) {
+  Tensuresetup();
+  ts->tv_sec =  currenttime.tv_sec;
+  ts->tv_nsec = currenttime.tv_usec * 1000 + 666;
+  switch (clk) {
+  case CLOCK_MONOTONIC: ts->tv_sec -= 1500000000; break;
+  case CLOCK_REALTIME:                            break;
+  default: Tmust("clock_gettime","clk",0);
+  }
+  return 0;
+}
 
 int Hwritev(int fd, const struct iovec *vector, size_t count) {
   size_t i;
@@ -132,6 +143,8 @@ m4_define(`hm_specsyscall', `')
 
 m4_include(`hsyscalls.i4')
 
+hm_stdsyscall_close
+
 void Tvbaddr(const struct sockaddr *addr, int len) {
   char buf[ADNS_ADDR2TEXT_BUFLEN];
   int err, port;
@@ -160,6 +173,11 @@ void Tvbfdset(int max, const fd_set *fds) {
   int i;
   const char *comma= "";
   
+  if (!fds) {
+    Tvba("null");
+    return;
+  }
+
   Tvba("[");
   for (i=0; i<max; i++) {
     if (!FD_ISSET(i,fds)) continue;
@@ -245,84 +263,21 @@ void Toutputerr(void) {
   Tfailed("write error on test harness output");
 }
 
-struct malloced {
-  struct malloced *next, *back;
-  size_t sz;
-  unsigned long count;
-  struct { double d; long ul; void *p; void (*fp)(void); } data;
-};
-
-static unsigned long malloccount, mallocfailat;
-static struct { struct malloced *head, *tail; } mallocedlist;
-
-#define MALLOCHSZ ((char*)&mallocedlist.head->data - (char*)mallocedlist.head)
-
-void *Hmalloc(size_t sz) {
-  struct malloced *newnode;
-  const char *mfavar;
-  char *ep;
-
-  assert(sz);
-
-  newnode= malloc(MALLOCHSZ + sz);  if (!newnode) Tnomem();
-
-  LIST_LINK_TAIL(mallocedlist,newnode);
-  newnode->sz= sz;
-  newnode->count= ++malloccount;
-  if (!mallocfailat) {
-    mfavar= getenv("ADNS_REGRESS_MALLOCFAILAT");
-    if (mfavar) {
-      mallocfailat= strtoul(mfavar,&ep,10);
-      if (!mallocfailat || *ep) Tfailed("ADNS_REGRESS_MALLOCFAILAT bad value");
-    } else {
-      mallocfailat= ~0UL;
-    }
-  }
-  assert(newnode->count != mallocfailat);
-  memset(&newnode->data,0xc7,sz);
-  return &newnode->data;
-}
-
-void Hfree(void *ptr) {
-  struct malloced *oldnode;
-
-  if (!ptr) return;
-
-  oldnode= (void*)((char*)ptr - MALLOCHSZ);
-  LIST_UNLINK(mallocedlist,oldnode);
-  memset(&oldnode->data,0x38,oldnode->sz);
-  free(oldnode);
+void Hexit(int rv) {
+  Tensuresetup();
+  vb.used= 0;
+  Tvbf("exit %d", rv);
+  Q_vb();
+  Texit(0);
 }
 
-void *Hrealloc(void *op, size_t nsz) {
-  struct malloced *oldnode;
-  void *np;
-  size_t osz;
-
-  if (op) { oldnode= (void*)((char*)op - MALLOCHSZ); osz= oldnode->sz; } else { osz= 0; }
-  np= Hmalloc(nsz);
-  if (osz) memcpy(np,op, osz>nsz ? nsz : osz);
-  Hfree(op);
-  return np;
+pid_t Hgetpid(void) {
+  return 2264; /* just some number */
 }
 
-void Hexit(int rv) {
-  struct malloced *loopnode;
-
+void Tcommonshutdown(void) {
   Tshutdown();
   adns__vbuf_free(&vb);
   adns__vbuf_free(&vbw);
-  if (mallocedlist.head) {
-    fprintf(stderr,"adns test harness: memory leaked:");
-    for (loopnode=mallocedlist.head; loopnode; loopnode=loopnode->next)
-      fprintf(stderr," %lu",loopnode->count);
-    putc('\n',stderr);
-    if (ferror(stderr)) exit(-1);
-  }
-  exit(rv);
-}
-
-pid_t Hgetpid(void) {
-  return 2264; /* just some number */
+  Tmallocshutdown();
 }
-