Files
WoW-Hybrid-gateway/tests/windows_wire_ipc_test.cpp
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

102 lines
4.0 KiB
C++

#ifndef NOMINMAX
#define NOMINMAX
#endif
#include "wine_wire_abi.h"
#include <array>
#include <cstring>
#include <filesystem>
#include <iostream>
#include <windows.h>
#include <winternl.h>
namespace {
void require(bool value, const char *reason) {
if (!value)
throw std::runtime_error(reason);
}
template <class T> T symbol(HMODULE module, const char *name) {
auto source = GetProcAddress(module, name);
T out = nullptr;
static_assert(sizeof(out) == sizeof(source));
std::memcpy(&out, &source, sizeof(out));
require(out != nullptr, "Existing Wire export absent");
return out;
}
void no_backend() {
require(!GetModuleHandleW(L"GWNativeBackend.dll") &&
!GetModuleHandleW(L"forever_codec.dll"),
"Backend/codec loaded in frontend process");
}
gw_wire_call call(uint32_t op) {
gw_wire_call c{};
c.abi = GW_WINE_WIRE_ABI;
c.size = sizeof(c);
c.operation = op;
return c;
}
} // namespace
int main(int argc, char **argv) {
try {
require(argc == 3, "Expected isolated Wire and backend paths");
auto wire_path = std::filesystem::canonical(std::filesystem::path(
std::u8string(argv[1], argv[1] + std::strlen(argv[1]))));
auto backend = std::filesystem::canonical(std::filesystem::path(
std::u8string(argv[2], argv[2] + std::strlen(argv[2]))));
no_backend();
auto module = LoadLibraryExW(wire_path.c_str(), nullptr,
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR |
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
require(module != nullptr, "Isolated same-name Wire load failed");
auto initialize =
symbol<NTSTATUS(WINAPI *)(const WCHAR *)>(module, "gw_wire_initialize");
auto dispatch =
symbol<NTSTATUS(WINAPI *)(gw_wire_call *)>(module, "gw_wire_dispatch");
auto shutdown = symbol<NTSTATUS(WINAPI *)()>(module, "gw_wire_shutdown");
no_backend();
require(initialize(nullptr) == NTSTATUS(0xc000000d), "Null path admitted");
require(initialize(L"relative.dll") == NTSTATUS(0xc000000d),
"Relative backend path admitted");
for (unsigned lifetime = 0; lifetime < 2; ++lifetime) {
require(initialize(backend.c_str()) == 0,
"Owned worker initialization/Ping failed");
no_backend();
std::array<uint8_t, 16> output{};
output.fill(0xa5);
auto ping = call(GW_WIRE_PING);
ping.output = output.data();
ping.capacity = uint32_t(output.size());
require(dispatch(&ping) == 0 && ping.result == 0 && ping.value == 1 &&
ping.required == 0 && output[0] == 0xa5,
"Real worker Ping/output ownership failed");
auto invalid = call(43);
require(dispatch(&invalid) == NTSTATUS(0xc000000d),
"Unknown operation admitted");
uint8_t synthetic = 1;
auto malformed = call(GW_WIRE_AUTHENTICATE_MEMORY_IPV4);
malformed.input = &synthetic;
malformed.input_bytes = 1;
require(dispatch(&malformed) == NTSTATUS(0xc000000d),
"Pointer-bearing malformed auth shape admitted");
ping = call(GW_WIRE_PING);
require(dispatch(&ping) == 0 && ping.result == 0 && ping.value == 1,
"Local refusal corrupted worker sequence");
auto counts = call(GW_WIRE_COUNTS);
require(dispatch(&counts) == 0 && counts.result == 0 &&
counts.value == 0 && counts.consumed == 0,
"Unexpected worker registry resources");
no_backend();
require(shutdown() == 0, "Owned worker shutdown failed");
require(dispatch(&ping) == NTSTATUS(0xc0000184),
"Dispatch after shutdown admitted");
no_backend();
}
require(FreeLibrary(module) != 0, "Wire unload failed");
std::cout
<< "PASS real same-name Wire->owned worker ABI, two clean lifetimes, "
"local refusals/sequence and no in-process backend/codec\n";
return 0;
} catch (const std::exception &error) {
std::cerr << "External Wire IPC boundary: " << error.what() << '\n';
return 1;
}
}