mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

al_xipe
29.56.2007 1d86ae4d71b5d7e7b371844d776dc60cc10a7f33
1. added the ability to save the server error and access log.\n2. the testcases are now timed down to the second. subsecond timing would have been too platform(C library actually) dependent in python\n3. adapted the XSL to report the number of known issues\n4. Still need to fix coverage % XSL template\n5. other minor XSL fixes\n6. added windows new line support in environment.xml
4 files modified
287 ■■■■ changed files
opends/tests/functional-tests/shared/functions/environment.xml 2 ●●●●● patch | view | raw | blame | history
opends/tests/functional-tests/shared/functions/utils.xml 136 ●●●● patch | view | raw | blame | history
opends/tests/functional-tests/shared/xsl/my-report.xsl 106 ●●●● patch | view | raw | blame | history
opends/tests/functional-tests/testcases/sample/sample.xml 43 ●●●●● patch | view | raw | blame | history
opends/tests/functional-tests/shared/functions/environment.xml
@@ -134,10 +134,12 @@
          fileExt='.bat'
          fileFolder='bat'
          pathSeparator=';'
          newLine='\r\n'
        else:
          fileExt=''
          fileFolder='bin'
          pathSeparator=':'
          newLine='\n'
      </script>
      
      <!-- Set the signal handlers -->
opends/tests/functional-tests/shared/functions/utils.xml
@@ -553,8 +553,18 @@
    <function-no-args />
      <sequence>
        <script>
          import time
          testcaseStart=int(time.time())
          testcaseStartTime=strftime("%Y%m%d@%H:%M:%S",localtime())
          issuesList=[]
          errorlog=open('%s/%s/logs/errors' % (TMPDIR,OPENDSNAME),'a')
          errorlog.seek(0,2)
          errorlog.write('Begin testcase %s\n' % STAXCurrentTestcase)
          errorlog.close()
          accesslog=open('%s/%s/logs/access' % (TMPDIR,OPENDSNAME),'a')
          accesslog.seek(0,2)
          accesslog.write('Begin testcase %s\n' % STAXCurrentTestcase)
          accesslog.close()
        </script>
        <call function="'testCase_StartBanner'" />
    </sequence>
@@ -582,7 +592,7 @@
        SignalRaised='' 
      </script>
      <!-- Query the test case results -->
      <!-- Query the test case results -->
      <call function="'queryTestcase'" />
      
      <script>
@@ -616,9 +626,21 @@
          'endat'     : testcaseEndTime }
      </call>
      <script>
        import re
        class Matcher:
          def search(self, r,s):
            _tmp = re.compile(r)
            self.value = _tmp.match(s)
            return self.value
          def __getitem__(self, i):
            return self.value.group(i)
        class Test:
          def __init__(self, group, suite, fullname, start, stop, failures, successes, issues):
          def __init__(self, group, suite, fullname, start, stop, failures, successes, issues, duration):
            self.log=''
            self.error=''
            self.access=''
            self.group=group
            self.suite=suite
            self.fullname=fullname
@@ -630,7 +652,7 @@
              self.name=''.join(tmp)
            else:
              self.name=fullname
            self.duration = 0
            self.duration = duration
            if len(issues) == 0:
              if failures == 0:
                if successes == 0:
