t/fiotestlib: improve JSON decoding
authorVincent Fu <vincent.fu@samsung.com>
Tue, 14 Jan 2025 18:27:55 +0000 (18:27 +0000)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 23 Jan 2025 17:57:42 +0000 (12:57 -0500)
Instead of skipping up to a fixed number of lines when trying to decode
JSON output, just skip everything until the first opening {.

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
t/fiotestlib.py

index 466e482dcdea377d30c3a30bf1ace5fc9e63a155..61adca1492f201122402384ef65b3e1817098cd6 100755 (executable)
@@ -322,19 +322,16 @@ class FioJobCmdTest(FioExeTest):
         #
         # Sometimes fio informational messages are included at the top of the
         # JSON output, especially under Windows. Try to decode output as JSON
-        # data, lopping off up to the first four lines
+        # data, skipping everything until the first {
         #
         lines = file_data.splitlines()
-        for i in range(5):
-            file_data = '\n'.join(lines[i:])
-            try:
-                self.json_data = json.loads(file_data)
-            except json.JSONDecodeError:
-                continue
-            else:
-                return True
+        file_data = '\n'.join(lines[lines.index("{"):])
+        try:
+            self.json_data = json.loads(file_data)
+        except json.JSONDecodeError:
+            return False
 
-        return False
+        return True
 
     @staticmethod
     def check_empty(job):