diff options
| author | nxf58843 <[email protected]> | 2021-08-23 09:55:04 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-23 09:55:04 -0700 |
| commit | fb16e80e575a44828f5367f4fb7380162b0354f0 (patch) | |
| tree | bb965cc935083d99e083667d4f0f1533d50a29f5 /test | |
| parent | 616562a48aa1d8ce2f4ca71f6e780a8bec9fb5eb (diff) | |
| parent | ea902493db49843dcdeca6bfa2b2efe540f44b2f (diff) | |
Merge pull request #2 from hathach/master
Pulling latest from source
Diffstat (limited to 'test')
| -rw-r--r-- | test/test/device/msc/test_msc_device.c | 14 | ||||
| -rw-r--r-- | test/test/device/usbd/test_usbd.c | 22 | ||||
| -rw-r--r-- | test/test/support/tusb_config.h | 14 | ||||
| -rw-r--r-- | test/test/test_fifo.c | 261 |
4 files changed, 271 insertions, 40 deletions
diff --git a/test/test/device/msc/test_msc_device.c b/test/test/device/msc/test_msc_device.c index 5003ac839..00bb86ccf 100644 --- a/test/test/device/msc/test_msc_device.c +++ b/test/test/device/msc/test_msc_device.c @@ -62,11 +62,11 @@ enum uint8_t const data_desc_configuration[] = { - // Interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), + // Config number, interface count, string index, total length, attribute, power in mA + TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), // Interface number, string index, EP Out & EP In address, EP size - TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 0, EDPT_MSC_OUT, EDPT_MSC_IN, (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED) ? 512 : 64), + TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 0, EDPT_MSC_OUT, EDPT_MSC_IN, TUD_OPT_HIGH_SPEED ? 512 : 64), }; tusb_control_request_t const request_set_configuration = @@ -184,8 +184,10 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index) return desc_configuration; } -uint16_t const* tud_descriptor_string_cb(uint8_t index) +uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) { + (void) langid; + return NULL; } @@ -200,7 +202,7 @@ void setUp(void) tusb_init(); } - dcd_event_bus_signal(rhport, DCD_EVENT_BUS_RESET, false); + dcd_event_bus_reset(rhport, TUSB_SPEED_HIGH, false); tud_task(); } @@ -238,8 +240,6 @@ void test_msc(void) dcd_event_setup_received(rhport, (uint8_t*) &request_set_configuration, false); - dcd_set_config_Expect(rhport, 1); - // open endpoints dcd_edpt_open_ExpectAndReturn(rhport, (tusb_desc_endpoint_t const *) desc_ep, true); dcd_edpt_open_ExpectAndReturn(rhport, (tusb_desc_endpoint_t const *) tu_desc_next(desc_ep), true); diff --git a/test/test/device/usbd/test_usbd.c b/test/test/device/usbd/test_usbd.c index 245353106..c90383b57 100644 --- a/test/test/device/usbd/test_usbd.c +++ b/test/test/device/usbd/test_usbd.c @@ -73,8 +73,8 @@ tusb_desc_device_t const data_desc_device = uint8_t const data_desc_configuration[] = { - // Interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(0, 0, TUD_CONFIG_DESC_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), + // Config number, interface count, string index, total length, attribute, power in mA + TUD_CONFIG_DESCRIPTOR(1, 0, 0, TUD_CONFIG_DESC_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), }; tusb_control_request_t const req_get_desc_device = @@ -111,8 +111,10 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index) return desc_configuration; } -uint16_t const* tud_descriptor_string_cb(uint8_t index) +uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) { + (void) langid; + return NULL; } @@ -207,10 +209,10 @@ void test_usbd_control_in_zlp(void) { // 128 byte total len, with EP0 size = 64, and request length = 256 // ZLP must be return - uint8_t zlp_desc_configuration[CFG_TUD_ENDOINT0_SIZE*2] = + uint8_t zlp_desc_configuration[CFG_TUD_ENDPOINT0_SIZE*2] = { - // Interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(0, 0, CFG_TUD_ENDOINT0_SIZE*2, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), + // Config number, interface count, string index, total length, attribute, power in mA + TUD_CONFIG_DESCRIPTOR(1, 0, 0, CFG_TUD_ENDPOINT0_SIZE*2, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), }; desc_configuration = zlp_desc_configuration; @@ -220,13 +222,13 @@ void test_usbd_control_in_zlp(void) // 1st transaction dcd_edpt_xfer_ExpectWithArrayAndReturn(rhport, EDPT_CTRL_IN, - zlp_desc_configuration, CFG_TUD_ENDOINT0_SIZE, CFG_TUD_ENDOINT0_SIZE, true); - dcd_event_xfer_complete(rhport, EDPT_CTRL_IN, CFG_TUD_ENDOINT0_SIZE, 0, false); + zlp_desc_configuration, CFG_TUD_ENDPOINT0_SIZE, CFG_TUD_ENDPOINT0_SIZE, true); + dcd_event_xfer_complete(rhport, EDPT_CTRL_IN, CFG_TUD_ENDPOINT0_SIZE, 0, false); // 2nd transaction dcd_edpt_xfer_ExpectWithArrayAndReturn(rhport, EDPT_CTRL_IN, - zlp_desc_configuration + CFG_TUD_ENDOINT0_SIZE, CFG_TUD_ENDOINT0_SIZE, CFG_TUD_ENDOINT0_SIZE, true); - dcd_event_xfer_complete(rhport, EDPT_CTRL_IN, CFG_TUD_ENDOINT0_SIZE, 0, false); + zlp_desc_configuration + CFG_TUD_ENDPOINT0_SIZE, CFG_TUD_ENDPOINT0_SIZE, CFG_TUD_ENDPOINT0_SIZE, true); + dcd_event_xfer_complete(rhport, EDPT_CTRL_IN, CFG_TUD_ENDPOINT0_SIZE, 0, false); // Expect Zero length Packet dcd_edpt_xfer_ExpectAndReturn(rhport, EDPT_CTRL_IN, NULL, 0, true); diff --git a/test/test/support/tusb_config.h b/test/test/support/tusb_config.h index 5e7b70e0d..0455f933b 100644 --- a/test/test/support/tusb_config.h +++ b/test/test/support/tusb_config.h @@ -43,16 +43,16 @@ #define CFG_TUSB_MCU OPT_MCU_NRF5X #endif -#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX +#ifndef CFG_TUSB_RHPORT0_MODE #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED) -#else -#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE #endif #define CFG_TUSB_OS OPT_OS_NONE // CFG_TUSB_DEBUG is defined by compiler in DEBUG build +#ifndef CFG_TUSB_DEBUG #define CFG_TUSB_DEBUG 0 +#endif /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put @@ -74,7 +74,7 @@ //-------------------------------------------------------------------- #define CFG_TUD_TASK_QUEUE_SZ 100 -#define CFG_TUD_ENDOINT0_SIZE 64 +#define CFG_TUD_ENDPOINT0_SIZE 64 //------------- CLASS -------------// //#define CFG_TUD_CDC 0 @@ -86,8 +86,8 @@ //------------- CDC -------------// // FIFO size of CDC TX and RX -#define CFG_TUD_CDC_RX_BUFSIZE 64 -#define CFG_TUD_CDC_TX_BUFSIZE 64 +#define CFG_TUD_CDC_RX_BUFSIZE 512 +#define CFG_TUD_CDC_TX_BUFSIZE 512 //------------- MSC -------------// @@ -97,7 +97,7 @@ //------------- HID -------------// // Should be sufficient to hold ID (if any) + Data -#define CFG_TUD_HID_BUFSIZE 16 +#define CFG_TUD_HID_EP_BUFSIZE 64 #ifdef __cplusplus } diff --git a/test/test/test_fifo.c b/test/test/test_fifo.c index 2cb8ada91..0a5f4d3b9 100644 --- a/test/test/test_fifo.c +++ b/test/test/test_fifo.c @@ -24,15 +24,19 @@ * This file is part of the TinyUSB stack. */ +#include <string.h> #include "unity.h" #include "tusb_fifo.h" #define FIFO_SIZE 10 -TU_FIFO_DEF(ff, FIFO_SIZE, uint8_t, false); +TU_FIFO_DEF(tu_ff, FIFO_SIZE, uint8_t, false); +tu_fifo_t* ff = &tu_ff; +tu_fifo_buffer_info_t info; void setUp(void) { - tu_fifo_clear(&ff); + tu_fifo_clear(ff); + memset(&info, 0, sizeof(tu_fifo_buffer_info_t)); } void tearDown(void) @@ -44,46 +48,271 @@ void tearDown(void) //--------------------------------------------------------------------+ void test_normal(void) { - for(uint8_t i=0; i < FIFO_SIZE; i++) tu_fifo_write(&ff, &i); + for(uint8_t i=0; i < FIFO_SIZE; i++) tu_fifo_write(ff, &i); for(uint8_t i=0; i < FIFO_SIZE; i++) { uint8_t c; - tu_fifo_read(&ff, &c); + tu_fifo_read(ff, &c); TEST_ASSERT_EQUAL(i, c); } } +void test_item_size(void) +{ + TU_FIFO_DEF(ff4, FIFO_SIZE, uint32_t, false); + tu_fifo_clear(&ff4); + + uint32_t data[20]; + for(uint32_t i=0; i<sizeof(data)/4; i++) data[i] = i; + + tu_fifo_write_n(&ff4, data, 10); + + uint32_t rd[10]; + uint16_t rd_count; + + // read 0 -> 4 + rd_count = tu_fifo_read_n(&ff4, rd, 5); + TEST_ASSERT_EQUAL( 5, rd_count ); + TEST_ASSERT_EQUAL_UINT32_ARRAY( data, rd, rd_count ); // 0 -> 4 + + tu_fifo_write_n(&ff4, data+10, 5); + + // read 5 -> 14 + rd_count = tu_fifo_read_n(&ff4, rd, 10); + TEST_ASSERT_EQUAL( 10, rd_count ); + TEST_ASSERT_EQUAL_UINT32_ARRAY( data+5, rd, rd_count ); // 5 -> 14 +} + +void test_read_n(void) +{ + // prepare data + uint8_t data[20]; + for(int i=0; i<sizeof(data); i++) data[i] = i; + + for(uint8_t i=0; i < FIFO_SIZE; i++) tu_fifo_write(ff, data+i); + + uint8_t rd[10]; + uint16_t rd_count; + + // case 1: Read index + count < depth + // read 0 -> 4 + rd_count = tu_fifo_read_n(ff, rd, 5); + TEST_ASSERT_EQUAL( 5, rd_count ); + TEST_ASSERT_EQUAL_MEMORY( data, rd, rd_count ); // 0 -> 4 + + // case 2: Read index + count > depth + // write 10, 11, 12 + tu_fifo_write(ff, data+10); + tu_fifo_write(ff, data+11); + tu_fifo_write(ff, data+12); + + rd_count = tu_fifo_read_n(ff, rd, 7); + TEST_ASSERT_EQUAL( 7, rd_count ); + + TEST_ASSERT_EQUAL_MEMORY( data+5, rd, rd_count ); // 5 -> 11 + + // Should only read until empty + TEST_ASSERT_EQUAL( 1, tu_fifo_read_n(ff, rd, 100) ); +} + +void test_write_n(void) +{ + // prepare data + uint8_t data[20]; + for(int i=0; i<sizeof(data); i++) data[i] = i; + + // case 1: wr + count < depth + tu_fifo_write_n(ff, data, 8); // wr = 8, count = 8 + + uint8_t rd[10]; + uint16_t rd_count; + + rd_count = tu_fifo_read_n(ff, rd, 5); // wr = 8, count = 3 + TEST_ASSERT_EQUAL( 5, rd_count ); + TEST_ASSERT_EQUAL_MEMORY( data, rd, rd_count ); // 0 -> 4 + + // case 2: wr + count > depth + tu_fifo_write_n(ff, data+8, 6); // wr = 3, count = 9 + + for(rd_count=0; rd_count<7; rd_count++) tu_fifo_read(ff, rd+rd_count); // wr = 3, count = 2 + + TEST_ASSERT_EQUAL_MEMORY( data+5, rd, rd_count); // 5 -> 11 + + TEST_ASSERT_EQUAL(2, tu_fifo_count(ff)); +} + void test_peek(void) { uint8_t temp; - temp = 10; tu_fifo_write(&ff, &temp); - temp = 20; tu_fifo_write(&ff, &temp); - temp = 30; tu_fifo_write(&ff, &temp); + temp = 10; tu_fifo_write(ff, &temp); + temp = 20; tu_fifo_write(ff, &temp); + temp = 30; tu_fifo_write(ff, &temp); temp = 0; - tu_fifo_peek(&ff, &temp); + tu_fifo_peek(ff, &temp); TEST_ASSERT_EQUAL(10, temp); - tu_fifo_peek_at(&ff, 1, &temp); - TEST_ASSERT_EQUAL(20, temp); + tu_fifo_read(ff, &temp); + tu_fifo_read(ff, &temp); + + tu_fifo_peek(ff, &temp); + TEST_ASSERT_EQUAL(30, temp); +} + +void test_get_read_info_when_no_wrap() +{ + uint8_t ch = 1; + + // write 6 items + for(uint8_t i=0; i < 6; i++) tu_fifo_write(ff, &ch); + + // read 2 items + tu_fifo_read(ff, &ch); + tu_fifo_read(ff, &ch); + + tu_fifo_get_read_info(ff, &info); + + TEST_ASSERT_EQUAL(4, info.len_lin); + TEST_ASSERT_EQUAL(0, info.len_wrap); + + TEST_ASSERT_EQUAL_PTR(ff->buffer+2, info.ptr_lin); + TEST_ASSERT_NULL(info.ptr_wrap); +} + +void test_get_read_info_when_wrapped() +{ + uint8_t ch = 1; + + // make fifo full + for(uint8_t i=0; i < FIFO_SIZE; i++) tu_fifo_write(ff, &ch); + + // read 6 items + for(uint8_t i=0; i < 6; i++) tu_fifo_read(ff, &ch); + + // write 2 items + tu_fifo_write(ff, &ch); + tu_fifo_write(ff, &ch); + + tu_fifo_get_read_info(ff, &info); + + TEST_ASSERT_EQUAL(FIFO_SIZE-6, info.len_lin); + TEST_ASSERT_EQUAL(2, info.len_wrap); + + TEST_ASSERT_EQUAL_PTR(ff->buffer+6, info.ptr_lin); + TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_wrap); +} + +void test_get_write_info_when_no_wrap() +{ + uint8_t ch = 1; + + // write 2 items + tu_fifo_write(ff, &ch); + tu_fifo_write(ff, &ch); + + tu_fifo_get_write_info(ff, &info); + + TEST_ASSERT_EQUAL(FIFO_SIZE-2, info.len_lin); + TEST_ASSERT_EQUAL(0, info.len_wrap); + + TEST_ASSERT_EQUAL_PTR(ff->buffer+2, info .ptr_lin); + // application should check len instead of ptr. + // TEST_ASSERT_NULL(info.ptr_wrap); +} + +void test_get_write_info_when_wrapped() +{ + uint8_t ch = 1; + + // write 6 items + for(uint8_t i=0; i < 6; i++) tu_fifo_write(ff, &ch); + + // read 2 items + tu_fifo_read(ff, &ch); + tu_fifo_read(ff, &ch); + + tu_fifo_get_write_info(ff, &info); + + TEST_ASSERT_EQUAL(FIFO_SIZE-6, info.len_lin); + TEST_ASSERT_EQUAL(2, info.len_wrap); + + TEST_ASSERT_EQUAL_PTR(ff->buffer+6, info .ptr_lin); + TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_wrap); } void test_empty(void) { uint8_t temp; - TEST_ASSERT_TRUE(tu_fifo_empty(&ff)); - tu_fifo_write(&ff, &temp); - TEST_ASSERT_FALSE(tu_fifo_empty(&ff)); + TEST_ASSERT_TRUE(tu_fifo_empty(ff)); + + // read info + tu_fifo_get_read_info(ff, &info); + + TEST_ASSERT_EQUAL(0, info.len_lin); + TEST_ASSERT_EQUAL(0, info.len_wrap); + + TEST_ASSERT_NULL(info.ptr_lin); + TEST_ASSERT_NULL(info.ptr_wrap); + + // write info + tu_fifo_get_write_info(ff, &info); + + TEST_ASSERT_EQUAL(FIFO_SIZE, info.len_lin); + TEST_ASSERT_EQUAL(0, info.len_wrap); + + TEST_ASSERT_EQUAL_PTR(ff->buffer, info .ptr_lin); + // application should check len instead of ptr. + // TEST_ASSERT_NULL(info.ptr_wrap); + + // write 1 then re-check empty + tu_fifo_write(ff, &temp); + TEST_ASSERT_FALSE(tu_fifo_empty(ff)); } void test_full(void) { - TEST_ASSERT_FALSE(tu_fifo_full(&ff)); + TEST_ASSERT_FALSE(tu_fifo_full(ff)); + + for(uint8_t i=0; i < FIFO_SIZE; i++) tu_fifo_write(ff, &i); - for(uint8_t i=0; i < FIFO_SIZE; i++) tu_fifo_write(&ff, &i); + TEST_ASSERT_TRUE(tu_fifo_full(ff)); - TEST_ASSERT_TRUE(tu_fifo_full(&ff)); + // read info + tu_fifo_get_read_info(ff, &info); + + TEST_ASSERT_EQUAL(FIFO_SIZE, info.len_lin); + TEST_ASSERT_EQUAL(0, info.len_wrap); + + TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_lin); + // skip this, application must check len instead of buffer + // TEST_ASSERT_NULL(info.ptr_wrap); + + // write info } + +void test_rd_idx_wrap() +{ + tu_fifo_t ff10; + uint8_t buf[10]; + uint8_t dst[10]; + + tu_fifo_config(&ff10, buf, 10, 1, 1); + + uint16_t n; + + ff10.wr_idx = 6; + ff10.rd_idx = 15; + + n = tu_fifo_read_n(&ff10, dst, 4); + TEST_ASSERT_EQUAL(n, 4); + TEST_ASSERT_EQUAL(ff10.rd_idx, 0); + n = tu_fifo_read_n(&ff10, dst, 4); + TEST_ASSERT_EQUAL(n, 4); + TEST_ASSERT_EQUAL(ff10.rd_idx, 4); + n = tu_fifo_read_n(&ff10, dst, 4); + TEST_ASSERT_EQUAL(n, 2); + TEST_ASSERT_EQUAL(ff10.rd_idx, 6); +}
\ No newline at end of file |
