def test_multiple_controllers_and_namespaces(pciaddr): # address list of the devices to test addr_list = ['01:00.0', '02:00.0', '03:00.0', '04:00.0'] addr_list = [ pciaddr, ] test_seconds = 10 # create all controllers and namespace pcie_list = [d.Pcie(a) for a in addr_list] nvme_list = [d.Controller(p) for p in pcie_list] ns_list = [d.Namespace(n) for n in nvme_list] # create two ioworkers on each namespace ioworkers = [] for ns in ns_list: w = ns.ioworker( io_size=8, lba_align=8, region_start=0, region_end=256 * 1024 * 8, # 1GB space lba_random=False, qdepth=64, read_percentage=100, time=test_seconds).start() ioworkers.append(w) w = ns.ioworker(io_size=8, lba_align=16, region_start=256 * 1024 * 8, region_end=2 * 256 * 1024 * 8, lba_random=True, qdepth=256, read_percentage=0, time=test_seconds).start() ioworkers.append(w) # collect test results io_total = 0 for w in ioworkers: r = w.close() io_total += (r.io_count_read + r.io_count_nonread) logging.info("total throughput: %d IOPS" % (io_total / test_seconds)) for n in ns_list: n.close() for p in pcie_list: p.close()
def subprocess_trim(pciaddr, seconds): pcie = d.Pcie(pciaddr) nvme0 = d.Controller(pcie, True) nvme0n1 = d.Namespace(nvme0) q = d.Qpair(nvme0, 8) buf = d.Buffer(4096) buf.set_dsm_range(0, 8, 8) # send trim commands start = time.time() while time.time() - start < seconds: nvme0n1.dsm(q, buf, 1).waitdone() q.delete() nvme0n1.close() pcie.close()
def test_namespace_multiple(buf): # create all controllers and namespace addr_list = [ '3d:00.0', ] # add more DUT BDF here pcie_list = [d.Pcie(a) for a in addr_list] for p in pcie_list: nvmex = d.Controller(p) qpair = d.Qpair(nvmex, 8) nvmexn1 = d.Namespace(nvmex) #Check if support write uncorrectable command wuecc_support = nvmex.id_data(521, 520) & 0x2 if wuecc_support != 0: nvmexn1.write_uncorrectable(qpair, 0, 8).waitdone() with pytest.warns(UserWarning, match="ERROR status: 02/81"): nvmexn1.read(qpair, buf, 0, 8).waitdone() nvmexn1.write(qpair, buf, 0, 8).waitdone() def this_read_cb(dword0, status1): assert status1 >> 1 == 0 nvmexn1.write_uncorrectable(qpair, 0, 8) nvmexn1.read(qpair, buf, 0, 8, cb=this_read_cb).waitdone(2) def another_read_cb(dword0, status1): logging.info("dword0: 0x%08x" % dword0) logging.info("phase bit: %d" % (status1 & 1)) logging.info("dnr: %d" % ((status1 >> 15) & 1)) logging.info("more: %d" % ((status1 >> 14) & 1)) logging.info("sct: 0x%x" % ((status1 >> 9) & 0x7)) logging.info("sc: 0x%x" % ((status1 >> 1) & 0xff)) with pytest.warns(UserWarning, match="ERROR status: 02/81"): nvmexn1.read(qpair, buf, 0, 8, cb=another_read_cb).waitdone() qpair.delete() nvmexn1.close() p.close()
def test_init_nvme_customerized(pciaddr): pcie = d.Pcie(pciaddr) nvme0 = d.Controller(pcie, skip_nvme_init=True) # 1. set pcie registers pcie.aspm = 0 # 2. disable cc.en and wait csts.rdy to 0 nvme0[0x14] = 0 while not (nvme0[0x1c] & 0x1) == 0: pass # 3. set admin queue registers nvme0.init_adminq() # 4. set register cc nvme0[0x14] = 0x00460000 # 5. enable cc.en nvme0[0x14] = 0x00460001 # 6. wait csts.rdy to 1 while not (nvme0[0x1c] & 0x1) == 1: pass # 7. identify controller nvme0.identify(d.Buffer(4096)).waitdone() # 8. create and identify all namespace nvme0.init_ns() # 9. set/get num of queues nvme0.setfeatures(0x7, cdw11=0x00ff00ff).waitdone() nvme0.getfeatures(0x7).waitdone() pcie.close()
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'] result = jsonrpc_call(sock, 'list_all_qpair') assert len(result) == 0 # create controller and admin queue 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 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 pcie.close() result = jsonrpc_call(sock, 'list_all_qpair') assert len(result) == 0
def pcie(nvme0): ret = d.Pcie(nvme0) yield ret del ret
def pcie(pciaddr): ret = d.Pcie(pciaddr) yield ret ret.close()