Patch from Zack Weinberg: normalize perror() tt functions and add tt_fail/tt_abort_printf

svn:r1340
This commit is contained in:
Nick Mathewson 2009-07-13 20:03:00 +00:00
parent 0cc10e419c
commit d866f05585
4 changed files with 12 additions and 14 deletions

View File

@ -356,7 +356,7 @@ dns_server(void)
/* Now configure a nameserver port. */ /* Now configure a nameserver port. */
sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock<=0) { if (sock<=0) {
tt_fail_perror("socket"); tt_abort_perror("socket");
} }
evutil_make_socket_nonblocking(sock); evutil_make_socket_nonblocking(sock);
@ -366,7 +366,7 @@ dns_server(void)
my_addr.sin_port = htons(35353); my_addr.sin_port = htons(35353);
my_addr.sin_addr.s_addr = htonl(0x7f000001UL); my_addr.sin_addr.s_addr = htonl(0x7f000001UL);
if (bind(sock, (struct sockaddr*)&my_addr, sizeof(my_addr)) < 0) { if (bind(sock, (struct sockaddr*)&my_addr, sizeof(my_addr)) < 0) {
tt_fail_perror("bind"); tt_abort_perror("bind");
} }
port = evdns_add_server_port(sock, 0, dns_server_request_cb, NULL); port = evdns_add_server_port(sock, 0, dns_server_request_cb, NULL);

View File

@ -90,7 +90,7 @@ test_edgetriggered(void *et)
int success; int success;
if (evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, pair) == -1) { if (evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, pair) == -1) {
tt_fail_perror("socketpair"); tt_abort_perror("socketpair");
} }
called = was_et = 0; called = was_et = 0;

View File

@ -261,7 +261,7 @@ test_bufferevent_zlib(void *arg)
= errorcb_invoked = 0; = errorcb_invoked = 0;
if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) { if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
tt_fail_perror("socketpair"); tt_abort_perror("socketpair");
} }
evutil_make_socket_nonblocking(pair[0]); evutil_make_socket_nonblocking(pair[0]);

View File

@ -68,12 +68,16 @@
TT_STMT_END TT_STMT_END
/* Fail and abort the current test for the reason in msg */ /* Fail and abort the current test for the reason in msg */
#define tt_abort_msg(msg) TT_DIE((msg)) #define tt_abort_printf(msg) TT_DIE(msg)
#define tt_abort() tt_fail_msg("(Failed.)") #define tt_abort_perror(op) TT_DIE(("%s: %s [%d]",(op),strerror(errno), errno))
#define tt_abort_msg(msg) TT_DIE(("%s", msg))
#define tt_abort() TT_DIE(("%s", "(Failed.)"))
/* Fail but do not abort the current test for the reason in msg. */ /* Fail but do not abort the current test for the reason in msg. */
#define tt_fail_msg(msg) TT_FAIL((msg)) #define tt_fail_printf(msg) TT_FAIL(msg)
#define tt_fail() tt_fail_msg("(Failed.)") #define tt_fail_perror(op) TT_FAIL(("%s: %s [%d]",(op),strerror(errno), errno))
#define tt_fail_msg(msg) TT_FAIL(("%s", msg))
#define tt_fail() TT_FAIL(("%s", "(Failed.)"))
/* End the current test, and indicate we are skipping it. */ /* End the current test, and indicate we are skipping it. */
#define tt_skip() \ #define tt_skip() \
@ -135,10 +139,4 @@
tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \ tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \
(strcmp(_val1,_val2) op 0),"<%s>") (strcmp(_val1,_val2) op 0),"<%s>")
/** Fail and log the errno as with perror. */
#define tt_fail_perror(op) \
TT_STMT_BEGIN \
TT_DIE(("%s: %s [%d]",(op),strerror(errno),errno)); \
TT_STMT_END
#endif #endif