Skip to content

Commit

Permalink
SerialIOTests: Windows compatibility
Browse files Browse the repository at this point in the history
Initialize Winsock API
  • Loading branch information
franzpoeschel committed Aug 18, 2023
1 parent 1d887a4 commit 1c937b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,11 @@ target_include_directories(openPMD PUBLIC

# Winsock library for gethostname() function on Windows
if(WIN32)
target_link_libraries(openPMD PRIVATE ws2_32)
# need to link this publically as WSAStartup() and WSACleanup() need to be
# called surrounding the gethostname() function on Windows
# and it needs to be done at client site since the winsocks API is
# initialized statically per process....
target_link_libraries(openPMD PUBLIC ws2_32)
endif()

# Catch2 for unit tests
Expand Down
20 changes: 20 additions & 0 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
#include <unistd.h>
#endif

#ifdef _WIN32
#include <windows.h>
// windows.h defines this macro and it breaks any function with the same name
#undef max
#endif

using namespace openPMD;

struct BackendSelection
Expand Down Expand Up @@ -1512,6 +1518,10 @@ TEST_CASE("dtype_test", "[serial]")

inline void write_test(const std::string &backend)
{
#ifdef _WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 0), &wsaData);
#endif
Series o = Series(
"../samples/serial_write." + backend,
Access::CREATE,
Expand Down Expand Up @@ -1620,6 +1630,9 @@ inline void write_test(const std::string &backend)
REQUIRE(
(read.mpiRanksMetaInfo(/* collective = */ false) ==
chunk_assignment::RankMeta{{0, host_info::hostname()}}));
#ifdef _WIN32
WSACleanup();
#endif
}

TEST_CASE("write_test", "[serial]")
Expand Down Expand Up @@ -1774,6 +1787,10 @@ fileBased_add_EDpic(ParticleSpecies &e, uint64_t const num_particles)

inline void fileBased_write_test(const std::string &backend)
{
#ifdef _WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 0), &wsaData);
#endif
if (auxiliary::directory_exists("../samples/subdir"))
auxiliary::remove_directory("../samples/subdir");

Expand Down Expand Up @@ -2154,6 +2171,9 @@ inline void fileBased_write_test(const std::string &backend)
close(dirfd);
}
#endif // defined(__unix__)
#ifdef _WIN32
WSACleanup();
#endif
}

TEST_CASE("fileBased_write_test", "[serial]")
Expand Down

0 comments on commit 1c937b8

Please sign in to comment.