From 4b9586249c8fb3e6a792ea0e75d750ed4985543f Mon Sep 17 00:00:00 2001
From: Christophe Sovant <christophe.sovant@forgerock.com>
Date: Mon, 03 Mar 2008 18:58:35 +0000
Subject: [PATCH] Add CompareFile function
---
opends/tests/functional-tests/staf-installer.xml | 2
opends/tests/shared/functions/topology.xml | 12 ++
opends/tests/shared/functions/ldap.xml | 54 +++-----
opends/tests/shared/functions/utils.xml | 225 +++++++++++++++++++++++++++++++++++++
opends/tests/shared/python/common.py | 34 +++++
5 files changed, 291 insertions(+), 36 deletions(-)
diff --git a/opends/tests/functional-tests/staf-installer.xml b/opends/tests/functional-tests/staf-installer.xml
index 8915200..aeb6f6f 100644
--- a/opends/tests/functional-tests/staf-installer.xml
+++ b/opends/tests/functional-tests/staf-installer.xml
@@ -929,7 +929,7 @@
<arg value="${staf.config}"/>
<env key="${path.var}" path="${java.home}${file.separator}bin${path.separator}${staf.install.dir}${file.separator}bin${path.separator}${path.current}"/>
<env key="LD_LIBRARY_PATH" path="${staf.install.dir}/lib"/>
- <env key="CLASSPATH" path="${staf.lib.dir}/JSTAF.jar${path.separator}${e.CLASSPATH}"/>
+ <env key="CLASSPATH" path="${staf.lib.dir}/JSTAF.jar${path.separator}:${project.home}/ext/svnkit/svnkit.jar${path.separator}${e.CLASSPATH}"/>
<env key="STAFCONVDIR" value="${staf.install.dir}/codepage"/>
<env key="STAFCODEPAGE" value="LATIN_1"/>
<env key="STAF_INSTANCE_NAME" value="STAF"/>
diff --git a/opends/tests/shared/functions/ldap.xml b/opends/tests/shared/functions/ldap.xml
index 2d5a99e..4417dc0 100755
--- a/opends/tests/shared/functions/ldap.xml
+++ b/opends/tests/shared/functions/ldap.xml
@@ -900,13 +900,19 @@
Only return these attributes
</function-arg-description>
<function-arg-property name="type" value="string"/>
- </function-arg-def>
- <function-arg-def name="outputFile" type="optional">
+ </function-arg-def>
+ <function-arg-def name="outputFile" type="optional" default="'None'">
<function-arg-description>
- Output file containing the search result in ldif format.
+ Output file containing the search result in ldif format
+ </function-arg-description>
+ <function-arg-property name="type" value="file"/>
+ </function-arg-def>
+ <function-arg-def name="ouputPath" type="optional">
+ <function-arg-description>
+ Path containing the outputFile
</function-arg-description>
<function-arg-property name="type" value="filepath"/>
- </function-arg-def>
+ </function-arg-def>
<function-arg-def name="expectedRC" type="optional" default="0">
<function-arg-description>
Expected return code value. Default value is 0
@@ -1069,38 +1075,24 @@
if dsAttributes:
STAFCmdParamsList.append('%s' % dsAttributes)
-
+ if not outputPath:
+ outputPath = '%s/..' % (dsPath)
+
STAFCmdParams=' '.join(STAFCmdParamsList)
</script>
- <message>
- '%s %s' % (STAFCmd, STAFCmdParams)
- </message>
-
- <process name="'LDAP Search Script to file'">
- <location>'%s' % location</location>
- <command>'%s' % STAFCmd</command>
- <parms>'%s' % STAFCmdParams</parms>
- <workdir>'%s' % dsBinPath</workdir>
- <envs>
- ['PATH=/bin:/usr/bin:%s' % dsBinPath, 'JAVA_HOME=%s' % JAVA_HOME]
- </envs>
- <stdout if="outputFile != None" mode="'replace'">'%s/../%s' % (dsPath,outputFile)</stdout>
- <stderr mode="'stdout'"/>
- <returnstdout/>
- </process>
-
- <script>
- STAXCode=RC
- STAXReason=STAXResult
- </script>
- <call function="'checktestRC'">
- { 'returncode' : STAXCode ,
- 'result' : STAXReason,
- 'expected' : expectedRC }
+ <call function="'runCommand'" >
+ { 'name' : 'LDAP Search Script',
+ 'command' : STAFCmd,
+ 'arguments' : STAFCmdParams,
+ 'location' : location,
+ 'outputFile': outputFile,
+ 'outputPath': outputPath,
+ 'expectedRC': expectedRC
+ }
</call>
<return>
- STAXReason
+ STAXResult
</return>
</sequence>
</function>
diff --git a/opends/tests/shared/functions/topology.xml b/opends/tests/shared/functions/topology.xml
index 99ca602..5c14571 100755
--- a/opends/tests/shared/functions/topology.xml
+++ b/opends/tests/shared/functions/topology.xml
@@ -218,6 +218,18 @@
}
</call>
+ <!-- Archive (.ref) files -->
+ <message>
+ 'Copy ref data files locally to %s.' % localTestsGroupDir
+ </message>
+ <call function="'CopyFolderByExtension'">
+ { 'location' : STAXServiceMachine,
+ 'srcfolder' : testsGroupDir,
+ 'destfolder' : localTestsGroupDir,
+ 'extension' : 'ref'
+ }
+ </call>
+
<!-- Archive java (.class) files -->
<script>
javaSharedDir='%s' % (TESTS_JAVA_DIR)
diff --git a/opends/tests/shared/functions/utils.xml b/opends/tests/shared/functions/utils.xml
index ac77407..0525e4c 100755
--- a/opends/tests/shared/functions/utils.xml
+++ b/opends/tests/shared/functions/utils.xml
@@ -1445,7 +1445,21 @@
<function-arg-description>
The duration that the process is allowed to run
</function-arg-description>
- </function-arg-def>
+ </function-arg-def>
+ <function-arg-def name="outputFile" type="optional" default="'None'">
+ <function-arg-description>
+ Output file containing the command output
+ </function-arg-description>
+ <function-arg-property name="type" value="file"/>
+ </function-arg-def>
+ <function-arg-def name="outputPath"
+ type="optional"
+ default="'%s/../..' % dsBinPath">
+ <function-arg-description>
+ Path containing the outputFile
+ </function-arg-description>
+ <function-arg-property name="type" value="filepath"/>
+ </function-arg-def>
<function-arg-def name="expectedRC" type="optional" default="0">
<function-arg-description>
Expected return code value. Default value is 0.
@@ -1479,6 +1493,7 @@
<workdir>path</workdir>
<envs>env</envs>
<console use="'same'"/>
+ <stdout if="outputFile != 'None'" mode="'replace'">'%s/%s' % (outputPath, outputFile)</stdout>
<stderr mode="'stdout'"/>
<returnstdout/>
</process>
@@ -1650,7 +1665,6 @@
</sequence>
</function>
-
<function name="grep">
<function-prolog>
This function search for a given string in a given file.
@@ -1727,5 +1741,210 @@
</sequence>
</function>
-
+ <function name="compareFile">
+ <function-prolog>
+ This function compares two files.
+ Print the differences if the comparison failed.
+ </function-prolog>
+ <function-map-args>
+ <function-arg-def name="location"
+ type="optional"
+ default="STAXServiceMachine">
+ <function-arg-description>
+ Location of target host
+ </function-arg-description>
+ <function-arg-property name="type" value="hostname"/>
+ </function-arg-def>
+ <function-arg-def name="remotehost"
+ type="optional"
+ default="STAF_REMOTE_HOSTNAME">
+ <function-arg-description>
+ The name of remote host
+ </function-arg-description>
+ <function-arg-property name="type" value="hostname"/>
+ </function-arg-def>
+ <function-arg-def name="dsPath"
+ type="optional"
+ default="'%s/%s' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)">
+ <function-arg-description>
+ Pathname to installation root
+ </function-arg-description>
+ <function-arg-property name="type" value="hostname"/>
+ </function-arg-def>
+ <function-arg-def name="outputFile" type="required">
+ <function-arg-description>
+ file containing output from the command
+ </function-arg-description>
+ <function-arg-property name="type" value="file"/>
+ </function-arg-def>
+ <function-arg-def name="outputPath" type="optional">
+ <function-arg-description>
+ path containing outputFile
+ </function-arg-description>
+ <function-arg-property name="type" value="filepath"/>
+ </function-arg-def>
+ <function-arg-def name="refFile" type="optional">
+ <function-arg-description>
+ reference file containing expected output
+ </function-arg-description>
+ <function-arg-property name="type" value="file"/>
+ </function-arg-def>
+ <function-arg-def name="refPath" type="optional">
+ <function-arg-description>
+ reference path containing refFile
+ </function-arg-description>
+ <function-arg-property name="type" value="filepath"/>
+ </function-arg-def>
+ <function-arg-def name="diffFile" type="optional">
+ <function-arg-description>
+ file containing diff output
+ </function-arg-description>
+ <function-arg-property name="type" value="file"/>
+ </function-arg-def>
+ <function-arg-def name="diffPath" type="optional">
+ <function-arg-description>
+ file containing diffFile
+ </function-arg-description>
+ <function-arg-property name="type" value="filepath"/>
+ </function-arg-def>
+ </function-map-args>
+
+ <sequence>
+ <script>
+ if CurrentTestPath.has_key('group'):
+ ThisGroupName = CurrentTestPath['group']
+ else:
+ ThisGroupName = 'unknown-group'
+
+ FormattedTestcase = format_testcase()
+ FormattedTestgroup = FormattedTestcase.group(ThisGroupName)
+
+ if not outputPath:
+ outputPath = '%s/..' % (dsPath)
+
+ if not refFile:
+ regexp = re.compile('\..*$')
+ tmpName = re.sub(regexp, '', outputFile)
+ refFile = '%s.ref' % tmpName
+
+ if not refPath:
+ refPath = '%s/%s' % (logsLocalDataDir,FormattedTestgroup)
+
+ if not diffFile:
+ regexp = re.compile('\..*$')
+ tmpName = re.sub(regexp, '', outputFile)
+ diffFile = '%s.diff' % tmpName
+
+ if not diffPath:
+ diffPath = '%s/%s/diffs' % (logsTestsDir,FormattedTestgroup)
+ else:
+ diffPath = '%s/diffs' % (diffPath)
+
+ cflocation=location
+ cfremotehost=remotehost
+ </script>
+
+ <!-- Check if 'diffPath' is already created -->
+ <call function="'GetEntry'">
+ {
+ 'location' : cflocation,
+ 'entry' : diffPath,
+ 'attribute' : 'TYPE'
+ }
+ </call>
+ <!-- If 'diffPath' is not already created then create it -->
+ <if expr="RC == 48">
+ <sequence>
+ <message>
+ 'Create folder %s' % diffPath
+ </message>
+ <call function="'createFolder'">
+ {
+ 'location' : cflocation ,
+ 'foldername' : diffPath
+ }
+ </call>
+ </sequence>
+ </if>
+
+ <message>
+ 'Copy file %s/%s (on %s) to %s/%s (on %s)' % \
+ (outputPath, outputFile, cfremotehost, diffPath, outputFile, cflocation)
+ </message>
+ <call function="'copyFile'">
+ {
+ 'location' : cfremotehost ,
+ 'srcfile' : '%s/%s' % (outputPath, outputFile) ,
+ 'destfile' : '%s/%s' % (diffPath, outputFile) ,
+ 'remotehost' : cflocation
+ }
+ </call>
+ <script>
+ outputRC=RC
+ </script>
+
+ <message>
+ 'Copy file %s/%s (on %s) to %s/%s (on %s)' % \
+ (refPath, refFile, cflocation, diffPath, refFile, cflocation)
+ </message>
+ <call function="'copyFile'">
+ {
+ 'location' : cflocation ,
+ 'srcfile' : '%s/%s' % (refPath, refFile) ,
+ 'destfile' : '%s/%s' % (diffPath, refFile) ,
+ 'remotehost' : cflocation
+ }
+ </call>
+ <script>
+ refRC=RC
+ </script>
+
+ <!-- If the copy of 'outputFile' and 'refFile' succeed
+ then compare these files -->
+ <if expr="outputRC == 0 and refRC == 0">
+ <sequence>
+ <message>
+ 'Compare file %s/%s to %s/%s on %s' % \
+ (diffPath, outputFile, diffPath, refFile, cflocation)
+ </message>
+ <script>
+ CompareFile = compare_file('%s/%s' % (diffPath, outputFile),
+ '%s/%s' % (diffPath, refFile),
+ '%s/%s' % (diffPath, diffFile))
+ diff = CompareFile.genDiff()
+ </script>
+
+ <if expr="diff == ''">
+ <sequence>
+ <tcstatus result="'pass'"/>
+ <message log="1">
+ 'SUCCESS : No differences were found between %s and %s' % \
+ (outputFile, refFile)
+ </message>
+ </sequence>
+ <else>
+ <sequence>
+ <tcstatus result="'fail'"/>
+ <message log="1">
+ 'ERROR : Differences were found between %s and %s\n%s' % \
+ (outputFile, refFile, diff)
+ </message>
+ <message log="1">
+ 'ERROR : Diff file is here: %s/%s' % (diffPath, diffFile)
+ </message>
+ </sequence>
+ </else>
+ </if>
+ </sequence>
+ <else>
+ <sequence>
+ <tcstatus result="'fail'"/>
+ <message log="1">
+ 'ERROR : Error during file comparision'
+ </message>
+ </sequence>
+ </else>
+ </if>
+ </sequence>
+ </function>
</stax>
diff --git a/opends/tests/shared/python/common.py b/opends/tests/shared/python/common.py
index 0b80e05..2dc6997 100644
--- a/opends/tests/shared/python/common.py
+++ b/opends/tests/shared/python/common.py
@@ -29,7 +29,8 @@
# $Source$
# public symbols
-__all__ = [ "format_testcase", "directory_server_information", "test_time", "report_generation" ]
+__all__ = [ "format_testcase", "directory_server_information", "test_time", \
+ "report_generation" , "compare_file" ]
class format_testcase:
'Format the Test name objects'
@@ -163,3 +164,34 @@
self.xml.close()
self.html.close()
+class compare_file:
+ 'Compare two files'
+
+ def __init__(self, file1, file2, diffFile):
+ self.file1 = file1
+ self.file2 = file2
+ self.diffFile = diffFile
+
+ def genDiff(self):
+ from org.tmatesoft.svn.core.wc import *
+ from java.io import File
+ from java.io import FileOutputStream
+
+ diff = DefaultSVNDiffGenerator()
+ diff.displayFileDiff("",
+ File("%s" % self.file1),
+ File("%s" % self.file2),
+ self.file1,
+ self.file2,
+ "text/plain",
+ "text/plain",
+ FileOutputStream(File("%s" % self.diffFile)))
+
+ try:
+ ret_str = ""
+ diff_file = open(self.diffFile, "r")
+ for line in diff_file.readlines():
+ ret_str = ret_str + line
+ return ret_str
+ finally:
+ diff_file.close()
--
Gitblit v1.10.0