All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiTest.XMLResultStream Class Reference
Inheritance diagram for GaudiTest.XMLResultStream:
Collaboration diagram for GaudiTest.XMLResultStream:

Public Member Functions

def __init__
 
def WriteAnnotation
 
def WriteResult
 
def Summarize
 

Static Public Attributes

list arguments
 

Private Attributes

 _xmlFile
 
 _startTime
 
 _endTime
 
 _tree
 
 _site
 
 _Testing
 
 _StartDateTime
 
 _StartTestTime
 
 _TestList
 
 _EndDateTime
 End time elements. More...
 
 _EndTestTime
 
 _ElapsedMinutes
 

Detailed Description

An 'XMLResultStream' writes its output to a Ctest XML file.

The argument 'dir' is used to select the destination file for the XML
report.
The destination directory may already contain the report from a previous run
(for example of a different package), in which case it will be overrided to
with the new data.

Definition at line 1938 of file GaudiTest.py.

Constructor & Destructor Documentation

def GaudiTest.XMLResultStream.__init__ (   self,
  arguments = None,
  args 
)
Prepare the destination directory.

Creates the destination directory and store in it some preliminary
annotations .

Definition at line 1965 of file GaudiTest.py.

1966  def __init__(self, arguments = None, **args):
1967  """Prepare the destination directory.
1968 
1969  Creates the destination directory and store in it some preliminary
1970  annotations .
1971  """
1972  ResultStream.__init__(self, arguments, **args)
1974  self._xmlFile = os.path.join(self.dir, self.prefix + 'Test.xml')
1975 
1976  # add some global variable
1977  self._startTime = None
1978  self._endTime = None
1979  # Format the XML file if it not exists
1980  if not os.path.isfile(self._xmlFile):
1981  # check that the container directory exists and create it if not
1982  if not os.path.exists(os.path.dirname(self._xmlFile)):
1983  os.makedirs(os.path.dirname(self._xmlFile))
1984 
1985  newdataset = ET.Element("newdataset")
1986  self._tree = ET.ElementTree(newdataset)
1987  self._tree.write(self._xmlFile)
1988  else :
1989  # Read the xml file
1990  self._tree = ET.parse(self._xmlFile)
1991  newdataset = self._tree.getroot()
1992 
1993  # Find the corresponding site, if do not exist, create it
1994 
1995  #site = newdataset.find('Site[@BuildStamp="'+result["qmtest.start_time"]+'"][@OSPlatform="'+os.getenv("CMTOPT")+'"]')
1996  # I don't know why this syntax doesn't work. Maybe it is because of the python version. Indeed,
1997  # This works well in the python terminal. So I have to make a for:
1998  for site in newdataset.getiterator() :
1999  if site.get("OSPlatform") == os.uname()[4]: # and site.get("BuildStamp") == result["qmtest.start_time"] and:
2000  # Here we can add some variable to define the difference beetween 2 site
2001  self._site = site
2002  break
2003  else :
2004  site = None
2005 
2006 
2007  if site is None :
2008  import socket
2009  import multiprocessing
2010  attrib = {
2011  "BuildName" : os.getenv("CMTCONFIG"),
2012  "Name" : os.uname()[1] ,
2013  "Generator" : "QMTest "+qm.version ,
2014  "OSName" : os.uname()[0] ,
2015  "Hostname" : socket.gethostname() ,
2016  "OSRelease" : os.uname()[2] ,
2017  "OSVersion" :os.uname()[3] ,
2018  "OSPlatform" :os.uname()[4] ,
2019  "Is64Bits" : "unknown" ,
2020  "VendorString" : "unknown" ,
2021  "VendorID" :"unknown" ,
2022  "FamilyID" :"unknown" ,
2023  "ModelID" :"unknown" ,
2024  "ProcessorCacheSize" :"unknown" ,
2025  "NumberOfLogicalCPU" : str(multiprocessing.cpu_count()) ,
2026  "NumberOfPhysicalCPU" : "0" ,
2027  "TotalVirtualMemory" : "0" ,
2028  "TotalPhysicalMemory" : "0" ,
2029  "LogicalProcessorsPerPhysical" : "0" ,
2030  "ProcessorClockFrequency" : "0" ,
2031  }
2032  self._site = ET.SubElement(newdataset, "Site", attrib)
2033  self._Testing = ET.SubElement(self._site,"Testing")
2034 
2035  # Start time elements
2036  self._StartDateTime = ET.SubElement(self._Testing, "StartDateTime")
2038  self._StartTestTime = ET.SubElement(self._Testing, "StartTestTime")
2039 
2041  self._TestList = ET.SubElement(self._Testing, "TestList")
2042 
2043  ## End time elements
2044  self._EndDateTime = ET.SubElement(self._Testing, "EndDateTime")
2045 
2047  self._EndTestTime = ET.SubElement(self._Testing, "EndTestTime")
2048 
2049 
2051  self._ElapsedMinutes = ET.SubElement(self._Testing, "ElapsedMinutes")
2052 
2053 
2054  else : # We get the elements
2055  self._Testing = self._site.find("Testing")
2056  self._StartDateTime = self._Testing.find("StartDateTime")
2057  self._StartTestTime = self._Testing.find("StartTestTime")
2058  self._TestList = self._Testing.find("TestList")
2059  self._EndDateTime = self._Testing.find("EndDateTime")
2060  self._EndTestTime = self._Testing.find("EndTestTime")
2061  self._ElapsedMinutes = self._Testing.find("ElapsedMinutes")
2062 
2063  """
2064  # Add some non-QMTest attributes
2065  if "CMTCONFIG" in os.environ:
2066  self.WriteAnnotation("cmt.cmtconfig", os.environ["CMTCONFIG"])
2067  import socket
2068  self.WriteAnnotation("hostname", socket.gethostname())
2069  """
2070 
_EndDateTime
End time elements.
Definition: GaudiTest.py:2043