@@ -645,42 +667,55 @@
              
            
          def toXML(self):
            xml  = '      &lt;test&gt;\n'
            xml += '        &lt;name&gt;%s&lt;/name&gt;\n'         % self.name
            xml += '        &lt;group&gt;%s&lt;/group&gt;\n'       % self.group
            xml += '        &lt;suite&gt;%s&lt;/suite&gt;\n'       % self.suite
            xml += '        &lt;start&gt;%s&lt;/start&gt;\n'       % self.start
            xml += '        &lt;stop&gt;%s&lt;/stop&gt;\n'         % self.stop
            xml += '        &lt;result&gt;%s&lt;/result&gt;\n'     % self.result
            xml += '        &lt;duration&gt;%d&lt;/duration&gt;\n' % self.duration
            xml += '        &lt;issues&gt;\n'
            xml  = '      &lt;test&gt;%s' % newLine
            xml += '        &lt;name&gt;%s&lt;/name&gt;%s'         % (self.name,newLine)
            xml += '        &lt;group&gt;%s&lt;/group&gt;%s'       % (self.group,newLine)
            xml += '        &lt;suite&gt;%s&lt;/suite&gt;%s'       % (self.suite,newLine)
            xml += '        &lt;start&gt;%s&lt;/start&gt;%s'       % (self.start,newLine)
            xml += '        &lt;stop&gt;%s&lt;/stop&gt;%s'         % (self.stop,newLine)
            xml += '        &lt;result&gt;%s&lt;/result&gt;%s'     % (self.result,newLine)
            xml += '        &lt;duration&gt;%d&lt;/duration&gt;%s' % (self.duration,newLine)
            xml += '        &lt;issues&gt;%s'                      % newLine
            for issue in self.issues:
              xml += '          &lt;issue&gt;%s&lt;/issue&gt;\n' % issue
            xml += '        &lt;/issues&gt;\n'
            xml += '        &lt;log&gt;\n&lt;![CDATA['
            xml += '%s' % self.log
            xml += '        ]]&gt;&lt;/log&gt;\n'
            xml += '      &lt;/test&gt;\n'
              xml += '          &lt;issue&gt;%s&lt;/issue&gt;%s'   % (issue,newLine)
            xml += '        &lt;/issues&gt;%s'                     % newLine
            xml += '        &lt;log&gt;\n&lt;![CDATA[%s'           % newLine
            xml += self.log
            xml += '        ]]&gt;&lt;/log&gt;%s'                  % newLine
            xml += '        &lt;error&gt;\n&lt;![CDATA[%s'         % newLine
            xml += self.error
            xml += '        ]]&gt;&lt;/error&gt;%s'                % newLine
            xml += '        &lt;access&gt;\n&lt;![CDATA[%s'        % newLine
            xml += self.access
            xml += '        ]]&gt;&lt;/access&gt;%s'               % newLine
            xml += '      &lt;/test&gt;%s'                         % newLine
            return xml
          def appendLog(self, log):
          def appendLog(self, category, log):
            _leftPadding=''
            wrappedLog=''
            while len(log)>100:
              _logChunk=log[:100]
              log=log[100:]
              self.log+='%s%s\n' % (_leftPadding,_logChunk)
              wrappedLog+='%s%s%s' % (_leftPadding,_logChunk,newLine)
              _leftPadding='...    '
            self.log += '%s%s\n' % (_leftPadding,log)
            wrappedLog += '%s%s%s' % (_leftPadding,log,newLine)
            if category == 'access':
              self.access+=wrappedLog
            elif category == 'error':
              self.error+=wrappedLog
            else:
              self.log += wrappedLog
            
          def getName(self):
            return self.name
        thisTest = Test(CurrentTestPath['group'],CurrentTestPath['suite'],STAXCurrentTestcase, testcaseStartTime,testcaseEndTime,numFail,numPass,issuesList)
        testcaseStop=int(time.time())
        testcaseDuration=testcaseStop-testcaseStart
        thisTest = Test(CurrentTestPath['group'],CurrentTestPath['suite'],STAXCurrentTestcase, testcaseStartTime,testcaseEndTime,numFail,numPass,issuesList,testcaseDuration)
        doLog = False
        testlog=open('%s/tests-log.xml' % TMPDIR,'a')
        testlog.seek(0,2)
        # loop through the log lines
        for element in STAFResult:
          level=element['level'] 
@@ -692,7 +727,7 @@
          
          # if the current element is actually this test's output then log it
          if doLog == True:
            thisTest.appendLog(element['message'])
            thisTest.appendLog('test',element['message'])
            
          # this test is AFTER the append log so we don't get the
          # "starting testcase ..." header in the XML
@@ -704,7 +739,48 @@
            # log facility)
            if tmp[3] == thisTest.getName():
              doLog=True
        # parse the server's error log
        # TODO: figure out how to do this for multiple instance for the replication
        #       tests for example
        errorlog=open('%s/%s/logs/errors' % (TMPDIR,OPENDSNAME),'a')
        errorlog.seek(0,2)
        errorlog.write('End testcase %s\n' % STAXCurrentTestcase)
        errorlog.close()
        accesslog=open('%s/%s/logs/access' % (TMPDIR,OPENDSNAME),'a')
        accesslog.seek(0,2)
        accesslog.write('End testcase %s\n' % STAXCurrentTestcase)
        accesslog.close()
        errorlog=open('%s/%s/logs/errors' % (TMPDIR,OPENDSNAME), 'r')
        _log=''
        _doLog=False
        for line in errorlog.readlines():
          if line.startswith('End testcase %s' % STAXCurrentTestcase):
            _doLog=False
          if _doLog:
            _log+=line
          if line.startswith('Begin testcase %s' % STAXCurrentTestcase):
            _doLog=True
        errorlog.close()
        thisTest.appendLog('error', _log)
        accesslog=open('%s/%s/logs/access' % (TMPDIR,OPENDSNAME), 'r')
        _log=''
        _doLog=False
        for line in accesslog.readlines():
          if line.startswith('End testcase %s' % STAXCurrentTestcase):
            _doLog=False
          if _doLog:
            _log+=line
          if line.startswith('Begin testcase %s' % STAXCurrentTestcase):
            _doLog=True
        accesslog.close()
        thisTest.appendLog('access', _log)
        # save to test log
        testlog=open('%s/tests-log.xml' % TMPDIR,'a')
        testlog.seek(0,2)
        testlog.write(thisTest.toXML())
        testlog.close()
      </script>
