]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
tests: fix hex to base-10 conversion in id-ctrl output
authorDennis Maisenbacher <dennis.maisenbacher@wdc.com>
Fri, 14 Feb 2025 08:11:41 +0000 (08:11 +0000)
committerDaniel Wagner <wagi@monom.org>
Fri, 14 Feb 2025 17:08:49 +0000 (18:08 +0100)
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 <dennis.maisenbacher@wdc.com>
tests/nvme_compare_test.py
tests/nvme_smart_log_test.py
tests/nvme_test.py

index e6b2b75ab9904805fbb14f7a2a75ac54046231d5..f704d6c2a74a00a62442f0078515e4553282a872 100644 (file)
@@ -30,6 +30,7 @@ NVMe Compare Command Testcase:-
 
 """
 
+from nvme_test import to_decimal
 from nvme_test_io import TestNVMeIO
 
 
@@ -52,7 +53,7 @@ class TestNVMeCompareCmd(TestNVMeIO):
             - 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 """
index ebc076c10d6cb06ca5f28fd89262e10a47a90420..2bc81d849467d87e4bd126ea5e6e65b2642a1bbb 100644 (file)
@@ -27,7 +27,7 @@ NVMe Smart Log Verification Testcase:-
 
 """
 
-from nvme_test import TestNVMe
+from nvme_test import TestNVMe, to_decimal
 
 
 class TestNVMeSmartLogCmd(TestNVMe):
@@ -84,6 +84,6 @@ class TestNVMeSmartLogCmd(TestNVMe):
     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)
index 67d926fad2576081f492bfbc3e58fb6a255d43d8..80750f5772e294aca6fb4afc5362119a0205f90c 100644 (file)
@@ -36,6 +36,16 @@ import time
 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):
 
     """
@@ -246,7 +256,7 @@ class TestNVMe(unittest.TestCase):
             - 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
@@ -284,7 +294,7 @@ class TestNVMe(unittest.TestCase):
             - 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
@@ -313,7 +323,7 @@ class TestNVMe(unittest.TestCase):
             - 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.