fix the CMake build

also, fix and simplify the CTest system
This commit is contained in:
Andreas Lauser 2012-10-19 14:42:37 +02:00
parent 7deaf50402
commit 95ae6949d8
3 changed files with 91 additions and 88 deletions

92
bin/fuzzycomparevtu.py Normal file → Executable file
View File

@ -1,50 +1,40 @@
#! /usr/bin/python
import argparse import argparse
from xml.dom import minidom import re
# fuzzy compare XML tree from XML strings # fuzzy compare two VTK files
def isFuzzyEqualXml(xml1, xml2, absolute, relative): def isFuzzyEqual(vtkFile1, vtkFile2, absTol, relTol):
dom1 = minidom.parseString(xml1) inField = False
dom2 = minidom.parseString(xml2) curFieldName = ""
return isFuzzyEqualNode(dom1.documentElement, dom2.documentElement, absolute, relative) for curLine1 in vtkFile1.xreadlines():
curLine2 = vtkFile2.readline()
# fuzzy compare of XML nodes if curLine1.find("</DataArray>"):
def isFuzzyEqualNode(node1, node2, absolute, relative): inField = False
if node1.tagName != node2.tagName: continue
print 'The name of the node differs in ', node1.tagName, ' and ', node2.tagName
return False
if sorted(node1.attributes.items()) != sorted(node2.attributes.items()):
print 'Attributs differ in node ', node1.tagName
return False
if len(node1.childNodes) != len(node2.childNodes):
print 'Number of children differs in node ', node1.tagName
return False
for node1child, node2child in zip(node1.childNodes, node2.childNodes):
if node1child.nodeType != node2child.nodeType:
print 'Node type differs in ', note1.tagName
return False
if node1child.nodeType == node1child.TEXT_NODE and not isFuzzyEqualText(node1child.data, node2child.data, absolute, relative):
print 'Data differs in node ', node1.tagName
return False
if node1child.nodeType == node1child.ELEMENT_NODE and not isFuzzyEqualNode(node1child, node2child, absolute, relative):
return False
return True
# fuzzy compare of text consisting of whitespace separated numbers m = re.match('Name="\([a-zA-Z0-9 _\-]*\)"', curLine1)
def isFuzzyEqualText(text1, text2, absolute, relative): if m:
list1 = text1.split() curFieldName = m.group(1)
list2 = text2.split() inField = True
# difference only in whitespace? continue
if (list1 == list2):
return True curVals1 = map(float, curLine1.split())
# compare number by number curVals2 = map(float, curLine2.split())
for number1, number2 in zip(list1, list2):
number1 = float(number1) if len(curVals1) != len(curVals2):
number2 = float(number2) print "Length of field '%s' is different"%curFieldName
if abs(number1 - number2) > absolute: return False
print 'Absolute difference between %f and %f too large (%f)'%(number1,number2,abs(number1 - number2))
else number2 != 0 \ for i in range(0, len(curVals1)):
and abs(number1/number2 - 1) > relative)): number1 = curVals1[i]
print 'Relative difference between %f and %f too large (%f%%)'%(number1,number2,abs(number1/number2 - 1)*100) number2 = curVals2[i]
if abs(number1 - number2) > absTol:
print 'Absolute difference between %f and %f too large (%f) in data field "%s"'%(number1,number2,abs(number1 - number2), curFieldName)
return False
elif number2 != 0 and abs(number1/number2 - 1) > relTol:
print 'Relative difference between %f and %f too large (%f%%) in data field "%s"'%(number1,number2,abs(number1/number2 - 1)*100, curFieldName)
return False return False
return True return True
@ -52,20 +42,20 @@ def isFuzzyEqualText(text1, text2, absolute, relative):
# handle arguments and print help message # handle arguments and print help message
parser = argparse.ArgumentParser(description='Fuzzy compare two VTK\ parser = argparse.ArgumentParser(description='Fuzzy compare two VTK\
(Visualization Toolkit) files. The files are accepted if for every\ (Visualization Toolkit) files. The files are accepted if for every\
value the difference is below the absolute error or below the\ value the difference is below the absTol error or below the\
relative error or below both.') relTol error or below both.')
parser.add_argument('vtu_file_1', type=open, parser.add_argument('vtu_file_1', type=open,
help='first file to compare') help='first file to compare')
parser.add_argument('vtu_file_2', type=open, parser.add_argument('vtu_file_2', type=open,
help='second file to compare') help='second file to compare')
parser.add_argument('-r', '--relative', type=float, default=1e-2, parser.add_argument('-r', '--relTol', type=float, default=1e-2,
help='maximum relative error (default=1e-2)') help='maximum tolerated absolute error (default=1e-2)')
parser.add_argument('-a', '--absolute', type=float, default=1e-9, parser.add_argument('-a', '--absTol', type=float, default=1e-9,
help='maximum relative error (default=1e-9)') help='maximum tolerated relative error (default=1e-9)')
args = parser.parse_args() args = parser.parse_args()
# fuzzy compare # fuzzy compare
if isFuzzyEqualXml(args.vtu_file_1.read(), args.vtu_file_2.read(), args.absolute, args.relative): if isFuzzyEqual(args.vtu_file_1, args.vtu_file_2, args.absTol, args.relTol):
exit exit(0)
else: else:
exit(1) exit(1)

