Unit tests for Cyclic Redundancy Check (CRC) driver.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdio.h>
#include <stdbool.h>
#include <asf.h>
#include <sysclk.h>
#include <dma.h>
#include <unit_test/suite.h>
#include <crc.h>
#include <sleepmgr.h>
#include "conf_test.h"
Macros | |
#define | LENGTH(x) (sizeof(x) / sizeof(*x)) |
Get array length. More... | |
Functions | |
int | main (void) |
Run CRC driver unit tests. More... | |
Helper functions | |
static void | setup_dma_channel (uint8_t buf_length, uint8_t *src_buffer, uint8_t *dst_buffer) |
Setup a DMA channel for CRC calculation. More... | |
static bool | wait_for_dma_transfer (const struct test_case *test) |
Wait for DMA transfer to complete and check status. More... | |
Unit test functions | |
static void | run_32bit_io_test (const struct test_case *test) |
32-bit checksum of data block test More... | |
static void | run_16bit_io_test (const struct test_case *test) |
16-bit checksum of data block test More... | |
static void | run_32bit_dma_test (const struct test_case *test) |
32-bit checksum of DMA transfer data More... | |
static void | run_16bit_dma_test (const struct test_case *test) |
16-bit checksum of DMA transfer data More... | |
static void | run_flash_test (const struct test_case *test) |
32-bit CRC of flash memory test More... | |
Data declarations | |
#define | CRC_CHECKSUM_32BIT 0x26CB2533 |
Pre-calculated checksums of data_8bit and data_8bit_flash (without the trailing zeros) More... | |
#define | CRC_CHECKSUM_16BIT 0x51D1 |
const uint8_t | data_8bit [] |
PROGMEM_DECLARE (uint8_t, data_8bit_flash[]) | |
#define CRC_CHECKSUM_16BIT 0x51D1 |
Referenced by run_16bit_dma_test(), and run_16bit_io_test().
#define CRC_CHECKSUM_32BIT 0x26CB2533 |
Pre-calculated checksums of data_8bit and data_8bit_flash (without the trailing zeros)
Referenced by run_32bit_dma_test(), run_32bit_io_test(), and run_flash_test().
#define LENGTH | ( | x | ) | (sizeof(x) / sizeof(*x)) |
Get array length.
Referenced by run_16bit_dma_test(), run_16bit_io_test(), run_32bit_dma_test(), run_32bit_io_test(), and run_flash_test().
int main | ( | void | ) |
Run CRC driver unit tests.
References usart_rs232_options::baudrate, board_init(), CONF_TEST_BAUDRATE, CONF_TEST_CHARLENGTH, CONF_TEST_PARITY, CONF_TEST_STOPBITS, CONF_TEST_USART, DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_16bit_dma_test(), run_16bit_io_test(), run_32bit_dma_test(), run_32bit_io_test(), run_flash_test(), sleepmgr_init(), stdio_serial_init(), sysclk_init(), and test_suite_run().
PROGMEM_DECLARE | ( | uint8_t | , |
data_8bit_flash | [] | ||
) |
|
static |
16-bit checksum of DMA transfer data
This test sets up DMA to do a data block transfer, and sets up the CRC module to do a 16 bit checksum on the data. The checksum will then be added to another buffer, the same procedure is setup with this new buffer which should result in a checksum = 0.
test | Current test case |
References CONF_TEST_DMACH, crc16_append_value(), CRC_16BIT, CRC_CHECKSUM_16BIT, crc_dma_checksum_stop(), data_8bit, dma_channel_disable(), dma_channel_trigger_block_transfer(), dma_disable(), LENGTH, setup_dma_channel(), test_assert_true, and wait_for_dma_transfer().
Referenced by main().
|
static |
16-bit checksum of data block test
This test does a checksum of a data block with a known checksum, and verifies that they are equal. It then appends the 16-bit CRC to the end of the data, and does another checksum operation, which should result in the zero flag being set.
test | Current test case |
References crc16_append_value(), CRC_16BIT, CRC_CHECKSUM_16BIT, crc_io_checksum(), crc_io_checksum_byte_add(), crc_io_checksum_byte_start(), crc_io_checksum_byte_stop(), data_8bit, LENGTH, and test_assert_true.
Referenced by main().
|
static |
32-bit checksum of DMA transfer data
This test sets up DMA to do a data block transfer, and sets up the CRC module to do a 32 bit checksum on the data. The checksum will then be added to another buffer, the same procedure is setup with this new buffer which should result in a checksum = 0.
test | Current test case |
References CONF_TEST_DMACH, crc32_append_value(), CRC_32BIT, CRC_CHECKSUM_32BIT, crc_dma_checksum_stop(), data_8bit, dma_channel_disable(), dma_channel_trigger_block_transfer(), dma_disable(), LENGTH, setup_dma_channel(), test_assert_true, and wait_for_dma_transfer().
Referenced by main().
|
static |
32-bit checksum of data block test
This test does a checksum of a data block with a known checksum, and verifies that they are equal. It then appends the 32-bit CRC to the end of the data, and does another checksum operation, which should result in the zero flag being set.
test | Current test case |
References crc32_append_value(), CRC_32BIT, CRC_CHECKSUM_32BIT, crc_io_checksum(), crc_io_checksum_byte_add(), crc_io_checksum_byte_start(), crc_io_checksum_byte_stop(), data_8bit, LENGTH, and test_assert_true.
Referenced by main().
|
static |
32-bit CRC of flash memory test
This test does a 32-bit checksum on the flash memory and verifies the checksum against a pre-calculated 32-bit CRC checksum.
test | Current test case |
References CRC_CHECKSUM_32BIT, crc_flash_checksum(), CRC_FLASH_RANGE, LENGTH, and test_assert_true.
Referenced by main().
|
static |
Setup a DMA channel for CRC calculation.
buf_length | Length of buffer to transfer |
src_buffer | Pointer to transfer buffer |
dst_buffer | Pointer to receive buffer |
References CONF_TEST_DMACH, dma_channel_enable(), dma_channel_read_config(), dma_channel_set_dest_dir_mode(), dma_channel_set_src_dir_mode(), dma_channel_write_burst_length(), dma_channel_write_config(), dma_channel_write_destination(), dma_channel_write_repeats(), dma_channel_write_source(), dma_channel_write_transfer_count(), and dma_enable().
Referenced by run_16bit_dma_test(), and run_32bit_dma_test().
Wait for DMA transfer to complete and check status.
test | Current test case |
true | if DMA transfer completed without error |
false | if DMA transfer failed |
References CONF_TEST_DMACH, DMA_CH_FREE, DMA_CH_TRANSFER_COMPLETED, DMA_CH_TRANSFER_ERROR, dma_get_channel_status(), and test_assert_true.
Referenced by run_16bit_dma_test(), and run_32bit_dma_test().
const uint8_t data_8bit[] |
Referenced by run_16bit_dma_test(), run_16bit_io_test(), run_32bit_dma_test(), and run_32bit_io_test().