[Piglit] [PATCH] core.py: Fix sporadic loss of tests in summary

Dylan Baker baker.dylan.c at gmail.com
Fri May 31 16:51:51 PDT 2013


The checking in TestrunResult to determine if a file was proper json or
not is very fragile: it assumes that the last line of the file will be
}. Sometimes this triggers and rebuilds a valid json file, dropping the
last test and resulting in python overhead.

This patch replaces that check with a try/except block. This block
attempts to load the json file with json.loads, and on failure attempts
to fix the json.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/core.py | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index 14a8161..2c06d5e 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -301,11 +301,6 @@ class TestrunResult:
         lines = file.readlines()
         file.seek(saved_position)
 
-        if lines[-1] == '}':
-            # JSON object was closed properly. No repair is
-            # necessary.
-            return file
-
         # JSON object was not closed properly.
         #
         # To repair the file, we execute these steps:
@@ -353,19 +348,30 @@ class TestrunResult:
         json.dump(raw_dict, file, indent=JSONWriter.INDENT)
 
     def parseFile(self, file):
-        file = self.__repairFile(file)
-        raw_dict = json.load(file)
-
-        # Check that only expected keys were unserialized.
-        for key in raw_dict:
-            if key not in self.serialized_keys:
-                raise Exception('unexpected key in results file: ' + str(key))
-
-        self.__dict__.update(raw_dict)
-
-        # Replace each raw dict in self.tests with a TestResult.
-        for (path, result) in self.tests.items():
-            self.tests[path] = TestResult(result)
+        # Attempt to open the json file raw, if it fails then attempt to repair
+        # it.
+        try:
+            results = json.loads(file)
+            self.name = results.name
+            self.glxinfo = results.glxinfo
+            self.lspci = results.lspci
+            self.time_elapsed = results.time_elapsed
+            self.tests = results.tests
+        except TypeError:
+            file = self.__repairFile(file)
+            raw_dict = json.load(file)
+
+            # Check that only expected keys were unserialized.
+            for key in raw_dict:
+                if key not in self.serialized_keys:
+                    raise Exception('unexpected key in results file: ',
+                                    str(key))
+
+            self.__dict__.update(raw_dict)
+
+            # Replace each raw dict in self.tests with a TestResult.
+            for (path, result) in self.tests.items():
+                self.tests[path] = TestResult(result)
 
 #############################################################################
 ##### Generic Test classes
-- 
1.8.1.4



More information about the Piglit mailing list