]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/app/test/test_crc.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
7 #include <rte_hexdump.h>
8 #include <rte_malloc.h>
9 #include <rte_memcpy.h>
10 #include <rte_net_crc.h>
12 #define CRC_VEC_LEN 32
13 #define CRC32_VEC_LEN1 1512
14 #define CRC32_VEC_LEN2 348
15 #define CRC16_VEC_LEN1 12
16 #define CRC16_VEC_LEN2 2
20 static const uint8_t crc_vec
[CRC_VEC_LEN
] = {
21 '0', '1', '2', '3', '4', '5', '6', '7',
22 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
23 'g', 'h', 'i', 'j', 'A', 'B', 'C', 'D',
24 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
27 /* 32-bit CRC test vector */
28 static const uint8_t crc32_vec1
[12] = {
29 0xBE, 0xD7, 0x23, 0x47, 0x6B, 0x8F,
30 0xB3, 0x14, 0x5E, 0xFB, 0x35, 0x59,
33 /* 16-bit CRC test vector 1 */
34 static const uint8_t crc16_vec1
[CRC16_VEC_LEN1
] = {
35 0x0D, 0x01, 0x01, 0x23, 0x45, 0x67,
36 0x89, 0x01, 0x23, 0x45, 0x00, 0x01,
39 /* 16-bit CRC test vector 2 */
40 static const uint8_t crc16_vec2
[CRC16_VEC_LEN2
] = {
44 static const uint32_t crc32_vec_res
= 0xb491aab4;
45 static const uint32_t crc32_vec1_res
= 0xac54d294;
46 static const uint32_t crc32_vec2_res
= 0xefaae02f;
47 static const uint32_t crc16_vec_res
= 0x6bec;
48 static const uint16_t crc16_vec1_res
= 0x8cdd;
49 static const uint16_t crc16_vec2_res
= 0xec5b;
52 crc_calc(const uint8_t *vec
,
54 enum rte_net_crc_type type
)
57 uint32_t ret
= rte_net_crc_calc(vec
, vec_len
, type
);
59 /* dump data on console */
60 debug_hexdump(stdout
, NULL
, vec
, vec_len
);
69 enum rte_net_crc_type type
;
74 /* 32-bit ethernet CRC: Test 1 */
75 type
= RTE_NET_CRC32_ETH
;
77 result
= crc_calc(crc_vec
, CRC_VEC_LEN
, type
);
78 if (result
!= crc32_vec_res
)
81 /* 32-bit ethernet CRC: Test 2 */
82 test_data
= rte_zmalloc(NULL
, CRC32_VEC_LEN1
, 0);
84 for (i
= 0; i
< CRC32_VEC_LEN1
; i
+= 12)
85 rte_memcpy(&test_data
[i
], crc32_vec1
, 12);
87 result
= crc_calc(test_data
, CRC32_VEC_LEN1
, type
);
88 if (result
!= crc32_vec1_res
) {
93 /* 32-bit ethernet CRC: Test 3 */
94 for (i
= 0; i
< CRC32_VEC_LEN2
; i
+= 12)
95 rte_memcpy(&test_data
[i
], crc32_vec1
, 12);
97 result
= crc_calc(test_data
, CRC32_VEC_LEN2
, type
);
98 if (result
!= crc32_vec2_res
) {
103 /* 16-bit CCITT CRC: Test 4 */
104 type
= RTE_NET_CRC16_CCITT
;
105 result
= crc_calc(crc_vec
, CRC_VEC_LEN
, type
);
106 if (result
!= crc16_vec_res
) {
110 /* 16-bit CCITT CRC: Test 5 */
111 result
= crc_calc(crc16_vec1
, CRC16_VEC_LEN1
, type
);
112 if (result
!= crc16_vec1_res
) {
116 /* 16-bit CCITT CRC: Test 6 */
117 result
= crc_calc(crc16_vec2
, CRC16_VEC_LEN2
, type
);
118 if (result
!= crc16_vec2_res
) {
135 /* set CRC scalar mode */
136 rte_net_crc_set_alg(RTE_NET_CRC_SCALAR
);
138 ret
= test_crc_calc();
140 printf("test_crc (scalar): failed (%d)\n", ret
);
143 /* set CRC sse4.2 mode */
144 rte_net_crc_set_alg(RTE_NET_CRC_SSE42
);
146 ret
= test_crc_calc();
148 printf("test_crc (x86_64_SSE4.2): failed (%d)\n", ret
);
152 /* set CRC neon mode */
153 rte_net_crc_set_alg(RTE_NET_CRC_NEON
);
155 ret
= test_crc_calc();
157 printf("test crc (arm64 neon pmull): failed (%d)\n", ret
);
164 REGISTER_TEST_COMMAND(crc_autotest
, test_crc
);