Merge remote-tracking branch 'origin/patches-2.0'

Conflicts:
	configure.in
	test/regress_buffer.c
	test/regress_dns.c
This commit is contained in:
Nick Mathewson 2012-07-26 10:09:13 -04:00
commit 7ef04e4b48
10 changed files with 72 additions and 19 deletions

View File

@ -216,11 +216,13 @@ AC_CHECK_HEADERS([ \
sys/select.h \ sys/select.h \
sys/sendfile.h \ sys/sendfile.h \
sys/socket.h \ sys/socket.h \
sys/stat.h \
sys/time.h \ sys/time.h \
sys/timerfd.h \ sys/timerfd.h \
sys/uio.h \ sys/uio.h \
sys/wait.h \ sys/wait.h \
]) ])
AC_CHECK_HEADERS(sys/sysctl.h, [], [], [ AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
#ifdef HAVE_SYS_PARAM_H #ifdef HAVE_SYS_PARAM_H
#include <sys/param.h> #include <sys/param.h>
@ -354,6 +356,7 @@ AC_CHECK_FUNCS([ \
strtoll \ strtoll \
sysctl \ sysctl \
timerfd_create \ timerfd_create \
umask \
unsetenv \ unsetenv \
usleep \ usleep \
vasprintf \ vasprintf \

View File

@ -2274,6 +2274,10 @@ test_event_pending(void *ptr)
NULL); NULL);
t = evtimer_new(data->base, timeout_cb, NULL); t = evtimer_new(data->base, timeout_cb, NULL);
tt_assert(r);
tt_assert(w);
tt_assert(t);
evutil_gettimeofday(&now, NULL); evutil_gettimeofday(&now, NULL);
event_add(r, NULL); event_add(r, NULL);
event_add(t, &tv); event_add(t, &tv);
@ -2371,6 +2375,7 @@ end:
event_free(ev1); event_free(ev1);
if (ev2) if (ev2)
event_free(ev2); event_free(ev2);
if (dfd >= 0)
close(dfd); close(dfd);
} }
#endif #endif

View File

@ -1232,6 +1232,8 @@ test_evbuffer_find(void *ptr)
unsigned int i; unsigned int i;
struct evbuffer * buf = evbuffer_new(); struct evbuffer * buf = evbuffer_new();
tt_assert(buf);
/* make sure evbuffer_find doesn't match past the end of the buffer */ /* make sure evbuffer_find doesn't match past the end of the buffer */
evbuffer_add(buf, (u_char*)test1, strlen(test1)); evbuffer_add(buf, (u_char*)test1, strlen(test1));
evbuffer_validate(buf); evbuffer_validate(buf);
@ -1273,6 +1275,8 @@ test_evbuffer_ptr_set(void *ptr)
struct evbuffer_ptr pos; struct evbuffer_ptr pos;
struct evbuffer_iovec v[1]; struct evbuffer_iovec v[1];
tt_assert(buf);
tt_int_op(evbuffer_get_length(buf), ==, 0); tt_int_op(evbuffer_get_length(buf), ==, 0);
tt_assert(evbuffer_ptr_set(buf, &pos, 0, EVBUFFER_PTR_SET) == 0); tt_assert(evbuffer_ptr_set(buf, &pos, 0, EVBUFFER_PTR_SET) == 0);
@ -1331,6 +1335,9 @@ test_evbuffer_search(void *ptr)
struct evbuffer *tmp = evbuffer_new(); struct evbuffer *tmp = evbuffer_new();
struct evbuffer_ptr pos, end; struct evbuffer_ptr pos, end;
tt_assert(buf);
tt_assert(tmp);
pos = evbuffer_search(buf, "x", 1, NULL); pos = evbuffer_search(buf, "x", 1, NULL);
tt_int_op(pos.pos, ==, -1); tt_int_op(pos.pos, ==, -1);
tt_assert(evbuffer_ptr_set(buf, &pos, 0, EVBUFFER_PTR_SET) == 0); tt_assert(evbuffer_ptr_set(buf, &pos, 0, EVBUFFER_PTR_SET) == 0);
@ -1436,6 +1443,10 @@ test_evbuffer_callbacks(void *ptr)
struct evbuffer *buf_out2 = evbuffer_new(); struct evbuffer *buf_out2 = evbuffer_new();
struct evbuffer_cb_entry *cb1, *cb2; struct evbuffer_cb_entry *cb1, *cb2;
tt_assert(buf);
tt_assert(buf_out1);
tt_assert(buf_out2);
cb1 = evbuffer_add_cb(buf, log_change_callback, buf_out1); cb1 = evbuffer_add_cb(buf, log_change_callback, buf_out1);
cb2 = evbuffer_add_cb(buf, log_change_callback, buf_out2); cb2 = evbuffer_add_cb(buf, log_change_callback, buf_out2);

View File

