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