Gaudi Framework, version v23r7

Home   Generated: Wed Mar 20 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | List of all members
GaudiTest.GaudiExeTest Class Reference
Inheritance diagram for GaudiTest.GaudiExeTest:
Inheritance graph
[legend]
Collaboration diagram for GaudiTest.GaudiExeTest:
Collaboration graph
[legend]

Public Member Functions

def PlatformIsNotSupported
 
def GetPlatform
 
def isWinPlatform
 
def CheckTTreesSummaries
 
def CheckHistosSummaries
 
def ValidateWithReference
 
def ValidateOutput
 
def DumpEnvironment
 
def Run
 
def RunProgram
 

Public Attributes

 callable
 
 extra_args
 
 args_order
 
 program
 
 reference
 
 error_reference
 
 use_temp_dir
 
 timeout
 

Static Public Attributes

list arguments
 

Private Member Functions

def _expandReferenceFileName
 
def _CreateEclipseLaunch
 

Detailed Description

Standard Gaudi test.

Definition at line 990 of file GaudiTest.py.

Member Function Documentation

def GaudiTest.GaudiExeTest._CreateEclipseLaunch (   self,
  prog,
  args,
  destdir = None 
)
private

Definition at line 1583 of file GaudiTest.py.

1584  def _CreateEclipseLaunch(self, prog, args, destdir = None):
1585  # Find the project name used in ecplise.
1586  # The name is in a file called ".project" in one of the parent directories
1587  projbasedir = os.path.normpath(destdir)
1588  while not os.path.exists(os.path.join(projbasedir, ".project")):
1589  oldprojdir = projbasedir
1590  projbasedir = os.path.normpath(os.path.join(projbasedir, os.pardir))
1591  # FIXME: the root level is invariant when trying to go up one level,
1592  # but it must be cheched on windows
1593  if oldprojdir == projbasedir:
1594  # If we cannot find a .project, so no point in creating a .launch file
1595  return
1596  # Ensure that we have a place where to write.
1597  if not os.path.exists(destdir):
1598  os.makedirs(destdir)
1599  # Use ElementTree to parse the XML file
1600  from xml.etree import ElementTree as ET
1601  t = ET.parse(os.path.join(projbasedir, ".project"))
1602  projectName = t.find("name").text
1603 
1604  # prepare the name/path of the generated file
1605  destfile = "%s.launch" % self._Runnable__id
1606  if destdir:
1607  destfile = os.path.join(destdir, destfile)
1608 
1609  if self.options.strip():
1610  # this means we have some custom options in the qmt file, so we have
1611  # to copy them from the temporary file at the end of the arguments
1612  # in another file
1613  tempfile = args.pop()
1614  optsfile = destfile + os.path.splitext(tempfile)[1]
1615  shutil.copyfile(tempfile, optsfile)
1616  args.append(optsfile)
1617 
1618  # prepare the data to insert in the XML file
1619  from xml.sax.saxutils import quoteattr # useful to quote XML special chars
1620  data = {}
1621  # Note: the "quoteattr(k)" is not needed because special chars cannot be part of a variable name,
1622  # but it doesn't harm.
1623  data["environment"] = "\n".join(['<mapEntry key=%s value=%s/>' % (quoteattr(k), quoteattr(v))
1624  for k, v in os.environ.iteritems()])
1625 
1626  data["exec"] = which(prog) or prog
1627  if os.path.basename(data["exec"]).lower().startswith("python"):
1628  data["stopAtMain"] = "false" # do not stop at main when debugging Python scripts
1629  else:
1630  data["stopAtMain"] = "true"
1631 
1632  data["args"] = "&#10;".join(map(rationalizepath, args))
1633  if self.isWinPlatform():
1634  data["args"] = "&#10;".join(["/debugexe"] + map(rationalizepath, [data["exec"]] + args))
1635  data["exec"] = which("vcexpress.exe")
1636 
1637  if not self.use_temp_dir:
1638  data["workdir"] = os.getcwd()
1639  else:
1640  # If the test is using a tmporary directory, it is better to run it
1641  # in the same directory as the .launch file when debugged in eclipse
1642  data["workdir"] = destdir
1643 
1644  data["project"] = projectName.strip()
1645 
1646  # Template for the XML file, based on eclipse 3.4
1647  xml = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1648 <launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType">
1649 <booleanAttribute key="org.eclipse.cdt.debug.mi.core.AUTO_SOLIB" value="true"/>
1650 <listAttribute key="org.eclipse.cdt.debug.mi.core.AUTO_SOLIB_LIST"/>
1651 <stringAttribute key="org.eclipse.cdt.debug.mi.core.DEBUG_NAME" value="gdb"/>
1652 <stringAttribute key="org.eclipse.cdt.debug.mi.core.GDB_INIT" value=".gdbinit"/>
1653 <listAttribute key="org.eclipse.cdt.debug.mi.core.SOLIB_PATH"/>
1654 <booleanAttribute key="org.eclipse.cdt.debug.mi.core.STOP_ON_SOLIB_EVENTS" value="false"/>
1655 <booleanAttribute key="org.eclipse.cdt.debug.mi.core.breakpointsFullPath" value="false"/>
1656 <stringAttribute key="org.eclipse.cdt.debug.mi.core.commandFactory" value="org.eclipse.cdt.debug.mi.core.standardCommandFactory"/>
1657 <stringAttribute key="org.eclipse.cdt.debug.mi.core.protocol" value="mi"/>
1658 <booleanAttribute key="org.eclipse.cdt.debug.mi.core.verboseMode" value="false"/>
1659 <intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
1660 <stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
1661 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_ID" value="org.eclipse.cdt.debug.mi.core.CDebuggerNew"/>
1662 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
1663 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="run"/>
1664 <booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="%(stopAtMain)s"/>
1665 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
1666 <booleanAttribute key="org.eclipse.cdt.launch.ENABLE_REGISTER_BOOKKEEPING" value="false"/>
1667 <booleanAttribute key="org.eclipse.cdt.launch.ENABLE_VARIABLE_BOOKKEEPING" value="false"/>
1668 <stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList/&gt;"/>
1669 <stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;globalVariableList/&gt;&#10;"/>
1670 <stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;memoryBlockExpressionList/&gt;&#10;"/>
1671 <stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="%(args)s"/>
1672 <stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="%(exec)s"/>
1673 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="%(project)s"/>
1674 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
1675 <stringAttribute key="org.eclipse.cdt.launch.WORKING_DIRECTORY" value="%(workdir)s"/>
1676 <booleanAttribute key="org.eclipse.cdt.launch.ui.ApplicationCDebuggerTab.DEFAULTS_SET" value="true"/>
1677 <booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/>
1678 <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
1679 <listEntry value="/%(project)s"/>
1680 </listAttribute>
1681 <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
1682 <listEntry value="4"/>
1683 </listAttribute>
1684 <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="false"/>
1685 <mapAttribute key="org.eclipse.debug.core.environmentVariables">
1686 %(environment)s
1687 </mapAttribute>
1688 <mapAttribute key="org.eclipse.debug.core.preferred_launchers">
1689 <mapEntry key="[debug]" value="org.eclipse.cdt.cdi.launch.localCLaunch"/>
1690 </mapAttribute>
1691 <listAttribute key="org.eclipse.debug.ui.favoriteGroups">
1692 <listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
1693 </listAttribute>
1694 </launchConfiguration>
1695 """ % data
1696 
1697  # Write the output file
1698  open(destfile, "w").write(xml)
1699  #open(destfile + "_copy.xml", "w").write(xml)
1700 
1701 
try:
def GaudiTest.GaudiExeTest._expandReferenceFileName (   self,
  reffile 
)
private

Definition at line 1143 of file GaudiTest.py.

1144  def _expandReferenceFileName(self, reffile):
1145  # if no file is passed, do nothing
1146  if not reffile:
1147  return ""
1148 
1149  # function to split an extension in constituents parts
1150  platformSplit = lambda p: set(p.split('-' in p and '-' or '_'))
1151 
1152  reference = os.path.normpath(os.path.expandvars(reffile))
1153  # old-style platform-specific reference name
1154  spec_ref = reference[:-3] + self.GetPlatform()[0:3] + reference[-3:]
1155  if os.path.isfile(spec_ref):
1156  reference = spec_ref
1157  else: # look for new-style platform specific reference files:
1158  # get all the files whose name start with the reference filename
1159  dirname, basename = os.path.split(reference)
1160  if not dirname: dirname = '.'
1161  head = basename + "."
1162  head_len = len(head)
1163  platform = platformSplit(self.GetPlatform())
1164  candidates = []
1165  for f in os.listdir(dirname):
1166  if f.startswith(head):
1167  req_plat = platformSplit(f[head_len:])
1168  if platform.issuperset(req_plat):
1169  candidates.append( (len(req_plat), f) )
1170  if candidates: # take the one with highest matching
1171  # FIXME: it is not possible to say if x86_64-slc5-gcc43-dbg
1172  # has to use ref.x86_64-gcc43 or ref.slc5-dbg
1173  candidates.sort()
1174  reference = os.path.join(dirname, candidates[-1][1])
1175  return reference
def GaudiTest.GaudiExeTest.CheckHistosSummaries (   self,
  stdout,
  result,
  causes,
  dict = None,
  ignore = None 
)
Compare the TTree summaries in stdout with the ones in trees_dict or in
the reference file. By default ignore the size, compression and basket
fields.
The presence of TTree summaries when none is expected is not a failure.

Definition at line 1212 of file GaudiTest.py.

1213  ignore = None):
1214  """
1215  Compare the TTree summaries in stdout with the ones in trees_dict or in
1216  the reference file. By default ignore the size, compression and basket
1217  fields.
1218  The presence of TTree summaries when none is expected is not a failure.
1219  """
1220  if dict is None:
1221  reference = self._expandReferenceFileName(self.reference)
1222  # call the validator if the file exists
1223  if reference and os.path.isfile(reference):
1224  dict = findHistosSummaries(open(reference).read())
1225  else:
1226  dict = {}
1227 
1228  from pprint import PrettyPrinter
1229  pp = PrettyPrinter()
1230  if dict:
1231  result["GaudiTest.Histos.expected"] = result.Quote(pp.pformat(dict))
1232  if ignore:
1233  result["GaudiTest.Histos.ignore"] = result.Quote(ignore)
1234 
1235  histos = findHistosSummaries(stdout)
1236  failed = cmpTreesDicts(dict, histos, ignore)
1237  if failed:
1238  causes.append("histos summaries")
1239  msg = "%s: %s != %s" % getCmpFailingValues(dict, histos, failed)
1240  result["GaudiTest.Histos.failure_on"] = result.Quote(msg)
1241  result["GaudiTest.Histos.found"] = result.Quote(pp.pformat(histos))
1242 
1243  return causes
def GaudiTest.GaudiExeTest.CheckTTreesSummaries (   self,
  stdout,
  result,
  causes,
  trees_dict = None,
  ignore = r"Basket|.*size|Compression" 
)
Compare the TTree summaries in stdout with the ones in trees_dict or in
the reference file. By default ignore the size, compression and basket
fields.
The presence of TTree summaries when none is expected is not a failure.

Definition at line 1178 of file GaudiTest.py.

1179  ignore = r"Basket|.*size|Compression"):
1180  """
1181  Compare the TTree summaries in stdout with the ones in trees_dict or in
1182  the reference file. By default ignore the size, compression and basket
1183  fields.
1184  The presence of TTree summaries when none is expected is not a failure.
1185  """
1186  if trees_dict is None:
1187  reference = self._expandReferenceFileName(self.reference)
1188  # call the validator if the file exists
1189  if reference and os.path.isfile(reference):
1190  trees_dict = findTTreeSummaries(open(reference).read())
1191  else:
1192  trees_dict = {}
1193 
1194  from pprint import PrettyPrinter
1195  pp = PrettyPrinter()
1196  if trees_dict:
1197  result["GaudiTest.TTrees.expected"] = result.Quote(pp.pformat(trees_dict))
1198  if ignore:
1199  result["GaudiTest.TTrees.ignore"] = result.Quote(ignore)
1200 
1201  trees = findTTreeSummaries(stdout)
1202  failed = cmpTreesDicts(trees_dict, trees, ignore)
1203  if failed:
1204  causes.append("trees summaries")
1205  msg = "%s: %s != %s" % getCmpFailingValues(trees_dict, trees, failed)
1206  result["GaudiTest.TTrees.failure_on"] = result.Quote(msg)
1207  result["GaudiTest.TTrees.found"] = result.Quote(pp.pformat(trees))
1208 
1209  return causes
def GaudiTest.GaudiExeTest.DumpEnvironment (   self,
  result 
)
Add the content of the environment to the result object.

Copied from the QMTest class of COOL.

Definition at line 1366 of file GaudiTest.py.

1367  def DumpEnvironment(self, result):
1368  """
1369  Add the content of the environment to the result object.
1370 
1371  Copied from the QMTest class of COOL.
1372  """
1373  vars = os.environ.keys()
1374  vars.sort()
1375  result['GaudiTest.environment'] = \
1376  result.Quote('\n'.join(["%s=%s"%(v,os.environ[v]) for v in vars]))
def GaudiTest.GaudiExeTest.GetPlatform (   self)
Return the platform Id defined in CMTCONFIG or SCRAM_ARCH.

Definition at line 1121 of file GaudiTest.py.

1122  def GetPlatform(self):
1123  """
1124  Return the platform Id defined in CMTCONFIG or SCRAM_ARCH.
1125  """
1126  arch = "None"
1127  # check architecture name
1128  if "CMTCONFIG" in os.environ:
1129  arch = os.environ["CMTCONFIG"]
1130  elif "SCRAM_ARCH" in os.environ:
1131  arch = os.environ["SCRAM_ARCH"]
1132  return arch
def GaudiTest.GaudiExeTest.isWinPlatform (   self)
Return True if the current platform is Windows.

This function was needed because of the change in the CMTCONFIG format,
from win32_vc71_dbg to i686-winxp-vc9-dbg.

Definition at line 1133 of file GaudiTest.py.

1134  def isWinPlatform(self):
1135  """
1136  Return True if the current platform is Windows.
1137 
1138  This function was needed because of the change in the CMTCONFIG format,
1139  from win32_vc71_dbg to i686-winxp-vc9-dbg.
1140  """
1141  platform = self.GetPlatform()
1142  return "winxp" in platform or platform.startswith("win")
def GaudiTest.GaudiExeTest.PlatformIsNotSupported (   self,
  context,
  result 
)

Definition at line 1107 of file GaudiTest.py.

1108  def PlatformIsNotSupported(self, context, result):
1109  platform = self.GetPlatform()
1110  unsupported = [ re.compile(x)
1111  for x in [ str(y).strip()
1112  for y in self.unsupported_platforms ]
1113  if x
1114  ]
1115  for p_re in unsupported:
1116  if p_re.search(platform):
1117  result.SetOutcome(result.UNTESTED)
1118  result[result.CAUSE] = 'Platform not supported.'
1119  return True
1120  return False
def GaudiTest.GaudiExeTest.Run (   self,
  context,
  result 
)
Run the test.

'context' -- A 'Context' giving run-time parameters to the
test.

'result' -- A 'Result' object.  The outcome will be
'Result.PASS' when this method is called.  The 'result' may be
modified by this method to indicate outcomes other than
'Result.PASS' or to add annotations.

Definition at line 1377 of file GaudiTest.py.

1378  def Run(self, context, result):
1379  """Run the test.
1380 
1381  'context' -- A 'Context' giving run-time parameters to the
1382  test.
1383 
1384  'result' -- A 'Result' object. The outcome will be
1385  'Result.PASS' when this method is called. The 'result' may be
1386  modified by this method to indicate outcomes other than
1387  'Result.PASS' or to add annotations."""
1388 
1389  # Check if the platform is supported
1390  if self.PlatformIsNotSupported(context, result):
1391  return
1392 
1393  # Prepare program name and arguments (expanding variables, and converting to absolute)
1394  if self.program:
1395  prog = rationalizepath(self.program)
1396  elif "GAUDIEXE" in os.environ:
1397  prog = os.environ["GAUDIEXE"]
1398  else:
1399  prog = "Gaudi.exe"
1400  self.program = prog
1401 
1402  dummy, prog_ext = os.path.splitext(prog)
1403  if prog_ext not in [ ".exe", ".py", ".bat" ] and self.isWinPlatform():
1404  prog += ".exe"
1405  prog_ext = ".exe"
1406 
1407  prog = which(prog) or prog
1408 
1409  # Convert paths to absolute paths in arguments and reference files
1410  args = map(rationalizepath, self.args)
1413 
1414 
1415  # check if the user provided inline options
1416  tmpfile = None
1417  if self.options.strip():
1418  ext = ".opts"
1419  if re.search(r"from\s*Gaudi.Configuration\s*import\s*\*", self.options):
1420  ext = ".py"
1421  tmpfile = TempFile(ext)
1422  tmpfile.writelines("\n".join(self.options.splitlines()))
1423  tmpfile.flush()
1424  args.append(tmpfile.name)
1425  result["GaudiTest.options"] = result.Quote(self.options)
1426 
1427  # if the program is a python file, execute it through python
1428  if prog_ext == ".py":
1429  args.insert(0,prog)
1430  if self.isWinPlatform():
1431  prog = which("python.exe") or "python.exe"
1432  else:
1433  prog = which("python") or "python"
1434 
1435  # Change to the working directory if specified or to the default temporary
1436  origdir = os.getcwd()
1437  if self.workdir:
1438  os.chdir(str(os.path.normpath(os.path.expandvars(self.workdir))))
1439  elif self.use_temp_dir == "true":
1440  if "QMTEST_TMPDIR" in os.environ:
1441  qmtest_tmpdir = os.environ["QMTEST_TMPDIR"]
1442  if not os.path.exists(qmtest_tmpdir):
1443  os.makedirs(qmtest_tmpdir)
1444  os.chdir(qmtest_tmpdir)
1445  elif "qmtest.tmpdir" in context:
1446  os.chdir(context["qmtest.tmpdir"])
1447 
1448  if "QMTEST_IGNORE_TIMEOUT" not in os.environ:
1449  self.timeout = max(self.timeout,600)
1450  else:
1451  self.timeout = -1
1452 
1453  try:
1454  # Generate eclipse.org debug launcher for the test
1455  self._CreateEclipseLaunch(prog, args, destdir = os.path.join(origdir, '.eclipse'))
1456  # Run the test
1457  self.RunProgram(prog,
1458  [ prog ] + args,
1459  context, result)
1460  # Record the content of the enfironment for failing tests
1461  if result.GetOutcome() not in [ result.PASS ]:
1462  self.DumpEnvironment(result)
1463  finally:
1464  # revert to the original directory
1465  os.chdir(origdir)
def GaudiTest.GaudiExeTest.RunProgram (   self,
  program,
  arguments,
  context,
  result 
)
Run the 'program'.

'program' -- The path to the program to run.

'arguments' -- A list of the arguments to the program.  This
list must contain a first argument corresponding to 'argv[0]'.

'context' -- A 'Context' giving run-time parameters to the
test.

'result' -- A 'Result' object.  The outcome will be
'Result.PASS' when this method is called.  The 'result' may be
modified by this method to indicate outcomes other than
'Result.PASS' or to add annotations.

@attention: This method has been copied from command.ExecTestBase
    (QMTest 2.3.0) and modified to keep stdout and stderr
    for tests that have been terminated by a signal.
    (Fundamental for debugging in the Application Area)

Definition at line 1466 of file GaudiTest.py.

1467  def RunProgram(self, program, arguments, context, result):
1468  """Run the 'program'.
1469 
1470  'program' -- The path to the program to run.
1471 
1472  'arguments' -- A list of the arguments to the program. This
1473  list must contain a first argument corresponding to 'argv[0]'.
1474 
1475  'context' -- A 'Context' giving run-time parameters to the
1476  test.
1477 
1478  'result' -- A 'Result' object. The outcome will be
1479  'Result.PASS' when this method is called. The 'result' may be
1480  modified by this method to indicate outcomes other than
1481  'Result.PASS' or to add annotations.
1482 
1483  @attention: This method has been copied from command.ExecTestBase
1484  (QMTest 2.3.0) and modified to keep stdout and stderr
1485  for tests that have been terminated by a signal.
1486  (Fundamental for debugging in the Application Area)
1487  """
1488 
1489  # Construct the environment.
1490  environment = self.MakeEnvironment(context)
1491  # FIXME: whithout this, we get some spurious '\x1b[?1034' in the std out on SLC6
1492  if "slc6" in environment.get('CMTCONFIG', ''):
1493  environment['TERM'] = 'dumb'
1494  # Create the executable.
1495  if self.timeout >= 0:
1496  timeout = self.timeout
1497  else:
1498  # If no timeout was specified, we sill run this process in a
1499  # separate process group and kill the entire process group
1500  # when the child is done executing. That means that
1501  # orphaned child processes created by the test will be
1502  # cleaned up.
1503  timeout = -2
1504  e = GaudiFilterExecutable(self.stdin, timeout)
1505  # Run it.
1506  exit_status = e.Run(arguments, environment, path = program)
1507  # Get the stack trace from the temporary file (if present)
1508  if e.stack_trace_file and os.path.exists(e.stack_trace_file):
1509  stack_trace = open(e.stack_trace_file).read()
1510  os.remove(e.stack_trace_file)
1511  else:
1512  stack_trace = None
1513  if stack_trace:
1514  result["ExecTest.stack_trace"] = result.Quote(stack_trace)
1515 
1516  # If the process terminated normally, check the outputs.
1517  if sys.platform == "win32" or os.WIFEXITED(exit_status):
1518  # There are no causes of failure yet.
1519  causes = []
1520  # The target program terminated normally. Extract the
1521  # exit code, if this test checks it.
1522  if self.exit_code is None:
1523  exit_code = None
1524  elif sys.platform == "win32":
1525  exit_code = exit_status
1526  else:
1527  exit_code = os.WEXITSTATUS(exit_status)
1528  # Get the output generated by the program.
1529  stdout = e.stdout
1530  stderr = e.stderr
1531  # Record the results.
1532  result["ExecTest.exit_code"] = str(exit_code)
1533  result["ExecTest.stdout"] = result.Quote(stdout)
1534  result["ExecTest.stderr"] = result.Quote(stderr)
1535  # Check to see if the exit code matches.
1536  if exit_code != self.exit_code:
1537  causes.append("exit_code")
1538  result["ExecTest.expected_exit_code"] \
1539  = str(self.exit_code)
1540  # Validate the output.
1541  causes += self.ValidateOutput(stdout, stderr, result)
1542  # If anything went wrong, the test failed.
1543  if causes:
1544  result.Fail("Unexpected %s." % string.join(causes, ", "))
1545  elif os.WIFSIGNALED(exit_status):
1546  # The target program terminated with a signal. Construe
1547  # that as a test failure.
1548  signal_number = str(os.WTERMSIG(exit_status))
1549  if not stack_trace:
1550  result.Fail("Program terminated by signal.")
1551  else:
1552  # The presence of stack_trace means tha we stopped the job because
1553  # of a time-out
1554  result.Fail("Exceeded time limit (%ds), terminated." % timeout)
1555  result["ExecTest.signal_number"] = signal_number
1556  result["ExecTest.stdout"] = result.Quote(e.stdout)
1557  result["ExecTest.stderr"] = result.Quote(e.stderr)
1558  elif os.WIFSTOPPED(exit_status):
1559  # The target program was stopped. Construe that as a
1560  # test failure.
1561  signal_number = str(os.WSTOPSIG(exit_status))
1562  if not stack_trace:
1563  result.Fail("Program stopped by signal.")
1564  else:
1565  # The presence of stack_trace means tha we stopped the job because
1566  # of a time-out
1567  result.Fail("Exceeded time limit (%ds), stopped." % timeout)
1568  result["ExecTest.signal_number"] = signal_number
1569  result["ExecTest.stdout"] = result.Quote(e.stdout)
1570  result["ExecTest.stderr"] = result.Quote(e.stderr)
1571  else:
1572  # The target program terminated abnormally in some other
1573  # manner. (This shouldn't normally happen...)
1574  result.Fail("Program did not terminate normally.")
1575 
1576  # Marco Cl.: This is a special trick to fix a "problem" with the output
1577  # of gaudi jobs when they use colors
1578  esc = '\x1b'
1579  repr_esc = '\\x1b'
1580  result["ExecTest.stdout"] = result["ExecTest.stdout"].replace(esc,repr_esc)
1581  # TODO: (MCl) improve the hack for colors in standard output
1582  # may be converting them to HTML tags
def GaudiTest.GaudiExeTest.ValidateOutput (   self,
  stdout,
  stderr,
  result 
)

Definition at line 1301 of file GaudiTest.py.

1302  def ValidateOutput(self, stdout, stderr, result):
1303  causes = []
1304  # if the test definition contains a custom validator, use it
1305  if self.validator.strip() != "":
1306  class CallWrapper(object):
1307  """
1308  Small wrapper class to dynamically bind some default arguments
1309  to a callable.
1310  """
1311  def __init__(self, callable, extra_args = {}):
1312  self.callable = callable
1313  self.extra_args = extra_args
1314  # get the list of names of positional arguments
1315  from inspect import getargspec
1316  self.args_order = getargspec(callable)[0]
1317  # Remove "self" from the list of positional arguments
1318  # since it is added automatically
1319  if self.args_order[0] == "self":
1320  del self.args_order[0]
1321  def __call__(self, *args, **kwargs):
1322  # Check which positional arguments are used
1323  positional = self.args_order[:len(args)]
1324 
1325  kwargs = dict(kwargs) # copy the arguments dictionary
1326  for a in self.extra_args:
1327  # use "extra_args" for the arguments not specified as
1328  # positional or keyword
1329  if a not in positional and a not in kwargs:
1330  kwargs[a] = self.extra_args[a]
1331  return apply(self.callable, args, kwargs)
1332  # local names to be exposed in the script
1333  exported_symbols = {"self":self,
1334  "stdout":stdout,
1335  "stderr":stderr,
1336  "result":result,
1337  "causes":causes,
1338  "findReferenceBlock":
1339  CallWrapper(findReferenceBlock, {"stdout":stdout,
1340  "result":result,
1341  "causes":causes}),
1342  "validateWithReference":
1343  CallWrapper(self.ValidateWithReference, {"stdout":stdout,
1344  "stderr":stderr,
1345  "result":result,
1346  "causes":causes}),
1347  "countErrorLines":
1348  CallWrapper(countErrorLines, {"stdout":stdout,
1349  "result":result,
1350  "causes":causes}),
1351  "checkTTreesSummaries":
1352  CallWrapper(self.CheckTTreesSummaries, {"stdout":stdout,
1353  "result":result,
1354  "causes":causes}),
1355  "checkHistosSummaries":
1356  CallWrapper(self.CheckHistosSummaries, {"stdout":stdout,
1357  "result":result,
1358  "causes":causes}),
1359 
1360  }
1361  exec self.validator in globals(), exported_symbols
1362  else:
1363  self.ValidateWithReference(stdout, stderr, result, causes)
1364 
1365  return causes
def GaudiTest.GaudiExeTest.ValidateWithReference (   self,
  stdout,
  stderr,
  result,
  causes,
  preproc = None 
)
Default validation action: compare standard output and error to the
reference files.

Definition at line 1244 of file GaudiTest.py.

1245  def ValidateWithReference(self, stdout, stderr, result, causes, preproc = None):
1246  """
1247  Default validation action: compare standard output and error to the
1248  reference files.
1249  """
1250  # set the default output preprocessor
1251  if preproc is None:
1252  preproc = normalizeExamples
1253  # check standard output
1254  reference = self._expandReferenceFileName(self.reference)
1255  # call the validator if the file exists
1256  if reference and os.path.isfile(reference):
1257  result["GaudiTest.output_reference"] = reference
1258  causes += ReferenceFileValidator(reference,
1259  "standard output",
1260  "GaudiTest.output_diff",
1261  preproc = preproc)(stdout, result)
1262 
1263  # Compare TTree summaries
1264  causes = self.CheckTTreesSummaries(stdout, result, causes)
1265  causes = self.CheckHistosSummaries(stdout, result, causes)
1266 
1267  if causes: # Write a new reference file for stdout
1268  try:
1269  newref = open(reference + ".new","w")
1270  # sanitize newlines
1271  for l in stdout.splitlines():
1272  newref.write(l.rstrip() + '\n')
1273  del newref # flush and close
1274  except IOError:
1275  # Ignore IO errors when trying to update reference files
1276  # because we may be in a read-only filesystem
1277  pass
1278 
1279  # check standard error
1280  reference = self._expandReferenceFileName(self.error_reference)
1281  # call the validator if we have a file to use
1282  if reference and os.path.isfile(reference):
1283  result["GaudiTest.error_reference"] = reference
1284  newcauses = ReferenceFileValidator(reference,
1285  "standard error",
1286  "GaudiTest.error_diff",
1287  preproc = preproc)(stderr, result)
1288  causes += newcauses
1289  if newcauses: # Write a new reference file for stdedd
1290  newref = open(reference + ".new","w")
1291  # sanitize newlines
1292  for l in stderr.splitlines():
1293  newref.write(l.rstrip() + '\n')
1294  del newref # flush and close
1295  else:
1296  causes += BasicOutputValidator(self.stderr,
1297  "standard error",
1298  "ExecTest.expected_stderr")(stderr, result)
1299 
1300  return causes

Member Data Documentation

GaudiTest.GaudiExeTest.args_order

Definition at line 1315 of file GaudiTest.py.

list GaudiTest.GaudiExeTest.arguments
static

Definition at line 993 of file GaudiTest.py.

GaudiTest.GaudiExeTest.callable

Definition at line 1311 of file GaudiTest.py.

GaudiTest.GaudiExeTest.error_reference

Definition at line 1411 of file GaudiTest.py.

GaudiTest.GaudiExeTest.extra_args

Definition at line 1312 of file GaudiTest.py.

GaudiTest.GaudiExeTest.program

Definition at line 1399 of file GaudiTest.py.

GaudiTest.GaudiExeTest.reference

Definition at line 1410 of file GaudiTest.py.

GaudiTest.GaudiExeTest.timeout

Definition at line 1448 of file GaudiTest.py.

GaudiTest.GaudiExeTest.use_temp_dir

Definition at line 1438 of file GaudiTest.py.


The documentation for this class was generated from the following file:
Generated at Wed Mar 20 2013 17:59:51 for Gaudi Framework, version v23r7 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004