Windows: full module parity and runtime-qualified test suite

- Net/IO: Winsock sockets (UdpSocket, TlsClientStream, WebSocketClient),
  HttpServer port with a loopback wake socket replacing eventfd, and the
  select-based IO backend built on Windows (ws2_32).
- Net: implement StaticFileResolver::open_safe and OpenedStaticFile on
  Windows (reparse-point rejection plus canonical containment check on the
  opened handle) and widen native handles to intptr_t.
- Plugin: hot reload works on Windows by loading a fresh copy while the old
  DLL stays mapped; enable the reload, discovery and FSM service reload
  tests and retire the plugin file by rename instead of replacement.
- Update: activation pointer as a directory junction on Windows.
- Stacktrace: portable path comparison for wide native strings.
- Docs/targets: every module allowlisted on Windows; record the Wine run
  (2000 tests, 1977 passed, 23 skipped, 0 failed).
- CMake: add -Wa,-mbig-obj for GNU MinGW targets (COFF section limit).
- Async: fix the FuturePool stopped-after-close test to wait for the
  executor to release its admission slot instead of racing it.

Windows and Linux suites both pass: Windows 2000/1977/23 skips/0 failed,
Linux 2027/2023/4 skips/0 failed.
This commit is contained in:
faumaray committed 2026-12-06 14:56:26 +03:00
1 parent 1b1947340f
commit b3c959b920
32 files changed
+1836 -401

No files matched your search

