[Piglit] [PATCH 4/5] framework: Make JSON backend test ordering deterministic

Dylan Baker dylan at pnwbakers.com
Mon May 2 21:21:13 UTC 2016


This changes the JSON backend to write results in a deterministic order
in the JSON store (assuming that concurrency is not used, there's no
easy way to enforce this with concurrency), this will be the same order
that the tests are run in. In combination with the previous patch this
will result in tests being run and written in a set order.

It's worth noting that because the JUnit backend uses different data
structures (list like objects) instead of dict-like objects it has
always had this property.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/backends/json.py | 9 +++++----
 framework/results.py       | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/framework/backends/json.py b/framework/backends/json.py
index 2bcedab..7533f53 100644
--- a/framework/backends/json.py
+++ b/framework/backends/json.py
@@ -23,10 +23,11 @@
 from __future__ import (
     absolute_import, division, print_function, unicode_literals
 )
+import collections
 import os
-import sys
-import shutil
 import posixpath
+import shutil
+import sys
 
 try:
     import simplejson as json
@@ -131,7 +132,7 @@ class JSONBackend(FileBackend):
         """
         # Create a dictionary that is full of data to be written to a single
         # file
-        data = {}
+        data = collections.OrderedDict()
 
         # Load the metadata and put it into a dictionary
         with open(os.path.join(self._dest, 'metadata.json'), 'r') as f:
@@ -142,7 +143,7 @@ class JSONBackend(FileBackend):
             data.update(metadata)
 
         # Add the tests to the dictionary
-        data['tests'] = {}
+        data['tests'] = collections.OrderedDict()
 
         test_dir = os.path.join(self._dest, 'tests')
         for test in os.listdir(test_dir):
diff --git a/framework/results.py b/framework/results.py
index 3bc5363..469abeb 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -292,7 +292,7 @@ class TestrunResult(object):
         self.clinfo = None
         self.lspci = None
         self.time_elapsed = TimeAttribute()
-        self.tests = {}
+        self.tests = collections.OrderedDict()
         self.totals = collections.defaultdict(Totals)
 
     def get_result(self, key):
-- 
2.8.2



More information about the Piglit mailing list