@@ -15,9 +15,12 @@ void test_crc16(void)
15
15
u8_t test1 [] = { 'A' };
16
16
u8_t test2 [] = { '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' };
17
17
18
- zassert (crc16_ccitt (test0 , sizeof (test0 )) == 0x1d0f , "pass" , "fail" );
19
- zassert (crc16_ccitt (test1 , sizeof (test1 )) == 0x9479 , "pass" , "fail" );
20
- zassert (crc16_ccitt (test2 , sizeof (test2 )) == 0xe5cc , "pass" , "fail" );
18
+ zassert_equal (crc16 (test0 , sizeof (test0 ), 0x1021 , 0xffff , true),
19
+ 0x1d0f , NULL );
20
+ zassert_equal (crc16 (test1 , sizeof (test1 ), 0x1021 , 0xffff , true),
21
+ 0x9479 , NULL );
22
+ zassert_equal (crc16 (test2 , sizeof (test2 ), 0x1021 , 0xffff , true),
23
+ 0xe5cc , NULL );
21
24
}
22
25
23
26
void test_crc16_ansi (void )
@@ -31,6 +34,47 @@ void test_crc16_ansi(void)
31
34
zassert (crc16_ansi (test2 , sizeof (test2 )) == 0x9ecf , "pass" , "fail" );
32
35
}
33
36
37
+ void test_crc16_ccitt (void )
38
+ {
39
+ u8_t test0 [] = { };
40
+ u8_t test1 [] = { 'A' };
41
+ u8_t test2 [] = { '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' };
42
+ u8_t test3 [] = { 'Z' , 'e' , 'p' , 'h' , 'y' , 'r' , 0 , 0 };
43
+ u16_t crc ;
44
+
45
+ zassert_equal (crc16_ccitt (0 , test0 , sizeof (test0 )), 0x0 , NULL );
46
+ zassert_equal (crc16_ccitt (0 , test1 , sizeof (test1 )), 0x538d , NULL );
47
+ zassert_equal (crc16_ccitt (0 , test2 , sizeof (test2 )), 0x2189 , NULL );
48
+
49
+ /* Appending the CRC to a buffer and computing the CRC over
50
+ * the extended buffer leaves a residual of zero.
51
+ */
52
+ crc = crc16_ccitt (0 , test3 , sizeof (test3 ) - sizeof (u16_t ));
53
+ test3 [sizeof (test3 )- 2 ] = (u8_t )(crc >> 0 );
54
+ test3 [sizeof (test3 )- 1 ] = (u8_t )(crc >> 8 );
55
+
56
+ zassert_equal (crc16_ccitt (0 , test3 , sizeof (test3 )), 0 , NULL );
57
+ }
58
+
59
+ void test_crc16_ccitt_for_ppp (void )
60
+ {
61
+ /* Example capture including FCS from
62
+ * https://www.horo.ch/techno/ppp-fcs/examples_en.html
63
+ */
64
+ u8_t test0 [] = {
65
+ 0xff , 0x03 , 0xc0 , 0x21 , 0x01 , 0x01 , 0x00 , 0x17 ,
66
+ 0x02 , 0x06 , 0x00 , 0x0a , 0x00 , 0x00 , 0x05 , 0x06 ,
67
+ 0x00 , 0x2a , 0x2b , 0x78 , 0x07 , 0x02 , 0x08 , 0x02 ,
68
+ 0x0d , 0x03 , 0x06 , 0xa5 , 0xf8
69
+ };
70
+ u8_t test2 [] = { '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' };
71
+
72
+ zassert_equal (crc16_ccitt (0xffff , test0 , sizeof (test0 )),
73
+ 0xf0b8 , NULL );
74
+ zassert_equal (crc16_ccitt (0xffff , test2 , sizeof (test2 )) ^ 0xFFFF ,
75
+ 0x906e , NULL );
76
+ }
77
+
34
78
void test_crc8_ccitt (void )
35
79
{
36
80
u8_t test0 [] = { 0 };
@@ -50,6 +94,8 @@ void test_main(void)
50
94
ztest_test_suite (test_crc ,
51
95
ztest_unit_test (test_crc16 ),
52
96
ztest_unit_test (test_crc16_ansi ),
97
+ ztest_unit_test (test_crc16_ccitt ),
98
+ ztest_unit_test (test_crc16_ccitt_for_ppp ),
53
99
ztest_unit_test (test_crc8_ccitt ));
54
100
ztest_run_test_suite (test_crc );
55
101
}
0 commit comments