]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
tests: Refactor prints
authorDennis Maisenbacher <dennis.maisenbacher@wdc.com>
Fri, 8 Nov 2024 09:25:29 +0000 (09:25 +0000)
committerDaniel Wagner <wagi@monom.org>
Tue, 10 Dec 2024 16:09:11 +0000 (17:09 +0100)
Remove unused prints and add some informative prints.

Signed-off-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com>
tests/nvme_copy_test.py
tests/nvme_create_max_ns_test.py
tests/nvme_flush_test.py
tests/nvme_format_test.py
tests/nvme_fw_log_test.py
tests/nvme_get_features_test.py
tests/nvme_get_lba_status_test.py
tests/nvme_id_ns_test.py
tests/nvme_lba_status_log_test.py
tests/nvme_test.py
tests/nvme_test_io.py

index 085c765053c0e9923c45dc9c82404292861e00dd..f73cd04b1e1ee642ccb138bf9955cc731a679b71 100644 (file)
@@ -34,7 +34,6 @@ class TestNVMeCopy(TestNVMe):
     def setUp(self):
         """ Pre Section for TestNVMeCopy """
         super().setUp()
-        print("\nSetting up test...")
         self.ocfs = self.get_ocfs()
         self.host_behavior_data = None
         cross_namespace_copy = self.ocfs & 0xc
@@ -78,7 +77,6 @@ class TestNVMeCopy(TestNVMe):
 
     def tearDown(self):
         """ Post Section for TestNVMeCopy """
-        print("Tearing down test...")
         if self.host_behavior_data:
             # restore saved host behavior support data
             set_features_cmd = f"{self.nvme_bin} set-feature {self.ctrl} " + \
@@ -117,12 +115,10 @@ class TestNVMeCopy(TestNVMe):
         if "sopts" in kwargs:
             copy_cmd += f" --sopts={kwargs['sopts']}"
         # run and assert success
-        print("Running command:", copy_cmd)
         self.assertEqual(self.exec_cmd(copy_cmd), 0)
 
     def test_copy(self):
         """ Testcase main """
-        print("Running test...")
         self.copy(0, 1, 2, descriptor_format=0)
         self.copy(0, 1, 2, descriptor_format=1)
         self.copy(0, 1, 2, descriptor_format=2, snsids=self.ns1_nsid)
index 5cb7448e34897a5d0442741b038db1ebb0a2750f..f4fa72c7bb279656c60314fec6eae53b02cde5bb 100644 (file)
@@ -82,21 +82,21 @@ class TestNVMeCreateMaxNS(TestNVMe):
         """ Testcase main """
         print(f"##### Testing max_ns: {self.max_ns}")
         for nsid in range(1, self.max_ns + 1):
-            print("##### Creating " + str(nsid))
+            print(f"##### Creating {nsid}")
             err = self.create_and_validate_ns(nsid,
                                               self.nsze,
                                               self.ncap,
                                               self.flbas,
                                               self.dps)
             self.assertEqual(err, 0)
-            print("##### Attaching " + str(nsid))
+            print(f"##### Attaching {nsid}")
             self.assertEqual(self.attach_ns(self.ctrl_id, nsid), 0)
-            print("##### Running IOs in " + str(nsid))
+            print(f"##### Running IOs in {nsid}")
             self.run_ns_io(nsid, 9, 1)
 
         for nsid in range(1, self.max_ns + 1):
-            print("##### Detaching " + str(nsid))
+            print(f"##### Detaching {nsid}")
             self.assertEqual(self.detach_ns(self.ctrl_id, nsid), 0)
-            print("#### Deleting " + str(nsid))
+            print(f"#### Deleting {nsid}")
             self.assertEqual(self.delete_and_validate_ns(nsid), 0)
         self.nvme_reset_ctrl()
