From 2ce3837f88119be9e503f704f7fea31fda32420a Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Mon, 31 May 2010 08:59:00 +0000
Subject: [PATCH] Improve shared and functional tests, as well as code coverage.

---
 opends/tests/staf-tests/shared/ant/tests.xml                           |   24 ++---
 opends/tests/staf-tests/shared/functions/topology.xml                  |   64 +++++++---------
 opends/tests/staf-tests/functional-tests/testcases/setup/import.xml    |   10 +
 opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_setup.xml |   38 +++++++++
 opends/tests/staf-tests/shared/functions/dsadm.xml                     |    7 -
 opends/tests/staf-tests/shared/functions/snmp.xml                      |   46 ++++++++++-
 6 files changed, 127 insertions(+), 62 deletions(-)

diff --git a/opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_setup.xml b/opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_setup.xml
index 9dacad3..485bb89 100755
--- a/opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_setup.xml
+++ b/opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_setup.xml
@@ -558,13 +558,20 @@
                 if WC_TYPE == 'tomcat':
                   destWebXml = os.path.join(WC_DIRECTORY, 'apache-%s-%s' % (WC_TYPE, WC_VERSION), 'webapps',
                                             'dsml', 'WEB-INF', 'web.xml')
+                  destEmmaProp = os.path.join(WC_DIRECTORY, 'apache-%s-%s' % (WC_TYPE, WC_VERSION), 'webapps',
+                                            'dsml', 'WEB-INF', 'classes', 'emma.properties')
                 elif WC_TYPE == 'glassfish':
                   destWebXml = os.path.join(WC_DIRECTORY, 'glassfishv3', 'glassfish',
                                             'domains', 'domain1', 'applications',
                                             'dsml', 'WEB-INF', 'web.xml')
+                  destEmmaProp = os.path.join(WC_DIRECTORY, 'glassfishv3', 'glassfish',
+                                            'domains', 'domain1', 'applications',
+                                            'dsml', 'WEB-INF', 'classes', 'emma.properties')
                 elif WC_TYPE == 'sunwebserver':
                   destWebXml = os.path.join(WC_DIRECTORY, '%s-%s' % (WC_TYPE, WC_VERSION), 'https-%s' % STAF_REMOTE_HOSTNAME,
                                  'generated', STAF_REMOTE_HOSTNAME, 'dsml', 'WEB-INF', 'web.xml')
+                  destEmmaProp = os.path.join(WC_DIRECTORY, '%s-%s' % (WC_TYPE, WC_VERSION), 'https-%s' % STAF_REMOTE_HOSTNAME,
+                                 'generated', STAF_REMOTE_HOSTNAME, 'dsml', 'WEB-INF', 'classes', 'emma.properties')
 
                 nbLoop = 10
                 loopSleep = 1000 # 1000 millisecondes
@@ -603,6 +610,37 @@
                     'result'     : STAXResult
                     }
                   </call>
+
+                  <script>
+                    ecPath = os.path.join(remote.temp,'coverage',CurrentTestPath['group'],'coverage_dsml.ec')
+
+                    coveragefh = open( '%s/emma_dsml.properties' % local.temp, 'w')
+                    coveragefh.write( 'coverage.out.file=%s\n' % ecPath )
+                    coveragefh.write( 'verbosity.level=silent\n')
+                    coveragefh.write( 'coverage.out.merge=true\n')
+                    coveragefh.close()
+                  </script>
+
+                  <message>
+                    'PATH ORIG %s/emma_dsml.properties' % local.temp
+                  </message>
+                  <message>
+                    'PATH DEST %s' % destEmmaProp
+                  </message>
+                  <call function="'copyFile'">
+                    { 'location'   : STAXServiceMachine,
+                      'remotehost' : '%s' % STAF_REMOTE_HOSTNAME,
+                      'srcfile'    : '%s/emma_dsml.properties' % local.temp,
+                      'destfile'   : destEmmaProp
+                     }
+                  </call>
+                  <call function="'checktestRC'">
+                    {
+                    'returncode' : RC ,
+                    'result'     : STAXResult
+                    }
+                  </call>
+
                   <call function="'stopWebcontainerWithScript'"/>
                   <call function="'startWebcontainerWithScript'"/>
                 </sequence>
diff --git a/opends/tests/staf-tests/functional-tests/testcases/setup/import.xml b/opends/tests/staf-tests/functional-tests/testcases/setup/import.xml
index cb69daa..128ad38 100644
--- a/opends/tests/staf-tests/functional-tests/testcases/setup/import.xml
+++ b/opends/tests/staf-tests/functional-tests/testcases/setup/import.xml
@@ -23,7 +23,7 @@
  !
  ! CDDL HEADER END
  !
- !      Copyright 2008-2009 Sun Microsystems, Inc.
+ !      Copyright 2008-2010 Sun Microsystems, Inc.
  ! -->
 <stax>
   
@@ -482,8 +482,12 @@
           </call>
 
           <script>
-            nb = len(STAFResult)
-            ct = (STAFResult[0] == 'lib')
+            res = STAFResult
+            if 'coverage.ec' in res:
+              res.remove('coverage.ec')
+
+            nb = len(res)
+            ct = (res[0] == 'lib')
             a = ' '
           </script>
 
