1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "spdk_cunit.h" 7 8 #include "ioat/ioat.c" 9 10 #include "spdk_internal/mock.h" 11 12 #include "common/lib/test_env.c" 13 14 int 15 spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx) 16 { 17 return -1; 18 } 19 20 int 21 spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar, 22 void **mapped_addr, uint64_t *phys_addr, uint64_t *size) 23 { 24 *mapped_addr = NULL; 25 *phys_addr = 0; 26 *size = 0; 27 return 0; 28 } 29 30 int 31 spdk_pci_device_unmap_bar(struct spdk_pci_device *dev, uint32_t bar, void *addr) 32 { 33 return 0; 34 } 35 36 int 37 spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, 38 uint32_t offset) 39 { 40 *value = 0xFFFFFFFFu; 41 return 0; 42 } 43 44 int 45 spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, 46 uint32_t offset) 47 { 48 return 0; 49 } 50 51 static void 52 ioat_state_check(void) 53 { 54 /* 55 * CHANSTS's STATUS field is 3 bits (8 possible values), but only has 5 valid states: 56 * ACTIVE 0x0 57 * IDLE 0x1 58 * SUSPENDED 0x2 59 * HALTED 0x3 60 * ARMED 0x4 61 */ 62 63 CU_ASSERT(is_ioat_active(0) == 1); /* ACTIVE */ 64 CU_ASSERT(is_ioat_active(1) == 0); /* IDLE */ 65 CU_ASSERT(is_ioat_active(2) == 0); /* SUSPENDED */ 66 CU_ASSERT(is_ioat_active(3) == 0); /* HALTED */ 67 CU_ASSERT(is_ioat_active(4) == 0); /* ARMED */ 68 CU_ASSERT(is_ioat_active(5) == 0); /* reserved */ 69 CU_ASSERT(is_ioat_active(6) == 0); /* reserved */ 70 CU_ASSERT(is_ioat_active(7) == 0); /* reserved */ 71 72 CU_ASSERT(is_ioat_idle(0) == 0); /* ACTIVE */ 73 CU_ASSERT(is_ioat_idle(1) == 1); /* IDLE */ 74 CU_ASSERT(is_ioat_idle(2) == 0); /* SUSPENDED */ 75 CU_ASSERT(is_ioat_idle(3) == 0); /* HALTED */ 76 CU_ASSERT(is_ioat_idle(4) == 0); /* ARMED */ 77 CU_ASSERT(is_ioat_idle(5) == 0); /* reserved */ 78 CU_ASSERT(is_ioat_idle(6) == 0); /* reserved */ 79 CU_ASSERT(is_ioat_idle(7) == 0); /* reserved */ 80 81 CU_ASSERT(is_ioat_suspended(0) == 0); /* ACTIVE */ 82 CU_ASSERT(is_ioat_suspended(1) == 0); /* IDLE */ 83 CU_ASSERT(is_ioat_suspended(2) == 1); /* SUSPENDED */ 84 CU_ASSERT(is_ioat_suspended(3) == 0); /* HALTED */ 85 CU_ASSERT(is_ioat_suspended(4) == 0); /* ARMED */ 86 CU_ASSERT(is_ioat_suspended(5) == 0); /* reserved */ 87 CU_ASSERT(is_ioat_suspended(6) == 0); /* reserved */ 88 CU_ASSERT(is_ioat_suspended(7) == 0); /* reserved */ 89 90 CU_ASSERT(is_ioat_halted(0) == 0); /* ACTIVE */ 91 CU_ASSERT(is_ioat_halted(1) == 0); /* IDLE */ 92 CU_ASSERT(is_ioat_halted(2) == 0); /* SUSPENDED */ 93 CU_ASSERT(is_ioat_halted(3) == 1); /* HALTED */ 94 CU_ASSERT(is_ioat_halted(4) == 0); /* ARMED */ 95 CU_ASSERT(is_ioat_halted(5) == 0); /* reserved */ 96 CU_ASSERT(is_ioat_halted(6) == 0); /* reserved */ 97 CU_ASSERT(is_ioat_halted(7) == 0); /* reserved */ 98 } 99 100 int 101 main(int argc, char **argv) 102 { 103 CU_pSuite suite = NULL; 104 unsigned int num_failures; 105 106 CU_set_error_action(CUEA_ABORT); 107 CU_initialize_registry(); 108 109 suite = CU_add_suite("ioat", NULL, NULL); 110 111 CU_ADD_TEST(suite, ioat_state_check); 112 113 CU_basic_set_mode(CU_BRM_VERBOSE); 114 CU_basic_run_tests(); 115 num_failures = CU_get_number_of_failures(); 116 CU_cleanup_registry(); 117 return num_failures; 118 } 119