mirror of
https://github.com/nqtronix/fifofast.git
synced 2026-02-06 09:02:54 +08:00
Implement tests for '_fff_rebase()'
This commit is contained in:
@@ -39,14 +39,13 @@ int main(void)
|
||||
fifofast_test_macro_add(0x40);
|
||||
fifofast_test_macro_remove_lite(0x50);
|
||||
fifofast_test_macro_remove(0x60);
|
||||
fifofast_test_macro_rebase(0x70);
|
||||
|
||||
fifofast_test_func_initial((fff_proto_t*)&fifo_uint8p);
|
||||
fifofast_test_func_write((fff_proto_t*)&fifo_uint8p, 0x70);
|
||||
fifofast_test_func_peek((fff_proto_t*)&fifo_uint8p, 0x80);
|
||||
fifofast_test_func_read((fff_proto_t*)&fifo_uint8p, 0x90);
|
||||
fifofast_test_func_add((fff_proto_t*)&fifo_uint8p, 0xa0);
|
||||
fifofast_test_func_remove_lite((fff_proto_t*)&fifo_uint8p, 0xb0);
|
||||
fifofast_test_func_remove((fff_proto_t*)&fifo_uint8p, 0xc0);
|
||||
fifofast_test_func_write((fff_proto_t*)&fifo_uint8p, 0x80);
|
||||
fifofast_test_func_peek((fff_proto_t*)&fifo_uint8p, 0x90);
|
||||
fifofast_test_func_remove_lite((fff_proto_t*)&fifo_uint8p, 0xa0);
|
||||
fifofast_test_func_remove((fff_proto_t*)&fifo_uint8p, 0xb0);
|
||||
|
||||
UT_BREAK();
|
||||
|
||||
|
||||
212
fifofast_test.c
212
fifofast_test.c
@@ -245,6 +245,135 @@ void fifofast_test_macro_remove(uint8_t startvalue)
|
||||
UT_ASSERT(_fff_is_full(fifo_uint8) == 0);
|
||||
}
|
||||
|
||||
void fifofast_test_macro_rebase(uint8_t startvalue)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Test 1: no rebase needed
|
||||
|
||||
// fill with any data (macros have been proved to work before)
|
||||
_fff_write_lite(fifo_uint8, startvalue+0);
|
||||
_fff_write_lite(fifo_uint8, startvalue+1);
|
||||
_fff_write_lite(fifo_uint8, startvalue+2);
|
||||
_fff_write_lite(fifo_uint8, startvalue+3);
|
||||
|
||||
_fff_rebase(fifo_uint8);
|
||||
|
||||
// Confirm it is exactly like before:
|
||||
UT_ASSERT(_fff_mem_level(fifo_uint8) == 4);
|
||||
UT_ASSERT(_fff_mem_free(fifo_uint8) == 0);
|
||||
UT_ASSERT(_fff_is_empty(fifo_uint8) == 0);
|
||||
UT_ASSERT(_fff_is_full(fifo_uint8) != 0);
|
||||
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 0) == startvalue+0);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 1) == startvalue+1);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 2) == startvalue+2);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 3) == startvalue+3);
|
||||
|
||||
// confirm that the element 0 is at array index 0
|
||||
UT_ASSERT(&_fff_peek(fifo_uint8, 0) == &fifo_uint8.data[0]);
|
||||
|
||||
_fff_reset(fifo_uint8);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Test 3: move 2 elements
|
||||
|
||||
// fill with any data (macros have been proved to work before)
|
||||
_fff_write_lite(fifo_uint8, startvalue+0);
|
||||
_fff_write_lite(fifo_uint8, startvalue+1);
|
||||
_fff_write_lite(fifo_uint8, startvalue+2);
|
||||
_fff_write_lite(fifo_uint8, startvalue+3);
|
||||
|
||||
_fff_read_lite(fifo_uint8);
|
||||
_fff_write_lite(fifo_uint8, startvalue+4);
|
||||
|
||||
_fff_rebase(fifo_uint8);
|
||||
|
||||
// Confirm it is exactly like before:
|
||||
UT_ASSERT(_fff_mem_level(fifo_uint8) == 4);
|
||||
UT_ASSERT(_fff_mem_free(fifo_uint8) == 0);
|
||||
UT_ASSERT(_fff_is_empty(fifo_uint8) == 0);
|
||||
UT_ASSERT(_fff_is_full(fifo_uint8) != 0);
|
||||
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 0) == startvalue+1);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 1) == startvalue+2);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 2) == startvalue+3);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 3) == startvalue+4);
|
||||
|
||||
// confirm that the element 0 is at array index 0
|
||||
UT_ASSERT(&_fff_peek(fifo_uint8, 0) == &fifo_uint8.data[0]);
|
||||
|
||||
_fff_reset(fifo_uint8);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Test 3: move 2 elements
|
||||
|
||||
// fill with any data (macros have been proved to work before)
|
||||
_fff_write_lite(fifo_uint8, startvalue+0);
|
||||
_fff_write_lite(fifo_uint8, startvalue+1);
|
||||
_fff_write_lite(fifo_uint8, startvalue+2);
|
||||
_fff_write_lite(fifo_uint8, startvalue+3);
|
||||
|
||||
_fff_read_lite(fifo_uint8);
|
||||
_fff_read_lite(fifo_uint8);
|
||||
_fff_write_lite(fifo_uint8, startvalue+4);
|
||||
_fff_write_lite(fifo_uint8, startvalue+5);
|
||||
|
||||
_fff_rebase(fifo_uint8);
|
||||
|
||||
// Confirm it is exactly like before:
|
||||
UT_ASSERT(_fff_mem_level(fifo_uint8) == 4);
|
||||
UT_ASSERT(_fff_mem_free(fifo_uint8) == 0);
|
||||
UT_ASSERT(_fff_is_empty(fifo_uint8) == 0);
|
||||
UT_ASSERT(_fff_is_full(fifo_uint8) != 0);
|
||||
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 0) == startvalue+2);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 1) == startvalue+3);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 2) == startvalue+4);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 3) == startvalue+5);
|
||||
|
||||
// confirm that the element 0 is at array index 0
|
||||
UT_ASSERT(&_fff_peek(fifo_uint8, 0) == &fifo_uint8.data[0]);
|
||||
|
||||
_fff_reset(fifo_uint8);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Test 2: move 3 elements
|
||||
|
||||
// fill with any data (macros have been proved to work before)
|
||||
_fff_write_lite(fifo_uint8, startvalue+0);
|
||||
_fff_write_lite(fifo_uint8, startvalue+1);
|
||||
_fff_write_lite(fifo_uint8, startvalue+2);
|
||||
_fff_write_lite(fifo_uint8, startvalue+3);
|
||||
|
||||
_fff_read_lite(fifo_uint8);
|
||||
_fff_read_lite(fifo_uint8);
|
||||
_fff_read_lite(fifo_uint8);
|
||||
_fff_write_lite(fifo_uint8, startvalue+4);
|
||||
_fff_write_lite(fifo_uint8, startvalue+5);
|
||||
_fff_write_lite(fifo_uint8, startvalue+6);
|
||||
|
||||
_fff_rebase(fifo_uint8);
|
||||
|
||||
// Confirm it is exactly like before:
|
||||
UT_ASSERT(_fff_mem_level(fifo_uint8) == 4);
|
||||
UT_ASSERT(_fff_mem_free(fifo_uint8) == 0);
|
||||
UT_ASSERT(_fff_is_empty(fifo_uint8) == 0);
|
||||
UT_ASSERT(_fff_is_full(fifo_uint8) != 0);
|
||||
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 0) == startvalue+3);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 1) == startvalue+4);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 2) == startvalue+5);
|
||||
UT_ASSERT(_fff_peek(fifo_uint8, 3) == startvalue+6);
|
||||
|
||||
// confirm that the element 0 is at array index 0
|
||||
UT_ASSERT(&_fff_peek(fifo_uint8, 0) == &fifo_uint8.data[0]);
|
||||
|
||||
_fff_reset(fifo_uint8);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Test Functions
|
||||
@@ -335,89 +464,6 @@ void fifofast_test_func_peek(fff_proto_t* fifo, uint8_t startvalue)
|
||||
fff_reset(fifo);
|
||||
}
|
||||
|
||||
void fifofast_test_func_read(fff_proto_t* fifo, uint8_t startvalue)
|
||||
{
|
||||
// uint8_t tmp0 = startvalue+0;
|
||||
// uint8_t tmp1 = startvalue+1;
|
||||
// uint8_t tmp2 = startvalue+2;
|
||||
// fff_write_lite(fifo, &tmp0);
|
||||
// fff_write_lite(fifo, &tmp1);
|
||||
// fff_write_lite(fifo, &tmp2);
|
||||
//
|
||||
// // read 2 values with the fast '_lite' variant (we know we have more than two entries)
|
||||
// UT_ASSERT(fff_read_lite(fifo) == startvalue+0);
|
||||
// UT_ASSERT(fff_read_lite(fifo) == startvalue+1);
|
||||
//
|
||||
// UT_ASSERT(fff_mem_level(fifo) == 1);
|
||||
// UT_ASSERT(fff_mem_free(fifo) == 2);
|
||||
// UT_ASSERT(fff_is_empty(fifo) == 0);
|
||||
// UT_ASSERT(fff_is_full(fifo) == 0);
|
||||
//
|
||||
// UT_ASSERT(*(uint8_t*)fff_peek_read(fifo, 0) == startvalue+2);
|
||||
//
|
||||
// // read 2 values to demonstrate overflow safety
|
||||
// UT_ASSERT(fff_read(fifo) == startvalue+2);
|
||||
// UT_ASSERT(fff_read(fifo) == 0x00);
|
||||
//
|
||||
// UT_ASSERT(fff_mem_level(fifo) == 0);
|
||||
// UT_ASSERT(fff_mem_free(fifo) == 3);
|
||||
// UT_ASSERT(fff_is_empty(fifo) != 0);
|
||||
// UT_ASSERT(fff_is_full(fifo) == 0);
|
||||
|
||||
fff_reset(fifo);
|
||||
}
|
||||
|
||||
void fifofast_test_func_add(fff_proto_t* fifo, uint8_t startvalue)
|
||||
{
|
||||
// __attribute__ ((unused)) volatile uint8_t* dbg_p0 = 0;
|
||||
// __attribute__ ((unused)) volatile uint8_t* dbg_p1 = 0;
|
||||
// __attribute__ ((unused)) volatile uint8_t* dbg_p2 = 0;
|
||||
//
|
||||
// // add 2 values with the fast '_lite' variant (after init we know it is empty)
|
||||
// dbg_p0 = fff_add_lite(fifo);
|
||||
// dbg_p1 = fff_add_lite(fifo);
|
||||
//
|
||||
// UT_ASSERT(dbg_p0 != 0);
|
||||
// UT_ASSERT(dbg_p1 != 0);
|
||||
//
|
||||
// if(dbg_p0 != 0) *dbg_p0 = startvalue+0;
|
||||
// if(dbg_p1 != 0) *dbg_p1 = startvalue+1;
|
||||
//
|
||||
// UT_ASSERT(fff_mem_level(fifo) == 2);
|
||||
// UT_ASSERT(fff_mem_free(fifo) == 1);
|
||||
// UT_ASSERT(fff_is_empty(fifo) == 0);
|
||||
// UT_ASSERT(fff_is_full(fifo) == 0);
|
||||
//
|
||||
// UT_ASSERT(*(uint8_t*)fff_peek_read(fifo, 0) == startvalue+0);
|
||||
// UT_ASSERT(*(uint8_t*)fff_peek_read(fifo, 1) == startvalue+1);
|
||||
//
|
||||
//
|
||||
// // add 3 values to demonstrate overflow safety
|
||||
// dbg_p0 = fff_add(fifo);
|
||||
// dbg_p1 = fff_add(fifo);
|
||||
// dbg_p2 = fff_add(fifo);
|
||||
//
|
||||
// UT_ASSERT(dbg_p0 != 0);
|
||||
// UT_ASSERT(dbg_p1 != 0);
|
||||
// UT_ASSERT(dbg_p2 == 0); // the fifo is full, so a null pointer must be returned
|
||||
//
|
||||
// if(dbg_p0 != 0) *dbg_p0 = startvalue+2;
|
||||
// if(dbg_p1 != 0) *dbg_p1 = startvalue+3;
|
||||
// if(dbg_p2 != 0) *dbg_p2 = startvalue+4;
|
||||
//
|
||||
// UT_ASSERT(fff_mem_level(fifo) == 3);
|
||||
// UT_ASSERT(fff_mem_free(fifo) == 0);
|
||||
// UT_ASSERT(fff_is_empty(fifo) == 0);
|
||||
// UT_ASSERT(fff_is_full(fifo) != 0);
|
||||
//
|
||||
// UT_ASSERT(*(uint8_t*)fff_peek_read(fifo, 0) == startvalue+0);
|
||||
// UT_ASSERT(*(uint8_t*)fff_peek_read(fifo, 1) == startvalue+1);
|
||||
// UT_ASSERT(*(uint8_t*)fff_peek_read(fifo, 2) == startvalue+2);
|
||||
// UT_ASSERT(*(uint8_t*)fff_peek_read(fifo, 3) == startvalue+3);
|
||||
|
||||
fff_reset(fifo);
|
||||
}
|
||||
|
||||
void fifofast_test_func_remove_lite(fff_proto_t* fifo, uint8_t startvalue)
|
||||
{
|
||||
// fill with any data (macros have been proved to work before)
|
||||
|
||||
@@ -26,12 +26,11 @@ void fifofast_test_macro_read(uint8_t startvalue);
|
||||
void fifofast_test_macro_add(uint8_t startvalue);
|
||||
void fifofast_test_macro_remove_lite(uint8_t startvalue);
|
||||
void fifofast_test_macro_remove(uint8_t startvalue);
|
||||
void fifofast_test_macro_rebase(uint8_t startvalue);
|
||||
|
||||
void fifofast_test_func_initial(fff_proto_t* fifo);
|
||||
void fifofast_test_func_write(fff_proto_t* fifo, uint8_t startvalue);
|
||||
void fifofast_test_func_peek(fff_proto_t* fifo, uint8_t startvalue);
|
||||
void fifofast_test_func_read(fff_proto_t* fifo, uint8_t startvalue);
|
||||
void fifofast_test_func_add(fff_proto_t* fifo, uint8_t startvalue);
|
||||
void fifofast_test_func_remove_lite(fff_proto_t* fifo, uint8_t startvalue);
|
||||
void fifofast_test_func_remove(fff_proto_t* fifo, uint8_t startvalue);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user