Skip to content

Commit

Permalink
tests: drivers: udc: Fixed behavior on devices that has 16 endpoints
Browse files Browse the repository at this point in the history
In the current test,

```
 #define FALSE_EP_ADDR 0x0FU
```

is to check non-existent EP, but if there are 16 EPs,
i.e., the USB standard is fully implemented,
this becomes a valid EP.

In that case, the test item that checks the operation of
 a non-existent EP will fail.

Even if this value is set to a larger value, the EP value is rounded
by the following macro, so it cannot point to a non-existent EP.

```
 #define USB_EP_LUT_IDX(ep) (USB_EP_DIR_IS_IN(ep) ? (ep & BIT_MASK(4)) + 16 : \
                                                    ep & BIT_MASK(4))
```

Essentially, I think it would be more appropriate to implement
`udc_get_ep_cfg()` to return NULL when a non-existent EP is specified,
but a major design change is required.

Here, I will refer to the value in the device tree to find the number of EPs,
and if 16 or more EPs are available, we will change it so that the test for
non-existent EPs is not performed.

Signed-off-by: TOKITA Hiroshi <[email protected]>
  • Loading branch information
soburi committed Feb 2, 2025
1 parent 3142c51 commit b4cf0e2
Showing 1 changed file with 43 additions and 14 deletions.
57 changes: 43 additions & 14 deletions tests/drivers/udc/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LOG_MODULE_REGISTER(udc_test, LOG_LEVEL_INF);
*/

#define FALSE_EP_ADDR 0x0FU
#define FALSE_EP_EXISTS (DT_PROP(DT_NODELABEL(zephyr_udc0), num_bidir_endpoints) < FALSE_EP_ADDR)

K_MSGQ_DEFINE(test_msgq, sizeof(struct udc_event), 8, sizeof(uint32_t));
static K_KERNEL_STACK_DEFINE(test_udc_stack, 512);
Expand Down Expand Up @@ -145,17 +146,23 @@ static void test_udc_ep_enable(const struct device *dev,
if (!udc_is_initialized(dev) && !udc_is_enabled(dev)) {
zassert_equal(err1, -EPERM, "Not failed to enable endpoint");
zassert_equal(err2, -EPERM, "Not failed to enable endpoint");
zassert_equal(err3, -EPERM, "Not failed to enable endpoint");
if (FALSE_EP_EXISTS) {
zassert_equal(err3, -EPERM, "Not failed to enable endpoint");
}
zassert_equal(err4, -EINVAL, "Not failed to enable endpoint");
} else if (udc_is_initialized(dev) && !udc_is_enabled(dev)) {
zassert_equal(err1, -EPERM, "Not failed to enable endpoint");
zassert_equal(err2, -EPERM, "Not failed to enable endpoint");
zassert_equal(err3, -EPERM, "Not failed to enable endpoint");
if (FALSE_EP_EXISTS) {
zassert_equal(err3, -EPERM, "Not failed to enable endpoint");
}
zassert_equal(err4, -EINVAL, "Not failed to enable endpoint");
} else {
zassert_equal(err1, 0, "Failed to enable endpoint");
zassert_equal(err2, -EALREADY, "Not failed to enable endpoint");
zassert_equal(err3, -ENODEV, "Not failed to enable endpoint");
if (FALSE_EP_EXISTS) {
zassert_equal(err3, -ENODEV, "Not failed to enable endpoint");
}
zassert_equal(err4, -EINVAL, "Not failed to enable endpoint");
}
}
Expand All @@ -176,17 +183,23 @@ static void test_udc_ep_disable(const struct device *dev,
if (!udc_is_initialized(dev) && !udc_is_enabled(dev)) {
zassert_equal(err1, -EPERM, "Not failed to disable endpoint");
zassert_equal(err2, -EPERM, "Not failed to disable endpoint");
zassert_equal(err3, -EPERM, "Not failed to disable endpoint");
if (FALSE_EP_EXISTS) {
zassert_equal(err3, -EPERM, "Not failed to disable endpoint");
}
zassert_equal(err4, -EINVAL, "Not failed to disable endpoint");
} else if (udc_is_initialized(dev) && !udc_is_enabled(dev)) {
zassert_equal(err1, -EALREADY, "Failed to disable endpoint");
zassert_equal(err2, -EALREADY, "Not failed to disable endpoint");
zassert_equal(err3, -ENODEV, "Not failed to disable endpoint");
if (FALSE_EP_EXISTS) {
zassert_equal(err3, -ENODEV, "Not failed to disable endpoint");
}
zassert_equal(err4, -EINVAL, "Not failed to disable endpoint");
} else {
zassert_equal(err1, 0, "Failed to disable endpoint");
zassert_equal(err2, -EALREADY, "Not failed to disable endpoint");
zassert_equal(err3, -ENODEV, "Not failed to disable endpoint");
if (FALSE_EP_EXISTS) {
zassert_equal(err3, -ENODEV, "Not failed to disable endpoint");
}
zassert_equal(err4, -EINVAL, "Not failed to disable endpoint");
}
}
Expand Down Expand Up @@ -233,10 +246,14 @@ static void test_udc_ep_halt(const struct device *dev,
zassert_equal(err1, 0, "Failed to set halt");
}