+60 -23
View File
@@ -12,16 +12,44 @@
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#ifndef SHUT_RDWR
#define SHUT_RDWR SD_BOTH
#endif
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
using SocketLength = int;
inline void close_socket(int fd) noexcept
{
(void)::closesocket(static_cast<SOCKET>(fd));
}
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
using SocketLength = socklen_t;
inline void close_socket(int fd) noexcept
{
(void)::close(fd);
}
#endif
#include <atomic>
#include <filesystem>
#include <fstream>
#include <netinet/in.h>
#include <stop_token>
#include <string>
#include <sys/socket.h>
#include <thread>
#include <unistd.h>
#include <vector>
#include <vector>
namespace
@@ -40,13 +68,14 @@ namespace
{
fd = ::socket(AF_INET, SOCK_STREAM, 0);
int yes = 1;
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<const char*>(&yes), sizeof(yes));
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = 0;
::bind(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
socklen_t len = sizeof(addr);
SocketLength len = sizeof(addr);
::getsockname(fd, reinterpret_cast<sockaddr*>(&addr), &len);
port = ntohs(addr.sin_port);
::listen(fd, 1);
@@ -55,15 +84,15 @@ namespace
int conn = ::accept(fd, nullptr, nullptr);
if (conn < 0) return;
char buf[4096];
const auto n = ::read(conn, buf, sizeof(buf));
const auto n = ::recv(conn, buf, sizeof(buf), 0);
if (n > 0) last_request.assign(buf, buf + n);
const std::string resp =
"HTTP/1.1 200 OK\r\nContent-Length: " +
std::to_string(body.size()) +
"\r\nConnection: close\r\n\r\n" + body;
[[maybe_unused]] auto w =
::write(conn, resp.data(), resp.size());
::close(conn);
::send(conn, resp.data(), resp.size(), 0);
close_socket(conn);
served = true;
});
}
@@ -71,7 +100,7 @@ namespace
~OneShotServer()
{
if (worker.joinable()) worker.join();
if (fd >= 0) ::close(fd);
if (fd >= 0) close_socket(fd);
}
};
@@ -120,12 +149,12 @@ namespace
const auto cert_path = dir / (std::string{"cert_"} + tag + ".pem");
const auto key_path = dir / (std::string{"key_"} + tag + ".pem");
FILE* cf = std::fopen(cert_path.c_str(), "wb");
FILE* cf = std::fopen(cert_path.string().c_str(), "wb");
Void::Testing::require(cf != nullptr);
Void::Testing::require(PEM_write_X509(cf, cert.get()) == 1);
std::fclose(cf);
FILE* kf = std::fopen(key_path.c_str(), "wb");
FILE* kf = std::fopen(key_path.string().c_str(), "wb");
Void::Testing::require(kf != nullptr);
Void::Testing::require(PEM_write_PrivateKey(kf, pkey.get(), nullptr,
nullptr, 0, nullptr,
@@ -145,15 +174,18 @@ namespace
ctx = SSL_CTX_new(TLS_server_method());
Void::Testing::require(ctx != nullptr);
Void::Testing::require(
SSL_CTX_use_certificate_file(ctx, creds.cert_file.c_str(),
SSL_FILETYPE_PEM) == 1);
SSL_CTX_use_certificate_file(ctx,
creds.cert_file.string().c_str(),
SSL_FILETYPE_PEM) == 1);
Void::Testing::require(
SSL_CTX_use_PrivateKey_file(ctx, creds.key_file.c_str(),
SSL_CTX_use_PrivateKey_file(ctx,
creds.key_file.string().c_str(),
SSL_FILETYPE_PEM) == 1);
fd = ::socket(AF_INET, SOCK_STREAM, 0);
int yes = 1;
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<const char*>(&yes), sizeof(yes));
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
@@ -161,7 +193,7 @@ namespace
Void::Testing::require(
::bind(fd, reinterpret_cast<sockaddr*>(&addr),
sizeof(addr)) == 0);
socklen_t len = sizeof(addr);
SocketLength len = sizeof(addr);
::getsockname(fd, reinterpret_cast<sockaddr*>(&addr), &len);
port = ntohs(addr.sin_port);
Void::Testing::require(::listen(fd, 1) == 0);
@@ -183,14 +215,14 @@ namespace
SSL_shutdown(ssl);
}
SSL_free(ssl);
::close(conn);
close_socket(conn);
});
}
~OneShotTlsServer()
{
if (worker.joinable()) worker.join();
if (fd >= 0) ::close(fd);
if (fd >= 0) close_socket(fd);
if (ctx != nullptr) SSL_CTX_free(ctx);
}
};
@@ -256,13 +288,14 @@ Void::Testing::Test http_client_timeout_bounds_a_stalled_server()
{
fd = ::socket(AF_INET, SOCK_STREAM, 0);
int yes = 1;
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<const char*>(&yes), sizeof(yes));
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = 0;
::bind(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
socklen_t len = sizeof(addr);
SocketLength len = sizeof(addr);
::getsockname(fd, reinterpret_cast<sockaddr*>(&addr), &len);
port = ntohs(addr.sin_port);
::listen(fd, 1);
@@ -273,10 +306,14 @@ Void::Testing::Test http_client_timeout_bounds_a_stalled_server()
~StallServer()
{
if (fd >= 0) ::shutdown(fd, SHUT_RDWR);
// Close the listener first: on Windows, shutdown() does not wake a
// thread blocked in accept().
if (fd >= 0) {
close_socket(fd);
fd = -1;
}
if (worker.joinable()) worker.join();
if (conn >= 0) ::close(conn);
if (fd >= 0) ::close(fd);
if (conn >= 0) close_socket(conn);
}
};
+25
View File
@@ -3,11 +3,28 @@
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#include <cstddef>
using ssize_t = std::ptrdiff_t;
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
#define close closesocket
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <poll.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
#include <algorithm>
#include <array>
@@ -42,11 +59,19 @@ namespace
const int fd = ::socket(AF_INET, SOCK_STREAM, 0);
Void::Testing::require(fd >= 0);
#ifdef _WIN32
DWORD tv = 3000;
(void)::setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,
reinterpret_cast<const char*>(&tv), sizeof(tv));
(void)::setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO,
reinterpret_cast<const char*>(&tv), sizeof(tv));
#else
timeval tv{};
tv.tv_sec = 3;
tv.tv_usec = 0;
(void)::setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
(void)::setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
#endif
sockaddr_in addr{};
addr.sin_family = AF_INET;
+29 -6
View File
@@ -4,10 +4,24 @@
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#ifndef SHUT_WR
#define SHUT_WR SD_SEND
#endif
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
#include <array>
#include <atomic>
@@ -31,9 +45,18 @@ namespace
using Void::Net::ServerRequest;
using Void::Net::ServerResponse;
void close_socket(int fd) noexcept
{
#ifdef _WIN32
(void)::closesocket(static_cast<SOCKET>(fd));
#else
(void)::close(fd);
#endif
}
std::string raw_http_exchange(std::uint16_t port, std::string_view raw_req)
{
const int fd = ::socket(AF_INET, SOCK_STREAM, 0);
const int fd = static_cast<int>(::socket(AF_INET, SOCK_STREAM, 0));
Void::Testing::require(fd >= 0);
sockaddr_in addr{};
@@ -46,7 +69,7 @@ namespace
std::size_t off = 0;
while (off < raw_req.size()) {
const ssize_t w =
const std::ptrdiff_t w =
::send(fd, raw_req.data() + off, raw_req.size() - off, 0);
Void::Testing::require(w > 0);
off += static_cast<std::size_t>(w);
@@ -56,13 +79,13 @@ namespace
std::string out;
std::array<char, 4096> buf{};
for (;;) {
const ssize_t r = ::recv(fd, buf.data(), buf.size(), 0);
const std::ptrdiff_t r = ::recv(fd, buf.data(), buf.size(), 0);
if (r <= 0) {
break;
}
out.append(buf.data(), static_cast<std::size_t>(r));
}
(void)::close(fd);
close_socket(fd);
return out;
}
@@ -230,7 +253,7 @@ Void::Testing::Test http_server_ephemeral_methods_and_concurrent_dispatch()
Void::Testing::expect_eq(server.bound_port(), std::uint16_t{0});
// No dangling listening socket after shutdown().
const int probe = ::socket(AF_INET, SOCK_STREAM, 0);
const int probe = static_cast<int>(::socket(AF_INET, SOCK_STREAM, 0));
Void::Testing::require(probe >= 0);
sockaddr_in addr{};
addr.sin_family = AF_INET;
@@ -239,7 +262,7 @@ Void::Testing::Test http_server_ephemeral_methods_and_concurrent_dispatch()
Void::Testing::expect(
::connect(probe, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) !=
0);
(void)::close(probe);
close_socket(probe);
}
Void::Testing::Test http_server_limits_smuggling_streaming_and_graceful_drain()
+9 -4
View File
@@ -228,7 +228,8 @@ Void::Testing::Test net_static_file_resolver_open_safe_pins_root_and_rejects_sym
std::ofstream f{secret};
f << "top-secret";
}
std::filesystem::create_symlink(secret, root / "escape.txt");
std::error_code link_ec;
std::filesystem::create_symlink(secret, root / "escape.txt", link_ec);
auto resolver = Void::Net::StaticFileResolver::create(root);
Void::Testing::require(resolver.has_value());
@@ -248,9 +249,13 @@ Void::Testing::Test net_static_file_resolver_open_safe_pins_root_and_rejects_sym
Void::Testing::require(missing.has_value());
Void::Testing::expect(!missing->has_value());
// Symlink inside root is rejected by O_NOFOLLOW.
auto sym = resolver->open_safe("/escape.txt");
Void::Testing::expect(!sym.has_value());
// Symlink inside root is rejected by O_NOFOLLOW (or reparse-point
// rejection on Windows); without symlink privilege there is nothing to
// create, so only that assertion is skipped.
if (!link_ec) {
auto sym = resolver->open_safe("/escape.txt");
Void::Testing::expect(!sym.has_value());
}
// Traversal rejected.
auto trav = resolver->open_safe("/../secret.txt");
+5 -5
View File
@@ -49,10 +49,10 @@ namespace
Void::Testing::require(ctx != nullptr);
Void::Testing::require(
SSL_CTX_use_certificate_file(
ctx, cert.cert_file.c_str(), SSL_FILETYPE_PEM) == 1);
ctx, cert.cert_file.string().c_str(), SSL_FILETYPE_PEM) == 1);
Void::Testing::require(
SSL_CTX_use_PrivateKey_file(
ctx, cert.key_file.c_str(), SSL_FILETYPE_PEM) == 1);
ctx, cert.key_file.string().c_str(), SSL_FILETYPE_PEM) == 1);
worker = std::thread([this, mode] { serve(mode); });
}
@@ -84,7 +84,7 @@ namespace
char byte = 0;
while (::recv(connection, &byte, 1, 0) > 0) {
}
::close(connection);
::test_close_socket(connection);
return;
}
@@ -97,7 +97,7 @@ namespace
const int accepted = SSL_accept(ssl);
if (accepted != 1) {
SSL_free(ssl);
::close(connection);
::test_close_socket(connection);
return;
}
tls = true;
@@ -205,7 +205,7 @@ namespace
SSL_shutdown(ssl);
SSL_free(ssl);
}
::close(connection);
::test_close_socket(connection);
}
};
+8 -8
View File
@@ -38,10 +38,10 @@ namespace
Void::Testing::require(ctx != nullptr);
Void::Testing::require(
SSL_CTX_use_certificate_file(
ctx, cert.cert_file.c_str(), SSL_FILETYPE_PEM) == 1);
ctx, cert.cert_file.string().c_str(), SSL_FILETYPE_PEM) == 1);
Void::Testing::require(
SSL_CTX_use_PrivateKey_file(
ctx, cert.key_file.c_str(), SSL_FILETYPE_PEM) == 1);
ctx, cert.key_file.string().c_str(), SSL_FILETYPE_PEM) == 1);
worker = std::thread(
[this, behavior = std::move(behavior)] {
const int connection = listener.accept_one();
@@ -55,7 +55,7 @@ namespace
SSL_shutdown(ssl);
}
SSL_free(ssl);
::close(connection);
::test_close_socket(connection);
});
}
@@ -88,7 +88,7 @@ namespace
char byte = 0;
while (::recv(connection, &byte, 1, 0) > 0) {
}
::close(connection);
::test_close_socket(connection);
});
}
@@ -221,7 +221,7 @@ Void::Testing::Test tls_client_never_falls_back_to_plaintext()
char buffer[64];
while (::recv(connection, buffer, sizeof(buffer), 0) > 0) {
}
::close(connection);
::test_close_socket(connection);
});
auto stream = Void::Net::TlsClientStream::connect(
make_options(listener.port));
@@ -329,10 +329,10 @@ Void::Testing::Test tls_client_starttls_upgrade()
SSL_CTX* ctx = SSL_CTX_new(TLS_server_method());
Void::Testing::require(ctx != nullptr);
Void::Testing::require(SSL_CTX_use_certificate_file(
ctx, cert.cert_file.c_str(),
ctx, cert.cert_file.string().c_str(),
SSL_FILETYPE_PEM) == 1);
Void::Testing::require(SSL_CTX_use_PrivateKey_file(
ctx, cert.key_file.c_str(),
ctx, cert.key_file.string().c_str(),
SSL_FILETYPE_PEM) == 1);
std::thread worker([&listener, ctx] {
const int connection = listener.accept_one();
@@ -356,7 +356,7 @@ Void::Testing::Test tls_client_starttls_upgrade()
SSL_shutdown(ssl);
}
SSL_free(ssl);
::close(connection);
::test_close_socket(connection);
});
auto options = make_options(listener.port, cert.cert_file.string());