From 2638237e1fd6643ae8e7e4e2faa75b647e6f7248 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 21 Jan 2023 07:52:36 -0500 Subject: [PATCH] build: add CI for OpenBSD and FreeBSD (#3548) Fixes: https://github.com/libuv/libuv/issues/3510 --- .github/workflows/CI-unix.yml | 33 +++++++++++++++++++++++++++++++++ src/unix/core.c | 4 ++-- src/unix/internal.h | 5 +++++ src/unix/thread.c | 4 ++-- test/task.h | 2 +- test/test-fs.c | 18 +++++++++--------- test/test-get-currentexe.c | 3 +++ test/test-gethostname.c | 2 +- test/test-metrics.c | 7 +++++-- test/test-tcp-rst.c | 3 +++ test/test-udp-connect.c | 3 +++ test/test-udp-connect6.c | 3 +++ test/test-udp-multicast-join.c | 3 +++ 13 files changed, 73 insertions(+), 17 deletions(-) diff --git a/.github/workflows/CI-unix.yml b/.github/workflows/CI-unix.yml index e2859e4e..52a8bf59 100644 --- a/.github/workflows/CI-unix.yml +++ b/.github/workflows/CI-unix.yml @@ -150,3 +150,36 @@ jobs: - name: Test run: | ${{ matrix.config.qemu }} build/uv_run_tests_a + + build-bsd: + timeout-minutes: 30 + runs-on: ${{ matrix.config.runner }} + name: build-${{ matrix.config.os }}-${{ matrix.config.version }} + + strategy: + fail-fast: false + matrix: + config: + # The OS versions supported are specific to the version of the action + # https://github.com/cross-platform-actions/action/blob/master/changelog.md + - { os: freebsd, version: '13.1', runner: 'ubuntu-latest', install: 'pkg install -y' } + - { os: openbsd, version: '7.2', runner: 'macos-11', install: 'pkg_add -I' } + + steps: + - uses: actions/checkout@v2 + + - uses: cross-platform-actions/action@v0.9.0 + with: + operating_system: ${{ matrix.config.os }} + version: ${{ matrix.config.version }} + run: | + sudo ${{ matrix.config.install }} cmake ninja + sudo hostname -s ci-host + mkdir build + cd build + cmake .. -DBUILD_TESTING=ON -G Ninja + cmake --build . + ls -lh + ./uv_run_tests platform_output + ./uv_run_tests_a platform_output + ctest -V diff --git a/src/unix/core.c b/src/unix/core.c index 706dcccb..0ef6ae8a 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -72,8 +72,8 @@ extern char** environ; # include # include # include -# include # if defined(__FreeBSD__) +# include # define uv__accept4 accept4 # endif # if defined(__NetBSD__) @@ -1490,7 +1490,7 @@ uv_pid_t uv_os_getppid(void) { } int uv_cpumask_size(void) { -#if defined(__linux__) || defined(__FreeBSD__) +#if UV__CPU_AFFINITY_SUPPORTED return CPU_SETSIZE; #else return UV_ENOTSUP; diff --git a/src/unix/internal.h b/src/unix/internal.h index 5497ee36..97823a91 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -425,5 +425,10 @@ uv__fs_copy_file_range(int fd_in, unsigned int flags); #endif +#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 1301000) +#define UV__CPU_AFFINITY_SUPPORTED 1 +#else +#define UV__CPU_AFFINITY_SUPPORTED 0 +#endif #endif /* UV_UNIX_INTERNAL_H_ */ diff --git a/src/unix/thread.c b/src/unix/thread.c index f75fe82a..8e3652f1 100644 --- a/src/unix/thread.c +++ b/src/unix/thread.c @@ -295,7 +295,7 @@ int uv_thread_create_ex(uv_thread_t* tid, return UV__ERR(err); } -#if defined(__linux__) || defined(__FreeBSD__) +#if UV__CPU_AFFINITY_SUPPORTED int uv_thread_setaffinity(uv_thread_t* tid, char* cpumask, @@ -383,7 +383,7 @@ int uv_thread_getaffinity(uv_thread_t* tid, #endif /* defined(__linux__) || defined(UV_BSD_H) */ int uv_thread_getcpu(void) { -#if defined(__linux__) || defined(__FreeBSD__) +#if UV__CPU_AFFINITY_SUPPORTED int cpu; cpu = sched_getcpu(); diff --git a/test/task.h b/test/task.h index 4ee81662..7f7ed015 100644 --- a/test/task.h +++ b/test/task.h @@ -371,7 +371,7 @@ UNUSED static int can_ipv6(void) { #endif #if !defined(__linux__) && \ - !defined(__FreeBSD__) && \ + !(defined(__FreeBSD__) && __FreeBSD_version >= 1301000) && \ !defined(_WIN32) # define NO_CPU_AFFINITY \ "affinity not supported on this platform." diff --git a/test/test-fs.c b/test/test-fs.c index f4fdd868..fd2b651c 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -2788,8 +2788,8 @@ TEST_IMPL(fs_lutime) { loop = uv_default_loop(); unlink(path); r = uv_fs_open(NULL, &req, path, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR, NULL); - ASSERT(r >= 0); - ASSERT(req.result >= 0); + ASSERT_GE(r, 0); + ASSERT_GE(req.result, 0); uv_fs_req_cleanup(&req); uv_fs_close(loop, &req, r, NULL); @@ -2805,8 +2805,8 @@ TEST_IMPL(fs_lutime) { "Symlink creation requires elevated console (with admin rights)"); } #endif - ASSERT(s == 0); - ASSERT(req.result == 0); + ASSERT_EQ(s, 0); + ASSERT_EQ(req.result, 0); uv_fs_req_cleanup(&req); /* Test the synchronous version. */ @@ -2820,12 +2820,12 @@ TEST_IMPL(fs_lutime) { r = uv_fs_lutime(NULL, &req, symlink_path, atime, mtime, NULL); #if (defined(_AIX) && !defined(_AIX71)) || \ defined(__MVS__) - ASSERT(r == UV_ENOSYS); + ASSERT_EQ(r, UV_ENOSYS); RETURN_SKIP("lutime is not implemented for z/OS and AIX versions below 7.1"); #endif - ASSERT(r == 0); + ASSERT_EQ(r, 0); lutime_cb(&req); - ASSERT(lutime_cb_count == 1); + ASSERT_EQ(lutime_cb_count, 1); /* Test the asynchronous version. */ atime = mtime = 1291404900; /* 2010-12-03 20:35:00 */ @@ -2835,9 +2835,9 @@ TEST_IMPL(fs_lutime) { checkme.path = symlink_path; r = uv_fs_lutime(loop, &req, symlink_path, atime, mtime, lutime_cb); - ASSERT(r == 0); + ASSERT_EQ(r, 0); uv_run(loop, UV_RUN_DEFAULT); - ASSERT(lutime_cb_count == 2); + ASSERT_EQ(lutime_cb_count, 2); /* Cleanup. */ unlink(path); diff --git a/test/test-get-currentexe.c b/test/test-get-currentexe.c index dc239cc8..becaf5c1 100644 --- a/test/test-get-currentexe.c +++ b/test/test-get-currentexe.c @@ -35,6 +35,9 @@ TEST_IMPL(get_currentexe) { #if defined(__QEMU__) RETURN_SKIP("Test does not currently work in QEMU"); #endif +#if defined(__OpenBSD__) + RETURN_SKIP("Test does not currently work in OpenBSD"); +#endif char buffer[PATHMAX]; char path[PATHMAX]; diff --git a/test/test-gethostname.c b/test/test-gethostname.c index 1a9816d4..dc29cd69 100644 --- a/test/test-gethostname.c +++ b/test/test-gethostname.c @@ -43,7 +43,7 @@ TEST_IMPL(gethostname) { enobufs_size = 1; buf[0] = '\0'; r = uv_os_gethostname(buf, &enobufs_size); - ASSERT(r == UV_ENOBUFS); + ASSERT_EQ(r, UV_ENOBUFS); ASSERT(buf[0] == '\0'); ASSERT(enobufs_size > 1); diff --git a/test/test-metrics.c b/test/test-metrics.c index bfc09251..1f887857 100644 --- a/test/test-metrics.c +++ b/test/test-metrics.c @@ -47,6 +47,9 @@ static void timer_spin_cb(uv_timer_t* handle) { TEST_IMPL(metrics_idle_time) { +#if defined(__OpenBSD__) + RETURN_SKIP("Test does not currently work in OpenBSD"); +#endif const uint64_t timeout = 1000; uv_timer_t timer; uint64_t idle_time; @@ -65,8 +68,8 @@ TEST_IMPL(metrics_idle_time) { idle_time = uv_metrics_idle_time(uv_default_loop()); /* Permissive check that the idle time matches within the timeout ±500 ms. */ - ASSERT((idle_time <= (timeout + 500) * UV_NS_TO_MS) && - (idle_time >= (timeout - 500) * UV_NS_TO_MS)); + ASSERT_LE(idle_time, (timeout + 500) * UV_NS_TO_MS); + ASSERT_GE(idle_time, (timeout - 500) * UV_NS_TO_MS); MAKE_VALGRIND_HAPPY(); return 0; diff --git a/test/test-tcp-rst.c b/test/test-tcp-rst.c index ed48e741..16bc9ce4 100644 --- a/test/test-tcp-rst.c +++ b/test/test-tcp-rst.c @@ -76,6 +76,9 @@ static void connect_cb(uv_connect_t *req, int status) { * RST. Test checks that uv_guess_handle still works on a reset TCP handle. */ TEST_IMPL(tcp_rst) { +#if defined(__OpenBSD__) + RETURN_SKIP("Test does not currently work in OpenBSD"); +#endif #ifndef _WIN32 struct sockaddr_in server_addr; int r; diff --git a/test/test-udp-connect.c b/test/test-udp-connect.c index 0be702ef..d78e62e3 100644 --- a/test/test-udp-connect.c +++ b/test/test-udp-connect.c @@ -98,6 +98,9 @@ static void sv_recv_cb(uv_udp_t* handle, TEST_IMPL(udp_connect) { +#if defined(__OpenBSD__) + RETURN_SKIP("Test does not currently work in OpenBSD"); +#endif uv_udp_send_t req; struct sockaddr_in ext_addr; struct sockaddr_in tmp_addr; diff --git a/test/test-udp-connect6.c b/test/test-udp-connect6.c index d000daf1..9195ef90 100644 --- a/test/test-udp-connect6.c +++ b/test/test-udp-connect6.c @@ -98,6 +98,9 @@ static void sv_recv_cb(uv_udp_t* handle, TEST_IMPL(udp_connect6) { +#if defined(__OpenBSD__) + RETURN_SKIP("Test does not currently work in OpenBSD"); +#endif uv_udp_send_t req; struct sockaddr_in6 ext_addr; struct sockaddr_in6 tmp_addr; diff --git a/test/test-udp-multicast-join.c b/test/test-udp-multicast-join.c index 9e603a84..2c375cc0 100644 --- a/test/test-udp-multicast-join.c +++ b/test/test-udp-multicast-join.c @@ -138,6 +138,9 @@ static void cl_recv_cb(uv_udp_t* handle, TEST_IMPL(udp_multicast_join) { +#if defined(__OpenBSD__) + RETURN_SKIP("Test does not currently work in OpenBSD"); +#endif int r; struct sockaddr_in addr;