From aec09a08fa32ec2fe8cdf591b125483586d7ea7f Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sun, 6 Dec 2026 03:03:17 +0300 Subject: [PATCH] Windows: qualify Runtime Port the /proc-based test helpers: thread counts come from Toolhelp32Snapshot and descriptor counts from GetProcessHandleCount on Windows. Allowlist Runtime for the Windows target. Windows cross build under Wine 11 (x86_64-w64-mingw32 GCC 16.2): Runtime;Testing 837 tests, 831 passed, 6 skipped, 0 failed. --- cmake/Targets.cmake | 1 + tests/standalone/Runtime/RuntimeShutdown.cpp | 25 +++++++++++++ tests/standalone/Runtime/RuntimeStart.cpp | 37 ++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/cmake/Targets.cmake b/cmake/Targets.cmake index 2185628..d529310 100644 --- a/cmake/Targets.cmake +++ b/cmake/Targets.cmake @@ -73,6 +73,7 @@ set(VOID_WINDOWS_MODULES Observability ObservabilityHooks Plugin + Runtime Scheduler Service Sqlite diff --git a/tests/standalone/Runtime/RuntimeShutdown.cpp b/tests/standalone/Runtime/RuntimeShutdown.cpp index e640f44..57e8a26 100644 --- a/tests/standalone/Runtime/RuntimeShutdown.cpp +++ b/tests/standalone/Runtime/RuntimeShutdown.cpp @@ -14,6 +14,11 @@ #include #include +#ifdef _WIN32 +#include +#include +#endif + #include #include #include @@ -60,6 +65,25 @@ using Void::Testing::require; [[nodiscard]] std::size_t count_tasks() { +#ifdef _WIN32 + const DWORD pid = ::GetCurrentProcessId(); + const HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); + if (snapshot == INVALID_HANDLE_VALUE) { + return 1; + } + THREADENTRY32 entry{}; + entry.dwSize = sizeof(entry); + std::size_t count = 0; + if (::Thread32First(snapshot, &entry) != 0) { + do { + if (entry.th32OwnerProcessID == pid) { + ++count; + } + } while (::Thread32Next(snapshot, &entry) != 0); + } + (void)::CloseHandle(snapshot); + return count == 0 ? 1 : count; +#else std::size_t count = 0; std::error_code ec; for (const auto& _ : std::filesystem::directory_iterator("/proc/self/task", ec)) { @@ -67,6 +91,7 @@ using Void::Testing::require; ++count; } return count; +#endif } // Linux pthread_join() returns at mm_release(), slightly before diff --git a/tests/standalone/Runtime/RuntimeStart.cpp b/tests/standalone/Runtime/RuntimeStart.cpp index ae97c17..3161c49 100644 --- a/tests/standalone/Runtime/RuntimeStart.cpp +++ b/tests/standalone/Runtime/RuntimeStart.cpp @@ -8,6 +8,11 @@ #include #include +#ifdef _WIN32 +#include +#include +#endif + #include #include #include @@ -44,6 +49,37 @@ using Void::Testing::require; [[nodiscard]] std::size_t count_dir_entries(const char* path) { +#ifdef _WIN32 + // /proc stand-ins: thread count from Toolhelp, descriptor count from the + // process handle count. + const std::string name{path}; + if (name == "/proc/self/task") { + const DWORD pid = ::GetCurrentProcessId(); + const HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); + if (snapshot == INVALID_HANDLE_VALUE) { + return 1; + } + THREADENTRY32 entry{}; + entry.dwSize = sizeof(entry); + std::size_t count = 0; + if (::Thread32First(snapshot, &entry) != 0) { + do { + if (entry.th32OwnerProcessID == pid) { + ++count; + } + } while (::Thread32Next(snapshot, &entry) != 0); + } + (void)::CloseHandle(snapshot); + return count == 0 ? 1 : count; + } + if (name == "/proc/self/fd") { + DWORD handles = 0; + return ::GetProcessHandleCount(::GetCurrentProcess(), &handles) != 0 + ? static_cast(handles) + : 0; + } + return 0; +#else std::size_t count = 0; std::error_code ec; for (const auto& _ : std::filesystem::directory_iterator(path, ec)) { @@ -51,6 +87,7 @@ using Void::Testing::require; ++count; } return count; +#endif } // Linux pthread_join() returns at mm_release(), slightly before