index 4c9e2b9e2f42efd6dae556cf5b23d866d8053f69..0f2d3c52a887ad0aa83ac3301dc30f75030dd7bb 100644 (file)
@@ -55,7 +55,6 @@ class TestNVMeFlushCmd(TestNVMe):
         """
         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)
 
     def test_nvme_flush(self):
index daf35740897a6206cbf05c7848a98df57a2c872f..68445ac843a0c785f6afafdad97e8a30b3279588 100644 (file)
@@ -122,6 +122,7 @@ class TestNVMeFormatCmd(TestNVMe):
         # extract the supported format information.
         self.attach_detach_primary_ns()
 
+        print("##### Testing lba formats:")
         # iterate through all supported format
         for flbas, lba_format in enumerate(self.lba_format_list):
             ds = lba_format['ds']
index 11d79cddb39b4ab371f7c1b5e3231306319dd73a..e56953df8bf80a8dcdcd234b2a7b2e39a8f8a366 100644 (file)
@@ -57,16 +57,12 @@ class TestNVMeFwLogCmd(TestNVMe):
             - Returns:
                 - 0 on success, error code on failure.
         """
-        err = 0
         fw_log_cmd = f"{self.nvme_bin} fw-log {self.ctrl}"
         proc = subprocess.Popen(fw_log_cmd,
                                 shell=True,
                                 stdout=subprocess.PIPE,
                                 encoding='utf-8')
-        fw_log_output = proc.communicate()[0]
-        print("\n" + fw_log_output + "\n")
-        err = proc.wait()
-        return err
+        return proc.wait()
 
     def test_fw_log(self):
         """ Testcase main """
index 6edf332444570c4c79264b9280d1e11bf327c134..d1bf6211f7647835fe96b16a1d2ac7c4d2d255b4 100644 (file)
@@ -88,8 +88,6 @@ class TestNVMeGetMandatoryFeatures(TestNVMe):
                                         shell=True,
                                         stdout=subprocess.PIPE,
                                         encoding='utf-8')
-                feature_output = proc.communicate()[0]
-                print(feature_output)
                 self.assertEqual(proc.wait(), 0)
         else:
             get_feat_cmd = f"{self.nvme_bin} get-feature {self.ctrl} " + \
@@ -100,8 +98,6 @@ class TestNVMeGetMandatoryFeatures(TestNVMe):
                                     shell=True,
                                     stdout=subprocess.PIPE,
                                     encoding='utf-8')
-            feature_output = proc.communicate()[0]
-            print(feature_output)
             self.assertEqual(proc.wait(), 0)
 
     def test_get_mandatory_features(self):
index 7577f6d089890c6af0b4ccd9e5e5043d97bdcf0f..15842cfba81ab1cc7a3010a5f6a46c9d535138da 100644 (file)
@@ -50,7 +50,6 @@ class TestNVMeGetLbaStatusCmd(TestNVMe):
             - Returns:
                 - 0 on success, error code on failure.
         """
-        err = 0
         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)} " + \
@@ -61,10 +60,7 @@ class TestNVMeGetLbaStatusCmd(TestNVMe):
                                 shell=True,
                                 stdout=subprocess.PIPE,
                                 encoding='utf-8')
-        get_lba_status_output = proc.communicate()[0]
-        print("\n" + get_lba_status_output + "\n")
-        err = proc.wait()
-        return err
+        return proc.wait()
 
     def test_get_lba_status(self):
         """ Testcase main """
index 247f75365d968b236d3bda0d5de0ccf9a28ebdb0..46ed3eeffe63ccc436a9862ba1f921eeed3205c2 100644 (file)
@@ -60,17 +60,13 @@ class TestNVMeIdentifyNamespace(TestNVMe):
             - Returns:
                 - 0 on success, error code on failure.
         """
-        err = 0
         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,
                                 encoding='utf-8')
-        id_ns_output = proc.communicate()[0]
-        print(id_ns_output + "\n")
-        err = proc.wait()
-        return err
+        return proc.wait()
 
     def get_id_ns_all(self):
         """
index 8eca23bd0b078db404eb23794369822ed0ed8be3..079fe5c71c161775fb5f365900c697d4a9ee0fab 100644 (file)
@@ -45,16 +45,12 @@ class TestNVMeLbaStatLogCmd(TestNVMe):
             - Returns:
                 - 0 on success, error code on failure.
         """
