Unit tests for First In First Out buffer service.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <compiler.h>
#include <conf_test.h>
#include <asf.h>
Data Structures | |
union | buffer_element |
Datatype for the FIFO buffer. More... | |
Macros | |
#define | TEST_FIFO_BUFFER_LENGTH 4 |
Size of buffer, as number of buffer_element. More... | |
#define | TEST_VALUE 0x12345678 |
Common value to use when pushing the different datatypes. More... | |
Functions | |
int | main (void) |
Run FIFO service unit tests. More... | |
FIFO unit test functions | |
static void | run_fifo_size_test (const struct test_case *test) |
Test size-checking functions on non-empty buffer. More... | |
static void | run_fifo_flush_test (const struct test_case *test) |
Test size-checking function on flushed buffer. More... | |
static void | run_fifo_underflow_test (const struct test_case *test) |
Test that underflow is reported. More... | |
static void | run_fifo_overflow_test (const struct test_case *test) |
Test that overflow is reported. More... | |
static void | run_fifo_push_pull_test (const struct test_case *test) |
Test push and pull. More... | |
Variables | |
union buffer_element | test_fifo_buffer [TEST_FIFO_BUFFER_LENGTH] |
Buffer to associate with FIFO. More... | |
fifo_desc_t | test_fifo_desc |
FIFO buffer descriptor to use. More... | |
#define TEST_FIFO_BUFFER_LENGTH 4 |
Size of buffer, as number of buffer_element.
Referenced by main(), run_fifo_flush_test(), run_fifo_overflow_test(), and run_fifo_size_test().
#define TEST_VALUE 0x12345678 |
Common value to use when pushing the different datatypes.
Referenced by run_fifo_flush_test(), run_fifo_overflow_test(), run_fifo_push_pull_test(), and run_fifo_size_test().
int main | ( | void | ) |
Run FIFO service unit tests.
Initializes the clock system, board, serial output and FIFO, then sets up the FIFO unit test suite and runs it.
References uart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, fifo_init(), NULL, run_fifo_flush_test(), run_fifo_overflow_test(), run_fifo_push_pull_test(), run_fifo_size_test(), run_fifo_underflow_test(), stdio_serial_init(), sysclk_init(), test_fifo_buffer, TEST_FIFO_BUFFER_LENGTH, test_suite_run(), and usart_serial_options.
|
static |
Test size-checking function on flushed buffer.
This test pushes one element to the buffer, then flushes it before checking that the functions for checking size return the expected values.
test | Current test case. |
References fifo_flush(), fifo_get_free_size(), fifo_get_used_size(), fifo_is_empty(), fifo_push_uint8(), status, test_assert_true, TEST_FIFO_BUFFER_LENGTH, and TEST_VALUE.
Referenced by main().
|
static |
Test that overflow is reported.
This test flushes the buffer and fills it with at least one element of every supported datatype, before attempting to push one more element of each type, checking that a buffer overflow is reported for all of them.
test | Current test case. |
References FIFO_ERROR_OVERFLOW, fifo_flush(), FIFO_OK, fifo_push_uint16(), fifo_push_uint32(), fifo_push_uint8(), status, test_assert_true, TEST_FIFO_BUFFER_LENGTH, and TEST_VALUE.
Referenced by main().
|
static |
Test push and pull.
This test pushes an element of every supported datatype, with increasing size, to the buffer. The elements are then pulled in the same order and their values verified.
test | Current test case. |
References buffer_element::byte, fifo_flush(), FIFO_OK, fifo_pull_uint16(), fifo_pull_uint32(), fifo_pull_uint8(), fifo_push_uint16(), fifo_push_uint32(), fifo_push_uint8(), buffer_element::halfword, status, test_assert_true, TEST_VALUE, and buffer_element::word.
Referenced by main().
|
static |
Test size-checking functions on non-empty buffer.
This test flushes the buffer, then pushes one element to it before checking that the functions for checking size return the expected values.
test | Current test case. |
References fifo_flush(), fifo_get_free_size(), fifo_get_used_size(), fifo_is_empty(), fifo_push_uint8(), status, test_assert_false, test_assert_true, TEST_FIFO_BUFFER_LENGTH, and TEST_VALUE.
Referenced by main().
|
static |
Test that underflow is reported.
This test flushes the buffer and attempts to pull an element of every supported datatype, checking that a buffer underflow is reported for all of them.
test | Current test case. |
References buffer_element::byte, FIFO_ERROR_UNDERFLOW, fifo_flush(), fifo_pull_uint16(), fifo_pull_uint32(), fifo_pull_uint8(), buffer_element::halfword, status, test_assert_true, and buffer_element::word.
Referenced by main().
union buffer_element test_fifo_buffer[TEST_FIFO_BUFFER_LENGTH] |
Buffer to associate with FIFO.
This buffer consists of TEST_FIFO_BUFFER_LENGTH elements capable of holding a byte, halfword or word.
Referenced by main().
fifo_desc_t test_fifo_desc |
FIFO buffer descriptor to use.
This descriptor contains information about the location of the FIFO buffer, its size and where to read from or write to upon the next buffer pull or push. This is required to access the FIFO buffer via the FIFO service.