]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Cache falloff test.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 27 Mar 2007 09:32:08 +0000 (09:32 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 27 Mar 2007 09:32:08 +0000 (09:32 +0000)
testbound can pass config options from replay file to unbound.

git-svn-id: file:///svn/unbound/trunk@199 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
testcode/replay.c
testcode/replay.h
testcode/testbound.c
testdata/fwd.rpl
testdata/fwd_cached.rpl
testdata/fwd_error.rpl
testdata/fwd_lrudrop.rpl [new file with mode: 0644]
testdata/fwd_notcached.rpl
testdata/fwd_timeout.rpl
testdata/fwd_two.rpl

index 5e67f645e1c0b415a833e89c67134f71fb3bbe7e..393fd2bcd15b67b2ee1021181c504ac1f1503370 100644 (file)
@@ -1,5 +1,8 @@
 27 March 2007: Wouter
        - added test for cache and not cached answers, in testbound replays.
+       - testbound can give config file and commandline options from the
+         replay file to unbound.
+       - created test that checks if items drop out of the cache.
 
 26 March 2007: Wouter
        - config settings for slab hash message cache.
index 264dd7bbdc3f558f3140db49ca9fef041ad6a24e..13be63d032d85c92d2b192d6f63c1b62a38f57e0 100644 (file)
@@ -234,11 +234,10 @@ make_scenario(char* line)
 }
 
 struct replay_scenario* 
