Microchip® Advanced Software Framework

unit_test.c File Reference

SAM NVM Unit test.

Copyright (c) 2013-2020 Microchip Technology Inc. and its subsidiaries.

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

Macros

#define BYTE_PATTERN1(x)   ((uint8_t)(((x) * 5 + 1) & 0xff))
 Generates byte pattern 1 for a given address. More...
 
#define BYTE_PATTERN2(x)   ((uint8_t)(((x) * 3) & 0xff))
 Generates byte pattern 2 for a given address. More...
 
#define TEST_PAGE_ADDR   (FLASH_NB_OF_PAGES - 8) * NVMCTRL_PAGE_SIZE
 

Functions

static void cdc_uart_init (void)
 Initialize USART for unit tests. More...
 
int main (void)
 Run NVM unit tests. More...
 
static void run_nvm_erase_test (const struct test_case *test)
 Test NVM erasing. More...
 
static void run_nvm_init_test (const struct test_case *test)
 Test NVM initialization. More...
 
static void run_nvm_parameter_test (const struct test_case *test)
 Test get flash parameter function. More...
 
static void run_nvm_read_and_write_test (const struct test_case *test)
 Test NVM writing. More...
 
static void run_nvm_update_test (const struct test_case *test)
 Test NVM update. More...
 

Variables

struct usart_module cdc_uart_module
 
static volatile bool nvm_init_success = false
 

#define BYTE_PATTERN1 (   x)    ((uint8_t)(((x) * 5 + 1) & 0xff))

Generates byte pattern 1 for a given address.

Referenced by run_nvm_read_and_write_test(), and run_nvm_update_test().

#define BYTE_PATTERN2 (   x)    ((uint8_t)(((x) * 3) & 0xff))

Generates byte pattern 2 for a given address.

Referenced by run_nvm_update_test().

#define TEST_PAGE_ADDR   (FLASH_NB_OF_PAGES - 8) * NVMCTRL_PAGE_SIZE

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

Run NVM unit tests.

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

References cdc_uart_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_nvm_erase_test(), run_nvm_init_test(), run_nvm_parameter_test(), run_nvm_read_and_write_test(), run_nvm_update_test(), system_init(), and test_suite_run().

static void run_nvm_erase_test ( const struct test_case test)
static

Test NVM erasing.

This test erases test row and verifies it

Parameters
testCurrent test case.

References nvm_erase_row(), nvm_init_success, STATUS_OK, test_assert_true, and TEST_PAGE_ADDR.

Referenced by main().

static void run_nvm_init_test ( const struct test_case test)
static

Test NVM initialization.

This function will write the default configuration to NVM and returns an error in case of failure.

Parameters
testCurrent test case.

References nvm_config::manual_page_write, nvm_get_config_defaults(), nvm_init_success, nvm_set_config(), STATUS_OK, test_assert_true, and nvm_config::wait_states.

Referenced by main().

static void run_nvm_parameter_test ( const struct test_case test)
static

Test get flash parameter function.

This test gets the nvm parameters from the function and checks the NVM page count and NVM page size

Parameters
testCurrent test case.

References nvm_get_parameters(), nvm_parameters::nvm_number_of_pages, nvm_parameters::page_size, and test_assert_true.

Referenced by main().

static void run_nvm_read_and_write_test ( const struct test_case test)
static

Test NVM writing.

This test writes erased test page with a pattern, reads it back and checks the integrity

Parameters
testCurrent test case.

References BYTE_PATTERN1, nvm_init_success, nvm_read_buffer(), nvm_write_buffer(), STATUS_OK, test_assert_true, and TEST_PAGE_ADDR.

Referenced by main().

static void run_nvm_update_test ( const struct test_case test)
static

Test NVM update.

This test modifies first half of the test page with different pattern, reads it back and checks whether the values are updated

Parameters
testCurrent test case.

References BYTE_PATTERN1, BYTE_PATTERN2, nvm_init_success, nvm_read_buffer(), nvm_update_buffer(), STATUS_OK, test_assert_true, and TEST_PAGE_ADDR.

Referenced by main().

struct usart_module cdc_uart_module

Referenced by cdc_uart_init().