opends/tests/functional-tests/shared/xsl/my-report.xsl
@@ -110,6 +110,7 @@
    <xsl:variable name="total"          select="count($tests)"/>
    <xsl:variable name="pass"           select="count($tests[result='pass'])"/>
    <xsl:variable name="fail"           select="count($tests[result='fail'])"/>
    <xsl:variable name="known"           select="count($tests[result='known'])"/>
    <xsl:variable name="unknown"        select="count($tests[result='inconclusive'])"/>
    <xsl:variable name="rate"           select="round((($pass div $total) * 100) - 0.5)"/>
    <!--- Test Report Header Variables -->
@@ -164,11 +165,12 @@
          <th align="center">Platform</th>
          <th align="center">JVM Version</th>
          <th align="center">JVM Vendor</th>
          <th align="center">Total</th>
          <th align="center">Pass</th>
          <th align="center">Fail</th>
          <th align="center">Inconclusive</th>
          <th align="center">Coverage</th>
          <th align="center" width="5%">Total</th>
          <th align="center" width="5%">Pass</th>
          <th align="center" width="5%">Fail</th>
          <th align="center" width="5%">Known Issues</th>
          <th align="center" width="5%">Inconclusive</th>
          <th align="center" width="5%">Coverage</th>
        </tr>
        <tr>
          <th align="center"><xsl:value-of select="$identification/buildid"/></th>
@@ -179,6 +181,7 @@
          <th align="center"><xsl:value-of select="$total"/></th>
          <th align="center"><xsl:value-of select="$pass"/></th>
          <th align="center"><xsl:value-of select="$fail"/></th>
          <th align="center"><xsl:value-of select="$known"/></th>
          <th align="center"><xsl:value-of select="$unknown"/></th>
          <th align="center">
            <a>
@@ -201,6 +204,7 @@
        <td width="5%">Success Rate</td>
        <td width="5%">Pass</td>
        <td width="5%">Fail</td>
        <td width="5%">Known</td>
        <td width="5%">Inc.</td>
        <td width="5%">Cov.</td>
      </tr>
@@ -213,6 +217,7 @@
          <xsl:variable name="group-total"    select="count($tests[group=$group])"/>
          <xsl:variable name="group-pass"    select="count($tests[group=$group][result='pass'])"/>
          <xsl:variable name="group-fail"    select="count($tests[group=$group][result='fail'])"/>
          <xsl:variable name="group-known"    select="count($tests[group=$group][result='known'])"/>
          <xsl:variable name="group-unknown" select="count($tests[group=$group][result='inconclusive'])"/>
          <xsl:variable name="group-rate"    select="round((($group-pass div $group-total) * 100) - 0.5)"/>
          <li>
@@ -255,6 +260,16 @@
                <td width="5%">
                  <xsl:attribute name="class">
                    <xsl:choose>
                      <xsl:when test="$group-known &gt; 0">
                        <xsl:value-of select="'warning'" />
                      </xsl:when>
                    </xsl:choose>
                  </xsl:attribute>
                  <xsl:value-of select="$group-known"/>
                </td>
                <td width="5%">
                  <xsl:attribute name="class">
                    <xsl:choose>
                      <xsl:when test="$group-unknown &gt; 0">
                        <xsl:value-of select="'warning'" />
                      </xsl:when>
@@ -262,6 +277,14 @@
                    </xsl:attribute>
                  <xsl:value-of select="$group-unknown"/>
                </td>
                <td width="5%">
                  <a>
                    <xsl:attribute name="href">
                      <xsl:value-of select="concat(concat('coverage/',$group),'/coverage.html')"/>
                    </xsl:attribute>
                    <xsl:value-of select="/qa/functional-tests/results/group[name='$group']/coverage"/>%
                  </a>
                </td>
              </tr>
            </table>
            <ul>