diff --git a/opends/tests/staf-tests/shared/ant/tests.xml b/opends/tests/staf-tests/shared/ant/tests.xml
index a79b057..04da670 100644
--- a/opends/tests/staf-tests/shared/ant/tests.xml
+++ b/opends/tests/staf-tests/shared/ant/tests.xml
@@ -462,8 +462,10 @@
 
     <java classpath="${temp.dir}/coverage-instr/dsml/WEB-INF/lib/emma.jar"
           classname="emma" fork="true">
-        <jvmarg value="-Demma.metadata.out.file=${temp.dir}/coverage-instr/dsml/WEB-INF/lib/coverage.em" />
+        <jvmarg value="-Demma.metadata.out.file=${temp.dir}/coverage-instr/opends/${opends.name}/coverage.em" />
         <arg value="instr" />
+        <arg value="-merge" />
+        <arg value="yes" />
         <arg value="-m" />
         <arg value="overwrite" />
         <arg value="-ix" />
@@ -483,26 +485,22 @@
       <matches string="${product.name}" pattern="^OpenDS ."/>
       <then>
         <!-- The war file is not in the opends archive, so we need to repackage the war file -->
-        <zip basedir="${temp.dir}/coverage-instr/dsml" destfile="${opends.dir}/${opends.name}-DSML.war">
-        <zipfileset dir="${temp.dir}/coverage-instr/dsml"
-                    includes="WEB-INF/**,META-INF/**"/>
-        </zip>
+        <zip basedir="${temp.dir}/coverage-instr/dsml" destfile="${opends.dir}/${opends.name}-DSML.war"/>
       </then>
       <else>
         <!-- The war file is in the opends archive, so we need to replace the war file -->
         <delete file="${temp.dir}/coverage-instr/opends/${opends.name}/addons/DSML.war"/>
-        <zip basedir="${temp.dir}/coverage-instr/dsml" destfile="${temp.dir}/coverage-instr/opends/${opends.name}/addons/DSML.war">
-        <zipfileset dir="${temp.dir}/coverage-instr/dsml"
-                    includes="WEB-INF/**,META-INF/**"/>
-        </zip>
+        <zip basedir="${temp.dir}/coverage-instr/dsml" destfile="${temp.dir}/coverage-instr/opends/${opends.name}/addons/DSML.war"/>
       </else>
     </if>
 
     <!-- Repackage OpenDS the product with coverage enabled scripts -->
-    <zip basedir="${temp.dir}/coverage-instr/opends" destfile="${opends.dir}/${opends.name}.zip">
-    <zipfileset dir="${temp.dir}/coverage-instr/opends"
-                includes="${opends.name}/setup,${opends.name}/uninstall,${opends.name}/upgrade,${opends.name}/bin/*,${opends.name}/lib/*.sh"
-                filemode="755" dirmode="755" />
+    <zip basedir="${temp.dir}/coverage-instr/opends"
+         destfile="${opends.dir}/${opends.name}.zip"
+         excludes="${opends.name}/setup,${opends.name}/uninstall,${opends.name}/upgrade,${opends.name}/bin/*,${opends.name}/lib/*.sh">
+      <zipfileset dir="${temp.dir}/coverage-instr/opends"
+                  includes="${opends.name}/setup,${opends.name}/uninstall,${opends.name}/upgrade,${opends.name}/bin/*,${opends.name}/lib/*.sh"
+                  filemode="755" dirmode="755"/>
     </zip>
 
     <delete dir="${temp.dir}/coverage-instr"/>
diff --git a/opends/tests/staf-tests/shared/functions/dsadm.xml b/opends/tests/staf-tests/shared/functions/dsadm.xml
index 33470fa..d3abf41 100755
--- a/opends/tests/staf-tests/shared/functions/dsadm.xml
+++ b/opends/tests/staf-tests/shared/functions/dsadm.xml
@@ -322,17 +322,12 @@
           </script>
 
           <call function="'createFolder'">
