Unit tests for Non Volatile Memory controller driver.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <nvm.h>
#include <string.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
Macros | |
Device signature readout unit test macros | |
#define | CHIP_DEVID0 SIGNATURE_0 |
Macro for device ID byte 0 in device header file. More... | |
#define | CHIP_DEVID1 SIGNATURE_1 |
Macro for device ID byte 1 in device header file. More... | |
#define | CHIP_DEVID2 SIGNATURE_2 |
Macro for device ID byte 2 in device header file. More... | |
EEPROM read/write access unit test macros | |
#define | EEPROM_ERASED 0xff |
Content of an erased EEPROM byte. More... | |
#define | TEST_ERASE_PAGE 2 |
EEPROM page to use in erase test. More... | |
#define | TEST_WRITE_PAGE 1 |
EEPROM page to use in write test. More... | |
#define | TEST_ATOMIC_WRITE_PAGE 2 |
EEPROM page to use in atomic write test. More... | |
#define | TEST_SPLIT_WRITE_PAGE 3 |
EEPROM page to use in split write test. More... | |
#define | TEST_ERASE_BYTES_PAGE_1 4 |
EEPROM page 1 of 2 to use in erase byte test. More... | |
#define | TEST_ERASE_BYTES_PAGE_2 5 |
EEPROM page 2 of 2 to use in erase byte test. More... | |
#define | TEST_READ_BUFFER_PAGE 6 |
EEPROM page to use in read buffer test. More... | |
#define | TEST_WRITE_BUFFER_PAGE 7 |
EEPROM page to use in write buffer test. More... | |
Functions | |
int | main (void) |
Run NVM driver unit tests. More... | |
Device signature readout unit test functions | |
static void | run_device_id_test (const struct test_case *test) |
Test device ID readout. More... | |
static void | run_device_serial_test (const struct test_case *test) |
Test device serial number readout. More... | |
EEPROM read/write access unit test functions | |
static void | run_eeprom_erase_test (const struct test_case *test) |
Test EEPROM erase. More... | |
static void | run_eeprom_write_test (const struct test_case *test) |
Test EEPROM write. More... | |
static void | run_eeprom_atomic_write_test (const struct test_case *test) |
Test EEPROM atomic write. More... | |
static void | run_eeprom_split_write_test (const struct test_case *test) |
Test EEPROM split write. More... | |
static void | run_eeprom_erase_byte_test (const struct test_case *test) |
Test EEPROM byte erase. More... | |
static void | run_eeprom_read_buffer_test (const struct test_case *test) |
Test EEPROM read buffer. More... | |
static void | run_eeprom_write_buffer_test (const struct test_case *test) |
Test EEPROM write buffer. More... | |
Helper functions and macros | |
#define | set_buffer(buffer, value) memset(buffer, value, sizeof(buffer)) |
Set all bytes in buffer to value. More... | |
static bool | is_eeprom_page_equal_to_buffer (uint8_t page, uint8_t *buffer) |
Check if EEPROM page is equal to memory buffer. More... | |
#define CHIP_DEVID0 SIGNATURE_0 |
Macro for device ID byte 0 in device header file.
Referenced by run_device_id_test().
#define CHIP_DEVID1 SIGNATURE_1 |
Macro for device ID byte 1 in device header file.
Referenced by run_device_id_test().
#define CHIP_DEVID2 SIGNATURE_2 |
Macro for device ID byte 2 in device header file.
Referenced by run_device_id_test().
#define EEPROM_ERASED 0xff |
Content of an erased EEPROM byte.
Referenced by run_eeprom_atomic_write_test(), run_eeprom_erase_byte_test(), run_eeprom_erase_test(), run_eeprom_read_buffer_test(), run_eeprom_split_write_test(), run_eeprom_write_buffer_test(), and run_eeprom_write_test().
Set all bytes in buffer to value.
Referenced by run_eeprom_atomic_write_test(), run_eeprom_erase_byte_test(), run_eeprom_erase_test(), run_eeprom_read_buffer_test(), run_eeprom_split_write_test(), run_eeprom_write_buffer_test(), and run_eeprom_write_test().
#define TEST_ATOMIC_WRITE_PAGE 2 |
EEPROM page to use in atomic write test.
Referenced by run_eeprom_atomic_write_test().
#define TEST_ERASE_BYTES_PAGE_1 4 |
EEPROM page 1 of 2 to use in erase byte test.
Referenced by run_eeprom_erase_byte_test().
#define TEST_ERASE_BYTES_PAGE_2 5 |
EEPROM page 2 of 2 to use in erase byte test.
Referenced by run_eeprom_erase_byte_test().
#define TEST_ERASE_PAGE 2 |
EEPROM page to use in erase test.
Referenced by run_eeprom_erase_test().
#define TEST_READ_BUFFER_PAGE 6 |
EEPROM page to use in read buffer test.
Referenced by run_eeprom_read_buffer_test().
#define TEST_SPLIT_WRITE_PAGE 3 |
EEPROM page to use in split write test.
Referenced by run_eeprom_split_write_test().
#define TEST_WRITE_BUFFER_PAGE 7 |
EEPROM page to use in write buffer test.
Referenced by run_eeprom_write_buffer_test().
#define TEST_WRITE_PAGE 1 |
EEPROM page to use in write test.
Referenced by run_eeprom_write_test().
|
static |
Check if EEPROM page is equal to memory buffer.
Referenced by run_eeprom_atomic_write_test(), run_eeprom_erase_byte_test(), run_eeprom_erase_test(), run_eeprom_read_buffer_test(), run_eeprom_split_write_test(), run_eeprom_write_buffer_test(), and run_eeprom_write_test().
int main | ( | void | ) |
Run NVM driver unit tests.
References usart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_device_id_test(), run_device_serial_test(), run_eeprom_atomic_write_test(), run_eeprom_erase_byte_test(), run_eeprom_erase_test(), run_eeprom_read_buffer_test(), run_eeprom_split_write_test(), run_eeprom_write_buffer_test(), run_eeprom_write_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.
|
static |
Test device ID readout.
This test reads out the DEVIDn registers and compares their value with the expected device ID for the device for which the project was compiled.
test | Current test case. |
References CHIP_DEVID0, CHIP_DEVID1, CHIP_DEVID2, nvm_device_id::devid0, nvm_device_id::devid1, nvm_device_id::devid2, nvm_read_device_id(), and test_assert_true.
Referenced by main().
|
static |
Test device serial number readout.
This test reads out the LOTNUMn, WAFNUM, COORDXn and COORDYn values from the device signature row and checks that they are not all 0xFF.
test | Current test case. |
References nvm_device_serial::byte, nvm_read_device_serial(), and test_assert_true.
Referenced by main().
|
static |
Test EEPROM atomic write.
This test erases test page TEST_ATOMIC_WRITE_PAGE, then writes the first byte in the page buffer before flushing it – this byte should then not be written to the EEPROM – and writing different values to the two successive bytes. An atomic write is then executed before the write of the latter two bytes is verified.
test | Current test case. |
References EEPROM_ERASED, is_eeprom_page_equal_to_buffer(), nvm_eeprom_atomic_write_page(), nvm_eeprom_erase_page(), nvm_eeprom_flush_buffer(), nvm_eeprom_load_byte_to_buffer(), set_buffer, success, test_assert_true, and TEST_ATOMIC_WRITE_PAGE.
Referenced by main().
|
static |
Test EEPROM byte erase.
This test writes two bytes to test pages TEST_ERASE_BYTES_PAGE_1 and TEST_ERASE_BYTES_PAGE_2, then tries to erase one of them in the first page before verifying the erase, then in all pages before verifying that the second page was also erased.
test | Current test case. |
References EEPROM_ERASED, is_eeprom_page_equal_to_buffer(), nvm_eeprom_erase_bytes_in_all_pages(), nvm_eeprom_erase_bytes_in_page(), nvm_eeprom_load_byte_to_buffer(), nvm_eeprom_write_byte(), set_buffer, success, test_assert_true, TEST_ERASE_BYTES_PAGE_1, and TEST_ERASE_BYTES_PAGE_2.
Referenced by main().
|
static |
Test EEPROM erase.
This test writes a single byte to test page TEST_ERASE_PAGE, then erases all pages and checks that the test page contains only EEPROM_ERASED.
test | Current test case. |
References EEPROM_ERASED, is_eeprom_page_equal_to_buffer(), nvm_eeprom_erase_all(), nvm_eeprom_write_byte(), set_buffer, success, test_assert_true, and TEST_ERASE_PAGE.
Referenced by main().
|
static |
Test EEPROM read buffer.
This test erases test page TEST_READ_BUFFER_PAGE then writes four bytes to the test page and tries to read the entire page using nvm_eeprom_read_buffer. It then compares the read page with what's actually in the EEPROM page.
test | Current test case. |
References EEPROM_ERASED, is_eeprom_page_equal_to_buffer(), nvm_eeprom_erase_bytes_in_page(), nvm_eeprom_read_buffer(), nvm_eeprom_write_byte(), set_buffer, success, test_assert_true, and TEST_READ_BUFFER_PAGE.
Referenced by main().
|
static |
Test EEPROM split write.
This test writes two bytes to test page TEST_SPLIT_WRITE_PAGE with an atomic write operation, then writes a third byte to the same page with a split write operation before verifying that the page contains all three bytes.
test | Current test case. |
References EEPROM_ERASED, is_eeprom_page_equal_to_buffer(), nvm_eeprom_atomic_write_page(), nvm_eeprom_load_byte_to_buffer(), nvm_eeprom_split_write_page(), set_buffer, success, test_assert_true, and TEST_SPLIT_WRITE_PAGE.
Referenced by main().
|
static |
Test EEPROM write buffer.
This test erases test page TEST_WRITE_BUFFER_PAGE then writes a buffer to the test page, and then overwrites this with the another buffer and checks that the last buffer written is what the page is containing.
test | Current test case. |
References EEPROM_ERASED, is_eeprom_page_equal_to_buffer(), nvm_eeprom_erase_and_write_buffer(), nvm_eeprom_erase_bytes_in_page(), set_buffer, success, test_assert_true, and TEST_WRITE_BUFFER_PAGE.
Referenced by main().
|
static |
Test EEPROM write.
This test erases test page TEST_WRITE_PAGE, then writes a single byte to it and verifies that the write succeeded.
test | Current test case. |
References EEPROM_ERASED, is_eeprom_page_equal_to_buffer(), nvm_eeprom_erase_page(), nvm_eeprom_write_byte(), set_buffer, success, test_assert_true, and TEST_WRITE_PAGE.
Referenced by main().