From: Nick Mathewson Date: Fri, 9 Apr 2010 19:28:26 +0000 (-0400) Subject: Unit-test every evbuffer_add_file() implementation. X-Git-Tag: release-2.0.5-beta~62 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06a4443abed28d3e0e9e27bcb99cf3191c0d3674;p=libevent Unit-test every evbuffer_add_file() implementation. Previously, we'd only test the default one, even if the others were still compiled in. --- diff --git a/buffer.c b/buffer.c index b566c123..5881890d 100644 --- a/buffer.c +++ b/buffer.c @@ -2755,3 +2755,51 @@ evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb) } } #endif + +/* These hooks are exposed so that the unit tests can temporarily disable + * sendfile support in order to test mmap, or both to test linear + * access. Don't use it; if we need to add a way to disable sendfile support + * in the future, it will probably be via an alternate version of + * evbuffer_add_file() with a 'flags' argument. + */ +int _evbuffer_testing_use_sendfile(void); +int _evbuffer_testing_use_mmap(void); +int _evbuffer_testing_use_linear_file_access(void); + +int +_evbuffer_testing_use_sendfile(void) +{ + int ok = 0; +#ifdef USE_SENDFILE + use_sendfile = 1; + ok = 1; +#endif +#ifdef _EVENT_HAVE_MMAP + use_mmap = 0; +#endif + return ok; +} +int +_evbuffer_testing_use_mmap(void) +{ + int ok = 0; +#ifdef USE_SENDFILE + use_sendfile = 0; +#endif +#ifdef _EVENT_HAVE_MMAP + use_mmap = 1; + ok = 1; +#endif + return ok; +} +int +_evbuffer_testing_use_linear_file_access(void) +{ +#ifdef USE_SENDFILE + use_sendfile = 0; +#endif +#ifdef _EVENT_HAVE_MMAP + use_mmap = 0; +#endif + return 1; +} diff --git a/event.c b/event.c index 7538b5e2..4e2f19a7 100644 --- a/event.c +++ b/event.c @@ -2514,8 +2514,12 @@ static void evthread_notify_drain_eventfd(evutil_socket_t fd, short what, void *arg) { ev_uint64_t msg; + ev_ssize_t r; - read(fd, (void*) &msg, sizeof(msg)); + r = read(fd, (void*) &msg, sizeof(msg)); + if (r<0 && errno != EAGAIN) { + event_sock_warn(fd, "Error reading from eventfd"); + } } #endif diff --git a/test/regress_buffer.c b/test/regress_buffer.c index 519d295e..f3762a38 100644 --- a/test/regress_buffer.c +++ b/test/regress_buffer.c @@ -510,14 +510,36 @@ test_evbuffer_reference(void *ptr) } #ifndef WIN32 +int _evbuffer_testing_use_sendfile(void); +int _evbuffer_testing_use_mmap(void); +int _evbuffer_testing_use_linear_file_access(void); + static void test_evbuffer_add_file(void *ptr) { + const char *impl = ptr; struct evbuffer *src = evbuffer_new(); const char *data = "this is what we add as file system data."; const char *compare; evutil_socket_t fd, pair[2]; + tt_assert(impl); + if (!strcmp(impl, "sendfile")) { + if (!_evbuffer_testing_use_sendfile()) + tt_skip(); + TT_BLATHER(("Using sendfile-based implementaion")); + } else if (!strcmp(impl, "mmap")) { + if (!_evbuffer_testing_use_mmap()) + tt_skip(); + TT_BLATHER(("Using mmap-based implementaion")); + } else if (!strcmp(impl, "linear")) { + if (!_evbuffer_testing_use_linear_file_access()) + tt_skip(); + TT_BLATHER(("Using read-based implementaion")); + } else { + TT_DIE(("Didn't recognize the implementation")); + } + if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) tt_abort_msg("socketpair failed"); @@ -1441,7 +1463,12 @@ struct testcase_t evbuffer_testcases[] = { { "freeze_end", test_evbuffer_freeze, 0, &nil_setup, (void*)"end" }, #ifndef WIN32 /* TODO: need a temp file implementation for Windows */ - { "add_file", test_evbuffer_add_file, TT_FORK, NULL, NULL }, + { "add_file_sendfile", test_evbuffer_add_file, TT_FORK, &nil_setup, + (void*)"sendfile" }, + { "add_file_mmap", test_evbuffer_add_file, TT_FORK, &nil_setup, + (void*)"mmap" }, + { "add_file_linear", test_evbuffer_add_file, TT_FORK, &nil_setup, + (void*)"linear" }, #endif END_OF_TESTCASES