-replay_scenario_read(FILE* in, const char* name)
+replay_scenario_read(FILE* in, const char* name, int* lineno)
 {
        char line[MAX_LINE_LEN];
        char *parse;
-       int lineno = 0;
        struct replay_scenario* scen = NULL;
        uint16_t ttl = 3600;
        ldns_rdf* or = NULL;
@@ -247,7 +246,7 @@ replay_scenario_read(FILE* in, const char* name)
 
        while(fgets(line, MAX_LINE_LEN-1, in)) {
                parse=line;
-               lineno++;
+               (*lineno)++;
                while(isspace(*parse))
                        parse++;
                if(!*parse) 
@@ -257,26 +256,26 @@ replay_scenario_read(FILE* in, const char* name)
                if(parse_keyword(&parse, "SCENARIO_BEGIN")) {
                        scen = make_scenario(parse);
                        if(!scen)
-                               fatal_exit("%d: could not make scen", lineno);
+                               fatal_exit("%d: could not make scen", *lineno);
                        continue;
                } 
                if(!scen)
-                       fatal_exit("%d: expected SCENARIO", lineno);
+                       fatal_exit("%d: expected SCENARIO", *lineno);
                if(parse_keyword(&parse, "RANGE_BEGIN")) {
                        struct replay_range* newr = replay_range_read(parse, 
-                               in, name, &lineno, line, &ttl, &or, &prev);
+                               in, name, lineno, line, &ttl, &or, &prev);
                        if(!newr)
-                               fatal_exit("%d: bad range", lineno);
+                               fatal_exit("%d: bad range", *lineno);
                        newr->next_range = scen->range_list;
                        scen->range_list = newr;
                } else if(parse_keyword(&parse, "STEP")) {
                        struct replay_moment* mom = replay_moment_read(parse, 
-                               in, name, &lineno, &ttl, &or, &prev);
+                               in, name, lineno, &ttl, &or, &prev);
                        if(!mom)
-                               fatal_exit("%d: bad moment", lineno);
+                               fatal_exit("%d: bad moment", *lineno);
                        if(scen->mom_last && 
                                scen->mom_last->time_step >= mom->time_step)
-                               fatal_exit("%d: time goes backwards", lineno);
+                               fatal_exit("%d: time goes backwards", *lineno);
                        if(scen->mom_last)
                                scen->mom_last->mom_next = mom;
                        else    scen->mom_first = mom;
index d0114eaf375674379e29db38733a8bd5baf32b1e..a873e5042e30dd76a1cedeeabf9758213eb256e2 100644 (file)
@@ -263,9 +263,11 @@ struct replay_answer {
  * Read a replay scenario from the file.
  * @param in: file to read from.
  * @param name: name to print in errors.
+ * @param lineno: incremented for every line read.
  * @return: Scenario. NULL if no scenario read.
  */
-struct replay_scenario* replay_scenario_read(FILE* in, const char* name);
+struct replay_scenario* replay_scenario_read(FILE* in, const char* name, 
+       int* lineno);
 
 /**
  * Delete scenario.
index b749c8874fe1521385547fd082ec0497207a0b47..67448f8e5678119b5ec4cfeda14603150cde0bb5 100644 (file)
@@ -51,6 +51,9 @@
 #include "daemon/unbound.c"
 #undef main
 
+/** maximum line length for lines in the replay file. */
+#define MAX_LINE_LEN 1024
+
 /** give commandline usage for testbound. */
 static void
 testbound_usage()
@@ -107,25 +110,66 @@ static void
 echo_cmdline(int argc, char* argv[])
 {
        int i;
-       printf("testbound is starting:");
+       fprintf(stderr, "testbound is starting:");
        for(i=0; i<argc; i++) {
-               printf(" [%s]", argv[i]);
+               fprintf(stderr, " [%s]", argv[i]);
+       }
+       fprintf(stderr, "\n");
+}
+
+/** process config elements */
+static void
+setup_config(FILE* in, char* configfile, int* lineno,
+       int* pass_argc, char* pass_argv[])
+{
+       char line[MAX_LINE_LEN];
+       char* parse;
+       FILE* cfg;
+       sprintf(configfile, "/tmp/testbound_cfg_%u.tmp", (unsigned)getpid());
+       add_opts("-c", pass_argc, pass_argv);
+       add_opts(configfile, pass_argc, pass_argv);
+       cfg = fopen(configfile, "w");
+       if(!cfg) fatal_exit("could not open %s: %s", 
+                       configfile, strerror(errno));
+       line[MAX_LINE_LEN-1] = 0;
+       while(fgets(line, MAX_LINE_LEN-1, in)) {
+               parse = line;
+               (*lineno)++;
+               while(isspace(*parse))
+                       parse++;
+               if(!*parse || parse[0] == ';')
+                       continue;
+               if(strncmp(parse, "COMMANDLINE", 11) == 0) {
+                       parse[strlen(parse)-1] = 0; /* strip off \n */
+                       add_opts(parse+11, pass_argc, pass_argv);
+                       continue;
+               }
+               if(strncmp(parse, "CONFIG_END", 10) == 0) {
+                       fclose(cfg);
+                       return;
+               }
+               fputs(line, cfg);
        }
-       printf("\n");
+       fatal_exit("No CONFIG_END in input file");
+
 }
 
 /** read playback file */
 static struct replay_scenario* 
-setup_playback(const char* filename)
+setup_playback(const char* filename, char* configfile,
+       int* pass_argc, char* pass_argv[])
 {
        struct replay_scenario* scen = NULL;
+       int lineno = 0;
+
        if(filename) {
                FILE *in = fopen(filename, "r");
                if(!in) {
                        perror(filename);
                        exit(1);
                }
-               scen = replay_scenario_read(in, filename);
+               setup_config(in, configfile, &lineno, pass_argc, pass_argv);
+               scen = replay_scenario_read(in, filename, &lineno);
                fclose(in);
                if(!scen)
                        fatal_exit("Could not read: %s", filename);
@@ -150,6 +194,7 @@ main(int argc, char* argv[])
        int init_optind = optind;
        char* init_optarg = optarg;
        struct replay_scenario* scen = NULL;
+       char cfgfile[128];
 
        log_init(NULL);
        log_info("Start of %s testbound program.", PACKAGE_STRING);
@@ -180,7 +225,7 @@ main(int argc, char* argv[])
        }
 
        /* setup test environment */
-       scen = setup_playback(playback_file);
+       scen = setup_playback(playback_file, cfgfile, &pass_argc, pass_argv);
        /* init fake event backend */
        fake_event_init(scen);
 
@@ -194,6 +239,7 @@ main(int argc, char* argv[])
        /* run the normal daemon */
        res = daemon_main(pass_argc, pass_argv);
 
+       unlink(cfgfile);
        fake_event_cleanup();
        for(c=1; c<pass_argc; c++)
                free(pass_argv[c]);
index 0f2b6848d333102a1a30c44cbfef217d68dc8c5d..a9c65df24299773d47d8dad95be23580f413fa87 100644 (file)
@@ -1,4 +1,6 @@
 ; This is a comment.
+; config options go here.
+CONFIG_END
 
 SCENARIO_BEGIN Sample of a valid query
 RANGE_BEGIN 0 100
index 8de5f9ea103460de8319504c4e73064cb1a258c3..4e07ed014157cde4a82204c455fe3dd1b6ab4af0 100644 (file)
@@ -1,4 +1,6 @@
 ; This is a comment.
+; config options go here.
+CONFIG_END
 
 SCENARIO_BEGIN Query receives answer from the cache
 
index f492cef3f9975a53c57c2d55d28e342f067a8d21..55f9e87fd30c9df041d5f7750d3b74198ff6a7f3 100644 (file)
@@ -1,3 +1,5 @@
+; config options go here.
+CONFIG_END
 SCENARIO_BEGIN Forwarder and an error happens on server query.
 STEP 1 QUERY
 ENTRY_BEGIN
diff --git a/testdata/fwd_lrudrop.rpl b/testdata/fwd_lrudrop.rpl
new file mode 100644 (file)
index 0000000..de393e6
--- /dev/null
@@ -0,0 +1,118 @@
+; This is a comment.
+; config options go here.
+; extremely small cache to force dropping old records.
+server:
+       msg-cache-size: 1 # one whole byte!
+       msg-cache-slabs: 1
+CONFIG_END
+
+SCENARIO_BEGIN Old answer is dropped from the cache
+
+STEP 1 QUERY
+ENTRY_BEGIN
+       SECTION QUESTION
+       www.example.com. IN A
+ENTRY_END
+; the query is sent to the forwarder - no cache yet.
+STEP 2 CHECK_OUT_QUERY
+ENTRY_BEGIN
+       MATCH qname qtype opcode
+       SECTION QUESTION
+       www.example.com. IN A
+ENTRY_END
+STEP 3 REPLY
+ENTRY_BEGIN
+       MATCH opcode qtype qname
+       ADJUST copy_id
+       REPLY QR RD RA NOERROR
+       SECTION QUESTION
+       www.example.com. IN A
+       SECTION ANSWER
+       www.example.com. IN A 10.20.30.40
+       SECTION AUTHORITY
+       www.example.com. IN NS ns.example.com.
+       SECTION ADDITIONAL
+       ns.example.com. IN A 10.20.30.50
+ENTRY_END
+STEP 4 CHECK_ANSWER
+ENTRY_BEGIN
+       MATCH opcode qname qtype
+       SECTION QUESTION
+       www.example.com. IN A
+       SECTION ANSWER
+       www.example.com. IN A 10.20.30.40
+ENTRY_END
+
+; another query to force the cache to drop the example.com entry.
+STEP 11 QUERY
+ENTRY_BEGIN
+       SECTION QUESTION
+       www.example.net. IN A
+ENTRY_END
+; the query is sent to the forwarder - no cache yet.
+STEP 12 CHECK_OUT_QUERY
+ENTRY_BEGIN
+       MATCH qname qtype opcode
+       SECTION QUESTION
+       www.example.net. IN A
+ENTRY_END
+STEP 13 REPLY
+ENTRY_BEGIN
+       MATCH opcode qtype qname
+       ADJUST copy_id
+       REPLY QR RD RA NOERROR
+       SECTION QUESTION
+       www.example.net. IN A
+       SECTION ANSWER
+       www.example.net. IN A 10.20.30.40
+       SECTION AUTHORITY
+       www.example.net. IN NS ns.example.net.
+       SECTION ADDITIONAL
+       ns.example.net. IN A 10.20.30.50
+ENTRY_END
+STEP 14 CHECK_ANSWER
+ENTRY_BEGIN
+       MATCH opcode qname qtype
+       SECTION QUESTION
+       www.example.net. IN A
+       SECTION ANSWER
+       www.example.net. IN A 10.20.30.40
+ENTRY_END
+
+
+; query, same as first, but it fell out of the cache.
+STEP 21 QUERY
+ENTRY_BEGIN
+       SECTION QUESTION
+       www.example.com. IN A
+ENTRY_END
+STEP 22 CHECK_OUT_QUERY
+ENTRY_BEGIN
+       MATCH qname qtype opcode
+       SECTION QUESTION
+       www.example.com. IN A
+ENTRY_END
+STEP 23 REPLY
+ENTRY_BEGIN
+       MATCH opcode qtype qname
+       ADJUST copy_id
+       REPLY QR RD RA NOERROR
+       SECTION QUESTION
+       www.example.com. IN A
+       SECTION ANSWER
+       www.example.com. IN A 10.20.30.40
+       SECTION AUTHORITY
+       www.example.com. IN NS ns.example.com.
+       SECTION ADDITIONAL
+       ns.example.com. IN A 10.20.30.50
+ENTRY_END
+STEP 24 CHECK_ANSWER
+ENTRY_BEGIN
+       MATCH opcode qname qtype
+       SECTION QUESTION
+       www.example.com. IN A
+       SECTION ANSWER
+       www.example.com. IN A 10.20.30.40
+ENTRY_END
+
+SCENARIO_END
index cf6a5a8c5decadee0713b7b88f399cb3298e0944..3c771448c4cc261c08013af53edb65df4c48ae86 100644 (file)
@@ -1,5 +1,12 @@
 ; This is a comment.
 
+; can set commandline options using something like this:
+; COMMANDLINE -v 
+; here config file options:
+server:
+       msg-cache-size: 1024
+CONFIG_END
+
 SCENARIO_BEGIN Query receives answer not from the cache
 
 STEP 1 QUERY
index 9ffd1287359091f423a7c3ce63777146f9d1f54a..27678c3de1ed6137cded5a5f6a2d67ec2451ba07 100644 (file)
@@ -1,3 +1,5 @@
+; config options go here.
+CONFIG_END
 SCENARIO_BEGIN Forwarder and a timeout happens on server query.
 STEP 1 QUERY
 ENTRY_BEGIN
index 530f388d2a71f9418ef54c72cfe9f3f8c563910a..fe7aaef72fe7c097eb6f8caafa51a5003535c3af 100644 (file)
@@ -1,3 +1,5 @@
+; config options go here.
+CONFIG_END
 SCENARIO_BEGIN Sample of a valid query
 
 ; query responses from authority servers.