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