From 45c94c2aa9ace7b2efdc5dcad97c0d5b2283715a Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 22 Mar 2013 17:36:59 +0700 Subject: test code clean up --- tests/test/host/ehci/test_ehci_pipe_bulk_xfer.c | 204 ---------------- tests/test/host/ehci/test_ehci_pipe_xfer_control.c | 256 --------------------- tests/test/host/ehci/test_pipe_bulk_xfer.c | 204 ++++++++++++++++ tests/test/host/ehci/test_pipe_control_xfer.c | 256 +++++++++++++++++++++ 4 files changed, 460 insertions(+), 460 deletions(-) delete mode 100644 tests/test/host/ehci/test_ehci_pipe_bulk_xfer.c delete mode 100644 tests/test/host/ehci/test_ehci_pipe_xfer_control.c create mode 100644 tests/test/host/ehci/test_pipe_bulk_xfer.c create mode 100644 tests/test/host/ehci/test_pipe_control_xfer.c diff --git a/tests/test/host/ehci/test_ehci_pipe_bulk_xfer.c b/tests/test/host/ehci/test_ehci_pipe_bulk_xfer.c deleted file mode 100644 index 1f6221abf..000000000 --- a/tests/test/host/ehci/test_ehci_pipe_bulk_xfer.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * test_ehci_pipe_bulk_xfer.c - * - * Created on: Feb 27, 2013 - * Author: hathach - */ - -/* - * Software License Agreement (BSD License) - * Copyright (c) 2012, hathach (tinyusb.net) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the tiny usb stack. - */ - -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller.h" - -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; - -uint8_t const control_max_packet_size = 64; -uint8_t const hub_addr = 2; -uint8_t const hub_port = 2; -uint8_t dev_addr; -uint8_t hostid; -uint8_t xfer_data [18000]; // 18K to test buffer pointer list -uint8_t data2[100]; - -ehci_qhd_t *async_head; -ehci_qhd_t *p_qhd_bulk; -pipe_handle_t pipe_hdl_bulk; - -tusb_descriptor_endpoint_t const desc_ept_bulk_in = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = 512, - .bInterval = 0 -}; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); - memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); - - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - memclr_(&ehci_data, sizeof(ehci_data_t)); - memclr_(xfer_data, sizeof(xfer_data)); - - hcd_init(); - - dev_addr = 1; - - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - for (uint8_t i=0; ialternate.terminate); // not used, always invalid - - //------------- status -------------// - TEST_ASSERT_FALSE(p_qtd->pingstate_err); - TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); - TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); - TEST_ASSERT_FALSE(p_qtd->xact_err); - TEST_ASSERT_FALSE(p_qtd->babble_err); - TEST_ASSERT_FALSE(p_qtd->buffer_err); - TEST_ASSERT_FALSE(p_qtd->halted); - TEST_ASSERT_TRUE(p_qtd->active); - - TEST_ASSERT_FALSE(p_qtd->data_toggle); - TEST_ASSERT_EQUAL(3, p_qtd->cerr); - TEST_ASSERT_EQUAL(0, p_qtd->current_page); - TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); - TEST_ASSERT_TRUE(p_qtd->used); - - TEST_ASSERT_EQUAL_HEX( p_data, p_qtd->buffer[0] ); - for(uint8_t i=1; i<5; i++) - { - TEST_ASSERT_EQUAL_HEX( align4k((uint32_t) (p_data+4096*i)), align4k(p_qtd->buffer[i]) ); - } -} - -void test_bulk_xfer(void) -{ - - //------------- Code Under Test -------------// - hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), true); - - ehci_qtd_t* p_qtd = p_qhd_bulk->p_qtd_list_head; - TEST_ASSERT_NOT_NULL(p_qtd); - - verify_qtd( p_qtd, xfer_data, sizeof(xfer_data)); - TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_qtd); - TEST_ASSERT_TRUE(p_qtd->next.terminate); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_qtd->pid); - TEST_ASSERT_TRUE(p_qtd->int_on_complete); -} - -void test_bulk_xfer_double(void) -{ - - //------------- Code Under Test -------------// - hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false); - hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true); - - ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head; - ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail; - - //------------- list head -------------// - TEST_ASSERT_NOT_NULL(p_head); - verify_qtd(p_head, xfer_data, sizeof(xfer_data)); - TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_head); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_head->pid); - TEST_ASSERT_FALSE(p_head->next.terminate); - TEST_ASSERT_FALSE(p_head->int_on_complete); - - //------------- list tail -------------// - TEST_ASSERT_NOT_NULL(p_tail); - verify_qtd(p_tail, data2, sizeof(data2)); - TEST_ASSERT_EQUAL_HEX( align32(p_head->next.address), p_tail); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_tail->pid); - TEST_ASSERT_TRUE(p_tail->next.terminate); - TEST_ASSERT_TRUE(p_tail->int_on_complete); -} - -void test_bulk_xfer_isr(void) -{ - hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false); - hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true); - - ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head; - ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail; - - ehci_controller_run(hostid); - - usbh_isr_Expect(pipe_hdl_bulk, TUSB_CLASS_MSC); - - //------------- Code Under Test -------------// - hcd_isr(hostid); - - TEST_ASSERT_TRUE(p_qhd_bulk->qtd_overlay.next.terminate); - TEST_ASSERT_FALSE(p_head->used); - TEST_ASSERT_FALSE(p_tail->used); - TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_head); - TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_tail); -} diff --git a/tests/test/host/ehci/test_ehci_pipe_xfer_control.c b/tests/test/host/ehci/test_ehci_pipe_xfer_control.c deleted file mode 100644 index 666637f84..000000000 --- a/tests/test/host/ehci/test_ehci_pipe_xfer_control.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * test_ehci_pipe_xfer.c - * - * Created on: Feb 27, 2013 - * Author: hathach - */ - -/* - * Software License Agreement (BSD License) - * Copyright (c) 2012, hathach (tinyusb.net) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the tiny usb stack. - */ - -#include "unity.h" -#include "tusb_option.h" -#include "errors.h" -#include "binary.h" - -#include "hal.h" -#include "mock_osal.h" -#include "hcd.h" -#include "mock_usbh_hcd.h" -#include "ehci.h" -#include "ehci_controller.h" - -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; - -uint8_t const control_max_packet_size = 64; -uint8_t const hub_addr = 2; -uint8_t const hub_port = 2; -uint8_t dev_addr; -uint8_t hostid; -uint8_t xfer_data [100]; - -ehci_qhd_t *async_head; - -ehci_qtd_t *p_setup; -ehci_qtd_t *p_data; -ehci_qtd_t *p_status; - -tusb_descriptor_endpoint_t const desc_ept_bulk_in = -{ - .bLength = sizeof(tusb_descriptor_endpoint_t), - .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = 512, - .bInterval = 0 -}; - -//--------------------------------------------------------------------+ -// Setup/Teardown + helper declare -//--------------------------------------------------------------------+ -void setUp(void) -{ - memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); - memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); - - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); - memclr_(&ehci_data, sizeof(ehci_data_t)); - memclr_(xfer_data, sizeof(xfer_data)); - - hcd_init(); - - dev_addr = 1; - - hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - for (uint8_t i=0; ialternate.terminate); // not used, always invalid - - TEST_ASSERT_FALSE(p_qtd->pingstate_err); - TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); - TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); - TEST_ASSERT_FALSE(p_qtd->xact_err); - TEST_ASSERT_FALSE(p_qtd->babble_err); - TEST_ASSERT_FALSE(p_qtd->buffer_err); - TEST_ASSERT_FALSE(p_qtd->halted); - TEST_ASSERT_TRUE(p_qtd->active); - - TEST_ASSERT_EQUAL(3, p_qtd->cerr); - TEST_ASSERT_EQUAL(0, p_qtd->current_page); - TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); - - TEST_ASSERT_EQUAL_HEX(p_data, p_qtd->buffer[0]); -} - -void test_control_addr0_xfer_get_check_qhd_qtd_mapping(void) -{ - dev_addr = 0; - ehci_qhd_t * const p_qhd = async_head; - - hcd_pipe_control_open(dev_addr, control_max_packet_size); - - //------------- Code Under TEST -------------// - hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data); - - p_setup = &ehci_data.addr0_qtd[0]; - p_data = &ehci_data.addr0_qtd[1]; - p_status = &ehci_data.addr0_qtd[2]; - - TEST_ASSERT_EQUAL_HEX( p_setup, p_qhd->qtd_overlay.next.address ); - TEST_ASSERT_EQUAL_HEX( p_setup , p_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX( p_data , p_setup->next.address); - TEST_ASSERT_EQUAL_HEX( p_status , p_data->next.address ); - TEST_ASSERT_TRUE( p_status->next.terminate ); - - verify_qtd(p_setup, &request_get_dev_desc, 8); -} - - -void test_control_xfer_get(void) -{ - ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd; - hcd_pipe_control_open(dev_addr, control_max_packet_size); - - //------------- Code Under TEST -------------// - hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data); - - TEST_ASSERT_EQUAL_HEX( p_setup, p_qhd->qtd_overlay.next.address ); - TEST_ASSERT_EQUAL_HEX( p_setup , p_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX( p_data , p_setup->next.address); - TEST_ASSERT_EQUAL_HEX( p_status , p_data->next.address ); - TEST_ASSERT_TRUE( p_status->next.terminate ); - - //------------- SETUP -------------// - verify_qtd(p_setup, &request_get_dev_desc, 8); - - TEST_ASSERT_FALSE(p_setup->int_on_complete); - TEST_ASSERT_FALSE(p_setup->data_toggle); - TEST_ASSERT_EQUAL(EHCI_PID_SETUP, p_setup->pid); - - //------------- DATA -------------// - verify_qtd(p_data, xfer_data, request_get_dev_desc.wLength); - TEST_ASSERT_FALSE(p_data->int_on_complete); - TEST_ASSERT_TRUE(p_data->data_toggle); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_data->pid); - - //------------- STATUS -------------// - verify_qtd(p_status, NULL, 0); - TEST_ASSERT_TRUE(p_status->int_on_complete); - TEST_ASSERT_TRUE(p_status->data_toggle); - TEST_ASSERT_EQUAL(EHCI_PID_OUT, p_status->pid); - TEST_ASSERT_TRUE(p_status->next.terminate); - - TEST_ASSERT_EQUAL_HEX(p_setup, p_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX(p_status, p_qhd->p_qtd_list_tail); -} - -void test_control_xfer_set(void) -{ - tusb_std_request_t request_set_dev_addr = - { - .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, - .bRequest = TUSB_REQUEST_SET_ADDRESS, - .wValue = 3 - }; - - ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd; - hcd_pipe_control_open(dev_addr, control_max_packet_size); - - //------------- Code Under TEST -------------// - hcd_pipe_control_xfer(dev_addr, &request_set_dev_addr, xfer_data); - - TEST_ASSERT_EQUAL_HEX( p_setup, p_qhd->qtd_overlay.next.address ); - TEST_ASSERT_EQUAL_HEX( p_setup , p_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX( p_status , p_setup->next.address ); - TEST_ASSERT_TRUE( p_status->next.terminate ); - - //------------- STATUS -------------// - verify_qtd(p_status, NULL, 0); - TEST_ASSERT_TRUE(p_status->int_on_complete); - TEST_ASSERT_TRUE(p_status->data_toggle); - TEST_ASSERT_EQUAL(EHCI_PID_IN, p_status->pid); - TEST_ASSERT_TRUE(p_status->next.terminate); - - TEST_ASSERT_EQUAL_HEX(p_setup, p_qhd->p_qtd_list_head); - TEST_ASSERT_EQUAL_HEX(p_status, p_qhd->p_qtd_list_tail); -} - -void test_control_xfer_isr(void) -{ - ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd; - hcd_pipe_control_open(dev_addr, control_max_packet_size); - - hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data); - ehci_controller_run(hostid); - - TEST_ASSERT_EQUAL_HEX(async_head, get_operational_register(hostid)->async_list_base); - TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(async_head->next.address)); - usbh_isr_Expect(((pipe_handle_t){.dev_addr = dev_addr}), 0); - - //------------- Code Under TEST -------------// - hcd_isr(hostid); - - TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); - TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); - - TEST_ASSERT_FALSE(p_setup->used); - TEST_ASSERT_FALSE(p_data->used); - TEST_ASSERT_FALSE(p_status->used); - -} diff --git a/tests/test/host/ehci/test_pipe_bulk_xfer.c b/tests/test/host/ehci/test_pipe_bulk_xfer.c new file mode 100644 index 000000000..1f6221abf --- /dev/null +++ b/tests/test/host/ehci/test_pipe_bulk_xfer.c @@ -0,0 +1,204 @@ +/* + * test_ehci_pipe_bulk_xfer.c + * + * Created on: Feb 27, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller.h" + +usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; + +uint8_t const control_max_packet_size = 64; +uint8_t const hub_addr = 2; +uint8_t const hub_port = 2; +uint8_t dev_addr; +uint8_t hostid; +uint8_t xfer_data [18000]; // 18K to test buffer pointer list +uint8_t data2[100]; + +ehci_qhd_t *async_head; +ehci_qhd_t *p_qhd_bulk; +pipe_handle_t pipe_hdl_bulk; + +tusb_descriptor_endpoint_t const desc_ept_bulk_in = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_ENDPOINT, + .bEndpointAddress = 0x81, + .bmAttributes = { .xfer = TUSB_XFER_BULK }, + .wMaxPacketSize = 512, + .bInterval = 0 +}; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); + memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); + + memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(&ehci_data, sizeof(ehci_data_t)); + memclr_(xfer_data, sizeof(xfer_data)); + + hcd_init(); + + dev_addr = 1; + + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + for (uint8_t i=0; ialternate.terminate); // not used, always invalid + + //------------- status -------------// + TEST_ASSERT_FALSE(p_qtd->pingstate_err); + TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); + TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); + TEST_ASSERT_FALSE(p_qtd->xact_err); + TEST_ASSERT_FALSE(p_qtd->babble_err); + TEST_ASSERT_FALSE(p_qtd->buffer_err); + TEST_ASSERT_FALSE(p_qtd->halted); + TEST_ASSERT_TRUE(p_qtd->active); + + TEST_ASSERT_FALSE(p_qtd->data_toggle); + TEST_ASSERT_EQUAL(3, p_qtd->cerr); + TEST_ASSERT_EQUAL(0, p_qtd->current_page); + TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); + TEST_ASSERT_TRUE(p_qtd->used); + + TEST_ASSERT_EQUAL_HEX( p_data, p_qtd->buffer[0] ); + for(uint8_t i=1; i<5; i++) + { + TEST_ASSERT_EQUAL_HEX( align4k((uint32_t) (p_data+4096*i)), align4k(p_qtd->buffer[i]) ); + } +} + +void test_bulk_xfer(void) +{ + + //------------- Code Under Test -------------// + hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), true); + + ehci_qtd_t* p_qtd = p_qhd_bulk->p_qtd_list_head; + TEST_ASSERT_NOT_NULL(p_qtd); + + verify_qtd( p_qtd, xfer_data, sizeof(xfer_data)); + TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_qtd); + TEST_ASSERT_TRUE(p_qtd->next.terminate); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_qtd->pid); + TEST_ASSERT_TRUE(p_qtd->int_on_complete); +} + +void test_bulk_xfer_double(void) +{ + + //------------- Code Under Test -------------// + hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false); + hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true); + + ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head; + ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail; + + //------------- list head -------------// + TEST_ASSERT_NOT_NULL(p_head); + verify_qtd(p_head, xfer_data, sizeof(xfer_data)); + TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_head); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_head->pid); + TEST_ASSERT_FALSE(p_head->next.terminate); + TEST_ASSERT_FALSE(p_head->int_on_complete); + + //------------- list tail -------------// + TEST_ASSERT_NOT_NULL(p_tail); + verify_qtd(p_tail, data2, sizeof(data2)); + TEST_ASSERT_EQUAL_HEX( align32(p_head->next.address), p_tail); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_tail->pid); + TEST_ASSERT_TRUE(p_tail->next.terminate); + TEST_ASSERT_TRUE(p_tail->int_on_complete); +} + +void test_bulk_xfer_isr(void) +{ + hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false); + hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true); + + ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head; + ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail; + + ehci_controller_run(hostid); + + usbh_isr_Expect(pipe_hdl_bulk, TUSB_CLASS_MSC); + + //------------- Code Under Test -------------// + hcd_isr(hostid); + + TEST_ASSERT_TRUE(p_qhd_bulk->qtd_overlay.next.terminate); + TEST_ASSERT_FALSE(p_head->used); + TEST_ASSERT_FALSE(p_tail->used); + TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_head); + TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_tail); +} diff --git a/tests/test/host/ehci/test_pipe_control_xfer.c b/tests/test/host/ehci/test_pipe_control_xfer.c new file mode 100644 index 000000000..666637f84 --- /dev/null +++ b/tests/test/host/ehci/test_pipe_control_xfer.c @@ -0,0 +1,256 @@ +/* + * test_ehci_pipe_xfer.c + * + * Created on: Feb 27, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +#include "unity.h" +#include "tusb_option.h" +#include "errors.h" +#include "binary.h" + +#include "hal.h" +#include "mock_osal.h" +#include "hcd.h" +#include "mock_usbh_hcd.h" +#include "ehci.h" +#include "ehci_controller.h" + +usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; + +uint8_t const control_max_packet_size = 64; +uint8_t const hub_addr = 2; +uint8_t const hub_port = 2; +uint8_t dev_addr; +uint8_t hostid; +uint8_t xfer_data [100]; + +ehci_qhd_t *async_head; + +ehci_qtd_t *p_setup; +ehci_qtd_t *p_data; +ehci_qtd_t *p_status; + +tusb_descriptor_endpoint_t const desc_ept_bulk_in = +{ + .bLength = sizeof(tusb_descriptor_endpoint_t), + .bDescriptorType = TUSB_DESC_ENDPOINT, + .bEndpointAddress = 0x81, + .bmAttributes = { .xfer = TUSB_XFER_BULK }, + .wMaxPacketSize = 512, + .bInterval = 0 +}; + +//--------------------------------------------------------------------+ +// Setup/Teardown + helper declare +//--------------------------------------------------------------------+ +void setUp(void) +{ + memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); + memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); + + memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(&ehci_data, sizeof(ehci_data_t)); + memclr_(xfer_data, sizeof(xfer_data)); + + hcd_init(); + + dev_addr = 1; + + hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; + for (uint8_t i=0; ialternate.terminate); // not used, always invalid + + TEST_ASSERT_FALSE(p_qtd->pingstate_err); + TEST_ASSERT_FALSE(p_qtd->non_hs_split_state); + TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe); + TEST_ASSERT_FALSE(p_qtd->xact_err); + TEST_ASSERT_FALSE(p_qtd->babble_err); + TEST_ASSERT_FALSE(p_qtd->buffer_err); + TEST_ASSERT_FALSE(p_qtd->halted); + TEST_ASSERT_TRUE(p_qtd->active); + + TEST_ASSERT_EQUAL(3, p_qtd->cerr); + TEST_ASSERT_EQUAL(0, p_qtd->current_page); + TEST_ASSERT_EQUAL(length, p_qtd->total_bytes); + + TEST_ASSERT_EQUAL_HEX(p_data, p_qtd->buffer[0]); +} + +void test_control_addr0_xfer_get_check_qhd_qtd_mapping(void) +{ + dev_addr = 0; + ehci_qhd_t * const p_qhd = async_head; + + hcd_pipe_control_open(dev_addr, control_max_packet_size); + + //------------- Code Under TEST -------------// + hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data); + + p_setup = &ehci_data.addr0_qtd[0]; + p_data = &ehci_data.addr0_qtd[1]; + p_status = &ehci_data.addr0_qtd[2]; + + TEST_ASSERT_EQUAL_HEX( p_setup, p_qhd->qtd_overlay.next.address ); + TEST_ASSERT_EQUAL_HEX( p_setup , p_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX( p_data , p_setup->next.address); + TEST_ASSERT_EQUAL_HEX( p_status , p_data->next.address ); + TEST_ASSERT_TRUE( p_status->next.terminate ); + + verify_qtd(p_setup, &request_get_dev_desc, 8); +} + + +void test_control_xfer_get(void) +{ + ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd; + hcd_pipe_control_open(dev_addr, control_max_packet_size); + + //------------- Code Under TEST -------------// + hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data); + + TEST_ASSERT_EQUAL_HEX( p_setup, p_qhd->qtd_overlay.next.address ); + TEST_ASSERT_EQUAL_HEX( p_setup , p_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX( p_data , p_setup->next.address); + TEST_ASSERT_EQUAL_HEX( p_status , p_data->next.address ); + TEST_ASSERT_TRUE( p_status->next.terminate ); + + //------------- SETUP -------------// + verify_qtd(p_setup, &request_get_dev_desc, 8); + + TEST_ASSERT_FALSE(p_setup->int_on_complete); + TEST_ASSERT_FALSE(p_setup->data_toggle); + TEST_ASSERT_EQUAL(EHCI_PID_SETUP, p_setup->pid); + + //------------- DATA -------------// + verify_qtd(p_data, xfer_data, request_get_dev_desc.wLength); + TEST_ASSERT_FALSE(p_data->int_on_complete); + TEST_ASSERT_TRUE(p_data->data_toggle); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_data->pid); + + //------------- STATUS -------------// + verify_qtd(p_status, NULL, 0); + TEST_ASSERT_TRUE(p_status->int_on_complete); + TEST_ASSERT_TRUE(p_status->data_toggle); + TEST_ASSERT_EQUAL(EHCI_PID_OUT, p_status->pid); + TEST_ASSERT_TRUE(p_status->next.terminate); + + TEST_ASSERT_EQUAL_HEX(p_setup, p_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX(p_status, p_qhd->p_qtd_list_tail); +} + +void test_control_xfer_set(void) +{ + tusb_std_request_t request_set_dev_addr = + { + .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, + .bRequest = TUSB_REQUEST_SET_ADDRESS, + .wValue = 3 + }; + + ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd; + hcd_pipe_control_open(dev_addr, control_max_packet_size); + + //------------- Code Under TEST -------------// + hcd_pipe_control_xfer(dev_addr, &request_set_dev_addr, xfer_data); + + TEST_ASSERT_EQUAL_HEX( p_setup, p_qhd->qtd_overlay.next.address ); + TEST_ASSERT_EQUAL_HEX( p_setup , p_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX( p_status , p_setup->next.address ); + TEST_ASSERT_TRUE( p_status->next.terminate ); + + //------------- STATUS -------------// + verify_qtd(p_status, NULL, 0); + TEST_ASSERT_TRUE(p_status->int_on_complete); + TEST_ASSERT_TRUE(p_status->data_toggle); + TEST_ASSERT_EQUAL(EHCI_PID_IN, p_status->pid); + TEST_ASSERT_TRUE(p_status->next.terminate); + + TEST_ASSERT_EQUAL_HEX(p_setup, p_qhd->p_qtd_list_head); + TEST_ASSERT_EQUAL_HEX(p_status, p_qhd->p_qtd_list_tail); +} + +void test_control_xfer_isr(void) +{ + ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd; + hcd_pipe_control_open(dev_addr, control_max_packet_size); + + hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data); + ehci_controller_run(hostid); + + TEST_ASSERT_EQUAL_HEX(async_head, get_operational_register(hostid)->async_list_base); + TEST_ASSERT_EQUAL_HEX((uint32_t) p_qhd, align32(async_head->next.address)); + usbh_isr_Expect(((pipe_handle_t){.dev_addr = dev_addr}), 0); + + //------------- Code Under TEST -------------// + hcd_isr(hostid); + + TEST_ASSERT_NULL(p_qhd->p_qtd_list_head); + TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail); + + TEST_ASSERT_FALSE(p_setup->used); + TEST_ASSERT_FALSE(p_data->used); + TEST_ASSERT_FALSE(p_status->used); + +} -- cgit v1.3.1