Skip to content

Commit

Permalink
tests: fix hex to base-10 conversion in id-ctrl output
Browse files Browse the repository at this point in the history
When doing bit checks on id-ctrl output fields we need to convert the
field numbers to a base-10 integer. However, the json output mostly
returns already base-10 integers, so we now first check for the '0x'
prefix before falsely converting the desired value.

Signed-off-by: Dennis Maisenbacher <[email protected]>
  • Loading branch information
MaisenbacherD authored and igaw committed Feb 14, 2025
1 parent 2ed94bd commit d746cd9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/nvme_compare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"""

from nvme_test import to_decimal
from nvme_test_io import TestNVMeIO


Expand All @@ -52,7 +53,7 @@ def compare_cmd_supported(self):
- Returns:
- True if 'compare' is supported, otherwise False
"""
return int(self.get_id_ctrl_field_value("oncs"), 16) & (1 << 0)
return to_decimal(self.get_id_ctrl_field_value("oncs")) & (1 << 0)

def setUp(self):
""" Pre Section for TestNVMeCompareCmd """
Expand Down
4 changes: 2 additions & 2 deletions tests/nvme_smart_log_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"""

from nvme_test import TestNVMe
from nvme_test import TestNVMe, to_decimal


class TestNVMeSmartLogCmd(TestNVMe):
Expand Down Expand Up @@ -84,6 +84,6 @@ def get_smart_log_all_ns(self):
def test_smart_log(self):
""" Testcase main """
self.assertEqual(self.get_smart_log_ctrl(), 0)
smlp = int(self.get_id_ctrl_field_value("lpa"), 16)
smlp = to_decimal(self.get_id_ctrl_field_value("lpa"))
if smlp & 0x1:
self.assertEqual(self.get_smart_log_all_ns(), 0)
16 changes: 13 additions & 3 deletions tests/nvme_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
from nvme_test_logger import TestNVMeLogger


def to_decimal(value):
""" Wrapper for converting numbers to base 10 decimal
- Args:
- value: A number in any common base
- Returns:
- Decimal integer
"""
return int(str(value), 0)


class TestNVMe(unittest.TestCase):

"""
Expand Down Expand Up @@ -246,7 +256,7 @@ def get_lba_status_supported(self):
- Returns:
- True if 'Get LBA Status' command is supported, otherwise False
"""
return int(self.get_id_ctrl_field_value("oacs"), 16) & (1 << 9)
return to_decimal(self.get_id_ctrl_field_value("oacs")) & (1 << 9)

def get_lba_format_size(self):
""" Wrapper for extracting lba format size of the given flbas
Expand Down Expand Up @@ -284,7 +294,7 @@ def get_ncap(self):
- Returns:
- Total NVM capacity.
"""
return int(self.get_id_ctrl_field_value("tnvmcap"))
return to_decimal(self.get_id_ctrl_field_value("tnvmcap"))

def get_id_ctrl_field_value(self, field):
""" Wrapper for extracting id-ctrl field values
Expand Down Expand Up @@ -313,7 +323,7 @@ def get_ocfs(self):
- Returns:
- Optional Copy Formats Supported
"""
return int(self.get_id_ctrl_field_value("ocfs"), 16)
return to_decimal(self.get_id_ctrl_field_value("ocfs"))

def delete_all_ns(self):
""" Wrapper for deleting all the namespaces.
Expand Down

0 comments on commit d746cd9

Please sign in to comment.