From eca87e5ee54f688372d2d34ee51dc3f72947d604 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 31 Jan 2013 11:05:33 +0700 Subject: [PATCH] add ASSERT_BIN8 and its test code add some common api for task in osal.h for mocking --- tests/test/test_assertion.c | 29 ++++++++++++++++++----------- tinyusb/common/assertion.h | 18 ++++++++++++++++++ tinyusb/osal/osal.h | 8 ++++++++ tinyusb/osal/osal_common.h | 2 ++ 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/tests/test/test_assertion.c b/tests/test/test_assertion.c index 1f6288def..e09278141 100644 --- a/tests/test/test_assertion.c +++ b/tests/test/test_assertion.c @@ -42,6 +42,7 @@ #include #include "unity.h" #include "CException.h" +#include "binary.h" #include "common/assertion.h" #include "errors.h" @@ -270,18 +271,24 @@ void test_assert_hex_within_greater(void) //--------------------------------------------------------------------+ void test_assert_bin_equal(void) { -// ASSERT_HEX (0xffee, 0xffee, __LINE__); -// ASSERT_HEX_EQUAL (0xffee, 0xffee, __LINE__); -// -// uint32_t x = 0xf0f0; -// uint32_t y = 0xf0f0; -// ASSERT_HEX (x++, y++, __LINE__); // test side effect -// TEST_ASSERT_EQUAL(0xf0f1, x); -// TEST_ASSERT_EQUAL(0xf0f1, y); -// -// ASSERT_HEX(0x1234, 0x4321, __LINE__); + Try + { + ASSERT_BIN8 (BIN8(11110000), BIN8(11110000), __LINE__); + ASSERT_BIN8_EQUAL (BIN8(00001111), BIN8(00001111), __LINE__); - TEST_IGNORE(); + // test side effect + uint32_t x = BIN8(11001100); + uint32_t y = BIN8(11001100); + ASSERT_BIN8 (x++, y++, __LINE__); + TEST_ASSERT_EQUAL(BIN8(11001101), x); + TEST_ASSERT_EQUAL(BIN8(11001101), y); + + ASSERT_BIN8(BIN8(11001111), BIN8(11111100), 0); + } + Catch(e) + { + TEST_ASSERT_EQUAL(0, e); + } } diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index 211a96073..5d26311fd 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -146,6 +146,24 @@ extern "C" //--------------------------------------------------------------------+ // TODO Bin Assert //--------------------------------------------------------------------+ +#define BIN8_PRINTF_PATTERN "%d%d%d%d%d%d%d%d" +#define BIN8_PRINTF_CONVERT(byte) \ + ((byte) & 0x80 ? 1 : 0), \ + ((byte) & 0x40 ? 1 : 0), \ + ((byte) & 0x20 ? 1 : 0), \ + ((byte) & 0x10 ? 1 : 0), \ + ((byte) & 0x08 ? 1 : 0), \ + ((byte) & 0x04 ? 1 : 0), \ + ((byte) & 0x02 ? 1 : 0), \ + ((byte) & 0x01 ? 1 : 0) + +#define ASSERT_BIN8(...) ASSERT_BIN8_EQUAL(__VA_ARGS__) +#define ASSERT_BIN8_EQUAL(expected, actual, error)\ + ASSERT_DEFINE(\ + uint8_t exp = (expected); uint8_t act = (actual),\ + exp==act,\ + error,\ + "expected " BIN8_PRINTF_PATTERN ", actual " BIN8_PRINTF_PATTERN, BIN8_PRINTF_CONVERT(exp), BIN8_PRINTF_CONVERT(act) ) //--------------------------------------------------------------------+ // TODO Bit Assert diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index 5552da4c6..609c660ad 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -76,6 +76,14 @@ typedef uint32_t osal_timeout_t; +//------------- Task -------------// +#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 -------------// typedef uint32_t osal_semaphore_t; typedef void* osal_semaphore_handle_t; diff --git a/tinyusb/osal/osal_common.h b/tinyusb/osal/osal_common.h index cb7a775eb..263798b90 100644 --- a/tinyusb/osal/osal_common.h +++ b/tinyusb/osal/osal_common.h @@ -57,6 +57,8 @@ #include "common/common.h" +//typedef void (*pfTask)( void * ); + enum { OSAL_TIMEOUT_NOTIMEOUT = 0, // for use within ISR, return immediately