- TRAFFIC keyword for testbound. Simplifies test generation.

${range lower val upper} to check probe timeout values.
- test with 5011-prepublish rollover and revocation.
- fix revocation of RR for autotrust, stray exclamation mark.


git-svn-id: file:///svn/unbound/trunk@1804 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards
2009-09-02 13:11:52 +00:00
parent c7bea9d33a
commit 8e2ef1caeb
13 changed files with 430 additions and 35 deletions
+6 -2
View File
@@ -133,6 +133,7 @@ repevt_string(enum replay_event_type t)
case repevt_autotrust_check: return "CHECK_AUTOTRUST";
case repevt_error: return "ERROR";
case repevt_assign: return "ASSIGN";
case repevt_traffic: return "TRAFFIC";
default: return "UNKNOWN";
}
}
@@ -512,7 +513,7 @@ autotrust_check(struct replay_runtime* runtime, struct replay_moment* mom)
expanded = macro_process(runtime->vars, runtime, p->str);
if(!expanded)
fatal_exit("could not expand macro line %d", lineno);
if(verbosity >= VERB_ALGO && strcmp(p->str, expanded) != 0)
if(verbosity >= 7 && strcmp(p->str, expanded) != 0)
log_info("expanded '%s' to '%s'", p->str, expanded);
if(strcmp(expanded, line) != 0) {
log_err("mismatch in file %s, line %d", name, lineno);
@@ -614,6 +615,9 @@ do_moment_and_advance(struct replay_runtime* runtime)
moment_assign(runtime, runtime->now);
advance_moment(runtime);
break;
case repevt_traffic:
advance_moment(runtime);
break;
default:
fatal_exit("testbound: unknown event type %d",
runtime->now->evt_type);
@@ -626,7 +630,7 @@ run_scenario(struct replay_runtime* runtime)
{
struct entry* entry = NULL;
struct fake_pending* pending = NULL;
int max_rounds = 50;
int max_rounds = 5000;
int rounds = 0;
runtime->now = runtime->scenario->mom_first;
log_info("testbound: entering fake runloop");
+48 -4
View File
@@ -322,6 +322,8 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
read_file_content(in, lineno, mom);
} else if(parse_keyword(&remain, "ERROR")) {
mom->evt_type = repevt_error;
} else if(parse_keyword(&remain, "TRAFFIC")) {
mom->evt_type = repevt_traffic;
} else if(parse_keyword(&remain, "ASSIGN")) {
mom->evt_type = repevt_assign;
read_assign_step(remain, mom);
@@ -681,28 +683,34 @@ perform_arith(double x, char op, double y, double* res)
/** do macro arithmetic on two numbers and operand */
static char*
do_macro_arith(char* at, size_t remain, char** arithstart)
do_macro_arith(char* orig, size_t remain, char** arithstart)
{
double x, y, result;
char operator;
int skip;
char buf[32];
char* at;
/* not yet done? we want number operand number expanded first. */
if(!*arithstart) {
/* remember start pos of expr, skip the first number */
at = orig;
*arithstart = at;
while(*at && (isdigit((int)*at) || *at == '.'))
at++;
return at;
}
/* move back to start */
remain += (size_t)(at - *arithstart);
remain += (size_t)(orig - *arithstart);
at = *arithstart;
/* parse operands */
if(sscanf(at, " %lf %c %lf%n", &x, &operator, &y, &skip) != 3) {
log_err("cannot parse arithmetic: %s", at);
return NULL;
*arithstart = NULL;
return do_macro_arith(orig, remain, arithstart);
}
if(isdigit((int)operator)) {
*arithstart = orig;
return at+skip; /* do nothing, but setup for later number */
}
/* calculate result */
@@ -721,6 +729,24 @@ do_macro_arith(char* at, size_t remain, char** arithstart)
return at;
}
/** Do range macro on expanded buffer */
static char*
do_macro_range(char* buf)
{
double x, y, z;
if(sscanf(buf, " %lf %lf %lf", &x, &y, &z) != 3) {
log_err("range func requires 3 args: %s", buf);
return NULL;
}
if(x <= y && y <= z) {
char res[1024];
snprintf(res, sizeof(res), "%.24g", y);
return strdup(res);
}
fatal_exit("value %.24g not in range [%.24g, %.24g]", y, x, z);
return NULL;
}
static char*
macro_expand(rbtree_t* store, struct replay_runtime* runtime, char** text)
{
@@ -752,6 +778,10 @@ macro_expand(rbtree_t* store, struct replay_runtime* runtime, char** text)
strncmp(buf, "ctime\t", 6) == 0) {
at += 6;
dofunc = 1;
} else if(strncmp(buf, "range ", 6) == 0 ||
strncmp(buf, "range\t", 6) == 0) {
at += 6;
dofunc = 1;
}
/* actual macro text expansion */
@@ -778,6 +808,8 @@ macro_expand(rbtree_t* store, struct replay_runtime* runtime, char** text)
/* post process functions, buf has the argument(s) */
if(strncmp(buf, "ctime", 5) == 0) {
return do_macro_ctime(buf+6);
} else if(strncmp(buf, "range", 5) == 0) {
return do_macro_range(buf+6);
}
}
return strdup(buf);
@@ -949,5 +981,17 @@ void testbound_selftest(void)
log_assert( v && strcmp(v, "108") == 0);
free(v);
v = macro_process(store, NULL, "${1 2 33 2 1}");
log_assert( v && strcmp(v, "1 2 33 2 1") == 0);
free(v);
v = macro_process(store, NULL, "${123 3 + 5}");
log_assert( v && strcmp(v, "123 8") == 0);
free(v);
v = macro_process(store, NULL, "${123 glug 3 + 5}");
log_assert( v && strcmp(v, "123 glug 8") == 0);
free(v);
macro_store_delete(store);
}
+15 -5
View File
@@ -70,6 +70,9 @@
* o TIME_PASSES ELAPSE [seconds] - increase 'now' time counter, can be
* a floating point number.
* TIME_PASSES EVAL [macro] - expanded for seconds to move time.
* o TRAFFIC - like CHECK_ANSWER, causes traffic to flow.
* actually the traffic flows before this step is taken.
* the step waits for traffic to stop.
* o CHECK_AUTOTRUST [id] - followed by FILE_BEGIN [to match] FILE_END.
* The file contents is macro expanded before match.
* o ERROR
@@ -83,11 +86,16 @@
* ${..} is macro expanded from its expression. Text substitution.
* o $var replaced with its value. var is identifier [azAZ09_]*
* o number is that number.
* o ${variables and arithmetic }
* o +, -, / and *. Note, evaluated left-to-right. Use ${} for brackets.
* o ${time} is the current time.
* o ${ctime value} is the text ctime(value), i.e. Fri 3 Aug 2009, ...
* must have one space after 'ctime'.
* o ${timeout} is the time until next timeout in the comm_timer list.
* So again, no precedence rules, so 2+3*4 === ${2+3}*4 === 20.
* Do 2+${3*4} to get 24.
* o ${function params}
* o ${time} is the current time for the simulated unbound.
* o ${ctime value} is the text ctime(value), Fri 3 Aug 2009, ...
* o ${timeout} is the time until next timeout in comm_timer list.
* o ${range lower value upper} checks if lower<=value<=upper
* returns value if check succeeds.
*
* ; Example file
* SCENARIO_BEGIN Example scenario
@@ -187,7 +195,9 @@ struct replay_moment {
/** an error happens to outbound query */
repevt_error,
/** assignment to a variable */
repevt_assign
repevt_assign,
/** cause traffic to flow */
repevt_traffic
}
/** variable with what is to happen this moment */
evt_type;