m4_dnl (part of complex test harness, not of the library)
m4_dnl - playback routines
-m4_dnl This file is part of adns, which is
-m4_dnl Copyright (C) 1997-2000,2003,2006,2014-2016,2020 Ian Jackson
-m4_dnl Copyright (C) 2014 Mark Wooding
-m4_dnl Copyright (C) 1999-2000,2003,2006 Tony Finch
-m4_dnl Copyright (C) 1991 Massachusetts Institute of Technology
-m4_dnl (See the file INSTALL for full details.)
+m4_dnl This file is part of adns, which is Copyright Ian Jackson
+m4_dnl and contributors (see the file INSTALL for full details).
m4_dnl
m4_dnl This program is free software; you can redistribute it and/or modify
m4_dnl it under the terms of the GNU General Public License as published by
static FILE *Tinputfile, *Tfuzzrawfile, *Treportfile;
static vbuf vb2;
-static void Tensurereportfile(void) {
+static void Tensure_reportfile(void) {
const char *fdstr;
int fd;
Treportfile= fdopen(fd,"a"); if (!Treportfile) Tfailed("fdopen ADNS_TEST_REPORT_FD");
}
-static void Tensurefuzzrawfile(void) {
+static void Tensure_fuzzrawfile(void) {
static int done;
if (done) return;
if (!Tfuzzrawfile) Tfailed("fdopen ADNS_TEST_FUZZRAW_DUMP_FD");
}
-static void FR_write(void *p, size_t sz) {
+static void FR_write(const void *p, size_t sz) {
if (!Tfuzzrawfile) return;
ssize_t got = fwrite(p,1,sz,Tfuzzrawfile);
if (ferror(Tfuzzrawfile)) Tfailed("write fuzzraw output file");
FR_WRITE(delta);
}
-void Tensurerecordfile(void) {
+void Tensuresetup(void) {
int fd;
int chars;
unsigned long sec, usec;
+ Tensure_reportfile();
+ Tensure_fuzzrawfile();
+
if (Tinputfile) return;
Tinputfile= stdin;
fd = Ttestinputfd();
static void P_updatetime(void) {
int chars;
- unsigned long sec, usec;
+ unsigned long sec;
+ long usec;
if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
chars= -1;
- sscanf(vb2.buf," +%lu.%lu%n",&sec,&usec,&chars);
+ sscanf(vb2.buf," +%lu.%ld%n",&sec,&usec,&chars);
if (chars==-1) Psyntax("update time invalid");
currenttime.tv_sec+= sec;
- currenttime.tv_usec+= usec;
- if (currenttime.tv_usec > 1000000) {
+ usec = (long)currenttime.tv_usec + usec;
+ while (usec < 0) {
+ currenttime.tv_sec--;
+ usec += 1000000;
+ }
+ while (usec > 1000000) {
currenttime.tv_sec++;
- currenttime.tv_usec -= 1000000;
+ usec -= 1000000;
}
+ currenttime.tv_usec = usec;
if (vb2.buf[chars] != hm_squote\nhm_squote) Psyntax("not newline after update time");
}
if (vb2.buf[vb2.used++] != hm_squote[hm_squote) Psyntax("fd set start not [");
FD_ZERO(set);
- if (vb2.buf[vb2.used] == hm_squote]hm_squote) { vb2.used++; return; }
- for (;;) {
- ul= strtoul(vb2.buf+vb2.used,&ep,10);
- if (ul>=max) Psyntax("fd set member > max");
- if (ep == (char*)vb2.buf+vb2.used) Psyntax("empty entry in fd set");
- FD_SET(ul,set);
- vb2.used= ep - (char*)vb2.buf;
- c= vb2.buf[vb2.used++];
- if (c == hm_squote]hm_squote) break;
- if (c != hm_squote,hm_squote) Psyntax("fd set separator not ,");
+ if (vb2.buf[vb2.used] == hm_squote]hm_squote) {
+ vb2.used++;
+ } else {
+ for (;;) {
+ ul= strtoul(vb2.buf+vb2.used,&ep,10);
+ if (ul>=max) Psyntax("fd set member > max");
+ if (ep == (char*)vb2.buf+vb2.used) Psyntax("empty entry in fd set");
+ FD_SET(ul,set);
+ vb2.used= ep - (char*)vb2.buf;
+ c= vb2.buf[vb2.used++];
+ if (c == hm_squote]hm_squote) break;
+ if (c != hm_squote,hm_squote) Psyntax("fd set separator not ,");
+ }
}
uint16_t accum;
if (vb2.buf[vb2.used++] != hm_squote[hm_squote) Psyntax("pollfds start not [");
for (i=0; i<nfds; i++) {
Pstring("{fd=","{fd= in pollfds");
- fds->fd= strtoul(vb2.buf+vb2.used,&ep,10);
+ int gotfd= strtoul(vb2.buf+vb2.used,&ep,10);
+ if (gotfd != fds->fd) Psyntax("poll fds[].fd changed");
vb2.used= ep - (char*)vb2.buf;
Pstring(", events=",", events= in pollfds");
- fds->events= Ppollfdevents();
+ int gotevents= Ppollfdevents();
+ if (gotevents != fds->events) Psyntax("poll fds[].events changed");
Pstring(", revents=",", revents= in pollfds");
fds->revents= Ppollfdevents();
+ if (gotevents) FR_WRITE(fds->revents);
Pstring("}","} in pollfds");
Pstring(comma,"separator in pollfds");
comma= ", ";
if (*ep && *ep != ' ') Psyntax("invalid port (bad syntax)");
if (ul >= 65536) Psyntax("port too large");
+ if (Tfuzzrawfile) {
+ int tl = strlen(p);
+ FR_WRITE(tl);
+ FR_write(p,tl);
+ uint16_t port16 = ul;
+ FR_WRITE(port16);
+ }
+
a.len= sizeof(a.addr);
err= adns_text2addr(p, (int)ul, 0, &a.addr.sa,&a.len);
if (err) Psyntax("invalid address");
void Q_vb(void) {
const char *nl;
- Tensurerecordfile();
+ Tensuresetup();
if (!adns__vbuf_ensure(&vb2,vb.used+2)) Tnomem();
fread(vb2.buf,1,vb.used+2,Tinputfile);
if (feof(Tinputfile)) {
vb.used,vb.buf, vb.used,vb2.buf+1);
exit(1);
}
- Tensurereportfile();
nl= memchr(vb.buf,'\n',vb.used);
fprintf(Treportfile," %.*s\n", (int)(nl ? nl - (const char*)vb.buf : vb.used), vb.buf);
}
if (!adns__vbuf_ensure(&vb2,1000)) Tnomem();
fgets(vb2.buf,vb2.avail,Tinputfile); Pcheckinput();
- Tensurereportfile();
- Tensurefuzzrawfile();
+ Tensuresetup();
fprintf(Treportfile,"%s",vb2.buf);
amtread= strlen(vb2.buf);
if (amtread<=0 || vb2.buf[--amtread]!=hm_squote\nhm_squote)
vb2.buf[amtread]= 0;
if (memcmp(vb2.buf," $1=",hm_r_offset)) Psyntax("syscall reply mismatch");
+#ifdef FUZZRAW_SYNC
+ hm_fr_syscall_ident($1)
+ FR_WRITE(sync_expect);
+#endif
+
m4_define(`hm_rv_check_errno',`
if (vb2.buf[hm_r_offset] == hm_squoteEhm_squote) {
int e;