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

al_xipe
08.18.2007 b99b1dc96d69451e3e42ee1a77bbd1e8b3d3d5a2
first commit towards the support of the new report format and the integration of the code coverage for the functional tests
2 files modified
380 ■■■■■ changed files
opendj-sdk/opends/tests/functional-tests/shared/functions/topology.xml 207 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/shared/functions/utils.xml 173 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/shared/functions/topology.xml
@@ -26,7 +26,6 @@
 !      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 ! -->
<stax>
  <function name="createTopology">
    <function-prolog>
        This function creates the topology required by the Test Group/Suite.
@@ -53,7 +52,6 @@
    </function-map-args>
      
    <sequence>
      <script>
        if not sharedDataFolder and CurrentTestPath.has_key('group'):
          sharedDataFolder=CurrentTestPath['group']
@@ -69,26 +67,19 @@
            <message>
              'SINGLE instance deployment: read parameters from config.py'
            </message>
            <call function="'createInstance'"></call>
          <call function="'createInstance'" />
            <if expr="RC == 0 and initialiseInstance == True">
              <sequence>
                <!-- Load the server with default data -->
                <import machine="'%s' % (STAF_LOCAL_HOSTNAME)"
                  file="'%s/testcases/quickstart/quickstart.xml' % (TESTS_DIR)" />          
                <call function="'main_quickstart'"/>          
              </sequence>
            </if>             
          </sequence>
      <else>
          <!-- MULTIPLE instance deployment: read parameters from topologyDescFile -->
          <sequence>
            <message>
              'MULTIPLE instance deployment: read parameters from %s' % topologyDescFile
            </message>          
@@ -113,37 +104,33 @@
                    'dsJmxPort' : server.getJmxPort(),
                    'dsBindDN' : server.getRootDn(),
                    'dsBindPwd' : server.getRootPwd(),
                    'dsBaseDN' : server.getBaseDn() }
                    'dsBaseDN'  : server.getBaseDn()
                  }
                </call>
                
                <!-- Configure replication if required so by the server
                  !  (i.e. server is a changelog server and/or has synchronized suffixes) -->
                     !  (i.e. server is a changelog server and/or has synchronized suffixes)
                -->
                <if expr="server.requiresSynchronization()">
                  <sequence>                    
                    <message> 'Instance requires REPLICATION configuration.' </message>
                    <message>
                      'Instance requires REPLICATION configuration.'
                    </message>
                    <call function="'configureReplication'">
                      [server]
                    </call>                                 
                  </sequence>
                </if>                   
              </sequence>
            </iterate>
          </sequence>
      </else>         
      </if>     
    </sequence>  
  </function>
    
    
  <function name="prepareInstanceCreation">
    <function-prolog>
        This function prepares locally the necessary 
@@ -158,7 +145,6 @@
      </function-arg-def>
    </function-map-args>     
    <sequence>
      <!-- ON LOCAL HOST: get data ready to copy to remote host -->
        <script>
          testsGroupDir='%s/%s/%s' % (TESTS_DIR,relativeDataDir,groupDataDir)
@@ -174,9 +160,7 @@
        <!-- If the test data is already created then don't redo it -->        
        <if expr="RC == 48">
          <sequence>
          <!-- Locally copy static data files to temporary staging area -->
          <!-- LDIF (.ldif) test data files -->
            <message>
@@ -186,9 +170,9 @@
                { 'location'   : STAXServiceMachine,
                  'srcfolder'  : testsGroupDir,
                  'destfolder' : localTestsGroupDir,
                  'extension'  : 'ldif' }
              'extension'  : 'ldif'
            }
            </call>
          <!-- LDIF (.ldif) files for quickinstall -->
            <script>
              quickStartGroupDir='%s/%s/quickstart' % (TESTS_DIR,relativeDataDir)
@@ -201,7 +185,8 @@
                { 'location'   : STAXServiceMachine,
                  'srcfolder'  : quickStartGroupDir,
                  'destfolder' : quickStartLocalTestsGroupDir,
                  'extension'  : 'ldif' }
              'extension'  : 'ldif'
            }
            </call>
                
            <!-- PWD (.pwd) files -->
@@ -212,7 +197,8 @@
                { 'location'   : STAXServiceMachine,
                  'srcfolder'  : testsGroupDir,
                  'destfolder' : localTestsGroupDir,
                  'extension'  : 'pwd' }
              'extension'  : 'pwd'
            }
            </call>
      
            <!-- Archive (.gz) files -->
