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

madiot
27.14.2010 e7e29543ddd6df23faa6e0630e963320eedf4e40
fix related to code coverage with EMMA
- serialize the startDS in the tools function startservers to avoid emma.properties generated file to overwrite each other
- skip the kill on OpenDS processes to avoid potential unexpected behaviour with code coverage
- generating a new Emma coverage.ec statistics file for each start of any given OpenDS instance

6 files modified
177 ■■■■■ changed files
opends/tests/staf-tests/shared/ant/tests.xml 2 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/functions/dsadm.xml 32 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/functions/tools.xml 94 ●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/functions/topology.xml 26 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/functions/utils.xml 21 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/tests/runTests.xml 2 ●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/ant/tests.xml
@@ -421,8 +421,6 @@
        <arg value="-ip" />
        <arg value="${tests.tmp.dir}/coverage-instr/${opends.name}/lib/OpenDS.jar:${tests.tmp.dir}/coverage-instr/${opends.name}/lib/extensions/snmp-mib2605.jar" />
    </java>
    <copy file="${tests.tmp.dir}/coverage-instr/${opends.name}/coverage.em"
          tofile="${tests.run.dir}/${tests.run.time}/coverage/coverage.em"/>
    <!-- Repackage the product with coverage enabled scripts -->
    <zip basedir="${tests.tmp.dir}/coverage-instr" destfile="${opends.dir}/${opends.name}.zip">
