[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH XTF v2 2/4] xtf: Add executable test class



The Executable test class runs on host (dom0). The class spawns a
process and searches the program output(stdio) for a specific pattern.

Signed-off-by: Petre Pircalabu <ppircalabu@xxxxxxxxxxxxxxx>
---
 xtf/__init__.py        |  2 +-
 xtf/executable_test.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++
 xtf/suite.py           |  5 ++-
 3 files changed, 88 insertions(+), 2 deletions(-)
 create mode 100644 xtf/executable_test.py

diff --git a/xtf/__init__.py b/xtf/__init__.py
index 889c1d5..07c269a 100644
--- a/xtf/__init__.py
+++ b/xtf/__init__.py
@@ -3,7 +3,7 @@
 
 # All test categories
 default_categories     = set(("functional", "xsa"))
-non_default_categories = set(("special", "utility", "in-development"))
+non_default_categories = set(("special", "utility", "in-development", "host"))
 all_categories         = default_categories | non_default_categories
 
 # All test environments
diff --git a/xtf/executable_test.py b/xtf/executable_test.py
new file mode 100644
index 0000000..31aa6e4
--- /dev/null
+++ b/xtf/executable_test.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Executable test classes
+
+Spawns a process and waits for a specific pattern
+"""
+
+import StringIO
+import pexpect
+
+from xtf.logger import Logger
+from xtf.test import TestInstance, TestInfo, TestResult
+
+class ExecutableTestInstance(TestInstance):
+    """Executable Test Instance"""
+    def __init__(self, name, cmd, args, pattern):
+        super(ExecutableTestInstance, self).__init__(name)
+
+        self._cmd = cmd
+        self._args = [x.encode('utf-8') for x in args]
+        self._pattern = [x.encode('utf-8') for x in pattern]
+        self._proc = None
+        self.env = "dom0"
+        self.output = StringIO.StringIO()
+
+    def __repr__(self):
+        return "test-%s-%s" %(self.env, self.name)
+
+    def wait_pattern(self, pattern):
+        """Expect the pattern given as parameter."""
+        return self._proc.expect(pattern + [pexpect.TIMEOUT, pexpect.EOF])
+
+    def set_up(self, opts, result):
+        self._proc = pexpect.spawn(self._cmd, self._args, logfile = 
self.output)
+        print self._cmd, self._args
+
+        if self._proc is None:
+            result.set(TestResult.ERROR)
+
+    def run(self, result):
+        """Executes the test instance"""
+        if self.wait_pattern(self._pattern) > len(self._pattern):
+            result.set(TestResult.FAILURE)
+            return
+
+        result.set(TestResult.SUCCESS)
+
+    def clean_up(self, result):
+        if self.output:
+            Logger().log(self.output.getvalue())
+            self.output.close()
+
+class ExecutableTestInfo(TestInfo):
+    """ Object representing a tests info.json, in a more convenient form. """
+
+    def __init__(self, test_json):
+        super(ExecutableTestInfo, self).__init__(test_json)
+        self.instance_class = ExecutableTestInstance
+
+        cmd = test_json["cmd"]
+        if not isinstance(cmd, (str, unicode)):
+            raise TypeError("Expected string for 'cmd', got '%s')"
+                            % (type(cmd), ))
+        self.cmd = cmd
+
+        args = test_json["args"]
+        if not isinstance(args, list):
+            raise TypeError("Expected list for 'args', got '%s')"
+                            % (type(args), ))
+        self.args = args
+
+        pattern = test_json["pattern"]
+        if not isinstance(pattern, list):
+            raise TypeError("Expected list for 'pattern', got '%s')"
+                            % (type(pattern), ))
+        self.pattern = pattern
+
+    def all_instances(self, env_filter = None, vary_filter = None):
+        """Returns an ExecutableTestInstance object"""
+        return [self.instance_class(self.name, self.cmd, self.args,
+                                    self.pattern),]
diff --git a/xtf/suite.py b/xtf/suite.py
index ad7d30f..2e0727c 100644
--- a/xtf/suite.py
+++ b/xtf/suite.py
@@ -75,7 +75,10 @@ def gather_all_test_info():
             try:
                 info_file = open(path.join("tests", test, "info.json"))
             except IOError:
-                continue
+                try:
+                    info_file = open(path.join("tests", test, "host.json"))
+                except IOError:
+                    continue
 
             # Ignore tests which have bad JSON
             try:
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.