Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test compilation errors on Windows #144

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci-linux-coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
12 changes: 3 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path to source>
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Debug <path to source>
make
make test

Expand Down
7 changes: 7 additions & 0 deletions src/windows/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd wrap a lot of these in ifdef _MSC_VER

MinGW supports a lot of this, including pthread.


#endif /* ! _KQUEUE_WINDOWS_PLATFORM_H */
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ set(LIBKQUEUE_TEST_SOURCES
kqueue.c
libkqueue.c
main.c
proc.c
read.c
test.c
timer.c
Expand Down
6 changes: 4 additions & 2 deletions test/libkqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows still doesn't support C11?!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it still doesn't support compound literals. I even tried enabling the latest conforming preprocessor:

https://devblogs.microsoft.com/cppblog/announcing-full-support-for-a-c-c-conformant-preprocessor-in-msvc/

printf("Unable to add the following kevent:\n%s\n",
kevent_to_str(&kev));
die("kevent");
Expand All @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions test/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -613,6 +618,7 @@ test_transition_from_write_to_read(struct test_context *ctx)
close(sd[0]);
close(sd[1]);
close(kqfd);
#endif
}

void
Expand Down
12 changes: 9 additions & 3 deletions test/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

#include "common.h"

#if defined(_WIN32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MinGW supports usleep.

#define SLEEP_MS(ms) Sleep(ms)
#else
#define SLEEP_MS(microseconds) usleep(microseconds * 1000)
#endif

void
test_kevent_timer_add(struct test_context *ctx)
{
Expand Down Expand Up @@ -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__)
Expand All @@ -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);
Expand All @@ -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 */
Expand Down