-        err = 0
         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,
                                 encoding='utf-8')
-        lba_stat_log_output = proc.communicate()[0]
-        print("\n" + lba_stat_log_output + "\n")
-        err = proc.wait()
-        return err
+        return proc.wait()
 
     def test_lba_stat_log(self):
         """ Testcase main """
index 8088ee2e934d94e9685061a714e989864e345a58..923e6747c00033ef2d4ee326be50277e80bbbb83 100644 (file)
@@ -66,12 +66,18 @@ class TestNVMe(unittest.TestCase):
         self.load_config()
         if self.do_validate_pci_device:
             self.validate_pci_device()
+        print(f"\nsetup: ctrl: {self.ctrl}, ns1: {self.ns1}, default_nsid: {self.default_nsid}, flbas: {self.flbas}\n")
 
     def tearDown(self):
         """ Post Section for TestNVMe. """
         if self.clear_log_dir is True:
             shutil.rmtree(self.log_dir, ignore_errors=True)
         self.create_and_attach_default_ns()
+        print(f"\nteardown: ctrl: {self.ctrl}, ns1: {self.ns1}, default_nsid: {self.default_nsid}, flbas: {self.flbas}\n")
+
+    @classmethod
+    def tearDownClass(cls):
+        print("\n")
 
     def create_and_attach_default_ns(self):
         """ Creates a default namespace with the full capacity of the ctrls NVM
@@ -104,8 +110,8 @@ class TestNVMe(unittest.TestCase):
                 - None
         """
         x1, x2, dev = self.ctrl.split('/')
-        cmd = cmd = "find /sys/devices -name \\*" + dev + " | grep -i pci"
-        err = subprocess.call(cmd, shell=True)
+        cmd = "find /sys/devices -name \\*" + dev + " | grep -i pci"
+        err = subprocess.call(cmd, shell=True, stdout=subprocess.DEVNULL)
         self.assertEqual(err, 0, "ERROR : Only NVMe PCI subsystem is supported")
 
     def load_config(self):
@@ -452,15 +458,12 @@ class TestNVMe(unittest.TestCase):
         """
         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,
                                 stdout=subprocess.PIPE,
                                 encoding='utf-8')
         err = proc.wait()
         self.assertEqual(err, 0, "ERROR : nvme smart log failed")
-        smart_log_output = proc.communicate()[0]
-        print(f"{smart_log_output}")
         return err
 
     def get_id_ctrl(self, vendor=False):
@@ -475,7 +478,6 @@ class TestNVMe(unittest.TestCase):
         else:
             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,
                                 stdout=subprocess.PIPE,
@@ -521,14 +523,14 @@ class TestNVMe(unittest.TestCase):
         ns_path = self.ctrl + "n" + str(nsid)
         io_cmd = "dd if=" + ns_path + " of=/dev/null" + " bs=" + \
                  str(block_size) + " count=" + str(count) + " > /dev/null 2>&1"
-        print(io_cmd)
+        print(f"Running io: {io_cmd}")
         run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE,
                                   encoding='utf-8')
         run_io_result = run_io.communicate()[1]
         self.assertEqual(run_io_result, None)
         io_cmd = "dd if=/dev/zero of=" + ns_path + " bs=" + \
                  str(block_size) + " count=" + str(count) + " > /dev/null 2>&1"
-        print(io_cmd)
+        print(f"Running io: {io_cmd}")
         run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE,
                                   encoding='utf-8')
         run_io_result = run_io.communicate()[1]
index e12d8c09d0c4a6cb9d4c214a073b8d57ba5cd872..6fac9db0f524789efbccd54ee3553ca52987fd1e 100644 (file)
@@ -94,5 +94,4 @@ class TestNVMeIO(TestNVMe):
             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)