added some tests for fifo.c

This commit is contained in:
hathach 2013-01-16 13:25:02 +07:00
parent c004cd4387
commit 8155fd38a5
3 changed files with 51 additions and 6 deletions

View File

@ -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:

View File

@ -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_()
void test_create_null(void)
{
TEST_IGNORE();
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_normal(void)
{
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));
}

View File

@ -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);