diff options
| author | Maxime Mansiet <AirKyzzZ@users.noreply.github.com> | 2026-11-23 02:59:55 +0100 |
|---|---|---|
| committer | Maxime Mansiet <AirKyzzZ@users.noreply.github.com> | 2026-11-23 02:59:55 +0100 |
| commit | 399b30f69b7105593e92c06499cdd8cc618edbb9 (patch) | |
| tree | 245859df1b2b17dd9efbc3d304c95f691d8cfd4a /runtime/test/gameinput_test.cpp | |
| parent | 03b09a086592a197db64d91655c6e65c30764d96 (diff) | |
gameinput: GetRawReport holds hid_mu while it reads the raw reports
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
| -rw-r--r-- | runtime/test/gameinput_test.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 1389b8f6d..d410f20dd 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include <cstring> | 18 | #include <cstring> |
| 19 | #include <deque> | 19 | #include <deque> |
| 20 | #include <string> | 20 | #include <string> |
| 21 | #include <thread> | ||
| 21 | #include <vector> | 22 | #include <vector> |
| 22 | 23 | ||
| 23 | #include "gameinput.h" | 24 | #include "gameinput.h" |
| @@ -299,11 +300,16 @@ struct FakeRawHid { | |||
| 299 | std::vector<std::vector<uint8_t>> writes, features_sent; | 300 | std::vector<std::vector<uint8_t>> writes, features_sent; |
| 300 | std::vector<uint8_t> feature_reply; | 301 | std::vector<uint8_t> feature_reply; |
| 301 | bool fail = false; | 302 | bool fail = false; |
| 303 | HANDLE in_open = nullptr, release_open = nullptr; | ||
| 302 | }; | 304 | }; |
| 303 | FakeRawHid g_raw; | 305 | FakeRawHid g_raw; |
| 304 | void* raw_open(const char*, uint16_t vendor, uint16_t product) { | 306 | void* raw_open(const char*, uint16_t vendor, uint16_t product) { |
| 305 | if (vendor != g_raw.vendor || product != g_raw.product) return nullptr; | 307 | if (vendor != g_raw.vendor || product != g_raw.product) return nullptr; |
| 306 | ++g_raw.opens; | 308 | ++g_raw.opens; |
| 309 | if (g_raw.release_open) { | ||
| 310 | SetEvent(g_raw.in_open); | ||
| 311 | WaitForSingleObject(g_raw.release_open, 5000); | ||
| 312 | } | ||
| 307 | return &g_raw; | 313 | return &g_raw; |
| 308 | } | 314 | } |
| 309 | void raw_close(void*) { ++g_raw.closes; } | 315 | void raw_close(void*) { ++g_raw.closes; } |
| @@ -456,6 +462,64 @@ void test_raw_hid(IGameInput* input) { | |||
| 456 | rt::gameinput::set_hid_backend(nullptr); | 462 | rt::gameinput::set_hid_backend(nullptr); |
| 457 | } | 463 | } |
| 458 | 464 | ||
| 465 | void test_raw_report_during_reconnect(IGameInput* input) { | ||
| 466 | rt::gameinput::set_hid_backend(&kFakeRawHid); | ||
| 467 | Pad raw_pad; | ||
| 468 | attach(raw_pad, "Leonida virtual raw pad", g_raw.vendor, g_raw.product, false); | ||
| 469 | rt::gameinput::poll(); | ||
| 470 | g_raw.inputs.push_back({0x01, 0x44, 0x55, 0x66}); | ||
| 471 | rt::gameinput::poll(); | ||
| 472 | IGameInputReading* held = nullptr; | ||
| 473 | check(input->GetCurrentReading(GameInputKindRawDeviceReport, nullptr, &held) == S_OK && held, | ||
| 474 | "raw hid reconnect: a reading with a raw report to hold"); | ||
| 475 | detach(raw_pad); | ||
| 476 | rt::gameinput::poll(); | ||
| 477 | if (!held) { | ||
| 478 | rt::gameinput::set_hid_backend(nullptr); | ||
| 479 | return; | ||
| 480 | } | ||
| 481 | |||
| 482 | g_raw.in_open = CreateEventW(nullptr, TRUE, FALSE, nullptr); | ||
| 483 | g_raw.release_open = CreateEventW(nullptr, TRUE, FALSE, nullptr); | ||
| 484 | HANDLE read_done = CreateEventW(nullptr, TRUE, FALSE, nullptr); | ||
| 485 | attach(raw_pad, "Leonida virtual raw pad", g_raw.vendor, g_raw.product, false); | ||
| 486 | std::thread poller([] { rt::gameinput::poll(); }); | ||
| 487 | const bool in_open = WaitForSingleObject(g_raw.in_open, 5000) == WAIT_OBJECT_0; | ||
| 488 | bool got = false; | ||
| 489 | void* report = nullptr; | ||
| 490 | std::thread reader([&] { | ||
| 491 | got = held->GetRawReport(&report); | ||
| 492 | SetEvent(read_done); | ||
| 493 | }); | ||
| 494 | const bool waited = WaitForSingleObject(read_done, 200) == WAIT_TIMEOUT; | ||
| 495 | SetEvent(g_raw.release_open); | ||
| 496 | poller.join(); | ||
| 497 | const bool finished = WaitForSingleObject(read_done, 5000) == WAIT_OBJECT_0; | ||
| 498 | reader.join(); | ||
| 499 | check(in_open && waited, "raw hid reconnect: GetRawReport waits while open_raw rebuilds the report tables"); | ||
| 500 | auto* rr = static_cast<IGameInputRawDeviceReport*>(report); | ||
| 501 | check(finished && got && rr && raw_bytes(rr) == std::vector<uint8_t>({0x44, 0x55, 0x66}), | ||
| 502 | "raw hid reconnect: then it gives the held reading's report"); | ||
| 503 | if (rr) rr->Release(); | ||
| 504 | IGameInputDevice* dev = nullptr; | ||
| 505 | held->GetDevice(&dev); | ||
| 506 | void* created = nullptr; | ||
| 507 | check(dev && (dev->GetDeviceStatus() & GameInputDeviceRawIoEnabled) && | ||
| 508 | dev->CreateRawDeviceReport(2, GameInputRawOutputReport, &created) == S_OK && created, | ||
| 509 | "raw hid reconnect: and the reconnected pad has raw I/O again"); | ||
| 510 | if (created) static_cast<IGameInputRawDeviceReport*>(created)->Release(); | ||
| 511 | if (dev) dev->Release(); | ||
| 512 | held->Release(); | ||
| 513 | |||
| 514 | CloseHandle(read_done); | ||
| 515 | CloseHandle(g_raw.in_open); | ||
| 516 | CloseHandle(g_raw.release_open); | ||
| 517 | g_raw.in_open = g_raw.release_open = nullptr; | ||
| 518 | detach(raw_pad); | ||
| 519 | rt::gameinput::poll(); | ||
| 520 | rt::gameinput::set_hid_backend(nullptr); | ||
| 521 | } | ||
| 522 | |||
| 459 | void test_motion(IGameInput* input) { | 523 | void test_motion(IGameInput* input) { |
| 460 | const size_t events_before = g_device_events.size(); // other tests' events are still queued in the vector | 524 | const size_t events_before = g_device_events.size(); // other tests' events are still queued in the vector |
| 461 | Pad gyro_pad, plain; | 525 | Pad gyro_pad, plain; |
| @@ -1822,6 +1886,7 @@ int main() { | |||
| 1822 | test_force_feedback(input); | 1886 | test_force_feedback(input); |
| 1823 | test_haptic_motors(input); | 1887 | test_haptic_motors(input); |
| 1824 | test_raw_hid(input); | 1888 | test_raw_hid(input); |
| 1889 | test_raw_report_during_reconnect(input); | ||
| 1825 | input->Release(); | 1890 | input->Release(); |
| 1826 | 1891 | ||
| 1827 | std::printf("%d checks, %d failures\n", g_checks, g_failures); | 1892 | std::printf("%d checks, %d failures\n", g_checks, g_failures); |