From b99b1dc96d69451e3e42ee1a77bbd1e8b3d3d5a2 Mon Sep 17 00:00:00 2001
From: al_xipe <al_xipe@localhost>
Date: Wed, 08 Aug 2007 13:18:54 +0000
Subject: [PATCH] first commit towards the support of the new report format and the integration of the code coverage for the functional tests
---
opendj-sdk/opends/tests/functional-tests/shared/functions/utils.xml | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 170 insertions(+), 7 deletions(-)
diff --git a/opendj-sdk/opends/tests/functional-tests/shared/functions/utils.xml b/opendj-sdk/opends/tests/functional-tests/shared/functions/utils.xml
index 728a832..9ee729e 100755
--- a/opendj-sdk/opends/tests/functional-tests/shared/functions/utils.xml
+++ b/opendj-sdk/opends/tests/functional-tests/shared/functions/utils.xml
@@ -434,7 +434,14 @@
</function-prolog>
<function-no-args />
<sequence>
- <message>''</message>
+ <script>
+ testcaseStartTime=strftime("%Y%m%d@%H:%M:%S",localtime())
+ myLog = open('%s/my.log' % TMPDIR, 'a')
+ myLog.seek(0,2)
+ myLog.write('%s - starting testcase: %s\n' % (testcaseStartTime, STAXCurrentTestcase ) )
+ myLog.close()
+ </script>
+ <message level="'start'">'testcase: %s' % STAXCurrentTestcase</message>
<message>'****************************************************'</message>
<message>'*** STARTING TEST CASE %s.' % STAXCurrentTestcase</message>
<message>'***'</message>
@@ -450,7 +457,7 @@
<message>'***'</message>
<message>'*** ENDING TEST CASE %s.' % STAXCurrentTestcase</message>
<message>'****************************************************'</message>
- <message>''</message>
+ <message level="'stop'">'testcase: %s' % STAXCurrentTestcase</message>
</sequence>
</function>
@@ -499,16 +506,98 @@
numFail=int(STAFResult['numFails'])
else:
numFail=int(0)
+
</script>
<if expr="numFail > 0">
- <message>'## Test Verdict: FAIL ##'</message>
+ <message level="'status'">'## Test Verdict: FAIL ##'</message>
<else>
- <message>'## Test Verdict: PASS ##'</message>
+ <message level="'status'">'## Test Verdict: PASS ##'</message>
</else>
- </if>
-
+ </if>
<call function="'testCase_EndBanner'" />
+
+ <script>
+ testcaseEndTime = strftime("%Y%m%d@%H:%M:%S",localtime())
+ </script>
+ <call function="'queryLogs'">
+ { 'location' : STAXServiceMachine,
+ 'logname' : 'STAX_Job_%s_User' % STAXJobID,
+ 'startfrom' : testcaseStartTime,
+ 'endat' : testcaseEndTime }
+ </call>
+ <script>
+ class Test:
+ def __init__(self, group, suite, fullname, start, stop, failures):
+ self.log=''
+ self.group=group
+ self.suite=suite
+ self.fullname=fullname
+ self.start=start
+ self.stop=stop
+ tmp=fullname.split(":")
+ del tmp[0:2]
+ self.name=''.join(tmp)
+ self.duration = 0
+ if failures == 0:
+ self.result='pass'
+ else:
+ self.result='fail'
+
+ def toXML(self):
+ xml = ' <test>\n'
+ xml += ' <name>%s</name>\n' % self.name
+ xml += ' <group>%s</group>\n' % self.group
+ xml += ' <suite>%s</suite>\n' % self.suite
+ xml += ' <start>%s</start>\n' % self.start
+ xml += ' <stop>%s</stop>\n' % self.stop
+ xml += ' <result>%s</result>\n' % self.result
+ xml += ' <duration>%d</duration>\n' % self.duration
+ xml += ' <log>\n'
+ xml += '%s' % self.log
+ xml += ' </log>\n'
+ xml += ' </test>\n'
+ return xml
+
+ def appendLog(self, log):
+ self.log +=' %s<br />\n' % log
+
+ def getName(self):
+ return self.name
+
+ thisTest = Test(CurrentTestPath['group'],CurrentTestPath['suite'],STAXCurrentTestcase, testcaseStartTime,testcaseEndTime,numFail)
+
+ doLog = False
+ testlog=open('%s/test.log' % TMPDIR,'a')
+ testlog.seek(0,2)
+
+ # loop through the log lines
+ for element in STAFResult:
+ level=element['level']
+
+ # this test is BEFORE the append so we don't get the
+ # end of testcase banner in the XML but only the relevant data
+ if level == 'Stop':
+ doLog=False
+
+ # if the current element is actually this test's output then log it
+ if doLog == True:
+ thisTest.appendLog(element['message'])
+
+ # this test is AFTER the append log so we don't get the
+ # "starting testcase ..." header in the XML
+ if level == 'Start':
+ tmp = element['message'].split(':')
+ # this is a verification that we start logging for the right
+ # test case. this is especially useful for tests that execute
+ # within the same second (that is the resolution of the STAF
+ # log facility)
+ if tmp[3] == thisTest.getName():
+ doLog=True
+
+ testlog.write(thisTest.toXML())
+ testlog.close()
+ </script>
</sequence>
</function>
@@ -529,6 +618,18 @@
ThisGroupName=CurrentTestPath['group']
ThisSuiteName=CurrentTestPath['suite']
+
+ mylog='::coverage: begin\n'
+ if os.path.exists('%s/classes' % dsPath):
+ mylog+='::coverage: setting %s/%s.coverage to file %s/classes/emma.properties\n' % (TMPDIR,CurrentTestPath['group'],dsPath)
+ coveragefh = open( '%s/classes/emma.properties' % dsPath, 'w' )
+ coveragefh.write( 'coverage.out.file=%s/%s.coverage\n' % (TMPDIR,CurrentTestPath['group']) )
+ coveragefh.close()
+ coveragefh = open( '%s/classes/emma.properties' % dsPath, 'r' )
+ mylog+='::coverage:contents: %s' % coveragefh.read()
+ coveragefh.close()
+
+
</script>
<!-- Start time of test suite -->
@@ -608,7 +709,7 @@
if not CurrentTestPath.has_key('group'):
CurrentTestPath['group']='unknown-group'
- ThisGroupName=CurrentTestPath['group']
+ ThisGroupName=CurrentTestPath['group']
</script>
<message>'##### %s group preamble #####' % ThisGroupName</message>
@@ -956,4 +1057,66 @@
</sequence>
</function>
+ <function name="runCommand" >
+ <function-description>
+ A general wrapper to run a command without having to write a dedicated
+ function for it
+ </function-description>
+ <function-map-args>
+ <function-arg-def name="command" type="required">
+ <function-arg-description>
+ the command to run
+ </function-arg-description>
+ </function-arg-def>
+ <function-arg-def name="path" type="optional" default="'%s' % dsPath">
+ <function-arg-description>
+ the path where the command is to be run from
+ </function-arg-description>
+ </function-arg-def>
+ <function-arg-def name="argmunents" type="optional" default="''">
+ <function-arg-description>
+ the path where the command is to be found
+ </function-arg-description>
+ </function-arg-def>
+ <function-arg-def name="env"
+ type="optional"
+ default="['PATH=/bin:/usr/bin:%s' % dsPath, 'JAVA_HOME=%s' % JAVA_HOME]">
+ <function-arg-description>
+ the environment variables to set. The default set here should just
+ work for OpenDS commands
+ </function-arg-description>
+ </function-arg-def>
+ <function-arg-def name="location"
+ type="optional"
+ default="'%s' % STAXServiceMachine">
+ <function-arg-description>
+ Which machine should the command be executed on
+ </function-arg-description>
+ </function-arg-def>
+ </function-map-args>
+ <sequence>
+ <message>
+ '%s' % command
+ </message>
+
+ <process name="'run a system command'">
+ <location>'%s' % location</location>
+ <command>'%s' % command</command>
+ <parms>'%s' % arguments</parms>
+ <workdir>'%s' % path</workdir>
+ <envs>
+ '%s' % env
+ </envs>
+ <console use="'same'"/>
+ <stderr mode="'stdout'"/>
+ <returnstdout/>
+ </process>
+ <script>
+ STAXResult.replace('EMMA: collecting runtime coverage data ...\n','')
+ </script>
+ <return>
+ [ RC , STAXResult ]
+ </return>
+ </sequence>
+ </function>
</stax>
--
Gitblit v1.10.0