]> granicus.if.org Git - libevent/commitdiff
Unit-test every evbuffer_add_file() implementation.
authorNick Mathewson <nickm@torproject.org>
Fri, 9 Apr 2010 19:28:26 +0000 (15:28 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 9 Apr 2010 19:28:26 +0000 (15:28 -0400)
Previously, we'd only test the default one, even if the others were still
compiled in.

buffer.c
event.c
test/regress_buffer.c

index b566c12303f73081ac09bb0ae81764ecaa120053..5881890df46ac4504b66786ff2904325f7092be9 100644 (file)
--- 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 7538b5e2694e0505a21b8847e16d28f7b816e2e2..4e2f19a78b23d686f9527d84a4c760d88fd30056 100644 (file)
--- 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
 
index 519d295e0bda819d778d7cf642fde8c9a9bbac6f..f3762a381f6866e57b51772c50eb626b4cb69241 100644 (file)
@@ -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