| 1 |
#!/bin/bash |
| 2 |
# Testing the installation of the dev tools |
| 3 |
# cepgenerator and devtools |
| 4 |
# |
| 5 |
# echo $? get the last returned value of the script |
| 6 |
# |
| 7 |
# TODO add complete library tests using cepgenerator |
| 8 |
# This can be done using exampleLibraryAction.xml |
| 9 |
# + adding a real action in there |
| 10 |
# + adding a component |
| 11 |
# + adding a test file |
| 12 |
# + adding source code files : |
| 13 |
# ActionDoSomething.cpp in |
| 14 |
# EmptyComponent.cpp to use the library |
| 15 |
# EmptyLibrary.h EmptyLibrary.cpp |
| 16 |
# + add "echo "#include "ActionDoSomething.cpp"" >> actions/emptyaction/Action.cpp" |
| 17 |
# and compile only then |
| 18 |
# @see the shaker lib turorial |
| 19 |
# |
| 20 |
# TODO add a complete example with all the possible Property types |
| 21 |
# @see the property tutorial |
| 22 |
# |
| 23 |
# TODO add another family of tests using testaction and testcomponent on cepgenerated action/components |
| 24 |
# |
| 25 |
# TODO distribute all the files from the ./sdk/applications/cepgenerator/testdata directory |
| 26 |
# in the package $(pkg-dev) so that they are installed in /usr/share/camitk-$(VER_SHORT)/testdata/cepgenerator/* |
| 27 |
# In this script, just copy all files from /usr/share/camitk-$(VER_SHORT)/testdata/cepgenerator/* to the tmpdir |
| 28 |
# and run a foreach on each .xml files |
| 29 |
|
| 30 |
set -e |
| 31 |
|
| 32 |
# Uncomment next line to debug |
| 33 |
set -x |
| 34 |
|
| 35 |
#DEBUG |
| 36 |
#To test with different library versions, you can use different install path, for instance: |
| 37 |
# CMAKE_OPTIONS="-DVTK_DIR:PATH=/opt/vtk6/lib/cmake/vtk-6.3 -DITK_DIR:PATH=/opt/vtk6/lib/cmake/ITK-4.9 -DGDCM_DIR:PATH=/opt/vtk6/lib/gdcm-2.6" |
| 38 |
|
| 39 |
# ---------------------- cleanup ---------------------- |
| 40 |
cleanup() { |
| 41 |
# cleanup on exit |
| 42 |
|
| 43 |
# backup the current exit status |
| 44 |
currentExitValue=$? |
| 45 |
echo |
| 46 |
echo "*** Cleaning up before exiting..." |
| 47 |
echo |
| 48 |
if [[ "$osName" != "Windows" ]]; then |
| 49 |
# kill the xfvb if still exist |
| 50 |
if [ -f /proc/$xvfbPid/status ]; then |
| 51 |
echo "Killing running xvfb server (pid $xvfbPid)..." |
| 52 |
kill $xvfbPid |
| 53 |
fi |
| 54 |
fi |
| 55 |
if [ "$currentExitValue" -ne "0" ]; then |
| 56 |
echo |
| 57 |
echo "*** Test failed " |
| 58 |
echo |
| 59 |
# output all possible files |
| 60 |
cd $workingDir |
| 61 |
# Test exist status of every file and directory otherwise the script abort and the temp directory is not removed |
| 62 |
if [ -f "./generated-$testDirName" ]; then |
| 63 |
echo "===== FAILED generated-$testDirName =====" |
| 64 |
cat ./generated-$testDirName |
| 65 |
echo "[FAIL] generation" |
| 66 |
else |
| 67 |
echo "===== File $workingDir/generated-$testDirName not found =====" |
| 68 |
fi |
| 69 |
if [ -d "$testDirName/build" ]; then |
| 70 |
cd $testDirName/build |
| 71 |
if [ -f "../cmake-log" ]; then |
| 72 |
echo "===== FAILED cmake-log =====" |
| 73 |
cat ../cmake-log |
| 74 |
else |
| 75 |
echo "===== File $testDirName/build/../cmake-log not found =====" |
| 76 |
fi |
| 77 |
if [ -f "../cmake-error" ]; then |
| 78 |
echo "===== FAILED cmake-error =====" |
| 79 |
cat ../cmake-error |
| 80 |
echo "[FAIL] CMake configuration" |
| 81 |
else |
| 82 |
echo "===== File $testDirName/build/../cmake-error not found =====" |
| 83 |
fi |
| 84 |
if [ -f "../make-log" ]; then |
| 85 |
echo "===== FAILED make-log =====" |
| 86 |
cat ../make-log |
| 87 |
else |
| 88 |
echo "===== File $testDirName/build/../make-log not found =====" |
| 89 |
fi |
| 90 |
if [ -f "../make-error" ]; then |
| 91 |
echo "===== FAILED make-error =====" |
| 92 |
cat ../make-error |
| 93 |
echo "[FAIL] Build" |
| 94 |
else |
| 95 |
echo "===== File $testDirName/build/../make-error not found =====" |
| 96 |
fi |
| 97 |
else |
| 98 |
echo "===== Directory $workingDir/$testDirName/build not found =====" |
| 99 |
fi |
| 100 |
cd |
| 101 |
fi |
| 102 |
# finally cleanup working dir |
| 103 |
echo "Cleaning up working directory $workingDir..." |
| 104 |
rm -rf $workingDir |
| 105 |
# use the backup value (otherwise the result of the "rm -rf" command above will |
| 106 |
# be used, and that's probably always 0 !) |
| 107 |
exit $currentExitValue |
| 108 |
} |
| 109 |
|
| 110 |
# ---------------------- checkcommand ---------------------- |
| 111 |
checkcommand() { |
| 112 |
# usage: checkcommand name |
| 113 |
if [ "$inBuild" == "0" ] ; then |
| 114 |
# check if current build is on windows debug version |
| 115 |
if ! hash ${1} 2>/dev/null; then |
| 116 |
echo "[FAIL] Error: executable not found" |
| 117 |
else |
| 118 |
echo "[OK]" |
| 119 |
fi |
| 120 |
else |
| 121 |
if [ ! -x ${1} ] ; then |
| 122 |
echo "[FAIL] Error: file not found or not executable" |
| 123 |
else |
| 124 |
echo "[OK]" |
| 125 |
fi |
| 126 |
fi |
| 127 |
} |
| 128 |
|
| 129 |
# ---------------------- init ---------------------- |
| 130 |
init() { |
| 131 |
echo |
| 132 |
echo "*** Checking configuration..." |
| 133 |
echo |
| 134 |
exitStatus=0 # nothing bad. By convention exit 0 indicates success |
| 135 |
checkValueId=1 # test id starts at 1 |
| 136 |
|
| 137 |
echo "===== Test script directory =====" |
| 138 |
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 139 |
echo "[OK] Test script directory is $scriptDir" |
| 140 |
|
| 141 |
echo "===== Creating temporary test directory =====" |
| 142 |
workingDir=$(mktemp --tmpdir -d camitk-test-tmp.XXXXXXXXXX) |
| 143 |
echo "[OK] Temporary test directory set to $workingDir" |
| 144 |
|
| 145 |
echo "===== Checking test parameters =====" |
| 146 |
totalNbOfArguments=$# |
| 147 |
nbOfParameters=$((totalNbOfArguments-1)) |
| 148 |
echo "[OK] Test launch with $nbOfParameters parameters: \"$1\" and \"$2\"" |
| 149 |
|
| 150 |
echo "===== CamiTK environment =====" |
| 151 |
if [ $# -lt 1 -o "$1" != "-inbuild" ] ; then |
| 152 |
echo "[OK] Test using installed CamiTK version" |
| 153 |
inBuild=0 |
| 154 |
# for installed camitk, just run the corresponding executables |
| 155 |
camitkGenerator=camitk-cepgenerator |
| 156 |
camitkConfig=camitk-config |
| 157 |
else |
| 158 |
echo "[OK] Test using inbuild directory \"$2\" (source code in \"$3\")" |
| 159 |
# if -inbuild option is specified, then the next argument should be the build dir (as set by ${PROJECT_BINARY_DIR} by cmake |
| 160 |
inBuild=1 |
| 161 |
# for in build test, use specific path for executables |
| 162 |
camitkGenerator=$2/bin/camitk-cepgenerator |
| 163 |
camitkConfig=$2/bin/camitk-config |
| 164 |
# specify CamiTK dir |
| 165 |
# Although it is not an install dir, it is better to use the build dir than to temporary installed, test and uninstall |
| 166 |
export CAMITK_DIR=$2 |
| 167 |
# Add extra cmake module path to find the CMake macros that are indeed not installed in the build dir |
| 168 |
CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_MODULE_PATH:PATH=$3/sdk/cmake/modules;$3/sdk/cmake/modules/macros" |
| 169 |
fi |
| 170 |
|
| 171 |
echo "===== Checking OS =====" |
| 172 |
unameOS=$(uname) |
| 173 |
if [[ "$unameOS" =~ ^MINGW64.* || "$unameOS" =~ ^MSYS_NT.* ]]; then |
| 174 |
osName="Windows" |
| 175 |
else |
| 176 |
osName="Linux" |
| 177 |
fi |
| 178 |
echo "[OK] uname is $unameOS → Test on OS $osName" |
| 179 |
|
| 180 |
if [[ "$osName" != "Windows" ]]; then |
| 181 |
echo "===== Configuring xvfb =====" |
| 182 |
displayID=15 |
| 183 |
# Starts the server first (to avoid a distracting warning output due to OpenGL context) |
| 184 |
Xvfb :$displayID -screen 0 1600x1200x24 -ac +extension GLX +render -noreset -v -fbdir $workingDir/ & |
| 185 |
xvfbPid=$! |
| 186 |
echo "[OK] PID of Xvfb: $xvfbPid" |
| 187 |
export DISPLAY=:$displayID |
| 188 |
export XAUTHORITY=/dev/null |
| 189 |
fi |
| 190 |
|
| 191 |
# Checking if current build is on windows debug version |
| 192 |
echo "===== Checking camitk-config =====" |
| 193 |
checkCamiTKConfig=$(checkcommand $camitkConfig) |
| 194 |
if [ "$checkCamiTKConfig" != "[OK]" ] ; then |
| 195 |
if [[ "$osName" == "Windows" ]]; then |
| 196 |
camitkConfig=$camitkConfig-debug |
| 197 |
echo "===== Checking camitk-config-debug =====" |
| 198 |
checkCamiTKConfig=$(checkcommand $camitkConfig) |
| 199 |
echo "$checkCamiTKConfig" |
| 200 |
if [ "$checkCamiTKConfig" != "[OK]" ] ; then |
| 201 |
echo "[FAIL] Error: cannot find camitk-config nor camitk-config-debug" |
| 202 |
else |
| 203 |
buildType="Debug" |
| 204 |
fi |
| 205 |
fi |
| 206 |
else |
| 207 |
echo "[OK] executable camitk-config found" |
| 208 |
buildType="Release" |
| 209 |
fi |
| 210 |
|
| 211 |
if [[ "$osName" == "Windows" ]]; then |
| 212 |
echo "==== Windows build type ====" |
| 213 |
echo "$buildType" |
| 214 |
fi |
| 215 |
|
| 216 |
echo "===== camitk-config configuration =====" |
| 217 |
echo "[OK] using $camitkConfig on $osName" |
| 218 |
|
| 219 |
echo "===== Checking camitk-generator =====" |
| 220 |
checkCamiTKGenerator=$(checkcommand $camitkGenerator) |
| 221 |
if [ "$checkCamiTKGenerator" != "[OK]" ] ; then |
| 222 |
if [[ "$osName" == "Windows" ]]; then |
| 223 |
camitkGenerator=$camitkGenerator-debug |
| 224 |
echo "===== Checking camitk-generator-debug =====" |
| 225 |
checkCamiTKGenerator=$(checkcommand $camitkGenerator) |
| 226 |
echo "$checkCamiTKGenerator" |
| 227 |
fi |
| 228 |
else |
| 229 |
echo "[OK] executable camitk-generator found" |
| 230 |
fi |
| 231 |
echo "===== camitk-generator configuration =====" |
| 232 |
echo "[OK] using $camitkGenerator on $osName" |
| 233 |
|
| 234 |
} |
| 235 |
|
| 236 |
# ---------------------- getConfig ---------------------- |
| 237 |
getConfig() { |
| 238 |
$camitkConfig --config 2>/dev/null # | sed "s/QStandardPaths.*'.*'//" |
| 239 |
} |
| 240 |
|
| 241 |
# ---------------------- generateConfigureAndMake ---------------------- |
| 242 |
getWorkingDirExtensionCount() { |
| 243 |
echo $(getConfig | grep "^ - \[W\] " | wc -l) |
| 244 |
} |
| 245 |
|
| 246 |
# ---------------------- generateConfigureAndMake ---------------------- |
| 247 |
generateConfigureAndMake() { |
| 248 |
# generate |
| 249 |
testDirName=$(basename $1 .xml) |
| 250 |
echo |
| 251 |
echo "*** $checkValueId.1 Generate, configure and build $testDirName..." |
| 252 |
echo |
| 253 |
echo "===== Generating source code from XML... =====" |
| 254 |
cd $workingDir |
| 255 |
rm -rf $testDirName |
| 256 |
mkdir $testDirName |
| 257 |
$camitkGenerator -f $1 -d $workingDir/$testDirName > ./generated-$testDirName |
| 258 |
if [ -s ./generated-$testDirName ] ; then |
| 259 |
cat ./generated-$testDirName |
| 260 |
fi |
| 261 |
|
| 262 |
cd $testDirName |
| 263 |
# get the created dir name |
| 264 |
srcDirName=$(ls) |
| 265 |
|
| 266 |
# check if there is a library (in this case copy dummy test lib to the given library name source dir |
| 267 |
if [ "$#" == 2 ]; then |
| 268 |
echo "===== Adding library code... =====" |
| 269 |
cp ../TestLib.* $srcDirName/libraries/$2 |
| 270 |
fi |
| 271 |
|
| 272 |
# configure |
| 273 |
mkdir build |
| 274 |
cd build |
| 275 |
echo "===== Configuring... =====" |
| 276 |
if [[ "$osName" == "Windows" ]]; then |
| 277 |
# choose the default msvc version and config from current install |
| 278 |
cmake $CMAKE_OPTIONS -Wno-dev ../$srcDirName > ../cmake-log 2> ../cmake-error |
| 279 |
else |
| 280 |
cmake $CMAKE_OPTIONS ../$srcDirName > ../cmake-log 2> ../cmake-error |
| 281 |
fi |
| 282 |
if [ -s ../cmake-log ] ; then |
| 283 |
echo "===== cmake log =====" |
| 284 |
cat ../cmake-log |
| 285 |
fi |
| 286 |
if [ -s ../cmake-error ] ; then |
| 287 |
echo "===== cmake error log =====" |
| 288 |
cat ../cmake-error |
| 289 |
fi |
| 290 |
|
| 291 |
echo "===== building... =====" |
| 292 |
if [[ "$osName" == "Windows" ]]; then |
| 293 |
cmake --build . --config $buildType --parallel 9 > ../make-log 2> ../make-error |
| 294 |
else |
| 295 |
# build (parallel) |
| 296 |
make -j9 > ../make-log 2> ../make-error |
| 297 |
fi |
| 298 |
if [ -s ../make-log ] ; then |
| 299 |
echo "===== make log =====" |
| 300 |
cat ../make-log |
| 301 |
fi |
| 302 |
if [ -s ../make-error ] ; then |
| 303 |
echo "===== make error log =====" |
| 304 |
cat ../make-error |
| 305 |
fi |
| 306 |
} |
| 307 |
|
| 308 |
# ---------------------- testcepfile ---------------------- |
| 309 |
# @param xmlfile |
| 310 |
# @param expected number of created extensions |
| 311 |
testcepfile() { |
| 312 |
generateConfigureAndMake $1 $3 |
| 313 |
expectedValue="$2" |
| 314 |
|
| 315 |
echo |
| 316 |
echo "*** $checkValueId.2 Checking $1 installation..." |
| 317 |
echo |
| 318 |
|
| 319 |
# check if everything is compiled and can be loaded |
| 320 |
value=$(getWorkingDirExtensionCount) |
| 321 |
echo "Number of extensions for $1: $value found ($expectedValue expected)" |
| 322 |
echo "$(getConfig | grep "^ - \[W\] ")" |
| 323 |
if [ "$value" -ne "$expectedValue" ]; then |
| 324 |
echo "[FAIL] Error: unexpected number of extensions installed in the working directory ($value != $expectedValue)" |
| 325 |
exitStatus=$checkValueId |
| 326 |
else |
| 327 |
echo "[OK]" |
| 328 |
fi |
| 329 |
echo |
| 330 |
# increase id |
| 331 |
checkValueId=$((checkValueId+1)) |
| 332 |
} |
| 333 |
|
| 334 |
# -------------------------------------------------------------------------- |
| 335 |
# |
| 336 |
# All tests are here |
| 337 |
# |
| 338 |
# -------------------------------------------------------------------------- |
| 339 |
|
| 340 |
# if a problem occurs, call the clean method |
| 341 |
trap "cleanup" 0 INT QUIT ABRT PIPE TERM EXIT |
| 342 |
|
| 343 |
init $* |
| 344 |
cd $workingDir |
| 345 |
$scriptDir/generate-coreschema-files.sh |
| 346 |
$scriptDir/generate-cpp-files.sh |
| 347 |
|
| 348 |
#testcepfile cep.xml nrOfExpectedNewExtensions |
| 349 |
testcepfile actionAndComponentUsingViewerExtension.xml 2 |
| 350 |
|
| 351 |
# test that is too difficult to manage on Windows |
| 352 |
# TODO: describe the reason why it is not easy to perform it on Windows |
| 353 |
if [[ "$osName" == "Windows" ]]; then |
| 354 |
echo "[OK] Windows: skip testing cep with lib" |
| 355 |
else |
| 356 |
testcepfile completeTest1.xml 3 testlib |
| 357 |
fi |
| 358 |
|
| 359 |
testcepfile exampleComponents.xml 2 |
| 360 |
testcepfile actionsExamplesLicence.xml 2 |
| 361 |
testcepfile actionsExamplesNoLicence.xml 2 |
| 362 |
testcepfile actionAndComponent.xml 2 |
| 363 |
testcepfile empty.xml 0 |
| 364 |
testcepfile viewerExample.xml 2 |
| 365 |
|
| 366 |
exit $exitStatus |