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 | |
5 | m4_dnl This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson |
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> |
27 | |
28 | #include "harness.h" |
29 | |
30 | static int begin_set; |
31 | static struct timeval begin; |
32 | |
33 | void Q_vb(void) { |
34 | if (!adns__vbuf_append(&vb,"",1)) Tnomem(); |
35 | Tensureoutputfile(); |
36 | if (fprintf(Toutputfile," %s\n",vb.buf) == EOF) Toutputerr(); |
37 | if (fflush(Toutputfile)) Toutputerr(); |
38 | } |
39 | |
40 | static void R_vb(void) { |
41 | Q_vb(); |
42 | } |
43 | |
44 | m4_define(`hm_syscall', ` |
45 | hm_create_proto_h |
46 | int H$1(hm_args_massage($3,void)) { |
47 | int r, e; |
48 | |
49 | hm_create_hqcall_vars |
50 | $3 |
51 | |
52 | hm_create_hqcall_init($1) |
53 | $3 |
54 | |
55 | hm_create_hqcall_args |
56 | Q$1(hm_args_massage($3)); |
57 | |
58 | hm_create_realcall_args |
59 | r= $1(hm_args_massage($3)); |
60 | e= errno; |
61 | |
62 | vb.used= 0; |
63 | Tvba("$1="); |
64 | m4_define(`hm_rv_any',` |
65 | if (r==-1) { Tvberrno(e); goto x_error; } |
66 | Tvbf("%d",r);') |
67 | m4_define(`hm_rv_fd',`hm_rv_any($'`1)') |
68 | m4_define(`hm_rv_succfail',` |
69 | if (r) { Tvberrno(e); goto x_error; } |
70 | Tvba("OK");') |
71 | m4_define(`hm_rv_must',`Tmust("$1","return",!r);') |
72 | m4_define(`hm_rv_len',` |
73 | if (r==-1) { Tvberrno(e); goto x_error; } |
74 | Tmust("$1","return",r<=$'`1); |
75 | Tvbf("%d",r);') |
76 | $2 |
77 | |
78 | hm_create_nothing |
79 | m4_define(`hm_arg_fdset_io',`Tvba(" $'`1="); Tvbfdset($'`2,$'`1);') |
80 | m4_define(`hm_arg_addr_out',`Tvba(" $'`1="); Tvbaddr($'`1,*$'`2);') |
81 | m4_define(`hm_arg_timeval_out_abs',` |
82 | if (!begin_set) { |
83 | Tvbf(" $'`1=%ld.%06ld",$'`1->tv_sec,$'`1->tv_usec); |
84 | begin= *$'`1; |
85 | begin_set= 1; |
86 | } else { |
87 | struct timeval diff; |
88 | diff.tv_sec= $'`1->tv_sec - begin.tv_sec; |
89 | diff.tv_usec= $'`1->tv_usec - begin.tv_usec; |
90 | if (diff.tv_usec < 0) { |
91 | diff.tv_sec -= 1; |
92 | diff.tv_usec += 1000000; |
93 | } |
94 | assert(diff.tv_sec >= 0); |
95 | assert(diff.tv_usec >= 0); |
96 | Tvbf(" $'`1=+%ld.%06ld",diff.tv_sec,diff.tv_usec); |
97 | }') |
98 | $3 |
99 | |
100 | hm_create_nothing |
101 | m4_define(`hm_arg_bytes_out',`Tvbbytes($'`2,r);') |
102 | $3 |
103 | |
104 | m4_define(`hm_rv_any',`x_error:') |
105 | m4_define(`hm_rv_fd',`x_error:') |
106 | m4_define(`hm_rv_succfail',`x_error:') |
107 | m4_define(`hm_rv_len',`x_error:') |
108 | m4_define(`hm_rv_must',`') |
109 | $2 |
110 | |
111 | R_vb(); |
112 | errno= e; |
113 | return r; |
114 | } |
115 | ') |
116 | |
117 | m4_include(`hsyscalls.i4') |