Microchip® Advanced Software Framework

unit_tests.c File Reference

Unit tests for at24cxx driver.

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

#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <string.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_clock.h>
#include <conf_board.h>
#include <conf_test.h>
#include <at24cxx.h>
#include "twi.h"

Macros

#define AT24C_MEM_ADDR   0
 Memory Start Address of AT24CXX chips. More...
 
#define AT24C_TWI_CLK   400000UL
 TWI Bus Clock 400kHz. More...
 
#define MEMORY_PATTERN   TEST_DATA
 
#define PAGE_ADDR   511UL
 
#define PAGE_SIZE   64UL
 
#define TEST_DATA   0xA5u
 Test data. More...
 
#define TEST_DATA_LENGTH   (sizeof(test_data_tx)/sizeof(uint8_t))
 

Functions

static bool buffer_cmp (const uint8_t *pbuf_0, const uint8_t *pbuf_1, uint32_t len)
 
static void buffer_fill (uint8_t *pbuf, uint32_t len, const uint8_t pattern)
 
int main (void)
 Run AT24CXX driver unit tests. More...
 
static void run_test_byte_access (const struct test_case *test)
 Test data write API function. More...
 
static void run_test_continuous_access (const struct test_case *test)
 Test data read API function. More...
 
static void run_test_fill_pattern (const struct test_case *test)
 Test data read/write API functions. More...
 
static void run_test_page_access (const struct test_case *test)
 Test data read API function. More...
 
static void run_test_setup (const struct test_case *test)
 Test data read/write API functions. More...
 

Variables

uint8_t page_read_buf [PAGE_SIZE]
 
uint8_t page_write_buf [PAGE_SIZE]
 
bool result = false
 
static uint8_t test_data_rx [TEST_DATA_LENGTH]
 
static uint8_t test_data_tx []
 

#define AT24C_MEM_ADDR   0

Memory Start Address of AT24CXX chips.

Referenced by run_test_byte_access(), run_test_continuous_access(), and run_test_fill_pattern().

#define AT24C_TWI_CLK   400000UL

TWI Bus Clock 400kHz.

Referenced by run_test_setup().

#define MEMORY_PATTERN   TEST_DATA
#define PAGE_ADDR   511UL

Referenced by run_test_page_access().

#define PAGE_SIZE   64UL

Referenced by run_test_page_access().

#define TEST_DATA   0xA5u

Test data.

Referenced by run_test_byte_access().

#define TEST_DATA_LENGTH   (sizeof(test_data_tx)/sizeof(uint8_t))

static bool buffer_cmp ( const uint8_t *  pbuf_0,
const uint8_t *  pbuf_1,
uint32_t  len 
)
static
static void buffer_fill ( uint8_t *  pbuf,
uint32_t  len,
const uint8_t  pattern 
)
static
static void run_test_byte_access ( const struct test_case test)
static

Test data write API function.

This test calls the data write API function and check if the write operation succeeded.

Parameters
testCurrent test case.

References AT24C_MEM_ADDR, AT24C_READ_SUCCESS, AT24C_WRITE_SUCCESS, at24cxx_read_byte(), at24cxx_write_byte(), result, test_assert_true, and TEST_DATA.

Referenced by main().

static void run_test_continuous_access ( const struct test_case test)
static

Test data read API function.

This test calls the data read API function and check if the read operation succeeded.

Parameters
testCurrent test case.

References AT24C_MEM_ADDR, AT24C_READ_SUCCESS, AT24C_WRITE_SUCCESS, at24cxx_read_continuous(), at24cxx_write_continuous(), buffer_cmp(), buffer_fill(), result, test_assert_true, TEST_DATA_LENGTH, test_data_rx, and test_data_tx.

Referenced by main().

static void run_test_fill_pattern ( const struct test_case test)
static

Test data read/write API functions.

This test calls the data read/write API functions and check the data consistency.

Parameters
testCurrent test case.

References AT24C_MEM_ADDR, AT24C_READ_SUCCESS, AT24C_WRITE_SUCCESS, at24cxx_fill_pattern(), at24cxx_read_continuous(), buffer_cmp(), buffer_fill(), MEMORY_PATTERN, result, test_assert_true, TEST_DATA_LENGTH, test_data_rx, and test_data_tx.

Referenced by main().

static void run_test_page_access ( const struct test_case test)
static

Test data read API function.

This test calls the data read API function and check if the read operation succeeded.

Parameters
testCurrent test case.

References AT24C_WRITE_SUCCESS, at24cxx_read_page(), at24cxx_write_page(), buffer_cmp(), buffer_fill(), MEMORY_PATTERN, PAGE_ADDR, page_read_buf, PAGE_SIZE, page_write_buf, result, and test_assert_true.

Referenced by main().

static void run_test_setup ( const struct test_case test)
static

Test data read/write API functions.

This test calls the data read/write API functions and check the data consistency.

Parameters
testCurrent test case.

References AT24C_TWI_CLK, BOARD_AT24C_TWI_INSTANCE, twi_options::master_clk, result, twi_options::speed, sysclk_get_cpu_hz(), test_assert_true, twi_master_setup(), and TWI_SUCCESS.

Referenced by main().

uint8_t page_read_buf[PAGE_SIZE]

Referenced by run_test_page_access().

uint8_t page_write_buf[PAGE_SIZE]

Referenced by run_test_page_access().

uint8_t test_data_rx[TEST_DATA_LENGTH]
static
uint8_t test_data_tx[]
static
Initial value:
= {
'A', 'T', '2', '4', 'C', 'X', 'X', ' ', 'U', 'N', 'I', 'T', ' ',
'T', 'E', 'S', 'T', 'S'
}

Referenced by run_test_continuous_access(), and run_test_fill_pattern().