Microchip® Advanced Software Framework

common/drivers/nvm/unit_tests/unit_tests.c File Reference

Common NVM driver Unit Test.

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

#include <stdint.h>
#include <stdbool.h>
#include <asf.h>
#include <string.h>
#include "common_nvm.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...
 

Functions

int main (void)
 Run common NVM driver unit tests. More...
 
static void run_buffer_access_test (const struct test_case *test)
 Test the read and write buffer operations on the NVM. More...
 
static void run_byte_access_test (const struct test_case *test)
 Test the read and write byte operations on the NVM. More...
 
static void run_memory_check_test (const struct test_case *test)
 Performs a memory check on the non volatile memory. More...
 

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

Generates byte pattern 1 for a given address.

Referenced by run_byte_access_test().

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

Generates byte pattern 2 for a given address.

Referenced by run_buffer_access_test().

int main ( void  )

Run common NVM driver unit tests.

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

References uart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_buffer_access_test(), run_byte_access_test(), run_memory_check_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.

static void run_buffer_access_test ( const struct test_case test)
static

Test the read and write buffer operations on the NVM.

This function will test the read and write functionalities of the NVM using buffer access. It will first fill a buffer with a known pattern and read it back by testing each value read.

Parameters
testCurrent test case.

References BYTE_PATTERN2, INT_FLASH, nvm_page_erase(), nvm_read(), nvm_write(), status, STATUS_OK, and test_assert_true.

Referenced by main().

static void run_byte_access_test ( const struct test_case test)
static

Test the read and write byte operations on the NVM.

This function will test the read and write functionalities of the NVM using byte access. It will first write a known pattern on the 2 consecutive addresses and read it back by testing each value read.

Parameters
testCurrent test case.

References BYTE_PATTERN1, INT_FLASH, nvm_page_erase(), nvm_read_char(), nvm_write_char(), read_data(), status, STATUS_OK, and test_assert_true.

Referenced by main().

static void run_memory_check_test ( const struct test_case test)
static

Performs a memory check on the non volatile memory.

This function will simply test the output of the function nvm_init and returns an error in case of failure.

Parameters
testCurrent test case.

References INT_FLASH, nvm_init(), status, STATUS_OK, and test_assert_true.

Referenced by main().