فهرست منبع

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

hathach 13 سال پیش
والد
کامیت
a253e4d648
6فایلهای تغییر یافته به همراه80 افزوده شده و 10 حذف شده
  1. 1 3
      .cproject
  2. 2 2
      .project
  3. 68 1
      tests/test/test_osal_none.c
  4. 7 2
      tinyusb/common/assertion.h
  5. 1 1
      tinyusb/osal/osal.h
  6. 1 1
      tinyusb/osal/osal_none.h

+ 1 - 3
.cproject

@@ -32,9 +32,7 @@
 							<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.1485867060" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
 							<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.694786126" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base"/>
 							<tool errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.1588045403" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base">
-								<option id="gnu.c.compiler.option.preprocessor.def.symbols.1484610767" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
-									<listOptionValue builtIn="false" value="__BASE_FILE__=__FILE__"/>
-								</option>
+								<option id="gnu.c.compiler.option.preprocessor.def.symbols.1484610767" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols"/>
 								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.451457393" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
 							</tool>
 							<tool errorParsers="org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.tool.gnu.c.linker.mingw.base.1896871485" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.base">

+ 2 - 2
.project

@@ -27,7 +27,7 @@
 				</dictionary>
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.buildCommand</key>
-					<value>rake.bat</value>
+					<value>make</value>
 				</dictionary>
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.buildLocation</key>
@@ -63,7 +63,7 @@
 				</dictionary>
 				<dictionary>
 					<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
-					<value>false</value>
+					<value>true</value>
 				</dictionary>
 			</arguments>
 		</buildCommand>

+ 68 - 1
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]);
+}

+ 7 - 2
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)

+ 1 - 1
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),\

+ 1 - 1
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),\