Skip to content

Commit 0938ecc

Browse files
kartbendkalowsk
authored andcommitted
tests: crc: add tests for crc4 and crc4_ti functions
Implemented unit tests for the crc4 and crc4_ti functions as they were missed when they were introduced Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
1 parent 655d5fd commit 0938ecc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/unit/crc/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../../../lib/crc/crc32c_sw.c"
1313
#include "../../../lib/crc/crc7_sw.c"
1414
#include "../../../lib/crc/crc24_sw.c"
15+
#include "../../../lib/crc/crc4_sw.c"
1516
#include "../../../lib/crc/crc32k_4_2_sw.c"
1617

1718
ZTEST(crc, test_crc32_k_4_2)
@@ -195,6 +196,25 @@ ZTEST(crc, test_crc16_itu_t)
195196

196197
}
197198

199+
ZTEST(crc, test_crc4)
200+
{
201+
uint8_t test1[] = {'A'};
202+
uint8_t test2[] = {'Z', 'e', 'p', 'h', 'y', 'r'};
203+
204+
zassert_equal(crc4(test1, sizeof(test1), 0x3, 0x0, true), 0x2);
205+
zassert_equal(crc4(test2, sizeof(test2), 0x3, 0x0, true), 0x0);
206+
zassert_equal(crc4(test1, sizeof(test1), 0x3, 0x0, false), 0x4);
207+
zassert_equal(crc4(test2, sizeof(test2), 0x3, 0x0, false), 0xE);
208+
}
209+
210+
ZTEST(crc, test_crc4_ti)
211+
{
212+
uint8_t test1[] = {'Z', 'e', 'p'};
213+
214+
zassert_equal(crc4_ti(0x0, test1, sizeof(test1)), 0xF);
215+
zassert_equal(crc4_ti(0x5, test1, sizeof(test1)), 0xB);
216+
}
217+
198218
ZTEST(crc, test_crc8_ccitt)
199219
{
200220
uint8_t test0[] = { 0 };

0 commit comments

Comments
 (0)