Commit 44aae046 authored by Bob Halley's avatar Bob Halley

basic test support

parent 754ae02c
......@@ -13,3 +13,4 @@ master_test
rbt_test
db_test
compress_test
t_journal
......@@ -30,6 +30,7 @@ LIBS = ../../lib/dns/libdns.a \
../../lib/isc/libisc.a \
@LIBS@
SUBDIRS = master names rbt
TARGETS = lex_test \
name_test \
sock_test \
......@@ -87,3 +88,4 @@ compress_test: compress_test.o ../../lib/isc/libisc.a ../../lib/dns/libdns.a
clean distclean::
rm -f ${TARGETS}
rm -f t_journal
# Copyright (C) 1999 Internet Software Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
CINCLUDES = -I${srcdir}/../../../lib/isc/unix/include \
-I${srcdir}/../../../lib/isc/pthreads/include \
-I${srcdir}/../../../lib/isc/include \
-I${srcdir}/../../../lib/dns/include \
-I${srcdir}/../../../lib/tests/include
CDEFINES =
CWARNINGS =
LIBS = ../../../lib/dns/libdns.a \
../../../lib/isc/libisc.a \
../../../lib/tests/libt_api.a \
@LIBS@
TARGETS = t_master
@BIND9_MAKE_RULES@
t_master: t_master.o
${CC} -o $@ t_master.o ${LIBS}
test:
-@ ./t_master -c @top_srcdir@/t_config -a >> ../t_journal 2>&1
testhelp:
@./t_master -h
clean distclean::
rm -f ${TARGETS}
#
# test data for dns_master_load test 1
#
# format is:
# <masterfile name><tab><origin><tab><expected result>
# where
# masterfile name is the name of a file containing master data
# origin is the origin
# expected_result is a text representation of a dns_result_t
#
master1.data test DNS_R_SUCCESS
#
# test data for dns_master_load test 1
#
# format is:
# <masterfile name><tab><origin><tab><expected result>
# where
# masterfile name is the name of a file containing master data
# origin is the origin
# expected_result is a text representation of a dns_result_t
#
master2.data test DNS_R_UNEXPECTEDEND
#
# test data for dns_master_load test 1
#
# format is:
# <masterfile name><tab><origin><tab><expected result>
# where
# masterfile name is the name of a file containing master data
# origin is the origin
# expected_result is a text representation of a dns_result_t
#
master3.data test DNS_R_NOOWNER
#
# test data for dns_master_load test 1
#
# format is:
# <masterfile name><tab><origin><tab><expected result>
# where
# masterfile name is the name of a file containing master data
# origin is the origin
# expected_result is a text representation of a dns_result_t
#
master4.data test DNS_R_NOTTL
#
# test data for dns_master_load test 5
#
# format is:
# <masterfile name><tab><origin><tab><expected result>
# where
# masterfile name is the name of a file containing master data
# origin is the origin
# expected_result is a text representation of a dns_result_t
#
master5.data test DNS_R_BADCLASS
$TTL 1000
@ in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
a in ns ns.vix.com.
a in ns ns2vix.com.
a in ns ns3vix.com.
b in a 1.2.3.4
$TTL 1000
@ in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
a in ns
a in ns ns2vix.com.
a in ns ns3vix.com.
b in a 1.2.3.4
$TTL 1000
in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
in ns ns.vix.com
in ns ns2vix.com.
a in ns ns3vix.com.
b in a 1.2.3.4
@ in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
a in ns ns.vix.com.
a in ns ns2vix.com.
a in ns ns3vix.com.
b in a 1.2.3.4
$TTL 1000
@ in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
a any ns ns.vix.com.
a in ns ns2vix.com.
a in ns ns3vix.com.
b in a 1.2.3.4
/*
* Copyright (C) 1998, 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <isc/mem.h>
#include <isc/buffer.h>
#include <isc/error.h>
#include <dns/master.h>
#include <dns/name.h>
#include <dns/rdataset.h>
#include <dns/result.h>
#include <dns/types.h>
#include <tests/t_api.h>
#define BUFLEN 255
#define BIGBUFLEN (64 * 1024)
static dns_result_t t1_commit_callback(dns_rdatacallbacks_t *callbacks,
dns_name_t *owner, dns_rdataset_t *dataset);
static void t1(void);
isc_mem_t *T1_mctx;
char *Tokens[T_MAXTOKS + 1];
static dns_result_t
t1_commit_callback(dns_rdatacallbacks_t *callbacks, dns_name_t *owner,
dns_rdataset_t *dataset) {
char buf[BIGBUFLEN];
isc_buffer_t target;
dns_result_t result;
callbacks = callbacks; /*unused*/
isc_buffer_init(&target, buf, BIGBUFLEN, ISC_BUFFERTYPE_TEXT);
result = dns_rdataset_totext(dataset, owner, ISC_FALSE, ISC_FALSE,
&target);
if (result != DNS_R_SUCCESS)
t_info("dns_rdataset_totext: %s\n", dns_result_totext(result));
return(result);
}
static int
test_master(char *testfile, char *origin, dns_result_t exp_result) {
int result;
int len;
isc_result_t isc_result;
dns_result_t dns_result;
dns_name_t dns_origin;
isc_buffer_t source;
isc_buffer_t target;
unsigned char name_buf[BUFLEN];
int soacount;
int nscount;
dns_rdatacallbacks_t callbacks;
result = T_UNRESOLVED;
if (T1_mctx == NULL)
isc_result = isc_mem_create(0, 0, &T1_mctx);
else
isc_result = ISC_R_SUCCESS;
if (isc_result == ISC_R_SUCCESS) {
len = strlen(origin);
isc_buffer_init(&source, origin, len,
ISC_BUFFERTYPE_TEXT);
isc_buffer_add(&source, len);
isc_buffer_setactive(&source, len);
isc_buffer_init(&target, name_buf, BUFLEN, ISC_BUFFERTYPE_BINARY);
dns_name_init(&dns_origin, NULL);
dns_result = dns_name_fromtext(&dns_origin, &source, dns_rootname,
ISC_FALSE, &target);
if (dns_result == DNS_R_SUCCESS) {
dns_rdatacallbacks_init(&callbacks);
callbacks.commit = t1_commit_callback;
dns_result = dns_master_load( testfile,
&dns_origin,
&dns_origin,
1,
&soacount,
&nscount,
&callbacks,
T1_mctx);
if (dns_result == exp_result)
result = T_PASS;
else {
t_info("dns_master_load: got %s, expected %s\n",
dns_result_totext(dns_result),
dns_result_totext(exp_result));
result = T_FAIL;
}
}
else {
t_info("dns_name_fromtext failed %s\n",
dns_result_totext(dns_result));
}
}
else {
t_info("isc_mem_create failed %d\n", isc_result);
}
return(result);
}
static int
test_master_x(char *filename) {
FILE *fp;
char *p;
int line;
int cnt;
int result;
result = T_UNRESOLVED;
fp = fopen(filename, "r");
if (fp != NULL) {
line = 0;
while ((p = t_fgetbs(fp)) != NULL) {
++line;
/* skip comment lines */
if ((isspace(*p)) || (*p == '#'))
continue;
/* name of data file, origin, expected result */
cnt = t_bustline(p, Tokens);
if (cnt == 3) {
result = test_master(
Tokens[0],
Tokens[1],
t_dns_result_fromtext(Tokens[2]));
}
else {
t_info("bad format in %s at line %d\n",
filename, line);
}
(void) free(p);
}
(void) fclose(fp);
}
else {
t_info("Missing datafile %s\n", filename);
}
return(result);
}
static char *a1 = "dns_master_load loads a valid master file and "
"returns DNS_R_SUCCESS";
static void
t1() {
int result;
t_assert("dns_master_load", 1, T_REQUIRED, a1);
result = test_master_x("dns_master_load_1_data");
t_result(result);
}
static char *a2 = "dns_master_load returns DNS_R_UNEXPECTEDEND when the "
"masterfile input ends unexpectedly";
static void
t2() {
int result;
t_assert("dns_master_load", 2, T_REQUIRED, a2);
result = test_master_x("dns_master_load_2_data");
t_result(result);
}
static char *a3 = "dns_master_load returns DNS_R_NOOWNER when the "
"an ownername is not specified";
static void
t3() {
int result;
t_assert("dns_master_load", 3, T_REQUIRED, a3);
result = test_master_x("dns_master_load_3_data");
t_result(result);
}
static char *a4 = "dns_master_load returns DNS_R_NOTTL when the "
"the ttl is not specified";
static void
t4() {
int result;
t_assert("dns_master_load", 4, T_REQUIRED, a4);
result = test_master_x("dns_master_load_4_data");
t_result(result);
}
static char *a5 = "dns_master_load returns DNS_R_BADCLASS when the "
"the record class did not match the zone class";
static void
t5() {
int result;
t_assert("dns_master_load", 5, T_REQUIRED, a5);
result = test_master_x("dns_master_load_5_data");
t_result(result);
}
testspec_t T_testlist[] = {
{ t1, "DNS_R_SUCCESS" },
{ t2, "DNS_R_UNEXPECTEDEND" },
{ t3, "DNS_NOOWNER" },
{ t4, "DNS_NOTTL" },
{ t5, "DNS_BADCLASS" },
{ NULL, NULL }
};
# Copyright (C) 1999 Internet Software Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
CINCLUDES = -I${srcdir}/../../../lib/isc/unix/include \
-I${srcdir}/../../../lib/isc/pthreads/include \
-I${srcdir}/../../../lib/isc/include \
-I${srcdir}/../../../lib/dns/include \
-I${srcdir}/../../../lib/tests/include
CDEFINES =
CWARNINGS =
LIBS = ../../../lib/dns/libdns.a \
../../../lib/isc/libisc.a \
../../../lib/tests/libt_api.a \
@LIBS@
TARGETS = t_names
@BIND9_MAKE_RULES@
t_names: t_names.o
${CC} -o $@ t_names.o ${LIBS}
test:
-@./t_names -c @top_srcdir@/t_config -a >> ../t_journal 2>&1
testhelp:
@./t_names -h
clean distclean::
rm -f ${TARGETS}
#
# format of file is <testname> <tab> <bitlabel_pos> <tab> <expected_bits>
#
\[x42/7] 0 7
a.b.c.\[x42/7] 3 7
\[o033/8] 0 8
#
# format is:
# <testname> <tab> <labelpos> <tab> <bitpos> <tab> <expected value>
#
\[x42/7] 0 6 1
a.b.c.\[x42/7] 3 5 0
\[o033/8] 0 2 1
\[o033/8] 0 3 1
\[o033/8] 0 4 0
#
# test data for dns_name_compare
# format:
# <name1> <tab> <name2> <tab> <exp_order>
# where: exp_order may be one of: -1, 0, 1
#
# and where: exp_nlabels and exp_nbits are not tested if < 0
#
c.d a.b.c.d -1
a.b.c.d c.d 1
a.b.c a.b.c 0
#
# test data for dns_name_countlabels
# format:
# <name> <tab> <nlabels>
#
c.d 2
c.d. 3
a.b.c.d 4
a.b.c 3
. 1
\[b1100110].b.\[xab].a 4
\[b1100110].b.\[xab].a. 5
\[b1100110].\[xa2].\[o031].a. 5
#
# test data for dns_name_fromregion
# format:
# <test_name>
# where: exp_order may be one of: -1, 0, 1
#
# and where: exp_nlabels and exp_nbits are not tested if < 0
#
#c.d.\[x31].abc.\[b110011]
a.b.c.d.
a.b.c.d.[A].[aaa.
Ba\x\aa.b.c\[\[o\\.Z
Ba\x\aa.b.c\[\[o\\\..\.Z
#
# test data for dns_name_fromtext
# format:
# <name1> <tab> <name2> <tab> <origin> <tab> <downcase>
#
a.b a.b.c.d C.d 1
a.b a.b.c.d C.d 1
a.b a.b.C.d C.d 0
a.b. a.b. C.d 0
#
# test data for dns_name_fromwire_1
# format:
# <msgfile> <testname_offset> <downcase>
# <dc_method> <exp_name> <exp_result>
#
# where msgfile contains a DNS message in hex form
#
# and where testname_offset is the byte offset in this message of
# the start of a name
#
# and where downcase is 1 or 0
#
# and where dc_method is one of
# DNS_COMPRESS_ALL
# DNS_COMPRESS_GLOBAL
# DNS_COMPRESS_GLOBAL14
# DNS_COMPRESS_GLOBAL16
# DNS_COMPRESS_LOCAL
# DNS_COMPRESS_NONE
#
# and where exp_name is the expected name after any decompression
# or case conversion
#
# and where exp_result may be one of
# DNS_R_NOSPACE
# DNS_R_BADLABELTYPE
# DNS_R_DISALLOWED
# DNS_R_BADPOINTER
# DNS_R_UNEXPECTEDEND
# DNS_R_TOOMANYHOPS
#
wire_test1.data 25 1 DNS_COMPRESS_ALL vix.com. DNS_R_SUCCESS
#
# test data for dns_name_fromwire_2
# format:
# <msgfile> <testname_offset> <downcase>
# <dc_method> <exp_name> <exp_result>
#
# where msgfile contains a DNS message in hex form
#
# and where testname_offset is the byte offset in this message of
# the start of a name
#
# and where downcase is 1 or 0
#
# and where dc_method is one of