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