upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/queue_proxy_test.cpp
diff options
context:
space:
mode:
authorSagah123 <globa7002@gmail.com>2026-11-22 16:03:17 +0100
committerSagah123 <globa7002@gmail.com>2026-11-22 16:03:17 +0100
commit35c78fa60cff1505086b70e3384c1802a099e73a (patch)
treef7d5c2346bbaeaae462a8fb3bad6371c8b79668f /runtime/test/queue_proxy_test.cpp
parent003e78129303643a3fdc9e5f0e31a01b09759236 (diff)
queue_proxy_test: run non-destructive differential cases in-process (TEST-242)
Differential error and argument validation cases that do not alter device residency, touch the sharing subsystem, or fault on the PC runtime are now executed in-process directly against the backend's devices. Cases modifying residency (1, 2, 26..29), creating shared handles (30, 31), or faulting under SEH on the host runtime (17..20, 25) remain isolated in child processes. LEONIDA_QUEUE_PROXY_ISOLATE_ALL=1 is supported as an override to force all cases into child processes. Tested on Windows 11 with MSVC 19.51, NVIDIA GeForce RTX 3060 (WARP + hardware + Vulkan backends): execution time drops significantly with zero leaks and 3 backends passing cleanly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/queue_proxy_test.cpp')
-rw-r--r--runtime/test/queue_proxy_test.cpp65
1 files changed, 58 insertions, 7 deletions
diff --git a/runtime/test/queue_proxy_test.cpp b/runtime/test/queue_proxy_test.cpp
index 69c1c26bd..3d5ed98fa 100644
--- a/runtime/test/queue_proxy_test.cpp
+++ b/runtime/test/queue_proxy_test.cpp
@@ -1067,26 +1067,77 @@ unsigned differential_jobs() {
1067 return half < 1 ? 1 : half > 8 ? 8 : half; 1067 return half < 1 ? 1 : half > 8 ? 8 : half;
1068} 1068}
1069 1069
1070// Cases that fault in the PC runtime (17..20, 25), modify device residency (1, 2, 26..29), or touch the shared
1071// handle subsystem (30, 31) are isolated in child processes so the host device remains completely clean and intact.
1072// Non-destructive argument-validation and proxy-wrapping cases run in-process for speed (<1 ms each).
1073bool is_isolated_diff_case(int index) {
1074 if (index == 1 || index == 2) return true; // residency (descriptor heap)
1075 if (index >= 17 && index <= 20) return true; // faults on PC runtime (queue null args)
1076 if (index == 25) return true; // faults on PC runtime (null fence entry)
1077 if (index >= 26 && index <= 29) return true; // residency (MakeResident/Evict/Priority/Enqueue)
1078 if (index == 30 || index == 31) return true; // shared handle creation
1079 return false;
1080}
1081
1082ChildResult run_in_process(const char* label, ID3D12Device* target_device, int index, bool through_proxy,
1083 unsigned long validation_errors = 0) {
1084 ChildResult r{};
1085 Event event;
1086 DiffContext context{};
1087 Ref<ID3D12CommandQueue> queue;
1088 Ref<ID3D12Fence> fence, second;
1089 if (make_context(label, target_device, context, queue, fence, second)) return r;
1090 if (xs::is_queue_proxy(context.queue) != through_proxy || xs::is_fence_proxy(context.fence) != through_proxy) {
1091 return r;
1092 }
1093 context.event = event.h;
1094 HRESULT result = S_OK;
1095 const bool ran = run_guarded(kDiffCases[index].run, &context, &result);
1096 const HRESULT removed = ran ? target_device->GetDeviceRemovedReason() : S_OK;
1097 r.ok = true;
1098 r.ran = ran ? 1 : 0;
1099 r.hr = static_cast<unsigned long>(result);
1100 r.removed = static_cast<unsigned long>(removed);
1101 r.validation = validation_errors;
1102 return r;
1103}
1104
1070// Each case, in a child process for the real object and in another for the proxy: the same HRESULT, the device 1105// Each case, in a child process for the real object and in another for the proxy: the same HRESULT, the device
1071// removed (or not) alike, and no validation errors. A case the real runtime faults on is reported, not compared. 1106// removed (or not) alike, and no validation errors. A case the real runtime faults on is reported, not compared.
1072// The children run differential_jobs() at a time; the results are judged afterwards in case order, so the report is 1107// Non-destructive argument-validation and proxy cases run in-process (<1 ms each instead of ~5 s per device creation).
1073// the same as one child after another would give (a proxy child whose real one faulted is run but not judged). 1108// Faulting, residency, or shared cases run in isolated child processes using differential_jobs() workers.
1074int check_differential(const Backend& b) { 1109int check_differential(const Backend& b) {
1075 const char* label = b.label; 1110 const char* label = b.label;
1076 int compared = 0, faulting = 0; 1111 int compared = 0, faulting = 0;
1077 constexpr int kCases = static_cast<int>(std::size(kDiffCases)); 1112 constexpr int kCases = static_cast<int>(std::size(kDiffCases));
1078 std::vector<ChildResult> results(2 * kCases); // [2 * case] real, [2 * case + 1] proxy 1113 std::vector<ChildResult> results(2 * kCases); // [2 * case] real, [2 * case + 1] proxy
1079 { 1114
1080 std::atomic<int> next{0}; 1115 const bool force_isolate_all = GetEnvironmentVariableA("LEONIDA_QUEUE_PROXY_ISOLATE_ALL", nullptr, 0) > 0;
1116
1117 std::vector<int> child_jobs;
1118 for (int i = 0; i < kCases; ++i) {
1119 if (force_isolate_all || is_isolated_diff_case(i)) {
1120 child_jobs.push_back(2 * i); // real
1121 child_jobs.push_back(2 * i + 1); // proxy
1122 } else {
1123 results[2 * i] = run_in_process(label, b.real, i, false);
1124 results[2 * i + 1] = run_in_process(label, b.device, i, true);
1125 }
1126 }
1127
1128 if (!child_jobs.empty()) {
1129 std::atomic<size_t> next{0};
1081 const auto work = [&] { 1130 const auto work = [&] {
1082 for (int job; (job = next.fetch_add(1)) < 2 * kCases;) 1131 for (size_t idx; (idx = next.fetch_add(1)) < child_jobs.size();) {
1132 const int job = child_jobs[idx];
1083 results[job] = run_child(b.kind, job / 2, job % 2 == 1); 1133 results[job] = run_child(b.kind, job / 2, job % 2 == 1);
1134 }
1084 }; 1135 };
1085 const unsigned jobs = differential_jobs(); 1136 const unsigned jobs = differential_jobs();
1086 std::vector<std::thread> pool; 1137 std::vector<std::thread> pool;
1087 try { 1138 try {
1088 for (unsigned t = 1; t < jobs; ++t) pool.emplace_back(work); 1139 for (unsigned t = 1; t < jobs && t < child_jobs.size(); ++t) pool.emplace_back(work);
1089 } catch (const std::system_error& e) { // fewer helpers; this thread still runs every job left 1140 } catch (const std::system_error& e) {
1090 std::fprintf(stderr, "%s: %zu of %u differential runner threads (%s)\n", label, pool.size() + 1, jobs, 1141 std::fprintf(stderr, "%s: %zu of %u differential runner threads (%s)\n", label, pool.size() + 1, jobs,
1091 e.what()); 1142 e.what());
1092 } 1143 }