summaryrefslogtreecommitdiff
path: root/test/fuzz/dcd_fuzz.cc
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2026-06-22 21:30:58 +0200
committerHiFiPhile <[email protected]>2026-06-22 21:30:58 +0200
commit693cdce08e14833f26f4e8a1f26e4fd546be4c35 (patch)
tree7667d2223dc32d9f21b5b60ab200e64ed46e3e20 /test/fuzz/dcd_fuzz.cc
parent41e9eaa65a935136085d78ec4b99c81ff991b560 (diff)
parentcd3561bf158afd5a5718904b8139a338d1e3b67c (diff)
Merge remote-tracking branch 'tinyusb/master' into pr-osal-spin-deinit
Signed-off-by: HiFiPhile <[email protected]>
Diffstat (limited to 'test/fuzz/dcd_fuzz.cc')
-rw-r--r--test/fuzz/dcd_fuzz.cc29
1 files changed, 19 insertions, 10 deletions
diff --git a/test/fuzz/dcd_fuzz.cc b/test/fuzz/dcd_fuzz.cc
index 046a90555..3e73f0acf 100644
--- a/test/fuzz/dcd_fuzz.cc
+++ b/test/fuzz/dcd_fuzz.cc
@@ -61,14 +61,22 @@ void dcd_int_handler(uint8_t rhport) {
// Choose if we want to generate a signal based on the fuzzed data.
if (_fuzz_data_provider->ConsumeBool()) {
- dcd_event_bus_signal(
- rhport,
- // Choose a random event based on the fuzz data.
- (dcd_eventid_t)_fuzz_data_provider->ConsumeIntegralInRange<uint8_t>(
- DCD_EVENT_INVALID + 1, DCD_EVENT_COUNT - 1),
- // Identify trigger as either an interrupt or a syncrhonous call
- // depending on fuzz data.
- _fuzz_data_provider->ConsumeBool());
+ // Only generate bus signal events that don't carry additional union data.
+ // DCD_EVENT_XFER_COMPLETE, DCD_EVENT_SOF, and DCD_EVENT_BUS_RESET need
+ // properly initialized union fields; USBD_EVENT_FUNC_CALL is internal only.
+ // Valid bus-signal-only events: UNPLUGGED(2), SUSPEND(4), RESUME(5).
+ static const dcd_eventid_t bus_signal_events[] = {
+ DCD_EVENT_UNPLUGGED, DCD_EVENT_SUSPEND, DCD_EVENT_RESUME};
+ uint8_t idx = _fuzz_data_provider->ConsumeIntegralInRange<uint8_t>(0, 2);
+ dcd_event_bus_signal(rhport, bus_signal_events[idx],
+ _fuzz_data_provider->ConsumeBool());
+ }
+
+ // Optionally generate a BUS_RESET event with a valid speed value.
+ if (_fuzz_data_provider->ConsumeBool()) {
+ tusb_speed_t speed = (tusb_speed_t)_fuzz_data_provider->ConsumeIntegralInRange<uint8_t>(
+ TUSB_SPEED_FULL, TUSB_SPEED_HIGH);
+ dcd_event_bus_reset(rhport, speed, _fuzz_data_provider->ConsumeBool());
}
if (_fuzz_data_provider->ConsumeBool()) {
@@ -104,7 +112,7 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr) {
UNUSED(rhport);
state.address = dev_addr;
// Respond with status.
- dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
+ dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0, false);
return;
}
@@ -160,10 +168,11 @@ void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr) {
// Submit a transfer, When complete dcd_event_xfer_complete() is invoked to
// notify the stack
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer,
- uint16_t total_bytes) {
+ uint16_t total_bytes, bool is_isr) {
UNUSED(rhport);
UNUSED(buffer);
UNUSED(total_bytes);
+ UNUSED(is_isr);
uint8_t const dir = tu_edpt_dir(ep_addr);