From: Vincent Fu Date: Tue, 4 Feb 2025 19:52:28 +0000 (+0000) Subject: t/fiotestlib: improve JSON decoding X-Git-Tag: fio-3.40~47 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=8bff30f806fcfa2583e8677c4c5ca557e2453877;p=fio.git t/fiotestlib: improve JSON decoding Sometimes error/informational messages appear at the end of the JSON data. Try to parse as JSON only the text between the first { and the last }. Signed-off-by: Vincent Fu --- diff --git a/t/fiotestlib.py b/t/fiotestlib.py index 61adca14..916dc17f 100755 --- a/t/fiotestlib.py +++ b/t/fiotestlib.py @@ -260,12 +260,13 @@ class FioJobFileTest(FioExeTest): return # - # Sometimes fio informational messages are included at the top of the - # JSON output, especially under Windows. Try to decode output as JSON - # data, skipping everything until the first { + # Sometimes fio informational messages are included outside the JSON + # output, especially under Windows. Try to decode output as JSON data, + # skipping outside the first { and last } # lines = file_data.splitlines() - file_data = '\n'.join(lines[lines.index("{"):]) + last = len(lines) - lines[::-1].index("}") + file_data = '\n'.join(lines[lines.index("{"):last]) try: self.json_data = json.loads(file_data) except json.JSONDecodeError: @@ -320,12 +321,13 @@ class FioJobCmdTest(FioExeTest): file_data = file.read() # - # Sometimes fio informational messages are included at the top of the - # JSON output, especially under Windows. Try to decode output as JSON - # data, skipping everything until the first { + # Sometimes fio informational messages are included outside the JSON + # output, especially under Windows. Try to decode output as JSON data, + # skipping outside the first { and last } # lines = file_data.splitlines() - file_data = '\n'.join(lines[lines.index("{"):]) + last = len(lines) - lines[::-1].index("}") + file_data = '\n'.join(lines[lines.index("{"):last]) try: self.json_data = json.loads(file_data) except json.JSONDecodeError: