upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test
diff options
context:
space:
mode:
authorLeonida local test <local-test@localhost>2026-11-22 23:15:09 +0100
committerLeonida local test <local-test@localhost>2026-11-22 23:15:09 +0100
commitdc01a173970ceccfefefc9e70e6cd31b1eeec43a (patch)
tree6c64d024783afb6e06647f1c43779f9b20fe3f86 /runtime/test
parent59aa22ff0ca967db25c0ff8116c52484b7773b5e (diff)
gameinput: report SDL's effect result from gameinput_probe (RT-160)
`--force-feedback` now reads the shim's output state once the poll thread has picked the effect up, and says whether SDL created it and is running it, or why it did not, so a wheel owner can tell a silent drop from a real run. The shim records SDL_CreateHapticEffect's id, SDL_RunHapticEffect's result and SDL's error text per device; gameinput_test asserts the success and the refusal. AI-assisted
Diffstat (limited to 'runtime/test')
-rw-r--r--runtime/test/gameinput_probe.cpp20
-rw-r--r--runtime/test/gameinput_test.cpp26
2 files changed, 43 insertions, 3 deletions
diff --git a/runtime/test/gameinput_probe.cpp b/runtime/test/gameinput_probe.cpp
index 58a6a1010..1d3202cb5 100644
--- a/runtime/test/gameinput_probe.cpp
+++ b/runtime/test/gameinput_probe.cpp
@@ -66,7 +66,9 @@ void play(const char* what, GameInputRumbleParams p) {
66// A constant force at full magnitude on the pad's first motor, held for a second: the effect a wheel feels as a 66// A constant force at full magnitude on the pad's first motor, held for a second: the effect a wheel feels as a
67// steady pull. A pad SDL did not open as a haptic device reports no motor, and the step says so and moves on. 67// steady pull. A pad SDL did not open as a haptic device reports no motor, and the step says so and moves on.
68void constant_force() { 68void constant_force() {
69 for (IGameInputDevice* d : g_devices) { 69 // g_devices is in connection order, which is what output_state indexes; the SDL outcome is read back per pad.
70 for (size_t n = 0; n < g_devices.size(); ++n) {
71 IGameInputDevice* d = g_devices[n];
70 const GameInputDeviceInfo* i = d->GetDeviceInfo(); 72 const GameInputDeviceInfo* i = d->GetDeviceInfo();
71 if (i->forceFeedbackMotorCount == 0) { 73 if (i->forceFeedbackMotorCount == 0) {
72 std::printf("force feedback: %s reports no force-feedback motor; skipped\n", 74 std::printf("force feedback: %s reports no force-feedback motor; skipped\n",
@@ -88,7 +90,21 @@ void constant_force() {
88 } 90 }
89 std::printf("force feedback: constant linearX 1.0 on motor 0, 1 s\n"); 91 std::printf("force feedback: constant linearX 1.0 on motor 0, 1 s\n");
90 e->SetState(GameInputFeedbackRunning); 92 e->SetState(GameInputFeedbackRunning);
91 Sleep(1000); 93 Sleep(1000); // the poll thread creates and runs the effect
94 char seen[256] = "no output state";
95 rt::gameinput::OutputState out{};
96 if (rt::gameinput::output_state(static_cast<int>(n), &out)) {
97 if (out.effect_id < 0) {
98 std::snprintf(seen, sizeof seen, "SDL did not create the effect (%s)",
99 out.effect_error[0] ? out.effect_error : "no error text");
100 } else if (!out.effect_ran) {
101 std::snprintf(seen, sizeof seen, "SDL created effect %d but did not run it (%s)", out.effect_id,
102 out.effect_error[0] ? out.effect_error : "no error text");
103 } else {
104 std::snprintf(seen, sizeof seen, "SDL created effect %d and is running it", out.effect_id);
105 }
106 }
107 std::printf("force feedback: %s\n", seen);
92 e->SetState(GameInputFeedbackStopped); 108 e->SetState(GameInputFeedbackStopped);
93 e->Release(); // the poll thread destroys the SDL effect 109 e->Release(); // the poll thread destroys the SDL effect
94 Sleep(300); 110 Sleep(300);
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index 1389b8f6d..1fab89b5a 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -998,6 +998,7 @@ struct FakeHaptic {
998 SDL_HAPTIC_SAWTOOTHUP | SDL_HAPTIC_SAWTOOTHDOWN | SDL_HAPTIC_RAMP | SDL_HAPTIC_SPRING | 998 SDL_HAPTIC_SAWTOOTHUP | SDL_HAPTIC_SAWTOOTHDOWN | SDL_HAPTIC_RAMP | SDL_HAPTIC_SPRING |
999 SDL_HAPTIC_FRICTION | SDL_HAPTIC_DAMPER | SDL_HAPTIC_INERTIA; 999 SDL_HAPTIC_FRICTION | SDL_HAPTIC_DAMPER | SDL_HAPTIC_INERTIA;
1000 int max_effects = 8; 1000 int max_effects = 8;
1001 int create_result = 1; // what create returns; negative is SDL refusing the effect
1001 int opens = 0, closes = 0, creates = 0, updates = 0, runs = 0, stops = 0, destroys = 0; 1002 int opens = 0, closes = 0, creates = 0, updates = 0, runs = 0, stops = 0, destroys = 0;
1002 int gain_calls = 0, last_gain = -1; 1003 int gain_calls = 0, last_gain = -1;
1003 uint32_t last_iterations = 0; 1004 uint32_t last_iterations = 0;
@@ -1017,8 +1018,12 @@ int fake_max_effects(void* h) { return static_cast<FakeHaptic*>(h)->max_effects;
1017int fake_create(void* h, const void* e) { 1018int fake_create(void* h, const void* e) {
1018 FakeHaptic* f = static_cast<FakeHaptic*>(h); 1019 FakeHaptic* f = static_cast<FakeHaptic*>(h);
1019 ++f->creates; 1020 ++f->creates;
1021 if (f->create_result < 0) {
1022 SDL_SetError("fake: refused");
1023 return -1;
1024 }
1020 f->last = *static_cast<const SDL_HapticEffect*>(e); 1025 f->last = *static_cast<const SDL_HapticEffect*>(e);
1021 return 1; 1026 return f->create_result;
1022} 1027}
1023bool fake_update(void* h, int, const void* e) { 1028bool fake_update(void* h, int, const void* e) {
1024 FakeHaptic* f = static_cast<FakeHaptic*>(h); 1029 FakeHaptic* f = static_cast<FakeHaptic*>(h);
@@ -1114,6 +1119,9 @@ void test_force_feedback(IGameInput* input) {
1114 const int runs0 = g_fake.runs; 1119 const int runs0 = g_fake.runs;
1115 rt::gameinput::poll(); 1120 rt::gameinput::poll();
1116 check(g_fake.creates == 1 && g_fake.runs == runs0 + 1, "force feedback: the poll thread creates and runs the effect"); 1121 check(g_fake.creates == 1 && g_fake.runs == runs0 + 1, "force feedback: the poll thread creates and runs the effect");
1122 rt::gameinput::OutputState sent{};
1123 check(rt::gameinput::output_state(0, &sent) && sent.effect_id == 1 && sent.effect_ran && !sent.effect_error[0],
1124 "force feedback: the output state reports the effect SDL created and is running");
1117 check(g_fake.last.type == SDL_HAPTIC_CONSTANT && g_fake.last.constant.level == 16384, 1125 check(g_fake.last.type == SDL_HAPTIC_CONSTANT && g_fake.last.constant.level == 16384,
1118 "force feedback: a constant 0.5 becomes SDL_HAPTIC_CONSTANT level 16384"); 1126 "force feedback: a constant 0.5 becomes SDL_HAPTIC_CONSTANT level 16384");
1119 check(g_fake.last.constant.length == 60000 && g_fake.last_iterations == 0, 1127 check(g_fake.last.constant.length == 60000 && g_fake.last_iterations == 0,
@@ -1121,6 +1129,22 @@ void test_force_feedback(IGameInput* input) {
1121 rt::gameinput::poll(); 1129 rt::gameinput::poll();
1122 check(g_fake.runs == runs0 + 1, "force feedback: an unchanged effect is not re-sent every poll"); 1130 check(g_fake.runs == runs0 + 1, "force feedback: an unchanged effect is not re-sent every poll");
1123 1131
1132 // SDL refusing an effect is visible, not swallowed: the output state carries the failure and SDL's error.
1133 g_fake.create_result = -1;
1134 IGameInputForceFeedbackEffect* refused = nullptr;
1135 check(dev->CreateForceFeedbackEffect(0, &params, reinterpret_cast<void**>(&refused)) == S_OK && refused,
1136 "force feedback: GameInput accepts an effect SDL will refuse");
1137 if (refused) {
1138 rt::gameinput::poll();
1139 rt::gameinput::OutputState refused_out{};
1140 check(rt::gameinput::output_state(0, &refused_out) && refused_out.effect_id < 0 && !refused_out.effect_ran &&
1141 std::strstr(refused_out.effect_error, "fake: refused"),
1142 "force feedback: SDL refusing the effect is recorded with its error");
1143 refused->Release();
1144 rt::gameinput::poll(); // the released effect leaves the device
1145 }
1146 g_fake.create_result = 1;
1147
1124 params.data.constant.magnitude.linearX = -1.0f; 1148 params.data.constant.magnitude.linearX = -1.0f;
1125 check(effect->SetParams(&params), "force feedback: SetParams"); 1149 check(effect->SetParams(&params), "force feedback: SetParams");
1126 rt::gameinput::poll(); 1150 rt::gameinput::poll();