View File

@ -1,11 +1,11 @@
# add build targets # add build targets
ADD_EXECUTABLE("tutorial_decoupled" tutorial_decoupled.cc) ADD_EXECUTABLE("tutorial_decoupled" tutorial_decoupled.cc)
TARGET_LINK_LIBRARIES("tutorial_decoupled" ${DumuxLinkLibraries}) TARGET_LINK_LIBRARIES("tutorial_decoupled" ${EwomsLinkLibraries})
ADD_EXECUTABLE("tutorial_coupled" tutorial_coupled.cc) ADD_EXECUTABLE("tutorial_coupled" tutorial_coupled.cc)
TARGET_LINK_LIBRARIES("tutorial_coupled" ${DumuxLinkLibraries}) TARGET_LINK_LIBRARIES("tutorial_coupled" ${EwomsLinkLibraries})
# add required libraries and includes to the build flags # add required libraries and includes to the build flags
LINK_DIRECTORIES(${DumuxLinkDirectories}) LINK_DIRECTORIES(${EwomsLinkDirectories})
INCLUDE_DIRECTORIES(${DumuxIncludeDirectories}) INCLUDE_DIRECTORIES(${EwomsIncludeDirectories})

View File

@ -10,33 +10,28 @@
function usage() { function usage() {
echo "Usage:" echo "Usage:"
echo echo
echo "runTest.sh REFERENCE_RESULT_FILE TEST_RESULT_FILE TEST_BINARY [TEST_ARGS]" echo "runTest.sh TEST_TYPE TEST_BINARY [TEST_ARGS]"
echo "where TEST_TYPE can either be --plain or --simulation"
}; };
REFERENCE_RESULT="$1" TEST_TYPE="$1"
TEST_RESULT="$2" TEST_NAME="$2"
TEST_BINARY="$3" TEST_ARGS="${@:3:100}"
TEST_ARGS="${@:4:100}"
# make sure we have at least 3 parameters # make sure we have at least 2 parameters
if test "$#" -lt 3; then if test "$#" -lt 2; then
echo "Wrong number of parameters" echo "Wrong number of parameters"
echo echo
usage usage
exit 1 exit 1
fi fi
# make sure the reference result exists # find the binary in the its folder
if ! test -r "$REFERENCE_RESULT"; then TEST_BINARY=$(find -type f -executable -name "$TEST_NAME")
echo "File $REFERENCE_RESULT does not exist or is not readable"
echo
usage
exit 1
fi
# make sure the binary is of the test is present # make sure the binary is of the test is present
if ! test -x "$TEST_BINARY"; then if ! test -x "$TEST_BINARY"; then
echo "$TEST_BINARY does not exist or is not executable" echo "$TEST_NAME does not exist or is not executable"
echo echo
usage usage
exit 1 exit 1
@ -44,22 +39,34 @@ fi
#run the test #run the test
echo "######################" echo "######################"
echo "# Running test" echo "# Running test '$TEST_NAME'"
echo "######################" echo "######################"
if ! "$TEST_BINARY" $TEST_ARGS; then if ! "$TEST_BINARY" $TEST_ARGS; then
echo "Executing the binary failed!" echo "Executing the binary failed!"
exit 1 exit 1
fi fi
case "$TEST_TYPE" in
"--simulation")
# compare the results # compare the results
echo "######################" echo "######################"
echo "# Comparing results" echo "# Comparing results"
echo "######################" echo "######################"
TEST_RESULT=$(ls --sort=time *.vtu *.vtp | head -n 1 2> /dev/null)
if ! test -r "$TEST_RESULT"; then if ! test -r "$TEST_RESULT"; then
echo "File $TEST_RESULT does not exist or is not readable" echo "File $TEST_RESULT does not exist or is not readable"
exit 1 exit 1
fi fi
REFERENCE_RESULT="referencesolutions/$TEST_RESULT"
if ! test -r "$REFERENCE_RESULT"; then
echo "File $REFERENCE_RESULT does not exist or is not readable"
exit 1
fi
if ! python bin/fuzzycomparevtu.py "$REFERENCE_RESULT" "$TEST_RESULT"; then if ! python bin/fuzzycomparevtu.py "$REFERENCE_RESULT" "$TEST_RESULT"; then
echo "The files \"$TEST_RESULT\" and \"$REFERENCE_RESULT\" are different." echo "The files \"$TEST_RESULT\" and \"$REFERENCE_RESULT\" are different."
echo "Make sure the contents of \"$TEST_RESULT\" are still valid and " echo "Make sure the contents of \"$TEST_RESULT\" are still valid and "
@ -70,3 +77,9 @@ fi
# SUCCESS!!!!!! # SUCCESS!!!!!!
echo "Result and reference result are identical" echo "Result and reference result are identical"
exit 0 exit 0
;;
*)
exit 0
;;
esac