1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-29 12:03:03 +00:00

Push snapshot_file copying down into run_tests function, and mark snapshot_file

const char *.

This fixes a bogus set of errors from gcc about strdup not being allowed a NULL
argument.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon
This commit is contained in:
Enji Cooper 2017-05-28 06:26:43 +00:00
parent e1b98d0774
commit 8eb2367596
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=319048
2 changed files with 32 additions and 25 deletions

View File

@ -410,11 +410,19 @@ addrinfo_read_hostlist_func(struct addrinfo *ai, char *line)
}
static void
run_tests(char *hostlist_file, char *snapshot_file, int ai_family)
run_tests(char *hostlist_file, const char *snapshot_file, int ai_family)
{
struct addrinfo_test_data td, td_snap;
char *snapshot_file_copy;
int rv;
if (snapshot_file == NULL)
snapshot_file_copy = NULL;
else {
snapshot_file_copy = strdup(snapshot_file);
ATF_REQUIRE(snapshot_file_copy != NULL);
}
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = ai_family;
hints.ai_flags = AI_CANONNAME;
@ -477,24 +485,17 @@ run_tests(char *hostlist_file, char *snapshot_file, int ai_family)
TEST_DATA_DESTROY(addrinfo, &td_snap);
TEST_DATA_DESTROY(addrinfo, &td);
free(hostlist_file);
free(snapshot_file);
free(snapshot_file_copy);
}
#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)
run_tests(_hostlist_file, snapshot_file, ai_family); \
free(_hostlist_file); \
} while (0)
ATF_TC_WITHOUT_HEAD(pf_unspec);
ATF_TC_BODY(pf_unspec, tc)

View File

@ -924,10 +924,19 @@ static int
run_tests(const char *hostlist_file, const char *snapshot_file, int _af_type,
enum test_methods method, bool use_ipv6_mapping)
{
char *snapshot_file_copy;
struct hostent_test_data td, td_addr, td_snap;
res_state statp;
int rv = -2;
if (snapshot_file == NULL)
snapshot_file_copy = NULL;
else {
snapshot_file_copy = strdup(snapshot_file);
ATF_REQUIRE(snapshot_file_copy != NULL);
}
snapshot_file = snapshot_file_copy;
switch (_af_type) {
case AF_INET:
ATF_REQUIRE_FEATURE("inet");
@ -946,8 +955,8 @@ run_tests(const char *hostlist_file, const char *snapshot_file, int _af_type,
if (statp == NULL || ((statp->options & RES_INIT) == 0 &&
res_ninit(statp) == -1)) {
printf("error: can't init res_state\n");
return (-1);
rv = -1;
goto fin2;
}
if (use_ipv6_mapping)
@ -1051,6 +1060,9 @@ run_tests(const char *hostlist_file, const char *snapshot_file, int _af_type,
TEST_DATA_DESTROY(hostent, &td_addr);
TEST_DATA_DESTROY(hostent, &td);
fin2:
free(snapshot_file_copy);
return (rv);
}
@ -1059,30 +1071,24 @@ run_tests(const char *hostlist_file, const char *snapshot_file, int _af_type,
#define _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
do { \
char *_hostlist_file; \
char *_snapshot_file; \
ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \
atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \
if (snapshot_file == NULL) \
_snapshot_file = NULL; \
else { \
_snapshot_file = strdup(snapshot_file); \
ATF_REQUIRE(_snapshot_file != NULL); \
} \
ATF_REQUIRE(run_tests(_hostlist_file, _snapshot_file, af_type, \
ATF_REQUIRE(run_tests(_hostlist_file, snapshot_file, af_type, \
method, use_ipv6_mapping) == 0); \
} while(0)
free(_hostlist_file); \
} while (0)
#define RUN_HOST_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
do { \
use_ipnode_functions = false; \
_RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \
} while(0)
} while (0)
#define RUN_IPNODE_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
do { \
use_ipnode_functions = true; \
_RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \
} while(0)
} while (0)
ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv4);
ATF_TC_BODY(gethostbyaddr_ipv4, tc)