Member Function Documentation

def GaudiTest.XMLResultStream.Summarize (   self)

Definition at line 2220 of file GaudiTest.py.

2221  def Summarize(self):
2222 
2223  # Set the final end date time
2224  self._EndTestTime.text = str(self._endTime)
2225  self._EndDateTime.text = time.strftime("%b %d %H:%M %Z", time.localtime(self._endTime))
2226 
2227  # Compute the total duration
2228  if self._endTime and self._startTime:
2229  delta = self._endTime - self._startTime
2230  else:
2231  delta = 0
2232  self._ElapsedMinutes.text = str(delta/60)
2233 
2234  # Write into the file
2235  self._tree.write(self._xmlFile, "utf-8") #,True) in python 2.7 to add the xml header
2236 
def GaudiTest.XMLResultStream.WriteAnnotation (   self,
  key,
  value 
)

Definition at line 2071 of file GaudiTest.py.

2072  def WriteAnnotation(self, key, value):
2073  if key == "qmtest.run.start_time":
2074  if self._site.get("qmtest.run.start_time") is not None :
2075  return None
self._site.set(str(key),str(value))
def GaudiTest.XMLResultStream.WriteResult (   self,
  result 
)
Prepare the test result directory in the destination directory storing
into it the result fields.
A summary of the test result is stored both in a file in the test directory
and in the global summary file.

Definition at line 2076 of file GaudiTest.py.

