Skip to content

Commit

Permalink
tests: usb: desc_sections: Check EP assignment order
Browse files Browse the repository at this point in the history
Check that endpoints are assigned in the right order.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information
finikorg authored and nashif committed May 6, 2019
1 parent c840383 commit 4626a8c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/subsys/usb/desc_sections/src/desc_sections.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -138,14 +138,20 @@ static struct usb_cfg_data *usb_get_cfg_data(struct usb_if_descriptor *iface)
} }


static bool find_cfg_data_ep(const struct usb_ep_descriptor * const ep_descr, static bool find_cfg_data_ep(const struct usb_ep_descriptor * const ep_descr,
const struct usb_cfg_data * const cfg_data) const struct usb_cfg_data * const cfg_data,
u8_t ep_count)
{ {
for (int i = 0; i < cfg_data->num_endpoints; i++) { for (int i = 0; i < cfg_data->num_endpoints; i++) {
if (cfg_data->endpoint[i].ep_addr == if (cfg_data->endpoint[i].ep_addr ==
ep_descr->bEndpointAddress) { ep_descr->bEndpointAddress) {
LOG_DBG("found ep[%d] %x", i, LOG_DBG("found ep[%d] %x", i,
ep_descr->bEndpointAddress); ep_descr->bEndpointAddress);


if (ep_count != i) {
LOG_ERR("EPs are assigned in wrong order");
return false;
}

return true; return true;
} }
} }
Expand All @@ -157,11 +163,14 @@ static void check_endpoint_allocation(struct usb_desc_header *head)
{ {
struct usb_cfg_data *cfg_data = NULL; struct usb_cfg_data *cfg_data = NULL;
static u8_t interfaces; static u8_t interfaces;
u8_t ep_count = 0;


while (head->bLength != 0) { while (head->bLength != 0) {
if (head->bDescriptorType == USB_INTERFACE_DESC) { if (head->bDescriptorType == USB_INTERFACE_DESC) {
struct usb_if_descriptor *if_descr = (void *)head; struct usb_if_descriptor *if_descr = (void *)head;


ep_count = 0;

LOG_DBG("iface %u", if_descr->bInterfaceNumber); LOG_DBG("iface %u", if_descr->bInterfaceNumber);


/* Check that interfaces get correct numbers */ /* Check that interfaces get correct numbers */
Expand All @@ -179,7 +188,8 @@ static void check_endpoint_allocation(struct usb_desc_header *head)
/* Check that we get iface desc before */ /* Check that we get iface desc before */
zassert_not_null(cfg_data, "Check available cfg data"); zassert_not_null(cfg_data, "Check available cfg data");


zassert_true(find_cfg_data_ep(ep_descr, cfg_data), zassert_true(find_cfg_data_ep(ep_descr, cfg_data,
ep_count++),
"Check endpoint config in cfg_data"); "Check endpoint config in cfg_data");
} }


Expand Down

0 comments on commit 4626a8c

Please sign in to comment.