@@ -20,6 +20,7 @@ extern "C" {
2020#include " jitter_test.h"
2121#include " usb_state.h"
2222#include " utils.h"
23+ #include " test_suite/test_hooks.h"
2324}
2425#include " command_app.hpp"
2526#include " controls_app.hpp"
@@ -36,6 +37,7 @@ typedef enum {
3637 ReportSink_Usb,
3738 ReportSink_BleHid,
3839 ReportSink_Dongle,
40+ ReportSink_TestSuite,
3941} report_sink_t ;
4042
4143// Exponential moving average (alpha=1/8) of the measured delay between a
@@ -53,6 +55,8 @@ static uint32_t dispatchTimeMs = 0;
5355// callback then reduces the estimate to "now + interval".
5456static constexpr uint32_t USB_REPORT_INTERVAL_MS = 1 ;
5557
58+ bool UnreliableTransportTestMode = false ;
59+
5660static uint32_t reportIntervalForSink (report_sink_t sink)
5761{
5862 switch (sink) {
@@ -66,7 +70,7 @@ static uint32_t reportIntervalForSink(report_sink_t sink)
6670 return 11 ;
6771#endif
6872 default :
69- return 0 ;
73+ return 1 ;
7074 }
7175}
7276
@@ -109,9 +113,14 @@ extern "C" void HidTransport_NoteNusReportSent(void)
109113
110114static report_sink_t determineSink ()
111115{
116+ if (TestHooks_Active) {
117+ return ReportSink_TestSuite;
118+ }
119+
112120#if DEVICE_IS_UHK_DONGLE || DEVICE_IS_UHK60
113121 return ReportSink_Usb;
114122#else
123+
115124 connection_type_t connectionType = Connections_Type (ActiveHostConnectionId);
116125
117126 if (!Connections_IsReady (ActiveHostConnectionId)) {
@@ -174,8 +183,8 @@ extern "C" errno_t Hid_SendKeyboardReport(const hid_keyboard_report_t *report)
174183 noteReportDispatched (sink);
175184 Trace_Printf (" z11,%d" , sink);
176185 errno_t err;
177- if (DEBUG_STRESS_REPORTS && Utils_Random () % 16 == 0 ) {
178- return 1 ;
186+ if (UnreliableTransportTestMode && Utils_Random () % 7 == 0 ) {
187+ return - EAGAIN ;
179188 }
180189 switch (sink) {
181190 case ReportSink_Usb:
@@ -196,6 +205,11 @@ extern "C" errno_t Hid_SendKeyboardReport(const hid_keyboard_report_t *report)
196205 }
197206 break ;
198207#endif
208+ case ReportSink_TestSuite:
209+ err = 0 ;
210+ TestHooks_CaptureReport (report);
211+ Hid_KeyboardReportSentCallback (HID_TRANSPORT_USB );
212+ break ;
199213 default :
200214#ifdef __ZEPHYR__
201215 printk (" Unhandled and unexpected switch state!\n " );
@@ -209,8 +223,7 @@ extern "C" errno_t Hid_SendKeyboardReport(const hid_keyboard_report_t *report)
209223
210224extern " C" void Hid_KeyboardReportSentCallback (hid_transport_t transport)
211225{
212- if (DEBUG_STRESS_REPORTS && Utils_Random () % 16 == 0 ) {
213- // 666
226+ if (UnreliableTransportTestMode && Utils_Random () % 7 == 0 ) {
214227 return ;
215228 }
216229 UsbReportUpdater_ConfirmKeyboardReportSent ();
0 commit comments