2077  def WriteResult(self, result):
2078  """Prepare the test result directory in the destination directory storing
2079  into it the result fields.
2080  A summary of the test result is stored both in a file in the test directory
2081  and in the global summary file.
2082  """
2083  summary = {}
2084  summary["id"] = result.GetId()
2085  summary["outcome"] = result.GetOutcome()
2086  summary["cause"] = result.GetCause()
2087  summary["fields"] = result.keys()
2088  summary["fields"].sort()
2089 
2090 
2091  # Since we miss proper JSON support, I hack a bit
2092  for f in ["id", "outcome", "cause"]:
2093  summary[f] = str(summary[f])
2094  summary["fields"] = map(str, summary["fields"])
2095 
2096 
2097  # format
2098  # package_Test.xml
2099 
2100  if "qmtest.start_time" in summary["fields"]:
2101  haveStartDate = True
2102  else :
2103  haveStartDate = False
2104  if "qmtest.end_time" in summary["fields"]:
2105  haveEndDate = True
2106  else :
2107  haveEndDate = False
2108 
2109  # writing the start date time
2110  if haveStartDate:
2111  self._startTime = calendar.timegm(time.strptime(result["qmtest.start_time"], "%Y-%m-%dT%H:%M:%SZ"))
2112  if self._StartTestTime.text is None:
2113  self._StartDateTime.text = time.strftime("%b %d %H:%M %Z", time.localtime(self._startTime))
2114  self._StartTestTime.text = str(self._startTime)
2115  self._site.set("BuildStamp" , result["qmtest.start_time"] )
2116 
2117  #Save the end date time in memory
2118  if haveEndDate:
2119  self._endTime = calendar.timegm(time.strptime(result["qmtest.end_time"], "%Y-%m-%dT%H:%M:%SZ"))
2120 
2121 
2122  #add the current test to the test list
2123  tl = ET.Element("Test")
2124  tl.text = summary["id"]
2125  self._TestList.insert(0,tl)
2126 
2127  #Fill the current test
2128  Test = ET.Element("Test")
2129  if summary["outcome"] == "PASS":
2130  Test.set("Status", "passed")
2131  elif summary["outcome"] == "FAIL":
2132  Test.set("Status", "failed")
2133  elif summary["outcome"] == "SKIPPED" or summary["outcome"] == "UNTESTED":
2134  Test.set("Status", "skipped")
2135  elif summary["outcome"] == "ERROR":
2136  Test.set("Status", "failed")
2137  Name = ET.SubElement(Test, "Name",)
2138  Name.text = summary["id"]
2139  Results = ET.SubElement(Test, "Results")
2140 
2141  # add the test after the other test
2142  self._Testing.insert(3,Test)
2143 
2144  if haveStartDate and haveEndDate:
2145  # Compute the test duration
2146  delta = self._endTime - self._startTime
2147  testduration = str(delta)
2148  Testduration= ET.SubElement(Results,"NamedMeasurement")
2149  Testduration.set("name","Execution Time")
2150  Testduration.set("type","numeric/float" )
2151  value = ET.SubElement(Testduration, "Value")
2152  value.text = testduration
2153 
2154  #remove the fields that we store in a different way
2155  for n in ("qmtest.end_time", "qmtest.start_time", "qmtest.cause", "ExecTest.stdout"):
2156  if n in summary["fields"]:
2157  summary["fields"].remove(n)
2158 
2159  # Here we can add some NamedMeasurment which we know the type
2160  #
2161  if "ExecTest.exit_code" in summary["fields"] :
2162  summary["fields"].remove("ExecTest.exit_code")
2163  ExitCode= ET.SubElement(Results,"NamedMeasurement")
2164  ExitCode.set("name","exit_code")
2165  ExitCode.set("type","numeric/integer" )
2166  value = ET.SubElement(ExitCode, "Value")
2167  value.text = convert_xml_illegal_chars(result["ExecTest.exit_code"])
2168 
2169  TestStartTime= ET.SubElement(Results,"NamedMeasurement")
2170  TestStartTime.set("name","Start_Time")
2171  TestStartTime.set("type","String" )
2172  value = ET.SubElement(TestStartTime, "Value")
2173  if haveStartDate :
2174  value.text = escape_xml_illegal_chars(time.strftime("%b %d %H:%M %Z %Y", time.localtime(self._startTime)))
2175  else :
2176  value.text = ""
2177 
2178  TestEndTime= ET.SubElement(Results,"NamedMeasurement")
2179  TestEndTime.set("name","End_Time")
2180  TestEndTime.set("type","String" )
2181  value = ET.SubElement(TestEndTime, "Value")
2182  if haveStartDate :
2183  value.text = escape_xml_illegal_chars(time.strftime("%b %d %H:%M %Z %Y", time.localtime(self._endTime)))
2184  else :
2185  value.text = ""
2186 
2187  if summary["cause"]:
2188  FailureCause= ET.SubElement(Results,"NamedMeasurement")
2189  FailureCause.set("name", "Cause")
2190  FailureCause.set("type", "String" )
2191  value = ET.SubElement(FailureCause, "Value")
2192  value.text = escape_xml_illegal_chars(summary["cause"])
2193 
2194  #Fill the result
2195  fields = {}
2196  for field in summary["fields"] :
2197  fields[field] = ET.SubElement(Results, "NamedMeasurement")
2198  fields[field].set("type","String")
2199  fields[field].set("name",field)
2200  value = ET.SubElement(fields[field], "Value")
2201  # to escape the <pre></pre>
2202  if "<pre>" in result[field][0:6] :
2203  value.text = convert_xml_illegal_chars(result[field][5:-6])
2204  else :
2205  value.text = convert_xml_illegal_chars(result[field])
2206 
2207 
2208  if result.has_key("ExecTest.stdout" ) : #"ExecTest.stdout" in result :
2209  Measurement = ET.SubElement(Results, "Measurement")
2210  value = ET.SubElement(Measurement, "Value")
2211  if "<pre>" in result["ExecTest.stdout"][0:6] :
2212  value.text = convert_xml_illegal_chars(result["ExecTest.stdout"][5:-6])
2213  else :
2214  value.text = convert_xml_illegal_chars(result["ExecTest.stdout"])
2215 
2216 
2217  # write the file
2218  self._tree.write(self._xmlFile, "utf-8") #,True) in python 2.7 to add the xml header
2219 
def escape_xml_illegal_chars
Definition: GaudiTest.py:340
struct GAUDI_API map
Parametrisation class for map-like implementation.
def remove
Definition: install.py:153
def convert_xml_illegal_chars
Definition: GaudiTest.py:337