opends/tests/staf-tests/shared/functions/dsadm.xml
@@ -304,7 +304,37 @@
      <message>
        '%s %s' % (STAFCmd, STAFCmdParams)
      </message>
      <!-- configure the coverage dump file -->
      <script>
        mylog = "Didn't find the emma.jar file : '%s'\n" % os.path.join(dsPath,'lib','emma.jar')
        if os.path.exists(os.path.join(dsPath,'lib','emma.jar')):
          mylog= ''
          mylog=" ::coverage on\n"
          coveragePath = os.path.join(LOGS_ROOT,'coverage')
          if not os.path.exists(coveragePath):
            os.mkdir(coveragePath)
            mylog+=" ::mkdir %s on\n" % coveragePath
            # copying coverage.em in coveragePath
            import shutil
            mylog+=" ::copying %s to %s\n" % (os.path.join(dsPath,'coverage.em'),coveragePath)
            if not os.path.exists(os.path.join(dsPath,'coverage.em')):
              mylog+= " Didn't find %s to copy to %s\n" % (os.path.join(dsPath,'coverage.em'),coveragePath)
            else:
              shutil.copy(os.path.join(dsPath,'coverage.em'),coveragePath)
          coverageGroupPath=os.path.join(coveragePath,CurrentTestPath['group'])
          if not os.path.exists(coverageGroupPath):
            mylog+=" ::mkdir %s on\n" % (coverageGroupPath)
            os.mkdir(coverageGroupPath)
          existingECs=[cf for cf in os.listdir(coverageGroupPath) if cf.startswith('coverage') and cf.endswith('.ec')]
          newCoverageEC=os.path.join(coverageGroupPath,'coverage%s.ec' % len(existingECs))
          coveragefh = open( '%s/classes/emma.properties' % (dsPath), 'w' )
          coveragefh.write( 'coverage.out.file=%s\n' % (newCoverageEC) )
          coveragefh.write( 'verbosity.level=silent\n')
          coveragefh.write( 'coverage.out.merge=true\n')
          coveragefh.close()
          mylog+=" ::writing %s to %s/%s/classes/emma.properties\n" % (newCoverageEC, dsPath,OPENDSNAME)
      </script>
      <message>'%s' % mylog</message>
      <call function="'runCommand'">
        { 'location'  : location,
          'command'   : STAFCmd,
opends/tests/staf-tests/shared/functions/tools.xml
@@ -1043,33 +1043,77 @@
      
    <sequence>
      <!-- Start the servers in the list -->    
      <paralleliterate var="server" in="serverList">
      <script>
        # check if using coverage in which case we'll avoid doing parallele iterate
        coverage = False
        if os.path.exists(os.path.join(serverList[0].getDir(),OPENDSNAME,'lib','emma.jar')):
          coverage = True
        print 'tools.xml - coverage=%s' % coverage
      </script>
      <if expr="coverage == True">
        <sequence>
          <message>
            'Start DS on host  %s to run on port %s' % (server.getHostname(),server.getPort())
          </message>
          <!--- Start DS -->
          <call function="'StartDsWithScript'">
            { 'location' : server.getHostname(),
              'dsPath'   : '%s/%s' % (server.getDir(),OPENDSNAME)
            }
          </call>
          <!--- Check that DS started -->
          <call function="'isAlive'">
            { 'location'         : server.getHostname(),
              'dsPath'           : '%s/%s' % (server.getDir(),OPENDSNAME),
              'dsInstanceHost'   : server.getHostname(),
              'dsInstancePort'   : server.getPort(),
              'dsInstanceDn'     : server.getRootDn(),
              'dsInstancePswd'   : server.getRootPwd(),
              'noOfLoops'        : 10 ,
              'noOfMilliSeconds' : 2000
            }
          </call>
          <message>'starting servers in sequence using "iterate"'</message>
          <iterate var="server" in="serverList">
            <sequence>
              <message>
                'Start DS on host  %s to run on port %s' % (server.getHostname(),server.getPort())
              </message>
              <!--- Start DS -->
              <call function="'StartDsWithScript'">
                { 'location' : server.getHostname(),
                  'dsPath'   : '%s/%s' % (server.getDir(),OPENDSNAME)
                }
              </call>
              <!--- Check that DS started -->
              <call function="'isAlive'">
                { 'location'         : server.getHostname(),
                  'dsPath'           : '%s/%s' % (server.getDir(),OPENDSNAME),
                  'dsInstanceHost'   : server.getHostname(),
                  'dsInstancePort'   : server.getPort(),
                  'dsInstanceDn'     : server.getRootDn(),
                  'dsInstancePswd'   : server.getRootPwd(),
                  'noOfLoops'        : 10 ,
                  'noOfMilliSeconds' : 2000
                }
              </call>
            </sequence>
          </iterate>
        </sequence>
      </paralleliterate>
        <else>
          <sequence>
            <message>'starting servers in parallel using "paralleliterate"'</message>
            <paralleliterate var="server" in="serverList">
              <sequence>
                <message>
                  'Start DS on host  %s to run on port %s' % (server.getHostname(),server.getPort())
                </message>
                <!--- Start DS -->
                <call function="'StartDsWithScript'">
                  { 'location' : server.getHostname(),
                    'dsPath'   : '%s/%s' % (server.getDir(),OPENDSNAME)
                  }
                </call>
                <!--- Check that DS started -->
                <call function="'isAlive'">
                  { 'location'         : server.getHostname(),
                    'dsPath'           : '%s/%s' % (server.getDir(),OPENDSNAME),
                    'dsInstanceHost'   : server.getHostname(),
                    'dsInstancePort'   : server.getPort(),
                    'dsInstanceDn'     : server.getRootDn(),
                    'dsInstancePswd'   : server.getRootPwd(),
                    'noOfLoops'        : 10 ,
                    'noOfMilliSeconds' : 2000
                  }
                </call>
              </sequence>
            </paralleliterate>
          </sequence>
        </else>
      </if>
    </sequence>
  </function>
  
opends/tests/staf-tests/shared/functions/topology.xml
@@ -782,32 +782,6 @@
        </else>
      </if>
      
      <!-- configure the coverage dump file -->
      <script>
        mylog="::coverage - checking for %s/%s/lib/emma.jar\n" % (dsDir,OPENDSNAME)
        if os.path.exists(os.path.join(dsDir,OPENDSNAME,'lib','emma.jar')):
          mylog+=" ::coverage on\n"
          coveragePath = os.path.join(LOGS_ROOT,'coverage')
          if not os.path.exists(coveragePath):
            os.mkdir(coveragePath)
            mylog+=" ::mkdir %s on\n" % coveragePath
            # copying coverage.em in coveragePath
            import shutil
            shutil.copy(os.path.join(dsDir,OPENDSNAME,'coverage.em'),coveragePath)
          coverageGroupPath=os.path.join(coveragePath,CurrentTestPath['group'])
          if not os.path.exists(coverageGroupPath):
            os.mkdir(coverageGroupPath)
            mylog+=" ::mkdir %s on\n" % (coverageGroupPath)
          mylog+=" ::writing to %s/%s/classes/emma.properties" % (dsDir,OPENDSNAME)
          existingECs=[cf for cf in os.listdir(coverageGroupPath) if cf.startswith('coverage') and cf.endswith('.ec')]
          newCoverageEC=os.path.join(coverageGroupPath,'coverage%s.ec' % len(existingECs))
          coveragefh = open( '%s/%s/classes/emma.properties' % (dsDir,OPENDSNAME), 'w' )
          coveragefh.write( 'coverage.out.file=%s\n' % (newCoverageEC) )
          coveragefh.write( 'verbosity.level=silent\n')
          coveragefh.write( 'coverage.out.merge=true\n')
          coveragefh.close()
      </script>
      <message>mylog</message>
      <!--- Set up DS -->
      <message>
        'Set up DS on %s : %s/%s' % (dsHost,dsDir,OPENDSNAME)
opends/tests/staf-tests/shared/functions/utils.xml
@@ -1145,7 +1145,7 @@
        <sequence>
          <script>
            coveragePath=os.path.join(LOGS_ROOT,'coverage')
            coverageEm=os.path.join(coveragePath,'coverage.em')
            coverageEm=os.path.join(DIRECTORY_INSTANCE_DIR,OPENDSNAME,'coverage.em')
            ecPath=os.path.join(coveragePath,CurrentTestPath['group'])
            coverageEcs=[ os.path.join(ecPath,ec) for ec in os.listdir(ecPath) if ec.startswith('coverage') and ec.endswith('.ec')]
            coverageFiles=','.join(coverageEcs)
@@ -1969,13 +1969,18 @@
          pid = STAXResult[:-1]
          _args = '-9 %s' % pid
      </script>
      <call function="'runCommand'">
        { 'name'      : 'Kill DS server',
          'location'  : location,
          'command'   : _cmd,
          'arguments' : _args
        }
      </call>
      <if expr="os.path.exists(os.path.join(dsPath,'lib','emma.jar')) == False">
        <call function="'runCommand'">
          { 'name'      : 'Kill DS server',
            'location'  : location,
            'command'   : _cmd,
            'arguments' : _args
          }
        </call>
        <else>
          <message>'skip the killing of process when running with coverage to avoid data corruption'</message>
        </else>
      </if>
      <return>STAXResult</return>        
    </sequence>
  </function>
opends/tests/staf-tests/shared/tests/runTests.xml
@@ -139,7 +139,7 @@
          <call function="'runCommand'">
              { 'name'      : 'Generate global coverage xml report',
                'command'   : 'java',
                'arguments' : '-Xms64M -Xmx2048m -cp %s emma report -r xml,html -in %s/coverage.em,%s -Dreport.xml.out.file=%s/coverage.xml -Dreport.html.out.file=%s/coverage.html -sp %s' % (emmaJar,coveragePath,coverageFiles,coveragePath,coveragePath,srcArgs),
                'arguments' : '-Xms64M -Xmx2048m -cp %s emma report -r xml,html -in %s/%s/coverage.em,%s -Dreport.xml.out.file=%s/coverage.xml -Dreport.html.out.file=%s/coverage.html -sp %s' % (emmaJar,DIRECTORY_INSTANCE_DIR,OPENDSNAME,coverageFiles,coveragePath,coveragePath,srcArgs),
                'path'      : TMPDIR
              }
          </call>