Atmel Software Framework

common/services/fifo/unit_tests/unit_tests.c File Reference

Unit tests for First In First Out buffer service.

Copyright (c) 2011 - 2012 Atmel Corporation. All rights reserved.

#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().

static void run_fifo_flush_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_fifo_overflow_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References FIFO_ERROR_OVERFLOW, fifo_flush(), FIFO_OK, fifo_push_uint16(), fifo_push_uint32(), fifo_push_uint8(), i, status, test_assert_true, TEST_FIFO_BUFFER_LENGTH, and TEST_VALUE.

Referenced by main().

static void run_fifo_push_pull_test ( const struct test_case test)
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.

Note
The elements are pushed with increasing datatype size to prevent corruption of the buffer contents. This is due to the FIFO indexes its buffer based on the datatype that is being pulled or pushed.
Parameters
testCurrent 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 void run_fifo_size_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_fifo_underflow_test ( const struct test_case test)
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.

Parameters
testCurrent 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.

Precondition
The descriptor must be initialized with fifo_init() before the FIFO buffer can be used.
Note
The FIFO buffer should be used with only one of its supported datatypes at a time, or the buffered values will be corrupted unless special conditions are met.