@@ -223,7 +209,8 @@
                { 'location'   : STAXServiceMachine,
                  'srcfolder'  : testsGroupDir,
                  'destfolder' : localTestsGroupDir,
                  'extension'  : 'gz' }
              'extension'  : 'gz'
            }
            </call>
            <!--  Delete the any existing testdata archive -->            
@@ -232,7 +219,8 @@
            </message>
            <call function="'deleteFile'">
              { 'location' : STAXServiceMachine,
                'filename' : '%s/testdata.zip' % logsTempDir }
              'filename' : '%s/testdata.zip' % logsTempDir
            }
            </call>
                                
            <!--  Zip up contents of tests directory -->
@@ -243,7 +231,8 @@
              { 'location'   : STAXServiceMachine,
                'zipfile'    : '%s/testdata.zip' % logsTempDir , 
                'folder'     : '%s' % localTestsGroupDir ,
                'relativeto' : logsTestDataDir }
              'relativeto' : logsTestDataDir
            }
            </call>     
    
            <message>
@@ -253,24 +242,21 @@
              { 'location'   : STAXServiceMachine,
                'zipfile'    : '%s/testdata.zip' % logsTempDir , 
                'folder'     : '%s' % quickStartLocalTestsGroupDir ,
                'relativeto' : logsTestDataDir }
              'relativeto' : logsTestDataDir
            }
            </call>
          </sequence>
        <else>
          <message>'Test data is already created.'</message>
          <message>
            'Test data is already created.'
          </message>
        </else>
        </if>                                                   
    </sequence>
  </function>   
    
    
    
  <function name="createInstance">
    <function-prolog>
        This function creates an instance on a given host.
@@ -329,14 +315,11 @@
      </function-arg-def>
    </function-map-args>
          
    <sequence>
      <message>
        'Create instance in host %s at directory %s' % (dsHost,dsDir)
      </message>
        
      <!-- ON REMOTE HOST: copy files, unzip, configure instance -->
      <!--- Delete folder if it exists on remote host-->
      <message>
@@ -344,7 +327,8 @@
      </message>
      <call function="'deleteFolder'">
        { 'location' : dsHost, 
          'foldername' : '%s/%s' % (dsDir,OPENDSNAME) }
          'foldername' : '%s/%s' % (dsDir,OPENDSNAME)
        }
      </call>
      <!--- Create folder on remote host-->
@@ -353,7 +337,8 @@
      </message>
      <call function="'createFolder'">
        { 'location' : dsHost, 
          'foldername' : '%s' % dsDir }
          'foldername' : '%s' % dsDir
        }
      </call>       
                              
      <!---   Copy staging data to remote host -->
@@ -363,7 +348,8 @@
      <call function="'copyFile'">
        { 'srcfile'    : '%s/testdata.zip' % logsTempDir,
          'destfile'   : '%s/testdata.zip' % dsDir,
          'remotehost' : dsHost }
          'remotehost' : dsHost
        }
      </call>
      <!---   Unzip contents of staging data on remote host -->
@@ -373,7 +359,8 @@
      <call function="'unZipFile'">
        { 'location' : dsHost, 
          'zipfile'  : '%s/testdata.zip' % dsDir, 
          'unzipdir' : dsDir }
          'unzipdir' : dsDir
        }
      </call>
      <!--- Install DS Copy zip file -->
@@ -383,7 +370,8 @@
      <call function="'copyFile'">
        { 'srcfile'    : '%s/%s' % (ZIPPATH,ZIPNAME), 
          'destfile'   : '%s/%s' % (dsDir,ZIPNAME),
          'remotehost' : dsHost }
          'remotehost' : dsHost
        }
      </call>
       <!--- Install DS Extract zip file -->
@@ -393,25 +381,41 @@
      <call function="'unZipFile'">
        { 'location' : dsHost, 
          'zipfile'  : '%s/%s' % (dsDir,ZIPNAME), 
          'unzipdir' : dsDir }
          'unzipdir' : dsDir
        }
      </call>
      <!-- fixMe: Windows Services are not enabled -->
      <if expr="isWindows">
        <script>
          enableWindowsService=''
        </script>
      <else>
        <script>
          enableWindowsService=''
        </script>
      </else>
      </if>
      <!-- configure the coverage dump file -->
      <script>
        mylog='::coverage: begin\n'
        emmaprops = '%s/%s/classes/emma.properties' % (dsDir,OPENDSNAME)
        group='emma'
        if CurrentTestPath['group']:
          group=CurrentTestPath['group'].strip()
        if os.path.exists('%s' % emmaprops):
          mylog+='::coverage: setting %s/%s.coverage to file %s\n' % (TMPDIR,group,emmaprops)
          coveragefh = open(emmaprops,'w')
          coveragefh.write('coverage.out.file=%s/%s.coverage\n' % (TMPDIR,group) )
          coveragefh.close()
      </script>
      <message>
        '%s' % mylog
      </message>
      <!--- Set up DS -->
      <message>
        'Set up DS on %s : %s/%s' % (dsHost,dsDir,OPENDSNAME)
