[Piglit] [PATCH 4/4] framework: Error out if there is a space in a test name

Dylan Baker baker.dylan.c at gmail.com
Tue Apr 14 13:52:46 PDT 2015


Python's Popen class requires a list of command arguments to be passed
to it. The way it handles spaces is to escape them as literals. thus
['grep foo', 'f'] != ['grep', 'foo', 'f'] (the later will work as
expected, the later will have an error, since it's very unlikely that
you have a command 'grep foo' on your system).

This adds a check to the Test.command.setter function to error out if a
command is set with a space in an element.

This has been tested against all.py, cl.py, igt.py, xts.py, and
deqp_gles3.py, and all of them work correctly.

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

diff --git a/framework/test/base.py b/framework/test/base.py
index 8a4bf99..4981d3d 100644
--- a/framework/test/base.py
+++ b/framework/test/base.py
@@ -42,10 +42,16 @@ from framework.results import TestResult
 
 __all__ = [
     'Test',
+    'CommandSpaceException',
     'WindowResizeMixin',
 ]
 
 
+class CommandSpaceException(Exception):
+    """Exception raised if there is a space in a test command element."""
+    pass
+
+
 class ProcessTimeout(threading.Thread):
     """ Timeout class for test processes
 
@@ -123,9 +129,9 @@ class Test(object):
 
     def __init__(self, command, run_concurrent=False):
         assert isinstance(command, list), command
-
+        self._command = None
         self.run_concurrent = run_concurrent
-        self._command = copy.copy(command)
+        self.command = command
         self.env = {}
         self.result = TestResult({'result': 'fail'})
         self.cwd = None
@@ -178,6 +184,16 @@ class Test(object):
                     '--tool=memcheck'] + self._command
         return self._command
 
+    @command.setter
+    def command(self, commandlist):
+        """If there is a space in the command list raise an exception."""
+        for each in commandlist:
+            if ' ' in each:
+                raise CommandSpaceException(
+                    'In command {}, a space was found in element {}'.format(
+                        commandlist, each))
+        self._command = copy.copy(commandlist)
+
     @abc.abstractmethod
     def interpret_result(self):
         """ Convert the raw output of the test into a form piglit understands
-- 
2.3.5



More information about the Piglit mailing list