@@ -271,6 +294,7 @@
                  <xsl:variable name="suite-total"   select="count($tests[group=$group][suite=$suite])"/>
                  <xsl:variable name="suite-pass"    select="count($tests[group=$group][suite=$suite][result='pass'])"/>
                  <xsl:variable name="suite-fail"    select="count($tests[group=$group][suite=$suite][result='fail'])"/>
                  <xsl:variable name="suite-known"    select="count($tests[group=$group][suite=$suite][result='known'])"/>
                  <xsl:variable name="suite-unknown" select="count($tests[group=$group][suite=$suite][result='inconclusive'])"/>
                  <xsl:variable name="suite-rate"    select="round((($suite-pass div $suite-total) * 100) - 0.5)"/>
                  <li>
@@ -316,6 +340,16 @@
                        <td width="5%">
                          <xsl:attribute name="class">
                            <xsl:choose>
                              <xsl:when test="$suite-known &gt; 0">
                                <xsl:value-of select="'warning'" />
                              </xsl:when>
                            </xsl:choose>
                          </xsl:attribute>
                          <xsl:value-of select="$suite-known"/>
                        </td>
                        <td width="5%">
                          <xsl:attribute name="class">
                            <xsl:choose>
                              <xsl:when test="$suite-unknown &gt; 0">
                                <xsl:value-of select="'warning'" />
                              </xsl:when>
@@ -366,8 +400,26 @@
                            </tr>
                          </table>
                          <ul>
                            <li>
                              <pre><xsl:value-of select="log" /></pre>
                            <li>Test Log<br />
                              <ul>
                                <li>
                                  <pre><xsl:value-of select="log" /></pre>
                                </li>
                              </ul>
                            </li>
                            <li>Server access Log<br />
                              <ul>
                                <li>
                                  <pre><xsl:value-of select="access" /></pre>
                                </li>
                              </ul>
                            </li>
                            <li>Server error Log<br />
                              <ul>
                                <li>
                                  <pre><xsl:value-of select="error" /></pre>
                                </li>
                              </ul>
                            </li>
                          </ul>
                        </li>
@@ -388,10 +440,12 @@
      <xsl:variable name="group" select="group"/>
      <xsl:if test="generate-id(.)=generate-id($tests[group=$group])">
        <xsl:variable name="group-total"    select="count($tests[group=$group])"/>
        <xsl:variable name="group-pass"    select="count($tests[group=$group][result='pass'])"/>
        <xsl:variable name="group-fail"    select="count($tests[group=$group][result='fail'])"/>
        <xsl:variable name="group-unknown" select="count($tests[group=$group][result='inconclusive'])"/>
        <xsl:variable name="group-rate"    select="round((($group-pass div $group-total) * 100) - 0.5)"/>
        <xsl:variable name="group-pass"     select="count($tests[group=$group][result='pass'])"/>
        <xsl:variable name="group-fail"     select="count($tests[group=$group][result='fail'])"/>
        <xsl:variable name="group-known"    select="count($tests[group=$group][result='known'])"/>
        <xsl:variable name="group-unknown"  select="count($tests[group=$group][result='inconclusive'])"/>
        <xsl:variable name="group-rate"     select="round((($group-pass div $group-total) * 100) - 0.5)"/>
        <xsl:variable name="group-coverage" select="coverage"/>
        <p>
          <table>
            <tr>
@@ -399,6 +453,7 @@
              <th width="5%">Success Rate</th>
              <th width="5%">Pass</th>
              <th width="5%">Fail</th>
              <th width="5%">Known</th>
              <th width="5%">Inc.</th>
              <th width="5%">Cov.</th>
            </tr>
