From 1b963f6a7117d754c47e860159ac0aa90d1db6dc Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 31 Jan 2013 13:11:50 +0700 Subject: [PATCH] change cmock ignore to args only implementing usbh_host.c --- tests/project.yml | 1 + tests/test/host/test_hid_host_keyboard.c | 12 +++++++--- tests/test/host/test_usbd_host.c | 30 +++++++++++++++++------- tinyusb/common/assertion.h | 2 +- tinyusb/common/errors.h | 1 + tinyusb/host/usbd_host.c | 14 +++++++---- tinyusb/osal/osal.h | 9 ++++++- tinyusb/osal/osal_common.h | 6 +++++ tinyusb/osal/osal_none.h | 2 +- 9 files changed, 58 insertions(+), 19 deletions(-) diff --git a/tests/project.yml b/tests/project.yml index a669e4b4..039d0457 100644 --- a/tests/project.yml +++ b/tests/project.yml @@ -75,6 +75,7 @@ - :ignore - :callback - :array + :ignore: :args_only :treat_as: uint8: HEX8 uint16: HEX16 diff --git a/tests/test/host/test_hid_host_keyboard.c b/tests/test/host/test_hid_host_keyboard.c index 1ee09c7a..72d28527 100644 --- a/tests/test/host/test_hid_host_keyboard.c +++ b/tests/test/host/test_hid_host_keyboard.c @@ -101,9 +101,10 @@ void test_keyboard_no_instances_invalid_para(void) void test_keyboard_install_ok(void) { tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); - TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(device_hdl)); + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, class_hid_keyboard_install(device_hdl, (uint8_t*) &kbd_descriptor)); + tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); TEST_ASSERT_EQUAL(1, tusbh_hid_keyboard_no_instances(device_hdl)); } @@ -154,6 +155,8 @@ void test_keyboard_get_invalid_para() tusbh_device_status_get_IgnoreAndReturn(0); TEST_ASSERT_EQUAL(TUSB_ERROR_DEVICE_NOT_READY, tusbh_hid_keyboard_get(TUSB_CFG_HOST_DEVICE_MAX, 0, &report)); + + tusbh_device_status_get_IgnoreAndReturn(0); TEST_ASSERT_EQUAL(TUSB_ERROR_DEVICE_NOT_READY, tusbh_hid_keyboard_get(0, TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE, &report)); } @@ -167,25 +170,28 @@ void test_keyboard_get_class_not_supported() void test_keyboard_get_report_not_available() { tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); - usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_BUSY); TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_AVAILABLE); TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); } void test_keyboard_get_ok() { - tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); usbh_pipe_status_get_StubWithCallback(pipe_status_get_stub); + tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); TEST_ASSERT_EQUAL_MEMORY(&sample_key[0], &report, sizeof(tusb_keyboard_report_t)); + tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY); TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t)); } diff --git a/tests/test/host/test_usbd_host.c b/tests/test/host/test_usbd_host.c index c340e666..255ef3da 100644 --- a/tests/test/host/test_usbd_host.c +++ b/tests/test/host/test_usbd_host.c @@ -36,6 +36,7 @@ */ #include "unity.h" +#include "errors.h" #include "usbd_host.h" #include "mock_osal.h" @@ -54,27 +55,38 @@ void tearDown(void) //--------------------------------------------------------------------+ // init, get_status //--------------------------------------------------------------------+ +void test_usbh_init_task_create_failed(void) +{ + osal_task_create_IgnoreAndReturn(TUSB_ERROR_OSAL_TASK_FAILED); + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TASK_FAILED, usbh_init()); +} + +void test_usbh_init_queue_create_failed(void) +{ + osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); + osal_queue_create_IgnoreAndReturn(NULL); + TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init()); +} + void test_usbh_init_checkmem(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); - osal_queue_create_IgnoreAndReturn(TUSB_ERROR_NONE); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); + osal_queue_create_IgnoreAndReturn((osal_queue_handle_t)(&dummy)); TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init()); - TEST_ASSERT_EQUAL_MEMORY(device_info_zero, device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); -} -void test_usbh_init_queue_create_fail(void) -{ - TEST_IGNORE(); - osal_queue_create_IgnoreAndReturn(TUSB_ERROR_OSAL_QUEUE_FAILED); - TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init()); + TEST_ASSERT_EQUAL_MEMORY(device_info_zero, device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); } void test_usbh_status_get_fail(void) { - usbh_init(); + device_info_pool[dev_hdl].status = 0; + TEST_ASSERT_EQUAL( 0, tusbh_device_status_get(TUSB_CFG_HOST_DEVICE_MAX) ); TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_UNPLUG, tusbh_device_status_get(dev_hdl) ); } diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index 5d26311f..8383b2f0 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -68,7 +68,7 @@ extern "C" //--------------------------------------------------------------------+ // Assert Helper //--------------------------------------------------------------------+ -#define ASSERT_FILENAME __BASE_FILE__ +#define ASSERT_FILENAME __FILE__ #define ASSERT_FUNCTION __PRETTY_FUNCTION__ #define ASSERT_STATEMENT _PRINTF("assert at %s: %s :%d :\n", ASSERT_FILENAME, ASSERT_FUNCTION, __LINE__) diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index a39e99b2..7af82920 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -66,6 +66,7 @@ ENTRY(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT)\ ENTRY(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE)\ ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\ + ENTRY(TUSB_ERROR_OSAL_TASK_FAILED)\ ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED)\ ENTRY(TUSB_ERROR_FAILED)\ diff --git a/tinyusb/host/usbd_host.c b/tinyusb/host/usbd_host.c index 5ddaaaef..c3489525 100644 --- a/tinyusb/host/usbd_host.c +++ b/tinyusb/host/usbd_host.c @@ -58,9 +58,11 @@ //--------------------------------------------------------------------+ STATIC_ usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; -#define ENUM_DEPTH 2 -//STATIC_ osal_queue_t queue_enumerate; -//STATIC_ uint8_t queue_enumerate_buffer[ENUM_DEPTH*sizeof(usbh_enumerate_t)]; +OSAL_TASK_DEF(enumeration_task, usbh_enumerate_task, 128, OSAL_PRIO_HIGH); + +#define ENUM_QUEUE_DEPTH 5 +OSAL_DEF_QUEUE(enumeration_queue, ENUM_QUEUE_DEPTH, uin32_t); +osal_queue_handle_t enumeration_queue_hdl; //--------------------------------------------------------------------+ // PUBLIC API (Parameter Verification is required) @@ -77,7 +79,11 @@ tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device tusb_error_t usbh_init(void) { memset(device_info_pool, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); -// ASSERT_STATUS(osal_queue_create()); + + ASSERT_STATUS( osal_task_create(&enumeration_task) ); + enumeration_queue_hdl = osal_queue_create(&enumeration_queue); + ASSERT_PTR(enumeration_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED); + return TUSB_ERROR_NONE; } diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index 609c660a..0dfb7368 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -77,11 +77,14 @@ typedef uint32_t osal_timeout_t; //------------- Task -------------// +typedef uint32_t osal_task_t; +#define OSAL_TASK_DEF(name, code, stack_depth, prio) \ + osal_task_t name + #define OSAL_TASK_LOOP #define OSAL_TASK_LOOP_BEGIN #define OSAL_TASK_LOOP_END -typedef uint32_t osal_task_t; tusb_error_t osal_task_create(osal_task_t *task); //------------- Semaphore -------------// @@ -94,6 +97,10 @@ tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl); //------------- Queue -------------// typedef uint32_t osal_queue_t; typedef void* osal_queue_handle_t; + +#define OSAL_DEF_QUEUE(name, queue_depth, type) \ + osal_queue_t name + osal_queue_handle_t osal_queue_create(osal_queue_t *queue); #endif diff --git a/tinyusb/osal/osal_common.h b/tinyusb/osal/osal_common.h index 263798b9..62a21ae7 100644 --- a/tinyusb/osal/osal_common.h +++ b/tinyusb/osal/osal_common.h @@ -65,6 +65,12 @@ enum OSAL_TIMEOUT_WAIT_FOREVER = 1 }; +typedef enum { + OSAL_PRIO_LOW, + OSAL_PRIO_NORMAL, + OSAL_PRIO_HIGH +}osal_prio_t; + #ifdef __cplusplus } #endif diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index 99f145a3..6833ada2 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -73,7 +73,7 @@ typedef uint32_t osal_timeout_t; // OSAL_TASK_LOOP_ENG // } //--------------------------------------------------------------------+ -#define osal_task_create(code, name, stack_depth, parameters, prio) +//#define osal_task_create(code, name, stack_depth, parameters, prio) #define OSAL_TASK_LOOP \ static uint16_t state = 0;\