bb7ba677 |
1 | m4_dnl hrecord.c.m4 |
2 | m4_dnl (part of complex test harness, not of the library) |
3 | m4_dnl - recording routines |
4 | |
d942707d |
5 | m4_dnl This file is |
6 | m4_dnl Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> |
7 | m4_dnl |
8 | m4_dnl It is part of adns, which is |
9 | m4_dnl Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> |
10 | m4_dnl Copyright (C) 1999 Tony Finch <dot@dotat.at> |
bb7ba677 |
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 2, 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 | m4_dnl Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | |
26 | m4_include(hmacros.i4) |
27 | |
28 | #include <assert.h> |
29 | #include <string.h> |
30 | #include <fcntl.h> |
31 | #include <errno.h> |
70a778e5 |
32 | #include <stdlib.h> |
bb7ba677 |
33 | |
34 | #include "harness.h" |
35 | |
70a778e5 |
36 | static FILE *Toutputfile; |
37 | |
98b6d5b4 |
38 | static void R_recordtime(void) { |
39 | int r; |
40 | struct timeval tv, tvrel; |
41 | |
42 | Tensureoutputfile(); |
43 | r= gettimeofday(&tv,0); if (r) Tfailed("gettimeofday syscallbegin"); |
44 | tvrel.tv_sec= tv.tv_sec - currenttime.tv_sec; |
45 | tvrel.tv_usec= tv.tv_usec - currenttime.tv_usec; |
46 | if (tv.tv_usec < 0) { tvrel.tv_usec += 1000000; tvrel.tv_sec--; } |
47 | Tvbf("\n +%ld.%06ld",(long)tvrel.tv_sec,(long)tvrel.tv_usec); |
48 | currenttime= tv; |
49 | } |
50 | |
70a778e5 |
51 | void Tensureoutputfile(void) { |
52 | const char *fdstr; |
98b6d5b4 |
53 | int fd, r; |
70a778e5 |
54 | |
98b6d5b4 |
55 | if (Toutputfile) return; |
56 | |
70a778e5 |
57 | Toutputfile= stdout; |
98b6d5b4 |
58 | fdstr= getenv("ADNS_TEST_OUT_FD"); |
59 | if (fdstr) { |
60 | fd= atoi(fdstr); |
61 | Toutputfile= fdopen(fd,"a"); if (!Toutputfile) Tfailed("fdopen ADNS_TEST_OUT_FD"); |
62 | } |
63 | |
64 | r= gettimeofday(¤ttime,0); if (r) Tfailed("gettimeofday syscallbegin"); |
65 | if (fprintf(Toutputfile," start %ld.%06ld\n", |
66 | (long)currenttime.tv_sec,(long)currenttime.tv_usec) == EOF) Toutputerr(); |
70a778e5 |
67 | } |
bb7ba677 |
68 | |
69 | void Q_vb(void) { |
70 | if (!adns__vbuf_append(&vb,"",1)) Tnomem(); |
71 | Tensureoutputfile(); |
72 | if (fprintf(Toutputfile," %s\n",vb.buf) == EOF) Toutputerr(); |
73 | if (fflush(Toutputfile)) Toutputerr(); |
74 | } |
75 | |
76 | static void R_vb(void) { |
77 | Q_vb(); |
78 | } |
98b6d5b4 |
79 | |
bb7ba677 |
80 | m4_define(`hm_syscall', ` |
81 | hm_create_proto_h |
82 | int H$1(hm_args_massage($3,void)) { |
83 | int r, e; |
84 | |
85 | hm_create_hqcall_vars |
86 | $3 |
87 | |
88 | hm_create_hqcall_init($1) |
89 | $3 |
90 | |
91 | hm_create_hqcall_args |
92 | Q$1(hm_args_massage($3)); |
93 | |
94 | hm_create_realcall_args |
95 | r= $1(hm_args_massage($3)); |
96 | e= errno; |
97 | |
98 | vb.used= 0; |
99 | Tvba("$1="); |
100 | m4_define(`hm_rv_any',` |
101 | if (r==-1) { Tvberrno(e); goto x_error; } |
102 | Tvbf("%d",r);') |
103 | m4_define(`hm_rv_fd',`hm_rv_any($'`1)') |
104 | m4_define(`hm_rv_succfail',` |
105 | if (r) { Tvberrno(e); goto x_error; } |
106 | Tvba("OK");') |
70a778e5 |
107 | m4_define(`hm_rv_must',`Tmust("$1","return",!r); Tvba("OK");') |
bb7ba677 |
108 | m4_define(`hm_rv_len',` |
109 | if (r==-1) { Tvberrno(e); goto x_error; } |
110 | Tmust("$1","return",r<=$'`1); |
70a778e5 |
111 | Tvba("OK");') |
73c4c523 |
112 | m4_define(`hm_rv_fcntl',` |
113 | if (r==-1) { Tvberrno(e); goto x_error; } |
114 | if (cmd == F_GETFL) { |
115 | Tvbf(r & O_NONBLOCK ? "O_NONBLOCK|..." : "~O_NONBLOCK&..."); |
73c4c523 |
116 | } else { |
b373026c |
117 | if (cmd == F_SETFL) { |
118 | Tmust("$1","return",!r); |
119 | } else { |
120 | Tmust("cmd","F_GETFL/F_SETFL",0); |
121 | } |
122 | Tvba("OK"); |
123 | }') |
bb7ba677 |
124 | $2 |
125 | |
126 | hm_create_nothing |
127 | m4_define(`hm_arg_fdset_io',`Tvba(" $'`1="); Tvbfdset($'`2,$'`1);') |
8b1171e6 |
128 | m4_define(`hm_arg_pollfds_io',`Tvba(" $'`1="); Tvbpollfds($'`1,$'`2);') |
bb7ba677 |
129 | m4_define(`hm_arg_addr_out',`Tvba(" $'`1="); Tvbaddr($'`1,*$'`2);') |
bb7ba677 |
130 | $3 |
131 | |
132 | hm_create_nothing |
133 | m4_define(`hm_arg_bytes_out',`Tvbbytes($'`2,r);') |
134 | $3 |
135 | |
136 | m4_define(`hm_rv_any',`x_error:') |
137 | m4_define(`hm_rv_fd',`x_error:') |
138 | m4_define(`hm_rv_succfail',`x_error:') |
139 | m4_define(`hm_rv_len',`x_error:') |
73c4c523 |
140 | m4_define(`hm_rv_fcntl',`x_error:') |
bb7ba677 |
141 | m4_define(`hm_rv_must',`') |
142 | $2 |
143 | |
98b6d5b4 |
144 | R_recordtime(); |
bb7ba677 |
145 | R_vb(); |
146 | errno= e; |
147 | return r; |
148 | } |
149 | ') |
150 | |
151 | m4_include(`hsyscalls.i4') |