@ -256,6 +256,8 @@ test_bufferevent_watermarks_impl(int use_pair)
bev1 = bufferevent_new(pair[0], NULL, wm_writecb, wm_errorcb, NULL); bev1 = bufferevent_new(pair[0], NULL, wm_writecb, wm_errorcb, NULL);
bev2 = bufferevent_new(pair[1], wm_readcb, NULL, wm_errorcb, NULL); bev2 = bufferevent_new(pair[1], wm_readcb, NULL, wm_errorcb, NULL);
} }
tt_assert(bev1);
tt_assert(bev2);
bufferevent_disable(bev1, EV_READ); bufferevent_disable(bev1, EV_READ);
bufferevent_enable(bev2, EV_READ); bufferevent_enable(bev2, EV_READ);
@ -280,7 +282,9 @@ test_bufferevent_watermarks_impl(int use_pair)
tt_assert(!event_pending(&bev2->ev_write, EV_WRITE, NULL)); tt_assert(!event_pending(&bev2->ev_write, EV_WRITE, NULL));
end: end:
if (bev1)
bufferevent_free(bev1); bufferevent_free(bev1);
if (bev2)
bufferevent_free(bev2); bufferevent_free(bev2);
} }
@ -390,7 +394,9 @@ test_bufferevent_filters_impl(int use_pair)
test_ok = 0; test_ok = 0;
end: end:
if (bev1)
bufferevent_free(bev1); bufferevent_free(bev1);
if (bev2)
bufferevent_free(bev2); bufferevent_free(bev2);
} }

View File

@ -1070,6 +1070,7 @@ test_bufferevent_connect_hostname(void *arg)
&n_accept, &n_accept,
LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC, LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC,
-1, (struct sockaddr *)&sin, sizeof(sin)); -1, (struct sockaddr *)&sin, sizeof(sin));
tt_assert(listener);
listener_port = regress_get_socket_port( listener_port = regress_get_socket_port(
evconnlistener_get_fd(listener)); evconnlistener_get_fd(listener));
@ -1215,6 +1216,7 @@ test_getaddrinfo_async(void *arg)
int n_dns_questions = 0; int n_dns_questions = 0;
struct evdns_base *dns_base = evdns_base_new(data->base, 0); struct evdns_base *dns_base = evdns_base_new(data->base, 0);
tt_assert(dns_base);
/* for localhost */ /* for localhost */
evdns_base_load_hosts(dns_base, NULL); evdns_base_load_hosts(dns_base, NULL);
@ -1712,6 +1714,7 @@ testleak_cleanup(const struct testcase_t *testcase, void *env_)
{ {
int ok = 0; int ok = 0;
struct testleak_env_t *env = env_; struct testleak_env_t *env = env_;
tt_assert(env);
#ifdef EVENT__DISABLE_DEBUG_MODE #ifdef EVENT__DISABLE_DEBUG_MODE
tt_int_op(allocated_chunks, ==, 0); tt_int_op(allocated_chunks, ==, 0);
#else #else
@ -1720,12 +1723,13 @@ testleak_cleanup(const struct testcase_t *testcase, void *env_)
#endif #endif
ok = 1; ok = 1;
end: end:
if (env) {
if (env->dns_base) if (env->dns_base)
evdns_base_free(env->dns_base, 0); evdns_base_free(env->dns_base, 0);
if (env->base) if (env->base)
event_base_free(env->base); event_base_free(env->base);
if (env)
free(env); free(env);
}
return ok; return ok;
} }

View File

@ -173,7 +173,9 @@ test_edgetriggered_mix_error(void *data_)
/* try mixing edge-triggered and level-triggered to make sure it fails*/ /* try mixing edge-triggered and level-triggered to make sure it fails*/
ev_et = event_new(base, data->pair[0], EV_READ|EV_ET, read_cb, ev_et); ev_et = event_new(base, data->pair[0], EV_READ|EV_ET, read_cb, ev_et);
tt_assert(ev_et);
ev_lt = event_new(base, data->pair[0], EV_READ, read_cb, ev_lt); ev_lt = event_new(base, data->pair[0], EV_READ, read_cb, ev_lt);
tt_assert(ev_lt);
/* Add edge-triggered, then level-triggered. Get an error. */ /* Add edge-triggered, then level-triggered. Get an error. */
tt_int_op(0, ==, event_add(ev_et, NULL)); tt_int_op(0, ==, event_add(ev_et, NULL));

View File

