Skip to content

Commit ee45192

Browse files
committed
tests: Port to nose2 and unittest
The test are still using nose which has been superseeded by nose2. Update the tests to use the nose2 and unittest. To minimize errors in most of the porting is done using sed, e.g 's/TestNVMeIO.__init__(self)/super().setUp()/g'. While at it also update the build system and move the test files to the build dir. This avoids in tree exectution of the Python files which leaves the __pycache__ dir in the source tree. This also fixes the problem, that the config file is not found when 'meson test -C .build' is used. We have the prober dir structure for Python and nose2 to find all resources in the build root. Furthermore, when running the tests the output is captured in the nvmetests dir. This dir is also created under the build root dir. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 563d3a9 commit ee45192

25 files changed

+221
-250
lines changed

Diff for: tests/README

+8-8
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ nvmetests
6767
test_*.
6868
3. Based on the requirement one can inherit TestNVMe or TestNVMeIO
6969
class.
70-
4. Write test precondition code into __init__. Make sure you are calling
71-
super class __init__.
72-
5. Write test post condition code into __del__. Make sure you are calling
73-
super class __del__.
70+
4. Write test precondition code into setUp. Make sure you are calling
71+
super class setUp.
72+
5. Write test post condition code into tearDown. Make sure you are calling
73+
super class tearDown.
7474
6. Before writing a new function have a look into TestNVMe to see if it
7575
can be reused.
7676
7. Once testcase is ready make sure :-
@@ -83,9 +83,9 @@ nvmetests
8383

8484
4. Running testcases with framework
8585
-----------------------------------
86-
1. Running single testcase with nose2 :-
87-
$ nose2 --verbose nvme_writezeros_test
88-
$ nose2 --verbose nvme_read_write_test
86+
1. Running single testcase (in the source tree) with nose2 :-
87+
$ nose2 --verbose --start-dir tests nvme_writezeros_test
88+
$ nose2 --verbose --start-dir tests nvme_read_write_test
8989

90-
2. Running all the testcases with ninja :-
90+
2. Running all the testcases (in the build root directory) with ninja :-
9191
$ ninja test -C .build

Diff for: tests/meson.build

+37-26
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
11
# SPDX-License-Identifier: GPL-2.0-or-later
22

3+
infra = [
4+
'config.json',
5+
'nvme_test.py',
6+
'nvme_test_io.py',
7+
'nvme_test_logger.py',
8+
'nvme_simple_template_test.py',
9+
]
10+
311
tests = [
4-
'nvme_attach_detach_ns_test',
5-
'nvme_compare_test',
6-
'nvme_create_max_ns_test',
7-
'nvme_error_log_test',
8-
'nvme_flush_test',
9-
'nvme_format_test',
10-
'nvme_fw_log_test',
11-
'nvme_get_features_test',
12-
'nvme_id_ctrl_test',
13-
'nvme_id_ns_test',
14-
'nvme_read_write_test',
15-
'nvme_simple_template_test',
16-
'nvme_smart_log_test',
17-
'nvme_test_io',
18-
'nvme_test_logger',
19-
'nvme_test',
20-
'nvme_writeuncor_test',
21-
'nvme_writezeros_test',
22-
'nvme_copy_test',
23-
'nvme_dsm_test',
24-
'nvme_verify_test',
25-
'nvme_lba_status_log_test',
26-
'nvme_get_lba_status_test',
12+
'nvme_attach_detach_ns_test.py',
13+
'nvme_compare_test.py',
14+
'nvme_create_max_ns_test.py',
15+
'nvme_error_log_test.py',
16+
'nvme_flush_test.py',
17+
'nvme_format_test.py',
18+
'nvme_fw_log_test.py',
19+
'nvme_get_features_test.py',
20+
'nvme_id_ctrl_test.py',
21+
'nvme_id_ns_test.py',
22+
'nvme_read_write_test.py',
23+
'nvme_smart_log_test.py',
24+
'nvme_writeuncor_test.py',
25+
'nvme_writezeros_test.py',
26+
'nvme_copy_test.py',
27+
'nvme_dsm_test.py',
28+
'nvme_verify_test.py',
29+
'nvme_lba_status_log_test.py',
30+
'nvme_get_lba_status_test.py',
2731
]
2832

