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
This commit is contained in:
parent
11b249f99e
commit
08ca345cfd
@ -271,6 +271,8 @@
|
||||
..
|
||||
..
|
||||
..
|
||||
nss
|
||||
..
|
||||
regex
|
||||
data
|
||||
..
|
||||
|
22
lib/libc/tests/nss/Makefile
Normal file
22
lib/libc/tests/nss/Makefile
Normal file
@ -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>
|
@ -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;
|
||||
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 (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());
|
||||
}
|
@ -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());
|
||||
}
|
1506
lib/libc/tests/nss/gethostby_test.c
Normal file
1506
lib/libc/tests/nss/gethostby_test.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -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());
|
||||
}
|
@ -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());
|
||||
}
|
@ -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(). */
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
@ -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());
|
||||
}
|
@ -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);
|
||||
|
||||
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());
|
||||
}
|
@ -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) \
|
@ -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}
|
@ -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
|
||||
|
@ -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
|
@ -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'
|
||||
|
@ -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'
|
File diff suppressed because it is too large
Load Diff
@ -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'
|
||||
|
@ -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'
|
@ -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'
|
@ -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'
|
@ -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'
|
@ -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'
|
Loading…
Reference in New Issue
Block a user