summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorbushman <bushman@FreeBSD.org>2007-06-24 06:14:18 +0000
committerbushman <bushman@FreeBSD.org>2007-06-24 06:14:18 +0000
commit15c31be18b815c9fe268c18b71f76ea363bc8352 (patch)
tree127d02029f11690547ab540bad866b9ef55136a3 /tools
parent99d11a55914ad6ec1c5cdf40a4ddea6f3e85ba12 (diff)
downloadFreeBSD-src-15c31be18b815c9fe268c18b71f76ea363bc8352.zip
FreeBSD-src-15c31be18b815c9fe268c18b71f76ea363bc8352.tar.gz
- Bugs in gethostbyXXX/getipnodebyXXX regression tests fixed.
Tests for getipnodebyXXX functions now cover most number of flags combinations. Approved by: re (kensmith), brooks (mentor)
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/lib/libc/nss/test-gethostby.c180
-rw-r--r--tools/regression/lib/libc/nss/test-gethostby.t55
2 files changed, 162 insertions, 73 deletions
diff --git a/tools/regression/lib/libc/nss/test-gethostby.c b/tools/regression/lib/libc/nss/test-gethostby.c
index 83db92d..61e4ca2 100644
--- a/tools/regression/lib/libc/nss/test-gethostby.c
+++ b/tools/regression/lib/libc/nss/test-gethostby.c
@@ -58,6 +58,7 @@ enum test_methods {
static int use_ipnode_functions = 0;
static int use_ipv6_mapping = 0;
+static int ipnode_flags = 0;
static int debug = 0;
static int af_type = AF_INET;
static enum test_methods method = TEST_BUILD_SNAPSHOT;
@@ -103,17 +104,11 @@ __gethostbyname2(const char *name, int af)
struct hostent *he;
int error;
- if (use_ipnode_functions == 0) {
- if (use_ipv6_mapping != 0)
- af = AF_INET;
-
+ if (use_ipnode_functions == 0)
he = gethostbyname2(name, af);
- } else {
+ else {
error = 0;
- if (use_ipv6_mapping != 0)
- af = AF_INET6;
- he = getipnodebyname(name, af, use_ipv6_mapping == 0 ? AI_ALL :
- AI_ALL | AI_V4MAPPED, &error);
+ he = getipnodebyname(name, af, ipnode_flags, &error);
if (he == NULL);
errno = error;
}
@@ -127,17 +122,11 @@ __gethostbyaddr(const void *addr, socklen_t len, int af)
struct hostent *he;
int error;
- if (use_ipnode_functions == 0) {
- if (use_ipv6_mapping != 0)
- af = AF_INET;
-
+ if (use_ipnode_functions == 0)
he = gethostbyaddr(addr, len, af);
- } else {
+ else {
error = 0;
- if (use_ipv6_mapping != 0)
- af = AF_INET6;
- he = getipnodebyaddr(addr, len, use_ipv6_mapping == 0 ? AI_ALL :
- AI_ALL | AI_V4MAPPED, &error);
+ he = getipnodebyaddr(addr, len, af, &error);
if (he == NULL)
errno = error;
}
@@ -238,7 +227,8 @@ free_hostent(struct hostent *ht)
static int
compare_hostent(struct hostent *ht1, struct hostent *ht2, void *mdata)
{
- char **c1, **c2;
+ char **c1, **c2, **ct, **cb;
+ int b;
if (ht1 == ht2)
return 0;
@@ -262,12 +252,39 @@ compare_hostent(struct hostent *ht1, struct hostent *ht2, void *mdata)
goto errfin;
if ((c1 != NULL) && (c2 != NULL)) {
- for (;*c1 && *c2; ++c1, ++c2)
- if (strcmp(*c1, *c2) != 0)
+ cb = c1;
+ for (;*c1; ++c1) {
+ b = 0;
+ for (ct = c2; *ct; ++ct) {
+ if (strcmp(*c1, *ct) == 0) {
+ b = 1;
+ break;
+ }
+ }
+ if (b == 0) {
+ if (debug)
+ printf("h1 aliases item can't be "\
+ "found in h2 aliases\n");
goto errfin;
-
- if ((*c1 != NULL) || (*c2 != NULL))
- goto errfin;
+ }
+ }
+
+ c1 = cb;
+ for (;*c2; ++c2) {
+ b = 0;
+ for (ct = c1; *ct; ++ct) {
+ if (strcmp(*c2, *ct) == 0) {
+ b = 1;
+ break;
+ }
+ }
+ if (b == 0) {
+ if (debug)
+ printf("h2 aliases item can't be "\
+ " found in h1 aliases\n");
+ goto errfin;
+ }
+ }
}
c1 = ht1->h_addr_list;
@@ -278,12 +295,39 @@ compare_hostent(struct hostent *ht1, struct hostent *ht2, void *mdata)
goto errfin;
if ((c1 != NULL) && (c2 != NULL)) {
- for (;*c1 && *c2; ++c1, ++c2)
- if (memcmp(*c1, *c2, ht1->h_length) != 0)
+ cb = c1;
+ for (;*c1; ++c1) {
+ b = 0;
+ for (ct = c2; *ct; ++ct) {
+ if (memcmp(*c1, *ct, ht1->h_length) == 0) {
+ b = 1;
+ break;
+ }
+ }
+ if (b == 0) {
+ if (debug)
+ printf("h1 addresses item can't be "\
+ "found in h2 addresses\n");
goto errfin;
-
- if ((*c1 != NULL) || (*c2 != NULL))
- goto errfin;
+ }
+ }
+
+ c1 = cb;
+ for (;*c2; ++c2) {
+ b = 0;
+ for (ct = c1; *ct; ++ct) {
+ if (memcmp(*c2, *ct, ht1->h_length) == 0) {
+ b = 1;
+ break;
+ }
+ }
+ if (b == 0) {
+ if (debug)
+ printf("h2 addresses item can't be "\
+ "found in h1 addresses\n");
+ goto errfin;
+ }
+ }
}
return 0;
@@ -588,8 +632,8 @@ hostent_read_snapshot_func(struct hostent *ht, char *line)
ts = (char *)malloc(ht->h_length);
assert(ts != NULL);
memset(ts, 0, ht->h_length);
- rv = hostent_read_snapshot_addr(
- s, ts, ht->h_length);
+ rv = hostent_read_snapshot_addr(s,\
+ (unsigned char *)ts, ht->h_length);
sl_add(sl2, ts);
if (rv != 0)
goto fin;
@@ -598,8 +642,8 @@ hostent_read_snapshot_func(struct hostent *ht, char *line)
ts = (char *)malloc(ht->h_length);
assert(ts != NULL);
memset(ts, 0, ht->h_length);
- rv = hostent_read_snapshot_addr(
- s, ts, ht->h_length);
+ rv = hostent_read_snapshot_addr(s,\
+ (unsigned char *)ts, ht->h_length);
sl_add(sl2, ts);
if (rv != 0)
goto fin;
@@ -869,7 +913,7 @@ static void
usage(void)
{
(void)fprintf(stderr,
- "Usage: %s -na2i [-o] [-d] [-m46] [-s <file>] -f <file>\n",
+ "Usage: %s -na2i [-o] [-d] [-46] [-mAcM] [-C] [-s <file>] -f <file>\n",
getprogname());
exit(1);
}
@@ -888,39 +932,29 @@ main(int argc, char **argv)
snapshot_file = NULL;
hostlist_file = NULL;
- while ((c = getopt(argc, argv, "m46na2idos:f:")) != -1)
+ while ((c = getopt(argc, argv, "nad2iod46mAcMs:f:")) != -1)
switch (c) {
case '4':
+ af_type = AF_INET;
+ break;
case '6':
+ af_type = AF_INET6;
+ break;
+ case 'M':
+ af_type = AF_INET6;
+ use_ipv6_mapping = 1;
+ ipnode_flags |= AI_V4MAPPED_CFG;
+ break;
case 'm':
- statp = __res_state();
- if ((statp == NULL) ||
- ((statp->options & RES_INIT) == 0 &&
- res_ninit(statp) == -1)) {
- if (debug)
- printf("error: can't init res_state\n");
-
- free(snapshot_file);
- free(hostlist_file);
- return (-1);
- }
-
- switch (c) {
- case '4':
- af_type = AF_INET;
- statp->options &= ~RES_USE_INET6;
- break;
- case '6':
- af_type = AF_INET6;
- statp->options &= ~RES_USE_INET6;
- break;
- case 'm':
- statp->options |= RES_USE_INET6;
- use_ipv6_mapping = 1;
- break;
- default:
- break;
- };
+ af_type = AF_INET6;
+ use_ipv6_mapping = 1;
+ ipnode_flags |= AI_V4MAPPED;
+ break;
+ case 'c':
+ ipnode_flags |= AI_ADDRCONFIG;
+ break;
+ case 'A':
+ ipnode_flags |= AI_ALL;
break;
case 'o':
use_ipnode_functions = 1;
@@ -949,6 +983,24 @@ main(int argc, char **argv)
default:
usage();
}
+
+ if (use_ipnode_functions == 0) {
+ statp = __res_state();
+ if ((statp == NULL) || ((statp->options & RES_INIT) == 0 &&
+ res_ninit(statp) == -1)) {
+ if (debug)
+ printf("error: can't init res_state\n");
+
+ free(snapshot_file);
+ free(hostlist_file);
+ return (-1);
+ }
+
+ if (use_ipv6_mapping == 0)
+ statp->options &= ~RES_USE_INET6;
+ else
+ statp->options |= RES_USE_INET6;
+ }
TEST_DATA_INIT(hostent, &td, clone_hostent, free_hostent);
TEST_DATA_INIT(hostent, &td_addr, clone_hostent, free_hostent);
@@ -1047,5 +1099,7 @@ fin:
TEST_DATA_DESTROY(hostent, &td);
free(hostlist_file);
free(snapshot_file);
+
return (rv);
}
+
diff --git a/tools/regression/lib/libc/nss/test-gethostby.t b/tools/regression/lib/libc/nss/test-gethostby.t
index d5fca17..42bed00 100644
--- a/tools/regression/lib/libc/nss/test-gethostby.t
+++ b/tools/regression/lib/libc/nss/test-gethostby.t
@@ -18,7 +18,7 @@ executable=`basename $0 .t`
make $executable 2>&1 > /dev/null
-echo 1..32
+echo 1..46
#Tests for gethostby***() functions
#IPv4-driven testing
do_test 1 'gethostbyname2() (IPv4)' '-4 -n -f mach'
@@ -49,7 +49,7 @@ do_test 16 'gethostbyaddr() snapshot (IPv6 mapped)'\
'-m -a -s snapshot_htaddr6map -f mach'
#Tests for getipnodeby***() functions
-#IPv4-driven testing
+#IPv4-driven testing, flags are 0
do_test 17 'getipnodebyname() (IPv4)' '-o -4 -n -f mach'
do_test 18 'getipnodebyaddr() (IPv4)' '-o -4 -a -f mach'
do_test 19 'getipnodebyname()-getaddrinfo() (IPv4)' '-o -4 -2 -f mach'
@@ -59,7 +59,7 @@ do_test 21 'getipnodebyname() snapshot (IPv4)'\
do_test 22 'getipnodebyname() snapshot (IPv4)'\
'-o -4 -a -s snapshot_ipnodeaddr4 -f mach'
-#IPv6-driven testing
+#IPv6-driven testing, flags are 0
do_test 23 'getipnodebyname() (IPv6)' '-o -6 -n -f mach'
do_test 24 'getipnodebyaddr() (IPv6)' '-o -6 -a -f mach'
do_test 25 'getipnodebyname()-getaddrinfo() (IPv6)' '-o -6 -2 -f mach'
@@ -69,10 +69,45 @@ do_test 27 'getipnodebyname() snapshot (IPv6)'\
do_test 28 'getipnodebyaddr() snapshot (IPv6)'\
'-o -6 -a -s snapshot_ipnodeaddr6 -f mach'
-#Mapped IPv6-driven testing (getaddrinfo() equality test is useless here)
-do_test 29 'getipnodebyname() (IPv6)' '-o -m -n -f mach'
-do_test 30 'getipnodebyaddr() (IPv6)' '-o -m -a -f mach'
-do_test 31 'getipnodebyname() snapshot (IPv6)'\
- '-o -m -n -s snapshot_ipnodename6map -f mach'
-do_test 32 'getipnodebyaddr() snapshot (IPv6)'\
- '-o -m -a -s snapshot_ipnodeaddr6map -f mach'
+#Mapped IPv6-driven testing, flags are AI_V4MAPPED
+do_test 29 'getipnodebyname() (IPv6, AI_V4MAPPED)' '-o -m -n -f mach'
+do_test 30 'getipnodebyaddr() (IPv6, AI_V4MAPPED)' '-o -m -a -f mach'
+do_test 31 'getipnodebyname() snapshot (IPv6, AI_V4MAPPED)'\
+ '-o -m -n -s snapshot_ipnodename6_AI_V4MAPPED -f mach'
+do_test 32 'getipnodebyaddr() snapshot (IPv6, AI_V4MAPPED)'\
+ '-o -m -a -s snapshot_ipnodeaddr6_AI_V4MAPPED -f mach'
+
+#Mapped IPv6-driven testing, flags are AI_V4MAPPED_CFG
+do_test 33 'getipnodebyname() (IPv6, AI_V4MAPPED_CFG)' '-o -M -n -f mach'
+do_test 34 'getipnodebyaddr() (IPv6, AI_V4MAPPED_CFG)' '-o -M -a -f mach'
+do_test 35 'getipnodebyname() snapshot (IPv6, AI_V4MAPPED_CFG)'\
+ '-o -M -n -s snapshot_ipnodename6_AI_V4MAPPED_CFG -f mach'
+do_test 36 'getipnodebyaddr() snapshot (IPv6, AI_V4MAPPED_CFG)'\
+ '-o -M -a -s snapshot_ipnodeaddr6_AI_V4MAPPED_CFG -f mach'
+
+#Mapped IPv6-driven testing, flags are AI_V4MAPPED_CFG | AI_ALL
+do_test 37 'getipnodebyname() (IPv6, AI_V4MAPPED_CFG | AI_ALL)'\
+ '-o -MA -n -f mach'
+do_test 38 'getipnodebyaddr() (IPv6, AI_V4MAPPED_CFG | AI_ALL)'\
+ '-o -MA -a -f mach'
+do_test 39 'getipnodebyname() snapshot (IPv6, AI_V4MAPPED_CFG | AI_ALL)'\
+ '-o -MA -n -s snapshot_ipnodename6_AI_V4MAPPED_CFG_AI_ALL -f mach'
+do_test 40 'getipnodebyaddr() snapshot (IPv6, AI_V4MAPPED_CFG | AI_ALL)'\
+ '-o -MA -a -s snapshot_ipnodeaddr6_AI_V4MAPPED_CFG_AI_ALL -f mach'
+
+#Mapped IPv6-driven testing, flags are AI_V4MAPPED_CFG | AI_ADDRCONFIG
+do_test 41 'getipnodebyname() (IPv6, AI_V4MAPPED_CFG | AI_ADDRCONFIG)'\
+ '-o -Mc -n -f mach'
+do_test 42 'getipnodebyname() snapshot (IPv6, AI_V4MAPPED_CFG | AI_ADDRCONFIG)'\
+ '-o -Mc -n -s snapshot_ipnodename6_AI_V4MAPPED_CFG_AI_ADDRCONFIG -f mach'
+
+#IPv4-driven testing, flags are AI_ADDRCONFIG
+do_test 43 'getipnodebyname() (IPv4, AI_ADDRCONFIG)' '-o -4c -n -f mach'
+do_test 44 'getipnodebyname() snapshot (IPv4, AI_ADDRCONFIG)'\
+ '-o -4c -n -s snapshot_ipnodename4_AI_ADDRCONFIG -f mach'
+
+#IPv6-driven testing, flags are AI_ADDRCONFIG
+do_test 45 'getipnodebyname() (IPv6, AI_ADDRCONFIG)' '-o -6c -n -f mach'
+do_test 46 'getipnodebyname() snapshot (IPv6, AI_ADDRCONFIG)'\
+ '-o -6c -n -s snapshot_ipnodename6_AI_ADDRCONFIG -f mach'
+
OpenPOWER on IntegriCloud