hs-test: use specific port for http3 test
[vpp.git] / src / vppinfra / test / crc32c.c
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright(c) 2021 Cisco Systems, Inc.
3  */
4
5 #include <vppinfra/format.h>
6 #include <vppinfra/test/test.h>
7 #include <vppinfra/crc32.h>
8
9 #ifndef CLIB_MARCH_VARIANT
10 char *crc32c_test_string =
11   "The quick brown fox jumped over the lazy dog and stumbled.";
12 u32 crc32c_test_values_data[] = {
13   0x00000000, 0x96bf4dcc, 0x65479df4, 0x60a63889, 0xda99c852, 0x3337e4e2,
14   0x4651af18, 0x83b586a1, 0x2235e3b5, 0x7f896b6f, 0x1f17a8f3, 0x60dc68bc,
15   0x6f95458b, 0x24c5aa40, 0xe40de8f0, 0x3e344ed8, 0x798903f4, 0x73ea05e3,
16   0xcfc61ead, 0xe6ed33a9, 0xfaa20d87, 0x5ce246c4, 0x4022138c, 0x111b090a,
17   0x1a6b673c, 0x298d6a78, 0x5d3485d5, 0xc6c24fec, 0x91600ac3, 0x877506df,
18   0xd9702ff7, 0xb7de5f4b, 0xf8f8e606, 0x905bdc1c, 0xb69298ce, 0x3b748c05,
19   0x1577ee4e, 0xc19389c7, 0x842bc1c7, 0x0db915db, 0x437d7c44, 0xa61f7901,
20   0x54919807, 0xeb4b5a35, 0xb0f5e17e, 0xfded9015, 0xb6ff2e82, 0xaec598e4,
21   0x8258fee0, 0xc30f7e3a, 0x390ac90e, 0x1a4376fc, 0xfa5ea3c2, 0xfca2d721,
22   0x52d74c9f, 0xe06c4bcd, 0x28728122, 0x67f288d5, 0
23 };
24 u32 *crc32c_test_values = crc32c_test_values_data;
25
26 #else
27 extern char *crc32c_test_string;
28 extern u32 *crc32c_test_values;
29 #endif
30
31 static clib_error_t *
32 test_clib_crc32c (clib_error_t *err)
33 {
34   int max_len = strlen (crc32c_test_string);
35   int i;
36   for (i = 0; i < max_len; i++)
37     {
38       u32 expected_crc32c = crc32c_test_values[i];
39       u32 calculated_crc32 = clib_crc32c ((u8 *) crc32c_test_string, i);
40       if (expected_crc32c != calculated_crc32)
41         {
42           return clib_error_return (
43             err,
44             "Bad CRC32C for test case %d: expected 0x%08x, calculated: 0x%08x",
45             i, expected_crc32c, calculated_crc32);
46         }
47     }
48   return err;
49 }
50
51 REGISTER_TEST (clib_crc32c) = {
52   .name = "clib_crc32c",
53   .fn = test_clib_crc32c,
54 };