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> |
70a778e5 |
27 | #include <stdlib.h> |
bb7ba677 |
28 | |
29 | #include "harness.h" |
30 | |
70a778e5 |
31 | static FILE *Toutputfile; |
32 | |
1e67a94f |
33 | /* fixme: record syscall durations, rather than gettimeofday results */ |
34 | |
98b6d5b4 |
35 | static void R_recordtime(void) { |
36 | int r; |
37 | struct timeval tv, tvrel; |
38 | |
39 | Tensureoutputfile(); |
40 | r= gettimeofday(&tv,0); if (r) Tfailed("gettimeofday syscallbegin"); |
41 | tvrel.tv_sec= tv.tv_sec - currenttime.tv_sec; |
42 | tvrel.tv_usec= tv.tv_usec - currenttime.tv_usec; |
43 | if (tv.tv_usec < 0) { tvrel.tv_usec += 1000000; tvrel.tv_sec--; } |
44 | Tvbf("\n +%ld.%06ld",(long)tvrel.tv_sec,(long)tvrel.tv_usec); |
45 | currenttime= tv; |
46 | } |
47 | |
70a778e5 |
48 | void Tensureoutputfile(void) { |
49 | const char *fdstr; |
98b6d5b4 |
50 | int fd, r; |
70a778e5 |
51 | |
98b6d5b4 |
52 | if (Toutputfile) return; |
53 | |
70a778e5 |
54 | Toutputfile= stdout; |
98b6d5b4 |
55 | fdstr= getenv("ADNS_TEST_OUT_FD"); |
56 | if (fdstr) { |
57 | fd= atoi(fdstr); |
58 | Toutputfile= fdopen(fd,"a"); if (!Toutputfile) Tfailed("fdopen ADNS_TEST_OUT_FD"); |
59 | } |
60 | |
61 | r= gettimeofday(¤ttime,0); if (r) Tfailed("gettimeofday syscallbegin"); |
62 | if (fprintf(Toutputfile," start %ld.%06ld\n", |
63 | (long)currenttime.tv_sec,(long)currenttime.tv_usec) == EOF) Toutputerr(); |
70a778e5 |
64 | } |
bb7ba677 |
65 | |
66 | void Q_vb(void) { |
67 | if (!adns__vbuf_append(&vb,"",1)) Tnomem(); |
68 | Tensureoutputfile(); |
69 | if (fprintf(Toutputfile," %s\n",vb.buf) == EOF) Toutputerr(); |
70 | if (fflush(Toutputfile)) Toutputerr(); |
71 | } |
72 | |
73 | static void R_vb(void) { |
74 | Q_vb(); |
75 | } |
98b6d5b4 |
76 | |
bb7ba677 |
77 | m4_define(`hm_syscall', ` |
78 | hm_create_proto_h |
79 | int H$1(hm_args_massage($3,void)) { |
80 | int r, e; |
81 | |
82 | hm_create_hqcall_vars |
83 | $3 |
84 | |
85 | hm_create_hqcall_init($1) |
86 | $3 |
87 | |
88 | hm_create_hqcall_args |
89 | Q$1(hm_args_massage($3)); |
90 | |
91 | hm_create_realcall_args |
92 | r= $1(hm_args_massage($3)); |
93 | e= errno; |
94 | |
95 | vb.used= 0; |
96 | Tvba("$1="); |
97 | m4_define(`hm_rv_any',` |
98 | if (r==-1) { Tvberrno(e); goto x_error; } |
99 | Tvbf("%d",r);') |
100 | m4_define(`hm_rv_fd',`hm_rv_any($'`1)') |
101 | m4_define(`hm_rv_succfail',` |
102 | if (r) { Tvberrno(e); goto x_error; } |
103 | Tvba("OK");') |
70a778e5 |
104 | m4_define(`hm_rv_must',`Tmust("$1","return",!r); Tvba("OK");') |
bb7ba677 |
105 | m4_define(`hm_rv_len',` |
106 | if (r==-1) { Tvberrno(e); goto x_error; } |
107 | Tmust("$1","return",r<=$'`1); |
70a778e5 |
108 | Tvba("OK");') |
bb7ba677 |
109 | $2 |
110 | |
111 | hm_create_nothing |
112 | m4_define(`hm_arg_fdset_io',`Tvba(" $'`1="); Tvbfdset($'`2,$'`1);') |
113 | m4_define(`hm_arg_addr_out',`Tvba(" $'`1="); Tvbaddr($'`1,*$'`2);') |
bb7ba677 |
114 | $3 |
115 | |
116 | hm_create_nothing |
117 | m4_define(`hm_arg_bytes_out',`Tvbbytes($'`2,r);') |
118 | $3 |
119 | |
120 | m4_define(`hm_rv_any',`x_error:') |
121 | m4_define(`hm_rv_fd',`x_error:') |
122 | m4_define(`hm_rv_succfail',`x_error:') |
123 | m4_define(`hm_rv_len',`x_error:') |
124 | m4_define(`hm_rv_must',`') |
125 | $2 |
126 | |
98b6d5b4 |
127 | R_recordtime(); |
bb7ba677 |
128 | R_vb(); |
129 | errno= e; |
130 | return r; |
131 | } |
132 | ') |
133 | |
134 | m4_include(`hsyscalls.i4') |