mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-27 23:41:18 +01:00
tests/unittests: add test for CRC-32 checksum
This commit is contained in:
parent
49a85f4633
commit
eb527d3481
72
tests/unittests/tests-checksum/tests-checksum-crc32.c
Normal file
72
tests/unittests/tests-checksum/tests-checksum-crc32.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2022 Benjamin Valentin <benpicco@googlemail.com>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include "checksum/crc32.h"
|
||||
#include "tests-checksum.h"
|
||||
|
||||
static void test_checksum_crc32_sequence_empty(void)
|
||||
{
|
||||
unsigned char buf[] = "";
|
||||
uint32_t expect = 0x0;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf) - 1));
|
||||
}
|
||||
|
||||
static void test_checksum_crc32_sequence_1a(void)
|
||||
{
|
||||
unsigned char buf[] = "A";
|
||||
uint32_t expect = 0xd3d99e8b;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf) - 1));
|
||||
}
|
||||
|
||||
static void test_checksum_crc32_sequence_256a(void)
|
||||
{
|
||||
unsigned char buf[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
||||
uint32_t expect = 0x49975b13;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf) - 1));
|
||||
}
|
||||
|
||||
static void test_checksum_crc32_sequence_1to9(void)
|
||||
{
|
||||
unsigned char buf[] = "123456789";
|
||||
uint32_t expect = 0xcbf43926;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf) - 1));
|
||||
}
|
||||
|
||||
static void test_checksum_crc32_sequence_4bytes(void)
|
||||
{
|
||||
unsigned char buf[] = { 0x12, 0x34, 0x56, 0x78 };
|
||||
uint32_t expect = 0x4a090e98;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
Test *tests_checksum_crc32_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_checksum_crc32_sequence_empty),
|
||||
new_TestFixture(test_checksum_crc32_sequence_1a),
|
||||
new_TestFixture(test_checksum_crc32_sequence_256a),
|
||||
new_TestFixture(test_checksum_crc32_sequence_1to9),
|
||||
new_TestFixture(test_checksum_crc32_sequence_4bytes),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(checksum_crc32_tests, NULL, NULL, fixtures);
|
||||
|
||||
return (Test *)&checksum_crc32_tests;
|
||||
}
|
||||
@ -15,6 +15,7 @@ void tests_checksum(void)
|
||||
TESTS_RUN(tests_checksum_crc16_ccitt_mcrf4xx_tests());
|
||||
TESTS_RUN(tests_checksum_crc16_ccitt_aug_tests());
|
||||
TESTS_RUN(tests_checksum_crc16_ccitt_false_tests());
|
||||
TESTS_RUN(tests_checksum_crc32_tests());
|
||||
TESTS_RUN(tests_checksum_fletcher16_tests());
|
||||
TESTS_RUN(tests_checksum_fletcher32_tests());
|
||||
TESTS_RUN(tests_checksum_ucrc16_tests());
|
||||
|
||||
@ -64,6 +64,13 @@ Test *tests_checksum_crc16_ccitt_false_tests(void);
|
||||
*/
|
||||
Test *tests_checksum_crc16_ccitt_aug_tests(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests for checksum/crc32.h
|
||||
*
|
||||
* @return embUnit tests if successful, NULL if not.
|
||||
*/
|
||||
Test *tests_checksum_crc32_tests(void);
|
||||
|
||||
/**
|
||||
* @brief Generates tests for checksum/fletcher16.h
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user