diff options
Diffstat (limited to 'bin/tests/net')
-rw-r--r-- | bin/tests/net/Makefile.in | 53 | ||||
-rw-r--r-- | bin/tests/net/driver.c | 107 | ||||
-rw-r--r-- | bin/tests/net/driver.h | 48 | ||||
-rw-r--r-- | bin/tests/net/netaddr_multicast.c | 112 | ||||
-rw-r--r-- | bin/tests/net/sockaddr_multicast.c | 36 | ||||
-rw-r--r-- | bin/tests/net/testsuite.h | 33 |
6 files changed, 389 insertions, 0 deletions
diff --git a/bin/tests/net/Makefile.in b/bin/tests/net/Makefile.in new file mode 100644 index 0000000..0c75c28 --- /dev/null +++ b/bin/tests/net/Makefile.in @@ -0,0 +1,53 @@ +# Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2000-2002 Internet Software Consortium. +# +# Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC 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. + +# $Id: Makefile.in,v 1.16 2007/06/19 23:47:00 tbox Exp $ + +srcdir = @srcdir@ +VPATH = @srcdir@ +top_srcdir = @top_srcdir@ + +@BIND9_MAKE_INCLUDES@ + +CINCLUDES = ${TEST_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES} + +CDEFINES = +CWARNINGS = + +ISCLIBS = ../../../lib/isc/libisc.@A@ + +ISCDEPLIBS = ../../../lib/isc/libisc.@A@ + +DEPLIBS = ${ISCDEPLIBS} + +LIBS = ${ISCLIBS} @LIBS@ + +TARGETS = t_net@EXEEXT@ + +SRCS = driver.c netaddr_multicast.c sockaddr_multicast.c + +OBJS = driver.@O@ netaddr_multicast.@O@ sockaddr_multicast.@O@ + +@BIND9_MAKE_RULES@ + +t_net@EXEEXT@: ${OBJS} ${DEPLIBS} ${TLIB} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${TLIB} ${LIBS} + +test: t_net@EXEEXT@ + -@./t_net@EXEEXT@ + +clean distclean:: + rm -f ${TARGETS} + rm -f ${OBJS} diff --git a/bin/tests/net/driver.c b/bin/tests/net/driver.c new file mode 100644 index 0000000..a8b3bf7 --- /dev/null +++ b/bin/tests/net/driver.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC 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. + */ + +/* $Id: driver.c,v 1.11 2007/06/19 23:47:00 tbox Exp $ */ + +#include <config.h> + +#include <stdlib.h> +#include <stdio.h> +#include <time.h> + +#include <isc/string.h> +#include <isc/util.h> + +#include "driver.h" + +#include "testsuite.h" + +#define NTESTS (sizeof(tests) / sizeof(test_t)) + +const char *gettime(void); +const char *test_result_totext(test_result_t); + +/* + * Not thread safe. + */ +const char * +gettime(void) { + static char now[512]; + time_t t; + + (void)time(&t); + + strftime(now, sizeof(now) - 1, + "%A %d %B %H:%M:%S %Y", + localtime(&t)); + + return (now); +} + +const char * +test_result_totext(test_result_t result) { + const char *s; + switch (result) { + case PASSED: + s = "PASS"; + break; + case FAILED: + s = "FAIL"; + break; + case UNTESTED: + s = "UNTESTED"; + break; + case UNKNOWN: + default: + s = "UNKNOWN"; + break; + } + + return (s); +} + +int +main(int argc, char **argv) { + test_t *test; + test_result_t result; + unsigned int n_failed; + unsigned int testno; + + UNUSED(argc); + UNUSED(argv); + + printf("S:%s:%s\n", SUITENAME, gettime()); + + n_failed = 0; + for (testno = 0; testno < NTESTS; testno++) { + test = &tests[testno]; + printf("T:%s:%u:A\n", test->tag, testno + 1); + printf("A:%s\n", test->description); + result = test->func(); + printf("R:%s\n", test_result_totext(result)); + if (result != PASSED) + n_failed++; + } + + printf("E:%s:%s\n", SUITENAME, gettime()); + + if (n_failed > 0) + exit(1); + + return (0); +} + diff --git a/bin/tests/net/driver.h b/bin/tests/net/driver.h new file mode 100644 index 0000000..1121efc --- /dev/null +++ b/bin/tests/net/driver.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC 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. + */ + +/* $Id: driver.h,v 1.8 2007/06/19 23:47:00 tbox Exp $ */ + +/* + * PASSED and FAILED mean the particular test passed or failed. + * + * UNKNOWN means that for one reason or another, the test process itself + * failed. For instance, missing files, error when parsing files or + * IP addresses, etc. That is, the test itself is broken, not what is + * being tested. + * + * UNTESTED means the test was unable to be run because a prerequisite test + * failed, the test is disabled, or the test needs a system component + * (for instance, Perl) and cannot run. + */ +typedef enum { + PASSED = 0, + FAILED = 1, + UNKNOWN = 2, + UNTESTED = 3 +} test_result_t; + +typedef test_result_t (*test_func_t)(void); + +typedef struct { + const char *tag; + const char *description; + test_func_t func; +} test_t; + +#define TESTDECL(name) test_result_t name(void) + diff --git a/bin/tests/net/netaddr_multicast.c b/bin/tests/net/netaddr_multicast.c new file mode 100644 index 0000000..79f260b --- /dev/null +++ b/bin/tests/net/netaddr_multicast.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC 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. + */ + +/* $Id: netaddr_multicast.c,v 1.12 2007/06/19 23:47:00 tbox Exp $ */ + +#include <config.h> + +#include <stdlib.h> +#include <stdio.h> + +#include <isc/net.h> +#include <isc/netaddr.h> +#include <isc/string.h> +#include <isc/types.h> +#include <isc/util.h> + +#include "driver.h" + +TESTDECL(netaddr_multicast); + +typedef struct { + int family; + const char *addr; + isc_boolean_t is_multicast; +} t_addr_t; + +static t_addr_t addrs[] = { + { AF_INET, "1.2.3.4", ISC_FALSE }, + { AF_INET, "4.3.2.1", ISC_FALSE }, + { AF_INET, "224.1.1.1", ISC_TRUE }, + { AF_INET, "1.1.1.244", ISC_FALSE }, + { AF_INET6, "::1", ISC_FALSE }, + { AF_INET6, "ff02::1", ISC_TRUE } +}; +#define NADDRS (sizeof(addrs) / sizeof(t_addr_t)) + +static isc_result_t to_netaddr(t_addr_t *, isc_netaddr_t *); + +static isc_result_t +to_netaddr(t_addr_t *addr, isc_netaddr_t *na) { + int r; + struct in_addr in; + struct in6_addr in6; + + switch (addr->family) { + case AF_INET: + r = inet_pton(AF_INET, addr->addr, (unsigned char *)&in); + if (r != 1) + return (ISC_R_FAILURE); + isc_netaddr_fromin(na, &in); + break; + case AF_INET6: + r = inet_pton(AF_INET6, addr->addr, (unsigned char *)&in6); + if (r != 1) + return (ISC_R_FAILURE); + isc_netaddr_fromin6(na, &in6); + break; + default: + return (ISC_R_UNEXPECTED); + } + + return (ISC_R_SUCCESS); +} + +test_result_t +netaddr_multicast(void) { + isc_netaddr_t na; + unsigned int n_fail; + t_addr_t *addr; + unsigned int i; + isc_result_t result; + isc_boolean_t tf; + + n_fail = 0; + for (i = 0; i < NADDRS; i++) { + addr = &addrs[i]; + result = to_netaddr(addr, &na); + if (result != ISC_R_SUCCESS) { + printf("I:to_netaddr() returned %s on item %u\n", + isc_result_totext(result), i); + return (UNKNOWN); + } + tf = isc_netaddr_ismulticast(&na); + if (tf == addr->is_multicast) { + printf("I:%s is%s multicast (PASSED)\n", + (addr->addr), (tf ? "" : " not")); + } else { + printf("I:%s is%s multicast (FAILED)\n", + (addr->addr), (tf ? "" : " not")); + n_fail++; + } + } + + if (n_fail > 0) + return (FAILED); + + return (PASSED); +} diff --git a/bin/tests/net/sockaddr_multicast.c b/bin/tests/net/sockaddr_multicast.c new file mode 100644 index 0000000..cfe04dc --- /dev/null +++ b/bin/tests/net/sockaddr_multicast.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC 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. + */ + +/* $Id: sockaddr_multicast.c,v 1.8 2007/06/19 23:47:00 tbox Exp $ */ + +#include <config.h> + +#include <stdlib.h> +#include <stdio.h> + +#include <isc/string.h> +#include <isc/util.h> + +#include "driver.h" + +TESTDECL(sockaddr_multicast); + +test_result_t +sockaddr_multicast(void) { + + return (PASSED); +} diff --git a/bin/tests/net/testsuite.h b/bin/tests/net/testsuite.h new file mode 100644 index 0000000..68a214c --- /dev/null +++ b/bin/tests/net/testsuite.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC 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. + */ + +/* $Id: testsuite.h,v 1.7 2007/06/19 23:47:00 tbox Exp $ */ + +#define SUITENAME "net" + +TESTDECL(netaddr_multicast); +TESTDECL(sockaddr_multicast); + +static test_t tests[] = { + { "isc_netaddr_ismulticast", + "Checking to see if multicast addresses are detected properly", + netaddr_multicast }, + { "isc_sockaddr_ismulticast", + "Checking to see if multicast addresses are detected properly", + sockaddr_multicast }, + +}; |