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 test_crc64_nvme(void) 13 { 14 unsigned int buf_size = 4096; 15 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 memset(buf, 0, buf_size); 24 crc = spdk_crc64_nvme(buf, buf_size, 0); 25 CU_ASSERT(crc == 0x6482D367EB22B64E); 26 27 /* Input buffer = 1s */ 28 memset(buf, 0xFF, buf_size); 29 crc = spdk_crc64_nvme(buf, buf_size, 0); 30 CU_ASSERT(crc == 0xC0DDBA7302ECA3AC); 31 32 /* Input buffer = 0x00, 0x01, 0x02, ... */ 33 memset(buf, 0, buf_size); 34 j = 0; 35 for (i = 0; i < buf_size; i++) { 36 buf[i] = (char)j; 37 if (j == 0xFF) { 38 j = 0; 39 } else { 40 j++; 41 } 42 } 43 crc = spdk_crc64_nvme(buf, buf_size, 0); 44 CU_ASSERT(crc == 0x3E729F5F6750449C); 45 46 /* Input buffer = 0xFF, 0xFE, 0xFD, ... */ 47 memset(buf, 0, buf_size); 48 j = 0xFF; 49 for (i = 0; i < buf_size ; i++) { 50 buf[i] = (char)j; 51 if (j == 0) { 52 j = 0xFF; 53 } else { 54 j--; 55 } 56 } 57 crc = spdk_crc64_nvme(buf, buf_size, 0); 58 CU_ASSERT(crc == 0x9A2DF64B8E9E517E); 59 } 60 61 int 62 main(int argc, char **argv) 63 { 64 CU_pSuite suite = NULL; 65 unsigned int num_failures; 66 67 CU_set_error_action(CUEA_ABORT); 68 CU_initialize_registry(); 69 70 suite = CU_add_suite("crc64", NULL, NULL); 71 72 CU_ADD_TEST(suite, test_crc64_nvme); 73 74 CU_basic_set_mode(CU_BRM_VERBOSE); 75 76 CU_basic_run_tests(); 77 78 num_failures = CU_get_number_of_failures(); 79 CU_cleanup_registry(); 80 81 return num_failures; 82 } 83