From 2799b359d3fa0c8d57ec4095e09ee701c5771e05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joakim=20S=C3=B6derberg?= Date: Tue, 17 Dec 2013 14:01:21 +0100 Subject: [PATCH] Added a test for testing if kqueue works with pipes. --- CMakeLists.txt | 11 +++++-- cmake/CheckWorkingKqueue.cmake | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 cmake/CheckWorkingKqueue.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 00cac54e..ea26e833 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ option(EVENT__DISABLE_OPENSSL "Define if libevent should build without support f option(EVENT__DISABLE_BENCHMARK "Defines if libevent should build without the benchmark exectuables" OFF) option(EVENT__DISABLE_TESTS "If tests should be compiled or not" OFF) option(EVENT__DISABLE_REGRESS "Disable the regress tests" OFF) +option(EVENT__FORCE_KQUEUE_CHECK "When crosscompiling forces running a test program that verifies that Kqueue works with pipes. Note that this requires you to manually run the test program on the the cross compilation target to verify that it works. See cmake documentation for try_run for more details" OFF) # TODO: Add --enable-verbose-debug, verbose debug logging # TODO: Add --disable-largefile omit support for large files @@ -370,9 +371,15 @@ CHECK_TYPE_SIZE("void *" EVENT__SIZEOF_VOID_P) CHECK_FILE_OFFSET_BITS() set(EVENT___FILE_OFFSET_BITS _FILE_OFFSET_BITS) -# TODO: Check EVENT__HAVE_WORKING_KQUEUE (Define if kqueue works correctly with pipes) +# Verify kqueue works with pipes. if (EVENT__HAVE_KQUEUE) - set(EVENT__HAVE_WORKING_KQUEUE 1) + if (CMAKE_CROSSCOMPILING AND NOT EVENT__FORCE_KQUEUE_CHECK) + message(WARNING "Cannot check if kqueue works with pipes when crosscompiling, use EVENT__FORCE_KQUEUE_CHECK to be sure (this requires manually running a test program on the cross compilation target)") + set(EVENT__HAVE_WORKING_KQUEUE 1) + else() + message("Checking if kqueue works with pipes...") + include(CheckWorkingKqueue) + endif() endif() CHECK_SYMBOL_EXISTS(_MINIX "stdio.h" EVENT___MINIX) diff --git a/cmake/CheckWorkingKqueue.cmake b/cmake/CheckWorkingKqueue.cmake new file mode 100644 index 00000000..47bf4e83 --- /dev/null +++ b/cmake/CheckWorkingKqueue.cmake @@ -0,0 +1,52 @@ +include(CheckCSourceRuns) + +check_c_source_runs( +" +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + int kq; + int n; + int fd[2]; + struct kevent ev; + struct timespec ts; + char buf[8000]; + + if (pipe(fd) == -1) + exit(1); + if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1) + exit(1); + + while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf)) + ; + + if ((kq = kqueue()) == -1) + exit(1); + + memset(&ev, 0, sizeof(ev)); + ev.ident = fd[1]; + ev.filter = EVFILT_WRITE; + ev.flags = EV_ADD | EV_ENABLE; + n = kevent(kq, &ev, 1, NULL, 0, NULL); + if (n == -1) + exit(1); + + read(fd[0], buf, sizeof(buf)); + + ts.tv_sec = 0; + ts.tv_nsec = 0; + n = kevent(kq, NULL, 0, &ev, 1, &ts); + if (n == -1 || n == 0) + exit(1); + + exit(0); +} + +" EVENT__HAVE_WORKING_KQUEUE) \ No newline at end of file -- 2.40.0