zassert_equal(err2, -ENODEV, "Not failed to set halt");
if (FALSE_EP_EXISTS) {
zassert_equal(err2, -ENODEV, "Not failed to set halt");
}
} else {
zassert_equal(err1, -EPERM, "Not failed to set halt");
zassert_equal(err2, -EPERM, "Not failed to set halt");
if (FALSE_EP_EXISTS) {
zassert_equal(err2, -EPERM, "Not failed to set halt");
}
}

err1 = udc_ep_clear_halt(dev, ed->bEndpointAddress);
Expand All @@ -249,10 +266,14 @@ static void test_udc_ep_halt(const struct device *dev,
zassert_equal(err1, 0, "Failed to clear halt ");
}

zassert_equal(err2, -ENODEV, "Not failed to clear halt");
if (FALSE_EP_EXISTS) {
zassert_equal(err2, -ENODEV, "Not failed to clear halt");
}
} else {
zassert_equal(err1, -EPERM, "Not failed to clear halt");
zassert_equal(err2, -EPERM, "Not failed to clear halt");
if (FALSE_EP_EXISTS) {
zassert_equal(err2, -EPERM, "Not failed to clear halt");
}
}
}

Expand All @@ -267,12 +288,16 @@ static void test_udc_ep_enqueue(const struct device *dev,
if (udc_is_enabled(dev)) {
false_buf = udc_ep_buf_alloc(dev, FALSE_EP_ADDR, 64);
zassert_not_null(false_buf, "Failed to allocate request");
err2 = udc_ep_enqueue(dev, false_buf);
if (FALSE_EP_EXISTS) {
err2 = udc_ep_enqueue(dev, false_buf);
}
}

if (udc_is_enabled(dev)) {
zassert_equal(err1, 0, "Failed to queue request");
zassert_equal(err2, -ENODEV, "Not failed to queue request");
if (FALSE_EP_EXISTS) {
zassert_equal(err2, -ENODEV, "Not failed to queue request");
}
} else {
zassert_equal(err1, -EPERM, "Not failed to queue request");
}
Expand All @@ -291,10 +316,14 @@ static void test_udc_ep_dequeue(const struct device *dev,

if (!udc_is_initialized(dev)) {
zassert_equal(err1, -EPERM, "Not failed to dequeue");
zassert_equal(err2, -EPERM, "Not failed to dequeue");
if (FALSE_EP_EXISTS) {
zassert_equal(err2, -EPERM, "Not failed to dequeue");
}
} else {
zassert_equal(err1, 0, "Failed to dequeue");
zassert_equal(err2, -ENODEV, "Not failed to dequeue");
if (FALSE_EP_EXISTS) {
zassert_equal(err2, -ENODEV, "Not failed to dequeue");
}
}
}

Expand Down

0 comments on commit b4cf0e2

Please sign in to comment.