TestCenter Reference
Slave.py
Go to the documentation of this file.
1 
2 # Already ported to Python 3
3 # **InsertLicense** code author="Gereon A. Frey"
4 
6 
7 # -- system imports ----------------------------------------------------------------------------{{{-
8 import os
9 import re
10 import traceback
11 
12 import sys
13 if sys.version_info.major >= 3:
14  unicode = str
15 
16 import xml.etree.cElementTree as etree
17 # ----------------------------------------------------------------------------------------------}}}-
18 
19 # -- local imports -----------------------------------------------------------------------------{{{-
20 import mevis
21 import PackageSorter
22 
23 from . import IPC
24 from . import Config
25 from . import Utils
26 from .LogHandler import LogHandler
27 from TestSupport.TestHelper import TestHelper
28 
29 from .TestCaseGeneric import GenericTestCase
30 from .TestCaseFunctional import FunctionalTestCase
31 import TestSupport
32 
33 from . import CodeCoverage
34 from .CodeTestSupport import getCodeTest, getCodeTestsByPackage, CodeTestTestCase
35 
36 # ----------------------------------------------------------------------------------------------}}}-
38 
39  def __init__(self, com):
40  self.stopped = False
41  self.__com = com
42 
43  def startTestCaseFunction(self, testType, testCase, testFunction):
44  resultNode = etree.Element("Progress")
45  resultNode.set("testType", testType)
46  resultNode.set("testCase", testCase)
47  resultNode.set("testFunction", testFunction)
48  if not self.__com.send(etree.tostring(resultNode), 5):
49  mevis.MLAB.logError("Couldn't send progress")
51  # receive the result, if it is "0", we are supposed to stop,
52  # otherwise we can continue
53  result = self.__com.recv(5)
54  if result=="0":
56 
57  def endTestCaseFunction(self, status, duration):
58  resultNode = etree.Element("Status")
59  resultNode.set("status", str(status))
60  if not self.__com.send(etree.tostring(resultNode), 5):
61  mevis.MLAB.logError("Couldn't send status")
63 
64 # -- class Slave -------------------------------------------------------------------------------{{{-
65 
67 class Slave (object):
68  # -- member variables ------------------------------------------------------------------------{{{-
69 
70  __ctx = None
71 
72  __com = None
73 
74 
75  __testCase = None
76 
77 
78  __running = None
79 
80 
81  __testCfg = None
82  # --------------------------------------------------------------------------------------------}}}-
83 
84  # -- def __init__ ----------------------------------------------------------------------------{{{-
85 
91  def __init__ (self, cfgFile, context, offline=False):
92  self.__ctx = context
93  self.__com = IPC.ComSlave() if not offline else None
94 
95  self.__testCaseListener = None
96  self.__agendaTestCase = None
97  self.__isInsideTestCaseManager = False
98 
99  # The current configuration
100  self._config = Config.Configuration(cfgFile)
101 
102  # Create result directory if not available.
103  resultDir = self._config.getResultDir()
104  if not os.path.isdir(resultDir):
105  os.makedirs(resultDir)
106 
107  # Set new logfile to use. This is required as there could be multiple
108  # MeVisLab instances writing to the same logfile what would make crash
109  # handling impossible.
110  self.__logfile = self._config.getSlaveLogFilePath()
111 
112  # Load test cases if not done already.
113  if not mevis.MLABTestCaseDatabase.areTestCasesLoaded():
114  mevis.MLABTestCaseDatabase.loadTestCases()
115 
116  # Initialize the test helper singleton.
117  TestHelper.getInstance(context=self.__ctx, resultDir=self._config.getResultDir())
118  # --------------------------------------------------------------------------------------------}}}-
119 
120  def setIsInsideTestCaseManager(self, isInsideTestCaseManager):
121  self.__isInsideTestCaseManager = isInsideTestCaseManager
122 
123  def setTestCaseListener(self, listener):
124  self.__testCaseListener = listener
125 
126  # -- def loadTestCase ------------------------------------------------------------------------{{{-
127 
132  def loadTestCase (self, testCaseNode):
133  testType = testCaseNode.get('type')
134  moduleName = testCaseNode.get('module') if testType == "GenericTestCase" else None
135  return self.__loadTestCase(testCaseNode.get('name'), testType, moduleName)
136  # --------------------------------------------------------------------------------------------}}}-
137 
138  # -- def __loadTestCase ----------------------------------------------------------------------{{{-
139 
145  def __loadTestCase (self, testCaseName, testCaseType, moduleName=None):
146  # Create test case depending on the type.
147  if testCaseType == 'GenericTestCase':
148  testCase = GenericTestCase(testCaseName, moduleName)
149  elif testCaseType == 'FunctionalTestCase':
150  testCase = FunctionalTestCase(testCaseName)
151  elif testCaseType == 'CodeTestTestCase':
152  testCase = CodeTestTestCase(testCaseName)
153  else:
154  raise Exception('Unsupported test case type %s' % testCaseType)
155  return testCase
156  # --------------------------------------------------------------------------------------------}}}-
157 
158  # -- def setAgendaTestCase -------------------------------------------------------------------------{{{-
159 
162  def setAgendaTestCase (self, testCase):
163  self.__agendaTestCase = testCase
164  # --------------------------------------------------------------------------------------------}}}-
165 
166  # -- def getTestCase -------------------------------------------------------------------------{{{-
167 
170  def getTestCase ( self ):
171  return self.__testCase
172  # --------------------------------------------------------------------------------------------}}}-
173 
174  # -- def unloadTestCase -------------------------------------------------------------------------{{{-
175 
176  def unloadTestCase ( self ):
177  self.__testCase = None
178  # --------------------------------------------------------------------------------------------}}}-
179 
180  # -- def __doTest ----------------------------------------------------------------------------{{{-
181 
185 
186  def __doTest (self,
187  testCaseNode,
188  resultNode):
189 
190  try:
191  maxErrorMessagesPerTestFunction = int(testCaseNode.get("maxErrorMessagesPerTestFunction"))
192  except:
193  maxErrorMessagesPerTestFunction = 10000
194  try:
195  maxInfoMessagesPerTestFunction = int(testCaseNode.get("maxInfoMessagesPerTestFunction"))
196  except:
197  maxInfoMessagesPerTestFunction = 10000
198 
199  # clear encoding cache for each test to prevent it from containing outdated encoding data
201 
202  #start coverage right in front of loading, since some code parts are only
203  #traversed during the loading phase of a test case. Those
204  #are mainly function definitions etc.
205  try:
206  pythonCoverage = CodeCoverage.PythonCoverage(config=self._config,
207  testCaseNode=testCaseNode)
208  except CodeCoverage.CoverageException as e:
209  pythonCoverage = None
210  mevis.MLAB.logError(e)
211 
212  try:
213  bullseyeCoverage = CodeCoverage.BullseyeCoverage(config=self._config,
214  testCaseNode=testCaseNode)
215  except CodeCoverage.CoverageException as e:
216  bullseyeCoverage = None
217  mevis.MLAB.logError(e)
218 
219  self.__testCase = self.loadTestCase(testCaseNode)
220 
221  # Run the test case only if it loaded correctly.
222  if self.__testCase:
223  # Do NOT run test, when status is TEST_STATUS_DO_NOT_TEST_MODULE. Only relevant for GenericTests
224  if not testCaseNode.get("status") == Utils.TEST_STATUS_DO_NOT_TEST_MODULE:
225  if pythonCoverage and pythonCoverage.isRunning():
226  #store the target file in a subNode so the HTML creation process knows there
227  #were coverage results for this test.
228  resultNode.set('pythonCoverage', pythonCoverage.getCoverageBinaryFilePath())
229 
230  if bullseyeCoverage and bullseyeCoverage.isRunning():
231  #store the target file in a subNode so the HTML creation process knows there
232  #were coverage results for this test.
233  resultNode.set('bullseyeCoverage', bullseyeCoverage.getCoverageBinaryFilePath())
234 
235  logHandler = LogHandler(self.__logfile)
236  logHandler.setErrorLimit(maxErrorMessagesPerTestFunction)
237  logHandler.setInfoLimit(maxInfoMessagesPerTestFunction)
238  TestHelper.getInstance().setLogHandler(logHandler)
239 
240  mevis.MLAB.priv().connect("loggingMessage(const QString&)", logHandler.appendMessage)
241  mevis.MLAB.priv().aboutToLogMessage.connect(logHandler.aboutToLogMessage)
242  mevis.MLAB.priv().startLogCollect()
244  self.__testCase.run(testCaseNode)
245 
246  mevis.MLAB.priv().stopLogCollect()
247  mevis.MLAB.priv().disconnect("loggingMessage(const QString&)", logHandler.appendMessage)
248  mevis.MLAB.priv().aboutToLogMessage.disconnect(logHandler.aboutToLogMessage)
249 
250  TestHelper.getInstance().unsetLogHandler()
251  logHandler.close()
252 
253  resultNode.set('errorCode', 'Ok')
254  # Append results to the resultNode.
255  resultNode.append(testCaseNode)
256  else:
257  resultNode.set('errorCode', 'TestCaseError')
258  etree.SubElement(resultNode, 'Error').text = "Unknown test case (%s)." % (testCaseNode.get('name'))
259 
260  if pythonCoverage:
261  pythonCoverage.stop()
262 
263  if bullseyeCoverage:
264  try:
265  bullseyeCoverage.stop()
266  except CodeCoverage.CoverageException as e:
267  mevis.MLAB.logError(e)
268 
269  # --------------------------------------------------------------------------------------------}}}-
270 
271  # -- def __buildTestAgenda -------------------------------------------------------------------{{{-
272 
277  def __buildTestAgenda (self, testCfg, resultNode):
278 
279  def ___addPackageInfoNode( rootNode ):
280  packageInfoNode = etree.SubElement( rootNode, 'PackageSortingInReport')
281  packageInfoNode.set( 'PackagesByNumberOfDependencies', ",".join( PackageSorter.byNumberOfDependencies.packages ) )
282  packageInfoNode.set( 'PackageGroupsByNumberOfDependencies', ",".join( PackageSorter.byNumberOfDependencies.packageGroups ) )
283 
284  testRunNode = etree.Element('TestRun')
285 
286  # An internal data structure with easier access than the XML structure.
287  self.__testCfg = { 'Packages': { 'Tested': [], 'Available': [] },
288  'TestGroups': [],
289  'TestSuites': [],
290  'Modules': [] }
291 
292  # Consolidate the information on the packages available.
293  self.__verifyPackages(testCfg)
294 
295  # Get information on the test groups selected.
296  for testGroupNode in testCfg.findall('TestGroups/TestGroup'):
297  self.__testCfg['TestGroups'].append(testGroupNode.get('name'))
298 
299  # Add the test cases from given test suites to the TestCases node
300  for testSuiteNode in testCfg.findall('TestSuites/TestSuite'):
301  testSuite = testSuiteNode.get('name')
302  testCaseNames = mevis.MLABTestCaseDatabase.allTestCaseSuites().get(testSuite, {}).get("testCases", [])
303  testCasesNode = testCfg.find('TestCases')
304  for name in testCaseNames:
305  etree.SubElement(testCasesNode, 'TestCase', {'name': name})
306 
307  # Set system information.
308  testRunNode.set('platform', mevis.MLAB.systemId())
309  testRunNode.set('compiler', mevis.MLAB.compilerInfo())
310  # Set build information.
311  testRunNode.set('builddate', mevis.MLAB.dateOfBuildJob().date().toString("yyyy-MM-dd"))
312  testRunNode.set('version', mevis.MLAB.priv().variable('Version', False))
313 
314  # Create nodes to store information on the test run.
315  infoNode = etree.SubElement(testRunNode, 'Information')
316  testResultNode = etree.SubElement(testRunNode, 'Results')
317  etree.SubElement(infoNode, 'TestCases')
318  etree.SubElement(infoNode, 'Modules')
319  ___addPackageInfoNode( infoNode )
320 
321  # Consolidate the information on the test cases that should be executed.
322  self.__verifyTestCaseList(testCfg, testRunNode)
323 
324  # If no generic test cases are used then don't build information list for
325  # modules (this causes major performance on windows machines when storing
326  # the resulting xml).
327  for testCaseNode in infoNode.findall("./TestCases/TestCase"):
328  if testCaseNode.get("type") == "GenericTestCase":
329  # extend the XML structure and hook in all modules to test
330  self.__collectModulesToTest(testCfg)
331  self.__buildModuleInfo(infoNode.find("Modules"))
332  break
333 
334  resultNode.set('errorCode', 'Ok')
335  resultNode.append(testRunNode)
336  resultNode.append(testCfg)
337 
338  self.__testCfg = None
339  # --------------------------------------------------------------------------------------------}}}-
340 
341  # -- def __buildTestCaseAgenda ---------------------------------------------------------------{{{-
342  def __buildTestCaseAgenda(self, requestNode, resultNode):
343  try:
344  parameterNode = requestNode.find('Parameters')
345  packagesToTest = parameterNode.get('packages', '').split(',')
346  modulesToTest = parameterNode.get('modules', '').split(',')
347  testCaseName = parameterNode.find('TestCase').get('name')
348  testResultsNode = etree.SubElement(resultNode, 'Results')
349  testCaseAgenda, status = self.__loadAndVerifyTestCase(testCaseName, testResultsNode, packagesToTest, modulesToTest)
350  testCase = testResultsNode.find('TestCase')
351  # Remove TestFunctions for GenericTests with status TEST_STATUS_DO_NOT_TEST_MODULE.
352  if testCase is not None and testCase.get('status',"") == str(Utils.TEST_STATUS_DO_NOT_TEST_MODULE):
353  functionListNode = testCaseAgenda.find('TestFunctions')
354  functionNodes = functionListNode.findall('Function')
355  for functionNode in functionNodes:
356  functionListNode.remove(functionNode)
357  assert(testCaseAgenda)
358  resultNode.append(testCaseAgenda)
359  if status != 'Ok':
360  etree.SubElement(resultNode, 'Error').text = 'Failed to load the test case'
361  resultNode.set('errorCode', status)
362  except:
363  resultNode.set('errorCode', 'Failed')
364  etree.SubElement(resultNode, 'Error').text = traceback.format_exc()
365  # --------------------------------------------------------------------------------------------}}}-
366 
367  # -- def __verifyTestCaseList ----------------------------------------------------------------{{{-
368 
372  def __verifyTestCaseList (self, testCfg, testRunNode):
373  # Get list of all available test cases.
374  availTestCaseList = []
375  for package in self.__testCfg['Packages']['Tested']:
376  availTestCaseList.extend(mevis.MLABTestCaseDatabase.allTestCasesForPackage(package))
378  availTestCaseList.extend(getCodeTestsByPackage().get(package,{}).keys())
379 
380  # If no test cases were given use list of available ones.
381  testCaseListNode = testCfg.find('TestCases')
382  if len(testCaseListNode.findall('TestCase')) == 0:
383  for testCaseName in availTestCaseList:
384  etree.SubElement(testCaseListNode, 'TestCase', name=testCaseName)
385 
386  # Get the node to append information to.
387  testInfoNode = testRunNode.find('Information/TestCases')
388 
389  for testCaseNode in testCfg.findall('TestCases/TestCase'):
390  testCaseName = testCaseNode.get('name')
391  if testCaseName in availTestCaseList:
392  infoDict = self.__getTestCaseInfo(testCaseName)
393  # Verify test groups if necessary.
394  if not self.__verifyTestGroups(infoDict, self.__testCfg['TestGroups']):
395  mevis.MLAB.logError("TestCase %s not in tested groups (%s)." % (testCaseName, ", ".join(self.__testCfg['TestGroups'])))
396  testCaseNode.set('isNotInTestGroups', str(True))
397  else:
398  testCaseNode.set('type', infoDict['type'])
399  testInfoNode.append(testCaseNode)
400  testCaseNode.set('status', str(Utils.TEST_STATUS_OK))
401  else:
402  mevis.MLAB.logError("test case not found %s %s" %( testCaseName, availTestCaseList))
403  testCaseNode.set('status', str(Utils.TEST_STATUS_ERROR))
404  # --------------------------------------------------------------------------------------------}}}-
405 
406  # -- def __verifyTestCase --------------------------------------------------------------------{{{-
407 
408  def __loadAndVerifyTestCase(self, testCaseName, testResultNode, packagesToTest, modulesToTest):
409  resolvedPackagesToTest = []
410  for package in packagesToTest:
411  pGroup, pName = package.split('/')
412  if pGroup == "*" and pName == "*":
413  for package in mevis.MLABPackageManager.packages():
414  resolvedPackagesToTest.append(package.packageIdentifier())
415  elif pName == "*":
416  for package in mevis.MLABPackageManager.packages():
417  if package.packageGroup() == pGroup:
418  resolvedPackagesToTest.append(package.packageIdentifier())
419  else:
420  resolvedPackagesToTest.append(package)
421  testCaseNode, status = self.__verifyTestCase(testCaseName, testResultNode, resolvedPackagesToTest, modulesToTest)
422  return testCaseNode, status
423  # --------------------------------------------------------------------------------------------}}}-
424 
425  def __getTestCaseInfo(self, testCaseName):
426  infoDict = mevis.MLABTestCaseDatabase.testCaseInfo(testCaseName)
427  if not infoDict:
428  codeTest = getCodeTest(testCaseName)
429  if codeTest != None:
430  infoDict = codeTest.getInfoDict()
431  return infoDict
432 
433  # -- def __verifyTestCase --------------------------------------------------------------------{{{-
434 
438  def __verifyTestCase (self, testCaseName, testResultNode, packagesToTest, modulesToTest):
439  infoDict = self.__getTestCaseInfo(testCaseName)
440 
441  # Try to load the test case.
442  testType = infoDict['type']
443 
444  # if agenda test case is set from outside, use it
445  testCase = self.__agendaTestCase
446  if not testCase:
447  mevis.MLAB.log("Trying to load test case %s" % testCaseName)
448  # no test case set, try loading it instead
449  testCase = self.__loadTestCase(testCaseName, testType)
450  mevis.MLAB.log("Loading complete")
451 
452  if testCase == None:
453  return None, 'Failed'
454 
455  # Add basic information for the actual testing.
456  if testType == 'GenericTestCase':
457  modulesToTest, modulesNotToTest = testCase.getModulesToTest(modulesToTest, packagesToTest)
458  for moduleName in modulesToTest:
459  etree.SubElement(testResultNode, "TestCase", name=testCaseName, type=testType, module=moduleName)
460  for moduleName in modulesNotToTest:
461  etree.SubElement(testResultNode, "TestCase", name=testCaseName, type=testType, module=moduleName, status=str(Utils.TEST_STATUS_DO_NOT_TEST_MODULE))
462  else:
463  etree.SubElement(testResultNode, 'TestCase', name=testCaseName, type=testType)
464 
465  return testCase.getTestCaseNode(), 'Ok'
466  # --------------------------------------------------------------------------------------------}}}-
467 
468  # -- def __verifyTestGroups ------------------------------------------------------------------{{{-
469 
475  def __verifyTestGroups (self, infoDict, testGroupList):
476  testCaseGroupList = infoDict['testGroups'] if 'testGroups' in infoDict else []
477 
478  if testGroupList:
479  if 'automatic' in testGroupList:
480  if 'manual' in testCaseGroupList:
481  return False
482  return True
483  for testGroup in testGroupList:
484  if testGroup in testCaseGroupList:
485  return True
486  return False
487  return True
488  # --------------------------------------------------------------------------------------------}}}-
489 
490  # -- def __verifyPackages --------------------------------------------------------------------{{{-
491 
497  def __verifyPackages (self, testCfg):
498  packageRoot = testCfg.find('Packages')
499 
500  # First go over list and substitute wildcards and verify all given
501  # packages.
502  tPkgNode = packageRoot.find('Tested')
503  aPkgNode = packageRoot.find('Available')
504  iPkgNode = packageRoot.find('Ignored')
505  # if no ignored package is given,
506  # then self.__verifyPackageListNode() would ignore all packages
507  if iPkgNode.getchildren():
508  self.__verifyPackageListNode(iPkgNode)
509  ignoredPackageIDs = set()
510  for ignoredPackage in iPkgNode.getchildren():
511  ignoredPackageIDs.add(ignoredPackage.get('name'))
512 
513  self.__verifyPackageListNode(tPkgNode, ignoredPackageIDs)
514  self.__verifyPackageListNode(aPkgNode, ignoredPackageIDs)
515  # Get list of verified packages.
516  tPkgSet = set()
517  for packageNode in tPkgNode.findall('Package'):
518  if packageNode.get('status') in ('Ok', 'Added'):
519  tPkgSet.add(packageNode.get('name'))
520 
521  aPkgSet = set()
522  for packageNode in aPkgNode.findall('Package'):
523  if packageNode.get('status') in ('Ok', 'Added'):
524  aPkgSet.add(packageNode.get('name'))
525 
526  # Save lists of packages sets for usage on slave side.
527  self.__testCfg['Packages']['Tested'] = list(tPkgSet)
528  self.__testCfg['Packages']['Available'] = list(tPkgSet.union(aPkgSet))
529 
530  # Add all available packages for usage on master side.
531  for item in tPkgSet.difference(aPkgSet):
532  etree.SubElement(aPkgNode, 'Package', name=item, status='Ok')
533  # --------------------------------------------------------------------------------------------}}}-
534 
535  # -- def __verifyPackageListNode -------------------------------------------------------------{{{-
536 
539  def __verifyPackageListNode (self, packageListNode, ignoredPackageIDs=[]):
540  # If no packages are given add everything!
541  if not packageListNode.getchildren():
542  etree.SubElement(packageListNode, "Package", name="*/*")
543 
544  for packageNode in packageListNode:
545  packageID = packageNode.get('name')
546  try:
547  pGroup, pName = packageID.split("/")
548  except:
549  packageNode.set('status', 'Invalid')
550  continue
551 
552  # Substitute the wildcards.
553  if pGroup == "*":
554  if pName == "*":
555  for package in mevis.MLABPackageManager.packages():
556  packageID = package.packageIdentifier()
557  if not packageID in ignoredPackageIDs:
558  etree.SubElement(packageListNode, "Package", name=packageID, status='Added')
559  # Remove node as the wildcard has been executed.
560  packageNode.set('status', 'Substituted')
561  else:
562  packageNode.set('status', 'Failed')
563  elif pName == "*":
564  packageNode.set('status', 'Substituted')
565  for package in mevis.MLABPackageManager.packagesByGroup(pGroup):
566  packageID = package.packageIdentifier()
567  if not packageID in ignoredPackageIDs:
568  etree.SubElement(packageListNode, "Package", name=packageID, status='Added')
569  else:
570  # If the given package exists add it to the package set otherwise
571  # remove the XML node.
572  if mevis.MLABPackageManager.packageByIdentifier(packageID):
573  packageNode.set('status', 'Ok')
574  else:
575  packageNode.set('status', 'Failed')
576  # --------------------------------------------------------------------------------------------}}}-
577 
578  # -- def __collectModulesToTest ---------------------------------------------------------------------{{{-
579 
584  def __collectModulesToTest (self, testCfg):
585  modulesNode = testCfg.find('Modules')
586 
587  # Build up a dictionary with all specified filters.
588  filterDict = {}
589  for filterNode in modulesNode.findall('Filter'):
590  key, valueList = filterNode.text.split(":")
591  filterDict[key] = []
592  for value in valueList.split(","):
593  filterDict[key].append(value)
594 
595  # Build up a list with all modules to be be taken into account.
596  availableModuleList = []
597  for packageName in self.__testCfg['Packages']['Tested']:
598  availableModuleList.extend(mevis.MLAB.allModulesForPackageIdentifier(packageName))
599 
600  # If the user did not specify a list of modules use all available.
601  if len(modulesNode.findall('Module')) == 0:
602  for moduleName in availableModuleList:
603  etree.SubElement(modulesNode, "Module", name=moduleName)
604 
605  # Find all modules to test.
606  for moduleNode in modulesNode.findall('Module'):
607  moduleName = moduleNode.get('name')
608  moduleInfo = mevis.MLAB.moduleInfo(moduleName)
609 
610  if moduleInfo and moduleName in availableModuleList:
611  useModule = True
612  # Does module pass filters?
613  for f in filterDict:
614  if not f in moduleInfo or not [x for x in filterDict[f] if re.search(x, moduleInfo[f])]:
615  useModule = False
616  break
617  if useModule:
618  self.__testCfg['Modules'].append(moduleName)
619  moduleNode.set('status', str(Utils.TEST_STATUS_OK))
620  else:
621  moduleNode.set('isModuleFiltered', str(True))
622  else:
623  modulesNode.set('status', str(Utils.TEST_STATUS_ERROR))
624  # --------------------------------------------------------------------------------------------}}}-
625 
626  # -- def __buildModuleInfo -------------------------------------------------------------------{{{-
627  # @param modulesInfoNode XML node taking the module information.
628  def __buildModuleInfo (self, modulesInfoNode):
629  for moduleName in self.__testCfg['Modules']:
630  moduleInfo = mevis.MLAB.moduleInfo(moduleName)
631  newModuleNode = etree.SubElement(modulesInfoNode, 'Module', name=moduleName)
632  for key in moduleInfo:
633  value = moduleInfo[key]
634  etree.SubElement(newModuleNode, key, type=value.__class__.__name__).text = unicode(value)
635  # --------------------------------------------------------------------------------------------}}}-
636 
637  # -- def __setPackageList --------------------------------------------------------------------{{{-
638 
641  def __setPackageList (self, xmlNode, resultNode):
642  packageList = []
643  for item in xmlNode.findall('Package'):
644  packageList.append(item.get('name'))
645  TestHelper.getInstance().setPackageList(packageList)
646  resultNode.set('errorCode', 'Ok')
647  # --------------------------------------------------------------------------------------------}}}-
648 
649  # -- def runCommand --------------------------------------------------------------------------{{{-
650 
654  def runCommand (self, requestNode):
655  command = requestNode.get('type')
656  mevis.MLAB.log("Running command '%s'" % command)
657 
658  resultNode = etree.Element('Result')
659  try:
660  if command == 'Quit':
661  resultNode.set('errorCode', 'Ok')
662  self.__running = False
663  elif command == 'DoTest':
664  testCaseNode = requestNode.find('TestCase')
665  if self.__com and testCaseNode.get("requestProgress") == "1":
667 
668  self.__doTest(testCaseNode, resultNode)
669 
670  if self.__com and testCaseNode.get("requestProgress") == "1":
671  self.setTestCaseListener(None)
672 
673  elif command == 'SetPackageList': self.__setPackageList(requestNode.find('Packages'), resultNode)
674  elif command == 'BuildTestAgenda': self.__buildTestAgenda(requestNode.find('Configuration'), resultNode)
675  elif command == 'BuildTestCaseAgenda': self.__buildTestCaseAgenda(requestNode, resultNode)
676  else:
677  raise Exception('Unknown command: %s' % (command))
678  except:
679  resultNode.set('errorCode', 'Exception')
680  etree.SubElement(resultNode, 'Error').text = traceback.format_exc()
681  mevis.MLAB.log(traceback.format_exc())
682  self.__running = False
683 
684  content = etree.tostring(resultNode).decode()
685  mevis.MLAB.log("Result content: %s%s" % (content[:150], " [...]" if len(content)>150 else ""))
686  return resultNode
687  # --------------------------------------------------------------------------------------------}}}-
688 
689  # -- def run ---------------------------------------------------------------------------------{{{-
690 
691  def run (self):
692  self.__com.connect()
693  self.__running = True
694  while self.__running:
695  request = self.__com.recv(20)
696  if request in ('', None):
697  mevis.MLAB.logError(self.__com.getLastErrorWithMessage()[1])
698  break
699 
700  requestNode = etree.fromstring(request)
701  resultNode = self.runCommand(requestNode)
702 
703  if not self.__com.send(etree.tostring(resultNode), 5):
704  mevis.MLAB.logError("Couldn't send result to request %s" % (request))
705  self.__running = False
706  self.__com.disconnect()
707  # --------------------------------------------------------------------------------------------}}}-
708 # ----------------------------------------------------------------------------------------------}}}-
__running
Control whether the slave is running.
Definition: Slave.py:78
def startTestCaseFunction(self, testType, testCase, testFunction)
Definition: Slave.py:43
def loadTestCase(self, testCaseNode)
Load the given test case.
Definition: Slave.py:132
__testCase
The test case loaded.
Definition: Slave.py:75
def unloadTestCase(self)
Clears the loaded test case.
Definition: Slave.py:176
def __verifyTestCaseList(self, testCfg, testRunNode)
Verify the availability of all the given tests.
Definition: Slave.py:372
__testCfg
Internal data-structure with information on the test run.
Definition: Slave.py:81
The implementation of the TestCase superclass for generic testing.
Implementation of the TestCase superclass for functional test cases.
def __getTestCaseInfo(self, testCaseName)
Definition: Slave.py:425
def __verifyTestGroups(self, infoDict, testGroupList)
Verify whether test case should be executed.
Definition: Slave.py:475
def __loadTestCase(self, testCaseName, testCaseType, moduleName=None)
Internal loading mechanism.
Definition: Slave.py:145
The class controlling a MeVisLab slave instance.
Definition: Slave.py:67
def __buildModuleInfo(self, modulesInfoNode)
Definition: Slave.py:628
def __verifyPackageListNode(self, packageListNode, ignoredPackageIDs=[])
Substitute wildcards and verify package nodes.
Definition: Slave.py:539
def __verifyTestCase(self, testCaseName, testResultNode, packagesToTest, modulesToTest)
Verify Test Case and add information on it.
Definition: Slave.py:438
def runCommand(self, requestNode)
Run a command given via the requestNode.
Definition: Slave.py:654
def __doTest(self, testCaseNode, resultNode)
Run the test received from the master.
Definition: Slave.py:188
def endTestCaseFunction(self, status, duration)
Definition: Slave.py:57
def setIsInsideTestCaseManager(self, isInsideTestCaseManager)
Definition: Slave.py:120
def clearEncodingCache()
Definition: Base.py:31
def __init__(self, cfgFile, context, offline=False)
The default constructor.
Definition: Slave.py:91
def getTestCase(self)
Returns the test case that has been run.
Definition: Slave.py:170
def __buildTestCaseAgenda(self, requestNode, resultNode)
Definition: Slave.py:342
def __verifyPackages(self, testCfg)
Build up a list of packages and verify existence of given ones.
Definition: Slave.py:497
def __loadAndVerifyTestCase(self, testCaseName, testResultNode, packagesToTest, modulesToTest)
Verify Test Case and add information on it.
Definition: Slave.py:408
def __setPackageList(self, xmlNode, resultNode)
Method to set the list of available packages given in the setting.
Definition: Slave.py:641
def setAgendaTestCase(self, testCase)
Set the test case that is used for building the agenda/function list.
Definition: Slave.py:162
def __buildTestAgenda(self, testCfg, resultNode)
Build a test agenda for the given request.
Definition: Slave.py:277
__com
The communication device to talk to master.
Definition: Slave.py:72
The connection's slave.
Definition: IPC.py:258
__ctx
The MeVisLab context.
Definition: Slave.py:70
def setTestCaseListener(self, listener)
Definition: Slave.py:123
def run(self)
The main method which handles all the request from the master.
Definition: Slave.py:691
def __collectModulesToTest(self, testCfg)
Get a list of all modules to test.
Definition: Slave.py:584