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 1940 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 1967 of file GaudiTest.py.

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

Member Function Documentation

def GaudiTest.XMLResultStream.Summarize (   self)

Definition at line 2222 of file GaudiTest.py.

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

Definition at line 2073 of file GaudiTest.py.

2074  def WriteAnnotation(self, key, value):
2075  if key == "qmtest.run.start_time":
2076  if self._site.get("qmtest.run.start_time") is not None :
2077  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 2078 of file GaudiTest.py.

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

GaudiTest.XMLResultStream._EndDateTime
private

End time elements.

Definition at line 2045 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndTestTime
private

Definition at line 2048 of file GaudiTest.py.

GaudiTest.XMLResultStream._endTime
private

Definition at line 1979 of file GaudiTest.py.

GaudiTest.XMLResultStream._site
private

Definition at line 2002 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartDateTime
private

Definition at line 2037 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartTestTime
private

Definition at line 2039 of file GaudiTest.py.

GaudiTest.XMLResultStream._startTime
private

Definition at line 1978 of file GaudiTest.py.

GaudiTest.XMLResultStream._Testing
private

Definition at line 2034 of file GaudiTest.py.

GaudiTest.XMLResultStream._TestList
private

Definition at line 2042 of file GaudiTest.py.

GaudiTest.XMLResultStream._tree
private

Definition at line 1987 of file GaudiTest.py.

GaudiTest.XMLResultStream._xmlFile
private

Definition at line 1975 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 1949 of file GaudiTest.py.


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