Microchip® Advanced Software Framework

unit_test.c File Reference

SAM EEPROM Emulator Service Unit test.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <stdio_serial.h>
#include <string.h>
#include "conf_test.h"

Macros

#define TEST_BUFFER_OFFSET   123
 
#define TEST_BUFFER_SIZE   19
 
#define TEST_EEPROM_PAGE   1
 

Functions

static void cdc_uart_init (void)
 Initialize the USART for unit test. More...
 
int main (void)
 Run EEPROM emulator unit tests. More...
 
static void run_eeprom_buffer_read_write_test (const struct test_case *test)
 Test for EEPROM emulator buffer read/write function. More...
 
static void run_eeprom_init_test (const struct test_case *test)
 Test for EEPROM emulator initialization. More...
 
static void run_eeprom_page_read_write_test (const struct test_case *test)
 Test for EEPROM emulator page read/write function. More...
 
static void setup_eeprom_buffer_read_write_test (const struct test_case *test)
 Setup function for EEPROM emulator buffer read/write test. More...
 
static void setup_eeprom_page_read_write_test (const struct test_case *test)
 Setup function for EEPROM emulator page read/write test. More...
 

Variables

struct usart_module cdc_uart_module
 
struct eeprom_emulator_parameters ee_params
 
uint16_t i
 
volatile bool init_success
 
uint8_t test_buffer [TEST_BUFFER_SIZE]
 
uint8_t test_page [EEPROM_PAGE_SIZE]
 
uint8_t verify_buffer [TEST_BUFFER_SIZE]
 
uint8_t verify_page [EEPROM_PAGE_SIZE]
 

#define TEST_BUFFER_OFFSET   123
#define TEST_BUFFER_SIZE   19
#define TEST_EEPROM_PAGE   1

static void cdc_uart_init ( void  )
static
int main ( void  )

Run EEPROM emulator unit tests.

Initializes the system and serial output, then sets up the EEPROM emulator unit test suite and runs it.

References cdc_uart_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_eeprom_buffer_read_write_test(), run_eeprom_init_test(), run_eeprom_page_read_write_test(), setup_eeprom_buffer_read_write_test(), setup_eeprom_page_read_write_test(), system_init(), and test_suite_run().

static void run_eeprom_buffer_read_write_test ( const struct test_case test)
static

Test for EEPROM emulator buffer read/write function.

This test writes a buffer of data of a given length to a given offset. It then reads back the data from that offset and verifies.

Parameters
testCurrent test case.

References eeprom_emulator_commit_page_buffer(), eeprom_emulator_read_buffer(), eeprom_emulator_write_buffer(), i, init_success, STATUS_OK, test_assert_true, test_buffer, TEST_BUFFER_OFFSET, TEST_BUFFER_SIZE, and verify_buffer.

Referenced by main().

static void run_eeprom_init_test ( const struct test_case test)
static

Test for EEPROM emulator initialization.

This test initializes the EEPROM emulator. If no memory was set for EEPROM in the fuses then all test will be skipped. During initialization it will format the EEPROM memory if it was not done previously.

It also checks the get parameter functionality.

Parameters
testCurrent test case.

References ee_params, eeprom_emulator_erase_memory(), eeprom_emulator_get_parameters(), eeprom_emulator_init(), EEPROM_PAGE_SIZE, init_success, eeprom_emulator_parameters::page_size, STATUS_ERR_NO_MEMORY, STATUS_OK, and test_assert_true.

Referenced by main().

static void run_eeprom_page_read_write_test ( const struct test_case test)
static

Test for EEPROM emulator page read/write function.

This test writes a page of data to a given page number. It then reads back the page and verifies.

Parameters
testCurrent test case.

References eeprom_emulator_commit_page_buffer(), eeprom_emulator_read_page(), eeprom_emulator_write_page(), EEPROM_PAGE_SIZE, i, init_success, STATUS_OK, test_assert_true, TEST_EEPROM_PAGE, test_page, and verify_page.

Referenced by main().

static void setup_eeprom_buffer_read_write_test ( const struct test_case test)
static

Setup function for EEPROM emulator buffer read/write test.

This function initializes the test buffer and verify buffer with appropriate values.

Parameters
testCurrent test case.

References i, test_buffer, TEST_BUFFER_SIZE, and verify_buffer.

Referenced by main().

static void setup_eeprom_page_read_write_test ( const struct test_case test)
static

Setup function for EEPROM emulator page read/write test.

This function initializes the test_page and verify_page data arrays with appropriate values.

Parameters
testCurrent test case.

References EEPROM_PAGE_SIZE, i, test_page, and verify_page.

Referenced by main().

struct usart_module cdc_uart_module

Referenced by cdc_uart_init().

struct eeprom_emulator_parameters ee_params

Referenced by run_eeprom_init_test().