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