LCOV - code coverage report
Current view: top level - spdk/test/unit/lib/util/crc64.c - crc64_ut.c (source / functions) Hit Total Coverage
Test: Combined Lines: 40 40 100.0 %
Date: 2024-07-12 14:09:53 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 18 72.2 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2023 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : #include "spdk_internal/cunit.h"
       8                 :            : #include "util/crc64.c"
       9                 :            : 
      10                 :            : 
      11                 :            : static void
      12                 :          6 : test_crc64_nvme(void)
      13                 :          6 : {
      14                 :          6 :         unsigned int buf_size = 4096;
      15         [ -  + ]:          6 :         char buf[buf_size];
      16                 :            :         uint64_t crc;
      17                 :            :         unsigned int i, j;
      18                 :            : 
      19                 :            :         /* All the expected CRC values are compliant with
      20                 :            :         * the NVM Command Set Specification 1.0c */
      21                 :            : 
      22                 :            :         /* Input buffer = 0s */
      23         [ -  + ]:          6 :         memset(buf, 0, buf_size);
      24                 :          6 :         crc = spdk_crc64_nvme(buf, buf_size, 0);
      25                 :          6 :         CU_ASSERT(crc == 0x6482D367EB22B64E);
      26                 :            : 
      27                 :            :         /* Input buffer = 1s */
      28         [ -  + ]:          6 :         memset(buf, 0xFF, buf_size);
      29                 :          6 :         crc = spdk_crc64_nvme(buf, buf_size, 0);
      30                 :          6 :         CU_ASSERT(crc == 0xC0DDBA7302ECA3AC);
      31                 :            : 
      32                 :            :         /* Input buffer = 0x00, 0x01, 0x02, ... */
      33         [ -  + ]:          6 :         memset(buf, 0, buf_size);
      34                 :          6 :         j = 0;
      35         [ +  + ]:      24582 :         for (i = 0; i < buf_size; i++) {
      36                 :      24576 :                 buf[i] = (char)j;
      37         [ +  + ]:      24576 :                 if (j == 0xFF) {
      38                 :         96 :                         j = 0;
      39                 :            :                 } else {
      40                 :      24480 :                         j++;
      41                 :            :                 }
      42                 :            :         }
      43                 :          6 :         crc = spdk_crc64_nvme(buf, buf_size, 0);
      44                 :          6 :         CU_ASSERT(crc == 0x3E729F5F6750449C);
      45                 :            : 
      46                 :            :         /* Input buffer = 0xFF, 0xFE, 0xFD, ... */
      47         [ -  + ]:          6 :         memset(buf, 0, buf_size);
      48                 :          6 :         j = 0xFF;
      49         [ +  + ]:      24582 :         for (i = 0; i < buf_size ; i++) {
      50                 :      24576 :                 buf[i] = (char)j;
      51         [ +  + ]:      24576 :                 if (j == 0) {
      52                 :         96 :                         j = 0xFF;
      53                 :            :                 } else {
      54                 :      24480 :                         j--;
      55                 :            :                 }
      56                 :            :         }
      57                 :          6 :         crc = spdk_crc64_nvme(buf, buf_size, 0);
      58                 :          6 :         CU_ASSERT(crc == 0x9A2DF64B8E9E517E);
      59                 :          6 : }
      60                 :            : 
      61                 :            : int
      62                 :          6 : main(int argc, char **argv)
      63                 :            : {
      64                 :          6 :         CU_pSuite       suite = NULL;
      65                 :            :         unsigned int    num_failures;
      66                 :            : 
      67                 :          6 :         CU_set_error_action(CUEA_ABORT);
      68                 :          6 :         CU_initialize_registry();
      69                 :            : 
      70                 :          6 :         suite = CU_add_suite("crc64", NULL, NULL);
      71                 :            : 
      72                 :          6 :         CU_ADD_TEST(suite, test_crc64_nvme);
      73                 :            : 
      74                 :          6 :         CU_basic_set_mode(CU_BRM_VERBOSE);
      75                 :            : 
      76                 :          6 :         CU_basic_run_tests();
      77                 :            : 
      78                 :          6 :         num_failures = CU_get_number_of_failures();
      79                 :          6 :         CU_cleanup_registry();
      80                 :            : 
      81                 :          6 :         return num_failures;
      82                 :            : }

Generated by: LCOV version 1.14