chiark / gitweb /
20764237e0d5817d34ddf4f39aee2a9cc973c12f
[adns.git] / regress / hrecord.c.m4
1 m4_dnl hrecord.c.m4
2 m4_dnl (part of complex test harness, not of the library)
3 m4_dnl - recording routines
4
5 m4_dnl  This file is part of adns, which is
6 m4_dnl    Copyright (C) 1997-2000,2003,2006,2014-2016,2020  Ian Jackson
7 m4_dnl    Copyright (C) 2014  Mark Wooding
8 m4_dnl    Copyright (C) 1999-2000,2003,2006  Tony Finch
9 m4_dnl    Copyright (C) 1991 Massachusetts Institute of Technology
10 m4_dnl  (See the file INSTALL for full details.)
11 m4_dnl  
12 m4_dnl  This program is free software; you can redistribute it and/or modify
13 m4_dnl  it under the terms of the GNU General Public License as published by
14 m4_dnl  the Free Software Foundation; either version 3, or (at your option)
15 m4_dnl  any later version.
16 m4_dnl  
17 m4_dnl  This program is distributed in the hope that it will be useful,
18 m4_dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 m4_dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 m4_dnl  GNU General Public License for more details.
21 m4_dnl  
22 m4_dnl  You should have received a copy of the GNU General Public License
23 m4_dnl  along with this program; if not, write to the Free Software Foundation.
24
25 m4_include(hmacros.i4)
26
27 #include <assert.h>
28 #include <string.h>
29 #include <errno.h>
30 #include <stdlib.h>
31
32 #include <sys/types.h>
33 #include <unistd.h>
34 #include <fcntl.h>
35
36 #include "harness.h"
37
38 static FILE *Toutputfile;
39
40 void Tshutdown(void) {
41 }
42
43 static void R_recordtime(void) {
44   int r;
45   struct timeval tv, tvrel;
46
47   Tensurerecordfile();
48   r= gettimeofday(&tv,0); if (r) Tfailed("gettimeofday syscallbegin");
49   tvrel.tv_sec= tv.tv_sec - currenttime.tv_sec;
50   tvrel.tv_usec= tv.tv_usec - currenttime.tv_usec;
51   if (tv.tv_usec < 0) { tvrel.tv_usec += 1000000; tvrel.tv_sec--; }
52   Tvbf("\n +%ld.%06ld",(long)tvrel.tv_sec,(long)tvrel.tv_usec);
53   currenttime= tv;
54 }
55
56 void T_gettimeofday_hook(void) { }
57
58 void Tensurerecordfile(void) {
59   const char *fdstr;
60   int fd, r;
61
62   if (Toutputfile) return;
63   
64   Toutputfile= stdout;
65   fdstr= getenv("ADNS_TEST_OUT_FD");
66   if (fdstr) {
67     fd= atoi(fdstr);
68     Toutputfile= fdopen(fd,"a"); if (!Toutputfile) Tfailed("fdopen ADNS_TEST_OUT_FD");
69   }
70
71   r= gettimeofday(&currenttime,0); if (r) Tfailed("gettimeofday syscallbegin");
72   if (fprintf(Toutputfile," start %ld.%06ld\n",
73               (long)currenttime.tv_sec,(long)currenttime.tv_usec) == EOF) Toutputerr();
74 }
75
76 void Q_vb(void) {
77   if (!adns__vbuf_append(&vb,"",1)) Tnomem();
78   Tensurerecordfile();
79   if (fprintf(Toutputfile," %s\n",vb.buf) == EOF) Toutputerr();
80   if (fflush(Toutputfile)) Toutputerr();
81 }
82
83 static void R_vb(void) {
84   Q_vb();
85 }
86
87 m4_define(`hm_syscall', `
88  hm_create_proto_h
89 int H$1(hm_args_massage($3,void)) {
90  int r, e;
91
92  hm_create_hqcall_vars
93  $3
94
95  hm_create_hqcall_init($1)
96  $3
97
98  hm_create_hqcall_args
99  Q$1(hm_args_massage($3));
100
101  hm_create_realcall_args
102  r= $1(hm_args_massage($3));
103  e= errno;
104
105  vb.used= 0;
106  Tvba("$1=");
107  m4_define(`hm_rv_any',`
108   if (r==-1) { Tvberrno(e); goto x_error; }
109   Tvbf("%d",r);')
110  m4_define(`hm_rv_fd',`hm_rv_any($'`1)')
111  m4_define(`hm_rv_succfail',`
112   if (r) { Tvberrno(e); goto x_error; }
113   Tvba("OK");')
114  m4_define(`hm_rv_must',`Tmust("$1","return",!r); Tvba("OK");')
115  m4_define(`hm_rv_len',`
116   if (r==-1) { Tvberrno(e); goto x_error; }
117   Tmust("$'`1","return",r<=$'`1);
118   Tvba("OK");')
119  m4_define(`hm_rv_fcntl',`
120   if (r==-1) { Tvberrno(e); goto x_error; }
121   if (cmd == F_GETFL) {
122     Tvbf(r & O_NONBLOCK ? "O_NONBLOCK|..." : "~O_NONBLOCK&...");
123   } else {
124     if (cmd == F_SETFL) {
125       Tmust("$1","return",!r);
126     } else {
127       Tmust("cmd","F_GETFL/F_SETFL",0);
128     }
129     Tvba("OK");
130   }')
131  $2
132
133  hm_create_nothing
134  m4_define(`hm_arg_fdset_io',`Tvba(" $'`1="); Tvbfdset($'`2,$'`1);')
135  m4_define(`hm_arg_pollfds_io',`Tvba(" $'`1="); Tvbpollfds($'`1,$'`2);')
136  m4_define(`hm_arg_addr_out',`Tvba(" $'`1="); Tvbaddr($'`1,*$'`2);')
137  $3
138
139  hm_create_nothing
140  m4_define(`hm_arg_bytes_out',`Tvbbytes($'`2,r);')
141  $3
142
143  m4_define(`hm_rv_any',`x_error:')
144  m4_define(`hm_rv_fd',`x_error:')
145  m4_define(`hm_rv_succfail',`x_error:')
146  m4_define(`hm_rv_len',`x_error:')
147  m4_define(`hm_rv_fcntl',`x_error:')
148  m4_define(`hm_rv_must',`')
149  $2
150
151  R_recordtime();
152  R_vb();
153  errno= e;
154  return r;
155 }
156 ')
157
158 m4_define(`hm_specsyscall', `')
159
160 m4_include(`hsyscalls.i4')
161
162 hm_stdsyscall_close