]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
tests: Fixup nvme_create_max_ns_test
authorDennis Maisenbacher <dennis.maisenbacher@wdc.com>
Tue, 15 Oct 2024 13:04:33 +0000 (13:04 +0000)
committerDaniel Wagner <wagi@monom.org>
Tue, 29 Oct 2024 06:37:41 +0000 (07:37 +0100)
Fix off by one errors and capacity allocation.

Small speedup for nvme_create_max_ns_test by reducing the io done by
`run_ns_io`. For this we introduce a new count parameter which can
overwrite the default value of 10.

Signed-off-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com>
tests/nvme_create_max_ns_test.py
tests/nvme_test.py

index bda93e196310e8a13772e72d75b656ac8c85aca7..76cd4d4a103071076e95d8ea57c2bbd8c6572e7d 100644 (file)
@@ -54,6 +54,10 @@ class TestNVMeCreateMaxNS(TestNVMe):
         self.flbas = 0
         self.nsze = int(self.get_ncap() /
                         self.get_format() / self.get_max_ns())
+        # Make sure that we have enough capacity for each ns.
+        # Creating a ns might allocate more bits (NVMCAP) than specified by
+        # nsze and ncap.
+        self.nsze = int(self.nsze / 2)
         self.ncap = self.nsze
         self.setup_log_dir(self.__class__.__name__)
         self.max_ns = self.get_max_ns()
@@ -75,11 +79,12 @@ class TestNVMeCreateMaxNS(TestNVMe):
                                                      self.flbas,
                                                      self.dps), 0)
         self.attach_ns(self.ctrl_id, self.default_nsid)
-        super.tearDown()
+        super().tearDown()
 
     def test_attach_detach_ns(self):
         """ Testcase main """
-        for nsid in range(1, self.max_ns):
+        print(f"##### Testing max_ns: {self.max_ns}")
+        for nsid in range(1, self.max_ns + 1):
             print("##### Creating " + str(nsid))
             err = self.create_and_validate_ns(nsid,
                                               self.nsze,
@@ -90,9 +95,9 @@ class TestNVMeCreateMaxNS(TestNVMe):
             print("##### Attaching " + str(nsid))
             self.assertEqual(self.attach_ns(self.ctrl_id, nsid), 0)
             print("##### Running IOs in " + str(nsid))
-            self.run_ns_io(nsid, 0)
+            self.run_ns_io(nsid, 9, 1)
 
-        for nsid in range(1, self.max_ns):
+        for nsid in range(1, self.max_ns + 1):
             print("##### Detaching " + str(nsid))
             self.assertEqual(self.detach_ns(self.ctrl_id, nsid), 0)
             print("#### Deleting " + str(nsid))
index 235c855a8f24567756e753d54828d815d3d1f222..b248c688713a44be96c6f2c1db2d792386b9314a 100644 (file)
@@ -500,7 +500,7 @@ class TestNVMe(unittest.TestCase):
 
         return 0 if err_log_entry_count == entry_count else 1
 
-    def run_ns_io(self, nsid, lbads):
+    def run_ns_io(self, nsid, lbads, count=10):
         """ Wrapper to run ios on namespace under test.
             - Args:
                 - lbads : LBA Data size supported in power of 2 format.
@@ -510,14 +510,14 @@ class TestNVMe(unittest.TestCase):
         block_size = mmap.PAGESIZE if int(lbads) < 9 else 2 ** int(lbads)
         ns_path = self.ctrl + "n" + str(nsid)
         io_cmd = "dd if=" + ns_path + " of=/dev/null" + " bs=" + \
-                 str(block_size) + " count=10 > /dev/null 2>&1"
+                 str(block_size) + " count=" + str(count) + " > /dev/null 2>&1"
         print(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=10 > /dev/null 2>&1"
+                 str(block_size) + " count=" + str(count) + " > /dev/null 2>&1"
         print(io_cmd)
         run_io = subprocess.Popen(io_cmd, shell=True, stdout=subprocess.PIPE,
                                   encoding='utf-8')