forked from pynvme/pynvme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver_test.py
3789 lines (2982 loc) · 118 KB
/
driver_test.py
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# BSD LICENSE
#
# Copyright (c) Crane Chu <[email protected]>
# 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.
# -*- coding: utf-8 -*-
import os
import time
import pytest
import logging
import warnings
import nvme as d
import nvme # test double import
@pytest.mark.parametrize("repeat", range(2))
def test_init_nvme_back_compatibility(pciaddr, repeat):
pcie = d.Pcie(pciaddr)
nvme0 = d.Controller(pcie)
logging.info(hex(pcie.register(0, 4)))
nvme0n1 = d.Namespace(nvme0, 1)
nvme0n1.format(512)
with nvme0n1.ioworker(time=1), \
nvme0n1.ioworker(time=1):
pass
nvme0n1.close()
pcie.close()
@pytest.mark.parametrize("repeat", range(2))
def test_init_nvme_customerized(pcie, repeat):
def nvme_init(nvme0):
# 1. disable cc.en and wait csts.rdy to 0
nvme0[0x14] = 0
while not (nvme0[0x1c] & 0x1) == 0:
pass
# 2. set admin queue registers
nvme0.init_adminq()
# 3. set register cc
nvme0[0x14] = 0x00460000
# 4. enable cc.en
nvme0[0x14] = 0x00460001
# 5. wait csts.rdy to 1
while not (nvme0[0x1c] & 0x1) == 1:
pass
# 6. identify controller
nvme0.identify(d.Buffer(4096)).waitdone()
# 7. create and identify all namespaces
nvme0.init_ns()
# 8. set/get num of queues
nvme0.setfeatures(0x7, cdw11=0x00ff00ff).waitdone()
nvme0.init_queues(nvme0.getfeatures(0x7).waitdone())
# 9. send out all aer
aerl = nvme0.id_data(259)+1
for i in range(aerl):
nvme0.aer()
# initialize pcie registers
pcie.aspm = 0
# create controller with user defined init process
nvme0 = d.Controller(pcie, nvme_init_func=nvme_init)
aerl = nvme0.id_data(259)+1
# test with ioworker
nvme0n1 = d.Namespace(nvme0, 1)
qpair = d.Qpair(nvme0, 10)
subsystem = d.Subsystem(nvme0)
with nvme0n1.ioworker(time=1):
pass
# ABORTED - BY REQUEST (00/07)
with pytest.warns(UserWarning, match="ERROR status: 00/07"):
for i in range(100):
nvme0.abort(127-i).waitdone()
for i in range(aerl):
nvme0.aer()
# ABORTED - BY REQUEST (00/07)
with pytest.warns(UserWarning, match="ERROR status: 00/07"):
for i in range(10):
nvme0.abort(127-i).waitdone()
for i in range(aerl):
nvme0.aer()
# ABORTED - BY REQUEST (00/07)
with pytest.warns(UserWarning, match="ERROR status: 00/07"):
for i in range(10):
nvme0.abort(127-i).waitdone()
qpair.delete()
nvme0.reset()
nvme0n1.ioworker(time=1).start().close()
nvme0n1.close()
nvme0.reset() # controller reset: CC.EN
nvme0.getfeatures(7).waitdone()
pcie.reset() # PCIe reset: hot reset, TS1, TS2
nvme0.reset() # reset controller after pcie reset
nvme0.getfeatures(7).waitdone()
subsystem.reset() # NVMe subsystem reset: NSSR
nvme0.reset() # controller reset: CC.EN
nvme0.getfeatures(7).waitdone()
subsystem.power_cycle(10) # power cycle NVMe device: cold reset
nvme0.reset() # controller reset: CC.EN
nvme0.getfeatures(7).waitdone()
subsystem.poweroff()
subsystem.poweron()
nvme0.reset() # controller reset: CC.EN
nvme0.getfeatures(7).waitdone()
def test_jsonrpc_list_qpairs(pciaddr):
import json
import socket
# create the jsonrpc client
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect('/var/tmp/pynvme.sock')
def jsonrpc_call(sock, method, params=[]):
# create and send the command
req = {}
req['id'] = 1234567890
req['jsonrpc'] = '2.0'
req['method'] = method
req['params'] = params
sock.sendall(json.dumps(req).encode('ascii'))
# receive the result
resp = json.loads(sock.recv(4096).decode('ascii'))
assert resp['id'] == 1234567890
assert resp['jsonrpc'] == '2.0'
return resp['result']
# no active controller
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 0
# create controller and namespace
pcie = d.Pcie(pciaddr)
nvme0 = d.Controller(pcie)
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 1
assert result[0]['qid']-1 == 0
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 1
assert result[0]['qid']-1 == 0
q1 = d.Qpair(nvme0, 8)
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 2
assert result[0]['qid']-1 == 0
assert result[1]['qid']-1 == 1
q2 = d.Qpair(nvme0, 8)
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 3
assert result[0]['qid']-1 == 0
assert result[1]['qid']-1 == 1
assert result[2]['qid']-1 == 2
nvme0n1 = d.Namespace(nvme0, 1, 1024)
with nvme0n1.ioworker(io_size=8, time=2):
time.sleep(1)
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 4
assert result[0]['qid']-1 == 0
assert result[1]['qid']-1 == 1
assert result[2]['qid']-1 == 2
assert result[3]['qid']-1 == 3
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 3
assert result[0]['qid']-1 == 0
assert result[1]['qid']-1 == 1
assert result[2]['qid']-1 == 2
q1.delete()
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 2
assert result[0]['qid']-1 == 0
assert result[1]['qid']-1 == 2
q2.delete()
result = jsonrpc_call(sock, 'list_all_qpair')
assert len(result) == 1
assert result[0]['qid']-1 == 0
nvme0n1.close()
pcie.close()
def test_expected_dut(nvme0):
logging.info("0x%x" % nvme0.id_data(1, 0))
logging.info("0x%x" % nvme0.id_data(3, 2))
logging.info(nvme0.id_data(63, 24, str))
logging.info(nvme0.id_data(71, 64, str))
assert nvme0.id_data(1, 0) == 0x1e95
assert "CA5-8D256-Q11 NVMe SSSTC 256GB" in nvme0.id_data(63, 24, str)
def test_read_fua_latency(nvme0n1, nvme0, qpair, buf):
# first time read to load data into SSD buffer
nvme0n1.read(qpair, buf, 0, 8).waitdone()
now = time.time()
for i in range(10000):
nvme0n1.read(qpair, buf, 0, 8).waitdone()
non_fua_time = time.time()-now
logging.info("normal read latency %fs" % non_fua_time)
now = time.time()
for i in range(10000):
nvme0n1.read(qpair, buf, 0, 8, 1 << 14).waitdone()
fua_time = time.time()-now
logging.info("FUA read latency %fs" % fua_time)
@pytest.mark.parametrize("repeat", range(2))
def test_false(nvme0, subsystem, repeat):
assert False
def test_enable_verify_with_large_namespace(nvme0):
# create namespace with full space verify, but memory is not enough
nvme0n1 = d.Namespace(nvme0)
assert nvme0n1.verify_enable() == True
nvme0n1.verify_enable(False)
nvme0n1.close()
def test_power_and_reset(pcie, nvme0, subsystem):
pcie.aspm = 2 # ASPM L1
pcie.power_state = 3 # PCI PM D3hot
pcie.aspm = 0
pcie.power_state = 0
nvme0.reset() # controller reset: CC.EN
nvme0.getfeatures(7).waitdone()
pcie.reset() # PCIe reset: hot reset, TS1, TS2
nvme0.reset() # reset controller after pcie reset
nvme0.getfeatures(7).waitdone()
pcie.flr() # PCIe function level reset
nvme0.reset() # reset controller after pcie reset
nvme0.getfeatures(7).waitdone()
subsystem.reset() # NVMe subsystem reset: NSSR
nvme0.reset() # controller reset: CC.EN
nvme0.getfeatures(7).waitdone()
subsystem.power_cycle(10) # power cycle NVMe device: cold reset
nvme0.reset() # controller reset: CC.EN
nvme0.getfeatures(7).waitdone()
subsystem.poweroff()
subsystem.poweron()
nvme0.reset() # controller reset: CC.EN
nvme0.getfeatures(7).waitdone()
def test_quarch_defined_poweron_poweroff(nvme0):
import quarchpy
def poweron():
logging.info("power off by quarch")
pwr = quarchpy.quarchDevice("SERIAL:/dev/ttyUSB0")
pwr.sendCommand("run:power up")
pwr.closeConnection()
def poweroff():
logging.info("power on by quarch")
pwr = quarchpy.quarchDevice("SERIAL:/dev/ttyUSB0")
pwr.sendCommand("signal:all:source 7")
pwr.sendCommand("run:power down")
pwr.closeConnection()
s = d.Subsystem(nvme0, poweron, poweroff)
def test_system_defined_poweron_poweroff(nvme0, nvme0n1):
# no callback provided, fallback to S3 power_cycle
s = d.Subsystem(nvme0)
s.poweroff()
s.poweron()
nvme0.reset()
test_hello_world(nvme0, nvme0n1, True)
def test_hello_world(nvme0, nvme0n1, verify):
assert verify
# prepare data buffer and IO queue
read_buf = d.Buffer(512)
write_buf = d.Buffer(512)
write_buf[10:21] = b'hello world'
qpair = d.Qpair(nvme0, 10)
# send write and read command
def write_cb(cdw0, status1): # command callback function
nvme0n1.read(qpair, read_buf, 0, 1)
nvme0n1.write(qpair, write_buf, 0, 1, cb=write_cb)
# wait commands complete and verify data
assert read_buf[10:21] != b'hello world'
qpair.waitdone(2)
assert read_buf[10:21] == b'hello world'
nvme0n1.compare(qpair, read_buf, 0).waitdone()
qpair.delete()
def test_create_device(nvme0, nvme0n1):
assert nvme0 is not None
def test_create_device_invalid():
with pytest.raises(d.NvmeEnumerateError):
nvme1 = d.Controller(d.Pcie("0000:00:00.0"))
def test_create_device_again(nvme0):
with pytest.raises(d.NvmeEnumerateError):
d.Controller(d.Pcie("0000:10:00.0"))
def test_qpair_overflow(nvme0, nvme0n1, buf):
q = d.Qpair(nvme0, 4)
nvme0n1.read(q, buf, 0, 8)
nvme0n1.read(q, buf, 8, 8)
nvme0n1.read(q, buf, 16, 8)
with pytest.raises(AssertionError):
nvme0n1.read(q, buf, 24, 8)
q.waitdone(3)
@pytest.mark.parametrize("shift", range(1, 8))
def test_qpair_different_size(nvme0n1, nvme0, shift):
size = 1 << shift
logging.info("create io queue size %d" % size)
q = d.Qpair(nvme0, size)
nvme0.getfeatures(7).waitdone()
q.delete()
def test_latest_cid(nvme0, nvme0n1, qpair, buf):
def aer_aborted(cpl):
logging.info("aer aborted")
nvme0.aer(cb=aer_aborted)
with pytest.warns(UserWarning, match="ERROR status: 00/07"):
nvme0.abort(nvme0.latest_cid).waitdone()
nvme0n1.read(qpair, buf, 0, 8)
nvme0.abort(qpair.latest_cid).waitdone()
qpair.waitdone()
nvme0n1.read(qpair, buf, 0, 8).waitdone()
nvme0.abort(qpair.latest_cid).waitdone()
def test_latest_latency(nvme0, nvme0n1, qpair, buf):
nvme0n1.read(qpair, buf, 0, 8).waitdone()
logging.info(qpair.latest_latency)
nvme0n1.write(qpair, buf, 0, 8).waitdone()
logging.info(qpair.latest_latency)
for ps in range(5):
nvme0.setfeatures(0x2, cdw11=ps).waitdone()
logging.info(nvme0.latest_latency)
def test_random_seed():
import random
assert random.randint(1, 1000000) != random.randint(0, 1000000)
d.srand(10)
a = random.randint(1, 1000000)
d.srand(10)
b = random.randint(1, 1000000)
assert a == b
d.srand(100)
b = random.randint(1, 1000000)
assert a != b
def test_controller_reset_redo(nvme0):
nvme0.reset()
nvme0.reset()
nvme0.reset()
nvme0.reset()
cdw0 = nvme0.getfeatures(7).waitdone()
assert cdw0 == 0xf000f
def test_ioworker_is_running(nvme0n1):
with nvme0n1.ioworker(io_size=8, time=6) as a:
for i in range(5):
time.sleep(1)
assert a.running == True
assert a.running == False
a = nvme0n1.ioworker(io_size=8, time=1)
b = nvme0n1.ioworker(io_size=8, time=10)
assert a.running == True
assert b.running == True
logging.info("PASS")
b.start()
a.start()
assert a.running == True
assert b.running == True
logging.info("PASS")
time.sleep(2)
assert a.running == False
logging.info("PASS")
assert b.running == True
logging.info("PASS")
a.close()
assert a.running == False
assert b.running == True
logging.info("PASS")
while b.running:
pass
assert a.running == False
logging.info("PASS")
b.close()
assert a.running == False
assert b.running == False
logging.info("PASS")
def test_ioworker_last_truncated_io(nvme0n1):
cmdlog_list = [None]*6
nvme0n1.ioworker(io_size=8,
lba_random=False,
io_count=6,
region_end=40,
qdepth=2,
output_cmdlog_list=cmdlog_list).start().close()
assert cmdlog_list[5][0] == 0
assert cmdlog_list[5][1] == 8
nvme0n1.ioworker(io_size=8,
lba_random=False,
io_count=6,
region_end=41,
qdepth=2,
output_cmdlog_list=cmdlog_list).start().close()
assert cmdlog_list[5][0] == 40
assert cmdlog_list[5][1] == 1
def test_ioworker_sequential_unfixed_iosize(nvme0n1):
cmdlog_list = [None]*1000
io_size_list = [1, 3, 8, 30, 64, 100, 128, 200, 256]
nvme0n1.ioworker(io_size=io_size_list,
lba_align=[1]*len(io_size_list),
lba_random=False,
io_count=len(cmdlog_list),
qdepth=2,
output_cmdlog_list=cmdlog_list).start().close()
for i in range(len(cmdlog_list)-1):
assert cmdlog_list[i][0]+cmdlog_list[i][1] == cmdlog_list[i+1][0]
nvme0n1.ioworker(io_size=7,
lba_align=1,
lba_random=False,
io_count=len(cmdlog_list),
qdepth=2,
output_cmdlog_list=cmdlog_list).start().close()
for i in range(len(cmdlog_list)-1):
assert cmdlog_list[i][0]+cmdlog_list[i][1] == cmdlog_list[i+1][0]
def test_getlogpage_send_cmd(nvme0, buf):
fid=1
for numd in (0, 4, 7, 15):
nvme0.send_cmd(2, buf, cdw10=fid|(numd<<16)).waitdone()
logging.info(buf.dump(64))
def test_ioworker_with_admin(nvme0, nvme0n1, buf, qpair):
with nvme0n1.ioworker(io_size=256, lba_random=False, read_percentage=100, time=10):
start_time = time.time()
while time.time()-start_time < 8:
nvme0.getlogpage(0x02, buf, 512).waitdone()
nvme0.identify(buf).waitdone()
with nvme0n1.ioworker(io_size=256, lba_random=False, read_percentage=100, time=10):
start_time = time.time()
while time.time()-start_time < 15:
nvme0.getfeatures(7).waitdone()
with nvme0n1.ioworker(io_size=256, lba_random=False, read_percentage=100, time=10), \
nvme0n1.ioworker(io_size=256, lba_random=False, read_percentage=100, time=10), \
nvme0n1.ioworker(io_size=256, lba_random=False, read_percentage=100, time=10):
start_time = time.time()
while time.time()-start_time < 15:
nvme0.getlogpage(0x02, buf, 512).waitdone()
with nvme0n1.ioworker(io_size=256, lba_random=False, read_percentage=100, time=10), \
nvme0n1.ioworker(io_size=256, lba_random=False, read_percentage=100, time=10), \
nvme0n1.ioworker(io_size=256, lba_random=False, read_percentage=100, time=10):
start_time = time.time()
qpair3 = d.Qpair(nvme0, 10)
while time.time()-start_time < 15:
nvme0n1.read(qpair3, buf, 0, 8).waitdone()
qpair3.delete()
def test_ioworker_region_smaller_than_iosize(nvme0n1):
cmdlog_list = [None]*1000
nvme0n1.ioworker(io_size=128,
region_end=100,
lba_random=False,
io_count=len(cmdlog_list),
output_cmdlog_list=cmdlog_list).start().close()
logging.debug(cmdlog_list)
for c in cmdlog_list:
assert c[0] == 0
assert c[1] == 100
assert c[2] == 2
nvme0n1.ioworker(io_size=128,
region_end=100,
lba_random=True,
io_count=len(cmdlog_list),
output_cmdlog_list=cmdlog_list).start().close()
logging.debug(cmdlog_list)
for c in cmdlog_list:
assert c[0]+c[1] == 100
assert c[2] == 2
def test_ioworker_sequential_region_unaligned_with_iosize(nvme0n1):
cmdlog_list = [None]*1000
nvme0n1.ioworker(io_size=128,
lba_random=False,
region_end=129,
io_count=len(cmdlog_list),
output_cmdlog_list=cmdlog_list).start().close()
for c in cmdlog_list:
if c[0] == 0:
assert c[1] == 128
else:
assert c[0] == 128
assert c[1] == 1
def test_ioworker_sequential_region_fill(nvme0n1):
cmdlog_list = [None]*11
nvme0n1.ioworker(io_size=8,
lba_random=False,
qdepth=2,
region_end=77,
output_cmdlog_list=cmdlog_list).start().close()
assert cmdlog_list[0][2] == 0
assert cmdlog_list[1][1] == 8
assert cmdlog_list[10][0] == 72
assert cmdlog_list[10][1] == 5
nvme0n1.ioworker(io_size=8,
lba_align=1,
lba_random=False,
region_start=1,
region_end=77,
qdepth=2,
output_cmdlog_list=cmdlog_list).start().close()
assert cmdlog_list[0][2] == 0
assert cmdlog_list[1][0] == 1
assert cmdlog_list[1][1] == 8
assert cmdlog_list[10][0] == 73
assert cmdlog_list[10][1] == 4
with pytest.raises(AssertionError):
nvme0n1.ioworker(
io_size=[8, 64, 128], lba_random=False, region_end=1000).start().close()
with pytest.raises(AssertionError):
nvme0n1.ioworker(io_size=8,
lba_random=False,
qdepth=2,
output_cmdlog_list=cmdlog_list).start().close()
def test_ioworker_input_out_of_range(nvme0n1):
nvme0n1.ioworker(io_size=128, region_end=200, time=1).start().close()
nvme0n1.ioworker(io_size=128, region_end=200,
qdepth=2, io_count=2).start().close()
nvme0n1.ioworker(io_size=128, region_end=300, time=1).start().close()
nvme0n1.ioworker(io_size=8, region_end=100, time=1).start().close()
nvme0n1.ioworker(io_size=range(8, 32, 16),
region_end=100, time=1).start().close()
nvme0n1.ioworker(io_size=128, region_end=100, time=1).start().close()
with pytest.raises(AssertionError):
nvme0n1.ioworker(io_size=range(8, 128, 8),
region_end=100, time=1).start().close()
with pytest.raises(AssertionError):
nvme0n1.ioworker(io_size=[8, 64, 128],
region_end=100, time=1).start().close()
with pytest.raises(AssertionError):
nvme0n1.ioworker(io_size={1: 1, 128: 1},
region_end=100, time=1).start().close()
nvme0n1.ioworker(io_size=128, region_end=300, time=1).start().close()
nvme0n1.ioworker(io_size=range(8, 64, 16),
region_end=100, time=1).start().close()
nvme0n1.ioworker(io_size=128, region_end=200, time=1).start().close()
nvme0n1.ioworker(io_size=128, region_end=256, time=1).start().close()
nvme0n1.ioworker(io_size=128, region_start=128,
region_end=256, time=1).start().close()
nvme0n1.ioworker(io_size=128, region_end=128, time=1).start().close()
nvme0n1.ioworker(io_size=128, region_end=256, time=1).start().close()
nvme0n1.ioworker(io_size=64, region_end=100, time=1).start().close()
nvme0n1.ioworker(io_size=8, region_end=1024, time=1).start().close()
def test_ioworker_power_cycle_async_cmdlog(nvme0, nvme0n1, subsystem):
cmdlog_list = [None]*11
with nvme0n1.ioworker(io_size=8, time=10, iops=2,
qdepth=2, lba_random=False,
output_cmdlog_list=cmdlog_list):
time.sleep(5)
subsystem.power_cycle(10)
nvme0.reset()
logging.info(cmdlog_list)
assert cmdlog_list[0][1] == 0
assert cmdlog_list[10][0] < 110
assert cmdlog_list[10][0] == 72
assert cmdlog_list[10][2] == 2
assert cmdlog_list[10][0] == cmdlog_list[9][0]+8
@pytest.mark.parametrize("nlba", [1, 2, 8])
@pytest.mark.parametrize("nlba_verify", [10, 100, 100*1024*1024*1024//512])
def test_namespace_nlba_verify(nvme0, nlba, nlba_verify, qpair):
nvme0n1 = d.Namespace(nvme0, 1, nlba_verify)
buf = d.Buffer()
for lba in (0, 9, 10, 11, 150*1024*1024*1024//512):
nvme0n1.write(qpair, buf, lba, nlba).waitdone()
nvme0n1.read(qpair, buf, lba, nlba).waitdone()
assert True == nvme0n1.verify_enable()
for lba in (0, 9, 10, 11, 150*1024*1024*1024//512):
nvme0n1.write(qpair, buf, lba, nlba).waitdone()
nvme0n1.read(qpair, buf, lba, nlba).waitdone()
nvme0n1.verify_enable(False)
nvme0n1.close()
def test_ioworker_activate_crc32(nvme0n1, verify, nvme0):
# verify should be enabled
assert verify
nvme0n1.format(512)
r1 = nvme0n1.ioworker(io_size=8, lba_align=8,
lba_random=False, qdepth=32,
region_end=1000000,
read_percentage=100, time=5).start().close()
# write some valid data first
w = nvme0n1.ioworker(io_size=256, lba_align=256,
lba_random=False, qdepth=32,
region_end=1000000,
read_percentage=0, time=10).start().close()
r2 = nvme0n1.ioworker(io_size=8, lba_align=8,
lba_random=False, qdepth=32,
region_end=1000000,
read_percentage=100, time=5).start().close()
assert r1["io_count_read"] > r2["io_count_read"]
def test_write_and_format(nvme0n1, nvme0):
with nvme0n1.ioworker(io_size=8, lba_align=16,
lba_random=True, qdepth=16,
read_percentage=0, time=1):
pass
nvme0.format(nvme0n1.get_lba_format(512, 0)).waitdone()
def test_get_identify_quick(nvme0, nvme0n1):
logging.info("vid: 0x%x" % nvme0.id_data(1, 0))
logging.info("namespace size: %d" % nvme0n1.id_data(7, 0))
logging.info("namespace capacity: %d" % nvme0n1.id_data(15, 8))
logging.info("namespace utilization: %d" % nvme0n1.id_data(23, 16))
assert nvme0n1.id_data(7, 0) == nvme0n1.id_data(15, 8)
assert nvme0.id_data(63, 24, str)[0] != 0
def test_get_identify(nvme0, nvme0n1):
logging.info("controller data")
id_buf = d.Buffer(4096, 'identify buffer')
assert id_buf[0] == 0
nvme0.identify(id_buf, 0, 1)
nvme0.waitdone()
assert id_buf[0] != 0
assert id_buf[0] == nvme0.id_data(0, 0)
logging.info("namespace data")
id_buf = d.Buffer(4096, 'identify buffer')
assert id_buf[0] == 0
nvme0.identify(id_buf, 1, 0)
nvme0.waitdone()
assert id_buf[0] != 0
assert id_buf[0] == nvme0n1.id_data(0)
assert nvme0.id_data(4, 0) != nvme0n1.id_data(4, 0)
assert nvme0n1.id_data(8, 5) != nvme0n1.id_data(4, 0)
assert nvme0n1.id_data(7, 0) == nvme0n1.id_data(15, 8)
logging.info("active namespace id data")
id_buf = d.Buffer(4096, 'identify buffer')
assert id_buf[0] == 0
nvme0.identify(id_buf, 0, 2)
nvme0.waitdone()
assert id_buf[0] != 0
logging.info("wrong namespace data")
with pytest.warns(UserWarning, match="ERROR status: 00/0b"):
nvme0.identify(id_buf, 0, 0).waitdone()
logging.info("wrong active namespace nsid")
with pytest.warns(UserWarning, match="ERROR status: 00/0b"):
nvme0.identify(id_buf, 0xffffffff, 2).waitdone()
logging.info("wrong namespace nsid")
with pytest.warns(UserWarning, match="ERROR status: 00/0b"):
nvme0.identify(id_buf, 0xffffff, 0).waitdone()
def test_identify_with_small_buffer(nvme0):
buf = d.Buffer(512, "part of identify")
with pytest.raises(AssertionError):
nvme0.identify(buf).waitdone()
buf = d.Buffer(3000, "part of identify")
with pytest.raises(AssertionError):
nvme0.identify(buf).waitdone()
buf = d.Buffer(4096, "part of identify")
nvme0.identify(buf).waitdone()
buf = d.Buffer(4096*2, "part of identify")
nvme0.identify(buf).waitdone()
def test_get_pcie_config_class_code(pcie):
assert pcie[9:12] == [2, 8, 1]
def test_get_pcie_registers(pcie):
vid = pcie.register(0, 2)
did = pcie.register(2, 2)
logging.info("vid %x, did %x" % (vid, did))
def test_pcie_capability_d3hot(pcie, nvme0n1):
assert None == pcie.cap_offset(2)
# get pm register
assert None != pcie.cap_offset(1)
pm_offset = pcie.cap_offset(1)
pmcs = pcie[pm_offset+4]
logging.info("curent power state: %d" % pcie.power_state)
# set d3hot
pcie.power_state = 3
logging.info("curent power state: %d" % pcie.power_state)
time.sleep(1)
# and exit d3hot
pcie.power_state = 0
logging.info("curent power state: %d" % pcie.power_state)
nvme0n1.ioworker(io_size=2, time=2).start().close()
# again
pcie.power_state = 0
logging.info("curent power state: %d" % pcie.power_state)
nvme0n1.ioworker(io_size=2, time=2).start().close()
assert pcie.power_state == 0
def test_get_nvme_register_vs(nvme0):
cid = nvme0[0x08]
assert cid == 0x010200 or cid == 0x010100 or cid == 0x010300
def test_power_cycle_and_format(nvme0, nvme0n1, subsystem):
subsystem.power_cycle()
nvme0.reset()
nvme0n1.format(512)
subsystem.power_cycle()
nvme0.reset()
nvme0n1.ioworker(read_percentage=100, io_count=1).start().close()
nvme0n1.format(512)
def test_get_lba_format(nvme0n1):
assert nvme0n1.get_lba_format() == nvme0n1.get_lba_format(512, 0)
assert nvme0n1.get_lba_format(4096, 0) != nvme0n1.get_lba_format(512, 0)
assert nvme0n1.get_lba_format(4097, 0) == None
assert nvme0n1.get_lba_format() < 16
@pytest.mark.parametrize("ps", [4, 3, 2, 1, 0])
def test_format_at_power_state(nvme0, nvme0n1, ps):
nvme0.setfeatures(0x2, cdw11=ps).waitdone()
assert nvme0n1.format(ses=0) == 0
assert nvme0n1.format(ses=1) == 0
p = nvme0.getfeatures(0x2).waitdone()
assert p == ps
def test_write_identify_and_verify(nvme0n1, nvme0):
id_buf = d.Buffer(4096)
nvme0.identify(id_buf)
nvme0.waitdone()
assert id_buf[0] != 0
nvme0n1.format(512)
# explict allocate resource when not using fixture
q = d.Qpair(nvme0, 20)
n = nvme0n1
n.write(q, id_buf, 5, 8)
q.waitdone()
read_buf = d.Buffer(4096, "read buffer")
n.read(q, read_buf, 5, 8)
q.waitdone()
assert id_buf[:10] == read_buf[:10]
id_buf[0] += 1
n.write(q, id_buf, 5, 8).waitdone()
n.read(q, read_buf, 5, 8).waitdone()
assert id_buf[:10] == read_buf[:10]
logging.info("test end")
q.delete()
def test_callback_with_whole_cpl(nvme0, nvme0n1, buf, qpair):
f1 = 0
def cb1(cpl):
nonlocal f1
f1 = cpl[0]
logging.info(cpl)
assert cpl[1] == 0
nvme0.getfeatures(7, cb=cb1).waitdone()
def cb2(cpl):
logging.info(cpl)
assert cpl[0] == 0
assert cpl[1] == 0
assert len(cpl) == 4
assert type(cpl) is tuple
nvme0n1.read(qpair, buf, 0, cb=cb2).waitdone()
a1 = 0
def cb1(cdw0, status):
nonlocal a1
a1 = cdw0
logging.info("in 2nd cb1")
nvme0.getfeatures(7, cb=cb1).waitdone()
assert a1 == f1
def cb3(cdw0, status, third):
pass
with pytest.warns(UserWarning, match="callback:"):
nvme0.getfeatures(7, cb=cb3).waitdone()
def test_multiple_callbacks(nvme0):
a1 = 0
def cb1(cdw0, status):
nonlocal a1
a1 = 1
nvme0.getfeatures(7, cb=cb1)
a2 = 0
def cb2(cdw0, status):
nonlocal a2
a2 = 2
nvme0.getfeatures(7, cb=cb2)
nvme0.waitdone(2)
assert a1 == 1
assert a2 == 2
def test_write_identify_and_verify_with_callback(nvme0, nvme0n1):
id_buf = d.Buffer(4096)
nvme0.identify(id_buf).waitdone()
q = d.Qpair(nvme0, 20)
n = nvme0n1
read_buf = d.Buffer(4096, "read buffer")
def read_cb(cdw0, status):
assert id_buf[:40] == read_buf[:40]
def write_cb(cdw0, status):
n.read(q, read_buf, 5, 8, cb=read_cb)
n.write(q, id_buf, 5, 8, cb=write_cb).waitdone(2)
id_buf[0] += 1
n.write(q, id_buf, 5, 8, cb=write_cb).waitdone(2)
id_buf[9] = (id_buf[9] >> 1)
n.write(q, id_buf, 5, 8, cb=write_cb).waitdone(2)
q.delete()
def test_io_waitdone_many_command(nvme0, nvme0n1):
id_buf = d.Buffer(4096)
q = d.Qpair(nvme0, 8)
nvme0n1.write(q, id_buf, 5, 8)
q.waitdone()
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)
q.waitdone()
q.waitdone()
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)
q.waitdone(2)
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)
q.waitdone(2)
q.waitdone(3)
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)
nvme0n1.write(q, id_buf, 5, 8)