]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/unit/lib/ioat/ioat.c/ioat_ut.c
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / test / unit / lib / ioat / ioat.c / ioat_ut.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "spdk_cunit.h"
35
36 #include "ioat/ioat.c"
37
38 #include "spdk_internal/mock.h"
39
40 #include "common/lib/test_env.c"
41
42 int
43 spdk_pci_ioat_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx)
44 {
45 return -1;
46 }
47
48 int
49 spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar,
50 void **mapped_addr, uint64_t *phys_addr, uint64_t *size)
51 {
52 *mapped_addr = NULL;
53 *phys_addr = 0;
54 *size = 0;
55 return 0;
56 }
57
58 int
59 spdk_pci_device_unmap_bar(struct spdk_pci_device *dev, uint32_t bar, void *addr)
60 {
61 return 0;
62 }
63
64 int
65 spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value,
66 uint32_t offset)
67 {
68 *value = 0xFFFFFFFFu;
69 return 0;
70 }
71
72 int
73 spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value,
74 uint32_t offset)
75 {
76 return 0;
77 }
78
79 static void ioat_state_check(void)
80 {
81 /*
82 * CHANSTS's STATUS field is 3 bits (8 possible values), but only has 5 valid states:
83 * ACTIVE 0x0
84 * IDLE 0x1
85 * SUSPENDED 0x2
86 * HALTED 0x3
87 * ARMED 0x4
88 */
89
90 CU_ASSERT(is_ioat_active(0) == 1); /* ACTIVE */
91 CU_ASSERT(is_ioat_active(1) == 0); /* IDLE */
92 CU_ASSERT(is_ioat_active(2) == 0); /* SUSPENDED */
93 CU_ASSERT(is_ioat_active(3) == 0); /* HALTED */
94 CU_ASSERT(is_ioat_active(4) == 0); /* ARMED */
95 CU_ASSERT(is_ioat_active(5) == 0); /* reserved */
96 CU_ASSERT(is_ioat_active(6) == 0); /* reserved */
97 CU_ASSERT(is_ioat_active(7) == 0); /* reserved */
98
99 CU_ASSERT(is_ioat_idle(0) == 0); /* ACTIVE */
100 CU_ASSERT(is_ioat_idle(1) == 1); /* IDLE */
101 CU_ASSERT(is_ioat_idle(2) == 0); /* SUSPENDED */
102 CU_ASSERT(is_ioat_idle(3) == 0); /* HALTED */
103 CU_ASSERT(is_ioat_idle(4) == 0); /* ARMED */
104 CU_ASSERT(is_ioat_idle(5) == 0); /* reserved */
105 CU_ASSERT(is_ioat_idle(6) == 0); /* reserved */
106 CU_ASSERT(is_ioat_idle(7) == 0); /* reserved */
107
108 CU_ASSERT(is_ioat_suspended(0) == 0); /* ACTIVE */
109 CU_ASSERT(is_ioat_suspended(1) == 0); /* IDLE */
110 CU_ASSERT(is_ioat_suspended(2) == 1); /* SUSPENDED */
111 CU_ASSERT(is_ioat_suspended(3) == 0); /* HALTED */
112 CU_ASSERT(is_ioat_suspended(4) == 0); /* ARMED */
113 CU_ASSERT(is_ioat_suspended(5) == 0); /* reserved */
114 CU_ASSERT(is_ioat_suspended(6) == 0); /* reserved */
115 CU_ASSERT(is_ioat_suspended(7) == 0); /* reserved */
116
117 CU_ASSERT(is_ioat_halted(0) == 0); /* ACTIVE */
118 CU_ASSERT(is_ioat_halted(1) == 0); /* IDLE */
119 CU_ASSERT(is_ioat_halted(2) == 0); /* SUSPENDED */
120 CU_ASSERT(is_ioat_halted(3) == 1); /* HALTED */
121 CU_ASSERT(is_ioat_halted(4) == 0); /* ARMED */
122 CU_ASSERT(is_ioat_halted(5) == 0); /* reserved */
123 CU_ASSERT(is_ioat_halted(6) == 0); /* reserved */
124 CU_ASSERT(is_ioat_halted(7) == 0); /* reserved */
125 }
126
127 int main(int argc, char **argv)
128 {
129 CU_pSuite suite = NULL;
130 unsigned int num_failures;
131
132 if (CU_initialize_registry() != CUE_SUCCESS) {
133 return CU_get_error();
134 }
135
136 suite = CU_add_suite("ioat", NULL, NULL);
137 if (suite == NULL) {
138 CU_cleanup_registry();
139 return CU_get_error();
140 }
141
142 if (
143 CU_add_test(suite, "ioat_state_check", ioat_state_check) == NULL) {
144 CU_cleanup_registry();
145 return CU_get_error();
146 }
147
148 CU_basic_set_mode(CU_BRM_VERBOSE);
149 CU_basic_run_tests();
150 num_failures = CU_get_number_of_failures();
151 CU_cleanup_registry();
152 return num_failures;
153 }