diff options
author | Pekka Paalanen <ppaalanen@gmail.com> | 2012-03-22 15:02:05 +0200 |
---|---|---|
committer | Pekka Paalanen <ppaalanen@gmail.com> | 2012-04-25 09:37:42 +0300 |
commit | b2eaf870cf8e8cb842ba29ea4718b596101252a6 (patch) | |
tree | ce24bd654adfd6ad7f4634f86cc074cef2b1924c /tests | |
parent | 35d5053c622a2b1502b71230c7755a8005b36301 (diff) |
os: wrap epoll_create
Some system C libraries do not have epoll_create1() nor EPOLL_CLOEXEC,
provide a fallback.
Add tests for the wrapper.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/os-wrappers-test.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/os-wrappers-test.c b/tests/os-wrappers-test.c index 657f1fe..967eb83 100644 --- a/tests/os-wrappers-test.c +++ b/tests/os-wrappers-test.c @@ -34,6 +34,7 @@ #include <stdarg.h> #include <fcntl.h> #include <stdio.h> +#include <sys/epoll.h> #include "../src/wayland-private.h" #include "test-runner.h" @@ -50,6 +51,9 @@ static int wrapped_calls_fcntl; static ssize_t (*real_recvmsg)(int, struct msghdr *, int); static int wrapped_calls_recvmsg; +static int (*real_epoll_create1)(int); +static int wrapped_calls_epoll_create1; + static void init_fallbacks(int do_fallbacks) { @@ -57,6 +61,7 @@ init_fallbacks(int do_fallbacks) real_socket = dlsym(RTLD_NEXT, "socket"); real_fcntl = dlsym(RTLD_NEXT, "fcntl"); real_recvmsg = dlsym(RTLD_NEXT, "recvmsg"); + real_epoll_create1 = dlsym(RTLD_NEXT, "epoll_create1"); } __attribute__ ((visibility("default"))) int @@ -105,6 +110,20 @@ recvmsg(int sockfd, struct msghdr *msg, int flags) return real_recvmsg(sockfd, msg, flags); } +__attribute__ ((visibility("default"))) int +epoll_create1(int flags) +{ + wrapped_calls_epoll_create1++; + + if (fall_back) { + wrapped_calls_epoll_create1++; /* epoll_create() not wrapped */ + errno = EINVAL; + return -1; + } + + return real_epoll_create1(flags); +} + static void do_os_wrappers_socket_cloexec(int n) { @@ -331,3 +350,35 @@ TEST(os_wrappers_recvmsg_cloexec_fallback) init_fallbacks(1); do_os_wrappers_recvmsg_cloexec(1); } + +static void +do_os_wrappers_epoll_create_cloexec(int n) +{ + int fd; + int nr_fds; + + nr_fds = count_open_fds(); + + fd = wl_os_epoll_create_cloexec(); + assert(fd >= 0); + +#ifdef EPOLL_CLOEXEC + assert(wrapped_calls_epoll_create1 == n); +#else + printf("No epoll_create1.\n"); +#endif + + exec_fd_leak_check(nr_fds); +} + +TEST(os_wrappers_epoll_create_cloexec) +{ + init_fallbacks(0); + do_os_wrappers_epoll_create_cloexec(1); +} + +TEST(os_wrappers_epoll_create_cloexec_fallback) +{ + init_fallbacks(1); + do_os_wrappers_epoll_create_cloexec(2); +} |