2933
runtests = find_program('nose2', required : false)
3034

3135
if runtests.found()
36+
foreach file : infra + tests
37+
configure_file(
38+
input: file,
39+
output: file,
40+
copy: true)
41+
endforeach
42+
3243
foreach t : tests
33-
test(t, runtests,
34-
args: ['--verbose', '--start-dir', meson.current_source_dir(), t],
35-
workdir: meson.current_source_dir(),
44+
t_name = t.split('.')[0]
45+
test(t_name, runtests,
46+
args: ['--verbose', '--start-dir', meson.build_root() + '/tests', t_name],
3647
env: ['PATH=' + meson.build_root() + ':/usr/bin:/usr/sbin'],
3748
timeout: 500)
3849
endforeach

Diff for: tests/nvme_attach_detach_ns_test.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import time
3333

34-
from nose.tools import assert_equal
3534
from nvme_test import TestNVMe
3635

3736

@@ -48,9 +47,9 @@ class TestNVMeAttachDetachNSCmd(TestNVMe):
4847
- ctrl_id : controller id.
4948
"""
5049

51-
def __init__(self):
50+
def setUp(self):
5251
""" Pre Section for TestNVMeAttachDetachNSCmd """
53-
TestNVMe.__init__(self)
52+
super().setUp()
5453
self.dps = 0
5554
self.flbas = 0
5655
self.nsze = 0x1400000
@@ -60,21 +59,21 @@ def __init__(self):
6059
self.delete_all_ns()
6160
time.sleep(1)
6261

63-
def __del__(self):
62+
def tearDown(self):
6463
"""
6564
Post Section for TestNVMeAttachDetachNSCmd
6665
6766
- Create primary namespace.
6867
- Atttach it to controller.
6968
- Call super class's destructor.
7069
"""
71-
assert_equal(self.create_and_validate_ns(self.default_nsid,
72-
self.nsze,
73-
self.ncap,
74-
self.flbas,
75-
self.dps), 0)
70+
self.assertEqual(self.create_and_validate_ns(self.default_nsid,
71+
self.nsze,
72+
self.ncap,
73+
self.flbas,
74+
self.dps), 0)
7675
self.attach_ns(self.ctrl_id, self.default_nsid)
77-
TestNVMe.__del__(self)
76+
super().tearDown()
7877

7978
def test_attach_detach_ns(self):
8079
""" Testcase main """
@@ -83,11 +82,11 @@ def test_attach_detach_ns(self):
8382
self.ncap,
8483
self.flbas,
8584
self.dps)
86-
assert_equal(err, 0)
87-
assert_equal(self.attach_ns(self.ctrl_id, self.default_nsid), 0)
85+
self.assertEqual(err, 0)
86+
self.assertEqual(self.attach_ns(self.ctrl_id, self.default_nsid), 0)
8887

8988
self.run_ns_io(self.default_nsid, 0)
9089

91-
assert_equal(self.detach_ns(self.ctrl_id, self.default_nsid), 0)
92-
assert_equal(self.delete_and_validate_ns(self.default_nsid), 0)
90+
self.assertEqual(self.detach_ns(self.ctrl_id, self.default_nsid), 0)
91+
self.assertEqual(self.delete_and_validate_ns(self.default_nsid), 0)
9392
self.nvme_reset_ctrl()

Diff for: tests/nvme_compare_test.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
3131
"""
3232

33-
from nose.tools import assert_equal, assert_not_equal
3433
from nvme_test_io import TestNVMeIO
3534

3635

@@ -46,9 +45,9 @@ class TestNVMeCompareCmd(TestNVMeIO):
4645
- test_log_dir : directory for logs, temp files.
4746
"""
4847

49-
def __init__(self):
48+
def setUp(self):
5049
""" Pre Section for TestNVMeCompareCmd """
51-
TestNVMeIO.__init__(self)
50+
super().setUp()
5251
self.data_size = 1024
5352
self.start_block = 1023
5453
self.setup_log_dir(self.__class__.__name__)
@@ -57,9 +56,9 @@ def __init__(self):
5756
self.create_data_file(self.write_file, self.data_size, "15")
5857
self.create_data_file(self.compare_file, self.data_size, "25")
5958

60-
def __del__(self):
59+
def tearDown(self):
6160
""" Post Section for TestNVMeCompareCmd """
62-
TestNVMeIO.__del__(self)
61+
super().tearDown()
6362

6463
def nvme_compare(self, cmp_file):
6564
""" Wrapper for nvme compare command.
@@ -76,6 +75,6 @@ def nvme_compare(self, cmp_file):
7675

7776
def test_nvme_compare(self):
7877
""" Testcase main """
79-
assert_equal(self.nvme_write(), 0)
80-
assert_not_equal(self.nvme_compare(self.compare_file), 0)
81-
assert_equal(self.nvme_compare(self.write_file), 0)
78+
self.assertEqual(self.nvme_write(), 0)
79+
self.assertNotEqual(self.nvme_compare(self.compare_file), 0)
80+
self.assertEqual(self.nvme_compare(self.write_file), 0)

Diff for: tests/nvme_copy_test.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
1414
"""
1515

16-
from nose.tools import assert_equal
1716
from nvme_test import TestNVMe
1817

1918

@@ -28,18 +27,18 @@ class TestNVMeCopy(TestNVMe):
2827
- test_log_dir : directory for logs, temp files.
2928
"""
3029

31-
def __init__(self):
30+
def setUp(self):
3231
""" Pre Section for TestNVMeCopy """
33-
TestNVMe.__init__(self)
32+
super().setUp()
3433
self.start_block = 0
3534
self.range = 1
3635
self.slbs = 1
3736
self.namespace = 1
3837
self.setup_log_dir(self.__class__.__name__)
3938

40-
def __del__(self):
39+
def tearDown(self):
4140
""" Post Section for TestNVMeCopy """
42-
TestNVMe.__del__(self)
41+
super().tearDown()
4342

4443
def copy(self):
4544
""" Wrapper for nvme copy
@@ -57,4 +56,4 @@ def copy(self):
5756

5857
def test_copy(self):
5958
""" Testcase main """
60-
assert_equal(self.copy(), 0)
59+
self.assertEqual(self.copy(), 0)

Diff for: tests/nvme_create_max_ns_test.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import time
3333

34-
from nose.tools import assert_equal
3534
from nvme_test import TestNVMe
3635

3736

@@ -48,9 +47,9 @@ class TestNVMeCreateMaxNS(TestNVMe):
4847
- ctrl_id : controller id.
4948
"""
5049

51-
def __init__(self):
50+
def setUp(self):
5251
""" Pre Section for TestNVMeAttachDetachNSCmd """
53-
TestNVMe.__init__(self)
52+
super().setUp()
5453
self.dps = 0
5554
self.flbas = 0
5655
self.nsze = int(self.get_ncap() /
@@ -62,21 +61,21 @@ def __init__(self):
6261
self.delete_all_ns()
6362
time.sleep(1)
6463

65-
def __del__(self):
64+
def tearDown(self):
6665
"""
6766
Post Section for TestNVMeAttachDetachNSCmd
6867
6968
- Create primary namespace.
7069
- Atttach it to controller.
7170
- Call super class's destructor.
7271
"""
73-
assert_equal(self.create_and_validate_ns(self.default_nsid,
74-
self.nsze,
75-
self.ncap,
76-
self.flbas,
77-
self.dps), 0)
72+
self.assertEqual(self.create_and_validate_ns(self.default_nsid,
73+
self.nsze,
74+
self.ncap,
75+
self.flbas,
76+
self.dps), 0)
7877
self.attach_ns(self.ctrl_id, self.default_nsid)
79-
TestNVMe.__del__(self)
78+
super.tearDown()
8079

8180
def test_attach_detach_ns(self):
8281
""" Testcase main """
@@ -87,15 +86,15 @@ def test_attach_detach_ns(self):
8786
self.ncap,
8887
self.flbas,
8988
self.dps)
90-
assert_equal(err, 0)
89+
self.assertEqual(err, 0)
9190
print("##### Attaching " + str(nsid))
92-
assert_equal(self.attach_ns(self.ctrl_id, nsid), 0)
91+
self.assertEqual(self.attach_ns(self.ctrl_id, nsid), 0)
9392
print("##### Running IOs in " + str(nsid))
9493
self.run_ns_io(nsid, 0)
9594

9695
for nsid in range(1, self.max_ns):
9796
print("##### Detaching " + str(nsid))
98-
assert_equal(self.detach_ns(self.ctrl_id, nsid), 0)
97+
self.assertEqual(self.detach_ns(self.ctrl_id, nsid), 0)
9998
print("#### Deleting " + str(nsid))
100-
assert_equal(self.delete_and_validate_ns(nsid), 0)
99+
self.assertEqual(self.delete_and_validate_ns(nsid), 0)
101100
self.nvme_reset_ctrl()

Diff for: tests/nvme_dsm_test.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
1414
"""
1515

16-
from nose.tools import assert_equal
1716
from nvme_test import TestNVMe
1817

1918

@@ -27,17 +26,17 @@ class TestNVMeDsm(TestNVMe):
2726
- test_log_dir : directory for logs, temp files.
2827
"""
2928

30-
def __init__(self):
29+
def setUp(self):
3130
""" Pre Section for TestNVMeDsm """
32-
TestNVMe.__init__(self)
31+
super().setUp()
3332
self.start_block = 0
3433
self.range = 0
3534
self.namespace = 1
3635
self.setup_log_dir(self.__class__.__name__)
3736

38-
def __del__(self):
37+
def tearDown(self):
3938
""" Post Section for TestNVMeDsm """
40-
TestNVMe.__del__(self)
39+
super().tearDown()
4140

4241
def dsm(self):
4342
""" Wrapper for nvme verify
@@ -54,4 +53,4 @@ def dsm(self):
5453

5554
def test_dsm(self):
5655
""" Testcase main """
57-
assert_equal(self.dsm(), 0)
56+
self.assertEqual(self.dsm(), 0)

Diff for: tests/nvme_error_log_test.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
2727
"""
2828

29-
from nose.tools import assert_equal
3029
from nvme_test import TestNVMe
3130

3231

@@ -38,18 +37,18 @@ class TestNVMeErrorLogCmd(TestNVMe):
3837
- Attributes:
3938
"""
4039

41-
def __init__(self):
40+
def setUp(self):
4241
""" Pre Section for TestNVMeErrorLogCmd """
43-
TestNVMe.__init__(self)
42+
super().setUp()
4443
self.setup_log_dir(self.__class__.__name__)
4544

46-
def __del__(self):
45+
def tearDown(self):
4746
"""
4847
Post Section for TestNVMeErrorLogCmd
4948
5049
- Call super class's destructor.
5150
"""
52-
TestNVMe.__del__(self)
51+
super().tearDown()
5352

5453
def get_error_log_ctrl(self):
5554
""" Wrapper for executing error-log on controller.
@@ -62,4 +61,4 @@ def get_error_log_ctrl(self):
6261

6362
def test_get_error_log(self):
6463
""" Testcase main """
65-
assert_equal(self.get_error_log_ctrl(), 0)
64+
self.assertEqual(self.get_error_log_ctrl(), 0)

0 commit comments

Comments
 (0)