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.
This commit is contained in:
1 parent
b6e2181f0e
commit
aec09a08fa
3 files changed
+63
No files matched your search
@@ -73,6 +73,7 @@ set(VOID_WINDOWS_MODULES
|
|||||||
Observability
|
Observability
|
||||||
ObservabilityHooks
|
ObservabilityHooks
|
||||||
Plugin
|
Plugin
|
||||||
|
Runtime
|
||||||
Scheduler
|
Scheduler
|
||||||
Service
|
Service
|
||||||
Sqlite
|
Sqlite
|
||||||
|
|||||||
@@ -14,6 +14,11 @@
|
|||||||
#include <Void/Testing/Test.hpp>
|
#include <Void/Testing/Test.hpp>
|
||||||
#include <Void/Time/Clock.hpp>
|
#include <Void/Time/Clock.hpp>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <tlhelp32.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -60,6 +65,25 @@ using Void::Testing::require;
|
|||||||
|
|
||||||
[[nodiscard]] std::size_t count_tasks()
|
[[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::size_t count = 0;
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
for (const auto& _ : std::filesystem::directory_iterator("/proc/self/task", ec)) {
|
for (const auto& _ : std::filesystem::directory_iterator("/proc/self/task", ec)) {
|
||||||
@@ -67,6 +91,7 @@ using Void::Testing::require;
|
|||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux pthread_join() returns at mm_release(), slightly before
|
// Linux pthread_join() returns at mm_release(), slightly before
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
#include <Void/Testing/Test.hpp>
|
#include <Void/Testing/Test.hpp>
|
||||||
#include <Void/Time/Clock.hpp>
|
#include <Void/Time/Clock.hpp>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <tlhelp32.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
@@ -44,6 +49,37 @@ using Void::Testing::require;
|
|||||||
|
|
||||||
[[nodiscard]] std::size_t count_dir_entries(const char* path)
|
[[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<std::size_t>(handles)
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
std::size_t count = 0;
|
std::size_t count = 0;
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
for (const auto& _ : std::filesystem::directory_iterator(path, ec)) {
|
for (const auto& _ : std::filesystem::directory_iterator(path, ec)) {
|
||||||
@@ -51,6 +87,7 @@ using Void::Testing::require;
|
|||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux pthread_join() returns at mm_release(), slightly before
|
// Linux pthread_join() returns at mm_release(), slightly before
|
||||||
|
|||||||
Reference in new issue
Block a user