@@ -425,12 +429,14 @@
          'dsBindDN'  : dsBindDN,
          'dsBindPwd' : dsBindPwd,
          'dsBaseDN'  : dsBaseDN,
          'dsEnableWindowsService' : enableWindowsService}
          'dsEnableWindowsService' : enableWindowsService
        }
      </call>
                        
      <call function="'checkRC'">
        { 'returncode' : RC ,
          'result'     : STAXResult }
          'result'     : STAXResult
        }
      </call>
      <if expr="returncode == 0">
@@ -443,16 +449,11 @@
          </message>
        </else>  
      </if>      
    </sequence> 
  </function>
  <function name="DEPRECATEDconfigureReplication">
    <function-prolog>
      This function configures replication in a given server.
@@ -489,27 +490,27 @@
      <call function="'copyFile'">
        { 'srcfile'    : filePath,
          'destfile'   : '%s/%s' % (dataDir,filename),
          'remotehost' : syncserver.getHostname() }
          'remotehost' : syncserver.getHostname()
        }
      </call>
      <!--- Add replication configuration entries to config.ldif in server -->
      <script>
        remoteFilePath = '%s/%s' % (dataDir, filename)
        syncserverPath = '%s/%s' % (syncserver.getDir(),OPENDSNAME)
      </script>
        
      <!--- Start DS -->                         
      <call function="'StartDsWithScript'">
        { 'location'  : syncserver.getHostname(),
           'dsPath' : syncserverPath }
           'dsPath'  : syncserverPath
         }
      </call>
      
      <call function="'checkRC'">
        { 'returncode' : RC ,
          'result'     : STAXResult }
          'result'     : STAXResult
        }
      </call>       
      <message>
@@ -523,15 +524,16 @@
          'dsInstancePort'   : syncserver.getPort(),
          'dsInstanceDn'    : syncserver.getRootDn(),
          'dsInstancePswd'  : syncserver.getRootPwd(),
          'entryToBeAdded'   : remoteFilePath }
          'entryToBeAdded' : remoteFilePath
        }
      </call>
    
      <call function="'checkRC'">
        { 'returncode' : RC,
          'result'     : STAXResult }
          'result'     : STAXResult
        }
      </call>           
      <!--- Stop DS -->                       
      <call function="'StopDsWithScript'">
        { 'location'  : syncserver.getHostname(),
@@ -539,21 +541,19 @@
          'dsPath' : syncserverPath,
          'dsPort'    : syncserver.getPort(),
          'dsBindDN'  : syncserver.getRootDn(),
          'dsBindPwd' : syncserver.getRootPwd() }
          'dsBindPwd' : syncserver.getRootPwd()
        }
      </call>
      
      <call function="'checkRC'">
        { 'returncode' : RC ,
          'result'     : STAXResult }
          'result'     : STAXResult
        }
      </call>                           
    </sequence> 
  </function>   
    
  <function name="configureReplication">
    <function-prolog>
      This function configures replication in a given server.
@@ -578,11 +578,11 @@
        syncserverPath = '%s/%s' % (syncserver.getDir(),OPENDSNAME)
      </script>
        
      <!--- Start DS -->                         
      <call function="'StartDsWithScript'">
        { 'location'  : syncserver.getHostname(),
           'dsPath' : syncserverPath }
           'dsPath'  : syncserverPath
         }
      </call>
      <message>
@@ -595,7 +595,8 @@
          'dsInstanceHost'    : syncserver.getHostname(),
          'dsInstancePort'   : syncserver.getPort(),
          'dsInstanceDn'    : syncserver.getRootDn(),
          'dsInstancePswd'  : syncserver.getRootPwd() }
          'dsInstancePswd' : syncserver.getRootPwd()
        }
      </call>
      <script>