-            { 'location'   : STAF_REMOTE_HOSTNAME,
+            { 'location'   : STAXServiceMachine,
               'foldername' : resultsCoveragePath
             }
           </call>
           <call function="'createFolder'">
             { 'location'   : STAF_REMOTE_HOSTNAME,
-              'foldername' : resultsPath
-            }
-          </call>
-          <call function="'createFolder'">
-            { 'location'   : STAF_REMOTE_HOSTNAME,
               'foldername' : remoteCoveragePath
             }
           </call>
diff --git a/opends/tests/staf-tests/shared/functions/snmp.xml b/opends/tests/staf-tests/shared/functions/snmp.xml
index b0b9cc2..c51915e 100755
--- a/opends/tests/staf-tests/shared/functions/snmp.xml
+++ b/opends/tests/staf-tests/shared/functions/snmp.xml
@@ -118,6 +118,26 @@
     </function-map-args>
 
     <sequence>
+      <!-- Check if 'emma.jar' exists -->
+      <call function="'GetEntry'">
+        {
+        'location'  : STAF_REMOTE_HOSTNAME ,
+        'entry'     : '%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME) ,
+        'attribute' : 'TYPE'
+        }
+      </call>
+      <if expr="RC != 48">
+        <!-- 'emma.jar' exists -->
+        <script>
+          emma_jarfile='%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
+        </script>
+        <else>
+          <script>
+            emma_jarfile=None
+          </script>
+        </else>
+      </if>
+
       <!-- Build the command -->
       <script>
         STAFCmdParamsList=[]
@@ -169,8 +189,7 @@
         snmpPath='%s/snmp' % remote.java
         jdmk_jarfile='%s/jdmkrt.jar' % snmpPath
 
-        emma_jarfile='%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
-        if os.path.exists(emma_jarfile):
+        if emma_jarfile:
           cp = 'CLASSPATH=%s%s%s%s%s%s.' \
           % (opends_jarfile,separator,jdmk_jarfile,separator,emma_jarfile,separator)
         else:
@@ -289,6 +308,26 @@
     </function-map-args>
 
     <sequence>
+      <!-- Check if 'emma.jar' exists -->
+      <call function="'GetEntry'">
+        {
+        'location'  : STAF_REMOTE_HOSTNAME ,
+        'entry'     : '%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME) ,
+        'attribute' : 'TYPE'
+        }
+      </call>
+      <if expr="RC != 48">
+        <!-- 'emma.jar' exists -->
+        <script>
+          emma_jarfile='%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
+        </script>
+        <else>
+          <script>
+            emma_jarfile=None
+          </script>
+        </else>
+      </if>
+
       <!-- Build the command -->
       <script>
         STAFCmdParamsList=[]
@@ -337,8 +376,7 @@
         snmpPath='%s/snmp' % remote.java
         jdmk_jarfile='%s/jdmkrt.jar' % snmpPath
 
-        emma_jarfile='%s/%s/lib/emma.jar' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
-        if os.path.exists(emma_jarfile):
+        if emma_jarfile:
           cp = 'CLASSPATH=%s%s%s%s%s%s.' \
           % (opends_jarfile,separator,jdmk_jarfile,separator,emma_jarfile,separator)
         else:
diff --git a/opends/tests/staf-tests/shared/functions/topology.xml b/opends/tests/staf-tests/shared/functions/topology.xml
index 5fb07b8..bb2a211 100755
--- a/opends/tests/staf-tests/shared/functions/topology.xml
+++ b/opends/tests/staf-tests/shared/functions/topology.xml
@@ -753,19 +753,36 @@
           'unzipdir' : dsDir
         }
       </call>
-      
-      <!--- Install DS Copy zip file -->
-      <message>
-        'Copy DS zip archive %s/%s to %s' % (local.temp,ZIPNAME,dsHost)
-      </message>
-      <call function="'copyFile'">
-        { 'srcfile'    : '%s/%s' % (ZIPPATH,ZIPNAME),
-          'destfile'   : '%s/%s' % (dsDir,ZIPNAME),
-          'remotehost' : dsHost
+
+      <!-- Check if DS Copy zip exists -->
+      <call function="'GetEntry'">
+        {
+        'location'  : dsHost,
+        'entry'     : '%s/%s' % (dsDir,ZIPNAME),
+        'attribute' : 'TYPE'
         }
       </call>
-      
-       <!--- Install DS Extract zip file -->
+      <if expr="RC == 48">
+        <sequence>
+          <!--- Copy DS Copy zip file -->
+          <message>
+            'Copy DS zip archive %s/%s to %s' % (ZIPPATH,ZIPNAME,dsHost)
+          </message>
+          <call function="'copyFile'">
+            { 'srcfile'    : '%s/%s' % (ZIPPATH,ZIPNAME),
+              'destfile'   : '%s/%s' % (dsDir,ZIPNAME),
+              'remotehost' : dsHost
+            }
+          </call>
+        </sequence>
+        <else>
+          <message>
+            'DS zip archive %s/%s already exists, nothing to do' % (dsDir,ZIPNAME)
+          </message>
+        </else>
+      </if>
+
+      <!--- Install DS Extract zip file -->
       <message>
         'Extract DS zip archive to %s on %s' % (dsDir,dsHost)
       </message>
@@ -1847,31 +1864,6 @@
           'filename' : '%s/testdata.zip' % dsDir 
         }
       </call>
-      
-      <!--- Delete OPENDS zip file on remote host-->
-      <message>
-        'Delete OPENDS zip file %s/%s' % (dsDir,ZIPNAME)
-      </message>
-      <call function="'deleteFile'">
-        { 'location' : dsHost, 
-          'filename' : '%s/%s' % (dsDir,ZIPNAME) }
-      </call>
-      
-      <call function="'checkRC'">
-        { 'returncode' : RC ,
-          'result'     : STAXResult 
-        }
-      </call>
-      <if expr="returncode == 0">
-        <message>
-          'Instance removed.'
-        </message>
-        <else>
-          <message>
-            'Failed to remove instance.'
-          </message>
-        </else>
-      </if>
     </sequence>
   </function>
   

--
Gitblit v1.10.0