From f13650d83175d59f5c46cd7d32c6a71edd0b745b Mon Sep 17 00:00:00 2001 From: Mark Heily Date: Mon, 20 Jun 2022 21:07:26 -0400 Subject: [PATCH 1/3] Always enable testing --- .github/workflows/ci-linux-coverity.yml | 1 - .github/workflows/ci-linux.yml | 1 - CMakeLists.txt | 12 +++--------- README.md | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci-linux-coverity.yml b/.github/workflows/ci-linux-coverity.yml index 0a1dabe4..0a618786 100644 --- a/.github/workflows/ci-linux-coverity.yml +++ b/.github/workflows/ci-linux-coverity.yml @@ -70,7 +70,6 @@ jobs: -DCMAKE_INSTALL_PREFIX="/usr" \ -DCMAKE_INSTALL_LIBDIR="lib" \ -DCMAKE_VERBOSE_MAKEFILE:BOOL="ON" \ - -DENABLE_TESTING="YES" \ -DCMAKE_BUILD_TYPE="Debug" - name: Build libkqueue diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 45de5855..555d99b1 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -99,7 +99,6 @@ jobs: -DCMAKE_INSTALL_PREFIX="/usr" \ -DCMAKE_INSTALL_LIBDIR="lib" \ -DCMAKE_VERBOSE_MAKEFILE:BOOL="ON" \ - -DENABLE_TESTING="YES" \ -DENABLE_ASAN="${ENABLE_ASAN:-NO}" \ -DENABLE_LSAN="${ENABLE_LSAN:-NO}" \ -DENABLE_UBSAN="${ENABLE_UBSAN:-NO}" \ diff --git a/CMakeLists.txt b/CMakeLists.txt index a49e2e31..d2d84328 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,15 +149,11 @@ check_include_files(sys/queue.h HAVE_SYS_QUEUE_H) check_include_files(sys/signalfd.h HAVE_SYS_SIGNALFD_H) check_include_files(sys/timerfd.h HAVE_SYS_TIMERFD_H) check_include_files(sys/types.h HAVE_SYS_TYPES_H) -if(ENABLE_TESTING) - check_include_files(err.h HAVE_ERR_H) -endif() +check_include_files(err.h HAVE_ERR_H) check_symbol_exists(EPOLLRDHUP sys/epoll.h HAVE_EPOLLRDHUP) check_symbol_exists(NOTE_TRUNCATE sys/event.h HAVE_NOTE_TRUNCATE) -if(ENABLE_TESTING) - check_symbol_exists(NOTE_REVOKE sys/event.h HAVE_NOTE_REVOKE) -endif() +check_symbol_exists(NOTE_REVOKE sys/event.h HAVE_NOTE_REVOKE) set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) check_symbol_exists(ppoll poll.h HAVE_DECL_PPOLL) @@ -301,9 +297,7 @@ if(WIN32) endif() -if(ENABLE_TESTING) - add_subdirectory(test) -endif() +add_subdirectory(test) if(CMAKE_SYSTEM_NAME STREQUAL Emscripten) target_compile_options(kqueue PRIVATE -pthread) diff --git a/README.md b/README.md index 08e00a03..ac385be1 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Source archive Running Unit Tests ------------------ - cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib -DENABLE_TESTING=YES -DCMAKE_BUILD_TYPE=Debug + cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Debug make make test From 323fbc373eb06cbeb4f60cb28f09a1242ad1c060 Mon Sep 17 00:00:00 2001 From: Mark Heily Date: Mon, 20 Jun 2022 22:11:28 -0400 Subject: [PATCH 2/3] Fix multiple test issues on Windows * Disable EVFILT_PROC as this is not supported. * Initialize kevent() timeouts using an older syntax. * Use Sleep() instead of usleep(). * Disable test_transition_from_write_to_read(). * Emulate the POSIX API for shutdown(2) and pipe(2). --- src/windows/platform.h | 7 +++++++ test/CMakeLists.txt | 1 - test/libkqueue.c | 6 ++++-- test/main.c | 2 ++ test/read.c | 6 ++++++ test/timer.c | 12 +++++++++--- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/windows/platform.h b/src/windows/platform.h index a36bf5eb..74456e73 100644 --- a/src/windows/platform.h +++ b/src/windows/platform.h @@ -173,5 +173,12 @@ typedef CRITICAL_SECTION pthread_rwlock_t; #define pthread_rwlock_unlock LeaveCriticalSection #define pthread_rwlock_init(x,y) InitializeCriticalSection((x)) +/* Emulate the POSIX symbolic names for the 'how' argument to shutdown(2) */ +#define SHUT_RD SD_RECEIVE +#define SHUT_WR SD_SEND +#define SHUT_RDWR SD_BOTH + +/* Emulate the POSIX pipe(2) interface */ +#define pipe(x) _pipe(x, 512, 0) #endif /* ! _KQUEUE_WINDOWS_PLATFORM_H */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6d8c11e4..df38712a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,7 +20,6 @@ set(LIBKQUEUE_TEST_SOURCES kqueue.c libkqueue.c main.c - proc.c read.c test.c timer.c diff --git a/test/libkqueue.c b/test/libkqueue.c index a7c86cf4..6aa1db75 100644 --- a/test/libkqueue.c +++ b/test/libkqueue.c @@ -20,9 +20,10 @@ static void test_libkqueue_version(struct test_context *ctx) { struct kevent kev, receipt; + struct timespec ts = {0, 0}; EV_SET(&kev, 0, EVFILT_LIBKQUEUE, EV_ADD, NOTE_VERSION, 0, NULL); - if (kevent(ctx->kqfd, &kev, 1, &receipt, 1, &(struct timespec){}) != 1) { + if (kevent(ctx->kqfd, &kev, 1, &receipt, 1, &ts) != 1) { printf("Unable to add the following kevent:\n%s\n", kevent_to_str(&kev)); die("kevent"); @@ -38,9 +39,10 @@ static void test_libkqueue_version_str(struct test_context *ctx) { struct kevent kev, receipt; + struct timespec ts = { 0, 0 }; EV_SET(&kev, 0, EVFILT_LIBKQUEUE, EV_ADD, NOTE_VERSION_STR, 0, NULL); - if (kevent(ctx->kqfd, &kev, 1, &receipt, 1, &(struct timespec){}) != 1) { + if (kevent(ctx->kqfd, &kev, 1, &receipt, 1, &ts) != 1) { printf("Unable to add the following kevent:\n%s\n", kevent_to_str(&kev)); die("kevent"); diff --git a/test/main.c b/test/main.c index e5c0dece..9ee6892b 100644 --- a/test/main.c +++ b/test/main.c @@ -155,10 +155,12 @@ main(int argc, char **argv) .ut_func = test_evfilt_signal, .ut_end = INT_MAX }, #endif +#if !defined(_WIN32) { .ut_name = "proc", .ut_enabled = 1, .ut_func = test_evfilt_proc, .ut_end = INT_MAX }, +#endif { .ut_name = "timer", .ut_enabled = 1, .ut_func = test_evfilt_timer, diff --git a/test/read.c b/test/read.c index b93b63e5..242269ec 100644 --- a/test/read.c +++ b/test/read.c @@ -593,6 +593,11 @@ test_kevent_regular_file(struct test_context *ctx) void test_transition_from_write_to_read(struct test_context *ctx) { +#if defined(_WIN32) + // socketpair() is not available on Windows. + return; +#else + struct kevent kev, ret[1]; int kqfd; int sd[2]; @@ -613,6 +618,7 @@ test_transition_from_write_to_read(struct test_context *ctx) close(sd[0]); close(sd[1]); close(kqfd); +#endif } void diff --git a/test/timer.c b/test/timer.c index fc4f78ed..502af54d 100644 --- a/test/timer.c +++ b/test/timer.c @@ -16,6 +16,12 @@ #include "common.h" +#if defined(_WIN32) +#define SLEEP_MS(ms) Sleep(ms) +#else +#define SLEEP_MS(microseconds) usleep(microseconds * 1000) +#endif + void test_kevent_timer_add(struct test_context *ctx) { @@ -204,7 +210,7 @@ test_kevent_timer_dispatch(struct test_context *ctx) kevent_cmp(&kev, ret); /* Confirm that the knote is disabled due to EV_DISPATCH */ - usleep(500000); /* 500 ms */ + SLEEP_MS(500); test_no_kevents(ctx->kqfd); #if WITH_NATIVE_KQUEUE_BUGS || !defined(__FreeBSD__) @@ -223,7 +229,7 @@ test_kevent_timer_dispatch(struct test_context *ctx) test_no_kevents(ctx->kqfd); /* Get the next event */ - usleep(1100000); /* 1100 ms */ + SLEEP_MS(1100); kev.flags = EV_ADD | EV_CLEAR | EV_DISPATCH; kev.data = 5; kevent_get(ret, NUM_ELEMENTS(ret), ctx->kqfd, 1); @@ -232,7 +238,7 @@ test_kevent_timer_dispatch(struct test_context *ctx) /* Remove the knote and ensure the event no longer fires */ kevent_add(ctx->kqfd, &kev, 4, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); - usleep(500000); /* 500 ms */ + SLEEP_MS(500); test_no_kevents(ctx->kqfd); } #endif /* EV_DISPATCH */ From 678a0fc69bb68a899ccd9555d4aeec05fe1f727d Mon Sep 17 00:00:00 2001 From: Mark Heily Date: Mon, 20 Jun 2022 22:35:48 -0400 Subject: [PATCH 3/3] Upgrade the Windows CI job to windows-2022 --- .github/workflows/ci-windows.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index a503155a..b2f8c39c 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -27,7 +27,7 @@ env: jobs: windows-build: timeout-minutes: 5 - runs-on: windows-2019 + runs-on: windows-2022 name: CI-windows (build) steps: @@ -36,9 +36,9 @@ jobs: - name: Configure build system run: | cmake --version - cmake -S . -B build_x64 -A x64 -G "Visual Studio 16 2019" -DSTATICLIB=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON + cmake -S . -B build_x64 -DCMAKE_VERBOSE_MAKEFILE=ON - name: Build libkqueue run: | - cmake --build build_x64 --target install --config Release --parallel 1 + cmake --build build_x64 --target install --parallel 1