summaryrefslogtreecommitdiff
path: root/tests/test
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-01-30 11:35:37 +0700
committerhathach <[email protected]>2013-01-30 11:35:37 +0700
commit07048b943e6b57aeee4a671b85d76a2f592e3205 (patch)
tree63af67247cbd779590cb4f0aa6798faccf680b5d /tests/test
parent6db8af20236cfecba5aef54da148309982b28396 (diff)
add primitive_types.h for portable with uint8,16,32_t, and bool
add osal_common.h to ease the complaint of MISRA 19.1 implement OSAL_NONE Task loop, semaphore wait/post and its test code
Diffstat (limited to 'tests/test')
-rw-r--r--tests/test/host/test_usbd_host.c1
-rw-r--r--tests/test/test_osal_none.c86
2 files changed, 84 insertions, 3 deletions
diff --git a/tests/test/host/test_usbd_host.c b/tests/test/host/test_usbd_host.c
index e9af68d91..c340e6666 100644
--- a/tests/test/host/test_usbd_host.c
+++ b/tests/test/host/test_usbd_host.c
@@ -67,6 +67,7 @@ void test_usbh_init_checkmem(void)
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());
}
diff --git a/tests/test/test_osal_none.c b/tests/test/test_osal_none.c
index 295a6d40a..2e5bfb3e5 100644
--- a/tests/test/test_osal_none.c
+++ b/tests/test/test_osal_none.c
@@ -35,12 +35,23 @@
* This file is part of the tiny usb stack.
*/
+#ifdef TUSB_CFG_OS
+#undef TUSB_CFG_OS
+#endif
+
+#define TUSB_CFG_OS TUSB_OS_NONE
#include "unity.h"
-#include "osal_none.h"
+#include "osal.h"
+
+uint32_t statements[10];
+osal_semaphore_t sem;
+osal_semaphore_handle_t sem_hdl;
void setUp(void)
{
-
+ memset(statements, 0, sizeof(statements));
+ sem = 0;
+ sem_hdl = osal_semaphore_create(&sem);
}
void tearDown(void)
@@ -48,9 +59,78 @@ void tearDown(void)
}
-void test_queue_put_invalid_para(void)
+//--------------------------------------------------------------------+
+// Semaphore
+//--------------------------------------------------------------------+
+void test_semaphore_create(void)
{
+ TEST_ASSERT_EQUAL_PTR(&sem, sem_hdl);
+ TEST_ASSERT_EQUAL(0, sem);
+}
+
+void test_semaphore_post(void)
+{
+ osal_semaphore_post(sem_hdl);
+ TEST_ASSERT_EQUAL(1, sem);
+}
+
+//--------------------------------------------------------------------+
+// Queue
+//--------------------------------------------------------------------+
+void test_queue_create(void)
+{
+ TEST_IGNORE();
// osal_queue_put();
}
+//--------------------------------------------------------------------+
+// TASK
+//--------------------------------------------------------------------+
+void sample_task_semaphore(void)
+{
+ OSAL_TASK_LOOP
+ {
+ OSAL_TASK_LOOP_BEGIN
+
+ statements[0]++;
+
+ osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER);
+ statements[1]++;
+
+ osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER);
+ statements[2]++;
+
+ osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER);
+ statements[3]++;
+
+ OSAL_TASK_LOOP_END
+ }
+}
+
+void test_task_with_semaphore(void)
+{
+ uint32_t i;
+ // several invoke before sempahore is available
+ for(i=0; i<10; i++)
+ sample_task_semaphore();
+ TEST_ASSERT_EQUAL(1, statements[0]);
+
+ // several invoke after posting semaphore
+ osal_semaphore_post(sem_hdl);
+ sample_task_semaphore();
+ TEST_ASSERT_EQUAL(1, statements[1]);
+
+ osal_semaphore_post(sem_hdl);
+ osal_semaphore_post(sem_hdl);
+ sample_task_semaphore();
+ TEST_ASSERT_EQUAL(1, statements[2]);
+ TEST_ASSERT_EQUAL(1, statements[3]);
+
+ // reach end of task loop, back to beginning
+ sample_task_semaphore();
+ TEST_ASSERT_EQUAL(2, statements[0]);
+
+}
+
+