Update tests for qemu
cover Update tests for qemu
Hi all,
here's an update to the nvme-cli test suite, to bring it more in line with the spec and to allow it to run under qemu.
The first part fixes up various tests to check if the functionality is implemented before running the test.
The second part is to make it to run under the quirky qemu NVMe emulation, which chose not to implement some mandatory features and log pages. But as this is qemu we sure can update the emulation, but that won't help us for existing platforms.
So there really is no good way except for masking it out in the tests.
As usual, comments and reviews are welcome
Hannes Reinecke (9):
tests/nvme_writezeros_test.py: check if write zeroes is supported tests/nvme_writeuncor_test.py: check if write uncorrectable is
supported
tests/nvme_compare_test.py: check if compare is supported
tests: ignore log tests for Qemu
tests/nvme_text.py: add test for namespace management tests/nvme_attach_detach_ns_test.py: skip if namespace mgmt is not
supported
tests/nvme_create_max_ns_test.py: skip if namespace mgmt is not
supported
tests/nvme_get_features_test.py: skip features for Qemu tests/nvme_format_test.py: skip test if namespace management is not
supported
tests/nvme_attach_detach_ns_test.py | 13 ++-- tests/nvme_compare_test.py | 7 ++- tests/nvme_create_max_ns_test.py | 10 ++- tests/nvme_error_log_test.py | 3 +- tests/nvme_format_test.py | 10 ++- tests/nvme_get_features_test.py | 2 + tests/nvme_smart_log_test.py | 5 +- tests/nvme_test.py | 119 ++++++++++++++++++++++++++++++++++++ tests/nvme_writeuncor_test.py | 11 ++-- tests/nvme_writezeros_test.py | 15 ++--- 10 files changed, 167 insertions(+), 28 deletions(-)
Signature · 1 line
2.13.7
PATCH 1/9 tests/nvme_writezeros_test.py: check if write zeroes is supported
Before testing the WRITE ZEROS command we should be testing the ONCS value of the IDENTIFY CONTROLLER command to figure out if the command is supported.
--- tests/nvme_test.py | 23 +++++++++++++++++++++++ tests/nvme_writezeros_test.py | 15 ++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-)
tests/nvme_test.py +23 -0
@@ -253,6 +253,29 @@ class TestNVMe(object): return int(nvm_format) @tools.nottest + def get_oncs_write_zeroes(self): + """ Wrapper for extracting write zeroes command support. + - Args: + - None + - Returns: + - true if supported. + """ + pattern = re.compile("^oncs[ ]+: [0-9]", re.IGNORECASE) + oncs = 0 + get_ctrl_id = "nvme id-ctrl " + self.ctrl + proc = subprocess.Popen(get_ctrl_id, + shell=True, + stdout=subprocess.PIPE) + err = proc.wait() + assert_equal(err, 0, "ERROR : reading oncs value failed") + + for line in proc.stdout: + if pattern.match(line): + oncs = line.split(":")[1].strip() + break + return int(oncs, 16) & 8 + + @tools.nottest def delete_all_ns(self): """ Wrapper for deleting all the namespaces. - Args:
tests/nvme_writezeros_test.py +8 -7
@@ -93,10 +93,11 @@ class TestNVMeWriteZeros(TestNVMeIO): return 0 if filecmp.cmp(self.zero_file, self.read_file) is True else 1 def test_write_zeros(self): - """ Testcae main """ - assert_equal(self.nvme_write(), 0) - assert_equal(self.nvme_read(), 0) - assert_equal(self.validate_write_read(), 0) - assert_equal(self.write_zeroes(), 0) - assert_equal(self.nvme_read(), 0) - assert_equal(self.validate_zeroes(), 0) + """ Testcase main """ + if self.get_oncs_write_zeroes() == 1: + assert_equal(self.nvme_write(), 0) + assert_equal(self.nvme_read(), 0) + assert_equal(self.validate_write_read(), 0) + assert_equal(self.write_zeroes(), 0) + assert_equal(self.nvme_read(), 0) + assert_equal(self.validate_zeroes(), 0)
Signature · 1 line
2.13.7
PATCH 2/9 tests/nvme_writeuncor_test.py: check if write uncorrectable is supported
In reply to Hannes ReineckeBefore testing the WRITE UNCORRECTABLE command we should be testing the ONCS value of the IDENTIFY CONTROLLER command to figure out if the command is supported.
--- tests/nvme_test.py | 24 ++++++++++++++++++++++++ tests/nvme_writeuncor_test.py | 11 ++++++----- 2 files changed, 30 insertions(+), 5 deletions(-)
tests/nvme_test.py +24 -0
@@ -276,6 +276,30 @@ class TestNVMe(object): return int(oncs, 16) & 8 @tools.nottest + def get_oncs_write_uncorr(self): + """ Wrapper for extracting write uncorrectable command support. + - Args: + - None + - Returns: + - true if supported. + """ + pattern = re.compile("^oncs[ ]+: [0-9]", re.IGNORECASE) + oncs = 0 + get_ctrl_id = "nvme id-ctrl " + self.ctrl + proc = subprocess.Popen(get_ctrl_id, + shell=True, + stdout=subprocess.PIPE) + err = proc.wait() + assert_equal(err, 0, "ERROR : reading oncs value failed") + + for line in proc.stdout: + if pattern.match(line): + oncs = line.split(":")[1].strip() + break + + return int(oncs, 16) & 2 + + @tools.nottest def delete_all_ns(self): """ Wrapper for deleting all the namespaces. - Args:
tests/nvme_writeuncor_test.py +6 -5
@@ -69,8 +69,9 @@ class TestNVMeUncor(TestNVMeIO): def test_write_uncor(self): """ Testcase main """ - assert_equal(self.nvme_read(), 0) - assert_equal(self.write_uncor(), 0) - assert_not_equal(self.nvme_read(), 0) - assert_equal(self.nvme_write(), 0) - assert_equal(self.nvme_read(), 0) + if self.get_oncs_write_uncorr() == 1: + assert_equal(self.nvme_read(), 0) + assert_equal(self.write_uncor(), 0) + assert_not_equal(self.nvme_read(), 0) + assert_equal(self.nvme_write(), 0) + assert_equal(self.nvme_read(), 0)
Signature · 1 line
2.13.7
PATCH 3/9 tests/nvme_compare_test.py: check if compare is supported
In reply to Hannes ReineckeBefore testing the COMPARE command we should be testing the ONCS value of the IDENTIFY CONTROLLER command to figure out if the command is supported.
--- tests/nvme_compare_test.py | 7 ++++--- tests/nvme_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-)
tests/nvme_compare_test.py +4 -3
@@ -74,6 +74,7 @@ class TestNVMeCompareCmd(TestNVMeIO): def test_nvme_compare(self): """ Testcase main """ - assert_equal(self.nvme_write(), 0) - assert_not_equal(self.nvme_compare(self.compare_file), 0) - assert_equal(self.nvme_compare(self.write_file), 0) + if self.get_oncs_compare() == 1: + assert_equal(self.nvme_write(), 0) + assert_not_equal(self.nvme_compare(self.compare_file), 0) + assert_equal(self.nvme_compare(self.write_file), 0)
tests/nvme_test.py +24 -0
@@ -300,6 +300,30 @@ class TestNVMe(object): return int(oncs, 16) & 2 @tools.nottest + def get_oncs_compare(self): + """ Wrapper for extracting compare command support. + - Args: + - None + - Returns: + - true if supported. + """ + pattern = re.compile("^oncs[ ]+: [0-9]", re.IGNORECASE) + oncs = 0 + get_ctrl_id = "nvme id-ctrl " + self.ctrl + proc = subprocess.Popen(get_ctrl_id, + shell=True, + stdout=subprocess.PIPE) + err = proc.wait() + assert_equal(err, 0, "ERROR : reading oncs value failed") + + for line in proc.stdout: + if pattern.match(line): + oncs = line.split(":")[1].strip() + break + + return int(oncs, 16) & 1 + + @tools.nottest def delete_all_ns(self): """ Wrapper for deleting all the namespaces. - Args:
Signature · 1 line
2.13.7
PATCH 4/9 tests: ignore log tests for Qemu
In reply to Hannes ReineckeThe Qemu NVMe implementation doesn't support the GET LOG command, so these tests are expected to fail.
--- tests/nvme_error_log_test.py | 3 ++- tests/nvme_smart_log_test.py | 5 +++-- tests/nvme_test.py | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-)
tests/nvme_error_log_test.py +2 -1
@@ -60,4 +60,5 @@ class TestNVMeErrorLogCmd(TestNVMe): def test_get_error_log(self): """ Testcase main """ - assert_equal(self.get_error_log_ctrl(), 0) + if self.is_qemu_controller() == 0: + assert_equal(self.get_error_log_ctrl(), 0)
tests/nvme_smart_log_test.py +3 -2
@@ -82,5 +82,6 @@ class TestNVMeSmartLogCmd(TestNVMe): def test_smart_log(self): """ Testcase main """ - assert_equal(self.get_smart_log_ctrl(), 0) - assert_equal(self.get_smart_log_all_ns(), 0) + if self.is_qemu_controller() == 0: + assert_equal(self.get_smart_log_ctrl(), 0) + assert_equal(self.get_smart_log_all_ns(), 0)
tests/nvme_test.py +24 -0
@@ -324,6 +324,30 @@ class TestNVMe(object): return int(oncs, 16) & 1 @tools.nottest + def is_qemu_controller(self): + """ Wrapper for checking for Qemu NVMe controller. + - Args: + - None + - Returns: + - true if supported. + """ + pattern = re.compile("^mn[ ]+: [a-z ]", re.IGNORECASE) + model = "" + get_ctrl_id = "nvme id-ctrl " + self.ctrl + proc = subprocess.Popen(get_ctrl_id, + shell=True, + stdout=subprocess.PIPE) + err = proc.wait() + assert_equal(err, 0, "ERROR : reading controller model value failed") + + for line in proc.stdout: + if pattern.match(line): + model = line.split(":")[1].strip() + break + + return model in "QEMU NVMe Ctrl" + + @tools.nottest def delete_all_ns(self): """ Wrapper for deleting all the namespaces. - Args:
Signature · 1 line
2.13.7
PATCH 5/9 tests/nvme_text.py: add test for namespace management
In reply to Hannes ReineckeSome commands are only mandatory if namespace management is supported, so add a test to detect it.
--- tests/nvme_test.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
tests/nvme_test.py +24 -0
@@ -324,6 +324,30 @@ class TestNVMe(object): return int(oncs, 16) & 1 @tools.nottest + def get_oacs_namespace_mgmt(self): + """ Wrapper for extracting namespace management support. + - Args: + - None + - Returns: + - true if supported. + """ + pattern = re.compile("^oacs[ ]+: [0-9]", re.IGNORECASE) + oacs = 0 + get_ctrl_id = "nvme id-ctrl " + self.ctrl + proc = subprocess.Popen(get_ctrl_id, + shell=True, + stdout=subprocess.PIPE) + err = proc.wait() + assert_equal(err, 0, "ERROR : reading oacs value failed") + + for line in proc.stdout: + if pattern.match(line): + oacs = line.split(":")[1].strip() + break + + return int(oacs, 16) & 8 + + @tools.nottest def is_qemu_controller(self): """ Wrapper for checking for Qemu NVMe controller. - Args:
Signature · 1 line
2.13.7
PATCH 6/9 tests/nvme_attach_detach_ns_test.py: skip if namespace mgmt is not supported
In reply to Hannes ReineckeIf namespace management is not supported the test will fail, too. So check for it prior to executing the test.
--- tests/nvme_attach_detach_ns_test.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
tests/nvme_attach_detach_ns_test.py +9 -4
@@ -53,18 +53,17 @@ class TestNVMeAttachDetachNSCmd(TestNVMe): self.nsze = 0x1400000 self.ncap = 0x1400000 self.setup_log_dir(self.__class__.__name__) - self.ctrl_id = self.get_ctrl_id() - self.delete_all_ns() - time.sleep(1) def __del__(self): """ Post Section for TestNVMeAttachDetachNSCmd - Create primary namespace. - - Atttach it to controller. + - Attach it to controller. - Call super class's destructor. """ + if self.get_oacs_namespace_mgmt() == 0: + return assert_equal(self.create_and_validate_ns(self.default_nsid, self.nsze, self.ncap,
@@ -75,6 +74,12 @@ class TestNVMeAttachDetachNSCmd(TestNVMe): def test_attach_detach_ns(self): """ Testcase main """ + if self.get_oacs_namespace_mgmt() == 0: + return + + self.ctrl_id = self.get_ctrl_id() + self.delete_all_ns() + time.sleep(1) err = self.create_and_validate_ns(self.default_nsid, self.nsze, self.ncap,
Signature · 1 line
2.13.7
PATCH 7/9 tests/nvme_create_max_ns_test.py: skip if namespace mgmt is not supported
In reply to Hannes ReineckeIf namespace management is not supported the test will fail, too. So check for it prior to executing the test.
--- tests/nvme_create_max_ns_test.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tests/nvme_create_max_ns_test.py +7 -3
@@ -54,9 +54,6 @@ class TestNVMeCreateMaxNS(TestNVMe): self.ncap = self.nsze self.setup_log_dir(self.__class__.__name__) self.max_ns = self.get_max_ns() - self.ctrl_id = self.get_ctrl_id() - self.delete_all_ns() - time.sleep(1) def __del__(self): """
@@ -66,6 +63,8 @@ class TestNVMeCreateMaxNS(TestNVMe): - Atttach it to controller. - Call super class's destructor. """ + if self.get_oacs_namespace_mgmt() == 0: + return assert_equal(self.create_and_validate_ns(self.default_nsid, self.nsze, self.ncap,
@@ -76,6 +75,11 @@ class TestNVMeCreateMaxNS(TestNVMe): def test_attach_detach_ns(self): """ Testcase main """ + if self.get_oacs_namespace_mgmt() == 0: + return + self.ctrl_id = self.get_ctrl_id() + self.delete_all_ns() + time.sleep(1) for nsid in range(1, self.max_ns): print("##### Creating " + str(nsid)) err = self.create_and_validate_ns(nsid,
Signature · 1 line
2.13.7
PATCH 8/9 tests/nvme_get_features_test.py: skip features for Qemu
In reply to Hannes ReineckeQemu doesn't implement all mandatory features, so we should only be querying the implemented features when running under qemu.
--- tests/nvme_get_features_test.py | 2 ++ 1 file changed, 2 insertions(+)
tests/nvme_get_features_test.py +2 -0
@@ -54,6 +54,8 @@ class TestNVMeGetMandatoryFeatures(TestNVMe): self.setup_log_dir(self.__class__.__name__) self.feature_id_list = ["0x01", "0x02", "0x04", "0x05", "0x07", "0x08", "0x09", "0x0A", "0x0B"] + if self.is_qemu_controller(): + self.feature_id_list = [ "0x06", "0x07" ] get_vector_list_cmd = "cat /proc/interrupts | grep nvme |" \ " cut -d : -f 1 | tr -d ' ' | tr '\n' ' '" proc = subprocess.Popen(get_vector_list_cmd,
Signature · 1 line
2.13.7
PATCH 9/9 tests/nvme_format_test.py: skip test if namespace management is not supported
In reply to Hannes ReineckeWhile the spec doesn't make any explicit reference to namespace management, the 'format' command itself is optional, and as such should be allowed to fail. And the test requires the use of the controller identifier, which in itself requires namespace management.
So add a check for namespace management before executing the tests.
--- tests/nvme_format_test.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tests/nvme_format_test.py +7 -3
@@ -65,14 +65,11 @@ class TestNVMeFormatCmd(TestNVMe): self.flbas = 0 # ns formattes logical block settings self.nsze = 0x1400000 # ns size self.ncap = 0x1400000 # ns capacity - self.ctrl_id = self.get_ctrl_id() self.lba_format_list = [] self.ms_list = [] self.lbads_list = [] self.test_log_dir = self.log_dir + "/" + self.__class__.__name__ self.setup_log_dir(self.__class__.__name__) - self.delete_all_ns() - time.sleep(1) def __del__(self): """
@@ -82,6 +79,8 @@ class TestNVMeFormatCmd(TestNVMe): - Atttach it to controller. - Call super class's destructor. """ + if self.get_oacs_namespace_mgmt() == 0: + return assert_equal(self.create_and_validate_ns(self.default_nsid, self.nsze, self.ncap,
@@ -92,6 +91,9 @@ class TestNVMeFormatCmd(TestNVMe): def attach_detach_primary_ns(self): """ Extract supported format information using default namespace """ + self.ctrl_id = self.get_ctrl_id() + self.delete_all_ns() + time.sleep(1) assert_equal(self.create_and_validate_ns(self.default_nsid, self.nsze, self.ncap,
@@ -123,6 +125,8 @@ class TestNVMeFormatCmd(TestNVMe): def test_format_ns(self): """ Testcase main """ # extract the supported format information. + if self.get_oacs_namespace_mgmt() == 0: + return self.attach_detach_primary_ns() # iterate through all supported format
Signature · 1 line
2.13.7
PATCH 1/9 tests/nvme_writezeros_test.py: check if write zeroes is supported
In reply to Hannes ReineckeQuoted 51 lines · Hannes Reinecke
Before testing the WRITE ZEROS command we should be testing the ONCS value of the IDENTIFY CONTROLLER command to figure out if the command is supported.
Signed-off-by Hannes Reinecke <hare at suse.com>--- tests/nvme_test.py | 23 +++++++++++++++++++++++ tests/nvme_writezeros_test.py | 15 ++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-)tests/nvme_test.py +23
-0@@ -253,6 +253,29 @@ class TestNVMe(object): return int(nvm_format) @tools.nottest + def get_oncs_write_zeroes(self): + """ Wrapper for extracting write zeroes command support. + - Args: + - None + - Returns: + - true if supported. + """ + pattern = re.compile("^oncs[ ]+: [0-9]", re.IGNORECASE) + oncs = 0 + get_ctrl_id = "nvme id-ctrl " + self.ctrl + proc = subprocess.Popen(get_ctrl_id, + shell=True, + stdout=subprocess.PIPE) + err = proc.wait() + assert_equal(err, 0, "ERROR : reading oncs value failed") + + for line in proc.stdout: + if pattern.match(line): + oncs = line.split(":")[1].strip() + break + return int(oncs, 16) & 8 + + @tools.nottest def delete_all_ns(self): """ Wrapper for deleting all the namespaces. - Args:tests/nvme_writezeros_test.py +0
-0@@ -93,10 +93,11 @@ class TestNVMeWriteZeros(TestNVMeIO): return 0 if filecmp.cmp(self.zero_file, self.read_file) is True else 1
tests/nvme_writezeros_test.py class TestNVMeWriteZeros(TestNVMeIO): · line 97
Quoted 10 lines
tests/nvme_writezeros_test.py +2
-7def test_write_zeros(self): - """ Testcae main """ - assert_equal(self.nvme_write(), 0) - assert_equal(self.nvme_read(), 0) - assert_equal(self.validate_write_read(), 0) - assert_equal(self.write_zeroes(), 0) - assert_equal(self.nvme_read(), 0) - assert_equal(self.validate_zeroes(), 0) + """ Testcase main """ + if self.get_oncs_write_zeroes() == 1:
I think you'll either need to shift the bit down in fhte get function, check here for 0x08, of check for a True condition
Quoted 7 lines
tests/nvme_writezeros_test.py +6
-0+ assert_equal(self.nvme_write(), 0) + assert_equal(self.nvme_read(), 0) + assert_equal(self.validate_write_read(), 0) + assert_equal(self.write_zeroes(), 0) + assert_equal(self.nvme_read(), 0) + assert_equal(self.validate_zeroes(), 0)
PATCH 2/9 tests/nvme_writeuncor_test.py: check if write uncorrectable is supported
In reply to Hannes ReineckeQuoted 50 lines · Hannes Reinecke
Before testing the WRITE UNCORRECTABLE command we should be testing the ONCS value of the IDENTIFY CONTROLLER command to figure out if the command is supported.
Signed-off-by Hannes Reinecke <hare at suse.com>--- tests/nvme_test.py | 24 ++++++++++++++++++++++++ tests/nvme_writeuncor_test.py | 11 ++++++----- 2 files changed, 30 insertions(+), 5 deletions(-)tests/nvme_test.py +24
-0@@ -276,6 +276,30 @@ class TestNVMe(object): return int(oncs, 16) & 8 @tools.nottest + def get_oncs_write_uncorr(self): + """ Wrapper for extracting write uncorrectable command support. + - Args: + - None + - Returns: + - true if supported. + """ + pattern = re.compile("^oncs[ ]+: [0-9]", re.IGNORECASE) + oncs = 0 + get_ctrl_id = "nvme id-ctrl " + self.ctrl + proc = subprocess.Popen(get_ctrl_id, + shell=True, + stdout=subprocess.PIPE) + err = proc.wait() + assert_equal(err, 0, "ERROR : reading oncs value failed") + + for line in proc.stdout: + if pattern.match(line): + oncs = line.split(":")[1].strip() + break + + return int(oncs, 16) & 2 + + @tools.nottest def delete_all_ns(self): """ Wrapper for deleting all the namespaces. - Args:tests/nvme_writeuncor_test.py +0
-0
tests/nvme_writeuncor_test.py class TestNVMeUncor(TestNVMeIO): · line 72
Quoted 9 lines
tests/nvme_writeuncor_test.py +1
-5@@ -69,8 +69,9 @@ class TestNVMeUncor(TestNVMeIO): def test_write_uncor(self): """ Testcase main """ - assert_equal(self.nvme_read(), 0) - assert_equal(self.write_uncor(), 0) - assert_not_equal(self.nvme_read(), 0) - assert_equal(self.nvme_write(), 0) - assert_equal(self.nvme_read(), 0) + if self.get_oncs_write_uncorr() == 1:
I think this needs to be '== 0x2' or change the get_oncs_write_uncorr function to shift the bit down, or check for a True condition
Quoted 6 lines
tests/nvme_writeuncor_test.py +5
-0+ assert_equal(self.nvme_read(), 0) + assert_equal(self.write_uncor(), 0) + assert_not_equal(self.nvme_read(), 0) + assert_equal(self.nvme_write(), 0) + assert_equal(self.nvme_read(), 0)