upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/acphal_test.cpp
diff options
context:
space:
mode:
authorandretuta <andreviniciusmerlia@gmail.com>2026-11-24 03:15:02 -0300
committerandretuta <andreviniciusmerlia@gmail.com>2026-11-24 03:15:02 -0300
commit12536c2ab33072b8f49a8d012c970093c90c0866 (patch)
tree7c4d428bb73644ce57e265eb040e068f24ead4dd /runtime/test/acphal_test.cpp
parent259772edb4042e4c81d9196ec5064a6f84c09ed7 (diff)
acphal: stop the XMA worker it was meant to stop
stop_worker set a shared stopping_ flag, moved the thread out and joined it after releasing worker_mutex_. A wake in that window reset stopping_ and started a second worker, so the old one kept running and the join could hang. Each worker is now a std::jthread with its own stop_token (waits use condition_variable_any with the token), so a stop only reaches its own thread. acphal_test races 20000 context alloc/release rounds against ENABLE_XMA on a second thread (the unfixed code hung there intermittently). AI-assisted. Tested: acphal_test 115 checks, 0 failures, repeated runs (clang 23 / mingw x64). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/acphal_test.cpp')
-rw-r--r--runtime/test/acphal_test.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/runtime/test/acphal_test.cpp b/runtime/test/acphal_test.cpp
index ca3167e64..276d5815a 100644
--- a/runtime/test/acphal_test.cpp
+++ b/runtime/test/acphal_test.cpp
@@ -6,10 +6,12 @@
6 6
7#include <windows.h> 7#include <windows.h>
8 8
9#include <atomic>
9#include <cstddef> 10#include <cstddef>
10#include <cstdint> 11#include <cstdint>
11#include <cstdio> 12#include <cstdio>
12#include <cstring> 13#include <cstring>
14#include <thread>
13#include <vector> 15#include <vector>
14 16
15#include "shims.h" 17#include "shims.h"
@@ -462,6 +464,41 @@ int main() {
462 check(release_ctx(&xma_ctx) == S_OK, "Release XMA SHAPE contexts joins decoder cleanly"); 464 check(release_ctx(&xma_ctx) == S_OK, "Release XMA SHAPE contexts joins decoder cleanly");
463 } 465 }
464 466
467 // 9. ENABLE_XMA (starts/wakes the decoder worker) racing bind/release (stops it).
468 // Every release must return; a lost stop would hang this block.
469 {
470 using RaceConnectFn = HRESULT(__stdcall*)(void*, uint32_t, uint32_t);
471 using RaceSubmitFn = HRESULT(__stdcall*)(void*, uint32_t, uint64_t, uint32_t, const void*, uint32_t);
472 using RaceReleaseFn = HRESULT(__stdcall*)(void*);
473
474 void* race_acp = nullptr;
475 check(create(&race_acp) == S_OK && race_acp != nullptr, "AcpHalCreate for XMA race test");
476 auto race_vt = *static_cast<void* const* const*>(race_acp);
477 const auto race_connect = reinterpret_cast<RaceConnectFn>(race_vt[0]);
478 const auto race_submit = reinterpret_cast<RaceSubmitFn>(race_vt[2]);
479 const auto race_release = reinterpret_cast<RaceReleaseFn>(race_vt[5]);
480 check(race_connect(race_acp, 0x1000, 0x1000) == S_OK, "Connect for XMA race test");
481
482 constexpr int kRaceIterations = 20000;
483 std::atomic<int> bind_failures{0};
484 std::thread enabler([&]() {
485 const uint32_t enable_arg = 1u;
486 for (int i = 0; i < kRaceIterations; ++i) {
487 race_submit(race_acp, 5, 0xe000u + static_cast<uint64_t>(i), 0xffffffffu,
488 &enable_arg, 0);
489 }
490 });
491 for (int i = 0; i < kRaceIterations; ++i) {
492 TestShapeContexts race_ctx{};
493 race_ctx.numXmaContexts = 4;
494 if (alloc_ctx(&race_ctx) != S_OK) ++bind_failures;
495 if (release_ctx(&race_ctx) != S_OK) ++bind_failures;
496 }
497 enabler.join();
498 check(bind_failures == 0, "20000 bind/release cycles race ENABLE_XMA without hanging");
499 check(race_release(race_acp) == S_OK, "Release race AcpHal succeeds");
500 }
501
465 std::printf("acphal_test complete: %d checks, %d failures\n", g_checks, g_failures); 502 std::printf("acphal_test complete: %d checks, %d failures\n", g_checks, g_failures);
466 return g_failures ? 1 : 0; 503 return g_failures ? 1 : 0;
467} 504}