Skip to content

Commit 253b0e1

Browse files
committed
Merge branch 'feature/usb_host_hcd_binterval_test_case' into 'master'
feature(hcd): Added test cases to verify intr pipe allocation with all possible bInterval See merge request espressif/esp-idf!37482
2 parents a33d709 + 168aa0d commit 253b0e1

File tree

1 file changed

+100
-2
lines changed

1 file changed

+100
-2
lines changed

components/usb/test_apps/hcd/main/test_hcd_intr.c

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -83,6 +83,104 @@ TEST_CASE("Test HCD interrupt pipe URBs", "[intr][low_speed]")
8383
}
8484
test_hcd_pipe_free(intr_pipe);
8585
test_hcd_pipe_free(default_pipe);
86-
// Clearnup
86+
// Cleanup
87+
test_hcd_wait_for_disconn(port_hdl, false);
88+
}
89+
90+
/*
91+
Test HCD interrupt pipe allocation, when bInterval = 0
92+
Purpose:
93+
- Test that an interrupt pipe cause no panic
94+
95+
Procedure:
96+
- Setup HCD and wait for connection
97+
- Allocate interrupt pipe with bInterval = 0
98+
- Expect ESP_ERR_NOT_SUPPORTED
99+
- Cleanup
100+
*Note: for all speeds (LS, FS, HS)
101+
*/
102+
TEST_CASE("Test HCD interrupt pipe alloc: bInterval=0", "[intr][low_speed][full_speed][high_speed]")
103+
{
104+
// Trigger a connection
105+
test_hcd_wait_for_conn(port_hdl);
106+
// The device speed not needed, we need just the connection to unlock pipe allocation
107+
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
108+
109+
usb_ep_desc_t test_ep_intr_desc = {
110+
.bLength = USB_EP_DESC_SIZE,
111+
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
112+
.bEndpointAddress = 0x81, // IN endpoint
113+
.bmAttributes = USB_BM_ATTRIBUTES_XFER_INT,
114+
.wMaxPacketSize = 8,
115+
.bInterval = 0, // bInterval = 0
116+
};
117+
118+
hcd_pipe_config_t pipe_config = {
119+
.callback = NULL, // No callback
120+
.callback_arg = NULL, // No callback argument
121+
.context = NULL, // No context
122+
.ep_desc = &test_ep_intr_desc, // IN endpoint descriptor
123+
.dev_addr = 1, // Any device address
124+
};
125+
126+
for (usb_speed_t test_speed = USB_SPEED_LOW; test_speed <= USB_SPEED_HIGH; test_speed++) {
127+
// Create an interrupt pipe (using a EP descriptor)
128+
hcd_pipe_handle_t pipe_hdl = NULL;
129+
pipe_config.dev_speed = test_speed;
130+
TEST_ASSERT_EQUAL_MESSAGE(ESP_ERR_NOT_SUPPORTED, hcd_pipe_alloc(port_hdl, &pipe_config, &pipe_hdl), "Create pipe with bInterval=0 should fail");
131+
TEST_ASSERT_NULL_MESSAGE(pipe_hdl, "Pipe handle should be NULL");
132+
}
133+
// Cleanup
134+
test_hcd_wait_for_disconn(port_hdl, false);
135+
}
136+
137+
/*
138+
Test HCD interrupt pipe allocation, when bInterval in the interval [0x01..0xFF]
139+
Purpose:
140+
- Test that an interrupt pipe can be created with bInterval in the interval [0x01..0xFF]
141+
- Test that an interrupt pipe creation cause no panic with any bInterval
142+
143+
Procedure:
144+
- Setup HCD and wait for connection
145+
- Allocate interrupt pipe with bInterval in the interval [0x01..0xFF]
146+
- Expect ESP_OK
147+
- Cleanup
148+
*Note: for all speeds (LS, FS, HS)
149+
*/
150+
TEST_CASE("Test HCD interrupt pipe alloc: bInterval [0x1..0xff]", "[intr][low_speed][full_speed][high_speed]")
151+
{
152+
// Trigger a connection
153+
test_hcd_wait_for_conn(port_hdl);
154+
// The device speed not needed, we need just the connection to unlock pipe allocation
155+
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
156+
157+
for (int test_bInterval = 1; test_bInterval <= 0xFF; test_bInterval++) {
158+
usb_ep_desc_t test_ep_intr_desc = {
159+
.bLength = USB_EP_DESC_SIZE,
160+
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
161+
.bEndpointAddress = 0x81, // IN endpoint
162+
.bmAttributes = USB_BM_ATTRIBUTES_XFER_INT,
163+
.wMaxPacketSize = 8,
164+
.bInterval = test_bInterval,
165+
};
166+
167+
hcd_pipe_config_t pipe_config = {
168+
.callback = NULL, // No callback
169+
.callback_arg = NULL, // No callback argument
170+
.context = NULL, // No context
171+
.ep_desc = &test_ep_intr_desc, // IN endpoint descriptor
172+
.dev_addr = 1, // Any device address
173+
};
174+
175+
for (usb_speed_t test_speed = USB_SPEED_LOW; test_speed <= USB_SPEED_HIGH; test_speed++) {
176+
// Create an interrupt pipe (using a EP descriptor)
177+
hcd_pipe_handle_t pipe_hdl = NULL;
178+
pipe_config.dev_speed = test_speed;
179+
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, hcd_pipe_alloc(port_hdl, &pipe_config, &pipe_hdl), "Create pipe should not fail");
180+
TEST_ASSERT_NOT_NULL_MESSAGE(pipe_hdl, "Pipe handle should not be NULL");
181+
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_free(pipe_hdl));
182+
}
183+
}
184+
// Cleanup
87185
test_hcd_wait_for_disconn(port_hdl, false);
88186
}

0 commit comments

Comments
 (0)