xref: /spdk/test/unit/lib/util/crc32_ieee.c/crc32_ieee_ut.c (revision 588dfe314bb83d86effdf67ec42837b11c2620bf)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #include "spdk/stdinc.h"
7 
8 #include "spdk_cunit.h"
9 
10 #include "util/crc32.c"
11 #include "util/crc32_ieee.c"
12 
13 static void
14 test_crc32_ieee(void)
15 {
16 	uint32_t crc;
17 	char buf[] = "Hello world!";
18 
19 	crc = 0xFFFFFFFFu;
20 	crc = spdk_crc32_ieee_update(buf, strlen(buf), crc);
21 	crc ^= 0xFFFFFFFFu;
22 	CU_ASSERT(crc == 0x1b851995);
23 }
24 
25 int
26 main(int argc, char **argv)
27 {
28 	CU_pSuite	suite = NULL;
29 	unsigned int	num_failures;
30 
31 	CU_set_error_action(CUEA_ABORT);
32 	CU_initialize_registry();
33 
34 	suite = CU_add_suite("crc32_ieee", NULL, NULL);
35 
36 	CU_ADD_TEST(suite, test_crc32_ieee);
37 
38 	CU_basic_set_mode(CU_BRM_VERBOSE);
39 
40 	CU_basic_run_tests();
41 
42 	num_failures = CU_get_number_of_failures();
43 	CU_cleanup_registry();
44 
45 	return num_failures;
46 }
47