From 1a794772b29adc3163e3c63bd9e7a09ff6f4620d Mon Sep 17 00:00:00 2001 From: Eli Lindsey Date: Mon, 29 Jun 2020 10:37:31 -0400 Subject: [PATCH] add openbsd support (#204) * add openbsd support Renames fileno() so it doesn't clash with OpenBSD's macro expansion. Makes minor changes to build steps so the test suite compiles and runs on OpenBSD. See https://github.com/skypjack/uvw/issues/201 for full context * drop no-error override * disable sendfile tests on openbsd * forgot to commit the new file --- src/uvw/handle.hpp | 2 +- test/CMakeLists.txt | 10 ++++- test/uvw/file_req.cpp | 59 ------------------------------ test/uvw/file_req_sendfile.cpp | 67 ++++++++++++++++++++++++++++++++++ test/uvw/handle.cpp | 2 +- 5 files changed, 77 insertions(+), 63 deletions(-) create mode 100644 test/uvw/file_req_sendfile.cpp diff --git a/src/uvw/handle.hpp b/src/uvw/handle.hpp index 274f4fc5..a6625f01 100644 --- a/src/uvw/handle.hpp +++ b/src/uvw/handle.hpp @@ -264,7 +264,7 @@ public: * @return The file descriptor attached to the hande or a negative value in * case of errors. */ - OSFileDescriptor fileno() const { + OSFileDescriptor fd() const { uv_os_fd_t fd; uv_fileno(this->template get(), &fd); return fd; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8d0b3e70..4c9846eb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,12 +31,14 @@ else() target_compile_features(gtest_main PUBLIC cxx_std_17) target_compile_features(gmock PUBLIC cxx_std_17) target_compile_features(gmock_main PUBLIC cxx_std_17) + + if(CMAKE_SYSTEM_NAME MATCHES OpenBSD) + target_compile_options(gtest PRIVATE -Wno-error) + endif() endif() if(WIN32) set(WINSOCK2 ws2_32) -elseif(NOT APPLE) - find_library(LIBRT rt) endif() function(ADD_UVW_TEST TEST_NAME TEST_SOURCE) @@ -104,6 +106,10 @@ ADD_UVW_TEST(underlying_type uvw/underlying_type.cpp) ADD_UVW_TEST(util uvw/util.cpp) ADD_UVW_TEST(work uvw/work.cpp) +if(NOT CMAKE_SYSTEM_NAME MATCHES OpenBSD) + ADD_UVW_DIR_TEST(file_req_sendfile uvw/file_req_sendfile.cpp) +endif() + if(BUILD_DNS_TEST) ADD_UVW_TEST(dns uvw/dns.cpp) endif() diff --git a/test/uvw/file_req.cpp b/test/uvw/file_req.cpp index 4921181c..aaa6e9e3 100644 --- a/test/uvw/file_req.cpp +++ b/test/uvw/file_req.cpp @@ -373,65 +373,6 @@ TEST(FileReq, TruncateSync) { } -TEST(FileReq, SendFile) { - const std::string srcFilename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/src.file"}; - const std::string dstFilename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/dst.file"}; - - auto loop = uvw::Loop::getDefault(); - auto srcReq = loop->resource(); - auto dstReq = loop->resource(); - - bool checkFileSendFileEvent = false; - - dstReq->on([](const auto &, auto &) { FAIL(); }); - srcReq->on([](const auto &, auto &) { FAIL(); }); - - dstReq->on>([&srcReq](const auto &, auto &req) { - srcReq->sendfile(static_cast(req), 0, 0); - }); - - srcReq->on>([&checkFileSendFileEvent, &dstReq](const auto &, auto &req) { - ASSERT_FALSE(checkFileSendFileEvent); - checkFileSendFileEvent = true; - dstReq->close(); - req.close(); - }); - - srcReq->on>([&dstFilename, &dstReq](const auto &, auto &) { - auto flags = uvw::Flags::from(); - dstReq->open(dstFilename, flags, 0644); - }); - - auto flags = uvw::Flags::from(); - srcReq->open(srcFilename, flags, 0644); - - loop->run(); - - ASSERT_TRUE(checkFileSendFileEvent); -} - - -TEST(FileReq, SendFileSync) { - const std::string srcFilename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/src.file"}; - const std::string dstFilename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/dst.file"}; - - auto loop = uvw::Loop::getDefault(); - auto srcReq = loop->resource(); - auto dstReq = loop->resource(); - - ASSERT_TRUE(srcReq->openSync(srcFilename, O_CREAT | O_RDONLY | O_TRUNC, 0644)); - ASSERT_TRUE(dstReq->openSync(dstFilename, O_CREAT | O_WRONLY | O_TRUNC, 0644)); - - auto sendfileR = srcReq->sendfileSync(static_cast(*dstReq), 0, 0); - - ASSERT_TRUE(sendfileR.first); - ASSERT_TRUE(srcReq->closeSync()); - ASSERT_TRUE(dstReq->closeSync()); - - loop->run(); -} - - TEST(FileReq, Chmod) { const std::string filename = std::string{TARGET_FILE_REQ_DIR} + std::string{"/test.file"}; diff --git a/test/uvw/file_req_sendfile.cpp b/test/uvw/file_req_sendfile.cpp new file mode 100644 index 00000000..714a71bc --- /dev/null +++ b/test/uvw/file_req_sendfile.cpp @@ -0,0 +1,67 @@ +#include +#include +#include + +#ifdef _WIN32 +#define _CRT_DECLARE_NONSTDC_NAMES 1 +#include +#endif + +TEST(FileReq, SendFile) { + const std::string srcFilename = std::string{TARGET_FILE_REQ_SENDFILE_DIR} + std::string{"/src.file"}; + const std::string dstFilename = std::string{TARGET_FILE_REQ_SENDFILE_DIR} + std::string{"/dst.file"}; + + auto loop = uvw::Loop::getDefault(); + auto srcReq = loop->resource(); + auto dstReq = loop->resource(); + + bool checkFileSendFileEvent = false; + + dstReq->on([](const auto &, auto &) { FAIL(); }); + srcReq->on([](const auto &, auto &) { FAIL(); }); + + dstReq->on>([&srcReq](const auto &, auto &req) { + srcReq->sendfile(static_cast(req), 0, 0); + }); + + srcReq->on>([&checkFileSendFileEvent, &dstReq](const auto &, auto &req) { + ASSERT_FALSE(checkFileSendFileEvent); + checkFileSendFileEvent = true; + dstReq->close(); + req.close(); + }); + + srcReq->on>([&dstFilename, &dstReq](const auto &, auto &) { + auto flags = uvw::Flags::from(); + dstReq->open(dstFilename, flags, 0644); + }); + + auto flags = uvw::Flags::from(); + srcReq->open(srcFilename, flags, 0644); + + loop->run(); + + ASSERT_TRUE(checkFileSendFileEvent); +} + + +TEST(FileReq, SendFileSync) { + const std::string srcFilename = std::string{TARGET_FILE_REQ_SENDFILE_DIR} + std::string{"/src.file"}; + const std::string dstFilename = std::string{TARGET_FILE_REQ_SENDFILE_DIR} + std::string{"/dst.file"}; + + auto loop = uvw::Loop::getDefault(); + auto srcReq = loop->resource(); + auto dstReq = loop->resource(); + + ASSERT_TRUE(srcReq->openSync(srcFilename, O_CREAT | O_RDONLY | O_TRUNC, 0644)); + ASSERT_TRUE(dstReq->openSync(dstFilename, O_CREAT | O_WRONLY | O_TRUNC, 0644)); + + auto sendfileR = srcReq->sendfileSync(static_cast(*dstReq), 0, 0); + + ASSERT_TRUE(sendfileR.first); + ASSERT_TRUE(srcReq->closeSync()); + ASSERT_TRUE(dstReq->closeSync()); + + loop->run(); +} + diff --git a/test/uvw/handle.cpp b/test/uvw/handle.cpp index 8cea4c02..55aa5735 100644 --- a/test/uvw/handle.cpp +++ b/test/uvw/handle.cpp @@ -42,7 +42,7 @@ TEST(Handle, Functionalities) { ASSERT_EQ(handle->recvBufferSize(), static_castrecvBufferSize())>(0)); ASSERT_FALSE(handle->recvBufferSize(0)); - ASSERT_NO_THROW(handle->fileno()); + ASSERT_NO_THROW(handle->fd()); }