Unit test work

git-svn-id: file:///svn/unbound/trunk@253 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-04-20 08:10:07 +00:00
parent 918858f9c9
commit 48db90e556
3 changed files with 21 additions and 15 deletions

View file

@ -1,3 +1,7 @@
20 April 2007: Wouter
- code comes through all of the unit tests now.
- disabled warning about spurious extra data.
19 April 2007: Wouter 19 April 2007: Wouter
- fix unit test to actually to tests. - fix unit test to actually to tests.
- fix write iov helper, and fakevent code. - fix write iov helper, and fakevent code.

View file

@ -48,6 +48,9 @@
#include "util/region-allocator.h" #include "util/region-allocator.h"
#include "util/net_help.h" #include "util/net_help.h"
/** verbose message parse unit test */
static int vbmp = 0;
/** skip whitespace */ /** skip whitespace */
static void static void
skip_whites(const char** p) skip_whites(const char** p)
@ -85,7 +88,7 @@ static void hex_to_buf(ldns_buffer* pkt, const char* hex)
skip_whites(&p); skip_whites(&p);
} }
ldns_buffer_flip(pkt); ldns_buffer_flip(pkt);
if(0) { if(vbmp) {
printf("packet size %u\n", (unsigned)ldns_buffer_limit(pkt)); printf("packet size %u\n", (unsigned)ldns_buffer_limit(pkt));
} }
} }
@ -178,14 +181,14 @@ test_buffers(ldns_buffer* pkt, ldns_buffer* out)
if(ldns_buffer_limit(pkt) == ldns_buffer_limit(out) && if(ldns_buffer_limit(pkt) == ldns_buffer_limit(out) &&
memcmp(ldns_buffer_begin(pkt), ldns_buffer_begin(out), memcmp(ldns_buffer_begin(pkt), ldns_buffer_begin(out),
ldns_buffer_limit(pkt)) == 0) { ldns_buffer_limit(pkt)) == 0) {
if(1) printf("binary the same (length=%u)\n", if(vbmp) printf("binary the same (length=%u)\n",
(unsigned)ldns_buffer_limit(pkt)); (unsigned)ldns_buffer_limit(pkt));
return 1; return 1;
} }
/* check if it 'means the same' */ /* check if it 'means the same' */
s1 = ldns_buffer2pkt_wire(&p1, pkt); s1 = ldns_buffer2pkt_wire(&p1, pkt);
s2 = ldns_buffer2pkt_wire(&p2, out); s2 = ldns_buffer2pkt_wire(&p2, out);
if(1) { if(vbmp) {
log_hex("orig in hex", ldns_buffer_begin(pkt), log_hex("orig in hex", ldns_buffer_begin(pkt),
ldns_buffer_limit(pkt)); ldns_buffer_limit(pkt));
log_hex("unbound out in hex", ldns_buffer_begin(out), log_hex("unbound out in hex", ldns_buffer_begin(out),
@ -219,7 +222,7 @@ checkformerr(ldns_buffer* pkt)
{ {
ldns_pkt* p; ldns_pkt* p;
ldns_status status = ldns_buffer2pkt_wire(&p, pkt); ldns_status status = ldns_buffer2pkt_wire(&p, pkt);
if(1) printf("formerr, ldns parse is: %s\n", if(vbmp) printf("formerr, ldns parse is: %s\n",
ldns_get_errorstr_by_id(status)); ldns_get_errorstr_by_id(status));
if(status == LDNS_STATUS_OK) { if(status == LDNS_STATUS_OK) {
printf("Formerr, but ldns gives packet:\n"); printf("Formerr, but ldns gives packet:\n");
@ -251,7 +254,7 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
flags = ntohs(flags); flags = ntohs(flags);
ret = reply_info_parse(pkt, alloc, &qi, &rep); ret = reply_info_parse(pkt, alloc, &qi, &rep);
if(ret != 0) { if(ret != 0) {
if(1) printf("parse code %d: %s\n", ret, if(vbmp) printf("parse code %d: %s\n", ret,
ldns_lookup_by_id(ldns_rcodes, ret)->name); ldns_lookup_by_id(ldns_rcodes, ret)->name);
if(ret == LDNS_RCODE_FORMERR) if(ret == LDNS_RCODE_FORMERR)
checkformerr(pkt); checkformerr(pkt);
@ -261,7 +264,7 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
timenow, region); timenow, region);
unit_assert(sz != 0); /* udp packets should fit in 1024 iov */ unit_assert(sz != 0); /* udp packets should fit in 1024 iov */
write_iov_buffer(out, iov, sz); write_iov_buffer(out, iov, sz);
printf("iov len outlen %u %u\n", (unsigned)sz, if(vbmp) printf("iov len outlen %u %u\n", (unsigned)sz,
(unsigned)ldns_buffer_limit(out)); (unsigned)ldns_buffer_limit(out));
test_buffers(pkt, out); test_buffers(pkt, out);
} }
@ -339,7 +342,7 @@ testfromfile(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
continue; continue;
if(strlen(buf) < 10) /* skip pcat line numbers. */ if(strlen(buf) < 10) /* skip pcat line numbers. */
continue; continue;
if(0) { if(vbmp) {
printf("test no %d: %s", no, buf); printf("test no %d: %s", no, buf);
fflush(stdout); fflush(stdout);
} }
@ -366,7 +369,7 @@ testfromdrillfile(ldns_buffer* pkt, struct alloc_cache* alloc,
continue; continue;
np = &np[strlen(np)]; np = &np[strlen(np)];
} }
if(0) { if(vbmp) {
printf("test %s", buf); printf("test %s", buf);
fflush(stdout); fflush(stdout);
} }
@ -385,10 +388,10 @@ void msgparse_test()
printf("testmsgparse\n"); printf("testmsgparse\n");
simpletest(pkt, &alloc, out); simpletest(pkt, &alloc, out);
testfromfile(pkt, &alloc, out, "testdata/test_packets.1");
testfromfile(pkt, &alloc, out, "testdata/test_packets.2");
testfromfile(pkt, &alloc, out, "testdata/test_packets.3");
if(0) testfromdrillfile(pkt, &alloc, out, "blabla"); if(0) testfromdrillfile(pkt, &alloc, out, "blabla");
if(0) testfromfile(pkt, &alloc, out, "testdata/test_packets.1");
if(0) testfromfile(pkt, &alloc, out, "testdata/test_packets.2");
if(0) testfromfile(pkt, &alloc, out, "testdata/test_packets.3");
/* cleanup */ /* cleanup */
alloc_clear(&alloc); alloc_clear(&alloc);

View file

@ -486,10 +486,9 @@ parse_packet(ldns_buffer* pkt, struct msg_parse* msg, region_type* region)
if((ret = parse_section(pkt, msg, region, LDNS_SECTION_ADDITIONAL, if((ret = parse_section(pkt, msg, region, LDNS_SECTION_ADDITIONAL,
msg->arcount, &msg->ar_rrsets)) != 0) msg->arcount, &msg->ar_rrsets)) != 0)
return ret; return ret;
if(ldns_buffer_remaining(pkt) > 0) { /* if(ldns_buffer_remaining(pkt) > 0) { */
/* spurious data at end of packet. ignore */ /* there is spurious data at end of packet. ignore */
verbose(VERB_DETAIL, "spurious data at end of packet ignored"); /* } */
}
msg->rrset_count = msg->an_rrsets + msg->ns_rrsets + msg->ar_rrsets; msg->rrset_count = msg->an_rrsets + msg->ns_rrsets + msg->ar_rrsets;
return 0; return 0;
} }