unbound 0.1
|
Store and use a replay of events for the DNS resolver. More...
#include "config.h"
#include <math.h>
#include "util/log.h"
#include "util/net_help.h"
#include "util/config_file.h"
#include "testcode/replay.h"
#include "testcode/ldns-testpkts.h"
#include "testcode/fake_event.h"
Defines | |
#define | MAX_LINE_LEN 10240 |
max length of lines in file | |
Functions | |
static char * | macro_expand (rbtree_t *store, struct replay_runtime *runtime, char **text) |
Expand a macro. | |
static int | timeval_smaller (const struct timeval *x, const struct timeval *y) |
compare of time values | |
static int | parse_keyword (char **line, const char *keyword) |
parse keyword in string. | |
static void | replay_moment_delete (struct replay_moment *mom) |
delete moment | |
static void | replay_range_delete (struct replay_range *rng) |
delete range | |
static void | strip_end_white (char *p) |
strip whitespace from end of string | |
static struct replay_range * | replay_range_read (char *remain, FILE *in, const char *name, int *lineno, char *line, uint32_t *ttl, ldns_rdf **or, ldns_rdf **prev) |
Read a range from file. | |
static void | read_file_content (FILE *in, int *lineno, struct replay_moment *mom) |
Read FILE match content. | |
static void | read_assign_step (char *remain, struct replay_moment *mom) |
read assign step info | |
static struct replay_moment * | replay_moment_read (char *remain, FILE *in, const char *name, int *lineno, uint32_t *ttl, ldns_rdf **or, ldns_rdf **prev) |
Read a replay moment 'STEP' from file. | |
static struct replay_scenario * | make_scenario (char *line) |
makes scenario with title on rest of line | |
struct replay_scenario * | replay_scenario_read (FILE *in, const char *name, int *lineno) |
Read a replay scenario from the file. | |
void | replay_scenario_delete (struct replay_scenario *scen) |
Delete scenario. | |
static struct fake_timer * | first_timer (struct replay_runtime *runtime) |
fetch oldest timer in list that is enabled | |
struct fake_timer * | replay_get_oldest_timer (struct replay_runtime *runtime) |
get oldest enabled fake timer | |
int | replay_var_compare (const void *a, const void *b) |
compare two replay_vars | |
rbtree_t * | macro_store_create (void) |
Create variable storage. | |
static void | del_macro (rbnode_t *x, void *arg) |
helper function to delete macro values | |
void | macro_store_delete (rbtree_t *store) |
Delete variable storage. | |
static size_t | macro_length (char *text) |
return length of macro | |
static int | do_buf_insert (char *buf, size_t remain, char *after, char *inserted) |
insert new stuff at start of buffer | |
static char * | do_macro_recursion (rbtree_t *store, struct replay_runtime *runtime, char *at, size_t remain) |
do macro recursion | |
static struct replay_var * | macro_getvar (rbtree_t *store, char *name) |
get var from store | |
static char * | do_macro_variable (rbtree_t *store, char *buf, size_t remain) |
do macro variable | |
static char * | do_macro_ctime (char *arg) |
do ctime macro on argument | |
static double | perform_arith (double x, char op, double y, double *res) |
perform arithmetic operator | |
static char * | do_macro_arith (char *orig, size_t remain, char **arithstart) |
do macro arithmetic on two numbers and operand | |
static char * | do_macro_range (char *buf) |
Do range macro on expanded buffer. | |
char * | macro_process (rbtree_t *store, struct replay_runtime *runtime, char *text) |
Apply macro substitution to string. | |
char * | macro_lookup (rbtree_t *store, char *name) |
Look up a macro value. | |
void | macro_print_debug (rbtree_t *store) |
Print macro variables stored as debug info. | |
int | macro_assign (rbtree_t *store, char *name, char *value) |
Set macro value. | |
void | testbound_selftest (void) |
testbounds self test |
Store and use a replay of events for the DNS resolver.
Used to test known scenarios to get known outcomes.
static char * macro_expand | ( | rbtree_t * | store, |
struct replay_runtime * | runtime, | ||
char ** | text | ||
) | [static] |
Expand a macro.
store,: | value storage |
runtime,: | replay runtime for other stuff. |
text,: | the macro text, after the ${, Updated to after the } when done (successfully). |
References do_macro_arith(), do_macro_ctime(), do_macro_range(), do_macro_recursion(), do_macro_variable(), first_timer(), macro_length(), replay_runtime::now_secs, and fake_timer::tv.
Referenced by do_macro_recursion(), and macro_process().
static int parse_keyword | ( | char ** | line, |
const char * | keyword | ||
) | [static] |
parse keyword in string.
line,: | if found, the line is advanced to after the keyword. |
keyword,: | string. |
Referenced by read_file_content(), replay_moment_read(), replay_range_read(), and replay_scenario_read().
static struct replay_range* replay_range_read | ( | char * | remain, |
FILE * | in, | ||
const char * | name, | ||
int * | lineno, | ||
char * | line, | ||
uint32_t * | ttl, | ||
ldns_rdf ** | or, | ||
ldns_rdf ** | prev | ||
) | [static, read] |
Read a range from file.
remain,: | Rest of line (after RANGE keyword). |
in,: | file to read from. |
name,: | name to print in errors. |
lineno,: | incremented as lines are read. |
line,: | line buffer. |
ttl,: | for readentry |
or,: | for readentry |
prev,: | for readentry |
References replay_range::addr, replay_range::addrlen, replay_range::end_step, extstrtoaddr(), fatal_exit(), log_err(), replay_range::match, MAX_LINE_LEN, entry::next, parse_keyword(), read_entry(), replay_range_delete(), replay_range::start_step, and strip_end_white().
Referenced by replay_scenario_read().
static struct replay_moment* replay_moment_read | ( | char * | remain, |
FILE * | in, | ||
const char * | name, | ||
int * | lineno, | ||
uint32_t * | ttl, | ||
ldns_rdf ** | or, | ||
ldns_rdf ** | prev | ||
) | [static, read] |
Read a replay moment 'STEP' from file.
remain,: | Rest of line (after STEP keyword). |
in,: | file to read from. |
name,: | name to print in errors. |
lineno,: | incremented as lines are read. |
ttl,: | for readentry |
or,: | for readentry |
prev,: | for readentry |
References replay_moment::addr, replay_moment::addrlen, replay_moment::autotrust_id, replay_moment::elapse, replay_moment::evt_type, extstrtoaddr(), fatal_exit(), log_err(), replay_moment::match, parse_keyword(), read_assign_step(), read_entry(), read_file_content(), replay_moment::repevt_assign, replay_moment::repevt_autotrust_check, replay_moment::repevt_back_query, replay_moment::repevt_back_reply, replay_moment::repevt_error, replay_moment::repevt_front_query, replay_moment::repevt_front_reply, replay_moment::repevt_infra_rtt, replay_moment::repevt_nothing, replay_moment::repevt_time_passes, replay_moment::repevt_timeout, replay_moment::repevt_traffic, replay_moment::string, and replay_moment::time_step.
Referenced by replay_scenario_read().
struct replay_scenario* replay_scenario_read | ( | FILE * | in, |
const char * | name, | ||
int * | lineno | ||
) | [read] |
Read a replay scenario from the file.
in,: | file to read from. |
name,: | name to print in errors. |
lineno,: | incremented for every line read. |
References fatal_exit(), log_info(), make_scenario(), MAX_LINE_LEN, replay_scenario::mom_first, replay_scenario::mom_last, replay_moment::mom_next, replay_range::next_range, parse_keyword(), replay_scenario::range_list, replay_moment_read(), replay_range_read(), replay_scenario_delete(), and replay_moment::time_step.
Referenced by setup_playback().
void replay_scenario_delete | ( | struct replay_scenario * | scen | ) |
Delete scenario.
scen,: | to delete. |
References replay_scenario::mom_first, replay_moment::mom_next, replay_range::next_range, replay_scenario::range_list, replay_moment_delete(), replay_range_delete(), and replay_scenario::title.
Referenced by fake_event_cleanup(), and replay_scenario_read().
rbtree_t* macro_store_create | ( | void | ) |
Create variable storage.
References rbtree_create(), and replay_var_compare().
Referenced by comm_base_create(), and testbound_selftest().
void macro_store_delete | ( | rbtree_t * | store | ) |
Delete variable storage.
store,: | the macro storage to free up. |
References del_macro(), and traverse_postorder().
Referenced by comm_base_delete(), and testbound_selftest().
char* macro_process | ( | rbtree_t * | store, |
struct replay_runtime * | runtime, | ||
char * | text | ||
) |
Apply macro substitution to string.
store,: | variable store. |
runtime,: | the runtime to look up values as needed. |
text,: | string to work on. |
References macro_expand(), and fake_timer::next.
Referenced by autotrust_check(), moment_assign(), testbound_selftest(), and time_passes().
char* macro_lookup | ( | rbtree_t * | store, |
char * | name | ||
) |
Look up a macro value.
Like calling ${$name}.
store,: | variable store |
name,: | macro name |
References macro_getvar(), and replay_var::value.
Referenced by testbound_selftest().
int macro_assign | ( | rbtree_t * | store, |
char * | name, | ||
char * | value | ||
) |
Set macro value.
store,: | variable store |
name,: | macro name |
value,: | text to set it to. Not expanded. |
References rbnode_t::key, macro_getvar(), replay_var::name, replay_var::node, rbtree_insert(), and replay_var::value.
Referenced by moment_assign(), and testbound_selftest().