nvmetcli: Allow different devices for make test
PATCH 1/1 nvmetcli: Allow different devices for make test
The test_nvmet.py by default uses /dev/ram0 and /dev/ram1 for 2 of the unit tests. Add env. variable to allow user to specify different devices or files. Additionally, skip these unit tests that require devices/files if they are not present. Update README too.
$ sudo make test ......s...s. ---------------------------------------------------------------------- Ran 12 tests in 0.043s
OK (skipped=2)
Name Stmts Miss Cover
-----------------------------------------nvmet/__init__.py 1 0 100%
nvmet/nvme.py 517 237 54% nvmet/test_nvmet.py 276 63 77%
-----------------------------------------
TOTAL 794 300 62%
$ sudo NVMET_TEST_DEVICES="/dev/sdc,/dev/sdd" make test ............ ---------------------------------------------------------------------- Ran 12 tests in 0.124s
OK
Name Stmts Miss Cover
-----------------------------------------nvmet/__init__.py 1 0 100%
nvmet/nvme.py 517 100 81% nvmet/test_nvmet.py 276 4 99%
-----------------------------------------
TOTAL 794 104 87%
--- README | 5 ++++- nvmet/test_nvmet.py | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-)
README +4 -1
@@ -47,7 +47,10 @@ Testing ------- nvmetcli comes with a testsuite that tests itself and the kernel configfs interface for the NVMe target. To run it make sure you have nose2 and -the coverage plugin for it installed and simple run 'make test'. +the coverage plugin for it installed and simple run 'make test'. To run all +the tests you also need some test block devices or files. Default is to +use /dev/ram0 and /dev/ram1. You can override default with environmental +variable eg. NVMET_TEST_DEVICES="/dev/sdk,/dev/sdj" make test . Development -----------------
nvmet/test_nvmet.py +22 -4
@@ -1,9 +1,22 @@ +import os import random +import stat import string import unittest import nvmet.nvme as nvme +# Default test devices are ram disks, but allow user to specify different +# block devices or files. +NVMET_TEST_DEVICES = os.getenv("NVMET_TEST_DEVICES", + "/dev/ram0,/dev/ram1").split(',') + + +def test_devices_present(): + return len([x for x in NVMET_TEST_DEVICES + if os.path.exists(x) and + (stat.S_ISBLK(os.stat(x).st_mode) or os.path.isfile(x))]) >= 2 + class TestNvmet(unittest.TestCase): def test_subsystem(self):
@@ -101,6 +114,8 @@ class TestNvmet(unittest.TestCase): n.delete() self.assertEqual(len(list(s.namespaces)), 0) + @unittest.skipUnless(test_devices_present(), + "Devices %s not available or suitable" % ','.join(NVMET_TEST_DEVICES)) def test_namespace_attrs(self): root = nvme.Root() root.clear_existing()
@@ -116,7 +131,7 @@ class TestNvmet(unittest.TestCase): self.assertRaises(nvme.CFSError, n.set_enable, 1) # now set a path and enable - n.set_attr('device', 'path', '/dev/ram0') + n.set_attr('device', 'path', NVMET_TEST_DEVICES[0]) n.set_enable(1) self.assertTrue(n.get_enable())
@@ -125,7 +140,7 @@ class TestNvmet(unittest.TestCase): # test that we can't write to attrs while enabled self.assertRaises(nvme.CFSError, n.set_attr, 'device', 'path', - '/dev/ram1') + NVMET_TEST_DEVICES[1]) self.assertRaises(nvme.CFSError, n.set_attr, 'device', 'nguid', '15f7767b-50e7-4441-949c-75b99153dea7')
@@ -403,6 +418,9 @@ class TestNvmet(unittest.TestCase): self.assertRaises(nvme.CFSError, nvme.Port, portid=1 << 17, mode='create') + @unittest.skipUnless(test_devices_present(), + "Devices %s not available or suitable" % ','.join( + NVMET_TEST_DEVICES)) def test_save_restore(self): root = nvme.Root() root.clear_existing()
@@ -416,7 +434,7 @@ class TestNvmet(unittest.TestCase): s2.set_attr('attr', 'allow_any_host', 1) n = nvme.Namespace(s, nsid=42, mode='create') - n.set_attr('device', 'path', '/dev/ram0') + n.set_attr('device', 'path', NVMET_TEST_DEVICES[0]) n.set_enable(1) nguid = n.get_attr('device', 'nguid')
@@ -454,7 +472,7 @@ class TestNvmet(unittest.TestCase): # and check everything is still the same self.assertTrue(n.get_enable()) - self.assertEqual(n.get_attr('device', 'path'), '/dev/ram0') + self.assertEqual(n.get_attr('device', 'path'), NVMET_TEST_DEVICES[0]) self.assertEqual(n.get_attr('device', 'nguid'), nguid) self.assertEqual(p.get_attr('addr', 'trtype'), 'loop')
Signature · 7 lines
2.25.1 _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
AppliedThanks,
applied.
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme