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