Skip to content

Commit ab37b22

Browse files
committed
tests: use common exec_cmd helper
Replace the open coded version of exec_cmd with this helper. Signed-off-by: Daniel Wagner <[email protected]>
1 parent c0eb6e1 commit ab37b22

6 files changed

Lines changed: 8 additions & 48 deletions

tests/nvme_fw_log_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
1. Execute fw-log on a device.
2727
"""
2828

29-
import subprocess
30-
3129
from nvme_test import TestNVMe
3230

3331

@@ -58,11 +56,7 @@ def get_fw_log(self):
5856
- 0 on success, error code on failure.
5957
"""
6058
fw_log_cmd = f"{self.nvme_bin} fw-log {self.ctrl}"
61-
proc = subprocess.Popen(fw_log_cmd,
62-
shell=True,
63-
stdout=subprocess.PIPE,
64-
encoding='utf-8')
65-
return proc.wait()
59+
return self.exec_cmd(fw_log_cmd)
6660

6761
def test_fw_log(self):
6862
""" Testcase main """

tests/nvme_get_features_test.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,13 @@ def get_mandatory_features(self, feature_id):
8484
get_feat_cmd = f"{self.nvme_bin} get-feature {self.ctrl} " + \
8585
f"--feature-id={str(feature_id)} " + \
8686
f"--cdw11={str(vector)} --human-readable"
87-
proc = subprocess.Popen(get_feat_cmd,
88-
shell=True,
89-
stdout=subprocess.PIPE,
90-
encoding='utf-8')
91-
self.assertEqual(proc.wait(), 0)
87+
self.assertEqual(self.exec_cmd(get_feat_cmd), 0)
9288
else:
9389
get_feat_cmd = f"{self.nvme_bin} get-feature {self.ctrl} " + \
9490
f"--feature-id={str(feature_id)} --human-readable"
9591
if str(feature_id) == "0x05":
9692
get_feat_cmd += f" --namespace-id={self.default_nsid}"
97-
proc = subprocess.Popen(get_feat_cmd,
98-
shell=True,
99-
stdout=subprocess.PIPE,
100-
encoding='utf-8')
101-
self.assertEqual(proc.wait(), 0)
93+
self.assertEqual(self.exec_cmd(get_feat_cmd), 0)
10294

10395
def test_get_mandatory_features(self):
10496
""" Testcase main """

tests/nvme_get_lba_status_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
1. Execute get-lba-status on a device.
1313
"""
1414

15-
import subprocess
16-
1715
from nvme_test import TestNVMe
1816

1917

@@ -56,11 +54,7 @@ def get_lba_status(self):
5654
f"--max-dw={str(self.max_dw)} " + \
5755
f"--action={str(self.action)} " + \
5856
f"--range-len={str(self.range_len)}"
59-
proc = subprocess.Popen(get_lba_status_cmd,
60-
shell=True,
61-
stdout=subprocess.PIPE,
62-
encoding='utf-8')
63-
return proc.wait()
57+
return self.exec_cmd(get_lba_status_cmd)
6458

6559
def test_get_lba_status(self):
6660
""" Testcase main """

tests/nvme_id_ns_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
2. Execute id-ns on all namespaces
2828
"""
2929

30-
import subprocess
31-
3230
from nvme_test import TestNVMe
3331

3432

@@ -62,11 +60,7 @@ def get_id_ns(self, nsid):
6260
"""
6361
id_ns_cmd = f"{self.nvme_bin} id-ns {self.ctrl} " + \
6462
f"--namespace-id={str(nsid)}"
65-
proc = subprocess.Popen(id_ns_cmd,
66-
shell=True,
67-
stdout=subprocess.PIPE,
68-
encoding='utf-8')
69-
return proc.wait()
63+
return self.exec_cmd(id_ns_cmd)
7064

7165
def get_id_ns_all(self):
7266
"""

tests/nvme_lba_status_log_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
1. Execute lba-status-log on a device.
1313
"""
1414

15-
import subprocess
16-
1715
from nvme_test import TestNVMe
1816

1917

@@ -46,11 +44,7 @@ def get_lba_stat_log(self):
4644
- 0 on success, error code on failure.
4745
"""
4846
lba_stat_log_cmd = f"{self.nvme_bin} lba-status-log {self.ctrl}"
49-
proc = subprocess.Popen(lba_stat_log_cmd,
50-
shell=True,
51-
stdout=subprocess.PIPE,
52-
encoding='utf-8')
53-
return proc.wait()
47+
return self.exec_cmd(lba_stat_log_cmd)
5448

5549
def test_lba_stat_log(self):
5650
""" Testcase main """

tests/nvme_test.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,7 @@ def get_smart_log(self, nsid):
486486
"""
487487
smart_log_cmd = f"{self.nvme_bin} smart-log {self.ctrl} " + \
488488
f"--namespace-id={str(nsid)}"
489-
proc = subprocess.Popen(smart_log_cmd,
490-
shell=True,
491-
stdout=subprocess.PIPE,
492-
encoding='utf-8')
493-
err = proc.wait()
489+
err = self.exec_cmd(smart_log_cmd)
494490
self.assertEqual(err, 0, "ERROR : nvme smart log failed")
495491
return err
496492

@@ -506,11 +502,7 @@ def get_id_ctrl(self, vendor=False):
506502
else:
507503
id_ctrl_cmd = f"{self.nvme_bin} id-ctrl " +\
508504
f"--vendor-specific {self.ctrl}"
509-
proc = subprocess.Popen(id_ctrl_cmd,
510-
shell=True,
511-
stdout=subprocess.PIPE,
512-
encoding='utf-8')
513-
err = proc.wait()
505+
err = self.exec_cmd(id_ctrl_cmd)
514506
self.assertEqual(err, 0, "ERROR : nvme id controller failed")
515507
return err
516508

0 commit comments

Comments
 (0)