Branch data Line data Source code
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_internal/cunit.h"
9 : :
10 : : #include "util/crc16.c"
11 : :
12 : : static void
13 : 6 : test_crc16_t10dif(void)
14 : : {
15 : : uint16_t crc;
16 : 6 : char buf[] = "123456789";
17 : :
18 : 6 : crc = spdk_crc16_t10dif(0, buf, strlen(buf));
19 : 6 : CU_ASSERT(crc == 0xd0db);
20 : 6 : }
21 : :
22 : : static void
23 : 6 : test_crc16_t10dif_seed(void)
24 : : {
25 : 6 : uint16_t crc = 0;
26 : 6 : char buf1[] = "1234";
27 : 6 : char buf2[] = "56789";
28 : :
29 : 6 : crc = spdk_crc16_t10dif(crc, buf1, strlen(buf1));
30 : 6 : crc = spdk_crc16_t10dif(crc, buf2, strlen(buf2));
31 : 6 : CU_ASSERT(crc == 0xd0db);
32 : 6 : }
33 : :
34 : : static void
35 : 6 : test_crc16_t10dif_copy(void)
36 : : {
37 : 6 : uint16_t crc1 = 0, crc2;
38 : 6 : char buf1[] = "1234";
39 : 6 : char buf2[] = "56789";
40 : 6 : char *buf3 = calloc(1, strlen(buf1) + strlen(buf2) + 1);
41 [ - + ]: 6 : SPDK_CU_ASSERT_FATAL(buf3 != NULL);
42 : :
43 : 6 : crc1 = spdk_crc16_t10dif_copy(crc1, buf3, buf1, strlen(buf1));
44 : 6 : crc1 = spdk_crc16_t10dif_copy(crc1, buf3 + strlen(buf1), buf2, strlen(buf2));
45 : 6 : CU_ASSERT(crc1 == 0xd0db);
46 : :
47 [ - + ]: 6 : crc2 = spdk_crc16_t10dif(0, buf3, strlen(buf3));
48 : 6 : CU_ASSERT(crc2 == 0xd0db);
49 : :
50 : 6 : free(buf3);
51 : 6 : }
52 : :
53 : : int
54 : 6 : main(int argc, char **argv)
55 : : {
56 : 6 : CU_pSuite suite = NULL;
57 : : unsigned int num_failures;
58 : :
59 : 6 : CU_initialize_registry();
60 : :
61 : 6 : suite = CU_add_suite("crc16", NULL, NULL);
62 : :
63 : 6 : CU_ADD_TEST(suite, test_crc16_t10dif);
64 : 6 : CU_ADD_TEST(suite, test_crc16_t10dif_seed);
65 : 6 : CU_ADD_TEST(suite, test_crc16_t10dif_copy);
66 : :
67 : :
68 : 6 : num_failures = spdk_ut_run_tests(argc, argv, NULL);
69 : :
70 : 6 : CU_cleanup_registry();
71 : :
72 : 6 : return num_failures;
73 : : }
|