From a253e4d64846316610aa92b231e3371acd7428e6 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 6 Feb 2013 13:15:12 +0700 Subject: [PATCH] fix TASK_ASSERT for osal_none.h add TASK_ASSERT test for osal_none integrate test project better with eclipse - assert message--> info windows - test fail --> error windows --- .cproject | 4 +-- .project | 4 +-- tests/test/test_osal_none.c | 69 ++++++++++++++++++++++++++++++++++++- tinyusb/common/assertion.h | 9 +++-- tinyusb/osal/osal.h | 2 +- tinyusb/osal/osal_none.h | 2 +- 6 files changed, 80 insertions(+), 10 deletions(-) diff --git a/.cproject b/.cproject index 81fb8ff3..655de95f 100644 --- a/.cproject +++ b/.cproject @@ -32,9 +32,7 @@ - + diff --git a/.project b/.project index 0a669605..e9443acb 100644 --- a/.project +++ b/.project @@ -27,7 +27,7 @@ org.eclipse.cdt.make.core.buildCommand - rake.bat + make org.eclipse.cdt.make.core.buildLocation @@ -63,7 +63,7 @@ org.eclipse.cdt.make.core.useDefaultBuildCmd - false + true diff --git a/tests/test/test_osal_none.c b/tests/test/test_osal_none.c index c48f384f..1d4b72a1 100644 --- a/tests/test/test_osal_none.c +++ b/tests/test/test_osal_none.c @@ -40,6 +40,7 @@ #endif #include "unity.h" +#include "errors.h" #include "osal_none.h" #define QUEUE_DEPTH 10 @@ -103,7 +104,7 @@ void test_queue_send(void) // blocking service such as semaphore wait need to be invoked within a task's loop //--------------------------------------------------------------------+ -// TASK +// TASK SEMAPHORE //--------------------------------------------------------------------+ void sample_task_semaphore(void) { @@ -161,6 +162,9 @@ void test_task_with_semaphore(void) TEST_ASSERT_EQUAL(2, statements[0]); } +//--------------------------------------------------------------------+ +// TASK SEMAPHORE +//--------------------------------------------------------------------+ void sample_task_with_queue(void) { uint32_t data; @@ -225,3 +229,66 @@ void test_task_with_queue(void) TEST_ASSERT_EQUAL(2, statements[0]); } +//--------------------------------------------------------------------+ +// TASK FLOW CONTROL +//--------------------------------------------------------------------+ +void flow_control_error_handler(void) +{ + statements[5]++; +} + +void sample_task_flow_control(void) +{ + tusb_error_t error; + + OSAL_TASK_LOOP_BEGIN + + statements[0]++; + + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); + TASK_ASSERT(TUSB_ERROR_NONE == error); + statements[1]++; + + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); + TASK_ASSERT_STATUS(error); + statements[2]++; + + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_NORMAL, &error); + TASK_ASSERT_STATUS_HANDLER(error, flow_control_error_handler()); + statements[3]++; + + OSAL_TASK_LOOP_END +} + +void test_task_flow_control_assert(void) +{ + sample_task_flow_control(); + for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 + 1; i++) osal_tick_tock(); + sample_task_flow_control(); + TEST_ASSERT_EQUAL(0, statements[1]); +} + +void test_task_flow_control_assert_status(void) +{ + for (uint8_t i=0; i<1; i++) osal_semaphore_post(sem_hdl); + + sample_task_flow_control(); + + for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 + 1; i++) osal_tick_tock(); + sample_task_flow_control(); + + TEST_ASSERT_EQUAL(0, statements[2]); +} + +void test_task_flow_control_assert_status_hanlder(void) +{ + for (uint8_t i=0; i<2; i++) osal_semaphore_post(sem_hdl); + + sample_task_flow_control(); + + for(uint32_t i=0; i<(OSAL_TIMEOUT_NORMAL*TUSB_CFG_OS_TICKS_PER_SECOND)/1000 + 1; i++) osal_tick_tock(); + sample_task_flow_control(); + + TEST_ASSERT_EQUAL(0, statements[3]); + TEST_ASSERT_EQUAL(1, statements[5]); +} diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index e8ce24c0..f0f780fe 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -68,8 +68,13 @@ extern "C" //--------------------------------------------------------------------+ // Assert Helper //--------------------------------------------------------------------+ -#define ASSERT_MESSAGE(format, ...)\ - _PRINTF("Assert at %s %s %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) +#ifndef _TEST_ + #define ASSERT_MESSAGE(format, ...)\ + _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) +#else + #define ASSERT_MESSAGE(format, ...)\ + _PRINTF("%d:note: Assert " format "\n", __LINE__, __VA_ARGS__) +#endif #ifndef _TEST_ASSERT_ #define ASSERT_ERROR_HANDLER(x, para) return (x) diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index 2482695f..21f322ba 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -90,7 +90,7 @@ typedef uint32_t osal_task_t; #define TASK_ASSERT_STATUS_HANDLER(sts, func_call) \ ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\ - TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status]) + TUSB_ERROR_NONE == status, (void) 0, "%s", TUSB_ErrorStr[status]) #define TASK_ASSERT_STATUS(sts) \ ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\ diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index e424d414..fb699e82 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -91,7 +91,7 @@ uint32_t osal_tick_get(void); } #define TASK_ASSERT_ERROR_HANDLER(error, func_call) \ - func_call; state = 0; break + func_call; state = 0; return #define TASK_ASSERT_STATUS_HANDLER(sts, func_call) \ ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\