- Returns:
- return code of the nvme compare command.
"""
- compare_cmd = "nvme compare " + self.ns1 + " --start-block=" + \
- str(self.start_block) + " --block-count=" + \
- str(self.block_count) + " --data-size=" + \
- str(self.data_size) + " --data=" + cmp_file
+ compare_cmd = f"{self.nvme_bin} compare {self.ns1} " + \
+ f"--start-block={str(self.start_block)} " + \
+ f"--block-count={str(self.block_count)} " + \
+ f"--data-size={str(self.data_size)} --data={cmp_file}"
return self.exec_cmd(compare_cmd)
def test_nvme_compare(self):
cross_namespace_copy = self.ocfs & 0xc
if cross_namespace_copy:
# get host behavior support data
- get_features_cmd = ["nvme", "get-feature", self.ctrl, "--feature-id=0x16", "--data-len=512", "-b"]
- print("Running command:", " ".join(get_features_cmd))
- self.host_behavior_data = subprocess.check_output(get_features_cmd)
+ get_features_cmd = f"{self.nvme_bin} get-feature {self.ctrl} " + \
+ "--feature-id=0x16 --data-len=512 --raw-binary"
+ proc = subprocess.Popen(get_features_cmd,
+ shell=True,
+ stdout=subprocess.PIPE,
+ encoding='utf-8')
+ err = proc.wait()
+ self.assertEqual(err, 0, "ERROR : nvme get-feature failed")
+ self.host_behavior_data = proc.stdout.read()
# enable cross-namespace copy formats
if self.host_behavior_data[4] & cross_namespace_copy:
# skip if already enabled
self.host_behavior_data = None
else:
data = self.host_behavior_data[:4] + cross_namespace_copy.to_bytes(2, 'little') + self.host_behavior_data[6:]
- set_features_cmd = ["nvme", "set-feature", self.ctrl, "--feature-id=0x16", "--data-len=512"]
- print("Running command:", " ".join(set_features_cmd))
+ set_features_cmd = f"{self.nvme_bin} set-feature " + \
+ f"{self.ctrl} --feature-id=0x16 --data-len=512"
proc = subprocess.Popen(set_features_cmd,
+ shell=True,
stdout=subprocess.PIPE,
- stdin=subprocess.PIPE)
+ stdin=subprocess.PIPE,
+ encoding='utf-8')
proc.communicate(input=data)
self.assertEqual(proc.returncode, 0, "Failed to enable cross-namespace copy formats")
- get_ns_id_cmd = ["nvme", "get-ns-id", self.ns1]
- print("Running command:", " ".join(get_ns_id_cmd))
- output = subprocess.check_output(get_ns_id_cmd)
- self.ns1_nsid = int(output.decode().strip().split(':')[-1])
+ get_ns_id_cmd = f"{self.nvme_bin} get-ns-id {self.ns1}"
+ proc = subprocess.Popen(get_ns_id_cmd,
+ shell=True,
+ stdout=subprocess.PIPE,
+ encoding='utf-8')
+ err = proc.wait()
+ self.assertEqual(err, 0, "ERROR : nvme get-ns-id failed")
+ output = proc.stdout.read()
+ self.ns1_nsid = int(output.strip().split(':')[-1])
self.setup_log_dir(self.__class__.__name__)
def tearDown(self):
print("Tearing down test...")
if self.host_behavior_data:
# restore saved host behavior support data
- set_features_cmd = ["nvme", "set-feature", self.ctrl, "--feature-id=0x16", "--data-len=512"]
- print("Running command:", " ".join(set_features_cmd))
+ set_features_cmd = f"{self.nvme_bin} set-feature {self.ctrl} " + \
+ "--feature-id=0x16 --data-len=512"
proc = subprocess.Popen(set_features_cmd,
+ shell=True,
stdout=subprocess.PIPE,
- stdin=subprocess.PIPE)
+ stdin=subprocess.PIPE,
+ encoding='utf-8')
proc.communicate(input=self.host_behavior_data)
super().tearDown()
print(f"Skip copy because descriptor format {desc_format} is not supported")
return
# build copy command
- copy_cmd = f"nvme copy {self.ns1} --format={desc_format} --sdlba={sdlba} --blocks={blocks} --slbs={slbs}"
+ copy_cmd = f"{self.nvme_bin} copy {self.ns1} " + \
+ f"--format={desc_format} --sdlba={sdlba} --blocks={blocks} " + \
+ f"--slbs={slbs}"
if "snsids" in kwargs:
copy_cmd += f" --snsids={kwargs['snsids']}"
if "sopts" in kwargs:
- Returns:
- return code for nvme controller reset.
"""
- ctrl_reset_cmd = "nvme reset " + self.ctrl
+ ctrl_reset_cmd = f"{self.nvme_bin} reset {self.ctrl}"
return self.exec_cmd(ctrl_reset_cmd)
def test_ctrl_reset(self):
- Returns:
- return code for nvme dsm command.
"""
- dsm_cmd = "nvme dsm " + self.ctrl + \
- " --namespace-id=" + str(self.namespace) + \
- " --blocks=" + str(self.range) + \
- " --slbs=" + str(self.start_block)
+ dsm_cmd = f"{self.nvme_bin} dsm {self.ctrl} " + \
+ f"--namespace-id={str(self.namespace)} " + \
+ f"--blocks={str(self.range)} --slbs={str(self.start_block)}"
return self.exec_cmd(dsm_cmd)
def test_dsm(self):
- Returns:
- None
"""
- flush_cmd = "nvme flush " + self.ctrl + " -n " + str(self.default_nsid)
+ flush_cmd = f"{self.nvme_bin} flush {self.ctrl} " + \
+ f"--namespace-id={str(self.default_nsid)}"
print(flush_cmd)
return self.exec_cmd(flush_cmd)
self.dps), 0)
self.assertEqual(self.attach_ns(self.ctrl_id, self.default_nsid), 0)
# read lbaf information
- id_ns = "nvme id-ns " + self.ctrl + \
- " -n1 | grep ^lbaf | awk '{print $2}' | tr -s \"\\n\" \" \""
+ id_ns = f"{self.nvme_bin} id-ns {self.ctrl} " + \
+ f"--namespace-id={self.default_nsid} " + \
+ "| grep ^lbaf | awk '{print $2}' | tr -s \"\\n\" \" \""
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
encoding='utf-8')
self.lba_format_list = proc.stdout.read().strip().split(" ")
if proc.wait() == 0:
# read lbads information
- id_ns = "nvme id-ns " + self.ctrl + \
- " -n1 | grep ^lbaf | awk '{print $5}'" + \
- " | cut -f 2 -d ':' | tr -s \"\\n\" \" \""
+ id_ns = f"{self.nvme_bin} id-ns {self.ctrl} " + \
+ f"--namespace-id={self.default_nsid} " + \
+ "| grep ^lbaf | awk '{print $5}' | cut -f 2 -d ':' | tr -s \"\\n\" \" \""
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
encoding='utf-8')
self.lbads_list = proc.stdout.read().strip().split(" ")
# read metadata information
- id_ns = "nvme id-ns " + self.ctrl + \
- " -n1 | grep ^lbaf | awk '{print $4}'" + \
- " | cut -f 2 -d ':' | tr -s \"\\n\" \" \""
+ id_ns = f"{self.nvme_bin} id-ns {self.ctrl} " + \
+ f"--namespace-id={self.default_nsid} " + \
+ "| grep ^lbaf | awk '{print $4}' | cut -f 2 -d ':' | tr -s \"\\n\" \" \""
proc = subprocess.Popen(id_ns, shell=True, stdout=subprocess.PIPE,
encoding='utf-8')
self.ms_list = proc.stdout.read().strip().split(" ")
- 0 on success, error code on failure.
"""
err = 0
- fw_log_cmd = "nvme fw-log " + self.ctrl
+ fw_log_cmd = f"{self.nvme_bin} fw-log {self.ctrl}"
proc = subprocess.Popen(fw_log_cmd,
shell=True,
stdout=subprocess.PIPE,
"""
if str(feature_id) == "0x09":
for vector in range(self.vector_list_len):
- get_feat_cmd = "nvme get-feature " + self.ctrl + \
- " --feature-id=" + str(feature_id) + \
- " --cdw11=" + str(vector) + " -H"
+ get_feat_cmd = f"{self.nvme_bin} get-feature {self.ctrl} " + \
+ f"--feature-id={str(feature_id)} " + \
+ f"--cdw11={str(vector)} --human-readable"
proc = subprocess.Popen(get_feat_cmd,
shell=True,
stdout=subprocess.PIPE,
print(feature_output)
self.assertEqual(proc.wait(), 0)
else:
- get_feat_cmd = "nvme get-feature " + self.ctrl + \
- " --feature-id=" + str(feature_id) + " -H"
+ get_feat_cmd = f"{self.nvme_bin} get-feature {self.ctrl} " + \
+ f"--feature-id={str(feature_id)} --human-readable"
if str(feature_id) == "0x05":
get_feat_cmd += f" --namespace-id={self.default_nsid}"
proc = subprocess.Popen(get_feat_cmd,
- 0 on success, error code on failure.
"""
err = 0
- get_lba_status_cmd = "nvme get-lba-status " + self.ctrl + \
- " --namespace-id=" + str(self.ns1) + \
- " --start-lba=" + str(self.start_lba) + \
- " --max-dw=" + str(self.max_dw) + \
- " --action=" + str(self.action) + \
- " --range-len=" + str(self.range_len)
+ get_lba_status_cmd = f"{self.nvme_bin} get-lba-status {self.ctrl} " + \
+ f"--namespace-id={str(self.ns1)} " + \
+ f"--start-lba={str(self.start_lba)} " + \
+ f"--max-dw={str(self.max_dw)} " + \
+ f"--action={str(self.action)} " + \
+ f"--range-len={str(self.range_len)}"
proc = subprocess.Popen(get_lba_status_cmd,
shell=True,
stdout=subprocess.PIPE,
- 0 on success, error code on failure.
"""
err = 0
- id_ns_cmd = "nvme id-ns " + self.ctrl + "n" + str(nsid)
+ id_ns_cmd = f"{self.nvme_bin} id-ns {self.ctrl} " + \
+ f"--namespace-id={str(nsid)}"
proc = subprocess.Popen(id_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
- 0 on success, error code on failure.
"""
err = 0
- lba_stat_log_cmd = "nvme lba-status-log " + self.ctrl
+ lba_stat_log_cmd = f"{self.nvme_bin} lba-status-log {self.ctrl}"
proc = subprocess.Popen(lba_stat_log_cmd,
shell=True,
stdout=subprocess.PIPE,
self.ctrl = "XXX"
self.ns1 = "XXX"
self.test_log_dir = "XXX"
+ self.nvme_bin = "nvme"
self.do_validate_pci_device = True
self.default_nsid = 0x1
self.config_file = 'tests/config.json'
self.ctrl = config['controller']
self.ns1 = config['ns1']
self.log_dir = config['log_dir']
- self.do_validate_pci_device = config.get('do_validate_pci_device', self.do_validate_pci_device)
+ self.nvme_bin = config.get('nvme_bin', self.nvme_bin)
+ print(f"\nUsing nvme binary '{self.nvme_bin}'")
+ self.do_validate_pci_device = config.get(
+ 'do_validate_pci_device', self.do_validate_pci_device)
self.clear_log_dir = False
if self.clear_log_dir is True:
- Returns:
- None
"""
- nvme_reset_cmd = "nvme reset " + self.ctrl
+ nvme_reset_cmd = f"{self.nvme_bin} reset {self.ctrl}"
err = subprocess.call(nvme_reset_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- controller id.
"""
- get_ctrl_id = f"nvme list-ctrl {self.ctrl} --output-format=json"
+ get_ctrl_id = f"{self.nvme_bin} list-ctrl {self.ctrl} " + \
+ "--output-format=json"
proc = subprocess.Popen(get_ctrl_id,
shell=True,
stdout=subprocess.PIPE,
- List of the namespaces.
"""
ns_list = []
- ns_list_cmd = "nvme list-ns " + self.ctrl
+ ns_list_cmd = f"{self.nvme_bin} list-ns {self.ctrl}"
proc = subprocess.Popen(ns_list_cmd,
shell=True,
stdout=subprocess.PIPE,
"""
pattern = re.compile("^nn[ ]+: [0-9]", re.IGNORECASE)
max_ns = -1
- max_ns_cmd = "nvme id-ctrl " + self.ctrl
+ max_ns_cmd = f"{self.nvme_bin} id-ctrl {self.ctrl}"
proc = subprocess.Popen(max_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- lba format size as a tuple of (data_size, metadata_size) in bytes.
"""
- nvme_id_ns_cmd = f"nvme id-ns {self.ns1} --output-format=json"
+ nvme_id_ns_cmd = f"{self.nvme_bin} id-ns {self.ns1} " + \
+ "--output-format=json"
proc = subprocess.Popen(nvme_id_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
"""
pattern = re.compile("^tnvmcap[ ]+: [0-9]", re.IGNORECASE)
ncap = -1
- ncap_cmd = "nvme id-ctrl " + self.ctrl
+ ncap_cmd = f"{self.nvme_bin} id-ctrl {self.ctrl}"
proc = subprocess.Popen(ncap_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- Filed value of the given field
"""
- id_ctrl_cmd = f"nvme id-ctrl {self.ctrl} --output-format=json"
+ id_ctrl_cmd = f"{self.nvme_bin} id-ctrl {self.ctrl} " + \
+ "--output-format=json"
proc = subprocess.Popen(id_ctrl_cmd,
shell=True,
stdout=subprocess.PIPE,
"""
# defaulting to 4K
nvm_format = 4096
- nvm_format_cmd = "nvme id-ns " + self.ctrl + " -n1"
+ nvm_format_cmd = f"{self.nvme_bin} id-ns {self.ctrl} " + \
+ f"--namespace-id={self.default_nsid}"
proc = subprocess.Popen(nvm_format_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- None
"""
- delete_ns_cmd = "nvme delete-ns " + self.ctrl + " -n 0xFFFFFFFF"
+ delete_ns_cmd = f"{self.nvme_bin} delete-ns {self.ctrl} " + \
+ "--namespace-id=0xFFFFFFFF"
self.assertEqual(self.exec_cmd(delete_ns_cmd), 0)
- list_ns_cmd = "nvme list-ns " + self.ctrl + " --all | wc -l"
+ list_ns_cmd = f"{self.nvme_bin} list-ns {self.ctrl} --all | wc -l"
proc = subprocess.Popen(list_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- return code of the nvme create namespace command.
"""
- create_ns_cmd = "nvme create-ns " + self.ctrl + " --nsze=" + \
- str(nsze) + " --ncap=" + str(ncap) + \
- " --flbas=" + str(flbas) + " --dps=" + str(dps)
+ create_ns_cmd = f"{self.nvme_bin} create-ns {self.ctrl} " + \
+ f"--nsze={str(nsze)} --ncap={str(ncap)} --flbas={str(flbas)} " + \
+ f"--dps={str(dps)}"
return self.exec_cmd(create_ns_cmd)
def create_and_validate_ns(self, nsid, nsze, ncap, flbas, dps):
err = self.create_ns(nsze, ncap, flbas, dps)
if err == 0:
time.sleep(2)
- id_ns_cmd = "nvme id-ns " + self.ctrl + " -n " + str(nsid)
+ id_ns_cmd = f"{self.nvme_bin} id-ns {self.ctrl} " + \
+ f"--namespace-id={str(nsid)}"
err = subprocess.call(id_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- 0 on success, error code on failure.
"""
- attach_ns_cmd = "nvme attach-ns " + self.ctrl + \
- " --namespace-id=" + str(ns_id) + \
- " --controllers=" + ctrl_id
+ attach_ns_cmd = f"{self.nvme_bin} attach-ns {self.ctrl} " + \
+ f"--namespace-id={str(ns_id)} --controllers={ctrl_id}"
err = subprocess.call(attach_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- 0 on success, error code on failure.
"""
- detach_ns_cmd = "nvme detach-ns " + self.ctrl + \
- " --namespace-id=" + str(nsid) + \
- " --controllers=" + ctrl_id
+ detach_ns_cmd = f"{self.nvme_bin} detach-ns {self.ctrl} " + \
+ f"--namespace-id={str(nsid)} --controllers={ctrl_id}"
return subprocess.call(detach_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
- 0 on success, 1 on failure.
"""
# delete the namespace
- delete_ns_cmd = "nvme delete-ns " + self.ctrl + " -n " + str(nsid)
+ delete_ns_cmd = f"{self.nvme_bin} delete-ns {self.ctrl} " + \
+ f"--namespace-id={str(nsid)}"
err = subprocess.call(delete_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- 0 on success, error code on failure.
"""
- smart_log_cmd = "nvme smart-log " + self.ctrl + " -n " + str(nsid)
+ smart_log_cmd = f"{self.nvme_bin} smart-log {self.ctrl} " + \
+ f"--namespace-id={str(nsid)}"
print(smart_log_cmd)
proc = subprocess.Popen(smart_log_cmd,
shell=True,
- 0 on success, error code on failure.
"""
if not vendor:
- id_ctrl_cmd = "nvme id-ctrl " + self.ctrl
+ id_ctrl_cmd = f"{self.nvme_bin} id-ctrl {self.ctrl}"
else:
- id_ctrl_cmd = "nvme id-ctrl --vendor-specific " + self.ctrl
+ id_ctrl_cmd = f"{self.nvme_bin} id-ctrl " +\
+ f"--vendor-specific {self.ctrl}"
print(id_ctrl_cmd)
proc = subprocess.Popen(id_ctrl_cmd,
shell=True,
- 0 on success, error code on failure.
"""
pattern = re.compile(r"^ Entry\[[ ]*[0-9]+\]")
- error_log_cmd = "nvme error-log " + self.ctrl
+ error_log_cmd = f"{self.nvme_bin} error-log {self.ctrl}"
proc = subprocess.Popen(error_log_cmd,
shell=True,
stdout=subprocess.PIPE,
- Returns:
- value for key requested.
"""
- id_ctrl = "nvme id-ctrl " + self.ctrl
+ id_ctrl = f"{self.nvme_bin} id-ctrl {self.ctrl}"
print("\n" + id_ctrl)
proc = subprocess.Popen(id_ctrl,
shell=True,
- Returns:
- return code for nvme write command.
"""
- write_cmd = "nvme write " + self.ns1 + " --start-block=" + \
- str(self.start_block) + " --block-count=" + \
- str(self.block_count) + " --data-size=" + \
- str(self.data_size) + " --data=" + self.write_file
+ write_cmd = f"{self.nvme_bin} write {self.ns1} " + \
+ f"--start-block={str(self.start_block)} " + \
+ f"--block-count={str(self.block_count)} " + \
+ f"--data-size={str(self.data_size)} --data={self.write_file}"
return self.exec_cmd(write_cmd)
def nvme_read(self):
- Returns:
- return code for nvme read command.
"""
- read_cmd = "nvme read " + self.ns1 + " --start-block=" + \
- str(self.start_block) + " --block-count=" + \
- str(self.block_count) + " --data-size=" + \
- str(self.data_size) + " --data=" + self.read_file
+ read_cmd = f"{self.nvme_bin} read {self.ns1} " + \
+ f"--start-block={str(self.start_block)} " + \
+ f"--block-count={str(self.block_count)} " + \
+ f"--data-size={str(self.data_size)} --data={self.read_file}"
print(read_cmd)
return self.exec_cmd(read_cmd)
- Returns:
- return code for nvme verify command.
"""
- verify_cmd = "nvme verify " + self.ctrl + \
- " --namespace-id=" + str(self.namespace) + \
- " --start-block=" + str(self.start_block) + \
- " --block-count=" + str(self.block_count)
+ verify_cmd = f"{self.nvme_bin} verify {self.ctrl} " + \
+ f"--namespace-id={str(self.namespace)} " + \
+ f"--start-block={str(self.start_block)} " + \
+ f"--block-count={str(self.block_count)}"
return self.exec_cmd(verify_cmd)
def test_verify(self):
- Returns:
- return code of nvme write uncorrectable command.
"""
- write_uncor_cmd = "nvme write-uncor " + self.ns1 + \
- " --start-block=" + str(self.start_block) + \
- " --block-count=" + str(self.block_count)
+ write_uncor_cmd = f"{self.nvme_bin} write-uncor {self.ns1} " + \
+ f"--start-block={str(self.start_block)} " + \
+ f"--block-count={str(self.block_count)}"
return self.exec_cmd(write_uncor_cmd)
def test_write_uncor(self):
- Returns:
- return code for nvme write command.
"""
- write_zeroes_cmd = "nvme write-zeroes " + self.ns1 + \
- " --start-block=" + str(self.start_block) + \
- " --block-count=" + str(self.block_count)
+ write_zeroes_cmd = f"{self.nvme_bin} write-zeroes {self.ns1} " + \
+ f"--start-block={str(self.start_block)} " + \
+ f"--block-count={str(self.block_count)}"
return self.exec_cmd(write_zeroes_cmd)
def validate_write_read(self):