Skip to content

Commit dbbdef1

Browse files
rgundicarlescufi
authored andcommitted
crc: Add Test for crc32c implementation
Add unit test for crc32c (Castagnoli). Signed-off-by: Rajavardhan Gundi <[email protected]>
1 parent 4269ecd commit dbbdef1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/unit/crc/main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,35 @@
99
#include "../../../lib/os/crc8_sw.c"
1010
#include "../../../lib/os/crc16_sw.c"
1111
#include "../../../lib/os/crc32_sw.c"
12+
#include "../../../lib/os/crc32c_sw.c"
1213
#include "../../../lib/os/crc7_sw.c"
1314

15+
void test_crc32c(void)
16+
{
17+
uint8_t test1[] = { 'A' };
18+
uint8_t test2[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
19+
uint8_t test3[] = { 'Z', 'e', 'p', 'h', 'y', 'r' };
20+
21+
/* Single streams */
22+
zassert_equal(crc32_c(0, test1, sizeof(test1), true, true),
23+
0xE16DCDEE, NULL);
24+
zassert_equal(crc32_c(0, test2, sizeof(test2), true, true),
25+
0xE3069283, NULL);
26+
zassert_equal(crc32_c(0, test3, sizeof(test3), true, true),
27+
0xFCDEB58D, NULL);
28+
29+
/* Continuous streams - test1, test2 and test3 are considered part
30+
* of one big stream whose CRC needs to be calculated. Note that the
31+
* CRC of the first string is passed over to the second crc calculation,
32+
* second to third and so on.
33+
*/
34+
zassert_equal(crc32_c(0, test1, sizeof(test1), true, false),
35+
0x1E923211, NULL);
36+
zassert_equal(crc32_c(0x1E923211, test2, sizeof(test2), false, false),
37+
0xB2983B83, NULL);
38+
zassert_equal(crc32_c(0xB2983B83, test3, sizeof(test3), false, true),
39+
0x7D4F9D21, NULL);
40+
}
1441

1542
void test_crc32_ieee(void)
1643
{
@@ -205,6 +232,7 @@ void test_crc8(void)
205232
void test_main(void)
206233
{
207234
ztest_test_suite(test_crc,
235+
ztest_unit_test(test_crc32c),
208236
ztest_unit_test(test_crc32_ieee),
209237
ztest_unit_test(test_crc16),
210238
ztest_unit_test(test_crc16_ansi),

0 commit comments

Comments
 (0)