Gaudi Framework, version v25r2

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

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.
 
 _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 1930 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 1957 of file GaudiTest.py.

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

Member Function Documentation

def GaudiTest.XMLResultStream.Summarize (   self)

Definition at line 2212 of file GaudiTest.py.

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

Definition at line 2063 of file GaudiTest.py.

2064  def WriteAnnotation(self, key, value):
2065  if key == "qmtest.run.start_time":
2066  if self._site.get("qmtest.run.start_time") is not None :
2067  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 2068 of file GaudiTest.py.

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

Member Data Documentation

GaudiTest.XMLResultStream._ElapsedMinutes
private

Definition at line 2042 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndDateTime
private

End time elements.

Definition at line 2035 of file GaudiTest.py.

GaudiTest.XMLResultStream._EndTestTime
private

Definition at line 2038 of file GaudiTest.py.

GaudiTest.XMLResultStream._endTime
private

Definition at line 1969 of file GaudiTest.py.

GaudiTest.XMLResultStream._site
private

Definition at line 1992 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartDateTime
private

Definition at line 2027 of file GaudiTest.py.

GaudiTest.XMLResultStream._StartTestTime
private

Definition at line 2029 of file GaudiTest.py.

GaudiTest.XMLResultStream._startTime
private

Definition at line 1968 of file GaudiTest.py.

GaudiTest.XMLResultStream._Testing
private

Definition at line 2024 of file GaudiTest.py.

GaudiTest.XMLResultStream._TestList
private

Definition at line 2032 of file GaudiTest.py.

GaudiTest.XMLResultStream._tree
private

Definition at line 1977 of file GaudiTest.py.

GaudiTest.XMLResultStream._xmlFile
private

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


The documentation for this class was generated from the following file:
Generated at Wed Jun 4 2014 14:49:06 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004