[Piglit] [PATCH 1/2] framework/summary.py: raise a FatalError for name collision

Dylan Baker baker.dylan.c at gmail.com
Tue Jun 9 16:43:02 PDT 2015


When two json results have the same "name" value in the root of the json
dictionary, piglit will try to create two directories with the same
name. In this event an OSError will be raised to the top level exception
handler, resulting in a bug warning.

This patch raises an expected error, giving the user advice on resolving
the issue.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/summary.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/framework/summary.py b/framework/summary.py
index 14eaf05..ecd59f1 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -31,13 +31,14 @@ import re
 import getpass
 import sys
 import posixpath
+import errno
 
 from mako.template import Template
 
 # a local variable status exists, prevent accidental overloading by renaming
 # the module
 import framework.status as so
-from framework import grouptools, backends
+from framework import grouptools, backends, exceptions
 
 __all__ = [
     'Summary',
@@ -475,7 +476,17 @@ class Summary:
         # Iterate across the tests creating the various test specific files
         for each in self.results:
             name = escape_pathname(each.name)
-            os.mkdir(path.join(destination, name))
+            try:
+                os.mkdir(path.join(destination, name))
+            except OSError as e:
+                if e.errno == errno.EEXIST:
+                    raise exceptions.PiglitFatalError(
+                        'Two or more of your results have the same "name" '
+                        'attribute. Try changing one or more of the "name" '
+                        'values in your json files.\n'
+                        'Duplicate value: {}'.format(name))
+                else:
+                    raise e
 
             if each.time_elapsed is not None:
                 time = datetime.timedelta(0, each.time_elapsed)
-- 
2.4.2



More information about the Piglit mailing list