summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
authorAndrew Yourtchenko <ayourtch@gmail.com>2023-03-14 09:28:35 +0000
committerDamjan Marion <dmarion@0xa5.net>2023-03-16 19:16:51 +0000
commitf39485ff6aa112c8ddcac06c99911c406f0a36df (patch)
tree9587f4caaeaf78ff2b4dc0f44fb57033f5890027 /src/vppinfra
parente541d6f0edd39a093bcbee91282969647c1e6ebf (diff)
vppinfra: add clib_crc32c testcase into infra tests
Type: test Change-Id: Id96448ba3ab69a5b22dfc27812fc17194136b969 Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/CMakeLists.txt1
-rw-r--r--src/vppinfra/test/crc32c.c54
2 files changed, 55 insertions, 0 deletions
diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt
index 40951336387..e24e0493ca9 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -279,6 +279,7 @@ set(test_files
test/array_mask.c
test/compress.c
test/count_equal.c
+ test/crc32c.c
test/index_to_ptr.c
test/ip_csum.c
test/mask_compare.c
diff --git a/src/vppinfra/test/crc32c.c b/src/vppinfra/test/crc32c.c
new file mode 100644
index 00000000000..8c0c691e2e8
--- /dev/null
+++ b/src/vppinfra/test/crc32c.c
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: Apache-2.0
+ * Copyright(c) 2021 Cisco Systems, Inc.
+ */
+
+#include <vppinfra/format.h>
+#include <vppinfra/test/test.h>
+#include <vppinfra/crc32.h>
+
+#ifndef CLIB_MARCH_VARIANT
+char *crc32c_test_string =
+ "The quick brown fox jumped over the lazy dog and stumbled.";
+u32 crc32c_test_values_data[] = {
+ 0x00000000, 0x96bf4dcc, 0x65479df4, 0x60a63889, 0xda99c852, 0x3337e4e2,
+ 0x4651af18, 0x83b586a1, 0x2235e3b5, 0x7f896b6f, 0x1f17a8f3, 0x60dc68bc,
+ 0x6f95458b, 0x24c5aa40, 0xe40de8f0, 0x3e344ed8, 0x798903f4, 0x73ea05e3,
+ 0xcfc61ead, 0xe6ed33a9, 0xfaa20d87, 0x5ce246c4, 0x4022138c, 0x111b090a,
+ 0x1a6b673c, 0x298d6a78, 0x5d3485d5, 0xc6c24fec, 0x91600ac3, 0x877506df,
+ 0xd9702ff7, 0xb7de5f4b, 0xf8f8e606, 0x905bdc1c, 0xb69298ce, 0x3b748c05,
+ 0x1577ee4e, 0xc19389c7, 0x842bc1c7, 0x0db915db, 0x437d7c44, 0xa61f7901,
+ 0x54919807, 0xeb4b5a35, 0xb0f5e17e, 0xfded9015, 0xb6ff2e82, 0xaec598e4,
+ 0x8258fee0, 0xc30f7e3a, 0x390ac90e, 0x1a4376fc, 0xfa5ea3c2, 0xfca2d721,
+ 0x52d74c9f, 0xe06c4bcd, 0x28728122, 0x67f288d5, 0
+};
+u32 *crc32c_test_values = crc32c_test_values_data;
+
+#else
+extern char *crc32c_test_string;
+extern u32 *crc32c_test_values;
+#endif
+
+static clib_error_t *
+test_clib_crc32c (clib_error_t *err)
+{
+ int max_len = strlen (crc32c_test_string);
+ int i;
+ for (i = 0; i < max_len; i++)
+ {
+ u32 expected_crc32c = crc32c_test_values[i];
+ u32 calculated_crc32 = clib_crc32c ((u8 *) crc32c_test_string, i);
+ if (expected_crc32c != calculated_crc32)
+ {
+ return clib_error_return (
+ err,
+ "Bad CRC32C for test case %d: expected 0x%08x, calculated: 0x%08x",
+ i, expected_crc32c, calculated_crc32);
+ }
+ }
+ return err;
+}
+
+REGISTER_TEST (clib_crc32c) = {
+ .name = "clib_crc32c",
+ .fn = test_clib_crc32c,
+};