upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/allocator_proxy_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/allocator_proxy_test.cpp')
-rw-r--r--runtime/test/allocator_proxy_test.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/runtime/test/allocator_proxy_test.cpp b/runtime/test/allocator_proxy_test.cpp
index 5f89366f5..b48b224b7 100644
--- a/runtime/test/allocator_proxy_test.cpp
+++ b/runtime/test/allocator_proxy_test.cpp
@@ -58,11 +58,13 @@ using SlotFn = std::uint64_t(WINAPI*)(void*, std::uint64_t, std::uint64_t, std::
58 std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, 58 std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t,
59 std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t); 59 std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t);
60 60
61// A call through slot `slot` with all words zero, the way a title calls a console method the PC interface lacks. 61// A call through slot `slot` with up to four explicit words (rest zero), the way a title calls a console method the PC
62HRESULT call_slot(void* object, unsigned slot) { 62// interface lacks.
63HRESULT call_slot(void* object, unsigned slot, std::uint64_t a1 = 0, std::uint64_t a2 = 0, std::uint64_t a3 = 0,
64 std::uint64_t a4 = 0) {
63 void** vtable = *reinterpret_cast<void***>(object); 65 void** vtable = *reinterpret_cast<void***>(object);
64 return static_cast<HRESULT>(static_cast<std::uint32_t>( 66 return static_cast<HRESULT>(static_cast<std::uint32_t>(
65 reinterpret_cast<SlotFn>(vtable[slot])(object, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); 67 reinterpret_cast<SlotFn>(vtable[slot])(object, a1, a2, a3, a4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
66} 68}
67 69
68ULONG_PTR g_fault_address = 0; 70ULONG_PTR g_fault_address = 0;
@@ -182,10 +184,24 @@ int check_proxy(const Backend& b, ID3D12CommandAllocator* allocator) {
182 back->Release(); 184 back->Release();
183 EXPECT(SUCCEEDED(allocator->SetPrivateDataInterface(key, nullptr))); 185 EXPECT(SUCCEEDED(allocator->SetPrivateDataInterface(key, nullptr)));
184 186
185 // The refused tail: every slot past the public chain, up to the table end, is E_NOTIMPL and counted. 187 // Console slot 9 (SetAllocatorCallbackX): records callback/context on the proxy and returns S_OK.
186 const unsigned table = xs::allocator_proxy_table_size(); 188 const unsigned table = xs::allocator_proxy_table_size();
187 EXPECT(table == 64); 189 EXPECT(table == 64);
188 for (unsigned slot = 9; slot < table; ++slot) { 190 {
191 EXPECT(xs::allocator_proxy_callback(allocator) == 0 && xs::allocator_proxy_callback_context(allocator) == 0);
192 constexpr std::uintptr_t fake_cb = 0x11223344u;
193 constexpr std::uintptr_t fake_ctx = 0x55667788u;
194 const std::uint64_t before = xs::allocator_slot_hits(9);
195 EXPECT(call_slot(allocator, 9, fake_cb, fake_ctx, 0, 0x99aabbccu) == S_OK);
196 EXPECT(xs::allocator_slot_hits(9) == before + 1 && xs::allocator_slot_first_call_seen(9));
197 EXPECT(xs::allocator_proxy_callback(allocator) == fake_cb &&
198 xs::allocator_proxy_callback_context(allocator) == fake_ctx);
199 EXPECT(call_slot(allocator, 9, 0, 0) == S_OK);
200 EXPECT(xs::allocator_proxy_callback(allocator) == 0 && xs::allocator_proxy_callback_context(allocator) == 0);
201 }
202
203 // The refused tail: every slot past slot 9, up to the table end, is E_NOTIMPL and counted.
204 for (unsigned slot = 10; slot < table; ++slot) {
189 const std::uint64_t before = xs::allocator_slot_hits(slot); 205 const std::uint64_t before = xs::allocator_slot_hits(slot);
190 EXPECT(call_slot(allocator, slot) == E_NOTIMPL); 206 EXPECT(call_slot(allocator, slot) == E_NOTIMPL);
191 EXPECT(xs::allocator_slot_hits(slot) == before + 1 && xs::allocator_slot_first_call_seen(slot)); 207 EXPECT(xs::allocator_slot_hits(slot) == before + 1 && xs::allocator_slot_first_call_seen(slot));
@@ -201,8 +217,9 @@ int check_proxy(const Backend& b, ID3D12CommandAllocator* allocator) {
201 EXPECT(g_fault_address == reinterpret_cast<ULONG_PTR>(&vtable[slot])); 217 EXPECT(g_fault_address == reinterpret_cast<ULONG_PTR>(&vtable[slot]));
202 EXPECT(xs::allocator_table_overruns() == before + 1); 218 EXPECT(xs::allocator_table_overruns() == before + 1);
203 } 219 }
204 std::printf("%s: allocator proxy: 9 public slots forwarded, slots 9-%u refused, the guard region names a read " 220 std::printf("%s: allocator proxy: 9 public slots forwarded, slot 9 SetAllocatorCallbackX handled, slots 10-%u "
205 "past the table; QueryInterface/GetDevice/private data keep the proxy identity\n", label, table - 1); 221 "refused, the guard region names a read past the table; QueryInterface/GetDevice/private data keep "
222 "the proxy identity\n", label, table - 1);
206 return 0; 223 return 0;
207} 224}
208 225