@@ -608,7 +609,6 @@
          <message>
            'Create replication server listening on port: %s' % replicationServer.getPort()
          </message>
          <call function="'createReplicationServer'">
            { 'location' : syncserver.getHostname(),
              'dsPath' : syncserverPath,
@@ -618,18 +618,17 @@
              'dsInstancePswd'  : syncserver.getRootPwd(),
              'replicationPort'  : replicationServer.getPort(),
              'replicationServerId'  :  replicationServer.getId(),
              'replicationServerList'  :  replicationServer.getChangelogServerList() }
              'replicationServerList' : replicationServer.getChangelogServerList()
            }
          </call>          
        </sequence>                    
      </if>
      <iterate var="suffix" in="replicatedSuffixList" indexvar="i">
        <sequence>
          <message>
            'Create domain name for suffix: %s' % suffix.getSuffixDn()
          </message>
          <call function="'createMultimasterDomain'">
            { 'location' : syncserver.getHostname(),
              'dsPath' : syncserverPath,
@@ -640,12 +639,12 @@
              'domainName'  : 'SUFFIX-%s' % i,
              'replicationDn'  : suffix.getSuffixDn(),
              'serverId'  :  suffix.getId(),
              'replicationServerList'  :  suffix.getChangelogServerList() }
              'replicationServerList' : suffix.getChangelogServerList()
            }
          </call>                                  
        </sequence>
      </iterate>          
                        
      <!--- Stop DS -->                       
      <call function="'StopDsWithScript'">
        { 'location'  : syncserver.getHostname(),
@@ -653,9 +652,9 @@
          'dsPath' : syncserverPath,
          'dsPort'    : syncserver.getPort(),
          'dsBindDN'  : syncserver.getRootDn(),
          'dsBindPwd' : syncserver.getRootPwd() }
          'dsBindPwd' : syncserver.getRootPwd()
        }
      </call>               
    </sequence>       
  </function>   
                    
@@ -678,7 +677,6 @@
    </function-map-args>      
      
    <sequence>
      <message>
        'Parse file %s for topology parameters' % file
      </message>    
@@ -785,10 +783,7 @@
        
        f.close()
      </script>
    </sequence>
  </function>   
    
    
@@ -813,14 +808,11 @@
      </function-arg-def>
    </function-map-args>
          
    <sequence>
      <message>
        'Removing instance %s/%s on host %s' % (dsDir,OPENDSNAME,dsHost)
      </message>
        
      <!-- ON REMOTE HOST: remove files and folders -->
          <!--- Delete staging data file on remote host-->
          <message>
@@ -828,7 +820,8 @@
          </message>
          <call function="'deleteFile'">
            { 'location' : dsHost,
              'filename' : '%s/testdata.zip' % dsDir }
          'filename' : '%s/testdata.zip' % dsDir
        }
          </call>
    
          <!--- Delete staging data folder on remote host -->
@@ -837,11 +830,10 @@
          </message>
          <call function="'deleteFolder'">
            { 'location'   : dsHost,
              'foldername' : '%s/shared' % dsDir }
          'foldername' : '%s/shared' % dsDir
        }
          </call>
            
          <!--- Delete OPENDS zip file on remote host-->
          <message>
            'Delete OPENDS zip file %s/%s' % (dsDir,ZIPNAME)
@@ -851,12 +843,11 @@
              'filename' : '%s/%s' % (dsDir,ZIPNAME) }
          </call>                       
        
      <call function="'checkRC'">
        { 'returncode' : RC ,
          'result'     : STAXResult }
          'result'     : STAXResult
        }
      </call>
      <if expr="returncode == 0">
        <message>
          'Instance removed.'
@@ -867,14 +858,11 @@
          </message>
        </else>  
      </if>      
    </sequence> 
  </function>
    
  <function name="removeTopology">
    <function-prolog>
        This function removes the topology created for the Test Group/Suite.
@@ -888,30 +876,21 @@
        <function-arg-property name="type" value="boolean"/>            
      </function-arg-def>   
    </function-map-args>
    <sequence>
      <if expr="multipleInstanceTopology == False"> 
          <!-- SINGLE instance deployment: parameters read from config.py (done by default) -->
          <call function="'removeInstance'"></call>
        <call function="'removeInstance'" />
      <else>
        <!-- MULTIPLE instance deployment: parameters read from topologyDescFile -->
        <iterate var="server" in="_topologyServerList">
          <call function="'removeInstance'">
            { 'dsHost' : server.getHostname(),
              'dsDir' : server.getDir() }
                'dsDir'  : server.getDir()
              }
          </call>
        </iterate>
      </else>
      </if>
    </sequence>  
  </function>
</stax>
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 &gt; 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>    
      <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  = '      &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;log&gt;\n'
            xml += '%s' % self.log
            xml += '        &lt;/log&gt;\n'
            xml += '      &lt;/test&gt;\n'
            return xml
          def appendLog(self, log):
            self.log +='          %s&lt;br /&gt;\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 -->      
@@ -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>