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