forked from nvmecompliance/tnvme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tnvmeHelpers.cpp
739 lines (654 loc) · 24.5 KB
/
tnvmeHelpers.cpp
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
/*
* Copyright (c) 2011, Intel Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include <errno.h>
#include <vector>
#include <unistd.h>
#include "tnvmeHelpers.h"
#include "globals.h"
#include "Utils/kernelAPI.h"
#include "Cmds/setFeatures.h"
#define INFORMATIVE_GRPNUM 0
/**
* A function to execute the desired test case(s). Param ignore
* indicates that when an error is reported from a test case, it is ignored to
* the point that the next test case will be allowed to run, if and only if,
* there are more tests which could have run if the test passed. The error
* itself won't be lost. because the end return value from this function will
* indicate an error was detected even though it was ignored.
* @param cl Pass the cmd line parameters
* @param groups Pass all groups being considered for execution
* @return true upon success, false if failures/errors detected;
*/
bool
ExecuteTests(struct CmdLine &cl, vector<Group *> &groups)
{
size_t iLoop;
int numPassed = 0;
int numFailed = 0;
int numSkipped = 0;
bool allTestsPass = true; // assuming success until we find otherwise
bool thisTestPass;
TestIteratorType testIter;
if ((cl.test.t.group != UINT_MAX) && (cl.test.t.group >= groups.size())) {
LOG_ERR("Specified test group does not exist");
return false;
}
for (iLoop = 0; iLoop < cl.loop; iLoop++) {
LOG_NRM("Start loop execution #%ld", iLoop);
for (size_t iGrp = 0; iGrp < groups.size(); iGrp++) {
bool allHaveRun = false;
// Always run the Informative group 1st, i.e. 0 always runs 1st
if (iGrp == INFORMATIVE_GRPNUM) {
LOG_NRM("Executing a new group, start from known point");
if (KernelAPI::SoftReset() == false)
return false;
// Run all tests within this group
testIter = groups[iGrp]->GetTestIterator();
while (allHaveRun == false) {
thisTestPass = true;
switch (groups[iGrp]->RunTest(testIter, cl.skiptest)) {
case Group::TR_SUCCESS:
numPassed++;
break;
case Group::TR_FAIL:
allTestsPass = false;
thisTestPass = false;
numFailed++;
break;
case Group::TR_SKIPPING:
numSkipped++;
break;
case Group::TR_NOTFOUND:
allHaveRun = true;
break;
}
if ((cl.ignore == false) && (allTestsPass == false)) {
goto FAIL_OUT;
} else if (cl.ignore && (thisTestPass == false)) {
LOG_NRM("Detected error, but forced to ignore");
break; // don't execute any more within this group
}
}
continue; // continue with next test in next group
}
// Now handle anything spec'd in the --test <cmd line option>
if (cl.test.t.group == UINT_MAX) {
// Do not run Informative group, that group always runs above
if (iGrp == INFORMATIVE_GRPNUM)
break; // continue with next test in next group
LOG_NRM("Executing a new group, start from known point");
if (KernelAPI::SoftReset() == false)
return false;
// Run all tests within all groups
testIter = groups[iGrp]->GetTestIterator();
while (allHaveRun == false) {
thisTestPass = true;
switch (groups[iGrp]->RunTest(testIter, cl.skiptest)) {
case Group::TR_SUCCESS:
numPassed++;
break;
case Group::TR_FAIL:
allTestsPass = false;
thisTestPass = false;
numFailed++;
break;
case Group::TR_SKIPPING:
numSkipped++;
break;
case Group::TR_NOTFOUND:
allHaveRun = true;
break;
}
if ((cl.ignore == false) && (allTestsPass == false)) {
goto FAIL_OUT;
} else if (cl.ignore && (thisTestPass == false)) {
LOG_NRM("Detected error, but forced to ignore");
break; // continue with next test in next group
}
}
} else if ((cl.test.t.major == UINT_MAX) ||
(cl.test.t.minor == UINT_MAX)) {
// Run all tests within spec'd group, except Informative grp
if ((iGrp == cl.test.t.group) && (iGrp != INFORMATIVE_GRPNUM)) {
LOG_NRM("Executing a new group, start from known point");
if (KernelAPI::SoftReset() == false)
return false;
// Run all tests within this group
testIter = groups[iGrp]->GetTestIterator();
while (allHaveRun == false) {
thisTestPass = true;
switch (groups[iGrp]->RunTest(testIter, cl.skiptest)) {
case Group::TR_SUCCESS:
numPassed++;
break;
case Group::TR_FAIL:
allTestsPass = false;
thisTestPass = false;
numFailed++;
break;
case Group::TR_SKIPPING:
numSkipped++;
break;
case Group::TR_NOTFOUND:
allHaveRun = true;
break;
}
if ((cl.ignore == false) && (allTestsPass == false)) {
goto FAIL_OUT;
} else if (cl.ignore && (thisTestPass == false)) {
LOG_NRM("Detected error, but forced to ignore");
break; // continue with next test in next group
}
}
break; // check if more loops must occur
}
} else {
// Run spec'd test within spec'd group, except Informative grp
if ((iGrp == cl.test.t.group) && (iGrp != INFORMATIVE_GRPNUM)) {
LOG_NRM("Executing a new group, start from known point");
if (KernelAPI::SoftReset() == false)
return false;
switch (groups[iGrp]->RunTest(cl.test.t, cl.skiptest)) {
case Group::TR_SUCCESS:
numPassed++;
break;
case Group::TR_FAIL:
allTestsPass = false;
numFailed++;
break;
case Group::TR_SKIPPING:
numSkipped++;
break;
case Group::TR_NOTFOUND:
LOG_DBG("Internal programming error, unknown test");
break;
}
if ((cl.ignore == false) && (allTestsPass == false))
goto FAIL_OUT;
break; // check if more loops must occur
}
}
}
LOG_NRM("Iteration SUMMARY passed : %d", numPassed);
if (numFailed) {
LOG_NRM(" failed : %d <----------", numFailed);
} else {
LOG_NRM(" failed : 0");
}
LOG_NRM(" skipped: %d", numSkipped);
LOG_NRM(" total : %d",
numPassed+numFailed+numSkipped);
LOG_NRM("Stop loop execution #%ld", iLoop);
}
return allTestsPass;
FAIL_OUT:
LOG_NRM("Tests passed: %d", numPassed);
if (numFailed) {
LOG_NRM(" failed: %d <--------------", numFailed);
} else {
LOG_NRM(" failed: 0");
}
LOG_NRM(" skipped: %d", numSkipped);
LOG_NRM(" total: %d", numPassed+numFailed+numSkipped);
LOG_NRM("Stop loop execution #%ld", iLoop);
return allTestsPass;
}
/**
* A function to specifically handle parsing cmd lines of the form
* "--skiptest <filename>".
* @param target Pass a structure to populate with parsing results
* @param optarg Pass the 'optarg' argument from the getopt_long() API.
* @return true upon successful parsing, otherwise false.
*/
bool
ParseSkipTestCmdLine(vector<TestRef> &skipTest, const char *optarg)
{
int fd;
ssize_t numRead;
char buffer[80];
string contents;
string line;
TestTarget tmp;
if ((fd = open(optarg, O_RDWR)) == -1) {
LOG_ERR("file=%s: %s", optarg, strerror(errno));
return false;
}
while ((numRead = read(fd, buffer, (sizeof(buffer)-1))) != -1) {
if (numRead == 0)
break;
buffer[numRead] = '\0';
contents += buffer;
}
if (numRead == -1) {
LOG_ERR("file=%s: %s", optarg, strerror(errno));
return false;
}
// Parse and make sense of the file's contents
for (size_t i = 0; i < contents.size(); i++) {
bool processThisLine = false;
if (contents[i] == '#') {
// Comment start; goes until the end of this line
for (size_t j = i; j < contents.size(); j++) {
if ((contents[j] == '\n') || (contents[j] == '\r')) {
i = j;
processThisLine = true;
break;
}
}
} else if ((contents[i] == '\n') || (contents[i] == '\r')) {
processThisLine = true;
} else {
if (isalnum(contents[i]) ||
(contents[i] == '.') ||
(contents[i] == ':')) {
line += contents[i];
}
}
if (processThisLine) {
if (line.size()) {
if (ParseTargetCmdLine(tmp, line.c_str()) == false) {
close(fd);
return false;
}
TestRef skipThis = tmp.t;
skipTest.push_back(skipThis);
line = "";
}
}
}
// Report what tests will be skipped
string output = "Execution will skip test case(s): <grp>:<major>.<minor>=";
char work[20];
for (size_t i = 0; i < skipTest.size(); i++ ) {
if ((skipTest[i].major == UINT_MAX) ||
(skipTest[i].minor == UINT_MAX)) {
snprintf(work, sizeof(work), "%ld:ALL.ALL, ", skipTest[i].group);
} else {
snprintf(work, sizeof(work), "%ld:%ld.%ld, ",
skipTest[i].group, skipTest[i].major, skipTest[i].minor);
}
output += work;
}
LOG_NRM("%s", output.c_str());
close(fd);
return true;
}
/**
* A function to specifically handle parsing cmd lines of the form
* "[<grp> | <grp>:<test>]" where the absent of the optional parameters means
* a user is specifying "all" things.
* @param target Pass a structure to populate with parsing results
* @param optarg Pass the 'optarg' argument from the getopt_long() API.
* @return true upon successful parsing, otherwise false.
*/
bool
ParseTargetCmdLine(TestTarget &target, const char *optarg)
{
size_t ulwork;
char *endptr;
string swork;
long tmp;
target.req = true;
target.t.group = UINT_MAX;
target.t.major = UINT_MAX;
target.t.minor = UINT_MAX;
if (optarg == NULL)
return true;
swork = optarg;
if ((ulwork = swork.find(":", 0)) == string::npos) {
// Specified format <grp>
tmp = strtol(swork.c_str(), &endptr, 10);
if (*endptr != '\0') {
LOG_ERR("Unrecognized format <grp>=%s", optarg);
return false;
} else if (tmp < 0) {
LOG_ERR("<grp> values < 0 are not supported");
return false;
}
target.t.group = tmp;
} else {
// Specified format <grp>:<test>
tmp = strtol(swork.substr(0, swork.size()).c_str(), &endptr, 10);
if (*endptr != ':') {
LOG_ERR("Missing ':' character in format string");
return false;
} else if (tmp < 0) {
LOG_ERR("<grp> values < 0 are not supported");
return false;
}
target.t.group = tmp;
// Find major piece of <test>
swork = swork.substr(swork.find_first_of(':') + 1, swork.length());
if (swork.length() == 0) {
LOG_ERR("Missing <test> format string");
return false;
}
tmp = strtol(swork.substr(0, swork.size()).c_str(), &endptr, 10);
if (*endptr != '.') {
LOG_ERR("Missing '.' character in format string");
return false;
} else if (tmp < 0) {
LOG_ERR("<major> values < 0 are not supported");
return false;
}
target.t.major = tmp;
// Find minor piece of <test>
swork = swork.substr(swork.find_first_of('.') + 1, swork.length());
if (swork.length() == 0) {
LOG_ERR("Unrecognized format <grp>:<major>.<minor>=%s", optarg);
return false;
}
tmp = strtol(swork.substr(0, swork.size()).c_str(), &endptr, 10);
if (*endptr != '\0') {
LOG_ERR("Unrecognized format <grp>:<major>.<minor>=%s", optarg);
return false;
} else if (tmp < 0) {
LOG_ERR("<minor> values < 0 are not supported");
return false;
}
target.t.minor = tmp;
}
if (target.t.group == UINT_MAX) {
LOG_ERR("Unrecognized format <grp>=%s\n", optarg);
return false;
} else if (((target.t.major == UINT_MAX) && (target.t.minor != UINT_MAX)) ||
((target.t.major != UINT_MAX) && (target.t.minor == UINT_MAX))) {
LOG_ERR("Unrecognized format <grp>:<major>.<minor>=%s", optarg);
return false;
}
return true;
}
/**
* A function to specifically handle parsing cmd lines of the form
* "<space:offset:num:acc>".
* @param rmmap Pass a structure to populate with parsing results
* @param optarg Pass the 'optarg' argument from the getopt_long() API.
* @return true upon successful parsing, otherwise false.
*/
bool
ParseRmmapCmdLine(RmmapIo &rmmap, const char *optarg)
{
size_t ulwork;
char *endptr;
string swork;
size_t tmp;
string sacc;
rmmap.req = true;
rmmap.space = NVMEIO_FENCE;
rmmap.offset = 0;
rmmap.size = 0;
rmmap.acc = ACC_FENCE;
LOG_DBG("Option selected = %s", optarg);
// Parsing <space:offset:size>
swork = optarg;
if ((ulwork = swork.find(":", 0)) == string::npos) {
LOG_ERR("Unrecognized format <space:off:size:acc>=%s", optarg);
return false;
}
if (strcmp("PCI", swork.substr(0, ulwork).c_str()) == 0) {
rmmap.space = NVMEIO_PCI_HDR;
} else if (strcmp("BAR01", swork.substr(0, ulwork).c_str()) == 0) {
rmmap.space = NVMEIO_BAR01;
} else {
LOG_ERR("Unrecognized identifier <space>=%s", optarg);
return false;
}
// Parsing <off:size:acc>
swork = swork.substr(ulwork+1, swork.size());
tmp = strtoul(swork.substr(0, swork.size()).c_str(), &endptr, 16);
if (*endptr != ':') {
LOG_ERR("Unrecognized format <off:size:acc>=%s", optarg);
return false;
}
rmmap.offset = tmp;
// Parsing <size:acc>
swork = swork.substr(swork.find_first_of(':') + 1, swork.length());
if (swork.length() == 0) {
LOG_ERR("Missing <size> format string");
return false;
}
tmp = strtoul(swork.substr(0, swork.size()).c_str(), &endptr, 16);
if (*endptr != ':') {
LOG_ERR("Unrecognized format <size:acc>=%s", optarg);
return false;
}
rmmap.size = tmp;
// Parsing <acc>
swork = swork.substr(swork.find_first_of(':') + 1, swork.length());
if (swork.length() == 0) {
LOG_ERR("Missing <acc> format string");
return false;
}
sacc = swork.substr(0, swork.size()).c_str();
tmp = strtoul(swork.substr(1, swork.size()).c_str(), &endptr, 16);
if (*endptr != '\0') {
LOG_ERR("Unrecognized format <acc>=%s", optarg);
return false;
}
// Detect the access width passed.
if (sacc.compare("b") == 0) {
rmmap.acc = BYTE_LEN;
} else if (sacc.compare("w") == 0) {
rmmap.acc = WORD_LEN;
} else if (sacc.compare("l") == 0) {
rmmap.acc = DWORD_LEN;
} else if (sacc.compare("q") == 0) {
rmmap.acc = QUAD_LEN;
} else {
LOG_ERR("Unrecognized access width to read.");
return false;
}
return true;
}
/**
* A function to specifically handle parsing cmd lines of the form
* "<space:offset:num:val:acc>".
* @param wmmap Pass a structure to populate with parsing results
* @param optarg Pass the 'optarg' argument from the getopt_long() API.
* @return true upon successful parsing, otherwise false.
*/
bool
ParseWmmapCmdLine(WmmapIo &wmmap, const char *optarg)
{
size_t ulwork;
char *endptr;
string swork;
size_t tmp;
uint64_t tmpVal;
string sacc;
wmmap.req = true;
wmmap.space = NVMEIO_FENCE;
wmmap.offset = 0;
wmmap.size = 0;
wmmap.value = 0;
wmmap.acc = ACC_FENCE;
// Parsing <space:off:siz:val:acc>
swork = optarg;
if ((ulwork = swork.find(":", 0)) == string::npos) {
LOG_ERR("Unrecognized format <space:off:siz:val:acc>=%s", optarg);
return false;
}
if (strcmp("PCI", swork.substr(0, ulwork).c_str()) == 0) {
wmmap.space = NVMEIO_PCI_HDR;
} else if (strcmp("BAR01", swork.substr(0, ulwork).c_str()) == 0) {
wmmap.space = NVMEIO_BAR01;
} else {
LOG_ERR("Unrecognized identifier <space>=%s", optarg);
return false;
}
// Parsing <off:siz:val:acc>
swork = swork.substr(ulwork+1, swork.size());
tmp = strtoul(swork.substr(0, swork.size()).c_str(), &endptr, 16);
if (*endptr != ':') {
LOG_ERR("Unrecognized format <off:siz:val:acc>=%s", optarg);
return false;
}
wmmap.offset = tmp;
// Parsing <size:val:acc>
swork = swork.substr(swork.find_first_of(':') + 1, swork.length());
tmp = strtoul(swork.substr(0, swork.size()).c_str(), &endptr, 16);
if (*endptr != ':') {
LOG_ERR("Unrecognized format <siz:val:acc>=%s", optarg);
return false;
} else if (tmp > MAX_SUPPORTED_REG_SIZE) {
LOG_ERR("<size> > allowed value of max of %d bytes",
MAX_SUPPORTED_REG_SIZE);
return false;
}
wmmap.size = tmp;
// Parsing <val:acc>
swork = swork.substr(swork.find_first_of(':') + 1, swork.length());
if (swork.length() == 0) {
LOG_ERR("Missing <val> format string");
return false;
}
tmpVal = strtoull(swork.substr(0, swork.size()).c_str(), &endptr, 16);
if (*endptr != ':') {
LOG_ERR("Unrecognized format <val:acc>=%s", optarg);
return false;
}
wmmap.value = tmpVal;
// Parsing <acc>
swork = swork.substr(swork.find_first_of(':') + 1, swork.length());
if (swork.length() == 0) {
LOG_ERR("Missing <acc> format string");
return false;
}
sacc = swork.substr(0, swork.size()).c_str();
tmp = strtoul(swork.substr(1, swork.size()).c_str(), &endptr, 16);
if (*endptr != '\0') {
LOG_ERR("Unrecognized format <acc>=%s", optarg);
return false;
}
if (sacc.compare("b") == 0) {
wmmap.acc = BYTE_LEN;
} else if (sacc.compare("w") == 0) {
wmmap.acc = WORD_LEN;
} else if (sacc.compare("l") == 0) {
wmmap.acc = DWORD_LEN;
} else if (sacc.compare("q") == 0) {
wmmap.acc = QUAD_LEN;
} else {
LOG_ERR("Unrecognized access width for writing.");
return false;
}
return true;
}
/**
* A function to specifically handle parsing cmd lines of the form
* "<ncqr:nsqr>".
* @param queues Pass a structure to populate with parsing results
* @param optarg Pass the 'optarg' argument from the getopt_long() API.
* @return true upon successful parsing, otherwise false.
*/
bool
ParseQueuesCmdLine(Queues &queues, const char *optarg)
{
char *endptr;
string swork;
size_t tmp;
string sacc;
queues.req = true;
queues.ncqr = 0;
queues.nsqr = 0;
// Parsing <ncqr:nsqr>
swork = optarg;
tmp = strtoul(swork.substr(0, swork.size()).c_str(), &endptr, 16);
if (*endptr != ':') {
LOG_ERR("Unrecognized format <ncqr:nsqr>=%s", optarg);
return false;
} else if (tmp > ((uint16_t)(-1))) {
LOG_ERR("<ncqr> > allowed max value of 0x%04X", ((uint16_t)(-1)));
return false;
}
queues.ncqr = (uint16_t)tmp;
// Parsing <nsqr>
swork = swork.substr(swork.find_first_of(':') + 1, swork.length());
if (swork.length() == 0) {
LOG_ERR("Missing <nsqr> format string");
return false;
}
tmp = strtoul(swork.substr(0, swork.size()).c_str(), &endptr, 16);
if (*endptr != '\0') {
LOG_ERR("Unrecognized format <nsqr>=%s", optarg);
return false;
} else if (tmp > ((uint16_t)(-1))) {
LOG_ERR("<nsqr> > allowed max value of 0x%04X", ((uint16_t)(-1)));
return false;
}
queues.nsqr = (uint16_t)tmp;
return true;
}
bool SetFeaturesNumberOfQueues(Queues &queues, int fd)
{
uint16_t numCE;
uint16_t ceRemain;
uint16_t numReaped;
try { // The objects to perform this work throw exceptions
LOG_NRM("Setting number of Q's; ncqr=0x%04X, nsqr=0x%04X",
queues.ncqr, queues.nsqr);
if (gCtrlrConfig->SetState(ST_DISABLE_COMPLETELY) == false)
throw exception();
LOG_NRM("Prepare the admin Q's to setup this request");
SharedACQPtr acq = SharedACQPtr(new ACQ(fd));
acq->Init(2);
SharedASQPtr asq = SharedASQPtr(new ASQ(fd));
asq->Init(2);
if (gCtrlrConfig->SetState(ST_ENABLE) == false)
throw exception();
LOG_NRM("Create the cmd to carry this data to the DUT");
SharedSetFeaturesPtr sfNumOfQ =
SharedSetFeaturesPtr(new SetFeatures(fd));
sfNumOfQ->SetFID(BaseFeatures::FID_NUM_QUEUES);
sfNumOfQ->SetNumberOfQueues(queues.ncqr, queues.nsqr);
LOG_NRM("Send the cmd to the ASQ, wait for it to complete");
asq->Send(sfNumOfQ);
asq->Ring();
if (acq->ReapInquiryWaitSpecify(2000, 1, numCE) == false) {
LOG_ERR("Unable to see completion of Set Features cmd");
throw exception();
} else if (numCE != 1) {
LOG_ERR("The ACQ should only have 1 CE as a result of a cmd");
throw exception();
}
LOG_NRM("The CQ's metrics before reaping holds head_ptr needed");
struct nvme_gen_cq acqMetrics = acq->GetQMetrics();
KernelAPI::LogCQMetrics(acqMetrics);
LOG_NRM("Reaping CE from ACQ, requires memory to hold reaped CE");
SharedMemBufferPtr ceMemIOCQ = SharedMemBufferPtr(new MemBuffer());
if ((numReaped = acq->Reap(ceRemain, ceMemIOCQ, numCE, true)) != 1) {
LOG_ERR("Verified there was 1 CE, but reaping produced %d",
numReaped);
throw exception();
}
LOG_NRM("The reaped get features CE is...");
acq->LogCE(acqMetrics.head_ptr);
union CE ce = acq->PeekCE(acqMetrics.head_ptr);
if (ce.n.status != 0) {
LOG_ERR("CE shows cmd failed: status = 0x%02X", ce.n.status);
throw exception();
}
printf("The operation succeeded to set number of queues\n");
} catch (...) {
printf("Operation failed to set number of queues\n");
return false;
}
return true;
}