]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | /*- | |
3 | * BSD LICENSE | |
4 | * | |
5 | * Copyright (c) Intel Corporation. | |
6 | * All rights reserved. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * | |
12 | * * Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | |
14 | * * Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in | |
16 | * the documentation and/or other materials provided with the | |
17 | * distribution. | |
18 | * * Neither the name of Intel Corporation nor the names of its | |
19 | * contributors may be used to endorse or promote products derived | |
20 | * from this software without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
33 | */ | |
34 | ||
35 | #include "spdk_cunit.h" | |
36 | ||
37 | #include "nvme/nvme_ctrlr_cmd.c" | |
38 | ||
39 | #define CTRLR_CDATA_ELPE 5 | |
40 | ||
41 | struct nvme_request g_req; | |
42 | ||
43 | uint32_t error_num_entries; | |
44 | uint32_t health_log_nsid = 1; | |
45 | uint8_t feature = 1; | |
46 | uint32_t feature_cdw11 = 1; | |
47 | uint32_t feature_cdw12 = 1; | |
48 | uint8_t get_feature = 1; | |
49 | uint32_t get_feature_cdw11 = 1; | |
50 | uint32_t fw_img_size = 1024; | |
51 | uint32_t fw_img_offset = 0; | |
52 | uint16_t abort_cid = 1; | |
53 | uint16_t abort_sqid = 1; | |
54 | uint32_t namespace_management_nsid = 1; | |
55 | uint32_t format_nvme_nsid = 1; | |
56 | ||
57 | typedef void (*verify_request_fn_t)(struct nvme_request *req); | |
58 | verify_request_fn_t verify_fn; | |
59 | ||
60 | static void verify_firmware_log_page(struct nvme_request *req) | |
61 | { | |
62 | uint32_t temp_cdw10; | |
63 | ||
64 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
65 | CU_ASSERT(req->cmd.nsid == SPDK_NVME_GLOBAL_NS_TAG); | |
66 | ||
67 | temp_cdw10 = ((sizeof(struct spdk_nvme_firmware_page) / sizeof(uint32_t) - 1) << 16) | | |
68 | SPDK_NVME_LOG_FIRMWARE_SLOT; | |
69 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
70 | } | |
71 | ||
72 | static void verify_health_log_page(struct nvme_request *req) | |
73 | { | |
74 | uint32_t temp_cdw10; | |
75 | ||
76 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
77 | CU_ASSERT(req->cmd.nsid == health_log_nsid); | |
78 | ||
79 | temp_cdw10 = ((sizeof(struct spdk_nvme_health_information_page) / sizeof(uint32_t) - 1) << 16) | | |
80 | SPDK_NVME_LOG_HEALTH_INFORMATION; | |
81 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
82 | } | |
83 | ||
84 | static void verify_error_log_page(struct nvme_request *req) | |
85 | { | |
86 | uint32_t temp_cdw10; | |
87 | ||
88 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
89 | CU_ASSERT(req->cmd.nsid == SPDK_NVME_GLOBAL_NS_TAG); | |
90 | ||
91 | temp_cdw10 = (((sizeof(struct spdk_nvme_error_information_entry) * error_num_entries) / | |
92 | sizeof(uint32_t) - 1) << 16) | SPDK_NVME_LOG_ERROR; | |
93 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
94 | } | |
95 | ||
96 | static void verify_set_feature_cmd(struct nvme_request *req) | |
97 | { | |
98 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_SET_FEATURES); | |
99 | CU_ASSERT(req->cmd.cdw10 == feature); | |
100 | CU_ASSERT(req->cmd.cdw11 == feature_cdw11); | |
101 | CU_ASSERT(req->cmd.cdw12 == feature_cdw12); | |
102 | } | |
103 | ||
104 | static void verify_get_feature_cmd(struct nvme_request *req) | |
105 | { | |
106 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_FEATURES); | |
107 | CU_ASSERT(req->cmd.cdw10 == get_feature); | |
108 | CU_ASSERT(req->cmd.cdw11 == get_feature_cdw11); | |
109 | } | |
110 | ||
111 | static void verify_abort_cmd(struct nvme_request *req) | |
112 | { | |
113 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_ABORT); | |
114 | CU_ASSERT(req->cmd.cdw10 == (((uint32_t)abort_cid << 16) | abort_sqid)); | |
115 | } | |
116 | ||
117 | static void verify_io_raw_cmd(struct nvme_request *req) | |
118 | { | |
119 | struct spdk_nvme_cmd command = {}; | |
120 | ||
121 | CU_ASSERT(memcmp(&req->cmd, &command, sizeof(req->cmd)) == 0); | |
122 | } | |
123 | ||
124 | static void verify_intel_smart_log_page(struct nvme_request *req) | |
125 | { | |
126 | uint32_t temp_cdw10; | |
127 | ||
128 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
129 | CU_ASSERT(req->cmd.nsid == health_log_nsid); | |
130 | ||
131 | temp_cdw10 = ((sizeof(struct spdk_nvme_intel_smart_information_page) / | |
132 | sizeof(uint32_t) - 1) << 16) | | |
133 | SPDK_NVME_INTEL_LOG_SMART; | |
134 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
135 | } | |
136 | ||
137 | static void verify_intel_temperature_log_page(struct nvme_request *req) | |
138 | { | |
139 | uint32_t temp_cdw10; | |
140 | ||
141 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
142 | ||
143 | temp_cdw10 = ((sizeof(struct spdk_nvme_intel_temperature_page) / sizeof(uint32_t) - 1) << 16) | | |
144 | SPDK_NVME_INTEL_LOG_TEMPERATURE; | |
145 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
146 | } | |
147 | ||
148 | static void verify_intel_read_latency_log_page(struct nvme_request *req) | |
149 | { | |
150 | uint32_t temp_cdw10; | |
151 | ||
152 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
153 | ||
154 | temp_cdw10 = ((sizeof(struct spdk_nvme_intel_rw_latency_page) / sizeof(uint32_t) - 1) << 16) | | |
155 | SPDK_NVME_INTEL_LOG_READ_CMD_LATENCY; | |
156 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
157 | } | |
158 | ||
159 | static void verify_intel_write_latency_log_page(struct nvme_request *req) | |
160 | { | |
161 | uint32_t temp_cdw10; | |
162 | ||
163 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
164 | ||
165 | temp_cdw10 = ((sizeof(struct spdk_nvme_intel_rw_latency_page) / sizeof(uint32_t) - 1) << 16) | | |
166 | SPDK_NVME_INTEL_LOG_WRITE_CMD_LATENCY; | |
167 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
168 | } | |
169 | ||
170 | static void verify_intel_get_log_page_directory(struct nvme_request *req) | |
171 | { | |
172 | uint32_t temp_cdw10; | |
173 | ||
174 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
175 | ||
176 | temp_cdw10 = ((sizeof(struct spdk_nvme_intel_log_page_directory) / sizeof(uint32_t) - 1) << 16) | | |
177 | SPDK_NVME_INTEL_LOG_PAGE_DIRECTORY; | |
178 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
179 | } | |
180 | ||
181 | static void verify_intel_marketing_description_log_page(struct nvme_request *req) | |
182 | { | |
183 | uint32_t temp_cdw10; | |
184 | ||
185 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_GET_LOG_PAGE); | |
186 | ||
187 | temp_cdw10 = ((sizeof(struct spdk_nvme_intel_marketing_description_page) / sizeof( | |
188 | uint32_t) - 1) << 16) | | |
189 | SPDK_NVME_INTEL_MARKETING_DESCRIPTION; | |
190 | CU_ASSERT(req->cmd.cdw10 == temp_cdw10); | |
191 | } | |
192 | ||
193 | static void verify_namespace_attach(struct nvme_request *req) | |
194 | { | |
195 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_NS_ATTACHMENT); | |
196 | CU_ASSERT(req->cmd.cdw10 == SPDK_NVME_NS_CTRLR_ATTACH); | |
197 | CU_ASSERT(req->cmd.nsid == namespace_management_nsid); | |
198 | } | |
199 | ||
200 | static void verify_namespace_detach(struct nvme_request *req) | |
201 | { | |
202 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_NS_ATTACHMENT); | |
203 | CU_ASSERT(req->cmd.cdw10 == SPDK_NVME_NS_CTRLR_DETACH); | |
204 | CU_ASSERT(req->cmd.nsid == namespace_management_nsid); | |
205 | } | |
206 | ||
207 | static void verify_namespace_create(struct nvme_request *req) | |
208 | { | |
209 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_NS_MANAGEMENT); | |
210 | CU_ASSERT(req->cmd.cdw10 == SPDK_NVME_NS_MANAGEMENT_CREATE); | |
211 | CU_ASSERT(req->cmd.nsid == 0); | |
212 | } | |
213 | ||
214 | static void verify_namespace_delete(struct nvme_request *req) | |
215 | { | |
216 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_NS_MANAGEMENT); | |
217 | CU_ASSERT(req->cmd.cdw10 == SPDK_NVME_NS_MANAGEMENT_DELETE); | |
218 | CU_ASSERT(req->cmd.nsid == namespace_management_nsid); | |
219 | } | |
220 | ||
221 | static void verify_format_nvme(struct nvme_request *req) | |
222 | { | |
223 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_FORMAT_NVM); | |
224 | CU_ASSERT(req->cmd.cdw10 == 0); | |
225 | CU_ASSERT(req->cmd.nsid == format_nvme_nsid); | |
226 | } | |
227 | ||
228 | static void verify_fw_commit(struct nvme_request *req) | |
229 | { | |
230 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_FIRMWARE_COMMIT); | |
231 | CU_ASSERT(req->cmd.cdw10 == 0x09); | |
232 | } | |
233 | ||
234 | static void verify_fw_image_download(struct nvme_request *req) | |
235 | { | |
236 | CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD); | |
237 | CU_ASSERT(req->cmd.cdw10 == (fw_img_size >> 2) - 1); | |
238 | CU_ASSERT(req->cmd.cdw11 == fw_img_offset >> 2); | |
239 | } | |
240 | ||
241 | struct nvme_request * | |
242 | nvme_allocate_request(struct spdk_nvme_qpair *qpair, | |
243 | const struct nvme_payload *payload, uint32_t payload_size, | |
244 | spdk_nvme_cmd_cb cb_fn, | |
245 | void *cb_arg) | |
246 | { | |
247 | struct nvme_request *req = &g_req; | |
248 | ||
249 | memset(req, 0, sizeof(*req)); | |
250 | ||
251 | req->payload = *payload; | |
252 | req->payload_size = payload_size; | |
253 | ||
254 | req->cb_fn = cb_fn; | |
255 | req->cb_arg = cb_arg; | |
256 | req->qpair = qpair; | |
257 | req->pid = getpid(); | |
258 | ||
259 | return req; | |
260 | } | |
261 | ||
262 | struct nvme_request * | |
263 | nvme_allocate_request_contig(struct spdk_nvme_qpair *qpair, void *buffer, uint32_t payload_size, | |
264 | spdk_nvme_cmd_cb cb_fn, void *cb_arg) | |
265 | { | |
266 | struct nvme_payload payload; | |
267 | ||
268 | payload.type = NVME_PAYLOAD_TYPE_CONTIG; | |
269 | payload.u.contig = buffer; | |
270 | payload.md = NULL; | |
271 | ||
272 | return nvme_allocate_request(qpair, &payload, payload_size, cb_fn, cb_arg); | |
273 | } | |
274 | ||
275 | struct nvme_request * | |
276 | nvme_allocate_request_null(struct spdk_nvme_qpair *qpair, spdk_nvme_cmd_cb cb_fn, void *cb_arg) | |
277 | { | |
278 | return nvme_allocate_request_contig(qpair, NULL, 0, cb_fn, cb_arg); | |
279 | } | |
280 | ||
281 | struct nvme_request * | |
282 | nvme_allocate_request_user_copy(struct spdk_nvme_qpair *qpair, void *buffer, uint32_t payload_size, | |
283 | spdk_nvme_cmd_cb cb_fn, void *cb_arg, bool host_to_controller) | |
284 | { | |
285 | /* For the unit test, we don't actually need to copy the buffer */ | |
286 | return nvme_allocate_request_contig(qpair, buffer, payload_size, cb_fn, cb_arg); | |
287 | } | |
288 | ||
289 | void | |
290 | nvme_free_request(struct nvme_request *req) | |
291 | { | |
292 | return; | |
293 | } | |
294 | ||
295 | int | |
296 | nvme_qpair_submit_request(struct spdk_nvme_qpair *qpair, struct nvme_request *req) | |
297 | { | |
298 | verify_fn(req); | |
299 | /* stop analyzer from thinking stack variable addresses are stored in a global */ | |
300 | memset(req, 0, sizeof(*req)); | |
301 | ||
302 | return 0; | |
303 | } | |
304 | ||
305 | int | |
306 | nvme_ctrlr_submit_admin_request(struct spdk_nvme_ctrlr *ctrlr, struct nvme_request *req) | |
307 | { | |
308 | verify_fn(req); | |
309 | /* stop analyzer from thinking stack variable addresses are stored in a global */ | |
310 | memset(req, 0, sizeof(*req)); | |
311 | ||
312 | return 0; | |
313 | } | |
314 | ||
315 | static void | |
316 | test_firmware_get_log_page(void) | |
317 | { | |
318 | struct spdk_nvme_ctrlr ctrlr = {}; | |
319 | struct spdk_nvme_firmware_page payload = {}; | |
320 | ||
321 | verify_fn = verify_firmware_log_page; | |
322 | ||
323 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_LOG_FIRMWARE_SLOT, SPDK_NVME_GLOBAL_NS_TAG, | |
324 | &payload, | |
325 | sizeof(payload), 0, NULL, NULL); | |
326 | } | |
327 | ||
328 | static void | |
329 | test_health_get_log_page(void) | |
330 | { | |
331 | struct spdk_nvme_ctrlr ctrlr = {}; | |
332 | struct spdk_nvme_health_information_page payload = {}; | |
333 | ||
334 | verify_fn = verify_health_log_page; | |
335 | ||
336 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_LOG_HEALTH_INFORMATION, health_log_nsid, | |
337 | &payload, | |
338 | sizeof(payload), 0, NULL, NULL); | |
339 | } | |
340 | ||
341 | static void | |
342 | test_error_get_log_page(void) | |
343 | { | |
344 | struct spdk_nvme_ctrlr ctrlr = {}; | |
345 | struct spdk_nvme_error_information_entry payload = {}; | |
346 | ||
347 | ctrlr.cdata.elpe = CTRLR_CDATA_ELPE; | |
348 | ||
349 | verify_fn = verify_error_log_page; | |
350 | ||
351 | /* valid page */ | |
352 | error_num_entries = 1; | |
353 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_LOG_ERROR, SPDK_NVME_GLOBAL_NS_TAG, &payload, | |
354 | sizeof(payload), 0, NULL, NULL); | |
355 | } | |
356 | ||
357 | static void test_intel_smart_get_log_page(void) | |
358 | { | |
359 | struct spdk_nvme_ctrlr ctrlr = {}; | |
360 | struct spdk_nvme_intel_smart_information_page payload = {}; | |
361 | ||
362 | verify_fn = verify_intel_smart_log_page; | |
363 | ||
364 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_INTEL_LOG_SMART, health_log_nsid, &payload, | |
365 | sizeof(payload), 0, NULL, NULL); | |
366 | } | |
367 | ||
368 | static void test_intel_temperature_get_log_page(void) | |
369 | { | |
370 | struct spdk_nvme_ctrlr ctrlr = {}; | |
371 | struct spdk_nvme_intel_temperature_page payload = {}; | |
372 | ||
373 | verify_fn = verify_intel_temperature_log_page; | |
374 | ||
375 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_INTEL_LOG_TEMPERATURE, SPDK_NVME_GLOBAL_NS_TAG, | |
376 | &payload, sizeof(payload), 0, NULL, NULL); | |
377 | } | |
378 | ||
379 | static void test_intel_read_latency_get_log_page(void) | |
380 | { | |
381 | struct spdk_nvme_ctrlr ctrlr = {}; | |
382 | struct spdk_nvme_intel_rw_latency_page payload = {}; | |
383 | ||
384 | verify_fn = verify_intel_read_latency_log_page; | |
385 | ||
386 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_INTEL_LOG_READ_CMD_LATENCY, | |
387 | SPDK_NVME_GLOBAL_NS_TAG, | |
388 | &payload, sizeof(payload), 0, NULL, NULL); | |
389 | } | |
390 | ||
391 | static void test_intel_write_latency_get_log_page(void) | |
392 | { | |
393 | struct spdk_nvme_ctrlr ctrlr = {}; | |
394 | struct spdk_nvme_intel_rw_latency_page payload = {}; | |
395 | ||
396 | verify_fn = verify_intel_write_latency_log_page; | |
397 | ||
398 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_INTEL_LOG_WRITE_CMD_LATENCY, | |
399 | SPDK_NVME_GLOBAL_NS_TAG, | |
400 | &payload, sizeof(payload), 0, NULL, NULL); | |
401 | } | |
402 | ||
403 | static void test_intel_get_log_page_directory(void) | |
404 | { | |
405 | struct spdk_nvme_ctrlr ctrlr = {}; | |
406 | struct spdk_nvme_intel_log_page_directory payload = {}; | |
407 | ||
408 | verify_fn = verify_intel_get_log_page_directory; | |
409 | ||
410 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_INTEL_LOG_PAGE_DIRECTORY, | |
411 | SPDK_NVME_GLOBAL_NS_TAG, | |
412 | &payload, sizeof(payload), 0, NULL, NULL); | |
413 | } | |
414 | ||
415 | static void test_intel_marketing_description_get_log_page(void) | |
416 | { | |
417 | struct spdk_nvme_ctrlr ctrlr = {}; | |
418 | struct spdk_nvme_intel_marketing_description_page payload = {}; | |
419 | ||
420 | verify_fn = verify_intel_marketing_description_log_page; | |
421 | ||
422 | spdk_nvme_ctrlr_cmd_get_log_page(&ctrlr, SPDK_NVME_INTEL_MARKETING_DESCRIPTION, | |
423 | SPDK_NVME_GLOBAL_NS_TAG, | |
424 | &payload, sizeof(payload), 0, NULL, NULL); | |
425 | } | |
426 | ||
427 | static void test_generic_get_log_pages(void) | |
428 | { | |
429 | test_error_get_log_page(); | |
430 | test_health_get_log_page(); | |
431 | test_firmware_get_log_page(); | |
432 | } | |
433 | ||
434 | static void test_intel_get_log_pages(void) | |
435 | { | |
436 | test_intel_get_log_page_directory(); | |
437 | test_intel_smart_get_log_page(); | |
438 | test_intel_temperature_get_log_page(); | |
439 | test_intel_read_latency_get_log_page(); | |
440 | test_intel_write_latency_get_log_page(); | |
441 | test_intel_marketing_description_get_log_page(); | |
442 | } | |
443 | ||
444 | static void | |
445 | test_set_feature_cmd(void) | |
446 | { | |
447 | struct spdk_nvme_ctrlr ctrlr = {}; | |
448 | ||
449 | verify_fn = verify_set_feature_cmd; | |
450 | ||
451 | spdk_nvme_ctrlr_cmd_set_feature(&ctrlr, feature, feature_cdw11, feature_cdw12, NULL, 0, NULL, NULL); | |
452 | } | |
453 | ||
454 | ||
455 | static void | |
456 | test_get_feature_cmd(void) | |
457 | { | |
458 | struct spdk_nvme_ctrlr ctrlr = {}; | |
459 | ||
460 | verify_fn = verify_get_feature_cmd; | |
461 | ||
462 | spdk_nvme_ctrlr_cmd_get_feature(&ctrlr, get_feature, get_feature_cdw11, NULL, 0, NULL, NULL); | |
463 | } | |
464 | ||
465 | static void | |
466 | test_abort_cmd(void) | |
467 | { | |
468 | struct spdk_nvme_ctrlr ctrlr = {}; | |
469 | struct spdk_nvme_qpair qpair = {}; | |
470 | ||
471 | STAILQ_INIT(&ctrlr.queued_aborts); | |
472 | ||
473 | verify_fn = verify_abort_cmd; | |
474 | ||
475 | qpair.id = abort_sqid; | |
476 | spdk_nvme_ctrlr_cmd_abort(&ctrlr, &qpair, abort_cid, NULL, NULL); | |
477 | } | |
478 | ||
479 | static void | |
480 | test_io_raw_cmd(void) | |
481 | { | |
482 | struct spdk_nvme_ctrlr ctrlr = {}; | |
483 | struct spdk_nvme_qpair qpair = {}; | |
484 | struct spdk_nvme_cmd cmd = {}; | |
485 | ||
486 | verify_fn = verify_io_raw_cmd; | |
487 | ||
488 | spdk_nvme_ctrlr_cmd_io_raw(&ctrlr, &qpair, &cmd, NULL, 1, NULL, NULL); | |
489 | } | |
490 | ||
491 | static void | |
492 | test_get_log_pages(void) | |
493 | { | |
494 | test_generic_get_log_pages(); | |
495 | test_intel_get_log_pages(); | |
496 | } | |
497 | ||
498 | static void | |
499 | test_namespace_attach(void) | |
500 | { | |
501 | struct spdk_nvme_ctrlr ctrlr = {}; | |
502 | struct spdk_nvme_ctrlr_list payload = {}; | |
503 | ||
504 | verify_fn = verify_namespace_attach; | |
505 | ||
506 | nvme_ctrlr_cmd_attach_ns(&ctrlr, namespace_management_nsid, &payload, NULL, NULL); | |
507 | } | |
508 | ||
509 | static void | |
510 | test_namespace_detach(void) | |
511 | { | |
512 | struct spdk_nvme_ctrlr ctrlr = {}; | |
513 | struct spdk_nvme_ctrlr_list payload = {}; | |
514 | ||
515 | verify_fn = verify_namespace_detach; | |
516 | ||
517 | nvme_ctrlr_cmd_detach_ns(&ctrlr, namespace_management_nsid, &payload, NULL, NULL); | |
518 | } | |
519 | ||
520 | static void | |
521 | test_namespace_create(void) | |
522 | { | |
523 | struct spdk_nvme_ctrlr ctrlr = {}; | |
524 | struct spdk_nvme_ns_data payload = {}; | |
525 | ||
526 | verify_fn = verify_namespace_create; | |
527 | nvme_ctrlr_cmd_create_ns(&ctrlr, &payload, NULL, NULL); | |
528 | } | |
529 | ||
530 | static void | |
531 | test_namespace_delete(void) | |
532 | { | |
533 | struct spdk_nvme_ctrlr ctrlr = {}; | |
534 | ||
535 | verify_fn = verify_namespace_delete; | |
536 | nvme_ctrlr_cmd_delete_ns(&ctrlr, namespace_management_nsid, NULL, NULL); | |
537 | } | |
538 | ||
539 | static void | |
540 | test_format_nvme(void) | |
541 | { | |
542 | struct spdk_nvme_ctrlr ctrlr = {}; | |
543 | struct spdk_nvme_format format = {}; | |
544 | ||
545 | verify_fn = verify_format_nvme; | |
546 | ||
547 | nvme_ctrlr_cmd_format(&ctrlr, format_nvme_nsid, &format, NULL, NULL); | |
548 | } | |
549 | ||
550 | static void | |
551 | test_fw_commit(void) | |
552 | { | |
553 | struct spdk_nvme_ctrlr ctrlr = {}; | |
554 | struct spdk_nvme_fw_commit fw_commit = {}; | |
555 | ||
556 | fw_commit.ca = SPDK_NVME_FW_COMMIT_REPLACE_AND_ENABLE_IMG; | |
557 | fw_commit.fs = 1; | |
558 | ||
559 | verify_fn = verify_fw_commit; | |
560 | ||
561 | nvme_ctrlr_cmd_fw_commit(&ctrlr, &fw_commit, NULL, NULL); | |
562 | } | |
563 | ||
564 | static void | |
565 | test_fw_image_download(void) | |
566 | { | |
567 | struct spdk_nvme_ctrlr ctrlr = {}; | |
568 | ||
569 | verify_fn = verify_fw_image_download; | |
570 | ||
571 | nvme_ctrlr_cmd_fw_image_download(&ctrlr, fw_img_size, fw_img_offset, NULL, | |
572 | NULL, NULL); | |
573 | } | |
574 | ||
575 | int main(int argc, char **argv) | |
576 | { | |
577 | CU_pSuite suite = NULL; | |
578 | unsigned int num_failures; | |
579 | ||
580 | if (CU_initialize_registry() != CUE_SUCCESS) { | |
581 | return CU_get_error(); | |
582 | } | |
583 | ||
584 | suite = CU_add_suite("nvme_ctrlr_cmd", NULL, NULL); | |
585 | if (suite == NULL) { | |
586 | CU_cleanup_registry(); | |
587 | return CU_get_error(); | |
588 | } | |
589 | ||
590 | if ( | |
591 | CU_add_test(suite, "test ctrlr cmd get_log_pages", test_get_log_pages) == NULL | |
592 | || CU_add_test(suite, "test ctrlr cmd set_feature", test_set_feature_cmd) == NULL | |
593 | || CU_add_test(suite, "test ctrlr cmd get_feature", test_get_feature_cmd) == NULL | |
594 | || CU_add_test(suite, "test ctrlr cmd abort_cmd", test_abort_cmd) == NULL | |
595 | || CU_add_test(suite, "test ctrlr cmd io_raw_cmd", test_io_raw_cmd) == NULL | |
596 | || CU_add_test(suite, "test ctrlr cmd namespace_attach", test_namespace_attach) == NULL | |
597 | || CU_add_test(suite, "test ctrlr cmd namespace_detach", test_namespace_detach) == NULL | |
598 | || CU_add_test(suite, "test ctrlr cmd namespace_create", test_namespace_create) == NULL | |
599 | || CU_add_test(suite, "test ctrlr cmd namespace_delete", test_namespace_delete) == NULL | |
600 | || CU_add_test(suite, "test ctrlr cmd format_nvme", test_format_nvme) == NULL | |
601 | || CU_add_test(suite, "test ctrlr cmd fw_commit", test_fw_commit) == NULL | |
602 | || CU_add_test(suite, "test ctrlr cmd fw_image_download", test_fw_image_download) == NULL | |
603 | ) { | |
604 | CU_cleanup_registry(); | |
605 | return CU_get_error(); | |
606 | } | |
607 | ||
608 | CU_basic_set_mode(CU_BRM_VERBOSE); | |
609 | CU_basic_run_tests(); | |
610 | num_failures = CU_get_number_of_failures(); | |
611 | CU_cleanup_registry(); | |
612 | return num_failures; | |
613 | } |