@@ -427,28 +482,25 @@
              <td align="center"><xsl:value-of select="$group-rate"/>%</td>
              <td align="center"><xsl:value-of select="$group-pass"/></td>
              <td align="center"><xsl:value-of select="$group-fail"/></td>
              <td align="center"><xsl:value-of select="$group-known"/></td>
              <td align="center"><xsl:value-of select="$group-unknown"/></td>
              <xsl:for-each select="$groups">
                <xsl:variable name="thisgroup" select="name"/>
                <xsl:if test="generate-id(.)=generate-id($groups[name=$thisgroup])">
                  <td>
                    <a>
                      <xsl:attribute name="href">
                        <xsl:value-of select="concat(concat('coverage/',$group),'/coverage.html')"/>
                      </xsl:attribute>
                      <xsl:value-of select="group"/>
                      <xsl:value-of select="coverage"/>%
                    </a>
                  </td>
                </xsl:if>
              </xsl:for-each>
              <td>
                <a>
                  <xsl:attribute name="href">
                    <xsl:value-of select="concat(concat('coverage/',$group),'/coverage.html')"/>
                  </xsl:attribute>
                  <xsl:variable name="group-cov" select="/qa/functional-tests/group[name=$group]" />
                  <xsl:value-of select="$group-cov/coverage"/>%
                </a>
              </td>
            </tr>
            <xsl:for-each select="$tests[group=$group]">
              <xsl:variable name="suite" select="suite"/>
              <xsl:if test="generate-id(.)=generate-id($tests[group=$group][suite=$suite])">
                <xsl:variable name="suite-total"    select="count($tests[group=$group][suite=$suite])"/>
                <xsl:variable name="suite-total"   select="count($tests[group=$group][suite=$suite])"/>
                <xsl:variable name="suite-pass"    select="count($tests[group=$group][suite=$suite][result='pass'])"/>
                <xsl:variable name="suite-fail"    select="count($tests[group=$group][suite=$suite][result='fail'])"/>
                <xsl:variable name="suite-known"   select="count($tests[group=$group][suite=$suite][result='known'])"/>
                <xsl:variable name="suite-unknown" select="count($tests[group=$group][suite=$suite][result='inconclusive'])"/>
                <xsl:variable name="suite-rate"    select="round((($suite-pass div $suite-total) * 100) - 0.5)"/>
                <tr>
@@ -460,6 +512,7 @@
                        <th width="5%">Success rate</th>
                        <th width="5%">Pass</th>
                        <th width="5%">Fail</th>
                        <th width="5%">Known</th>
                        <th width="5%">Inc.</th>
                      </tr>
                      <tr>
@@ -488,6 +541,7 @@
                        <td><xsl:value-of select="$suite-rate"/>%</td>
                        <td><xsl:value-of select="$suite-pass"/></td>
                        <td><xsl:value-of select="$suite-fail"/></td>
                        <td><xsl:value-of select="$suite-known"/></td>
                        <td><xsl:value-of select="$suite-unknown"/></td>
                      </tr>
                    </table>
opends/tests/functional-tests/testcases/sample/sample.xml
@@ -55,7 +55,7 @@
             -->
            <call function="setupStep" />
          </iterate>
          <iterate in="['passing_test']" var="testStep">
          <iterate in="['sample_test','knownIssue_test','passing_test','failing_test']" var="testStep">
            <!-- the sequence tag is superfluous here since there is only a 
                 single instruction to execute within the iterate block 
             -->
@@ -126,6 +126,47 @@
      </sequence>
    </block>
  </function>
  <!-- the test -->
  <function name="knownIssue_test">
    <!---
      Place test-specific test information here.
      The tag, TestMarker, must be the same as the tag, TestSuiteName.
      #@TestMarker                Sample
      #@TestName                  sample_test
      #@TestIssue                 xyz
      #@TestPurpose               Illustrate how to issue a query on OpenDS
      #@TestPreamble              none
      #@TestStep                  Fetch all the entries in the server
      #@TestPostamble             none
      #@TestResult                Success if OpenDS returns 0
    -->
    <block name="'knownIssue_test'">
      <sequence>
        <script>
          CurrentTestPath['suite']= 'search'
        </script>
        <testcase name="getTestCaseName(STAXCurrentBlock)">
          <sequence>
            <call function="'testCase_Preamble'" />
            <!-- search for an entry that does not exist -->
            <call function="'SearchObject'">
            { 'dsInstanceHost'   : DIRECTORY_INSTANCE_HOST ,
              'dsInstancePort'   : DIRECTORY_INSTANCE_PORT ,
              'dsInstanceDn'     : DIRECTORY_INSTANCE_DN   ,
              'dsInstancePswd'   : DIRECTORY_INSTANCE_PSWD ,
              'dsBaseDN'         : DIRECTORY_INSTANCE_SFX  ,
              'dsFilter'         : 'uid=wronguid'         }
            </call>
            <script>
              knownIssue(828)
            </script>
            <call function="'testCase_Postamble'" />
          </sequence>
        </testcase>
      </sequence>
    </block>
  </function>
  
  <!-- the dummy failing test -->
  <function name="failing_test">