LCOV - code coverage report
Current view: top level - spdk/test/unit/lib/util/crc16.c - crc16_ut.c (source / functions) Hit Total Coverage
Test: Combined Lines: 36 36 100.0 %
Date: 2024-07-15 17:17:46 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 4 50.0 %

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

Generated by: LCOV version 1.14