diff options
| author | hathach <[email protected]> | 2013-02-06 12:03:01 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-02-06 12:03:01 +0700 |
| commit | e20025b54d16deccbd6e86433f31d80f5a976fd4 (patch) | |
| tree | b94fc6905de315cc5ce3778d297cc711cc195f0f /tests | |
| parent | aeccdfde3f4462fae5e3b9cbb4eae76526bdb204 (diff) | |
refractor move test enum to its own file
add assert with handler
add task assert with error catcher
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/project.yml | 3 | ||||
| -rw-r--r-- | tests/test/host/test_enum_task.c | 191 | ||||
| -rw-r--r-- | tests/test/host/test_usbh.c | 116 | ||||
| -rw-r--r-- | tests/test/support/descriptor_test.c | 2 | ||||
| -rw-r--r-- | tests/test/support/descriptor_test.h | 3 | ||||
| -rw-r--r-- | tests/test/support/tusb_callback.h | 71 |
6 files changed, 268 insertions, 118 deletions
diff --git a/tests/project.yml b/tests/project.yml index 54da541dd..54a07be6f 100644 --- a/tests/project.yml +++ b/tests/project.yml @@ -88,6 +88,7 @@ :load_paths: - vendor/ceedling/plugins :enabled: - - stdout_pretty_tests_report + #- stdout_pretty_tests_report + - stdout_ide_tests_report - module_generator ... diff --git a/tests/test/host/test_enum_task.c b/tests/test/host/test_enum_task.c new file mode 100644 index 000000000..8c57cc85b --- /dev/null +++ b/tests/test/host/test_enum_task.c @@ -0,0 +1,191 @@ +/* + * test_enum_task.c + * + * Created on: Feb 5, 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 "errors.h" +#include "usbh.h" +#include "descriptor_test.h" +#include "mock_osal.h" +#include "mock_hcd.h" +#include "mock_usbh_hcd.h" +#include "mock_tusb_callback.h" + +extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; +extern usbh_device_addr0_t device_addr0; +tusb_handle_device_t dev_hdl; +pipe_handle_t pipe_addr0 = 12; + +usbh_enumerate_t const enum_connect = { + .core_id = 0, + .hub_addr = 0, + .hub_port = 0, + .connect_status = 1 +}; + +void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call); +void semaphore_wait_success_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call); +tusb_error_t control_xfer_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call); + +void setUp(void) +{ + memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + + osal_queue_receive_StubWithCallback(queue_recv_stub); + osal_semaphore_wait_StubWithCallback(semaphore_wait_success_stub); + hcd_pipe_control_xfer_StubWithCallback(control_xfer_stub); + + hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); + hcd_port_speed_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL); + + hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE); + hcd_addr0_close_IgnoreAndReturn(TUSB_ERROR_NONE); +} + +void tearDown(void) +{ +} + +//--------------------------------------------------------------------+ +// STUB & HELPER +//--------------------------------------------------------------------+ +void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) +{ + (*p_data) = ( *((uint32_t*) &enum_connect) ); + (*p_error) = TUSB_ERROR_NONE; +} + +void semaphore_wait_success_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) +{ + (*p_error) = TUSB_ERROR_NONE; +} + +#define semaphore_wait_timeout_stub(n) semaphore_wait_timeout_##n +#define semaphore_wait_timeout(n) \ + void semaphore_wait_timeout_##n(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) {\ + if (num_call >= n)\ + (*p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ + else \ + (*p_error) = TUSB_ERROR_NONE;\ + } + +semaphore_wait_timeout(0) +semaphore_wait_timeout(1) +semaphore_wait_timeout(2) +semaphore_wait_timeout(3) +semaphore_wait_timeout(4) + +tusb_error_t control_xfer_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) +{ + switch (num_call) + { + case 0: // get 8 bytes of device descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_DEVICE, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(8, p_request->wLength); + memcpy(data, &desc_device, p_request->wLength); + break; + + case 1: // set device address + TEST_ASSERT_EQUAL(TUSB_REQUEST_SET_ADDRESS, p_request->bRequest); + TEST_ASSERT_EQUAL(p_request->wValue, 1); + break; + + case 2: // get full device decriptor for new address + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_DEVICE, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(18, p_request->wLength); + memcpy(data, &desc_device, p_request->wLength); + break; + + case 3: // get 9 bytes of configuration descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_CONFIGURATION, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(9, p_request->wLength); + memcpy(data, &desc_configuration, p_request->wLength); + break; + + case 4: // get full-length configuration descriptor + TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); + TEST_ASSERT_EQUAL(TUSB_DESC_CONFIGURATION, p_request->wValue >> 8); + TEST_ASSERT_EQUAL(desc_configuration.configuration.wTotalLength, p_request->wLength); + memcpy(data, &desc_configuration, p_request->wLength); + break; + } + + return TUSB_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// enum connect directed +//--------------------------------------------------------------------+ +void test_failed_get_first_dev_desc(void) +{ + osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(0)); + tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_FAILED, NULL); + + usbh_enumeration_task(); +} + +void test_enum_task_connect(void) +{ + + usbh_enumeration_task(); + + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_ADDRESSED, usbh_device_info_pool[0].status); + TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_device_info_pool[0].speed); + TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_device_info_pool[0].core_id); + TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_device_info_pool[0].hub_addr); + TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[0].hub_port); + +// hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); + +} + +void test_enum_task_disconnect(void) +{ + TEST_IGNORE(); +} + +void test_enum_task_connect_via_hub(void) +{ + TEST_IGNORE(); +} + +void test_enum_task_disconnect_via_hub(void) +{ + TEST_IGNORE(); +} diff --git a/tests/test/host/test_usbh.c b/tests/test/host/test_usbh.c index 911756ede..e0fc003ee 100644 --- a/tests/test/host/test_usbh.c +++ b/tests/test/host/test_usbh.c @@ -38,7 +38,6 @@ #include "unity.h" #include "errors.h" #include "usbh.h" -#include "descriptor_test.h" #include "mock_osal.h" #include "mock_hcd.h" #include "mock_usbh_hcd.h" @@ -83,13 +82,12 @@ void test_usbh_init_queue_create_failed(void) TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init()); } - void test_usbh_init_ok(void) { uint32_t dummy; usbh_device_info_t device_info_zero[TUSB_CFG_HOST_DEVICE_MAX]; - memset(device_info_zero, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + memclr_(device_info_zero, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); for(uint32_t i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++) hcd_init_ExpectAndReturn(i, TUSB_ERROR_NONE); @@ -115,115 +113,3 @@ void test_usbh_status_get_succeed(void) usbh_device_info_pool[dev_hdl].status = TUSB_DEVICE_STATUS_READY; TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_READY, tusbh_device_status_get(dev_hdl) ); } - -//--------------------------------------------------------------------+ -// enum task -//--------------------------------------------------------------------+ -extern osal_queue_handle_t enum_queue_hdl; -usbh_enumerate_t enum_connect = -{ - .core_id = 0, - .hub_addr = 0, - .hub_port = 0, - .connect_status = 1 -}; -extern usbh_device_addr0_t device_addr0; - - -void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) -{ - TEST_ASSERT_EQUAL_PTR(enum_queue_hdl, queue_hdl); - (*p_data) = ( *((uint32_t*) &enum_connect) ); - (*p_error) = TUSB_ERROR_NONE; -} - -void semaphore_wait_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) -{ - (*p_error) = TUSB_ERROR_NONE; -} - -tusb_error_t get_device_desc_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) -{ - TEST_ASSERT(num_call < 2); - TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); - TEST_ASSERT_EQUAL(TUSB_DESC_DEVICE, p_request->wValue >> 8); - - memcpy(data, &desc_device, p_request->wLength); - - return TUSB_ERROR_NONE; -} - -tusb_error_t set_device_addr_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) -{ - TEST_ASSERT_EQUAL(TUSB_REQUEST_SET_ADDRESS, p_request->bRequest); - TEST_ASSERT_EQUAL(p_request->wValue, 1); - return TUSB_ERROR_NONE; -} - -tusb_error_t get_configuration_desc_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call) -{ - TEST_ASSERT(num_call < 2); - - TEST_ASSERT_EQUAL(TUSB_REQUEST_GET_DESCRIPTOR, p_request->bRequest); - TEST_ASSERT_EQUAL(TUSB_DESC_CONFIGURATION, p_request->wValue >> 8); - - memcpy(data, &desc_device, p_request->wLength); - - return TUSB_ERROR_NONE; -} - -void test_enum_task_connect(void) -{ - pipe_handle_t pipe_addr0 = 12; - - osal_queue_receive_StubWithCallback(queue_recv_stub); - hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); - hcd_port_speed_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL); - - { - hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE); - - // get 8-byte of device descriptor - hcd_pipe_control_xfer_StubWithCallback(get_device_desc_stub); - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); - // set device address - hcd_pipe_control_xfer_StubWithCallback(set_device_addr_stub); - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); - - hcd_addr0_close_IgnoreAndReturn(TUSB_ERROR_NONE); - } - - usbh_enumeration_task(); - - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_ADDRESSED, usbh_device_info_pool[0].status); - TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_device_info_pool[0].speed); - TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_device_info_pool[0].core_id); - TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_device_info_pool[0].hub_addr); - TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[0].hub_port); - - hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); - - hcd_pipe_control_xfer_StubWithCallback(get_device_desc_stub); // get full device descriptor - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); - - hcd_pipe_control_xfer_StubWithCallback(get_configuration_desc_stub); // get 9 bytes of configuration descriptor - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); - - hcd_pipe_control_xfer_StubWithCallback(get_configuration_desc_stub); // get full-length configuration descriptor - osal_semaphore_wait_StubWithCallback(semaphore_wait_stub); -} - -void test_enum_task_disconnect(void) -{ - TEST_IGNORE(); -} - -void test_enum_task_connect_via_hub(void) -{ - TEST_IGNORE(); -} - -void test_enum_task_disconnect_via_hub(void) -{ - TEST_IGNORE(); -} diff --git a/tests/test/support/descriptor_test.c b/tests/test/support/descriptor_test.c index bbc5c72c6..7851716ad 100644 --- a/tests/test/support/descriptor_test.c +++ b/tests/test/support/descriptor_test.c @@ -39,7 +39,7 @@ #include "descriptor_test.h" TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) -tusb_descriptor_device_t desc_device = +tusb_descriptor_device_t const desc_device = { .bLength = sizeof(tusb_descriptor_device_t), .bDescriptorType = TUSB_DESC_DEVICE, diff --git a/tests/test/support/descriptor_test.h b/tests/test/support/descriptor_test.h index 71f6351c9..70694b1b7 100644 --- a/tests/test/support/descriptor_test.h +++ b/tests/test/support/descriptor_test.h @@ -98,7 +98,8 @@ typedef struct unsigned char ConfigDescTermination; } app_configuration_desc_t; -extern tusb_descriptor_device_t desc_device; +extern tusb_descriptor_device_t const desc_device; +extern app_configuration_desc_t const desc_configuration; #ifdef __cplusplus } diff --git a/tests/test/support/tusb_callback.h b/tests/test/support/tusb_callback.h new file mode 100644 index 000000000..5a6e11eb5 --- /dev/null +++ b/tests/test/support/tusb_callback.h @@ -0,0 +1,71 @@ +/* + * tusb_callback.h + * + * Created on: Feb 5, 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. + */ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_TUSB_CALLBACK_H_ +#define _TUSB_TUSB_CALLBACK_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +#include "common/common.h" +#include "usbh.h" + +uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; +void tusbh_device_mounted_cb (tusb_handle_device_t device_hdl) ATTR_WEAK; +void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK; + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_TUSB_CALLBACK_H_ */ + +/** @} */ |