@ -2665,9 +2665,11 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
if (header == NULL) if (header == NULL)
goto out; goto out;
/* 13 chars */ /* 13 chars */
if (strcmp(header, "d")) if (strcmp(header, "d")) {
free((void*)header);
goto out; goto out;
free((char*)header); }
free((void*)header);
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 13), if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 13),
"This is funny", 13)) "This is funny", 13))
@ -2693,8 +2695,10 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
if (header == NULL) if (header == NULL)
goto out; goto out;
/* 8 chars */ /* 8 chars */
if (strcmp(header, "8")) if (strcmp(header, "8")) {
free((void*)header);
goto out; goto out;
}
free((char *)header); free((char *)header);
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 8), if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 8),
@ -2707,9 +2711,11 @@ http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
if (header == NULL) if (header == NULL)
goto out; goto out;
/* 0 chars */ /* 0 chars */
if (strcmp(header, "0")) if (strcmp(header, "0")) {
free((void*)header);
goto out; goto out;
free((char *)header); }
free((void *)header);
test_ok = 2; test_ok = 2;
@ -3220,26 +3226,30 @@ static void
http_primitives(void *ptr) http_primitives(void *ptr)
{ {
char *escaped = NULL; char *escaped = NULL;
struct evhttp *http; struct evhttp *http = NULL;
escaped = evhttp_htmlescape("<script>"); escaped = evhttp_htmlescape("<script>");
tt_assert(escaped);
tt_str_op(escaped, ==, "&lt;script&gt;"); tt_str_op(escaped, ==, "&lt;script&gt;");
free(escaped); free(escaped);
escaped = evhttp_htmlescape("\"\'&"); escaped = evhttp_htmlescape("\"\'&");
tt_assert(escaped);
tt_str_op(escaped, ==, "&quot;&#039;&amp;"); tt_str_op(escaped, ==, "&quot;&#039;&amp;");
http = evhttp_new(NULL); http = evhttp_new(NULL);
tt_assert(http);
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, 0); tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, 0);
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, -1); tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, -1);
tt_int_op(evhttp_del_cb(http, "/test"), ==, 0); tt_int_op(evhttp_del_cb(http, "/test"), ==, 0);
tt_int_op(evhttp_del_cb(http, "/test"), ==, -1); tt_int_op(evhttp_del_cb(http, "/test"), ==, -1);
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, 0); tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, NULL), ==, 0);
evhttp_free(http);
end: end:
if (escaped) if (escaped)
free(escaped); free(escaped);
if (http)
evhttp_free(http);
} }
static void static void

View File

@ -59,6 +59,9 @@
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#ifdef EVENT__HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifndef _WIN32 #ifndef _WIN32
#include <sys/socket.h> #include <sys/socket.h>
@ -125,6 +128,9 @@ regress_make_tmpfile(const void *data, size_t datalen, char **filename_out)
int fd; int fd;
*filename_out = NULL; *filename_out = NULL;
strcpy(tmpfilename, "/tmp/eventtmp.XXXXXX"); strcpy(tmpfilename, "/tmp/eventtmp.XXXXXX");
#ifdef EVENT__HAVE_UMASK
umask(0077);
#endif
fd = mkstemp(tmpfilename); fd = mkstemp(tmpfilename);
if (fd == -1) if (fd == -1)
return (-1); return (-1);
@ -305,7 +311,7 @@ static void *
legacy_test_setup(const struct testcase_t *testcase) legacy_test_setup(const struct testcase_t *testcase)
{ {
struct basic_test_data *data = basic_test_setup(testcase); struct basic_test_data *data = basic_test_setup(testcase);
if (data == (void*)TT_SKIP) if (data == (void*)TT_SKIP || data == NULL)
return data; return data;
global_base = data->base; global_base = data->base;
pair[0] = data->pair[0]; pair[0] = data->pair[0];

View File

@ -113,6 +113,7 @@ MessageCb(EVRPC_STRUCT(Message)* rpc, void *arg)
struct evhttp_request* req = EVRPC_REQUEST_HTTP(rpc); struct evhttp_request* req = EVRPC_REQUEST_HTTP(rpc);
const char *header = evhttp_find_header( const char *header = evhttp_find_header(
req->input_headers, "X-Hook"); req->input_headers, "X-Hook");
assert(header);
assert(strcmp(header, "input") == 0); assert(strcmp(header, "input") == 0);
} }
@ -332,6 +333,7 @@ GotKillCb(struct evrpc_status *status,
struct evhttp_request *req = status->http_req; struct evhttp_request *req = status->http_req;
const char *header = evhttp_find_header( const char *header = evhttp_find_header(
req->input_headers, "X-Pool-Hook"); req->input_headers, "X-Pool-Hook");
assert(header);
assert(strcmp(header, "ran") == 0); assert(strcmp(header, "ran") == 0);
} }
@ -734,6 +736,9 @@ rpc_test(void)
int i; int i;
msg = msg_new(); msg = msg_new();
tt_assert(msg);
EVTAG_ASSIGN(msg, from_name, "niels"); EVTAG_ASSIGN(msg, from_name, "niels");
EVTAG_ASSIGN(msg, to_name, "phoenix"); EVTAG_ASSIGN(msg, to_name, "phoenix");

View File

@ -101,7 +101,7 @@ regress_get_dnsserver(struct event_base *base,
struct sockaddr_in my_addr; struct sockaddr_in my_addr;
sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock <= 0) { if (sock < 0) {
tt_abort_perror("socket"); tt_abort_perror("socket");
} }
@ -112,6 +112,7 @@ regress_get_dnsserver(struct event_base *base,
my_addr.sin_port = htons(*portnum); my_addr.sin_port = htons(*portnum);
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) {
evutil_closesocket(sock);
tt_abort_perror("bind"); tt_abort_perror("bind");
} }
port = evdns_add_server_port_with_base(base, sock, 0, cb, arg); port = evdns_add_server_port_with_base(base, sock, 0, cb, arg);