diff options
author | ngie <ngie@FreeBSD.org> | 2015-12-16 08:09:03 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2015-12-16 08:09:03 +0000 |
commit | 33a47e413b3e7db79637f488d589056cff9b1212 (patch) | |
tree | 743f934d696b9ce0f5014fc2840edc85030ea91a | |
parent | f990abc0015f0d89da088f70145cd0d63b56728b (diff) | |
download | FreeBSD-src-33a47e413b3e7db79637f488d589056cff9b1212.zip FreeBSD-src-33a47e413b3e7db79637f488d589056cff9b1212.tar.gz |
Integrate tools/regression/lib/libc/nss into the FreeBSD test suite as
lib/libc/tests/nss
- Convert the testcases to ATF
- Do some style(9) cleanups:
-- Sort headers
-- Apply indentation fixes
-- Remove superfluous parentheses
- Explicitly print out debug printfs for use with `kyua {debug,report}`; for
items that were overly noisy, they've been put behind #ifdef DEBUG
conditionals
- Fix some format strings
MFC after: 1 week
Sponsored by: EMC / Isilon Storage Division
23 files changed, 2486 insertions, 2515 deletions
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 5b22e0d..0f4f264 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -271,6 +271,8 @@ .. .. .. + nss + .. regex data .. diff --git a/lib/libc/tests/nss/Makefile b/lib/libc/tests/nss/Makefile new file mode 100644 index 0000000..1b777c2 --- /dev/null +++ b/lib/libc/tests/nss/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/lib/libc/nss +BINDIR= ${TESTSDIR} + +.PATH: ${.CURDIR:H}/resolv + +FILES+= mach + +CFLAGS+= -I${SRCTOP}/tests + +ATF_TESTS_C+= getaddrinfo_test +ATF_TESTS_C+= getgr_test +ATF_TESTS_C+= gethostby_test +TEST_METADATA.gethostby_test= timeout="1200" +ATF_TESTS_C+= getpw_test +ATF_TESTS_C+= getproto_test +ATF_TESTS_C+= getrpc_test +ATF_TESTS_C+= getserv_test +ATF_TESTS_C+= getusershell_test + +.include <bsd.test.mk> diff --git a/tools/regression/lib/libc/nss/test-getaddr.c b/lib/libc/tests/nss/getaddrinfo_test.c index f0729ec..0c9704f 100644 --- a/tools/regression/lib/libc/nss/test-getaddr.c +++ b/lib/libc/tests/nss/getaddrinfo_test.c @@ -28,11 +28,10 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <arpa/inet.h> -#include <sys/socket.h> #include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> #include <netinet/in.h> -#include <assert.h> #include <errno.h> #include <netdb.h> #include <resolv.h> @@ -41,6 +40,10 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <stringlist.h> #include <unistd.h> + +#include <atf-c.h> + +#include "freebsd_test_suite/macros.h" #include "testutil.h" enum test_methods { @@ -48,7 +51,6 @@ enum test_methods { TEST_BUILD_SNAPSHOT }; -static int debug = 0; static struct addrinfo hints; static enum test_methods method = TEST_GETADDRINFO; @@ -59,7 +61,6 @@ DECLARE_2PASS_TEST(addrinfo) static void clone_addrinfo(struct addrinfo *, struct addrinfo const *); static int compare_addrinfo(struct addrinfo *, struct addrinfo *, void *); static void dump_addrinfo(struct addrinfo *); -static void free_addrinfo(struct addrinfo *); static void sdump_addrinfo(struct addrinfo *, char *, size_t); @@ -70,23 +71,23 @@ IMPLEMENT_2PASS_TEST(addrinfo) static void clone_addrinfo(struct addrinfo *dest, struct addrinfo const *src) { - assert(dest != NULL); - assert(src != NULL); + + ATF_REQUIRE(dest != NULL); + ATF_REQUIRE(src != NULL); memcpy(dest, src, sizeof(struct addrinfo)); if (src->ai_canonname != NULL) dest->ai_canonname = strdup(src->ai_canonname); if (src->ai_addr != NULL) { - dest->ai_addr = (struct sockaddr *)malloc(src->ai_addrlen); - assert(dest->ai_addr != NULL); + dest->ai_addr = malloc(src->ai_addrlen); + ATF_REQUIRE(dest->ai_addr != NULL); memcpy(dest->ai_addr, src->ai_addr, src->ai_addrlen); } if (src->ai_next != NULL) { - dest->ai_next = (struct addrinfo *)malloc( - sizeof(struct addrinfo)); - assert(dest->ai_next != NULL); + dest->ai_next = malloc(sizeof(struct addrinfo)); + ATF_REQUIRE(dest->ai_next != NULL); clone_addrinfo(dest->ai_next, src->ai_next); } } @@ -94,29 +95,30 @@ clone_addrinfo(struct addrinfo *dest, struct addrinfo const *src) static int compare_addrinfo_(struct addrinfo *ai1, struct addrinfo *ai2) { + if ((ai1 == NULL) || (ai2 == NULL)) return (-1); - if ((ai1->ai_flags != ai2->ai_flags) || - (ai1->ai_family != ai2->ai_family) || - (ai1->ai_socktype != ai2->ai_socktype) || - (ai1->ai_protocol != ai2->ai_protocol) || - (ai1->ai_addrlen != ai2->ai_addrlen) || - (((ai1->ai_addr == NULL) || (ai2->ai_addr == NULL)) && - (ai1->ai_addr != ai2->ai_addr)) || - (((ai1->ai_canonname == NULL) || (ai2->ai_canonname == NULL)) && - (ai1->ai_canonname != ai2->ai_canonname))) + if (ai1->ai_flags != ai2->ai_flags || + ai1->ai_family != ai2->ai_family || + ai1->ai_socktype != ai2->ai_socktype || + ai1->ai_protocol != ai2->ai_protocol || + ai1->ai_addrlen != ai2->ai_addrlen || + ((ai1->ai_addr == NULL || ai2->ai_addr == NULL) && + ai1->ai_addr != ai2->ai_addr) || + ((ai1->ai_canonname == NULL || ai2->ai_canonname == NULL) && + ai1->ai_canonname != ai2->ai_canonname)) return (-1); - if ((ai1->ai_canonname != NULL) && - (strcmp(ai1->ai_canonname, ai2->ai_canonname) != 0)) + if (ai1->ai_canonname != NULL && + strcmp(ai1->ai_canonname, ai2->ai_canonname) != 0) return (-1); - if ((ai1->ai_addr != NULL) && - (memcmp(ai1->ai_addr, ai2->ai_addr, ai1->ai_addrlen) != 0)) + if (ai1->ai_addr != NULL && + memcmp(ai1->ai_addr, ai2->ai_addr, ai1->ai_addrlen) != 0) return (-1); - if ((ai1->ai_next == NULL) && (ai2->ai_next == NULL)) + if (ai1->ai_next == NULL && ai2->ai_next == NULL) return (0); else return (compare_addrinfo_(ai1->ai_next, ai2->ai_next)); @@ -127,20 +129,16 @@ compare_addrinfo(struct addrinfo *ai1, struct addrinfo *ai2, void *mdata) { int rv; - if (debug) { - printf("testing equality of 2 addrinfo structures\n"); - } + printf("testing equality of 2 addrinfo structures\n"); rv = compare_addrinfo_(ai1, ai2); - if (debug) { - if (rv == 0) - printf("equal\n"); - else { - dump_addrinfo(ai1); - dump_addrinfo(ai2); - printf("not equal\n"); - } + if (rv == 0) + printf("equal\n"); + else { + dump_addrinfo(ai1); + dump_addrinfo(ai2); + printf("not equal\n"); } return (rv); @@ -184,18 +182,18 @@ sdump_addrinfo(struct addrinfo *ai, char *buffer, size_t buflen) return; buflen -= written; } else { - for (i = 0; i < ai->ai_addrlen; ++i ) { - written = snprintf(buffer, buflen, - i + 1 != ai->ai_addrlen ? "%d." : "%d", - ((unsigned char *)ai->ai_addr)[i]); - buffer += written; - if (written > buflen) - return; - buflen -= written; - - if (buflen == 0) - return; - } + for (i = 0; i < ai->ai_addrlen; i++) { + written = snprintf(buffer, buflen, + i + 1 != ai->ai_addrlen ? "%d." : "%d", + ((unsigned char *)ai->ai_addr)[i]); + buffer += written; + if (written > buflen) + return; + buflen -= written; + + if (buflen == 0) + return; + } } if (ai->ai_next != NULL) { @@ -226,7 +224,7 @@ addrinfo_read_snapshot_addr(char *addr, unsigned char *result, size_t len) char *s, *ps, *ts; ps = addr; - while ( (s = strsep(&ps, ".")) != NULL) { + while ((s = strsep(&ps, ".")) != NULL) { if (len == 0) return (-1); @@ -253,55 +251,53 @@ addrinfo_read_snapshot_ai(struct addrinfo *ai, char *line) i = 0; ps = line; memset(ai, 0, sizeof(struct addrinfo)); - while ( (s = strsep(&ps, " ")) != NULL) { + while ((s = strsep(&ps, " ")) != NULL) { switch (i) { - case 0: - case 1: - case 2: - case 3: - pi = &ai->ai_flags + i; - *pi = (int)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; - break; - case 4: - ai->ai_addrlen = (socklen_t)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; - break; - case 5: - if (strcmp(s, "(null)") != 0) { - ai->ai_canonname = strdup(s); - assert(ai->ai_canonname != NULL); - } - break; - case 6: - if (strcmp(s, "(null)") != 0) { - ai->ai_addr = (struct sockaddr *)malloc( - ai->ai_addrlen); - assert(ai->ai_addr != NULL); - memset(ai->ai_addr, 0, ai->ai_addrlen); - rv = addrinfo_read_snapshot_addr(s, - (unsigned char *)ai->ai_addr, - ai->ai_addrlen); - - if (rv != 0) - goto fin; - } - break; - default: - /* NOTE: should not be reachable */ - rv = -1; + case 0: + case 1: + case 2: + case 3: + pi = &ai->ai_flags + i; + *pi = (int)strtol(s, &ts, 10); + if (*ts != '\0') + goto fin; + break; + case 4: + ai->ai_addrlen = (socklen_t)strtol(s, &ts, 10); + if (*ts != '\0') goto fin; - }; + break; + case 5: + if (strcmp(s, "(null)") != 0) { + ai->ai_canonname = strdup(s); + ATF_REQUIRE(ai->ai_canonname != NULL); + } + break; + case 6: + if (strcmp(s, "(null)") != 0) { + ai->ai_addr = calloc(1, ai->ai_addrlen); + ATF_REQUIRE(ai->ai_addr != NULL); + rv = addrinfo_read_snapshot_addr(s, + (unsigned char *)ai->ai_addr, + ai->ai_addrlen); + + if (rv != 0) + goto fin; + } + break; + default: + /* NOTE: should not be reachable */ + rv = -1; + goto fin; + } ++i; } fin: - if ((i != 7) || (rv != 0)) { + if (i != 7 || rv != 0) { free_addrinfo(ai); - memset(ai, 0, sizeof(struct addrinfo)); + ai = NULL; return (-1); } @@ -315,8 +311,7 @@ addrinfo_read_snapshot_func(struct addrinfo *ai, char *line) char *s, *ps; int i, rv; - if (debug) - printf("1 line read from snapshot:\n%s\n", line); + printf("1 line read from snapshot:\n%s\n", line); rv = 0; i = 0; @@ -331,15 +326,14 @@ addrinfo_read_snapshot_func(struct addrinfo *ai, char *line) return (-1); ai2 = ai; - while ( (s = strsep(&ps, ":")) != NULL) { - ai2->ai_next = (struct addrinfo *)malloc( - sizeof(struct addrinfo)); - assert(ai2->ai_next != NULL); - memset(ai2->ai_next, 0, sizeof(struct addrinfo)); + while ((s = strsep(&ps, ":")) != NULL) { + ai2->ai_next = calloc(1, sizeof(struct addrinfo)); + ATF_REQUIRE(ai2->ai_next != NULL); rv = addrinfo_read_snapshot_ai(ai2->ai_next, s); if (rv != 0) { free_addrinfo(ai); + ai = NULL; return (-1); } @@ -352,39 +346,36 @@ addrinfo_read_snapshot_func(struct addrinfo *ai, char *line) static int addrinfo_test_correctness(struct addrinfo *ai, void *mdata) { - if (debug) { - printf("testing correctness with the following data:\n"); - dump_addrinfo(ai); - } + + printf("testing correctness with the following data:\n"); + dump_addrinfo(ai); if (ai == NULL) goto errfin; - if (!((ai->ai_family >= 0) && (ai->ai_family < AF_MAX))) + if (!(ai->ai_family >= 0 && ai->ai_family < AF_MAX)) goto errfin; - if ((ai->ai_socktype != 0) && (ai->ai_socktype != SOCK_STREAM) && - (ai->ai_socktype != SOCK_DGRAM) && (ai->ai_socktype != SOCK_RAW)) + if (ai->ai_socktype != 0 && ai->ai_socktype != SOCK_STREAM && + ai->ai_socktype != SOCK_DGRAM && ai->ai_socktype != SOCK_RAW) goto errfin; - if ((ai->ai_protocol != 0) && (ai->ai_protocol != IPPROTO_UDP) && - (ai->ai_protocol != IPPROTO_TCP)) + if (ai->ai_protocol != 0 && ai->ai_protocol != IPPROTO_UDP && + ai->ai_protocol != IPPROTO_TCP) goto errfin; if ((ai->ai_flags & ~(AI_CANONNAME | AI_NUMERICHOST | AI_PASSIVE)) != 0) goto errfin; - if ((ai->ai_addrlen != ai->ai_addr->sa_len) || - (ai->ai_family != ai->ai_addr->sa_family)) + if (ai->ai_addrlen != ai->ai_addr->sa_len || + ai->ai_family != ai->ai_addr->sa_family) goto errfin; - if (debug) - printf("correct\n"); + printf("correct\n"); return (0); errfin: - if (debug) - printf("incorrect\n"); + printf("incorrect\n"); return (-1); } @@ -395,93 +386,49 @@ addrinfo_read_hostlist_func(struct addrinfo *ai, char *line) struct addrinfo *result; int rv; - if (debug) - printf("resolving %s: ", line); + printf("resolving %s: ", line); rv = getaddrinfo(line, NULL, &hints, &result); if (rv == 0) { - if (debug) - printf("found\n"); + printf("found\n"); rv = addrinfo_test_correctness(result, NULL); if (rv != 0) { freeaddrinfo(result); + result = NULL; return (rv); } clone_addrinfo(ai, result); freeaddrinfo(result); + result = NULL; } else { - if (debug) - printf("not found\n"); + printf("not found\n"); memset(ai, 0, sizeof(struct addrinfo)); } return (0); } -static void -usage(void) -{ - (void)fprintf(stderr, - "Usage: %s [-d] [-46] [-s <file]> -f <file>\n", - getprogname()); - exit(1); -} - -int -main(int argc, char **argv) +void +run_tests(char *hostlist_file, char *snapshot_file, int ai_family) { struct addrinfo_test_data td, td_snap; - char *snapshot_file, *hostlist_file; int rv; - int c; - if (argc < 2) - usage(); - - snapshot_file = NULL; - hostlist_file = NULL; memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = PF_UNSPEC; + hints.ai_family = ai_family; hints.ai_flags = AI_CANONNAME; - while ((c = getopt(argc, argv, "46dns:f:")) != -1) - switch (c) { - case '4': - hints.ai_family = PF_INET; - break; - case '6': - hints.ai_family = PF_INET6; - break; - case 'd': - debug = 1; - break; - case 's': - snapshot_file = strdup(optarg); - method = TEST_BUILD_SNAPSHOT; - break; - case 'f': - hostlist_file = strdup(optarg); - break; - default: - usage(); - } + + if (snapshot_file != NULL) + method = TEST_BUILD_SNAPSHOT; TEST_DATA_INIT(addrinfo, &td, clone_addrinfo, free_addrinfo); TEST_DATA_INIT(addrinfo, &td_snap, clone_addrinfo, free_addrinfo); - if (hostlist_file == NULL) - usage(); + ATF_REQUIRE_MSG(access(hostlist_file, R_OK) == 0, + "can't access the hostlist file %s\n", hostlist_file); - if (access(hostlist_file, R_OK) != 0) { - if (debug) - printf("can't access the hostlist file %s\n", - hostlist_file); - - usage(); - } - - if (debug) - printf("building host lists from %s\n", hostlist_file); + printf("building host lists from %s\n", hostlist_file); rv = TEST_SNAPSHOT_FILE_READ(addrinfo, hostlist_file, &td, addrinfo_read_hostlist_func); @@ -493,9 +440,8 @@ main(int argc, char **argv) if (errno == ENOENT) method = TEST_BUILD_SNAPSHOT; else { - if (debug) - printf("can't access the snapshot file %s\n", - snapshot_file); + printf("can't access the snapshot " + "file %s\n", snapshot_file); rv = -1; goto fin; @@ -504,8 +450,8 @@ main(int argc, char **argv) rv = TEST_SNAPSHOT_FILE_READ(addrinfo, snapshot_file, &td_snap, addrinfo_read_snapshot_func); if (rv != 0) { - if (debug) - printf("error reading snapshot file\n"); + printf("error reading snapshot file: %s\n", + strerror(errno)); goto fin; } } @@ -514,26 +460,97 @@ main(int argc, char **argv) switch (method) { case TEST_GETADDRINFO: if (snapshot_file != NULL) - rv = DO_2PASS_TEST(addrinfo, &td, &td_snap, - compare_addrinfo, NULL); + ATF_CHECK(DO_2PASS_TEST(addrinfo, &td, &td_snap, + compare_addrinfo, NULL) == 0); break; case TEST_BUILD_SNAPSHOT: if (snapshot_file != NULL) { - rv = TEST_SNAPSHOT_FILE_WRITE(addrinfo, snapshot_file, &td, - sdump_addrinfo); + ATF_CHECK(TEST_SNAPSHOT_FILE_WRITE(addrinfo, + snapshot_file, &td, sdump_addrinfo) == 0); } break; default: - rv = 0; break; - }; + } fin: TEST_DATA_DESTROY(addrinfo, &td_snap); TEST_DATA_DESTROY(addrinfo, &td); + free(hostlist_file); free(snapshot_file); - return (rv); +} + +#define HOSTLIST_FILE "mach" +#define RUN_TESTS(tc, snapshot_file, ai_family) do { \ + char *_hostlist_file; \ + char *_snapshot_file; \ + ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \ + atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \ + if (snapshot_file == NULL) \ + _snapshot_file = NULL; \ + else { \ + _snapshot_file = strdup(snapshot_file); \ + ATF_REQUIRE(_snapshot_file != NULL); \ + } \ + run_tests(_hostlist_file, _snapshot_file, ai_family); \ +} while(0) + +ATF_TC_WITHOUT_HEAD(pf_unspec); +ATF_TC_BODY(pf_unspec, tc) +{ + + RUN_TESTS(tc, NULL, AF_UNSPEC); +} + +ATF_TC_WITHOUT_HEAD(pf_unspec_with_snapshot); +ATF_TC_BODY(pf_unspec_with_snapshot, tc) +{ + + RUN_TESTS(tc, "snapshot_ai", AF_UNSPEC); +} + +ATF_TC_WITHOUT_HEAD(pf_inet); +ATF_TC_BODY(pf_inet, tc) +{ + + ATF_REQUIRE_FEATURE("inet"); + RUN_TESTS(tc, NULL, AF_INET); +} +ATF_TC_WITHOUT_HEAD(pf_inet_with_snapshot); +ATF_TC_BODY(pf_inet_with_snapshot, tc) +{ + + ATF_REQUIRE_FEATURE("inet"); + RUN_TESTS(tc, "snapshot_ai4", AF_INET); } +ATF_TC_WITHOUT_HEAD(pf_inet6); +ATF_TC_BODY(pf_inet6, tc) +{ + + ATF_REQUIRE_FEATURE("inet6"); + RUN_TESTS(tc, NULL, AF_INET6); +} + +ATF_TC_WITHOUT_HEAD(pf_inet6_with_snapshot); +ATF_TC_BODY(pf_inet6_with_snapshot, tc) +{ + + ATF_REQUIRE_FEATURE("inet6"); + RUN_TESTS(tc, "snapshot_ai6", AF_INET6); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, pf_unspec); + ATF_TP_ADD_TC(tp, pf_unspec_with_snapshot); + ATF_TP_ADD_TC(tp, pf_inet); + ATF_TP_ADD_TC(tp, pf_inet_with_snapshot); + ATF_TP_ADD_TC(tp, pf_inet6); + ATF_TP_ADD_TC(tp, pf_inet6_with_snapshot); + + return (atf_no_error()); +} diff --git a/tools/regression/lib/libc/nss/test-getgr.c b/lib/libc/tests/nss/getgr_test.c index 0ccebae..d9851ef 100644 --- a/tools/regression/lib/libc/nss/test-getgr.c +++ b/lib/libc/tests/nss/getgr_test.c @@ -29,7 +29,6 @@ __FBSDID("$FreeBSD$"); #include <arpa/inet.h> -#include <assert.h> #include <errno.h> #include <grp.h> #include <stdio.h> @@ -37,17 +36,19 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <stringlist.h> #include <unistd.h> + +#include <atf-c.h> + #include "testutil.h" enum test_methods { - TEST_GETGRENT, - TEST_GETGRNAM, - TEST_GETGRGID, - TEST_GETGRENT_2PASS, - TEST_BUILD_SNAPSHOT + TEST_GETGRENT = 1, + TEST_GETGRNAM = 2, + TEST_GETGRGID = 4, + TEST_GETGRENT_2PASS = 8, + TEST_BUILD_SNAPSHOT = 16, }; -static int debug = 0; static enum test_methods method = TEST_BUILD_SNAPSHOT; DECLARE_TEST_DATA(group) @@ -71,8 +72,6 @@ static int group_test_getgrnam(struct group *, void *); static int group_test_getgrgid(struct group *, void *); static int group_test_getgrent(struct group *, void *); -static void usage(void) __attribute__((__noreturn__)); - IMPLEMENT_TEST_DATA(group) IMPLEMENT_TEST_FILE_SNAPSHOT(group) IMPLEMENT_1PASS_TEST(group) @@ -81,8 +80,8 @@ IMPLEMENT_2PASS_TEST(group) static void clone_group(struct group *dest, struct group const *src) { - assert(dest != NULL); - assert(src != NULL); + ATF_REQUIRE(dest != NULL); + ATF_REQUIRE(src != NULL); char **cp; int members_num; @@ -91,12 +90,12 @@ clone_group(struct group *dest, struct group const *src) if (src->gr_name != NULL) { dest->gr_name = strdup(src->gr_name); - assert(dest->gr_name != NULL); + ATF_REQUIRE(dest->gr_name != NULL); } if (src->gr_passwd != NULL) { dest->gr_passwd = strdup(src->gr_passwd); - assert(dest->gr_passwd != NULL); + ATF_REQUIRE(dest->gr_passwd != NULL); } dest->gr_gid = src->gr_gid; @@ -105,14 +104,12 @@ clone_group(struct group *dest, struct group const *src) for (cp = src->gr_mem; *cp; ++cp) ++members_num; - dest->gr_mem = (char **)malloc( - (members_num + 1) * (sizeof(char *))); - assert(dest->gr_mem != NULL); - memset(dest->gr_mem, 0, (members_num+1) * (sizeof(char *))); + dest->gr_mem = calloc(1, (members_num + 1) * sizeof(char *)); + ATF_REQUIRE(dest->gr_mem != NULL); for (cp = src->gr_mem; *cp; ++cp) { dest->gr_mem[cp - src->gr_mem] = strdup(*cp); - assert(dest->gr_mem[cp - src->gr_mem] != NULL); + ATF_REQUIRE(dest->gr_mem[cp - src->gr_mem] != NULL); } } } @@ -122,7 +119,7 @@ free_group(struct group *grp) { char **cp; - assert(grp != NULL); + ATF_REQUIRE(grp != NULL); free(grp->gr_name); free(grp->gr_passwd); @@ -140,31 +137,31 @@ compare_group(struct group *grp1, struct group *grp2, void *mdata) if (grp1 == grp2) return (0); - if ((grp1 == NULL) || (grp2 == NULL)) + if (grp1 == NULL || grp2 == NULL) goto errfin; - if ((strcmp(grp1->gr_name, grp2->gr_name) != 0) || - (strcmp(grp1->gr_passwd, grp2->gr_passwd) != 0) || - (grp1->gr_gid != grp2->gr_gid)) + if (strcmp(grp1->gr_name, grp2->gr_name) != 0 || + strcmp(grp1->gr_passwd, grp2->gr_passwd) != 0 || + grp1->gr_gid != grp2->gr_gid) goto errfin; c1 = grp1->gr_mem; c2 = grp2->gr_mem; - if ((grp1->gr_mem == NULL) || (grp2->gr_mem == NULL)) + if (grp1->gr_mem == NULL || grp2->gr_mem == NULL) goto errfin; - for (;*c1 && *c2; ++c1, ++c2) + for (; *c1 && *c2; ++c1, ++c2) if (strcmp(*c1, *c2) != 0) goto errfin; - if ((*c1 != '\0') || (*c2 != '\0')) + if (*c1 != '\0' || *c2 != '\0') goto errfin; return 0; errfin: - if ((debug) && (mdata == NULL)) { + if (mdata == NULL) { printf("following structures are not equal:\n"); dump_group(grp1); dump_group(grp2); @@ -211,54 +208,55 @@ group_read_snapshot_func(struct group *grp, char *line) char *s, *ps, *ts; int i; - if (debug) - printf("1 line read from snapshot:\n%s\n", line); + printf("1 line read from snapshot:\n%s\n", line); i = 0; sl = NULL; ps = line; memset(grp, 0, sizeof(struct group)); - while ( (s = strsep(&ps, " ")) != NULL) { + while ((s = strsep(&ps, " ")) != NULL) { switch (i) { - case 0: - grp->gr_name = strdup(s); - assert(grp->gr_name != NULL); + case 0: + grp->gr_name = strdup(s); + ATF_REQUIRE(grp->gr_name != NULL); break; - case 1: - grp->gr_passwd = strdup(s); - assert(grp->gr_passwd != NULL); + case 1: + grp->gr_passwd = strdup(s); + ATF_REQUIRE(grp->gr_passwd != NULL); break; - case 2: - grp->gr_gid = (gid_t)strtol(s, &ts, 10); - if (*ts != '\0') { - free(grp->gr_name); - free(grp->gr_passwd); - return (-1); - } + case 2: + grp->gr_gid = (gid_t)strtol(s, &ts, 10); + if (*ts != '\0') { + free(grp->gr_name); + free(grp->gr_passwd); + grp->gr_name = NULL; + grp->gr_passwd = NULL; + return (-1); + } break; - default: - if (sl == NULL) { - if (strcmp(s, "(null)") == 0) - return (0); + default: + if (sl == NULL) { + if (strcmp(s, "(null)") == 0) + return (0); - sl = sl_init(); - assert(sl != NULL); + sl = sl_init(); + ATF_REQUIRE(sl != NULL); - if (strcmp(s, "nomem") != 0) { - ts = strdup(s); - assert(ts != NULL); - sl_add(sl, ts); - } - } else { + if (strcmp(s, "nomem") != 0) { ts = strdup(s); - assert(ts != NULL); + ATF_REQUIRE(ts != NULL); sl_add(sl, ts); } + } else { + ts = strdup(s); + ATF_REQUIRE(ts != NULL); + sl_add(sl, ts); + } break; - }; + } ++i; } @@ -308,10 +306,8 @@ group_fill_test_data(struct group_test_data *td) static int group_test_correctness(struct group *grp, void *mdata) { - if (debug) { - printf("testing correctness with the following data:\n"); - dump_group(grp); - } + printf("testing correctness with the following data:\n"); + dump_group(grp); if (grp == NULL) goto errfin; @@ -325,13 +321,11 @@ group_test_correctness(struct group *grp, void *mdata) if (grp->gr_mem == NULL) goto errfin; - if (debug) - printf("correct\n"); + printf("correct\n"); return (0); errfin: - if (debug) - printf("incorrect\n"); + printf("incorrect\n"); return (-1); } @@ -352,28 +346,20 @@ group_test_getgrnam(struct group *grp_model, void *mdata) { struct group *grp; - if (debug) { - printf("testing getgrnam() with the following data:\n"); - dump_group(grp_model); - } + printf("testing getgrnam() with the following data:\n"); + dump_group(grp_model); grp = getgrnam(grp_model->gr_name); if (group_test_correctness(grp, NULL) != 0) goto errfin; - if ((compare_group(grp, grp_model, NULL) != 0) && - (group_check_ambiguity((struct group_test_data *)mdata, grp) - !=0)) + if (compare_group(grp, grp_model, NULL) != 0 && + group_check_ambiguity((struct group_test_data *)mdata, grp) != 0) goto errfin; - if (debug) - printf("ok\n"); return (0); errfin: - if (debug) - printf("not ok\n"); - return (-1); } @@ -382,23 +368,16 @@ group_test_getgrgid(struct group *grp_model, void *mdata) { struct group *grp; - if (debug) { - printf("testing getgrgid() with the following data...\n"); - dump_group(grp_model); - } + printf("testing getgrgid() with the following data...\n"); + dump_group(grp_model); grp = getgrgid(grp_model->gr_gid); - if ((group_test_correctness(grp, NULL) != 0) || - ((compare_group(grp, grp_model, NULL) != 0) && - (group_check_ambiguity((struct group_test_data *)mdata, grp) - != 0))) { - if (debug) - printf("not ok\n"); - return (-1); + if (group_test_correctness(grp, NULL) != 0 || + (compare_group(grp, grp_model, NULL) != 0 && + group_check_ambiguity((struct group_test_data *)mdata, grp) != 0)) { + return (-1); } else { - if (debug) - printf("ok\n"); - return (0); + return (0); } } @@ -410,50 +389,11 @@ group_test_getgrent(struct group *grp, void *mdata) return (group_test_correctness(grp, NULL)); } -static void -usage(void) -{ - (void)fprintf(stderr, - "Usage: %s -nge2 [-d] [-s <file>]\n", - getprogname()); - exit(1); -} - -int -main(int argc, char **argv) +static int +run_tests(const char *snapshot_file, enum test_methods method) { struct group_test_data td, td_snap, td_2pass; - char *snapshot_file; int rv; - int c; - - if (argc < 2) - usage(); - - snapshot_file = NULL; - while ((c = getopt(argc, argv, "nge2ds:")) != -1) - switch (c) { - case 'd': - debug++; - break; - case 'n': - method = TEST_GETGRNAM; - break; - case 'g': - method = TEST_GETGRGID; - break; - case 'e': - method = TEST_GETGRENT; - break; - case '2': - method = TEST_GETGRENT_2PASS; - break; - case 's': - snapshot_file = strdup(optarg); - break; - default: - usage(); - } TEST_DATA_INIT(group, &td, clone_group, free_group); TEST_DATA_INIT(group, &td_snap, clone_group, free_group); @@ -462,9 +402,8 @@ main(int argc, char **argv) if (errno == ENOENT) method = TEST_BUILD_SNAPSHOT; else { - if (debug) - printf("can't access the file %s\n", - snapshot_file); + printf("can't access the file %s\n", + snapshot_file); rv = -1; goto fin; @@ -518,17 +457,85 @@ main(int argc, char **argv) break; case TEST_BUILD_SNAPSHOT: if (snapshot_file != NULL) - rv = TEST_SNAPSHOT_FILE_WRITE(group, snapshot_file, &td, - sdump_group); + rv = TEST_SNAPSHOT_FILE_WRITE(group, snapshot_file, &td, + sdump_group); break; default: rv = 0; break; - }; + } fin: TEST_DATA_DESTROY(group, &td_snap); TEST_DATA_DESTROY(group, &td); - free(snapshot_file); + return (rv); } + +#define SNAPSHOT_FILE "snapshot_grp" + +ATF_TC_BODY(getgrent, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getgrent_with_snapshot); +ATF_TC_BODY(getgrent_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getgrent_with_two_pass); +ATF_TC_BODY(getgrent_with_two_pass, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRENT_2PASS) == 0); +} + +ATF_TC_WITHOUT_HEAD(getgrgid); +ATF_TC_BODY(getgrgid, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRGID) == 0); +} + +ATF_TC_WITHOUT_HEAD(getgrgid_with_snapshot); +ATF_TC_BODY(getgrgid_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRGID) == 0); +} + +ATF_TC_WITHOUT_HEAD(getgrnam); +ATF_TC_BODY(getgrnam, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRNAM) == 0); +} + +ATF_TC_WITHOUT_HEAD(getgrnam_with_snapshot); +ATF_TC_BODY(getgrnam_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETGRNAM) == 0); +} + +ATF_TC_WITHOUT_HEAD(getgrent); +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, getgrent); + ATF_TP_ADD_TC(tp, getgrent_with_snapshot); + ATF_TP_ADD_TC(tp, getgrent_with_two_pass); + ATF_TP_ADD_TC(tp, getgrgid); + ATF_TP_ADD_TC(tp, getgrgid_with_snapshot); + ATF_TP_ADD_TC(tp, getgrnam); + ATF_TP_ADD_TC(tp, getgrnam_with_snapshot); + + return (atf_no_error()); +} diff --git a/lib/libc/tests/nss/gethostby_test.c b/lib/libc/tests/nss/gethostby_test.c new file mode 100644 index 0000000..bdeafbc --- /dev/null +++ b/lib/libc/tests/nss/gethostby_test.c @@ -0,0 +1,1506 @@ +/*- + * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#include <errno.h> +#include <netdb.h> +#include <resolv.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stringlist.h> +#include <unistd.h> + +#include <atf-c.h> + +#include "freebsd_test_suite/macros.h" +#include "testutil.h" + +enum test_methods { + TEST_GETHOSTBYNAME2, + TEST_GETHOSTBYADDR, + TEST_GETHOSTBYNAME2_GETADDRINFO, + TEST_GETHOSTBYADDR_GETNAMEINFO, + TEST_BUILD_SNAPSHOT, + TEST_BUILD_ADDR_SNAPSHOT +}; + +static int ipnode_flags = 0; +static int af_type = AF_INET; +static bool use_ipnode_functions; + +DECLARE_TEST_DATA(hostent) +DECLARE_TEST_FILE_SNAPSHOT(hostent) +DECLARE_1PASS_TEST(hostent) +DECLARE_2PASS_TEST(hostent) + +/* These stubs will use gethostby***() or getipnodeby***() functions, + * depending on the use_ipnode_functions global variable value */ +static struct hostent *__gethostbyname2(const char *, int); +static struct hostent *__gethostbyaddr(const void *, socklen_t, int); +static void __freehostent(struct hostent *); + +static void clone_hostent(struct hostent *, struct hostent const *); +static int compare_hostent(struct hostent *, struct hostent *, void *); +static void dump_hostent(struct hostent *); +static void free_hostent(struct hostent *); + +static int is_hostent_equal(struct hostent *, struct addrinfo *); + +static void sdump_hostent(struct hostent *, char *, size_t); +static int hostent_read_hostlist_func(struct hostent *, char *); +static int hostent_read_snapshot_addr(char *, unsigned char *, size_t); +static int hostent_read_snapshot_func(struct hostent *, char *); + +static int hostent_test_correctness(struct hostent *, void *); +static int hostent_test_gethostbyaddr(struct hostent *, void *); +static int hostent_test_getaddrinfo_eq(struct hostent *, void *); +static int hostent_test_getnameinfo_eq(struct hostent *, void *); + +static void usage(void) __attribute__((__noreturn__)); + +IMPLEMENT_TEST_DATA(hostent) +IMPLEMENT_TEST_FILE_SNAPSHOT(hostent) +IMPLEMENT_1PASS_TEST(hostent) +IMPLEMENT_2PASS_TEST(hostent) + +static struct hostent * +__gethostbyname2(const char *name, int af) +{ + struct hostent *he; + int error; + + if (use_ipnode_functions) { + error = 0; + he = getipnodebyname(name, af, ipnode_flags, &error); + if (he == NULL) + errno = error; + } else + he = gethostbyname2(name, af); + + return (he); +} + +static struct hostent * +__gethostbyaddr(const void *addr, socklen_t len, int af) +{ + struct hostent *he; + int error; + + if (use_ipnode_functions) { + error = 0; + he = getipnodebyaddr(addr, len, af, &error); + if (he == NULL) + errno = error; + } else + he = gethostbyaddr(addr, len, af); + + return (he); +} + +static void +__freehostent(struct hostent *he) +{ + + /* NOTE: checking for he != NULL - just in case */ + if (use_ipnode_functions && he != NULL) + freehostent(he); +} + +static void +clone_hostent(struct hostent *dest, struct hostent const *src) +{ + ATF_REQUIRE(dest != NULL); + ATF_REQUIRE(src != NULL); + + char **cp; + int aliases_num; + int addrs_num; + size_t offset; + + memset(dest, 0, sizeof(struct hostent)); + + if (src->h_name != NULL) { + dest->h_name = strdup(src->h_name); + ATF_REQUIRE(dest->h_name != NULL); + } + + dest->h_addrtype = src->h_addrtype; + dest->h_length = src->h_length; + + if (src->h_aliases != NULL) { + aliases_num = 0; + for (cp = src->h_aliases; *cp; ++cp) + ++aliases_num; + + dest->h_aliases = calloc(1, (aliases_num + 1) * + sizeof(char *)); + ATF_REQUIRE(dest->h_aliases != NULL); + + for (cp = src->h_aliases; *cp; ++cp) { + dest->h_aliases[cp - src->h_aliases] = strdup(*cp); + ATF_REQUIRE(dest->h_aliases[cp - src->h_aliases] != NULL); + } + } + + if (src->h_addr_list != NULL) { + addrs_num = 0; + for (cp = src->h_addr_list; *cp; ++cp) + ++addrs_num; + + dest->h_addr_list = calloc(1, (addrs_num + 1) * sizeof(char *)); + ATF_REQUIRE(dest->h_addr_list != NULL); + + for (cp = src->h_addr_list; *cp; ++cp) { + offset = cp - src->h_addr_list; + dest->h_addr_list[offset] = malloc(src->h_length); + ATF_REQUIRE(dest->h_addr_list[offset] != NULL); + memcpy(dest->h_addr_list[offset], + src->h_addr_list[offset], src->h_length); + } + } +} + +static void +free_hostent(struct hostent *ht) +{ + char **cp; + + ATF_REQUIRE(ht != NULL); + + free(ht->h_name); + + if (ht->h_aliases != NULL) { + for (cp = ht->h_aliases; *cp; ++cp) + free(*cp); + free(ht->h_aliases); + } + + if (ht->h_addr_list != NULL) { + for (cp = ht->h_addr_list; *cp; ++cp) + free(*cp); + free(ht->h_addr_list); + } +} + +static int +compare_hostent(struct hostent *ht1, struct hostent *ht2, void *mdata) +{ + char **c1, **c2, **ct, **cb; + int b; + + if (ht1 == ht2) + return 0; + + if (ht1 == NULL || ht2 == NULL) + goto errfin; + + if (ht1->h_name == NULL || ht2->h_name == NULL) + goto errfin; + + if (ht1->h_addrtype != ht2->h_addrtype || + ht1->h_length != ht2->h_length || + strcmp(ht1->h_name, ht2->h_name) != 0) + goto errfin; + + c1 = ht1->h_aliases; + c2 = ht2->h_aliases; + + if ((ht1->h_aliases == NULL || ht2->h_aliases == NULL) && + ht1->h_aliases != ht2->h_aliases) + goto errfin; + + if (c1 != NULL && c2 != NULL) { + cb = c1; + for (;*c1; ++c1) { + b = 0; + for (ct = c2; *ct; ++ct) { + if (strcmp(*c1, *ct) == 0) { + b = 1; + break; + } + } + if (b == 0) { + printf("h1 aliases item can't be found in h2 " + "aliases\n"); + 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) { + printf("h2 aliases item can't be found in h1 " + "aliases\n"); + goto errfin; + } + } + } + + c1 = ht1->h_addr_list; + c2 = ht2->h_addr_list; + + if ((ht1->h_addr_list == NULL || ht2->h_addr_list== NULL) && + ht1->h_addr_list != ht2->h_addr_list) + goto errfin; + + if (c1 != NULL && c2 != NULL) { + 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) { + printf("h1 addresses item can't be found in " + "h2 addresses\n"); + 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) { + printf("h2 addresses item can't be found in " + "h1 addresses\n"); + goto errfin; + } + } + } + + return 0; + +errfin: + if (mdata == NULL) { + printf("following structures are not equal:\n"); + dump_hostent(ht1); + dump_hostent(ht2); + } + + return (-1); +} + +static int +check_addrinfo_for_name(struct addrinfo *ai, char const *name) +{ + struct addrinfo *ai2; + + for (ai2 = ai; ai2 != NULL; ai2 = ai2->ai_next) { + if (strcmp(ai2->ai_canonname, name) == 0) + return (0); + } + + return (-1); +} + +static int +check_addrinfo_for_addr(struct addrinfo *ai, char const *addr, + socklen_t addrlen, int af) +{ + struct addrinfo *ai2; + + for (ai2 = ai; ai2 != NULL; ai2 = ai2->ai_next) { + if (af != ai2->ai_family) + continue; + + switch (af) { + case AF_INET: + if (memcmp(addr, + (void *)&((struct sockaddr_in *)ai2->ai_addr)->sin_addr, + MIN(addrlen, ai2->ai_addrlen)) == 0) + return (0); + break; + case AF_INET6: + if (memcmp(addr, + (void *)&((struct sockaddr_in6 *)ai2->ai_addr)->sin6_addr, + MIN(addrlen, ai2->ai_addrlen)) == 0) + return (0); + break; + default: + break; + } + } + + return (-1); +} + +static int +is_hostent_equal(struct hostent *he, struct addrinfo *ai) +{ + char **cp; + int rv; + +#ifdef DEBUG + printf("checking equality of he and ai\n"); +#endif + + rv = check_addrinfo_for_name(ai, he->h_name); + if (rv != 0) { + printf("not equal - he->h_name couldn't be found\n"); + return (rv); + } + + for (cp = he->h_addr_list; *cp; ++cp) { + rv = check_addrinfo_for_addr(ai, *cp, he->h_length, + he->h_addrtype); + if (rv != 0) { + printf("not equal - one of he->h_addr_list couldn't be found\n"); + return (rv); + } + } + +#ifdef DEBUG + printf("equal\n"); +#endif + + return (0); +} + +static void +sdump_hostent(struct hostent *ht, char *buffer, size_t buflen) +{ + char **cp; + size_t i; + int written; + + written = snprintf(buffer, buflen, "%s %d %d", + ht->h_name, ht->h_addrtype, ht->h_length); + buffer += written; + if (written > buflen) + return; + buflen -= written; + + if (ht->h_aliases != NULL) { + if (*(ht->h_aliases) != NULL) { + for (cp = ht->h_aliases; *cp; ++cp) { + written = snprintf(buffer, buflen, " %s",*cp); + buffer += written; + if (written > buflen) + return; + buflen -= written; + + if (buflen == 0) + return; + } + } else { + written = snprintf(buffer, buflen, " noaliases"); + buffer += written; + if (written > buflen) + return; + buflen -= written; + } + } else { + written = snprintf(buffer, buflen, " (null)"); + buffer += written; + if (written > buflen) + return; + buflen -= written; + } + + written = snprintf(buffer, buflen, " : "); + buffer += written; + if (written > buflen) + return; + buflen -= written; + + if (ht->h_addr_list != NULL) { + if (*(ht->h_addr_list) != NULL) { + for (cp = ht->h_addr_list; *cp; ++cp) { + for (i = 0; i < ht->h_length; ++i ) { + written = snprintf(buffer, buflen, + i + 1 != ht->h_length ? "%d." : "%d", + (unsigned char)(*cp)[i]); + buffer += written; + if (written > buflen) + return; + buflen -= written; + + if (buflen == 0) + return; + } + + if (*(cp + 1) ) { + written = snprintf(buffer, buflen, " "); + buffer += written; + if (written > buflen) + return; + buflen -= written; + } + } + } else { + written = snprintf(buffer, buflen, " noaddrs"); + buffer += written; + if (written > buflen) + return; + buflen -= written; + } + } else { + written = snprintf(buffer, buflen, " (null)"); + buffer += written; + if (written > buflen) + return; + buflen -= written; + } +} + +static int +hostent_read_hostlist_func(struct hostent *he, char *line) +{ + struct hostent *result; + int rv; + +#ifdef DEBUG + printf("resolving %s: ", line); +#endif + result = __gethostbyname2(line, af_type); + if (result != NULL) { +#ifdef DEBUG + printf("found\n"); +#endif + + rv = hostent_test_correctness(result, NULL); + if (rv != 0) { + __freehostent(result); + return (rv); + } + + clone_hostent(he, result); + __freehostent(result); + } else { +#ifdef DEBUG + printf("not found\n"); +#endif + memset(he, 0, sizeof(struct hostent)); + he->h_name = strdup(line); + ATF_REQUIRE(he->h_name != NULL); + } + return (0); +} + +static int +hostent_read_snapshot_addr(char *addr, unsigned char *result, size_t len) +{ + char *s, *ps, *ts; + + ps = addr; + while ( (s = strsep(&ps, ".")) != NULL) { + if (len == 0) + return (-1); + + *result = (unsigned char)strtol(s, &ts, 10); + ++result; + if (*ts != '\0') + return (-1); + + --len; + } + if (len != 0) + return (-1); + else + return (0); +} + +static int +hostent_read_snapshot_func(struct hostent *ht, char *line) +{ + StringList *sl1, *sl2; + char *s, *ps, *ts; + int i, rv; + +#ifdef DEBUG + printf("1 line read from snapshot:\n%s\n", line); +#endif + + rv = 0; + i = 0; + sl1 = sl2 = NULL; + ps = line; + memset(ht, 0, sizeof(struct hostent)); + while ((s = strsep(&ps, " ")) != NULL) { + switch (i) { + case 0: + ht->h_name = strdup(s); + ATF_REQUIRE(ht->h_name != NULL); + break; + + case 1: + ht->h_addrtype = (int)strtol(s, &ts, 10); + if (*ts != '\0') + goto fin; + break; + + case 2: + ht->h_length = (int)strtol(s, &ts, 10); + if (*ts != '\0') + goto fin; + break; + + case 3: + if (sl1 == NULL) { + if (strcmp(s, "(null)") == 0) + return (0); + + sl1 = sl_init(); + ATF_REQUIRE(sl1 != NULL); + + if (strcmp(s, "noaliases") != 0) { + ts = strdup(s); + ATF_REQUIRE(ts != NULL); + sl_add(sl1, ts); + } + } else { + if (strcmp(s, ":") == 0) + ++i; + else { + ts = strdup(s); + ATF_REQUIRE(ts != NULL); + sl_add(sl1, ts); + } + } + break; + + case 4: + if (sl2 == NULL) { + if (strcmp(s, "(null)") == 0) + return (0); + + sl2 = sl_init(); + ATF_REQUIRE(sl2 != NULL); + + if (strcmp(s, "noaddrs") != 0) { + ts = calloc(1, ht->h_length); + ATF_REQUIRE(ts != NULL); + rv = hostent_read_snapshot_addr(s, + (unsigned char *)ts, + ht->h_length); + sl_add(sl2, ts); + if (rv != 0) + goto fin; + } + } else { + ts = calloc(1, ht->h_length); + ATF_REQUIRE(ts != NULL); + rv = hostent_read_snapshot_addr(s, + (unsigned char *)ts, ht->h_length); + sl_add(sl2, ts); + if (rv != 0) + goto fin; + } + break; + default: + break; + } + + if (i != 3 && i != 4) + ++i; + } + +fin: + if (sl1 != NULL) { + sl_add(sl1, NULL); + ht->h_aliases = sl1->sl_str; + } + if (sl2 != NULL) { + sl_add(sl2, NULL); + ht->h_addr_list = sl2->sl_str; + } + + if ((i != 4) || (rv != 0)) { + free_hostent(ht); + memset(ht, 0, sizeof(struct hostent)); + return (-1); + } + + /* NOTE: is it a dirty hack or not? */ + free(sl1); + free(sl2); + return (0); +} + +static void +dump_hostent(struct hostent *result) +{ + if (result != NULL) { + char buffer[1024]; + sdump_hostent(result, buffer, sizeof(buffer)); + printf("%s\n", buffer); + } else + printf("(null)\n"); +} + +static int +hostent_test_correctness(struct hostent *ht, void *mdata) +{ + +#ifdef DEBUG + printf("testing correctness with the following data:\n"); + dump_hostent(ht); +#endif + + if (ht == NULL) + goto errfin; + + if (ht->h_name == NULL) + goto errfin; + + if (!((ht->h_addrtype >= 0) && (ht->h_addrtype < AF_MAX))) + goto errfin; + + if ((ht->h_length != sizeof(struct in_addr)) && + (ht->h_length != sizeof(struct in6_addr))) + goto errfin; + + if (ht->h_aliases == NULL) + goto errfin; + + if (ht->h_addr_list == NULL) + goto errfin; + +#ifdef DEBUG + printf("correct\n"); +#endif + + return (0); +errfin: + printf("incorrect\n"); + + return (-1); +} + +static int +hostent_test_gethostbyaddr(struct hostent *he, void *mdata) +{ + struct hostent *result; + struct hostent_test_data *addr_test_data; + int rv; + + addr_test_data = (struct hostent_test_data *)mdata; + + /* We should omit unresolved hostents */ + if (he->h_addr_list != NULL) { + char **cp; + for (cp = he->h_addr_list; *cp; ++cp) { +#ifdef DEBUG + printf("doing reverse lookup for %s\n", he->h_name); +#endif + + result = __gethostbyaddr(*cp, he->h_length, + he->h_addrtype); + if (result == NULL) { +#ifdef DEBUG + printf("%s: warning: reverse lookup failed " + "for %s: %s\n", __func__, he->h_name, + strerror(errno)); +#endif + continue; + } + rv = hostent_test_correctness(result, NULL); + if (rv != 0) { + __freehostent(result); + return (rv); + } + + if (addr_test_data != NULL) + TEST_DATA_APPEND(hostent, addr_test_data, + result); + + __freehostent(result); + } + } + + return (0); +} + +static int +hostent_test_getaddrinfo_eq(struct hostent *he, void *mdata) +{ + struct addrinfo *ai, hints; + int rv; + + ai = NULL; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = af_type; + hints.ai_flags = AI_CANONNAME; + + printf("using getaddrinfo() to resolve %s\n", he->h_name); + + /* struct hostent *he was not resolved */ + if (he->h_addr_list == NULL) { + /* We can be sure that he->h_name is not NULL */ + rv = getaddrinfo(he->h_name, NULL, &hints, &ai); + if (rv == 0) { + printf("not ok - shouldn't have been resolved\n"); + return (-1); + } + } else { + rv = getaddrinfo(he->h_name, NULL, &hints, &ai); + if (rv != 0) { + printf("not ok - should have been resolved\n"); + return (-1); + } + + rv = is_hostent_equal(he, ai); + if (rv != 0) { + printf("not ok - addrinfo and hostent are not equal\n"); + return (-1); + } + + } + + return (0); +} + +static int +hostent_test_getnameinfo_eq(struct hostent *he, void *mdata) +{ + char **cp; + char buffer[NI_MAXHOST]; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + struct sockaddr *saddr; + struct hostent *result; + int i, rv; + + if (he->h_addr_list == NULL) + return (0); + + for (cp = he->h_addr_list; *cp; ++cp) { +#ifdef DEBUG + printf("doing reverse lookup for %s\n", he->h_name); +#endif + result = __gethostbyaddr(*cp, he->h_length, + he->h_addrtype); + if (result != NULL) { + rv = hostent_test_correctness(result, NULL); + if (rv != 0) { + __freehostent(result); + return (rv); + } + } else + printf("%s: warning: reverse lookup failed " + "for %s: %s\n", __func__, he->h_name, + strerror(errno)); + + switch (he->h_addrtype) { + case AF_INET: + memset(&sin, 0, sizeof(struct sockaddr_in)); + sin.sin_len = sizeof(struct sockaddr_in); + sin.sin_family = AF_INET; + memcpy(&sin.sin_addr, *cp, he->h_length); + + saddr = (struct sockaddr *)&sin; + break; + case AF_INET6: + memset(&sin6, 0, sizeof(struct sockaddr_in6)); + sin6.sin6_len = sizeof(struct sockaddr_in6); + sin6.sin6_family = AF_INET6; + memcpy(&sin6.sin6_addr, *cp, he->h_length); + + saddr = (struct sockaddr *)&sin6; + break; + default: + printf("warning: %d family is unsupported\n", + he->h_addrtype); + continue; + } + + ATF_REQUIRE(saddr != NULL); + rv = getnameinfo(saddr, saddr->sa_len, buffer, + sizeof(buffer), NULL, 0, NI_NAMEREQD); + + if (rv != 0 && result != NULL) { + printf("getnameinfo() didn't make the reverse " + "lookup, when it should have (%s)\n", + gai_strerror(rv)); + return (rv); + } + + if (rv == 0 && result == NULL) { + printf("getnameinfo() made the " + "reverse lookup, when it shouldn't have\n"); + return (rv); + } + + if (rv != 0 && result == NULL) { +#ifdef DEBUG + printf("both getnameinfo() and ***byaddr() failed as " + "expected\n"); +#endif + continue; + } + +#ifdef DEBUG + printf("comparing %s with %s\n", result->h_name, + buffer); +#endif + + /* + * An address might reverse resolve to hostname alias or the + * official hostname, e.g. moon.vub.ac.be. + */ + bool found_a_match; + + if (strcmp(result->h_name, buffer) == 0) { + found_a_match = true; +#ifdef DEBUG + printf("matched official hostname\n"); +#endif + } else { + for (i = 0; i < nitems(result->h_aliases); i++) { + printf("[%d] resolved: %s\n", i, + result->h_aliases[i]); + if (strcmp(result->h_aliases[i], + buffer) == 0) { + printf("matched hostname alias\n"); + found_a_match = true; + break; + } + } + } + __freehostent(result); + + if (found_a_match) { +#ifdef DEBUG + printf("getnameinfo() and ***byaddr() results are " + "equal\n"); +#endif + } else { + printf("getnameinfo() and ***byaddr() results are not " + "equal for %s\n", he->h_name); + return (-1); + } + } + + return (0); +} + +int +run_tests(const char *hostlist_file, const char *snapshot_file, int af_type, + enum test_methods method, bool use_ipv6_mapping) +{ + struct hostent_test_data td, td_addr, td_snap; + res_state statp; + int rv = -2; + + switch (af_type) { + case AF_INET: + ATF_REQUIRE_FEATURE("inet"); + ATF_REQUIRE(!use_ipv6_mapping); + break; + case AF_INET6: + ATF_REQUIRE_FEATURE("inet6"); + break; + default: + atf_tc_fail("unhandled address family: %d", af_type); + break; + } + + if (!use_ipnode_functions) { + statp = __res_state(); + if (statp == NULL || ((statp->options & RES_INIT) == 0 && + res_ninit(statp) == -1)) { + printf("error: can't init res_state\n"); + + return (-1); + } + + if (use_ipv6_mapping) + 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); + TEST_DATA_INIT(hostent, &td_snap, clone_hostent, free_hostent); + + if (access(hostlist_file, R_OK) != 0) { + printf("can't access the hostlist file %s\n", hostlist_file); + rv = -1; + goto fin; + } + +#ifdef DEBUG + printf("building host lists from %s\n", hostlist_file); +#endif + + rv = TEST_SNAPSHOT_FILE_READ(hostent, hostlist_file, &td, + hostent_read_hostlist_func); + if (rv != 0) { + printf("failed to read the host list file: %s\n", + hostlist_file); + goto fin; + } + + if (snapshot_file != NULL) { + if (access(snapshot_file, W_OK | R_OK) != 0) { + if (errno == ENOENT) { + if (method != TEST_GETHOSTBYADDR) + method = TEST_BUILD_SNAPSHOT; + else + method = TEST_BUILD_ADDR_SNAPSHOT; + } else { + printf("can't access the snapshot file %s\n", + snapshot_file); + rv = -1; + goto fin; + } + } else { + rv = TEST_SNAPSHOT_FILE_READ(hostent, snapshot_file, + &td_snap, hostent_read_snapshot_func); + if (rv != 0) { + printf("error reading snapshot file\n"); + goto fin; + } + } + } + + switch (method) { + case TEST_GETHOSTBYNAME2: + if (snapshot_file != NULL) + rv = DO_2PASS_TEST(hostent, &td, &td_snap, + compare_hostent, NULL); + break; + case TEST_GETHOSTBYADDR: + rv = DO_1PASS_TEST(hostent, &td, + hostent_test_gethostbyaddr, (void *)&td_addr); + if (rv != 0) + goto fin; + + if (snapshot_file != NULL) + rv = DO_2PASS_TEST(hostent, &td_addr, &td_snap, + compare_hostent, NULL); + break; + case TEST_GETHOSTBYNAME2_GETADDRINFO: + rv = DO_1PASS_TEST(hostent, &td, + hostent_test_getaddrinfo_eq, NULL); + break; + case TEST_GETHOSTBYADDR_GETNAMEINFO: + rv = DO_1PASS_TEST(hostent, &td, + hostent_test_getnameinfo_eq, NULL); + break; + case TEST_BUILD_SNAPSHOT: + if (snapshot_file != NULL) { + rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file, + &td, sdump_hostent); + } + break; + case TEST_BUILD_ADDR_SNAPSHOT: + if (snapshot_file != NULL) { + rv = DO_1PASS_TEST(hostent, &td, + hostent_test_gethostbyaddr, (void *)&td_addr); + if (rv != 0) + goto fin; + rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file, + &td_addr, sdump_hostent); + } + break; + default: + rv = 0; + break; + } + +fin: + TEST_DATA_DESTROY(hostent, &td_snap); + TEST_DATA_DESTROY(hostent, &td_addr); + TEST_DATA_DESTROY(hostent, &td); + + return (rv); +} + +#define HOSTLIST_FILE "mach" + +#define _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \ +do { \ + char *_hostlist_file; \ + char *_snapshot_file; \ + ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \ + atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \ + if (snapshot_file == NULL) \ + _snapshot_file = NULL; \ + else { \ + _snapshot_file = strdup(snapshot_file); \ + ATF_REQUIRE(_snapshot_file != NULL); \ + } \ + ATF_REQUIRE(run_tests(_hostlist_file, _snapshot_file, af_type, \ + method, use_ipv6_mapping) == 0); \ +} while(0) + +#define RUN_HOST_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \ +do { \ + use_ipnode_functions = false; \ + _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \ +} while(0) + +#define RUN_IPNODE_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \ +do { \ + use_ipnode_functions = true; \ + _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \ +} while(0) + +ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv4); +ATF_TC_BODY(gethostbyaddr_ipv4, tc) +{ + + RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv4_with_snapshot); +ATF_TC_BODY(gethostbyaddr_ipv4_with_snapshot, tc) +{ + + RUN_HOST_TESTS(tc, "snapshot_htaddr4", AF_INET, TEST_GETHOSTBYADDR, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6); +ATF_TC_BODY(gethostbyaddr_ipv6, tc) +{ + + RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_AI_V4MAPPED); +ATF_TC_BODY(gethostbyaddr_ipv6_AI_V4MAPPED, tc) +{ + + ipnode_flags = AI_V4MAPPED; + RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true); +} + +ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_with_snapshot); +ATF_TC_BODY(gethostbyaddr_ipv6_with_snapshot, tc) +{ + + RUN_HOST_TESTS(tc, "snapshot_htaddr6", AF_INET6, TEST_GETHOSTBYADDR, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED); +ATF_TC_BODY(gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED, tc) +{ + + ipnode_flags = AI_V4MAPPED; + RUN_HOST_TESTS(tc, "snapshot_htaddr6map", AF_INET6, TEST_GETHOSTBYADDR, true); +} + +ATF_TC_WITHOUT_HEAD(gethostbyname2_getaddrinfo_ipv4); +ATF_TC_BODY(gethostbyname2_getaddrinfo_ipv4, tc) +{ + + RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2_GETADDRINFO, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyname2_getaddrinfo_ipv6); +ATF_TC_BODY(gethostbyname2_getaddrinfo_ipv6, tc) +{ + + RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2_GETADDRINFO, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyaddr_getnameinfo_ipv4); +ATF_TC_BODY(gethostbyaddr_getnameinfo_ipv4, tc) +{ + + RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR_GETNAMEINFO, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyaddr_getnameinfo_ipv6); +ATF_TC_BODY(gethostbyaddr_getnameinfo_ipv6, tc) +{ + + RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR_GETNAMEINFO, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv4); +ATF_TC_BODY(gethostbyname2_ipv4, tc) +{ + + RUN_HOST_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv4_with_snapshot); +ATF_TC_BODY(gethostbyname2_ipv4_with_snapshot, tc) +{ + + RUN_HOST_TESTS(tc, "snapshot_htname4", AF_INET, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6); +ATF_TC_BODY(gethostbyname2_ipv6, tc) +{ + + RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_AI_V4MAPPED); +ATF_TC_BODY(gethostbyname2_ipv6_AI_V4MAPPED, tc) +{ + + ipnode_flags = AI_V4MAPPED; + RUN_HOST_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true); +} + +ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_with_snapshot); +ATF_TC_BODY(gethostbyname2_ipv6_with_snapshot, tc) +{ + + RUN_HOST_TESTS(tc, "snapshot_htname6", AF_INET6, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED); +ATF_TC_BODY(gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED, tc) +{ + + ipnode_flags = AI_V4MAPPED; + RUN_HOST_TESTS(tc, "snapshot_htname6map", AF_INET6, TEST_GETHOSTBYNAME2, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv4); +ATF_TC_BODY(getipnodebyaddr_ipv4, tc) +{ + + RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv4_with_snapshot); +ATF_TC_BODY(getipnodebyaddr_ipv4_with_snapshot, tc) +{ + + RUN_IPNODE_TESTS(tc, "snapshot_ipnodeaddr4", AF_INET, TEST_GETHOSTBYADDR, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_getnameinfo_ipv4); +ATF_TC_BODY(getipnodebyaddr_getnameinfo_ipv4, tc) +{ + + RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYADDR_GETNAMEINFO, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6); +ATF_TC_BODY(getipnodebyaddr_ipv6, tc) +{ + + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED); +ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED, tc) +{ + + ipnode_flags = AI_V4MAPPED; + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG); +ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG; + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL); +ATF_TC_BODY(getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG | AI_ALL; + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot); +ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot, tc) +{ + + RUN_IPNODE_TESTS(tc, "snapshot_ipnodeaddr6", AF_INET6, TEST_GETHOSTBYADDR, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED); +ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED, tc) +{ + + ipnode_flags = AI_V4MAPPED; + RUN_IPNODE_TESTS(tc, + "snapshot_ipnodeaddr6_AI_V4MAPPED", AF_INET6, + TEST_GETHOSTBYADDR, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG); +ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG; + RUN_IPNODE_TESTS(tc, + "snapshot_ipnodeaddr6_AI_V4MAPPED_CFG", AF_INET6, + TEST_GETHOSTBYADDR, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL); +ATF_TC_BODY(getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG | AI_ALL; + RUN_IPNODE_TESTS(tc, + "snapshot_ipnodeaddr6_AI_V4MAPPED_CFG_AI_ALL", AF_INET6, + TEST_GETHOSTBYADDR, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyaddr_getnameinfo_ipv6); +ATF_TC_BODY(getipnodebyaddr_getnameinfo_ipv6, tc) +{ + + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYADDR_GETNAMEINFO, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4); +ATF_TC_BODY(getipnodebyname_ipv4, tc) +{ + + RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_with_snapshot); +ATF_TC_BODY(getipnodebyname_ipv4_with_snapshot, tc) +{ + + RUN_IPNODE_TESTS(tc, "snapshot_ipnodename4", AF_INET, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_AI_ADDRCONFIG); +ATF_TC_BODY(getipnodebyname_ipv4_AI_ADDRCONFIG, tc) +{ + + ipnode_flags = AI_ADDRCONFIG; + RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG); +ATF_TC_BODY(getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG, tc) +{ + + ipnode_flags = AI_ADDRCONFIG; + RUN_IPNODE_TESTS(tc, "snapshot_ipnodename4_AI_ADDRCONFIG", AF_INET, + TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_getaddrinfo_ipv4); +ATF_TC_BODY(getipnodebyname_getaddrinfo_ipv4, tc) +{ + + RUN_IPNODE_TESTS(tc, NULL, AF_INET, TEST_GETHOSTBYNAME2_GETADDRINFO, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6); +ATF_TC_BODY(getipnodebyname_ipv6, tc) +{ + + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot); +ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot, tc) +{ + + RUN_IPNODE_TESTS(tc, "snapshot_ipnodename6", AF_INET6, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_ADDRCONFIG); +ATF_TC_BODY(getipnodebyname_ipv6_AI_ADDRCONFIG, tc) +{ + + ipnode_flags = AI_ADDRCONFIG; + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED); +ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED, tc) +{ + + ipnode_flags = AI_V4MAPPED; + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG); +ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG; + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG); +ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG | AI_ADDRCONFIG; + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL); +ATF_TC_BODY(getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG | AI_ALL; + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED); +ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED, tc) +{ + + ipnode_flags = AI_V4MAPPED; + RUN_IPNODE_TESTS(tc, + "snapshot_ipnodename6_AI_V4MAPPED", AF_INET6, + TEST_GETHOSTBYNAME2, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG); +ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG; + RUN_IPNODE_TESTS(tc, + "snapshot_ipnodename6_AI_V4MAPPED_CFG", AF_INET6, + TEST_GETHOSTBYNAME2, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG); +ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG | AI_ADDRCONFIG; + RUN_IPNODE_TESTS(tc, + "snapshot_ipnodename6_AI_V4MAPPED_CFG_AI_ADDRCONFIG", AF_INET6, + TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL); +ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL, tc) +{ + + ipnode_flags = AI_V4MAPPED_CFG | AI_ALL; + RUN_IPNODE_TESTS(tc, + "snapshot_ipnodename6_AI_V4MAPPED_CFG_AI_ALL", AF_INET6, + TEST_GETHOSTBYNAME2, true); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG); +ATF_TC_BODY(getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG, tc) +{ + + ipnode_flags = AI_ADDRCONFIG; + RUN_IPNODE_TESTS(tc, "snapshot_ipnodename6_AI_ADDRCONFIG", AF_INET6, + TEST_GETHOSTBYNAME2, false); +} + +ATF_TC_WITHOUT_HEAD(getipnodebyname_getaddrinfo_ipv6); +ATF_TC_BODY(getipnodebyname_getaddrinfo_ipv6, tc) +{ + + RUN_IPNODE_TESTS(tc, NULL, AF_INET6, TEST_GETHOSTBYNAME2_GETADDRINFO, false); +} + +ATF_TP_ADD_TCS(tp) +{ + + /* gethostbyaddr */ + ATF_TP_ADD_TC(tp, gethostbyaddr_ipv4); + ATF_TP_ADD_TC(tp, gethostbyaddr_ipv4_with_snapshot); + ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6); + ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_AI_V4MAPPED); /* XXX */ + ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_with_snapshot); + ATF_TP_ADD_TC(tp, gethostbyaddr_ipv6_with_snapshot_AI_V4MAPPED); + ATF_TP_ADD_TC(tp, gethostbyaddr_getnameinfo_ipv4); + ATF_TP_ADD_TC(tp, gethostbyaddr_getnameinfo_ipv6); + + /* gethostbyname2 */ + ATF_TP_ADD_TC(tp, gethostbyname2_getaddrinfo_ipv4); + ATF_TP_ADD_TC(tp, gethostbyname2_getaddrinfo_ipv6); + ATF_TP_ADD_TC(tp, gethostbyname2_ipv4); + ATF_TP_ADD_TC(tp, gethostbyname2_ipv4_with_snapshot); + ATF_TP_ADD_TC(tp, gethostbyname2_ipv6); + ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_AI_V4MAPPED); + ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_with_snapshot); + ATF_TP_ADD_TC(tp, gethostbyname2_ipv6_with_snapshot_AI_V4MAPPED); + + /* getipnodebyaddr */ + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv4); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv4_with_snapshot); + ATF_TP_ADD_TC(tp, getipnodebyaddr_getnameinfo_ipv4); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED_CFG); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_AI_V4MAPPED_CFG_AI_ALL); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG); + ATF_TP_ADD_TC(tp, getipnodebyaddr_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL); + ATF_TP_ADD_TC(tp, getipnodebyaddr_getnameinfo_ipv6); + + /* getipnodebyname */ + ATF_TP_ADD_TC(tp, getipnodebyname_ipv4); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_with_snapshot); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_AI_ADDRCONFIG); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv4_with_snapshot_AI_ADDRCONFIG); + ATF_TP_ADD_TC(tp, getipnodebyname_getaddrinfo_ipv4); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_ADDRCONFIG); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ADDRCONFIG); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_AI_V4MAPPED_CFG_AI_ALL); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ADDRCONFIG); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_V4MAPPED_CFG_AI_ALL); + ATF_TP_ADD_TC(tp, getipnodebyname_ipv6_with_snapshot_AI_ADDRCONFIG); + ATF_TP_ADD_TC(tp, getipnodebyname_getaddrinfo_ipv6); + + return (atf_no_error()); +} diff --git a/tools/regression/lib/libc/nss/test-getproto.c b/lib/libc/tests/nss/getproto_test.c index a3ba271..fdb6804 100644 --- a/tools/regression/lib/libc/nss/test-getproto.c +++ b/lib/libc/tests/nss/getproto_test.c @@ -37,6 +37,9 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <stringlist.h> #include <unistd.h> + +#include <atf-c.h> + #include "testutil.h" enum test_methods { @@ -47,9 +50,6 @@ enum test_methods { TEST_BUILD_SNAPSHOT }; -static int debug = 0; -static enum test_methods method = TEST_BUILD_SNAPSHOT; - DECLARE_TEST_DATA(protoent) DECLARE_TEST_FILE_SNAPSHOT(protoent) DECLARE_1PASS_TEST(protoent) @@ -71,8 +71,6 @@ static int protoent_test_getprotobyname(struct protoent *, void *); static int protoent_test_getprotobynumber(struct protoent *, void *); static int protoent_test_getprotoent(struct protoent *, void *); -static void usage(void) __attribute__((__noreturn__)); - IMPLEMENT_TEST_DATA(protoent) IMPLEMENT_TEST_FILE_SNAPSHOT(protoent) IMPLEMENT_1PASS_TEST(protoent) @@ -101,9 +99,8 @@ clone_protoent(struct protoent *dest, struct protoent const *src) for (cp = src->p_aliases; *cp; ++cp) ++aliases_num; - dest->p_aliases = (char **)malloc((aliases_num+1) * (sizeof(char *))); + dest->p_aliases = calloc(1, (aliases_num+1) * sizeof(char *)); assert(dest->p_aliases != NULL); - memset(dest->p_aliases, 0, (aliases_num+1) * (sizeof(char *))); for (cp = src->p_aliases; *cp; ++cp) { dest->p_aliases[cp - src->p_aliases] = strdup(*cp); @@ -157,7 +154,7 @@ compare_protoent(struct protoent *pe1, struct protoent *pe2, void *mdata) return 0; errfin: - if ((debug) && (mdata == NULL)) { + if (mdata == NULL) { printf("following structures are not equal:\n"); dump_protoent(pe1); dump_protoent(pe2); @@ -204,8 +201,7 @@ protoent_read_snapshot_func(struct protoent *pe, char *line) char *s, *ps, *ts; int i; - if (debug) - printf("1 line read from snapshot:\n%s\n", line); + printf("1 line read from snapshot:\n%s\n", line); i = 0; sl = NULL; @@ -245,7 +241,7 @@ protoent_read_snapshot_func(struct protoent *pe, char *line) sl_add(sl, ts); } break; - }; + } ++i; } @@ -294,10 +290,8 @@ protoent_fill_test_data(struct protoent_test_data *td) static int protoent_test_correctness(struct protoent *pe, void *mdata) { - if (debug) { - printf("testing correctness with the following data:\n"); - dump_protoent(pe); - } + printf("testing correctness with the following data:\n"); + dump_protoent(pe); if (pe == NULL) goto errfin; @@ -311,13 +305,11 @@ protoent_test_correctness(struct protoent *pe, void *mdata) if (pe->p_aliases == NULL) goto errfin; - if (debug) - printf("correct\n"); + printf("correct\n"); return (0); errfin: - if (debug) - printf("incorrect\n"); + printf("incorrect\n"); return (-1); } @@ -341,10 +333,8 @@ protoent_test_getprotobyname(struct protoent *pe_model, void *mdata) char **alias; struct protoent *pe; - if (debug) { - printf("testing getprotobyname() with the following data:\n"); - dump_protoent(pe_model); - } + printf("testing getprotobyname() with the following data:\n"); + dump_protoent(pe_model); pe = getprotobyname(pe_model->p_name); if (protoent_test_correctness(pe, NULL) != 0) @@ -367,13 +357,11 @@ protoent_test_getprotobyname(struct protoent *pe_model, void *mdata) goto errfin; } - if (debug) - printf("ok\n"); + printf("ok\n"); return (0); errfin: - if (debug) - printf("not ok\n"); + printf("not ok\n"); return (-1); } @@ -383,23 +371,19 @@ protoent_test_getprotobynumber(struct protoent *pe_model, void *mdata) { struct protoent *pe; - if (debug) { - printf("testing getprotobyport() with the following data...\n"); - dump_protoent(pe_model); - } + printf("testing getprotobyport() with the following data...\n"); + dump_protoent(pe_model); pe = getprotobynumber(pe_model->p_proto); if ((protoent_test_correctness(pe, NULL) != 0) || ((compare_protoent(pe, pe_model, NULL) != 0) && (protoent_check_ambiguity((struct protoent_test_data *)mdata, pe) != 0))) { - if (debug) printf("not ok\n"); - return (-1); + return (-1); } else { - if (debug) printf("ok\n"); - return (0); + return (0); } } @@ -411,50 +395,11 @@ protoent_test_getprotoent(struct protoent *pe, void *mdata) return (protoent_test_correctness(pe, NULL)); } -static void -usage(void) -{ - (void)fprintf(stderr, - "Usage: %s -nve2 [-d] [-s <file>]\n", - getprogname()); - exit(1); -} - int -main(int argc, char **argv) +run_tests(const char *snapshot_file, enum test_methods method) { struct protoent_test_data td, td_snap, td_2pass; - char *snapshot_file; int rv; - int c; - - if (argc < 2) - usage(); - - snapshot_file = NULL; - while ((c = getopt(argc, argv, "nve2ds:")) != -1) - switch (c) { - case 'd': - debug++; - break; - case 'n': - method = TEST_GETPROTOBYNAME; - break; - case 'v': - method = TEST_GETPROTOBYNUMBER; - break; - case 'e': - method = TEST_GETPROTOENT; - break; - case '2': - method = TEST_GETPROTOENT_2PASS; - break; - case 's': - snapshot_file = strdup(optarg); - break; - default: - usage(); - } TEST_DATA_INIT(protoent, &td, clone_protoent, free_protoent); TEST_DATA_INIT(protoent, &td_snap, clone_protoent, free_protoent); @@ -463,9 +408,8 @@ main(int argc, char **argv) if (errno == ENOENT) method = TEST_BUILD_SNAPSHOT; else { - if (debug) - printf("can't access the file %s\n", - snapshot_file); + printf("can't access the file %s\n", + snapshot_file); rv = -1; goto fin; @@ -510,27 +454,103 @@ main(int argc, char **argv) compare_protoent, NULL); break; case TEST_GETPROTOENT_2PASS: - TEST_DATA_INIT(protoent, &td_2pass, clone_protoent, - free_protoent); - rv = protoent_fill_test_data(&td_2pass); - if (rv != -1) - rv = DO_2PASS_TEST(protoent, &td, &td_2pass, - compare_protoent, NULL); - TEST_DATA_DESTROY(protoent, &td_2pass); + TEST_DATA_INIT(protoent, &td_2pass, clone_protoent, + free_protoent); + rv = protoent_fill_test_data(&td_2pass); + if (rv != -1) + rv = DO_2PASS_TEST(protoent, &td, &td_2pass, + compare_protoent, NULL); + TEST_DATA_DESTROY(protoent, &td_2pass); break; case TEST_BUILD_SNAPSHOT: if (snapshot_file != NULL) - rv = TEST_SNAPSHOT_FILE_WRITE(protoent, snapshot_file, &td, - sdump_protoent); + rv = TEST_SNAPSHOT_FILE_WRITE(protoent, snapshot_file, + &td, sdump_protoent); break; default: rv = 0; break; - }; + } fin: TEST_DATA_DESTROY(protoent, &td_snap); TEST_DATA_DESTROY(protoent, &td); - free(snapshot_file); + return (rv); } + +#define SNAPSHOT_FILE "snapshot_proto" + +ATF_TC_WITHOUT_HEAD(build_snapshot); +ATF_TC_BODY(build_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getprotoent); +ATF_TC_BODY(getprotoent, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getprotoent_with_snapshot); +ATF_TC_BODY(getprotoent_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getprotoent_with_two_pass); +ATF_TC_BODY(getprotoent_with_two_pass, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOENT_2PASS) == 0); +} + +ATF_TC_WITHOUT_HEAD(getprotobyname); +ATF_TC_BODY(getprotobyname, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOBYNAME) == 0); +} + +ATF_TC_WITHOUT_HEAD(getprotobyname_with_snapshot); +ATF_TC_BODY(getprotobyname_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOBYNAME) == 0); +} + +ATF_TC_WITHOUT_HEAD(getprotobynumber); +ATF_TC_BODY(getprotobynumber, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETPROTOBYNUMBER) == 0); +} + +ATF_TC_WITHOUT_HEAD(getprotobynumber_with_snapshot); +ATF_TC_BODY(getprotobynumber_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPROTOBYNUMBER) == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, build_snapshot); + ATF_TP_ADD_TC(tp, getprotoent); + ATF_TP_ADD_TC(tp, getprotoent_with_snapshot); + ATF_TP_ADD_TC(tp, getprotoent_with_two_pass); + ATF_TP_ADD_TC(tp, getprotobyname); + ATF_TP_ADD_TC(tp, getprotobyname_with_snapshot); + ATF_TP_ADD_TC(tp, getprotobynumber); + ATF_TP_ADD_TC(tp, getprotobynumber_with_snapshot); + + return (atf_no_error()); +} diff --git a/tools/regression/lib/libc/nss/test-getpw.c b/lib/libc/tests/nss/getpw_test.c index a0b348d..98f890f 100644 --- a/tools/regression/lib/libc/nss/test-getpw.c +++ b/lib/libc/tests/nss/getpw_test.c @@ -28,13 +28,15 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <assert.h> #include <errno.h> #include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> + +#include <atf-c.h> + #include "testutil.h" enum test_methods { @@ -45,7 +47,6 @@ enum test_methods { TEST_BUILD_SNAPSHOT }; -static int debug = 0; static enum test_methods method = TEST_BUILD_SNAPSHOT; DECLARE_TEST_DATA(passwd) @@ -69,8 +70,6 @@ static int passwd_test_getpwnam(struct passwd *, void *); static int passwd_test_getpwuid(struct passwd *, void *); static int passwd_test_getpwent(struct passwd *, void *); -static void usage(void) __attribute__((__noreturn__)); - IMPLEMENT_TEST_DATA(passwd) IMPLEMENT_TEST_FILE_SNAPSHOT(passwd) IMPLEMENT_1PASS_TEST(passwd) @@ -79,8 +78,8 @@ IMPLEMENT_2PASS_TEST(passwd) static void clone_passwd(struct passwd *dest, struct passwd const *src) { - assert(dest != NULL); - assert(src != NULL); + ATF_REQUIRE(dest != NULL); + ATF_REQUIRE(src != NULL); memcpy(dest, src, sizeof(struct passwd)); if (src->pw_name != NULL) @@ -100,24 +99,23 @@ clone_passwd(struct passwd *dest, struct passwd const *src) static int compare_passwd(struct passwd *pwd1, struct passwd *pwd2, void *mdata) { - assert(pwd1 != NULL); - assert(pwd2 != NULL); + ATF_REQUIRE(pwd1 != NULL); + ATF_REQUIRE(pwd2 != NULL); if (pwd1 == pwd2) return (0); - if ((pwd1->pw_uid != pwd2->pw_uid) || - (pwd1->pw_gid != pwd2->pw_gid) || - (pwd1->pw_change != pwd2->pw_change) || - (pwd1->pw_expire != pwd2->pw_expire) || - (pwd1->pw_fields != pwd2->pw_fields) || - (strcmp(pwd1->pw_name, pwd2->pw_name) != 0) || - (strcmp(pwd1->pw_passwd, pwd2->pw_passwd) != 0) || - (strcmp(pwd1->pw_class, pwd2->pw_class) != 0) || - (strcmp(pwd1->pw_gecos, pwd2->pw_gecos) != 0) || - (strcmp(pwd1->pw_dir, pwd2->pw_dir) != 0) || - (strcmp(pwd1->pw_shell, pwd2->pw_shell) != 0) - ) + if (pwd1->pw_uid != pwd2->pw_uid || + pwd1->pw_gid != pwd2->pw_gid || + pwd1->pw_change != pwd2->pw_change || + pwd1->pw_expire != pwd2->pw_expire || + pwd1->pw_fields != pwd2->pw_fields || + strcmp(pwd1->pw_name, pwd2->pw_name) != 0 || + strcmp(pwd1->pw_passwd, pwd2->pw_passwd) != 0 || + strcmp(pwd1->pw_class, pwd2->pw_class) != 0 || + strcmp(pwd1->pw_gecos, pwd2->pw_gecos) != 0 || + strcmp(pwd1->pw_dir, pwd2->pw_dir) != 0 || + strcmp(pwd1->pw_shell, pwd2->pw_shell) != 0) return (-1); else return (0); @@ -137,10 +135,11 @@ free_passwd(struct passwd *pwd) static void sdump_passwd(struct passwd *pwd, char *buffer, size_t buflen) { - snprintf(buffer, buflen, "%s:%s:%d:%d:%d:%s:%s:%s:%s:%d:%d", - pwd->pw_name, pwd->pw_passwd, pwd->pw_uid, pwd->pw_gid, - pwd->pw_change, pwd->pw_class, pwd->pw_gecos, pwd->pw_dir, - pwd->pw_shell, pwd->pw_expire, pwd->pw_fields); + snprintf(buffer, buflen, "%s:%s:%d:%d:%jd:%s:%s:%s:%s:%jd:%d", + pwd->pw_name, pwd->pw_passwd, pwd->pw_uid, pwd->pw_gid, + (uintmax_t)pwd->pw_change, pwd->pw_class, pwd->pw_gecos, + pwd->pw_dir, pwd->pw_shell, (uintmax_t)pwd->pw_expire, + pwd->pw_fields); } static void @@ -160,66 +159,67 @@ passwd_read_snapshot_func(struct passwd *pwd, char *line) char *s, *ps, *ts; int i; - if (debug) - printf("1 line read from snapshot:\n%s\n", line); +#ifdef DEBUG + printf("1 line read from snapshot:\n%s\n", line); +#endif i = 0; ps = line; memset(pwd, 0, sizeof(struct passwd)); - while ( (s = strsep(&ps, ":")) != NULL) { + while ((s = strsep(&ps, ":")) != NULL) { switch (i) { - case 0: - pwd->pw_name = strdup(s); - assert(pwd->pw_name != NULL); + case 0: + pwd->pw_name = strdup(s); + ATF_REQUIRE(pwd->pw_name != NULL); break; - case 1: - pwd->pw_passwd = strdup(s); - assert(pwd->pw_passwd != NULL); + case 1: + pwd->pw_passwd = strdup(s); + ATF_REQUIRE(pwd->pw_passwd != NULL); break; - case 2: - pwd->pw_uid = (uid_t)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; + case 2: + pwd->pw_uid = (uid_t)strtol(s, &ts, 10); + if (*ts != '\0') + goto fin; break; - case 3: - pwd->pw_gid = (gid_t)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; + case 3: + pwd->pw_gid = (gid_t)strtol(s, &ts, 10); + if (*ts != '\0') + goto fin; break; - case 4: - pwd->pw_change = (time_t)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; + case 4: + pwd->pw_change = (time_t)strtol(s, &ts, 10); + if (*ts != '\0') + goto fin; break; - case 5: - pwd->pw_class = strdup(s); - assert(pwd->pw_class != NULL); + case 5: + pwd->pw_class = strdup(s); + ATF_REQUIRE(pwd->pw_class != NULL); break; - case 6: - pwd->pw_gecos = strdup(s); - assert(pwd->pw_gecos != NULL); + case 6: + pwd->pw_gecos = strdup(s); + ATF_REQUIRE(pwd->pw_gecos != NULL); break; - case 7: - pwd->pw_dir = strdup(s); - assert(pwd->pw_dir != NULL); + case 7: + pwd->pw_dir = strdup(s); + ATF_REQUIRE(pwd->pw_dir != NULL); break; - case 8: - pwd->pw_shell = strdup(s); - assert(pwd->pw_shell != NULL); + case 8: + pwd->pw_shell = strdup(s); + ATF_REQUIRE(pwd->pw_shell != NULL); break; - case 9: - pwd->pw_expire = (time_t)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; + case 9: + pwd->pw_expire = (time_t)strtol(s, &ts, 10); + if (*ts != '\0') + goto fin; break; - case 10: - pwd->pw_fields = (int)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; + case 10: + pwd->pw_fields = (int)strtol(s, &ts, 10); + if (*ts != '\0') + goto fin; break; - default: + default: break; - }; + } ++i; } @@ -253,10 +253,11 @@ passwd_fill_test_data(struct passwd_test_data *td) static int passwd_test_correctness(struct passwd *pwd, void *mdata) { - if (debug) { - printf("testing correctness with the following data:\n"); - dump_passwd(pwd); - } + +#ifdef DEBUG + printf("testing correctness with the following data:\n"); + dump_passwd(pwd); +#endif if (pwd == NULL) return (-1); @@ -279,13 +280,15 @@ passwd_test_correctness(struct passwd *pwd, void *mdata) if (pwd->pw_shell == NULL) goto errfin; - if (debug) - printf("correct\n"); +#ifdef DEBUG + printf("correct\n"); +#endif return (0); errfin: - if (debug) - printf("incorrect\n"); +#ifdef DEBUG + printf("incorrect\n"); +#endif return (-1); } @@ -306,10 +309,10 @@ passwd_test_getpwnam(struct passwd *pwd_model, void *mdata) { struct passwd *pwd; - if (debug) { - printf("testing getpwnam() with the following data:\n"); - dump_passwd(pwd_model); - } +#ifdef DEBUG + printf("testing getpwnam() with the following data:\n"); + dump_passwd(pwd_model); +#endif pwd = getpwnam(pwd_model->pw_name); if (passwd_test_correctness(pwd, NULL) != 0) @@ -320,14 +323,15 @@ passwd_test_getpwnam(struct passwd *pwd_model, void *mdata) !=0)) goto errfin; - if (debug) - printf("ok\n"); +#ifdef DEBUG + printf("ok\n"); +#endif return (0); errfin: - if (debug) - printf("not ok\n"); - +#ifdef DEBUG + printf("not ok\n"); +#endif return (-1); } @@ -336,23 +340,25 @@ passwd_test_getpwuid(struct passwd *pwd_model, void *mdata) { struct passwd *pwd; - if (debug) { - printf("testing getpwuid() with the following data...\n"); - dump_passwd(pwd_model); - } +#ifdef DEBUG + printf("testing getpwuid() with the following data...\n"); + dump_passwd(pwd_model); +#endif pwd = getpwuid(pwd_model->pw_uid); if ((passwd_test_correctness(pwd, NULL) != 0) || ((compare_passwd(pwd, pwd_model, NULL) != 0) && (passwd_check_ambiguity((struct passwd_test_data *)mdata, pwd) != 0))) { - if (debug) +#ifdef DEBUG printf("not ok\n"); - return (-1); +#endif + return (-1); } else { - if (debug) +#ifdef DEBUG printf("ok\n"); - return (0); +#endif + return (0); } } @@ -364,50 +370,11 @@ passwd_test_getpwent(struct passwd *pwd, void *mdata) return (passwd_test_correctness(pwd, NULL)); } -static void -usage(void) -{ - (void)fprintf(stderr, - "Usage: %s -nue2 [-d] [-s <file>]\n", - getprogname()); - exit(1); -} - -int -main(int argc, char **argv) +static int +run_tests(const char *snapshot_file, enum test_methods method) { struct passwd_test_data td, td_snap, td_2pass; - char *snapshot_file; int rv; - int c; - - if (argc < 2) - usage(); - - snapshot_file = NULL; - while ((c = getopt(argc, argv, "nue2ds:")) != -1) - switch (c) { - case 'd': - debug++; - break; - case 'n': - method = TEST_GETPWNAM; - break; - case 'u': - method = TEST_GETPWUID; - break; - case 'e': - method = TEST_GETPWENT; - break; - case '2': - method = TEST_GETPWENT_2PASS; - break; - case 's': - snapshot_file = strdup(optarg); - break; - default: - usage(); - } TEST_DATA_INIT(passwd, &td, clone_passwd, free_passwd); TEST_DATA_INIT(passwd, &td_snap, clone_passwd, free_passwd); @@ -416,10 +383,8 @@ main(int argc, char **argv) if (errno == ENOENT) method = TEST_BUILD_SNAPSHOT; else { - if (debug) - printf("can't access the file %s\n", - snapshot_file); - + printf("can't access the file %s\n", + snapshot_file); rv = -1; goto fin; } @@ -464,26 +429,102 @@ main(int argc, char **argv) compare_passwd, NULL); break; case TEST_GETPWENT_2PASS: - TEST_DATA_INIT(passwd, &td_2pass, clone_passwd, free_passwd); - rv = passwd_fill_test_data(&td_2pass); - if (rv != -1) - rv = DO_2PASS_TEST(passwd, &td, &td_2pass, - compare_passwd, NULL); - TEST_DATA_DESTROY(passwd, &td_2pass); + TEST_DATA_INIT(passwd, &td_2pass, clone_passwd, free_passwd); + rv = passwd_fill_test_data(&td_2pass); + if (rv != -1) + rv = DO_2PASS_TEST(passwd, &td, &td_2pass, + compare_passwd, NULL); + TEST_DATA_DESTROY(passwd, &td_2pass); break; case TEST_BUILD_SNAPSHOT: if (snapshot_file != NULL) - rv = TEST_SNAPSHOT_FILE_WRITE(passwd, snapshot_file, &td, - sdump_passwd); + rv = TEST_SNAPSHOT_FILE_WRITE(passwd, snapshot_file, + &td, sdump_passwd); break; default: rv = 0; break; - }; + } fin: TEST_DATA_DESTROY(passwd, &td_snap); TEST_DATA_DESTROY(passwd, &td); - free(snapshot_file); + return (rv); } + +#define SNAPSHOT_FILE "snapshot_pwd" + +ATF_TC_WITHOUT_HEAD(build_snapshot); +ATF_TC_BODY(build_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getpwent); +ATF_TC_BODY(getpwent, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getpwent_with_snapshot); +ATF_TC_BODY(getpwent_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getpwent_with_two_pass); +ATF_TC_BODY(getpwent_with_two_pass, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWENT_2PASS) == 0); +} + +ATF_TC_WITHOUT_HEAD(getpwnam); +ATF_TC_BODY(getpwnam, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWNAM) == 0); +} + +ATF_TC_WITHOUT_HEAD(getpwnam_with_snapshot); +ATF_TC_BODY(getpwnam_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWNAM) == 0); +} + +ATF_TC_WITHOUT_HEAD(getpwuid); +ATF_TC_BODY(getpwuid, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWUID) == 0); +} + +ATF_TC_WITHOUT_HEAD(getpwuid_with_snapshot); +ATF_TC_BODY(getpwuid_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETPWUID) == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, build_snapshot); + ATF_TP_ADD_TC(tp, getpwent); + ATF_TP_ADD_TC(tp, getpwent_with_snapshot); + ATF_TP_ADD_TC(tp, getpwent_with_two_pass); + ATF_TP_ADD_TC(tp, getpwnam); + ATF_TP_ADD_TC(tp, getpwnam_with_snapshot); + ATF_TP_ADD_TC(tp, getpwuid); + ATF_TP_ADD_TC(tp, getpwuid_with_snapshot); + + return (atf_no_error()); +} diff --git a/tools/regression/lib/libc/nss/test-getrpc.c b/lib/libc/tests/nss/getrpc_test.c index 707186e..89de986 100644 --- a/tools/regression/lib/libc/nss/test-getrpc.c +++ b/lib/libc/tests/nss/getrpc_test.c @@ -30,13 +30,15 @@ __FBSDID("$FreeBSD$"); #include <arpa/inet.h> #include <rpc/rpc.h> -#include <assert.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stringlist.h> #include <unistd.h> + +#include <atf-c.h> + #include "testutil.h" enum test_methods { @@ -47,9 +49,6 @@ enum test_methods { TEST_BUILD_SNAPSHOT }; -static int debug = 0; -static enum test_methods method = TEST_BUILD_SNAPSHOT; - DECLARE_TEST_DATA(rpcent) DECLARE_TEST_FILE_SNAPSHOT(rpcent) DECLARE_1PASS_TEST(rpcent) @@ -81,8 +80,8 @@ IMPLEMENT_2PASS_TEST(rpcent) static void clone_rpcent(struct rpcent *dest, struct rpcent const *src) { - assert(dest != NULL); - assert(src != NULL); + ATF_REQUIRE(dest != NULL); + ATF_REQUIRE(src != NULL); char **cp; int aliases_num; @@ -91,7 +90,7 @@ clone_rpcent(struct rpcent *dest, struct rpcent const *src) if (src->r_name != NULL) { dest->r_name = strdup(src->r_name); - assert(dest->r_name != NULL); + ATF_REQUIRE(dest->r_name != NULL); } dest->r_number = src->r_number; @@ -101,13 +100,12 @@ clone_rpcent(struct rpcent *dest, struct rpcent const *src) for (cp = src->r_aliases; *cp; ++cp) ++aliases_num; - dest->r_aliases = (char **)malloc((aliases_num+1) * (sizeof(char *))); - assert(dest->r_aliases != NULL); - memset(dest->r_aliases, 0, (aliases_num+1) * (sizeof(char *))); + dest->r_aliases = calloc(1, (aliases_num + 1) * sizeof(char *)); + ATF_REQUIRE(dest->r_aliases != NULL); for (cp = src->r_aliases; *cp; ++cp) { dest->r_aliases[cp - src->r_aliases] = strdup(*cp); - assert(dest->r_aliases[cp - src->r_aliases] != NULL); + ATF_REQUIRE(dest->r_aliases[cp - src->r_aliases] != NULL); } } } @@ -117,7 +115,7 @@ free_rpcent(struct rpcent *rpc) { char **cp; - assert(rpc != NULL); + ATF_REQUIRE(rpc != NULL); free(rpc->r_name); @@ -157,7 +155,7 @@ compare_rpcent(struct rpcent *rpc1, struct rpcent *rpc2, void *mdata) return 0; errfin: - if ((debug) && (mdata == NULL)) { + if (mdata == NULL) { printf("following structures are not equal:\n"); dump_rpcent(rpc1); dump_rpcent(rpc2); @@ -204,49 +202,48 @@ rpcent_read_snapshot_func(struct rpcent *rpc, char *line) char *s, *ps, *ts; int i; - if (debug) - printf("1 line read from snapshot:\n%s\n", line); + printf("1 line read from snapshot:\n%s\n", line); i = 0; sl = NULL; ps = line; memset(rpc, 0, sizeof(struct rpcent)); - while ( (s = strsep(&ps, " ")) != NULL) { + while ((s = strsep(&ps, " ")) != NULL) { switch (i) { - case 0: + case 0: rpc->r_name = strdup(s); - assert(rpc->r_name != NULL); + ATF_REQUIRE(rpc->r_name != NULL); break; - case 1: - rpc->r_number = (int)strtol(s, &ts, 10); - if (*ts != '\0') { - free(rpc->r_name); - return (-1); - } + case 1: + rpc->r_number = (int)strtol(s, &ts, 10); + if (*ts != '\0') { + free(rpc->r_name); + return (-1); + } break; - default: - if (sl == NULL) { - if (strcmp(s, "(null)") == 0) - return (0); + default: + if (sl == NULL) { + if (strcmp(s, "(null)") == 0) + return (0); - sl = sl_init(); - assert(sl != NULL); + sl = sl_init(); + ATF_REQUIRE(sl != NULL); - if (strcmp(s, "noaliases") != 0) { - ts = strdup(s); - assert(ts != NULL); - sl_add(sl, ts); - } - } else { + if (strcmp(s, "noaliases") != 0) { ts = strdup(s); - assert(ts != NULL); + ATF_REQUIRE(ts != NULL); sl_add(sl, ts); } + } else { + ts = strdup(s); + ATF_REQUIRE(ts != NULL); + sl_add(sl, ts); + } break; - }; - ++i; + } + i++; } if (i < 3) { @@ -294,10 +291,9 @@ rpcent_fill_test_data(struct rpcent_test_data *td) static int rpcent_test_correctness(struct rpcent *rpc, void *mdata) { - if (debug) { - printf("testing correctness with the following data:\n"); - dump_rpcent(rpc); - } + + printf("testing correctness with the following data:\n"); + dump_rpcent(rpc); if (rpc == NULL) goto errfin; @@ -311,13 +307,11 @@ rpcent_test_correctness(struct rpcent *rpc, void *mdata) if (rpc->r_aliases == NULL) goto errfin; - if (debug) - printf("correct\n"); + printf("correct\n"); return (0); errfin: - if (debug) - printf("incorrect\n"); + printf("incorrect\n"); return (-1); } @@ -341,10 +335,8 @@ rpcent_test_getrpcbyname(struct rpcent *rpc_model, void *mdata) char **alias; struct rpcent *rpc; - if (debug) { - printf("testing getrpcbyname() with the following data:\n"); - dump_rpcent(rpc_model); - } + printf("testing getrpcbyname() with the following data:\n"); + dump_rpcent(rpc_model); rpc = getrpcbyname(rpc_model->r_name); if (rpcent_test_correctness(rpc, NULL) != 0) @@ -367,13 +359,11 @@ rpcent_test_getrpcbyname(struct rpcent *rpc_model, void *mdata) goto errfin; } - if (debug) - printf("ok\n"); + printf("ok\n"); return (0); errfin: - if (debug) - printf("not ok\n"); + printf("not ok\n"); return (-1); } @@ -383,78 +373,38 @@ rpcent_test_getrpcbynumber(struct rpcent *rpc_model, void *mdata) { struct rpcent *rpc; - if (debug) { - printf("testing getrpcbyport() with the following data...\n"); - dump_rpcent(rpc_model); - } + printf("testing getrpcbyport() with the following data...\n"); + dump_rpcent(rpc_model); rpc = getrpcbynumber(rpc_model->r_number); - if ((rpcent_test_correctness(rpc, NULL) != 0) || - ((compare_rpcent(rpc, rpc_model, NULL) != 0) && - (rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc) - != 0))) { - if (debug) + if (rpcent_test_correctness(rpc, NULL) != 0 || + (compare_rpcent(rpc, rpc_model, NULL) != 0 && + rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc) + != 0)) { printf("not ok\n"); - return (-1); + return (-1); } else { - if (debug) printf("ok\n"); - return (0); + return (0); } } static int rpcent_test_getrpcent(struct rpcent *rpc, void *mdata) { - /* Only correctness can be checked when doing 1-pass test for - * getrpcent(). */ - return (rpcent_test_correctness(rpc, NULL)); -} -static void -usage(void) -{ - (void)fprintf(stderr, - "Usage: %s -nve2 [-d] [-s <file>]\n", - getprogname()); - exit(1); + /* + * Only correctness can be checked when doing 1-pass test for + * getrpcent(). + */ + return (rpcent_test_correctness(rpc, NULL)); } int -main(int argc, char **argv) +run_tests(const char *snapshot_file, enum test_methods method) { struct rpcent_test_data td, td_snap, td_2pass; - char *snapshot_file; int rv; - int c; - - if (argc < 2) - usage(); - - snapshot_file = NULL; - while ((c = getopt(argc, argv, "nve2ds:")) != -1) - switch (c) { - case 'd': - debug++; - break; - case 'n': - method = TEST_GETRPCBYNAME; - break; - case 'v': - method = TEST_GETRPCBYNUMBER; - break; - case 'e': - method = TEST_GETRPCENT; - break; - case '2': - method = TEST_GETRPCENT_2PASS; - break; - case 's': - snapshot_file = strdup(optarg); - break; - default: - usage(); - } TEST_DATA_INIT(rpcent, &td, clone_rpcent, free_rpcent); TEST_DATA_INIT(rpcent, &td_snap, clone_rpcent, free_rpcent); @@ -463,9 +413,8 @@ main(int argc, char **argv) if (errno == ENOENT) method = TEST_BUILD_SNAPSHOT; else { - if (debug) - printf("can't access the file %s\n", - snapshot_file); + printf("can't access the file %s\n", + snapshot_file); rv = -1; goto fin; @@ -525,11 +474,87 @@ main(int argc, char **argv) default: rv = 0; break; - }; + } fin: TEST_DATA_DESTROY(rpcent, &td_snap); TEST_DATA_DESTROY(rpcent, &td); - free(snapshot_file); + return (rv); } + +#define SNAPSHOT_FILE "snapshot_rpc" + +ATF_TC_WITHOUT_HEAD(build_snapshot); +ATF_TC_BODY(build_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getrpcbyname); +ATF_TC_BODY(getrpcbyname, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETRPCBYNAME) == 0); +} + +ATF_TC_WITHOUT_HEAD(getrpcbyname_with_snapshot); +ATF_TC_BODY(getrpcbyname_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCBYNAME) == 0); +} + +ATF_TC_WITHOUT_HEAD(getrpcbynumber); +ATF_TC_BODY(getrpcbynumber, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETRPCBYNUMBER) == 0); +} + +ATF_TC_WITHOUT_HEAD(getrpcbynumber_with_snapshot); +ATF_TC_BODY(getrpcbynumber_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCBYNUMBER) == 0); +} + +ATF_TC_WITHOUT_HEAD(getrpcbyent); +ATF_TC_BODY(getrpcbyent, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETRPCENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getrpcbyent_with_snapshot); +ATF_TC_BODY(getrpcbyent_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getrpcbyent_with_two_pass); +ATF_TC_BODY(getrpcbyent_with_two_pass, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETRPCENT_2PASS) == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, build_snapshot); + ATF_TP_ADD_TC(tp, getrpcbyname); + ATF_TP_ADD_TC(tp, getrpcbyname_with_snapshot); + ATF_TP_ADD_TC(tp, getrpcbynumber); + ATF_TP_ADD_TC(tp, getrpcbynumber_with_snapshot); + ATF_TP_ADD_TC(tp, getrpcbyent); + ATF_TP_ADD_TC(tp, getrpcbyent_with_snapshot); + ATF_TP_ADD_TC(tp, getrpcbyent_with_two_pass); + + return (atf_no_error()); +} diff --git a/tools/regression/lib/libc/nss/test-getserv.c b/lib/libc/tests/nss/getserv_test.c index 31e4700..29c1dfa 100644 --- a/tools/regression/lib/libc/nss/test-getserv.c +++ b/lib/libc/tests/nss/getserv_test.c @@ -29,7 +29,6 @@ __FBSDID("$FreeBSD$"); #include <arpa/inet.h> -#include <assert.h> #include <errno.h> #include <netdb.h> #include <stdio.h> @@ -37,6 +36,9 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <stringlist.h> #include <unistd.h> + +#include <atf-c.h> + #include "testutil.h" enum test_methods { @@ -47,9 +49,6 @@ enum test_methods { TEST_BUILD_SNAPSHOT }; -static int debug = 0; -static enum test_methods method = TEST_BUILD_SNAPSHOT; - DECLARE_TEST_DATA(servent) DECLARE_TEST_FILE_SNAPSHOT(servent) DECLARE_1PASS_TEST(servent) @@ -71,8 +70,6 @@ static int servent_test_getservbyname(struct servent *, void *); static int servent_test_getservbyport(struct servent *, void *); static int servent_test_getservent(struct servent *, void *); -static void usage(void) __attribute__((__noreturn__)); - IMPLEMENT_TEST_DATA(servent) IMPLEMENT_TEST_FILE_SNAPSHOT(servent) IMPLEMENT_1PASS_TEST(servent) @@ -81,8 +78,8 @@ IMPLEMENT_2PASS_TEST(servent) static void clone_servent(struct servent *dest, struct servent const *src) { - assert(dest != NULL); - assert(src != NULL); + ATF_REQUIRE(dest != NULL); + ATF_REQUIRE(src != NULL); char **cp; int aliases_num; @@ -91,12 +88,12 @@ clone_servent(struct servent *dest, struct servent const *src) if (src->s_name != NULL) { dest->s_name = strdup(src->s_name); - assert(dest->s_name != NULL); + ATF_REQUIRE(dest->s_name != NULL); } if (src->s_proto != NULL) { dest->s_proto = strdup(src->s_proto); - assert(dest->s_proto != NULL); + ATF_REQUIRE(dest->s_proto != NULL); } dest->s_port = src->s_port; @@ -105,13 +102,12 @@ clone_servent(struct servent *dest, struct servent const *src) for (cp = src->s_aliases; *cp; ++cp) ++aliases_num; - dest->s_aliases = (char **)malloc((aliases_num+1) * (sizeof(char *))); - assert(dest->s_aliases != NULL); - memset(dest->s_aliases, 0, (aliases_num+1) * (sizeof(char *))); + dest->s_aliases = calloc(1, (aliases_num + 1) * sizeof(char *)); + ATF_REQUIRE(dest->s_aliases != NULL); for (cp = src->s_aliases; *cp; ++cp) { dest->s_aliases[cp - src->s_aliases] = strdup(*cp); - assert(dest->s_aliases[cp - src->s_aliases] != NULL); + ATF_REQUIRE(dest->s_aliases[cp - src->s_aliases] != NULL); } } } @@ -121,7 +117,7 @@ free_servent(struct servent *serv) { char **cp; - assert(serv != NULL); + ATF_REQUIRE(serv != NULL); free(serv->s_name); free(serv->s_proto); @@ -163,7 +159,7 @@ compare_servent(struct servent *serv1, struct servent *serv2, void *mdata) return 0; errfin: - if ((debug) && (mdata == NULL)) { + if (mdata == NULL) { printf("following structures are not equal:\n"); dump_servent(serv1); dump_servent(serv2); @@ -210,8 +206,7 @@ servent_read_snapshot_func(struct servent *serv, char *line) char *s, *ps, *ts; int i; - if (debug) - printf("1 line read from snapshot:\n%s\n", line); + printf("1 line read from snapshot:\n%s\n", line); i = 0; sl = NULL; @@ -221,7 +216,7 @@ servent_read_snapshot_func(struct servent *serv, char *line) switch (i) { case 0: serv->s_name = strdup(s); - assert(serv->s_name != NULL); + ATF_REQUIRE(serv->s_name != NULL); break; case 1: @@ -235,7 +230,7 @@ servent_read_snapshot_func(struct servent *serv, char *line) case 2: serv->s_proto = strdup(s); - assert(serv->s_proto != NULL); + ATF_REQUIRE(serv->s_proto != NULL); break; default: @@ -244,20 +239,20 @@ servent_read_snapshot_func(struct servent *serv, char *line) return (0); sl = sl_init(); - assert(sl != NULL); + ATF_REQUIRE(sl != NULL); if (strcmp(s, "noaliases") != 0) { ts = strdup(s); - assert(ts != NULL); + ATF_REQUIRE(ts != NULL); sl_add(sl, ts); } } else { ts = strdup(s); - assert(ts != NULL); + ATF_REQUIRE(ts != NULL); sl_add(sl, ts); } break; - }; + } ++i; } @@ -307,10 +302,8 @@ servent_fill_test_data(struct servent_test_data *td) static int servent_test_correctness(struct servent *serv, void *mdata) { - if (debug) { - printf("testing correctness with the following data:\n"); - dump_servent(serv); - } + printf("testing correctness with the following data:\n"); + dump_servent(serv); if (serv == NULL) goto errfin; @@ -327,13 +320,11 @@ servent_test_correctness(struct servent *serv, void *mdata) if (serv->s_aliases == NULL) goto errfin; - if (debug) - printf("correct\n"); + printf("correct\n"); return (0); errfin: - if (debug) - printf("incorrect\n"); + printf("incorrect\n"); return (-1); } @@ -357,10 +348,8 @@ servent_test_getservbyname(struct servent *serv_model, void *mdata) char **alias; struct servent *serv; - if (debug) { - printf("testing getservbyname() with the following data:\n"); - dump_servent(serv_model); - } + printf("testing getservbyname() with the following data:\n"); + dump_servent(serv_model); serv = getservbyname(serv_model->s_name, serv_model->s_proto); if (servent_test_correctness(serv, NULL) != 0) @@ -369,7 +358,7 @@ servent_test_getservbyname(struct servent *serv_model, void *mdata) if ((compare_servent(serv, serv_model, NULL) != 0) && (servent_check_ambiguity((struct servent_test_data *)mdata, serv) !=0)) - goto errfin; + goto errfin; for (alias = serv_model->s_aliases; *alias; ++alias) { serv = getservbyname(*alias, serv_model->s_proto); @@ -383,13 +372,11 @@ servent_test_getservbyname(struct servent *serv_model, void *mdata) goto errfin; } - if (debug) - printf("ok\n"); + printf("ok\n"); return (0); errfin: - if (debug) - printf("not ok\n"); + printf("not ok\n"); return (-1); } @@ -399,23 +386,19 @@ servent_test_getservbyport(struct servent *serv_model, void *mdata) { struct servent *serv; - if (debug) { - printf("testing getservbyport() with the following data...\n"); - dump_servent(serv_model); - } + printf("testing getservbyport() with the following data...\n"); + dump_servent(serv_model); serv = getservbyport(serv_model->s_port, serv_model->s_proto); if ((servent_test_correctness(serv, NULL) != 0) || ((compare_servent(serv, serv_model, NULL) != 0) && (servent_check_ambiguity((struct servent_test_data *)mdata, serv) != 0))) { - if (debug) printf("not ok\n"); - return (-1); + return (-1); } else { - if (debug) printf("ok\n"); - return (0); + return (0); } } @@ -427,50 +410,11 @@ servent_test_getservent(struct servent *serv, void *mdata) return (servent_test_correctness(serv, NULL)); } -static void -usage(void) -{ - (void)fprintf(stderr, - "Usage: %s -npe2 [-d] [-s <file>]\n", - getprogname()); - exit(1); -} - int -main(int argc, char **argv) +run_tests(const char *snapshot_file, enum test_methods method) { struct servent_test_data td, td_snap, td_2pass; - char *snapshot_file; int rv; - int c; - - if (argc < 2) - usage(); - - snapshot_file = NULL; - while ((c = getopt(argc, argv, "npe2ds:")) != -1) - switch (c) { - case 'd': - debug++; - break; - case 'n': - method = TEST_GETSERVBYNAME; - break; - case 'p': - method = TEST_GETSERVBYPORT; - break; - case 'e': - method = TEST_GETSERVENT; - break; - case '2': - method = TEST_GETSERVENT_2PASS; - break; - case 's': - snapshot_file = strdup(optarg); - break; - default: - usage(); - } TEST_DATA_INIT(servent, &td, clone_servent, free_servent); TEST_DATA_INIT(servent, &td_snap, clone_servent, free_servent); @@ -479,9 +423,8 @@ main(int argc, char **argv) if (errno == ENOENT) method = TEST_BUILD_SNAPSHOT; else { - if (debug) - printf("can't access the file %s\n", - snapshot_file); + printf("can't access the file %s\n", + snapshot_file); rv = -1; goto fin; @@ -541,11 +484,87 @@ main(int argc, char **argv) default: rv = 0; break; - }; + } fin: TEST_DATA_DESTROY(servent, &td_snap); TEST_DATA_DESTROY(servent, &td); - free(snapshot_file); + return (rv); } + +#define SNAPSHOT_FILE "snapshot_serv" + +ATF_TC_WITHOUT_HEAD(build_snapshot); +ATF_TC_BODY(build_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getservbyname); +ATF_TC_BODY(getservbyname, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETSERVBYNAME) == 0); +} + +ATF_TC_WITHOUT_HEAD(getservbyname_with_snapshot); +ATF_TC_BODY(getservbyname_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETSERVBYNAME) == 0); +} + +ATF_TC_WITHOUT_HEAD(getservbyport); +ATF_TC_BODY(getservbyport, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETSERVBYPORT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getservbyport_with_snapshot); +ATF_TC_BODY(getservbyport_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETSERVBYPORT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getservbyent); +ATF_TC_BODY(getservbyent, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETSERVENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getservbyent_with_snapshot); +ATF_TC_BODY(getservbyent_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETSERVENT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getservbyent_with_two_pass); +ATF_TC_BODY(getservbyent_with_two_pass, tc) +{ + + ATF_REQUIRE(run_tests(NULL, TEST_GETSERVENT_2PASS) == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, build_snapshot); + ATF_TP_ADD_TC(tp, getservbyent); + ATF_TP_ADD_TC(tp, getservbyent_with_snapshot); + ATF_TP_ADD_TC(tp, getservbyent_with_two_pass); + ATF_TP_ADD_TC(tp, getservbyname); + ATF_TP_ADD_TC(tp, getservbyname_with_snapshot); + ATF_TP_ADD_TC(tp, getservbyport); + ATF_TP_ADD_TC(tp, getservbyport_with_snapshot); + + return (atf_no_error()); +} diff --git a/tools/regression/lib/libc/nss/test-getusershell.c b/lib/libc/tests/nss/getusershell_test.c index b7b835f..ccd8cf9 100644 --- a/tools/regression/lib/libc/nss/test-getusershell.c +++ b/lib/libc/tests/nss/getusershell_test.c @@ -34,6 +34,9 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> #include <unistd.h> + +#include <atf-c.h> + #include "testutil.h" enum test_methods { @@ -45,7 +48,6 @@ struct usershell { char *path; }; -static int debug = 0; static enum test_methods method = TEST_GETUSERSHELL; DECLARE_TEST_DATA(usershell) @@ -59,10 +61,6 @@ static void free_usershell(struct usershell *); static void sdump_usershell(struct usershell *, char *, size_t); static void dump_usershell(struct usershell *); -static int usershell_read_snapshot_func(struct usershell *, char *); - -static void usage(void) __attribute__((__noreturn__)); - IMPLEMENT_TEST_DATA(usershell) IMPLEMENT_TEST_FILE_SNAPSHOT(usershell) IMPLEMENT_2PASS_TEST(usershell) @@ -129,69 +127,39 @@ dump_usershell(struct usershell *us) static int usershell_read_snapshot_func(struct usershell *us, char *line) { + us->path = strdup(line); - assert(us->path != NULL); + ATF_REQUIRE(us->path != NULL); return (0); } -static void -usage(void) -{ - (void)fprintf(stderr, - "Usage: %s [-d] -s <file>\n", - getprogname()); - exit(1); -} - int -main(int argc, char **argv) +run_tests(const char *snapshot_file, enum test_methods method) { struct usershell_test_data td, td_snap; struct usershell ushell; - char *snapshot_file; int rv; - int c; - - if (argc < 2) - usage(); rv = 0; - snapshot_file = NULL; - while ((c = getopt(argc, argv, "ds:")) != -1) { - switch (c) { - case 'd': - debug = 1; - break; - case 's': - snapshot_file = strdup(optarg); - break; - default: - usage(); - } - } TEST_DATA_INIT(usershell, &td, clone_usershell, free_usershell); TEST_DATA_INIT(usershell, &td_snap, clone_usershell, free_usershell); setusershell(); while ((ushell.path = getusershell()) != NULL) { - if (debug) { - printf("usershell found:\n"); - dump_usershell(&ushell); - } + printf("usershell found:\n"); + dump_usershell(&ushell); TEST_DATA_APPEND(usershell, &td, &ushell); } endusershell(); - if (snapshot_file != NULL) { if (access(snapshot_file, W_OK | R_OK) != 0) { if (errno == ENOENT) method = TEST_BUILD_SNAPSHOT; else { - if (debug) - printf("can't access the snapshot file %s\n", + printf("can't access the snapshot file %s\n", snapshot_file); rv = -1; @@ -201,8 +169,7 @@ main(int argc, char **argv) rv = TEST_SNAPSHOT_FILE_READ(usershell, snapshot_file, &td_snap, usershell_read_snapshot_func); if (rv != 0) { - if (debug) - printf("error reading snapshot file\n"); + printf("error reading snapshot file\n"); goto fin; } } @@ -210,26 +177,49 @@ main(int argc, char **argv) switch (method) { case TEST_GETUSERSHELL: - if (snapshot_file != NULL) { - rv = DO_2PASS_TEST(usershell, &td, &td_snap, - compare_usershell, NULL); - } + rv = DO_2PASS_TEST(usershell, &td, &td_snap, + compare_usershell, NULL); break; case TEST_BUILD_SNAPSHOT: if (snapshot_file != NULL) { - rv = TEST_SNAPSHOT_FILE_WRITE(usershell, snapshot_file, &td, - sdump_usershell); + rv = TEST_SNAPSHOT_FILE_WRITE(usershell, snapshot_file, + &td, sdump_usershell); } break; default: rv = 0; break; - }; + } fin: TEST_DATA_DESTROY(usershell, &td_snap); TEST_DATA_DESTROY(usershell, &td); - free(snapshot_file); + return (rv); +} + +#define SNAPSHOT_FILE "snapshot_usershell" + +ATF_TC_WITHOUT_HEAD(getusershell_with_snapshot); +ATF_TC_BODY(getusershell_with_snapshot, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); +} + +ATF_TC_WITHOUT_HEAD(getusershell_with_two_pass); +ATF_TC_BODY(getusershell_with_two_pass, tc) +{ + + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0); + ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETUSERSHELL) == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, getusershell_with_snapshot); + ATF_TP_ADD_TC(tp, getusershell_with_two_pass); + return (atf_no_error()); } diff --git a/tools/regression/lib/libc/nss/testutil.h b/lib/libc/tests/nss/testutil.h index 711c49f..39c4f41 100644 --- a/tools/regression/lib/libc/nss/testutil.h +++ b/lib/libc/tests/nss/testutil.h @@ -73,9 +73,9 @@ __##ent##_test_data_init(struct ent##_test_data *td, \ void (*clonef)(struct ent *, struct ent const *), \ void (*freef)(struct ent *)) \ { \ - assert(td != NULL); \ - assert(clonef != NULL); \ - assert(freef != NULL); \ + ATF_REQUIRE(td != NULL); \ + ATF_REQUIRE(clonef != NULL); \ + ATF_REQUIRE(freef != NULL); \ \ memset(td, 0, sizeof(*td)); \ td->clone_func = clonef; \ @@ -94,11 +94,11 @@ __##ent##_test_data_append(struct ent##_test_data *td, struct ent *app_data)\ { \ struct ent##_entry *e; \ \ - assert(td != NULL); \ - assert(app_data != NULL); \ + ATF_REQUIRE(td != NULL); \ + ATF_REQUIRE(app_data != NULL); \ \ e = (struct ent##_entry *)malloc(sizeof(struct ent##_entry)); \ - assert(e != NULL); \ + ATF_REQUIRE(e != NULL); \ memset(e, 0, sizeof(struct ent##_entry)); \ \ td->clone_func(&e->data, app_data); \ @@ -112,8 +112,8 @@ __##ent##_test_data_foreach(struct ent##_test_data *td, \ struct ent##_entry *e; \ int rv; \ \ - assert(td != NULL); \ - assert(forf != NULL); \ + ATF_REQUIRE(td != NULL); \ + ATF_REQUIRE(forf != NULL); \ \ rv = 0; \ STAILQ_FOREACH(e, &td->snapshot_data, entries) { \ @@ -132,9 +132,9 @@ __##ent##_test_data_compare(struct ent##_test_data *td1, struct ent##_test_data struct ent##_entry *e1, *e2; \ int rv; \ \ - assert(td1 != NULL); \ - assert(td2 != NULL); \ - assert(cmp_func != NULL); \ + ATF_REQUIRE(td1 != NULL); \ + ATF_REQUIRE(td2 != NULL); \ + ATF_REQUIRE(cmp_func != NULL); \ \ e1 = STAILQ_FIRST(&td1->snapshot_data); \ e2 = STAILQ_FIRST(&td2->snapshot_data); \ @@ -163,8 +163,8 @@ __##ent##_test_data_find(struct ent##_test_data *td, struct ent *data, \ struct ent##_entry *e; \ struct ent *result; \ \ - assert(td != NULL); \ - assert(cmp != NULL); \ + ATF_REQUIRE(td != NULL); \ + ATF_REQUIRE(cmp != NULL); \ \ result = NULL; \ STAILQ_FOREACH(e, &td->snapshot_data, entries) { \ @@ -182,7 +182,7 @@ void \ __##ent##_test_data_clear(struct ent##_test_data *td) \ { \ struct ent##_entry *e; \ - assert(td != NULL); \ + ATF_REQUIRE(td != NULL); \ \ while (!STAILQ_EMPTY(&td->snapshot_data)) { \ e = STAILQ_FIRST(&td->snapshot_data); \ @@ -190,6 +190,7 @@ __##ent##_test_data_clear(struct ent##_test_data *td) \ \ td->free_func(&e->data); \ free(e); \ + e = NULL; \ } \ } @@ -217,7 +218,7 @@ __##ent##_snapshot_write_func(struct ent *data, void *mdata) \ char buffer[1024]; \ struct ent##_snp_param *param; \ \ - assert(data != NULL); \ + ATF_REQUIRE(data != NULL); \ \ param = (struct ent##_snp_param *)mdata; \ param->sdump_func(data, buffer, sizeof(buffer)); \ @@ -233,8 +234,8 @@ __##ent##_snapshot_write(char const *fname, struct ent##_test_data *td, \ { \ struct ent##_snp_param param; \ \ - assert(fname != NULL); \ - assert(td != NULL); \ + ATF_REQUIRE(fname != NULL); \ + ATF_REQUIRE(td != NULL); \ \ param.fp = fopen(fname, "w"); \ if (param.fp == NULL) \ @@ -258,8 +259,8 @@ __##ent##_snapshot_read(char const *fname, struct ent##_test_data *td, \ size_t len; \ int rv; \ \ - assert(fname != NULL); \ - assert(td != NULL); \ + ATF_REQUIRE(fname != NULL); \ + ATF_REQUIRE(td != NULL); \ \ fi = fopen(fname, "r"); \ if (fi == NULL) \ diff --git a/tools/regression/lib/libc/nss/Makefile b/tools/regression/lib/libc/nss/Makefile deleted file mode 100644 index 8c8a514..0000000 --- a/tools/regression/lib/libc/nss/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# $FreeBSD$ - -TESTS= test-getaddr test-getgr test-gethostby test-getpw test-getproto\ - test-getrpc test-getserv test-getusershell -CFLAGS+= -g -Wall - -.PHONY: tests -tests: ${TESTS} - -.PHONY: clean -clean: - -rm -f ${TESTS} diff --git a/tools/regression/lib/libc/nss/README b/tools/regression/lib/libc/nss/README deleted file mode 100644 index bf32913..0000000 --- a/tools/regression/lib/libc/nss/README +++ /dev/null @@ -1,203 +0,0 @@ -$FreeBSD$ - -A brief how-to --------------- - -Each nsswitch regression test does 2 kinds of actions: -1. It runs a series of queries and tests the correctness of results. - There are 2 basic criteria which are used for that: - - numbers must be in the correct range - - certain pointers should not be NULL - -2. It makes a snapshot of the results of all queries that were made. - The idea of snapshots is to test that nsswitch-related function - calls behave equally (i.e. return same results for the same queries) - between system upgrades. When the test is executed and the snapshot is - already created, the test will compare the result of each query with - the appropriate result from the snapshot and will signal if they - differ. - -In order for nsswitch tests to be as useful as possible you should use -them in the following way: - -Step 1 (before upgrading your system). -Build the tests with "make" command and execute them with "prove -v" -command. If there are errors during the execution, then appropriate -nsswitch functions should be checked. Note, that errors on this state -can happen only if the particular function return incorrect data. - -After the stage 1 a number of "snapshot_[test name]" files will appear -in your test folder. - -Step 2 (after upgrading you system). -Rebuild the tests with "make clean; make" command and execute them -again with "prove -v" (check that "snapshot_[test name]" files -are in the same folder with tests). On this stage regression tests -will catch not only the correctness errors, but will also determine -the changes in nsswitch functions behaviour. - -In case of the test failure you will get the following message: - -To get more details about the error you should do the following: -Step 1. Run the test alone with debug output enabled. -Step 2. Mail the snapshot file and the debug test output to the -freebsd-current@ mailing list. - -Example testing session for getpwXXX() family of functions ----------------------------------------------------------- -1. make - -2. prove -v ./test-getpw.t - - test-getpw....1..8 - ok 1 - getpwnam() - ok 2 - getpwuid() - ok 3 - getpwent() - ok 4 - getpwent() 2-pass - ok 5 - building snapshot, if needed - ok 6 - getpwnam() snapshot - ok 7 - getpwuid() snapshot - ok 8 - getpwent() snapshot - ok - All tests successful. - Files=1, Tests=8, 1 wallclock secs ( 0.00 cusr + 0.20 csys = 0.20 CPU) - - -3. Upgrading the system. - -4. make clean; make - -5. prove -v ./test-getpw.t (suppose that something has gone wrong) - - test-getpw....1..8 - ok 1 - getpwnam() - ok 2 - getpwuid() - ok 3 - getpwent() - ok 4 - getpwent() 2-pass - ok 5 - building snapshot, if needed - not ok 6 - getpwnam() snapshot - ok 7 - getpwuid() snapshot - not ok 8 - getpwent() snapshot - FAILED tests 6, 8 - Failed 2/8 tests, 75.00% okay - Failed 1/1 test scripts, 0.00% okay. 2/8 subtests failed, 75.00% okay. - -6. We see that test number 6 failed. According to get-getpw.t, this test - is executed like this: - do_test 6 'getpwnam() snapshot' '-n -s snapshot_pwd' - - To determine why the test has failed, we need to run it in debug mode - - it means adding "-d" to the options list. - -7. ./test-getpw -dn -s snapshot_pwd - ... - testing getpwnam() with the following data: - toor:*:0:0:0::ne-again Superuser:/root::0:4831 - testing correctness with the following data: - toor:*:0:0:0::Bourne-again Superuser:/root::0:4831 - correct - not ok - -8. Here we can see that the data from snapshot (first "toor" line) and - the data received from the getpwnam() call (second "toor" line) are - different. It is the reason why the test has failed. If you can't - (or don't want) to investigate the problem by yourself, mail - the test debug output and the snapshot file to the developers list. - -Notes on using standalone nsswitch tests ----------------------------------------- - -All nsswitch tests have [-d] optional command line argument which enables -debug output. The debug output can be extremely helpful to determine the -cause of test failure. - -In all nsswitch tests -s <file> command line argument specifies the -snapshot file. If this file doesn't exist, it would be built during -test execution. If it already exists then it will be used to check -the results of particular function calls. This argument is mostly -optional, but some tests (test-getaddr and test-getusershell) force -it to be specified. - -test-gethostby and test-getaddr require the list of hostnames, that should -be queried during the test. This list must be specified via -f <file> -command line argument. Each hostname should occupy exactly one line -in the file. - -Detailed tests description --------------------------- - -./test-getaddr - tests the getaddrinfo() function. - Usage: test-getaddr [-d] [-46] [-s <file>] -f <file> - -d - enable debug output - -4 - force IPv4 usage - -6 - force IPv6 usage - -s - build/use specified snapshot file - -f - use specified hostnames list for testing - -./test-getgr - Usage: test-getgr -nge2 [-d] [-s <file>] - -d - enable debug output - -n - test getgrnam(3) - -g - test getgrgid(3) - -e - test getgrent(3) - -2 - test getgrent(3) in 2-pass mode - -s - build/use specified snapshot file - -./test-gethostby - Usage: test-gethostby -na2i [-o] [-d] [-m46] [-s <file>] -f <file> - -n - test gethostbyname2(3) - -a - test gethostbyaddr(3) - -2 - test gethostbyname2(3) results to be equal with getaddrinfo(3) - results for the similar query - -i - test gethostbyaddr(3) results to be equal with getnameinfo(3) - results for the similar query - -o - use getipnodebyname(3)/getipnodebyaddr(3) for testing instead of - gethostbyname2(3)/gethostbyaddr(3) - -d - enable debug output - -m - force IPv4-to-IPv6 mapping - -4 - force IPv4 usage - -6 - force IPv6 usage - -s - build/use specified snapshot file - -f - use specified hostnames list for testing - -./test-getproto - Usage: test-getproto -nve2 [-d] [-s <file>] - -d - enable debug output - -n - test getprotobyname(3) - -v - test getprotobynumber(3) - -e - test getprotoent(3) - -2 - test getprotoent(3) in 2-pass mode - -s - build/use specified snapshot file - -./test-getpw - Usage: test-getpw -nue2 [-d] [-s <file>] - -d - enable debug output - -n - test getpwnam(3) - -u - test getpwuid(3) - -e - test getpwent(3) - -2 - test getpwent(3) in 2-pass mode - -s - build/use snapshot file - -./test-getrpc - Usage: test-getrpc -nve2 [-d] [-s <file>] - -d - enable debug output - -n - test getrpcbyname(3) - -v - test getrpcbynumber(3) - -e - test getrpcent(3) - -2 - test getrpcent(3) in 2-pass mode - -s - build/use specified snapshot file - -./test-getserv - Usage: test-getserv -npe2 [-d] [-s <file>] - -d - enable debug output - -n - test getservbyname(3) - -p - test getservbyport(3) - -e - test getservent(3) - -2 - test getservent(3) in 2-pass mode - -s - build/use specified snapshot file - -./test-getusershell - Usage: test-getusershell [-d] -s <file> - -d - enable debug output - -s - build/use specified snapshot file - diff --git a/tools/regression/lib/libc/nss/mach b/tools/regression/lib/libc/nss/mach deleted file mode 100644 index 4b47ebb..0000000 --- a/tools/regression/lib/libc/nss/mach +++ /dev/null @@ -1,46 +0,0 @@ -# $FreeBSD$ -localhost -anoncvs.cirr.com -anoncvs.netbsd.se -antioche.antioche.eu.org -centaurus.4web.cz -chur.math.ntnu.no -console.netbsd.org -cvs.netbsd.org -cvsup.netbsd.se -ftp.chg.ru -ftp.estpak.ee -ftp.fsn.hu -ftp.funet.fi -ftp.netbsd.org -ftp.nluug.nl -ftp.plig.org -ftp.uni-erlangen.de -ftp.xgate.co.kr -gd.tuwien.ac.at -gort.ludd.luth.se -irc.warped.net -knug.youn.co.kr -mail.jp.netbsd.org -mail.netbsd.org -melanoma.cs.rmit.edu.au -mirror.aarnet.edu.au -moon.vub.ac.be -net.bsd.cz -netbsd.3miasto.net -netbsd.4ka.mipt.ru -netbsd.csie.nctu.edu.tw -netbsd.enderunix.org -netbsd.ftp.fu-berlin.de -netbsd.pair.com -netbsdiso.interoute.net.uk -netbsdwww.cs.rmit.edu.au -netbsdwww.interoute.net.uk -ns.netbsd.org -skeleton.phys.spbu.ru -www.en.netbsd.de -www.netbsd.cl -www.netbsd.nl -www.netbsd.org -www.netbsd.ro -zeppo.rediris.es diff --git a/tools/regression/lib/libc/nss/test-getaddr.t b/tools/regression/lib/libc/nss/test-getaddr.t deleted file mode 100644 index b3020f0..0000000 --- a/tools/regression/lib/libc/nss/test-getaddr.t +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -do_test() { - number=$1 - comment=$2 - opt=$3 - if ./$executable $opt; then - echo "ok $number - $comment" - else - echo "not ok $number - $comment" - fi -} - -cd `dirname $0` - -executable=`basename $0 .t` - -make $executable 2>&1 > /dev/null - -echo 1..6 -#Tests with hints.ai_family is set to PF_UNSPEC -do_test 1 'getaddrinfo() (PF_UNSPEC)' '-f mach' -do_test 2 'getaddrinfo() snapshot (PF_UNSPEC)' '-f mach -s snapshot_ai' - -#Tests with hints.ai_family is set to PF_INET -do_test 3 'getaddrinfo() (PF_INET)' '-f mach' -do_test 4 'getaddrinfo() snapshot (PF_INET)' '-4 -f mach -s snapshot_ai4' - -#Tests with hints.ai_family is set to PF_INET6 -do_test 5 'getaddrinfo() (PF_INET6)' '-f mach' -do_test 6 'getaddrinfo() snapshot (PF_INET6)' '-6 -f mach -s snapshot_ai6' - diff --git a/tools/regression/lib/libc/nss/test-getgr.t b/tools/regression/lib/libc/nss/test-getgr.t deleted file mode 100644 index e2cf8e5..0000000 --- a/tools/regression/lib/libc/nss/test-getgr.t +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -do_test() { - number=$1 - comment=$2 - opt=$3 - if ./$executable $opt; then - echo "ok $number - $comment" - else - echo "not ok $number - $comment" - fi -} - -cd `dirname $0` - -executable=`basename $0 .t` - -make $executable 2>&1 > /dev/null - -echo 1..8 -do_test 1 'getgrnam()' '-n' -do_test 2 'getgrgid()' '-g' -do_test 3 'getgrent()' '-e' -do_test 4 'getgrent() 2-pass' '-2' -do_test 5 'building snapshot, if needed' '-s snapshot_grp' -do_test 6 'getgrnam() snapshot' '-n -s snapshot_grp' -do_test 7 'getgrgid() snapshot' '-g -s snapshot_grp' -do_test 8 'getgrent() snapshot' '-e -s snapshot_grp' diff --git a/tools/regression/lib/libc/nss/test-gethostby.c b/tools/regression/lib/libc/nss/test-gethostby.c deleted file mode 100644 index 9e7bdf5..0000000 --- a/tools/regression/lib/libc/nss/test-gethostby.c +++ /dev/null @@ -1,1105 +0,0 @@ -/*- - * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <arpa/inet.h> -#include <sys/socket.h> -#include <sys/types.h> -#include <netinet/in.h> -#include <assert.h> -#include <errno.h> -#include <netdb.h> -#include <resolv.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stringlist.h> -#include <unistd.h> -#include "testutil.h" - -#ifndef min -#define min(a,b) (((a)<(b))?(a):(b)) -#endif - -enum test_methods { - TEST_GETHOSTBYNAME2, - TEST_GETHOSTBYADDR, - TEST_GETHOSTBYNAME2_GETADDRINFO, - TEST_GETHOSTBYADDR_GETNAMEINFO, - TEST_BUILD_SNAPSHOT, - TEST_BUILD_ADDR_SNAPSHOT -}; - -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; - -DECLARE_TEST_DATA(hostent) -DECLARE_TEST_FILE_SNAPSHOT(hostent) -DECLARE_1PASS_TEST(hostent) -DECLARE_2PASS_TEST(hostent) - -/* These stubs will use gethostby***() or getipnodeby***() functions, - * depending on the use_ipnode_functions global variable value */ -static struct hostent *__gethostbyname2(const char *, int); -static struct hostent *__gethostbyaddr(const void *, socklen_t, int); -static void __freehostent(struct hostent *); - -static void clone_hostent(struct hostent *, struct hostent const *); -static int compare_hostent(struct hostent *, struct hostent *, void *); -static void dump_hostent(struct hostent *); -static void free_hostent(struct hostent *); - -static int is_hostent_equal(struct hostent *, struct addrinfo *); - -static void sdump_hostent(struct hostent *, char *, size_t); -static int hostent_read_hostlist_func(struct hostent *, char *); -static int hostent_read_snapshot_addr(char *, unsigned char *, size_t); -static int hostent_read_snapshot_func(struct hostent *, char *); - -static int hostent_test_correctness(struct hostent *, void *); -static int hostent_test_gethostbyaddr(struct hostent *, void *); -static int hostent_test_getaddrinfo_eq(struct hostent *, void *); -static int hostent_test_getnameinfo_eq(struct hostent *, void *); - -static void usage(void) __attribute__((__noreturn__)); - -IMPLEMENT_TEST_DATA(hostent) -IMPLEMENT_TEST_FILE_SNAPSHOT(hostent) -IMPLEMENT_1PASS_TEST(hostent) -IMPLEMENT_2PASS_TEST(hostent) - -static struct hostent * -__gethostbyname2(const char *name, int af) -{ - struct hostent *he; - int error; - - if (use_ipnode_functions == 0) - he = gethostbyname2(name, af); - else { - error = 0; - he = getipnodebyname(name, af, ipnode_flags, &error); - if (he == NULL) - errno = error; - } - - return (he); -} - -static struct hostent * -__gethostbyaddr(const void *addr, socklen_t len, int af) -{ - struct hostent *he; - int error; - - if (use_ipnode_functions == 0) - he = gethostbyaddr(addr, len, af); - else { - error = 0; - he = getipnodebyaddr(addr, len, af, &error); - if (he == NULL) - errno = error; - } - - return (he); -} - -static void -__freehostent(struct hostent *he) -{ - /* NOTE: checking for he != NULL - just in case */ - if ((use_ipnode_functions != 0) && (he != NULL)) - freehostent(he); -} - -static void -clone_hostent(struct hostent *dest, struct hostent const *src) -{ - assert(dest != NULL); - assert(src != NULL); - - char **cp; - int aliases_num; - int addrs_num; - size_t offset; - - memset(dest, 0, sizeof(struct hostent)); - - if (src->h_name != NULL) { - dest->h_name = strdup(src->h_name); - assert(dest->h_name != NULL); - } - - dest->h_addrtype = src->h_addrtype; - dest->h_length = src->h_length; - - if (src->h_aliases != NULL) { - aliases_num = 0; - for (cp = src->h_aliases; *cp; ++cp) - ++aliases_num; - - dest->h_aliases = (char **)malloc((aliases_num + 1) * - (sizeof(char *))); - assert(dest->h_aliases != NULL); - memset(dest->h_aliases, 0, (aliases_num + 1) * - (sizeof(char *))); - - for (cp = src->h_aliases; *cp; ++cp) { - dest->h_aliases[cp - src->h_aliases] = strdup(*cp); - assert(dest->h_aliases[cp - src->h_aliases] != NULL); - } - } - - if (src->h_addr_list != NULL) { - addrs_num = 0; - for (cp = src->h_addr_list; *cp; ++cp) - ++addrs_num; - - dest->h_addr_list = (char **)malloc((addrs_num + 1) * - (sizeof(char *))); - assert(dest->h_addr_list != NULL); - memset(dest->h_addr_list, 0, (addrs_num + 1) * - (sizeof(char *))); - - for (cp = src->h_addr_list; *cp; ++cp) { - offset = cp - src->h_addr_list; - dest->h_addr_list[offset] = - (char *)malloc(src->h_length); - assert(dest->h_addr_list[offset] != NULL); - memcpy(dest->h_addr_list[offset], - src->h_addr_list[offset], src->h_length); - } - } -} - -static void -free_hostent(struct hostent *ht) -{ - char **cp; - - assert(ht != NULL); - - free(ht->h_name); - - if (ht->h_aliases != NULL) { - for (cp = ht->h_aliases; *cp; ++cp) - free(*cp); - free(ht->h_aliases); - } - - if (ht->h_addr_list != NULL) { - for (cp = ht->h_addr_list; *cp; ++cp) - free(*cp); - free(ht->h_addr_list); - } -} - -static int -compare_hostent(struct hostent *ht1, struct hostent *ht2, void *mdata) -{ - char **c1, **c2, **ct, **cb; - int b; - - if (ht1 == ht2) - return 0; - - if ((ht1 == NULL) || (ht2 == NULL)) - goto errfin; - - if ((ht1->h_name == NULL) || (ht2->h_name == NULL)) - goto errfin; - - if ((ht1->h_addrtype != ht2->h_addrtype) || - (ht1->h_length != ht2->h_length) || - (strcmp(ht1->h_name, ht2->h_name) != 0)) - goto errfin; - - c1 = ht1->h_aliases; - c2 = ht2->h_aliases; - - if (((ht1->h_aliases == NULL) || (ht2->h_aliases == NULL)) && - (ht1->h_aliases != ht2->h_aliases)) - goto errfin; - - if ((c1 != NULL) && (c2 != NULL)) { - 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; - } - } - - 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; - c2 = ht2->h_addr_list; - - if (((ht1->h_addr_list == NULL) || (ht2->h_addr_list== NULL)) && - (ht1->h_addr_list != ht2->h_addr_list)) - goto errfin; - - if ((c1 != NULL) && (c2 != NULL)) { - 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; - } - } - - 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; - -errfin: - if ((debug) && (mdata == NULL)) { - printf("following structures are not equal:\n"); - dump_hostent(ht1); - dump_hostent(ht2); - } - - return (-1); -} - -static int -check_addrinfo_for_name(struct addrinfo *ai, char const *name) -{ - struct addrinfo *ai2; - - for (ai2 = ai; ai2 != NULL; ai2 = ai2->ai_next) { - if (strcmp(ai2->ai_canonname, name) == 0) - return (0); - } - - return (-1); -} - -static int -check_addrinfo_for_addr(struct addrinfo *ai, char const *addr, - socklen_t addrlen, int af) -{ - struct addrinfo *ai2; - - for (ai2 = ai; ai2 != NULL; ai2 = ai2->ai_next) { - if (af != ai2->ai_family) - continue; - - switch (af) { - case AF_INET: - if (memcmp(addr, - (void *)&((struct sockaddr_in *)ai2->ai_addr)->sin_addr, - min(addrlen, ai2->ai_addrlen)) == 0) - return (0); - break; - case AF_INET6: - if (memcmp(addr, - (void *)&((struct sockaddr_in6 *)ai2->ai_addr)->sin6_addr, - min(addrlen, ai2->ai_addrlen)) == 0) - return (0); - break; - default: - break; - } - } - - return (-1); -} - -static int -is_hostent_equal(struct hostent *he, struct addrinfo *ai) -{ - char **cp; - int rv; - - if (debug) - printf("checking equality of he and ai\n"); - - rv = check_addrinfo_for_name(ai, he->h_name); - if (rv != 0) { - if (debug) - printf("not equal - he->h_name couldn't be found\n"); - - return (rv); - } - - for (cp = he->h_addr_list; *cp; ++cp) { - rv = check_addrinfo_for_addr(ai, *cp, he->h_length, - he->h_addrtype); - if (rv != 0) { - if (debug) - printf("not equal - one of he->h_addr_list couldn't be found\n"); - - return (rv); - } - } - - if (debug) - printf("equal\n"); - - return (0); -} - -static void -sdump_hostent(struct hostent *ht, char *buffer, size_t buflen) -{ - char **cp; - size_t i; - int written; - - written = snprintf(buffer, buflen, "%s %d %d", - ht->h_name, ht->h_addrtype, ht->h_length); - buffer += written; - if (written > buflen) - return; - buflen -= written; - - if (ht->h_aliases != NULL) { - if (*(ht->h_aliases) != NULL) { - for (cp = ht->h_aliases; *cp; ++cp) { - written = snprintf(buffer, buflen, " %s",*cp); - buffer += written; - if (written > buflen) - return; - buflen -= written; - - if (buflen == 0) - return; - } - } else { - written = snprintf(buffer, buflen, " noaliases"); - buffer += written; - if (written > buflen) - return; - buflen -= written; - } - } else { - written = snprintf(buffer, buflen, " (null)"); - buffer += written; - if (written > buflen) - return; - buflen -= written; - } - - written = snprintf(buffer, buflen, " : "); - buffer += written; - if (written > buflen) - return; - buflen -= written; - - if (ht->h_addr_list != NULL) { - if (*(ht->h_addr_list) != NULL) { - for (cp = ht->h_addr_list; *cp; ++cp) { - for (i = 0; i < ht->h_length; ++i ) { - written = snprintf(buffer, buflen, - i + 1 != ht->h_length ? "%d." : "%d", - (unsigned char)(*cp)[i]); - buffer += written; - if (written > buflen) - return; - buflen -= written; - - if (buflen == 0) - return; - } - - if (*(cp + 1) ) { - written = snprintf(buffer, buflen, " "); - buffer += written; - if (written > buflen) - return; - buflen -= written; - } - } - } else { - written = snprintf(buffer, buflen, " noaddrs"); - buffer += written; - if (written > buflen) - return; - buflen -= written; - } - } else { - written = snprintf(buffer, buflen, " (null)"); - buffer += written; - if (written > buflen) - return; - buflen -= written; - } -} - -static int -hostent_read_hostlist_func(struct hostent *he, char *line) -{ - struct hostent *result; - int rv; - - if (debug) - printf("resolving %s: ", line); - result = __gethostbyname2(line, af_type); - if (result != NULL) { - if (debug) - printf("found\n"); - - rv = hostent_test_correctness(result, NULL); - if (rv != 0) { - __freehostent(result); - return (rv); - } - - clone_hostent(he, result); - __freehostent(result); - } else { - if (debug) - printf("not found\n"); - - memset(he, 0, sizeof(struct hostent)); - he->h_name = strdup(line); - assert(he->h_name != NULL); - } - return (0); -} - -static int -hostent_read_snapshot_addr(char *addr, unsigned char *result, size_t len) -{ - char *s, *ps, *ts; - - ps = addr; - while ( (s = strsep(&ps, ".")) != NULL) { - if (len == 0) - return (-1); - - *result = (unsigned char)strtol(s, &ts, 10); - ++result; - if (*ts != '\0') - return (-1); - - --len; - } - if (len != 0) - return (-1); - else - return (0); -} - -static int -hostent_read_snapshot_func(struct hostent *ht, char *line) -{ - StringList *sl1, *sl2; - char *s, *ps, *ts; - int i, rv; - - if (debug) - printf("1 line read from snapshot:\n%s\n", line); - - rv = 0; - i = 0; - sl1 = sl2 = NULL; - ps = line; - memset(ht, 0, sizeof(struct hostent)); - while ( (s = strsep(&ps, " ")) != NULL) { - switch (i) { - case 0: - ht->h_name = strdup(s); - assert(ht->h_name != NULL); - break; - - case 1: - ht->h_addrtype = (int)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; - break; - - case 2: - ht->h_length = (int)strtol(s, &ts, 10); - if (*ts != '\0') - goto fin; - break; - - case 3: - if (sl1 == NULL) { - if (strcmp(s, "(null)") == 0) - return (0); - - sl1 = sl_init(); - assert(sl1 != NULL); - - if (strcmp(s, "noaliases") != 0) { - ts = strdup(s); - assert(ts != NULL); - sl_add(sl1, ts); - } - } else { - if (strcmp(s, ":") == 0) - ++i; - else { - ts = strdup(s); - assert(ts != NULL); - sl_add(sl1, ts); - } - } - break; - - case 4: - if (sl2 == NULL) { - if (strcmp(s, "(null)") == 0) - return (0); - - sl2 = sl_init(); - assert(sl2 != NULL); - - if (strcmp(s, "noaddrs") != 0) { - ts = (char *)malloc(ht->h_length); - assert(ts != NULL); - memset(ts, 0, ht->h_length); - rv = hostent_read_snapshot_addr(s,\ - (unsigned char *)ts, ht->h_length); - sl_add(sl2, ts); - if (rv != 0) - goto fin; - } - } else { - ts = (char *)malloc(ht->h_length); - assert(ts != NULL); - memset(ts, 0, ht->h_length); - rv = hostent_read_snapshot_addr(s,\ - (unsigned char *)ts, ht->h_length); - sl_add(sl2, ts); - if (rv != 0) - goto fin; - } - break; - default: - break; - }; - - if ((i != 3) && (i != 4)) - ++i; - } - -fin: - if (sl1 != NULL) { - sl_add(sl1, NULL); - ht->h_aliases = sl1->sl_str; - } - if (sl2 != NULL) { - sl_add(sl2, NULL); - ht->h_addr_list = sl2->sl_str; - } - - if ((i != 4) || (rv != 0)) { - free_hostent(ht); - memset(ht, 0, sizeof(struct hostent)); - return (-1); - } - - /* NOTE: is it a dirty hack or not? */ - free(sl1); - free(sl2); - return (0); -} - -static void -dump_hostent(struct hostent *result) -{ - if (result != NULL) { - char buffer[1024]; - sdump_hostent(result, buffer, sizeof(buffer)); - printf("%s\n", buffer); - } else - printf("(null)\n"); -} - -static int -hostent_test_correctness(struct hostent *ht, void *mdata) -{ - if (debug) { - printf("testing correctness with the following data:\n"); - dump_hostent(ht); - } - - if (ht == NULL) - goto errfin; - - if (ht->h_name == NULL) - goto errfin; - - if (!((ht->h_addrtype >= 0) && (ht->h_addrtype < AF_MAX))) - goto errfin; - - if ((ht->h_length != sizeof(struct in_addr)) && - (ht->h_length != sizeof(struct in6_addr))) - goto errfin; - - if (ht->h_aliases == NULL) - goto errfin; - - if (ht->h_addr_list == NULL) - goto errfin; - - if (debug) - printf("correct\n"); - - return (0); -errfin: - if (debug) - printf("incorrect\n"); - - return (-1); -} - -static int -hostent_test_gethostbyaddr(struct hostent *he, void *mdata) -{ - struct hostent *result; - struct hostent_test_data *addr_test_data; - int rv; - - addr_test_data = (struct hostent_test_data *)mdata; - - /* We should omit unresolved hostents */ - if (he->h_addr_list != NULL) { - char **cp; - for (cp = he->h_addr_list; *cp; ++cp) { - if (debug) - printf("doing reverse lookup for %s\n", he->h_name); - - result = __gethostbyaddr(*cp, he->h_length, - he->h_addrtype); - if (result == NULL) { - if (debug) - printf("warning: reverse lookup failed\n"); - - continue; - } - rv = hostent_test_correctness(result, NULL); - if (rv != 0) { - __freehostent(result); - return (rv); - } - - if (addr_test_data != NULL) - TEST_DATA_APPEND(hostent, addr_test_data, result); - - __freehostent(result); - } - } - - return (0); -} - -static int -hostent_test_getaddrinfo_eq(struct hostent *he, void *mdata) -{ - struct addrinfo *ai, hints; - int rv; - - ai = NULL; - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = af_type; - hints.ai_flags = AI_CANONNAME; - - if (debug) - printf("using getaddrinfo() to resolve %s\n", he->h_name); - - /* struct hostent *he was not resolved */ - if (he->h_addr_list == NULL) { - /* We can be sure that he->h_name is not NULL */ - rv = getaddrinfo(he->h_name, NULL, &hints, &ai); - if (rv == 0) { - if (debug) - printf("not ok - shouldn't have been resolved\n"); - return (-1); - } - } else { - rv = getaddrinfo(he->h_name, NULL, &hints, &ai); - if (rv != 0) { - if (debug) - printf("not ok - should have beed resolved\n"); - return (-1); - } - - rv = is_hostent_equal(he, ai); - if (rv != 0) { - if (debug) - printf("not ok - addrinfo and hostent are not equal\n"); - return (-1); - } - - } - - return (0); -} - -static int -hostent_test_getnameinfo_eq(struct hostent *he, void *mdata) -{ - char buffer[NI_MAXHOST]; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - struct sockaddr *saddr; - struct hostent *result; - int rv; - - if (he->h_addr_list != NULL) { - char **cp; - for (cp = he->h_addr_list; *cp; ++cp) { - if (debug) - printf("doing reverse lookup for %s\n", he->h_name); - - result = __gethostbyaddr(*cp, he->h_length, - he->h_addrtype); - if (result != NULL) { - rv = hostent_test_correctness(result, NULL); - if (rv != 0) { - __freehostent(result); - return (rv); - } - } else { - if (debug) - printf("reverse lookup failed\n"); - } - - switch (he->h_addrtype) { - case AF_INET: - memset(&sin, 0, sizeof(struct sockaddr_in)); - sin.sin_len = sizeof(struct sockaddr_in); - sin.sin_family = AF_INET; - memcpy(&sin.sin_addr, *cp, he->h_length); - - saddr = (struct sockaddr *)&sin; - break; - case AF_INET6: - memset(&sin6, 0, sizeof(struct sockaddr_in6)); - sin6.sin6_len = sizeof(struct sockaddr_in6); - sin6.sin6_family = AF_INET6; - memcpy(&sin6.sin6_addr, *cp, he->h_length); - - saddr = (struct sockaddr *)&sin6; - break; - default: - if (debug) - printf("warning: %d family is unsupported\n", - he->h_addrtype); - continue; - } - - assert(saddr != NULL); - rv = getnameinfo(saddr, saddr->sa_len, buffer, - sizeof(buffer), NULL, 0, NI_NAMEREQD); - - if ((rv != 0) && (result != NULL)) { - if (debug) - printf("not ok - getnameinfo() didn't make the reverse lookup, when it should have (%s)\n", - gai_strerror(rv)); - return (rv); - } - - if ((rv == 0) && (result == NULL)) { - if (debug) - printf("not ok - getnameinfo() made the reverse lookup, when it shouldn't have\n"); - return (rv); - } - - if ((rv != 0) && (result == NULL)) { - if (debug) - printf("ok - both getnameinfo() and ***byaddr() failed\n"); - - continue; - } - - if (debug) - printf("comparing %s with %s\n", result->h_name, - buffer); - - rv = strcmp(result->h_name, buffer); - __freehostent(result); - - if (rv != 0) { - if (debug) - printf("not ok - getnameinfo() and ***byaddr() results are not equal\n"); - return (rv); - } else { - if (debug) - printf("ok - getnameinfo() and ***byaddr() results are equal\n"); - } - } - } - - return (0); -} - -static void -usage(void) -{ - (void)fprintf(stderr, - "Usage: %s -na2i [-o] [-d] [-46] [-mAcM] [-C] [-s <file>] -f <file>\n", - getprogname()); - exit(1); -} - -int -main(int argc, char **argv) -{ - struct hostent_test_data td, td_addr, td_snap; - char *snapshot_file, *hostlist_file; - res_state statp; - int rv; - int c; - - if (argc < 2) - usage(); - - snapshot_file = NULL; - hostlist_file = NULL; - 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': - 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; - break; - case 'd': - debug = 1; - break; - case 'n': - method = TEST_GETHOSTBYNAME2; - break; - case 'a': - method = TEST_GETHOSTBYADDR; - break; - case '2': - method = TEST_GETHOSTBYNAME2_GETADDRINFO; - break; - case 'i': - method = TEST_GETHOSTBYADDR_GETNAMEINFO; - break; - case 's': - snapshot_file = strdup(optarg); - break; - case 'f': - hostlist_file = strdup(optarg); - break; - 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); - TEST_DATA_INIT(hostent, &td_snap, clone_hostent, free_hostent); - - if (hostlist_file == NULL) - usage(); - - if (access(hostlist_file, R_OK) != 0) { - if (debug) - printf("can't access the hostlist file %s\n", - hostlist_file); - - usage(); - } - - if (debug) - printf("building host lists from %s\n", hostlist_file); - - rv = TEST_SNAPSHOT_FILE_READ(hostent, hostlist_file, &td, - hostent_read_hostlist_func); - if (rv != 0) - goto fin; - - if (snapshot_file != NULL) { - if (access(snapshot_file, W_OK | R_OK) != 0) { - if (errno == ENOENT) { - if (method != TEST_GETHOSTBYADDR) - method = TEST_BUILD_SNAPSHOT; - else - method = TEST_BUILD_ADDR_SNAPSHOT; - } else { - if (debug) - printf("can't access the snapshot file %s\n", - snapshot_file); - - rv = -1; - goto fin; - } - } else { - rv = TEST_SNAPSHOT_FILE_READ(hostent, snapshot_file, - &td_snap, hostent_read_snapshot_func); - if (rv != 0) { - if (debug) - printf("error reading snapshot file\n"); - goto fin; - } - } - } - - switch (method) { - case TEST_GETHOSTBYNAME2: - if (snapshot_file != NULL) - rv = DO_2PASS_TEST(hostent, &td, &td_snap, - compare_hostent, NULL); - break; - case TEST_GETHOSTBYADDR: - rv = DO_1PASS_TEST(hostent, &td, - hostent_test_gethostbyaddr, (void *)&td_addr); - - if (snapshot_file != NULL) - rv = DO_2PASS_TEST(hostent, &td_addr, &td_snap, - compare_hostent, NULL); - break; - case TEST_GETHOSTBYNAME2_GETADDRINFO: - rv = DO_1PASS_TEST(hostent, &td, - hostent_test_getaddrinfo_eq, NULL); - break; - case TEST_GETHOSTBYADDR_GETNAMEINFO: - rv = DO_1PASS_TEST(hostent, &td, - hostent_test_getnameinfo_eq, NULL); - break; - case TEST_BUILD_SNAPSHOT: - if (snapshot_file != NULL) { - rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file, &td, - sdump_hostent); - } - break; - case TEST_BUILD_ADDR_SNAPSHOT: - if (snapshot_file != NULL) { - rv = DO_1PASS_TEST(hostent, &td, - hostent_test_gethostbyaddr, (void *)&td_addr); - - rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file, - &td_addr, sdump_hostent); - } - break; - default: - rv = 0; - break; - }; - -fin: - TEST_DATA_DESTROY(hostent, &td_snap); - TEST_DATA_DESTROY(hostent, &td_addr); - 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 deleted file mode 100644 index 42bed00..0000000 --- a/tools/regression/lib/libc/nss/test-gethostby.t +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -do_test() { - number=$1 - comment=$2 - opt=$3 - if ./$executable $opt; then - echo "ok $number - $comment" - else - echo "not ok $number - $comment" - fi -} - -cd `dirname $0` - -executable=`basename $0 .t` - -make $executable 2>&1 > /dev/null - -echo 1..46 -#Tests for gethostby***() functions -#IPv4-driven testing -do_test 1 'gethostbyname2() (IPv4)' '-4 -n -f mach' -do_test 2 'gethostbyaddr() (IPv4)' '-4 -a -f mach' -do_test 3 'gethostbyname2()-getaddrinfo() (IPv4)' '-4 -2 -f mach' -do_test 4 'gethostbyaddr()-getnameinfo() (IPv4)' '-4 -i -f mach' -do_test 5 'gethostbyname2() snapshot (IPv4)'\ - '-4 -n -s snapshot_htname4 -f mach' -do_test 6 'gethostbyaddr() snapshot (IPv4)'\ - '-4 -a -s snapshot_htaddr4 -f mach' - -#IPv6-driven testing -do_test 7 'gethostbyname2() (IPv6)' '-6 -n -f mach' -do_test 8 'gethostbyaddr() (IPv6)' '-6 -a -f mach' -do_test 9 'gethostbyname2()-getaddrinfo() (IPv6)' '-6 -2 -f mach' -do_test 10 'gethostbyaddr()-getnameinfo() (IPv6)' '-6 -i -f mach' -do_test 11 'gethostbyname2() snapshot (IPv6)'\ - '-6 -n -s snapshot_htname6 -f mach' -do_test 12 'gethostbyaddr() snapshot (IPv6)'\ - '-6 -a -s snapshot_htaddr6 -f mach' - -#Mapped IPv6-driven testing (getaddrinfo() equality test is useless here) -do_test 13 'gethostbyname2() (IPv6 mapped)' '-m -n -f mach' -do_test 14 'gethostbyaddr() (IPv6 mapped)' '-m -a -f mach' -do_test 15 'gethostbyname2() snapshot (IPv6 mapped)'\ - '-m -n -s snapshot_htname6map -f mach' -do_test 16 'gethostbyaddr() snapshot (IPv6 mapped)'\ - '-m -a -s snapshot_htaddr6map -f mach' - -#Tests for getipnodeby***() functions -#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' -do_test 20 'getipnodebyaddr()-getnameinfo() (IPv4)' '-o -4 -i -f mach' -do_test 21 'getipnodebyname() snapshot (IPv4)'\ - '-o -4 -n -s snapshot_ipnodename4 -f mach' -do_test 22 'getipnodebyname() snapshot (IPv4)'\ - '-o -4 -a -s snapshot_ipnodeaddr4 -f mach' - -#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' -do_test 26 'getipnodebyaddr()-getnameinfo() (IPv6)' '-o -6 -i -f mach' -do_test 27 'getipnodebyname() snapshot (IPv6)'\ - '-o -6 -n -s snapshot_ipnodename6 -f mach' -do_test 28 'getipnodebyaddr() snapshot (IPv6)'\ - '-o -6 -a -s snapshot_ipnodeaddr6 -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' - diff --git a/tools/regression/lib/libc/nss/test-getproto.t b/tools/regression/lib/libc/nss/test-getproto.t deleted file mode 100644 index f582d31..0000000 --- a/tools/regression/lib/libc/nss/test-getproto.t +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -do_test() { - number=$1 - comment=$2 - opt=$3 - if ./$executable $opt; then - echo "ok $number - $comment" - else - echo "not ok $number - $comment" - fi -} - -cd `dirname $0` - -executable=`basename $0 .t` - -make $executable 2>&1 > /dev/null - -echo 1..8 -do_test 1 'getprotobyname()' '-n' -do_test 2 'getprotobynumber()' '-v' -do_test 3 'getprotoent()' '-e' -do_test 4 'getprotoent() 2-pass' '-2' -do_test 5 'building snapshot, if needed' '-s snapshot_proto' -do_test 6 'getprotobyname() snapshot' '-n -s snapshot_proto' -do_test 7 'getprotobynumber() snapshot' '-v -s snapshot_proto' -do_test 8 'getprotoent() snapshot' '-e -s snapshot_proto' diff --git a/tools/regression/lib/libc/nss/test-getpw.t b/tools/regression/lib/libc/nss/test-getpw.t deleted file mode 100644 index 5172177..0000000 --- a/tools/regression/lib/libc/nss/test-getpw.t +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -do_test() { - number=$1 - comment=$2 - opt=$3 - if ./$executable $opt; then - echo "ok $number - $comment" - else - echo "not ok $number - $comment" - fi -} - -cd `dirname $0` - -executable=`basename $0 .t` - -make $executable 2>&1 > /dev/null - -echo 1..8 -do_test 1 'getpwnam()' '-n' -do_test 2 'getpwuid()' '-u' -do_test 3 'getpwent()' '-e' -do_test 4 'getpwent() 2-pass' '-2' -do_test 5 'building snapshot, if needed' '-s snapshot_pwd' -do_test 6 'getpwnam() snapshot' '-n -s snapshot_pwd' -do_test 7 'getpwuid() snapshot' '-u -s snapshot_pwd' -do_test 8 'getpwent() snapshot' '-e -s snapshot_pwd' diff --git a/tools/regression/lib/libc/nss/test-getrpc.t b/tools/regression/lib/libc/nss/test-getrpc.t deleted file mode 100644 index 831a086..0000000 --- a/tools/regression/lib/libc/nss/test-getrpc.t +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -do_test() { - number=$1 - comment=$2 - opt=$3 - if ./$executable $opt; then - echo "ok $number - $comment" - else - echo "not ok $number - $comment" - fi -} - -cd `dirname $0` - -executable=`basename $0 .t` - -make $executable 2>&1 > /dev/null - -echo 1..8 -do_test 1 'getrpcbyname()' '-n' -do_test 2 'getrpcbynumber()' '-v' -do_test 3 'getrpcent()' '-e' -do_test 4 'getrpcent() 2-pass' '-2' -do_test 5 'building snapshot, if needed' '-s snapshot_rpc' -do_test 6 'getrpcbyname() snapshot' '-n -s snapshot_rpc' -do_test 7 'getrpcbynumber() snapshot' '-v -s snapshot_rpc' -do_test 8 'getrpcent() snapshot' '-e -s snapshot_rpc' diff --git a/tools/regression/lib/libc/nss/test-getserv.t b/tools/regression/lib/libc/nss/test-getserv.t deleted file mode 100644 index 60a6c50..0000000 --- a/tools/regression/lib/libc/nss/test-getserv.t +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -do_test() { - number=$1 - comment=$2 - opt=$3 - if ./$executable $opt; then - echo "ok $number - $comment" - else - echo "not ok $number - $comment" - fi -} - -cd `dirname $0` - -executable=`basename $0 .t` - -make $executable 2>&1 > /dev/null - -echo 1..8 -do_test 1 'getservbyname()' '-n' -do_test 2 'getservbyport()' '-p' -do_test 3 'getservent()' '-e' -do_test 4 'getservent() 2-pass' '-2' -do_test 5 'building snapshot, if needed' '-s snapshot_serv' -do_test 6 'getservbyname() snapshot' '-n -s snapshot_serv' -do_test 7 'getservbyport() snapshot' '-p -s snapshot_serv' -do_test 8 'getservent() snapshot' '-e -s snapshot_serv' diff --git a/tools/regression/lib/libc/nss/test-getusershell.t b/tools/regression/lib/libc/nss/test-getusershell.t deleted file mode 100644 index 16a392a..0000000 --- a/tools/regression/lib/libc/nss/test-getusershell.t +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -do_test() { - number=$1 - comment=$2 - opt=$3 - if ./$executable $opt; then - echo "ok $number - $comment" - else - echo "not ok $number - $comment" - fi -} - -cd `dirname $0` - -executable=`basename $0 .t` - -make $executable 2>&1 > /dev/null - -echo 1..1 -do_test 1 'getusershell() snapshot' '-s snapshot_usershell' |