summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-10-30 16:19:47 +0700
committerhathach <[email protected]>2019-10-30 16:19:47 +0700
commit8f2e70756b582f75d47257c8f116449babb5059d (patch)
tree31ba2de59dc94d7a1f14cc8df23a5b1f85b190b9
parent16665672a45c4f85cb2e1a47873825f2b48fcf1a (diff)
added firs usbd test with get device descriptor
-rw-r--r--test/project.yml1
-rw-r--r--test/test/test_usbd/test_usbd.c (renamed from test/test/test_usbd.c)61
2 files changed, 58 insertions, 4 deletions
diff --git a/test/project.yml b/test/project.yml
index cf29c3b04..8ceaf63ce 100644
--- a/test/project.yml
+++ b/test/project.yml
@@ -54,6 +54,7 @@
:plugins:
- :ignore
- :callback
+ - :array
:treat_as:
uint8: HEX8
uint16: HEX16
diff --git a/test/test/test_usbd.c b/test/test/test_usbd/test_usbd.c
index 8c29ee853..fe8adf5d8 100644
--- a/test/test/test_usbd.c
+++ b/test/test/test_usbd/test_usbd.c
@@ -29,6 +29,7 @@
#include "tusb.h"
#include "usbd.h"
TEST_FILE("usbd_control.c")
+//TEST_FILE("usb_descriptors.c")
// Mock File
#include "mock_dcd.h"
@@ -37,13 +38,41 @@ TEST_FILE("usbd_control.c")
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
+uint8_t const rhport = 0;
+
+tusb_desc_device_t const desc_device =
+{
+ .bLength = sizeof(tusb_desc_device_t),
+ .bDescriptorType = TUSB_DESC_DEVICE,
+ .bcdUSB = 0x0200,
+
+ // Use Interface Association Descriptor (IAD) for CDC
+ // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
+ .bDeviceClass = TUSB_CLASS_MISC,
+ .bDeviceSubClass = MISC_SUBCLASS_COMMON,
+ .bDeviceProtocol = MISC_PROTOCOL_IAD,
+
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+
+ .idVendor = 0xCafe,
+ .idProduct = 0xCafe,
+ .bcdDevice = 0x0100,
+
+ .iManufacturer = 0x01,
+ .iProduct = 0x02,
+ .iSerialNumber = 0x03,
+
+ .bNumConfigurations = 0x01
+};
+
uint8_t const * tud_descriptor_device_cb(void)
{
- return NULL;
+ return (uint8_t const *) &desc_device;
}
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
{
+ TEST_FAIL();
return NULL;
}
@@ -52,17 +81,41 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index)
return NULL;
}
-//------------- IMPLEMENTATION -------------//
void setUp(void)
{
-
+ dcd_init_Expect(rhport);
+ dcd_int_enable_Expect(rhport);
+ tusb_init();
}
void tearDown(void)
{
}
-void test_ok(void)
+//--------------------------------------------------------------------+
+//
+//--------------------------------------------------------------------+
+void test_usbd_get_device_descriptor(void)
{
+ tusb_control_request_t request =
+ {
+ .bmRequestType = 0x80,
+ .bRequest = TUSB_REQ_GET_DESCRIPTOR,
+ .wValue = (TUSB_DESC_DEVICE << 8),
+ .wIndex = 0x0000,
+ .wLength = 64
+ };
+
+ dcd_int_disable_Expect(rhport);
+ dcd_int_enable_Expect(rhport);
+ dcd_event_setup_received(rhport, (uint8_t*) &request, false);
+
+ dcd_int_disable_Expect(rhport);
+ dcd_int_enable_Expect(rhport);
+
+ dcd_edpt_xfer_ExpectWithArrayAndReturn(rhport, 0x80, (uint8_t*)&desc_device, sizeof(tusb_desc_device_t), sizeof(tusb_desc_device_t), true);
+ dcd_int_disable_Expect(rhport);
+ dcd_int_enable_Expect(rhport);
+ tud_task();
}