From 5bf3908ee632a18c59d3ed9946cf53facdcfaef1 Mon Sep 17 00:00:00 2001 From: filimonov <1549571+filimonov@users.noreply.github.com> Date: Thu, 6 Jan 2022 12:23:11 +0100 Subject: [PATCH] Create windows_msvc.yml #130 --- .github/workflows/windows_msvc.yml | 31 +++++++++++++++++++++++++++++ tests/simple/CMakeLists.txt | 2 +- ut/CMakeLists.txt | 2 +- ut/tcp_server.cpp | 32 +++++++++++++++++++++++++----- ut/tcp_server.h | 4 +++- ut/utils.h | 5 ++--- 6 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/windows_msvc.yml diff --git a/.github/workflows/windows_msvc.yml b/.github/workflows/windows_msvc.yml new file mode 100644 index 00000000..119b0fc3 --- /dev/null +++ b/.github/workflows/windows_msvc.yml @@ -0,0 +1,31 @@ +name: Windows + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + BUILD_TYPE: Release + # It is impossible to start CH server in docker on Windows due to github actions limitations, + # so limit tests to ones that do no require server interaction. + GTEST_FILTER: --gtest_filter=-"Client/*:*Performance*" + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + - uses: ilammy/msvc-dev-cmd@v1 + + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON + + - name: Build + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Test + working-directory: ${{github.workspace}}/build/ut + run: Release\clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}" diff --git a/tests/simple/CMakeLists.txt b/tests/simple/CMakeLists.txt index 116116a4..34b6dc2a 100644 --- a/tests/simple/CMakeLists.txt +++ b/tests/simple/CMakeLists.txt @@ -3,7 +3,7 @@ ADD_EXECUTABLE (simple-test ) TARGET_LINK_LIBRARIES (simple-test - clickhouse-cpp-lib + clickhouse-cpp-lib-static ) IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") diff --git a/ut/CMakeLists.txt b/ut/CMakeLists.txt index 5cc125b1..bdb9bc98 100644 --- a/ut/CMakeLists.txt +++ b/ut/CMakeLists.txt @@ -25,7 +25,7 @@ ADD_EXECUTABLE (clickhouse-cpp-ut ) TARGET_LINK_LIBRARIES (clickhouse-cpp-ut - clickhouse-cpp-lib + clickhouse-cpp-lib-static gtest-lib ) IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") diff --git a/ut/tcp_server.cpp b/ut/tcp_server.cpp index cd479446..15ec1864 100644 --- a/ut/tcp_server.cpp +++ b/ut/tcp_server.cpp @@ -1,13 +1,22 @@ #include "tcp_server.h" #include -#include #include #include #include -#include + +#include +/* +#if defined(_win_) +# include +#else +# include +# include +# include +#endif +*/ + #include -#include namespace clickhouse { @@ -23,7 +32,7 @@ LocalTcpServer::~LocalTcpServer() { void LocalTcpServer::start() { //setup a socket sockaddr_in servAddr; - bzero((char*)&servAddr, sizeof(servAddr)); + memset((char*)&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = AF_INET; servAddr.sin_addr.s_addr = htonl(INADDR_ANY); servAddr.sin_port = htons(port_); @@ -33,7 +42,14 @@ void LocalTcpServer::start() { throw std::runtime_error("Error establishing server socket"); } int enable = 1; - if (setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) { + +#if defined(_unix_) + auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); +#else + auto res = setsockopt(serverSd_, SOL_SOCKET, SO_REUSEADDR, (const char*)&enable, sizeof(enable)); +#endif + + if (res < 0) { std::cerr << "setsockopt(SO_REUSEADDR) failed" << std::endl; } //bind the socket to its local address @@ -47,8 +63,14 @@ void LocalTcpServer::start() { void LocalTcpServer::stop() { if(serverSd_ > 0) { + +#if defined(_unix_) shutdown(serverSd_, SHUT_RDWR); close(serverSd_); +#else + shutdown(serverSd_, SD_BOTH); + closesocket(serverSd_); +#endif serverSd_ = -1; } } diff --git a/ut/tcp_server.h b/ut/tcp_server.h index d8f3cd57..00d61e44 100644 --- a/ut/tcp_server.h +++ b/ut/tcp_server.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace clickhouse { class LocalTcpServer { @@ -15,7 +17,7 @@ class LocalTcpServer { private: int port_; - int serverSd_; + SOCKET serverSd_; }; } diff --git a/ut/utils.h b/ut/utils.h index 0bde2c73..430dcec2 100644 --- a/ut/utils.h +++ b/ut/utils.h @@ -39,9 +39,8 @@ struct Timer private: static auto Now() { - struct timespec ts; - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); - return std::chrono::nanoseconds(ts.tv_sec * 1000000000LL + ts.tv_nsec); + std::chrono::nanoseconds ns = std::chrono::high_resolution_clock::now().time_since_epoch(); + return ns; } private: