summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-01-16 13:25:02 +0700
committerhathach <[email protected]>2013-01-16 13:25:02 +0700
commit8155fd38a580603af60bc91fa54197b08ce68464 (patch)
tree98db374db9fbd50201fd690436cce88fd2363917
parentc004cd438724063007eec0f43a4681e84a839252 (diff)
added some tests for fifo.c
-rw-r--r--tests/project.yml5
-rw-r--r--tests/test/test_fifo.c48
-rw-r--r--tinyusb/common/fifo.h2
3 files changed, 50 insertions, 5 deletions
diff --git a/tests/project.yml b/tests/project.yml
index 10885baca..f45531096 100644
--- a/tests/project.yml
+++ b/tests/project.yml
@@ -32,6 +32,7 @@
- ../tinyusb/**
- -:../demos
- -:../test_old
+ - ../../CMSISv2p10_LPC13Uxx/**
#- ../../CMSISv2p10_LPC43xx_DriverLib/inc
:support:
- test/support
@@ -44,12 +45,12 @@
:test:
- *common_defines
- _TEST_
- - MCU=MCU_LPC43XX
+ - MCU=MCU_LPC13UXX
- CORE_M4
:test_preprocess:
- *common_defines
- _TEST_
- - MCU=MCU_LPC43XX
+ - MCU=MCU_LPC13UXX
- CORE_M4
#:flags:
diff --git a/tests/test/test_fifo.c b/tests/test/test_fifo.c
index edc76783b..5741d6bcb 100644
--- a/tests/test/test_fifo.c
+++ b/tests/test/test_fifo.c
@@ -38,16 +38,60 @@
#include "unity.h"
#include "fifo.h"
+#define FIFO_SIZE 10
+static fifo_t ff;
+static uint8_t buffer[FIFO_SIZE];
+
void setUp(void)
{
+ fifo_init(&ff, buffer, FIFO_SIZE, 0, 0);
}
void tearDown(void)
{
+ memset(&ff, 0, sizeof(fifo_t));
+}
+void test_create_null(void)
+{
+ memset(&ff, 0, sizeof(fifo_t)); // clear fifo to test null created
+ TEST_ASSERT_FALSE( fifo_init(&ff, buffer, 0, 0, 0) );
+ TEST_ASSERT_TRUE( fifo_init(&ff, buffer, 1, 0, 0) );
}
-void test_()
+void test_normal(void)
{
- TEST_IGNORE();
+ uint8_t i;
+
+ for(i=0; i < FIFO_SIZE; i++)
+ {
+ fifo_write(&ff, i);
+ }
+
+ for(i=0; i < FIFO_SIZE; i++)
+ {
+ uint8_t c;
+ fifo_read(&ff, &c);
+ TEST_ASSERT_EQUAL(i, c);
+ }
}
+void test_is_empty(void)
+{
+ TEST_ASSERT_TRUE(fifo_isEmpty(&ff));
+ fifo_write(&ff, 1);
+ TEST_ASSERT_FALSE(fifo_isEmpty(&ff));
+}
+
+void test_is_full(void)
+{
+ uint8_t i;
+
+ TEST_ASSERT_FALSE(fifo_isFull(&ff));
+
+ for(i=0; i < FIFO_SIZE; i++)
+ {
+ fifo_write(&ff, i);
+ }
+
+ TEST_ASSERT_TRUE(fifo_isFull(&ff));
+}
diff --git a/tinyusb/common/fifo.h b/tinyusb/common/fifo.h
index ea50bc563..c79299352 100644
--- a/tinyusb/common/fifo.h
+++ b/tinyusb/common/fifo.h
@@ -66,7 +66,7 @@ typedef struct _fifo_t
volatile uint16_t wr_ptr ; ///< write pointer
volatile uint16_t rd_ptr ; ///< read pointer
bool overwritable ; ///< allow overwrite data when full
- IRQn_Type irq ; ///< interrupt used to lock fifo
+ IRQn_Type irq ; ///< TODO (abstract later) interrupt used to lock fifo
} fifo_t;
bool fifo_init(fifo_t* f, uint8_t* buffer, uint16_t size, bool overwritable, IRQn_Type irq);