Commit 61b8eaf7 authored by Marek Vavruša's avatar Marek Vavruša

Merge branch 'tests_no_extra_records' into 'master'

Cleanup tests, no extra records required, bugfixes

Supported integration tests should now pass

See merge request !8
parents d7293994 14ed14b6
......@@ -6,6 +6,7 @@ env:
- PKG_CONFIG_PATH="${HOME}/fakeroot/lib/pkgconfig"
- LDFLAGS="-L${HOME}/fakeroot/lib"
- PIP_DOWNLOAD_CACHE="${HOME}/.pip-cache"
- CFLAGS="${CFLAGS} -DNDEBUG"
before_script:
- ./scripts/bootstrap-depends.sh ${HOME}/fakeroot
- pip install --user travis -r tests/pydnstest/requirements.txt
......
......@@ -29,7 +29,12 @@
#include "lib/cache.h"
#include "lib/defines.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[cache] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
#define db_api namedb_lmdb_api()
namedb_t *kr_cache_open(const char *handle, mm_ctx_t *mm, size_t maxsize)
......
......@@ -26,7 +26,11 @@
#include "lib/rplan.h"
#include "lib/utils.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[qiter] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
/* Iterator often walks through packet section, this is an abstraction. */
typedef int (*rr_callback_t)(const knot_rrset_t *, struct kr_layer_param *);
......@@ -63,7 +67,7 @@ static bool is_paired_to_query(const knot_pkt_t *answer, struct kr_query *query)
const knot_dname_t *qname = minimized_qname(query, &qtype);
return query->id == knot_wire_get_id(answer->wire) &&
query->sclass == knot_pkt_qclass(answer) &&
(query->sclass == KNOT_CLASS_ANY || query->sclass == knot_pkt_qclass(answer)) &&
qtype == knot_pkt_qtype(answer) &&
knot_dname_is_equal(qname, knot_pkt_qname(answer));
}
......
......@@ -24,7 +24,11 @@
#include "lib/layer/iterate.h"
#include "lib/utils.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[cache] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
typedef int (*rr_callback_t)(const knot_rrset_t *, unsigned, struct kr_layer_param *);
......
......@@ -19,7 +19,11 @@
#include "lib/layer/stats.h"
#include "lib/rplan.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[stats] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
//static void update_stats(struct kr_ns *ns, double rtt)
//{
......@@ -38,11 +42,11 @@ static int begin(knot_layer_t *ctx, void *param)
static int finish(knot_layer_t *ctx)
{
#ifndef NDEBUG
struct kr_layer_param *param = ctx->data;
struct kr_rplan *rplan = param->rplan;
const knot_pkt_t *answer = param->answer;
#ifndef NDEBUG
/* Calculate total RTT and number of queries. */
double total_rtt = 0.0;
size_t nr_queries = list_size(&rplan->resolved);
......
......@@ -29,7 +29,11 @@
#include "lib/layer/static.h"
#include "lib/layer/stats.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[reslv] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
/* Defines */
#define ITER_LIMIT 50
......
......@@ -25,7 +25,11 @@
#include "lib/cache.h"
#include "lib/utils.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[rplan] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
static struct kr_query *query_create(mm_ctx_t *pool, const knot_dname_t *name)
{
......
......@@ -23,7 +23,11 @@
#include "lib/utils.h"
#include "lib/rplan.h"
#ifndef NDEBUG
#define DEBUG_MSG(fmt, ...) fprintf(stderr, "[z-cut] " fmt, ## __VA_ARGS__)
#else
#define DEBUG_MSG(fmt, ...)
#endif
/* \brief Root hint descriptor. */
struct hint_info {
......
......@@ -19,6 +19,7 @@ class Entry:
self.adjust_fields = None
self.origin = '.'
self.message = dns.message.Message()
self.sections = []
def match_part(self, code, msg):
""" Compare scripted reply to given message using single criteria. """
......@@ -48,7 +49,7 @@ class Entry:
""" Compare scripted reply to given message based on match criteria. """
match_fields = self.match_fields
if 'all' in match_fields:
match_fields = ('flags', 'question', 'answer', 'authority', 'additional')
match_fields = tuple(['flags'] + self.sections)
for code in match_fields:
try:
self.match_part(code, msg)
......@@ -74,19 +75,25 @@ class Entry:
def set_reply(self, fields):
""" Set reply flags and rcode. """
eflags = []
flags = []
rcode = dns.rcode.from_text(self.default_rc)
for code in fields:
if code == 'DO':
eflags.append(code)
continue
try:
rcode = dns.rcode.from_text(code)
except:
flags.append(code)
self.message.flags = dns.flags.from_text(' '.join(flags))
self.message.ednsflags = dns.flags.edns_from_text(' '.join(eflags))
self.message.rcode = rcode
def begin_section(self, section):
""" Begin packet section. """
self.section = section
self.sections.append(section.lower())
def add_record(self, owner, args):
""" Add record to current packet section. """
......@@ -102,7 +109,6 @@ class Entry:
else:
raise Exception('bad section %s' % self.section)
def __rr_from_str(self, owner, args):
""" Parse RR from tokenized string. """
if not owner.endswith('.'):
......@@ -110,13 +116,13 @@ class Entry:
ttl = self.default_ttl
rdclass = self.default_cls
try:
dns.ttl.from_text(args[0])
ttl = args.pop(0)
ttl = dns.ttl.from_text(args[0])
args.pop(0)
except:
pass # optional
try:
dns.rdataclass.from_text(args[0])
rdclass = args.pop(0)
rdclass = dns.rdataclass.from_text(args[0])
args.pop(0)
except:
pass # optional
rdtype = args.pop(0)
......@@ -196,6 +202,8 @@ class Step:
""" Play one step from a scenario. """
if self.type == 'QUERY':
return self.__query(ctx)
elif self.type == 'CHECK_OUT_QUERY':
pass # Ignore
elif self.type == 'CHECK_ANSWER':
return self.__check_answer(ctx)
elif self.type == 'TIME_PASSES':
......@@ -231,7 +239,7 @@ class Step:
class Scenario:
def __init__(self, info):
""" Initialize scenario with description. """
print '# %s' % info
self.info = info
self.ranges = []
self.steps = []
self.current_step = None
......
......@@ -15,12 +15,13 @@ def get_next(file_in):
line = file_in.readline()
if len(line) == 0:
return False
for csep in (';', '#'):
if csep in line:
line = line[0 : line.index(csep)]
tokens = ' '.join(line.strip().split()).split()
if len(tokens) == 0:
continue # Skip empty lines
op = tokens.pop(0)
if op.startswith(';') or op.startswith('#'):
continue # Skip comments
return op, tokens
......@@ -87,7 +88,6 @@ def parse_scenario(op, args, file_in):
out.steps.append(parse_step(op, args, file_in))
return out
def parse_file(file_in):
""" Parse scenario from a file. """
try:
......@@ -106,7 +106,8 @@ def find_objects(path):
for e in os.listdir(path):
result += find_objects(os.path.join(path, e))
elif os.path.isfile(path):
result.append(path)
if path.endswith('.rpl'):
result.append(path)
return result
......
......@@ -111,10 +111,10 @@ SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. IN A 10.20.30.40
SECTION AUTHORITY
example.com. IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. IN A 1.2.3.4
;SECTION AUTHORITY
;example.com. IN NS ns.example.com.
;SECTION ADDITIONAL
;ns.example.com. IN A 1.2.3.4
ENTRY_END
SCENARIO_END
......@@ -112,10 +112,10 @@ SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. IN A 10.20.30.40
SECTION AUTHORITY
example.com. IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. IN A 1.2.3.4
;SECTION AUTHORITY
;example.com. IN NS ns.example.com.
;SECTION ADDITIONAL
;ns.example.com. IN A 1.2.3.4
ENTRY_END
SCENARIO_END
; config options
server:
target-fetch-policy: "0 0 0 0 0"
prefetch: "yes"
stub-zone:
name: "."
stub-addr: 193.0.14.129 # K.ROOT-SERVERS.NET.
CONFIG_END
SCENARIO_BEGIN Test resolver prefetch of almost expired data
; K.ROOT-SERVERS.NET.
RANGE_BEGIN 0 100
ADDRESS 193.0.14.129
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
. IN NS
SECTION ANSWER
. IN NS K.ROOT-SERVERS.NET.
SECTION ADDITIONAL
K.ROOT-SERVERS.NET. IN A 193.0.14.129
ENTRY_END
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION AUTHORITY
com. IN NS a.gtld-servers.net.
SECTION ADDITIONAL
a.gtld-servers.net. IN A 192.5.6.30
ENTRY_END
RANGE_END
; a.gtld-servers.net.
RANGE_BEGIN 0 100
ADDRESS 192.5.6.30
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
com. IN NS
SECTION ANSWER
com. IN NS a.gtld-servers.net.
SECTION ADDITIONAL
a.gtld-servers.net. IN A 192.5.6.30
ENTRY_END
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION AUTHORITY
example.com. IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. IN A 1.2.3.4
ENTRY_END
RANGE_END
; ns.example.com.
RANGE_BEGIN 0 40
ADDRESS 1.2.3.4
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
example.com. IN NS
SECTION ANSWER
example.com. IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. IN A 1.2.3.4
ENTRY_END
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 3600 IN A 10.20.30.40
SECTION AUTHORITY
example.com. 3600 IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. 3600 IN A 1.2.3.4
ENTRY_END
RANGE_END
; ns.example.com.
RANGE_BEGIN 50 100
ADDRESS 1.2.3.4
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
example.com. IN NS
SECTION ANSWER
example.com. IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. IN A 1.2.3.4
ENTRY_END
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 3600 IN A 10.20.30.40
SECTION AUTHORITY
example.com. 3600 IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. 3600 IN A 1.2.3.4
ENTRY_END
RANGE_END
STEP 1 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
www.example.com. IN A
ENTRY_END
; recursion happens here.
STEP 10 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 3600 IN A 10.20.30.40
SECTION AUTHORITY
example.com. 3600 IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. 3600 IN A 1.2.3.4
ENTRY_END
; after 1800 secs still the cached answer
STEP 20 TIME_PASSES ELAPSE 1800
STEP 30 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
www.example.com. IN A
ENTRY_END
; recursion happens here.
STEP 40 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 1800 IN A 10.20.30.40
SECTION AUTHORITY
example.com. 1800 IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. 1800 IN A 1.2.3.4
ENTRY_END
; after 1440 we are 360 seconds before the expiry
; (the authority changes behind the scenes to detect new lookup)
STEP 50 TIME_PASSES ELAPSE 1440
STEP 60 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
www.example.com. IN A
ENTRY_END
; recursion happens here.
STEP 70 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 360 IN A 10.20.30.40
SECTION AUTHORITY
example.com. 360 IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. 360 IN A 1.2.3.4
ENTRY_END
STEP 80 TRAFFIC
; let traffic flow for prefetch to happen
; above a cache reply with 10% of the original TTL
; but the actual cache is changed, try to get that
STEP 120 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
www.example.com. IN A
ENTRY_END
; recursion happens here.
STEP 130 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 3600 IN A 10.20.30.40
SECTION AUTHORITY
; NS rrset picked up from parent-NS (the child-NS timed out at now+prefetch)
example.com. 3600 IN NS ns.example.com.
SECTION ADDITIONAL
ns.example.com. 3600 IN A 1.2.3.4
ENTRY_END
SCENARIO_END
; config options
server:
target-fetch-policy: "0 0 0 0 0"
prefetch: "yes"
stub-zone:
name: "."
stub-addr: 193.0.14.129 # K.ROOT-SERVERS.NET.
CONFIG_END
SCENARIO_BEGIN Test resolver prefetch and a moved domain
; for bug #425.
; K.ROOT-SERVERS.NET.
RANGE_BEGIN 0 500
ADDRESS 193.0.14.129
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
. IN NS
SECTION ANSWER
. IN NS K.ROOT-SERVERS.NET.
SECTION ADDITIONAL
K.ROOT-SERVERS.NET. IN A 193.0.14.129
ENTRY_END
ENTRY_BEGIN
MATCH opcode subdomain
ADJUST copy_id copy_query
REPLY QR NOERROR
SECTION QUESTION
com. IN A
SECTION AUTHORITY
com. IN NS a.gtld-servers.net.
SECTION ADDITIONAL
a.gtld-servers.net. IN A 192.5.6.30
ENTRY_END
RANGE_END
; a.gtld-servers.net. (before sale of domain)
RANGE_BEGIN 0 30
ADDRESS 192.5.6.30
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
com. IN NS
SECTION ANSWER
com. IN NS a.gtld-servers.net.
SECTION ADDITIONAL
a.gtld-servers.net. IN A 192.5.6.30
ENTRY_END
ENTRY_BEGIN
MATCH opcode subdomain
ADJUST copy_id copy_query
REPLY QR NOERROR
SECTION QUESTION
example.com. IN A
SECTION AUTHORITY
example.com. 86400 IN NS old-ns.example.com.
SECTION ADDITIONAL
old-ns.example.com. 86400 IN A 192.168.0.1
ENTRY_END
RANGE_END
; a.gtld-servers.net. (after sale of domain)
RANGE_BEGIN 40 500
ADDRESS 192.5.6.30
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR NOERROR
SECTION QUESTION
com. IN NS
SECTION ANSWER
com. IN NS a.gtld-servers.net.
SECTION ADDITIONAL
a.gtld-servers.net. IN A 192.5.6.30
ENTRY_END
ENTRY_BEGIN
MATCH opcode subdomain
ADJUST copy_id copy_query
REPLY QR NOERROR
SECTION QUESTION
example.com. IN A
SECTION AUTHORITY
example.com. 86400 IN NS new-ns.example.com.
SECTION ADDITIONAL
new-ns.example.com. 86400 IN A 172.16.0.1
ENTRY_END
RANGE_END
; ns.example.com. first owner
RANGE_BEGIN 0 500
ADDRESS 192.168.0.1
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR AA NOERROR
SECTION QUESTION
example.com. IN NS
SECTION ANSWER
example.com. 86400 IN NS old-ns.example.com.
SECTION ADDITIONAL
old-ns.example.com. 86400 IN A 192.168.0.1
ENTRY_END
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR AA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 3600 IN A 10.1.1.1
SECTION AUTHORITY
example.com. 86400 IN NS old-ns.example.com.
SECTION ADDITIONAL
old-ns.example.com. 86400 IN A 192.168.0.1
ENTRY_END
RANGE_END
; ns.example.com. new owner
RANGE_BEGIN 0 500
ADDRESS 172.16.0.1
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR AA NOERROR
SECTION QUESTION
example.com. IN NS
SECTION ANSWER
example.com. 86400 IN NS new-ns.example.com.
SECTION ADDITIONAL
new-ns.example.com. 86400 IN A 172.16.0.1
ENTRY_END
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR AA NOERROR
SECTION QUESTION
old-ns.example.com. IN A
SECTION ANSWER
old-ns.example.com. 86400 IN A 172.16.0.1
SECTION AUTHORITY
example.com. 86400 IN NS new-ns.example.com.
SECTION ADDITIONAL
new-ns.example.com. 86400 IN A 172.16.0.1
ENTRY_END
ENTRY_BEGIN
MATCH opcode qtype qname
ADJUST copy_id
REPLY QR AA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 3600 IN A 10.2.2.2
SECTION AUTHORITY
example.com. 86400 IN NS new-ns.example.com.
SECTION ADDITIONAL
new-ns.example.com. 86400 IN A 172.16.0.1
ENTRY_END
RANGE_END
STEP 1 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
www.example.com. IN A
ENTRY_END
; recursion happens here.
STEP 10 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 3600 IN A 10.1.1.1
SECTION AUTHORITY
example.com. 86400 IN NS old-ns.example.com.
SECTION ADDITIONAL
old-ns.example.com. 86400 IN A 192.168.0.1
ENTRY_END
; after 1800 secs still the cached answer
STEP 20 TIME_PASSES ELAPSE 1800
STEP 30 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
www.example.com. IN A
ENTRY_END
; recursion happens here.
STEP 40 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 1800 IN A 10.1.1.1
SECTION AUTHORITY
example.com. 84600 IN NS old-ns.example.com.
SECTION ADDITIONAL
old-ns.example.com. 84600 IN A 192.168.0.1
ENTRY_END
; after 1440 we are 360 seconds before the expiry
; but it still contacts the old-ns
STEP 50 TIME_PASSES ELAPSE 1440
STEP 60 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
www.example.com. IN A
ENTRY_END
; recursion happens here.
STEP 70 CHECK_ANSWER
ENTRY_BEGIN
MATCH all ttl
REPLY QR RD RA NOERROR
SECTION QUESTION
www.example.com. IN A
SECTION ANSWER
www.example.com. 360 IN A 10.1.1.1
SECTION AUTHORITY
example.com. 83160 IN NS old-ns.example.com.