repevt_string(enum replay_event_type t)
{
switch(t) {
- case repevt_nothing: return "NOTHING";
- case repevt_front_query:return "QUERY";
- case repevt_front_reply:return "CHECK_ANSWER";
- case repevt_timeout: return "TIMEOUT";
- case repevt_back_reply: return "REPLY";
- case repevt_back_query: return "CHECK_OUT_QUERY";
- case repevt_error: return "ERROR";
- default: return "UNKNOWN";
+ case repevt_nothing: return "NOTHING";
+ case repevt_front_query: return "QUERY";
+ case repevt_front_reply: return "CHECK_ANSWER";
+ case repevt_timeout: return "TIMEOUT";
+ case repevt_back_reply: return "REPLY";
+ case repevt_back_query: return "CHECK_OUT_QUERY";
+ case repevt_error: return "ERROR";
+ default: return "UNKNOWN";
};
}
{
ldns_status status;
ldns_pkt* answer_pkt = NULL;
- log_assert(entry->reply_list);
+ log_assert(entry && entry->reply_list);
ldns_buffer_clear(buffer);
if(entry->reply_list->reply_from_hex) {
status = ldns_buffer2pkt_wire(&answer_pkt,
answer_pkt = ldns_pkt_clone(entry->reply_list->reply);
}
if(answer_pkt) {
- if(q)
- adjust_packet(entry, answer_pkt, q);
+ if(q) adjust_packet(entry, answer_pkt, q);
status = ldns_pkt2buffer_wire(buffer, answer_pkt);
if(status != LDNS_STATUS_OK)
fatal_exit("ldns: cannot pkt2buffer_wire parsed pkt");
/**
* Perform range entry on pending message.
- * @param runtime: runtime, needed?.
+ * @param runtime: runtime buffer size preference.
* @param entry: entry that codes for the reply to do.
* @param pend: pending query that is answered, callback called.
*/
tr = transport_udp;
if(find_match(runtime->now->match, ans->pkt, tr)) {
struct replay_answer *n = ans->next;
- log_info("testbound matched event %s entry %d",
- repevt_string(runtime->now->evt_type),
+ log_info("testbound matched event entry from line %d",
runtime->now->match->lineno);
log_info("testbound: do STEP %d %s",
runtime->now->time_step,
*prev = ans->next;
delete_replay_answer(ans);
ans = n;
+ return;
} else {
prev = &ans->next;
ans = ans->next;
}
}
+ log_info("testbound: do STEP %d %s", runtime->now->time_step,
+ repevt_string(runtime->now->evt_type));
+ fatal_exit("testbound: not matched");
}
/**
memset(&repinfo, 0, sizeof(repinfo));
repinfo.c = (struct comm_point*)calloc(1, sizeof(struct comm_point));
repinfo.addrlen = (socklen_t)sizeof(struct sockaddr_in);
+ repinfo.c->fd = -1;
repinfo.c->ev = (struct internal_event*)runtime;
repinfo.c->buffer = ldns_buffer_new(runtime->bufsize);
repinfo.c->type = comm_udp;
fill_buffer_with_reply(repinfo.c->buffer, todo->match, NULL);
- log_info("testbound: incoming QUERY (event from time %d)",
- todo->time_step);
+ log_info("testbound: incoming QUERY");
/* call the callback for incoming queries */
if((*runtime->callback_query)(repinfo.c, runtime->cb_arg,
NETEVENT_NOERROR, &repinfo)) {
if(!runtime->now)
runtime->now = runtime->scenario->mom_first;
else runtime->now = runtime->now->mom_next;
-
}
/**
log_info("testbound: do STEP %d %s", runtime->now->time_step,
repevt_string(runtime->now->evt_type));
switch(runtime->now->evt_type) {
- case repevt_nothing:
+ case repevt_nothing:
advance_moment(runtime);
break;
- case repevt_front_query:
+ case repevt_front_query:
+ /* advance moment before doing the step, so that the next
+ moment which may check some result of the mom step
+ can catch those results. */
mom = runtime->now;
advance_moment(runtime);
fake_front_query(runtime, mom);
break;
- case repevt_front_reply:
- log_err("No query answer or query answer did not match.");
+ case repevt_front_reply:
if(runtime->answer_list)
- log_err("There are unmatched answers.");
+ log_err("testbound: There are unmatched answers.");
fatal_exit("testbound: query answer not matched");
break;
- case repevt_timeout:
+ case repevt_timeout:
mom = runtime->now;
advance_moment(runtime);
fake_pending_callback(runtime, mom, NETEVENT_TIMEOUT);
break;
- case repevt_back_reply:
+ case repevt_back_reply:
mom = runtime->now;
advance_moment(runtime);
fake_pending_callback(runtime, mom, NETEVENT_NOERROR);
break;
- case repevt_back_query:
- log_err("Back queries are matched when they are sent out.");
- log_err("But no query matching the current moment was sent.");
+ case repevt_back_query:
+ /* Back queries are matched when they are sent out. */
+ log_err("No query matching the current moment was sent.");
fatal_exit("testbound: back query not matched");
break;
- case repevt_error:
+ case repevt_error:
mom = runtime->now;
advance_moment(runtime);
fake_pending_callback(runtime, mom, NETEVENT_CLOSED);
/* else if precoded_range matches pending, do it */
/* else do the current moment */
if(pending_matches_current(runtime, &entry, &pending)) {
- advance_moment(runtime);
- log_info("testbound: do STEP %d REPLY",
+ log_info("testbound: do STEP %d CHECK_OUT_QUERY",
runtime->now->time_step);
+ advance_moment(runtime);
if(entry->copy_id)
answer_callback_from_entry(runtime, entry,
pending);
fatal_exit("testbound: too many rounds, it loops.");
} while(runtime->now);
- log_info("testbound: exiting event loop (success).");
if(runtime->pending_list) {
fatal_exit("testbound: there are still messages pending.");
}
if(runtime->answer_list) {
fatal_exit("testbound: there are unmatched answers.");
}
+ log_info("testbound: exiting fake runloop.");
}
/*********** Dummy routines ***********/
struct listen_dnsport*
-listen_create(struct comm_base* base,
- int ATTR_UNUSED(num_ifs), const char* ATTR_UNUSED(ifs[]),
- const char* ATTR_UNUSED(port),
+listen_create(struct comm_base* base, int ATTR_UNUSED(num_ifs),
+ const char* ATTR_UNUSED(ifs[]), const char* ATTR_UNUSED(port),
int ATTR_UNUSED(do_ip4), int ATTR_UNUSED(do_ip6),
int ATTR_UNUSED(do_udp), int ATTR_UNUSED(do_tcp),
size_t bufsize, comm_point_callback_t* cb, void* cb_arg)
struct outside_network*
outside_network_create(struct comm_base* base, size_t bufsize,
- size_t ATTR_UNUSED(num_ports),
- const char** ATTR_UNUSED(ifs), int ATTR_UNUSED(num_ifs),
- int ATTR_UNUSED(do_ip4), int ATTR_UNUSED(do_ip6),
- int ATTR_UNUSED(port_base))
+ size_t ATTR_UNUSED(num_ports), const char** ATTR_UNUSED(ifs),
+ int ATTR_UNUSED(num_ifs), int ATTR_UNUSED(do_ip4),
+ int ATTR_UNUSED(do_ip6), int ATTR_UNUSED(port_base))
{
struct outside_network* outnet = calloc(1,
sizeof(struct outside_network));
ldns_status status;
log_assert(pend);
pend->buffer = ldns_buffer_new(ldns_buffer_capacity(packet));
+ log_assert(pend->buffer);
ldns_buffer_write(pend->buffer, ldns_buffer_begin(packet),
ldns_buffer_limit(packet));
ldns_buffer_flip(pend->buffer);
/* see if it matches the current moment */
if(runtime->now && runtime->now->evt_type == repevt_back_query &&
- find_match(runtime->now->match, pend->pkt, transport_udp)) {
+ find_match(runtime->now->match, pend->pkt, pend->transport)) {
log_info("testbound: matched pending to event. "
"advance time between events.");
log_info("testbound: do STEP %d %s", runtime->now->time_step,
repevt_string(runtime->now->evt_type));
advance_moment(runtime);
+ /* still create the pending, because we need it to callback */
}
log_info("testbound: created fake pending");
/* add to list */
len = (size_t)(np-p);
else len = strlen(p);
/* allocate and copy option */
- if(*pass_argc >= MAXARG-1) {
- /* printf because log_init is not yet called. */
- printf("too many arguments: '%s'\n", p);
- exit(1);
- }
+ if(*pass_argc >= MAXARG-1)
+ fatal_exit("too many arguments: '%s'", p);
pass_argv[*pass_argc] = (char*)malloc(len+1);
- if(!pass_argv[*pass_argc]) {
- printf("out of memory\n");
- exit(1);
- }
+ if(!pass_argv[*pass_argc])
+ fatal_exit("add_opts: out of memory");
memcpy(pass_argv[*pass_argc], p, len);
pass_argv[*pass_argc][len] = 0;
(*pass_argc)++;
echo_cmdline(int argc, char* argv[])
{
int i;
- printf("starting:");
+ printf("testbound is starting:");
for(i=0; i<argc; i++) {
printf(" [%s]", argv[i]);
}
fatal_exit("Could not read: %s", filename);
}
else fatal_exit("need a playback file (-p)");
- printf("Scenario: %s\n", scen->title);
+ log_info("Scenario: %s", scen->title);
return scen;
}
/**
- * Main unit test program. Setup, teardown and report errors.
+ * Main fake event test program. Setup, teardown and report errors.
* @param argc: arg count.
* @param argv: array of commandline arguments.
*/
char* init_optarg = optarg;
struct replay_scenario* scen = NULL;
- printf("Start of %s testbound program.\n", PACKAGE_STRING);
+ log_info("Start of %s testbound program.", PACKAGE_STRING);
/* determine commandline options for the daemon */
pass_argc = 1;
pass_argv[0] = "unbound";