Member Data Documentation

GaudiTest.XMLResultStream._ElapsedMinutes
private

Definition at line 2050 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndDateTime
private

End time elements.

Definition at line 2043 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndTestTime
private

Definition at line 2046 of file GaudiTest.py.

GaudiTest.XMLResultStream._endTime
private

Definition at line 1977 of file GaudiTest.py.

GaudiTest.XMLResultStream._site
private

Definition at line 2000 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartDateTime
private

Definition at line 2035 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartTestTime
private

Definition at line 2037 of file GaudiTest.py.

GaudiTest.XMLResultStream._startTime
private

Definition at line 1976 of file GaudiTest.py.

GaudiTest.XMLResultStream._Testing
private

Definition at line 2032 of file GaudiTest.py.

GaudiTest.XMLResultStream._TestList
private

Definition at line 2040 of file GaudiTest.py.

GaudiTest.XMLResultStream._tree
private

Definition at line 1985 of file GaudiTest.py.

GaudiTest.XMLResultStream._xmlFile
private

Definition at line 1973 of file GaudiTest.py.

list GaudiTest.XMLResultStream.arguments
static
Initial value:
1 = [
2  qm.fields.TextField(
3  name = "dir",
4  title = "Destination Directory",
5  description = """The name of the directory.All results will be written to the directory indicated.""",
6  verbatim = "true",
7  default_value = ""),
8  qm.fields.TextField(
9  name = "prefix",
10  title = "Output File Prefix",
11  description = """The output file name will be the specified prefixfollowed by 'Test.xml' (CTest convention).""",
12  verbatim = "true",
13  default_value = ""),
14  ]

Definition at line 1947 of file GaudiTest.py.


The documentation for this class was generated from the following file: