summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <thibault.saunier@collabora.com>2012-06-18 09:56:48 -0400
committerThibault Saunier <thibault.saunier@collabora.com>2012-06-21 10:00:09 -0400
commit479d889f9f380a40338f247ef95370c1be813f14 (patch)
tree88b169519cdb922166dd4a9e01667d3c104476ac
parenta58032d40313e4f15f690c04e060ee33311c6778 (diff)
insanity: Make Monitor aware of start/stop iterations
-rw-r--r--insanity/monitor.py46
-rw-r--r--insanity/test.py22
2 files changed, 67 insertions, 1 deletions
diff --git a/insanity/monitor.py b/insanity/monitor.py
index 6911f14..29bd009 100644
--- a/insanity/monitor.py
+++ b/insanity/monitor.py
@@ -105,6 +105,8 @@ class Monitor(object):
self._checklist = {}
self._extraInfo = {}
self._outputfiles = {}
+ self._iteration = 0
+ self._iteration_outputfiles = {}
def setUp(self):
"""
@@ -117,6 +119,27 @@ class Monitor(object):
"""
return True
+ def start(self, iteration):
+ """
+ Prepare the monitor.
+
+ Returns True if everything went well, else False.
+
+ Sub-classes should call their parent-class start() before
+ their implementation.
+ """
+ self._iteration = iteration
+ return True
+
+ def stop(self):
+ """
+ Stop the monitor.
+
+ Sub-classes should call their parent-class stop() before
+ their implementation.
+ """
+ return True
+
def tearDown(self):
"""
Clean up the monitor.
@@ -161,6 +184,29 @@ class Monitor(object):
debug("%s : %r", key, value)
self._extraInfo[key] = value
+ def addIterationOutputFile(self, key, value):
+ """
+ Report the location of an output file for a specific iteration
+ """
+ debug("%s : %s", key, value)
+ try:
+ self._iteration_outputfiles[self._iteration][key] = value
+ except KeyError:
+ kv = {}
+ kv[key] = value
+ self._iteration_outputfiles[self._iteration] = kv
+
+ def getIterationOutputFiles(self, iteration):
+ """
+ Return a dictionnary containing the outputfiles in the form of
+ {outputfile-name: /path/to/file} for a specific iteration
+ """
+ try:
+ return self._iteration_outputfiles[iteration]
+ except KeyError:
+ debug("No outputfile for iteration %s", iteration)
+ return None
+
def setOutputFile(self, key, value):
"""
Report the location of an output file
diff --git a/insanity/test.py b/insanity/test.py
index 9c133a1..f110bad 100644
--- a/insanity/test.py
+++ b/insanity/test.py
@@ -427,12 +427,25 @@ class Test(gobject.GObject):
self._testtimeoutid = 0
notimeout = True
self.validateChecklistItem("no-timeout", notimeout)
+ self._stopMonitors()
self.emit("stop", self._iteration)
+
self.iteration_checklist[self._iteration] = self._checklist
self.iteration_extrainfo[self._iteration] = self._extrainfo
self.iteration_outputfiles[self._iteration] = self._outputfiles
self.iteration_success_percentage[self._iteration] = self.getSuccessPercentage()
+ def _stopMonitors(self):
+ for monitorinstance in self._monitorinstances:
+ if not monitorinstance.stop():
+ info("Could not stop monitor %s", monitorinstance)
+ continue
+
+ ofiles = monitorinstance.getIterationOutputFiles(self._iteration)
+ if ofiles:
+ self.iteration_outputfiles.update(ofiles)
+
+
def start(self):
"""
Starts the test.
@@ -446,6 +459,7 @@ class Test(gobject.GObject):
# Upon first start, we save checklist, etc so they can be copied
# as base for each successive iteration, while keeping the state
# acquired in setup
+ self._startMonitors()
if self._iteration == 1:
self._base_checklist = self._checklist[:]
self._base_extrainfo = self._extrainfo.copy()
@@ -466,7 +480,6 @@ class Test(gobject.GObject):
self._running = True
self.emit("start", self._iteration)
self.validateChecklistItem("test-started")
-
if self._iteration > 1:
iteraction_checklist = self.getIterationCheckList(self._iteration - 1, False)
for item, value in self.getFullCheckList().iteritems():
@@ -482,6 +495,13 @@ class Test(gobject.GObject):
self._testTimeoutCb)
self.test()
+ def _startMonitors(self):
+ for monitorinstance in self._monitorinstances:
+ if not monitorinstance.start(self._iteration):
+ info("Could not start monitor %s", monitorinstance)
+ return False
+ return True
+
def test(self):
"""
This method will be called at the beginning of the test