qmtestRun.sh.in 8.28 KB
Newer Older
1
#! /bin/bash
2
3
topdir=`dirname $0`
topdir=`cd $topdir; pwd`
4

5
6
7
8
9
10
11
# Check optional arguments: usage if 1st argument is --help
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
  echo "Usage: `basename $0` [--valgrind] [tests]          --> Run tests"
  echo "Usage: `basename $0` -ls|--list [tests]            --> List available tests"
  echo "Usage: `basename $0` -h|--help                     --> Print usage"
  exit 1
fi
12

13
14
15
16
17
18
19
# Check optional arguments: list tests if 1st argument is --list
listonly=0
if [ "$1" == "-ls" ] || [ "$1" == "--list" ]; then
  listonly=1
  shift
# Check optional arguments: run through valgrind if 1st argument is --valgrind
elif [ "$1" == "-valgrind" ] || [ "$1" == "--valgrind" ]; then
20
21
22
23
24
25
26
27
  echo "The test suite will be executed through valgrind ('-valgrind')"
  export CORAL_TESTSUITE_VALGRIND=1
  shift
else
  echo "The test suite will NOT be executed through valgrind (no '-valgrind')"
  unset CORAL_TESTSUITE_VALGRIND
fi

28
# Check next optional arguments to choose which tests to run
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
if [ "$1" = "" ]; then
  #--- All tests (whether in CoralTest or CoolTest)
  theTests=ALL 
  #--- Specific tests (only in CoralTest)
  ###theTests=integration
  ###theTests=unit
  ###theTests=unit_coralserver
  #--- Specific tests (only in CoolTest)
  ###theTests=sqlite
  ###theTests=relationalcool.oracle.raldatabasesvc
  ###theTests=relationalcool.mysql.raldatabasesvc
  ###theTests=relationalcool.sqlite.raldatabasesvc
  ###theTests=pycool.import_pycool
  ###theTests=pycoolutilities.sqlite.evolution_130
  ###theTests=pycoolutilities.frontier
else
  theTests=""
  while [ "$1" != "" ]; do
    if [ "$theTests" = "" ]; then
      theTests="$1"
    else
      theTests="$theTests $1"
    fi
    shift
  done
fi

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Check if this is CORAL or COOL
thisProj=@CMAKE_PROJECT_NAME@ # From CMAKE_PROJECT_NAME
if [ "$thisProj" == "CORAL" ]; then
  thisPkg=CoralTest
elif [ "$thisProj" == "COOL" ]; then
  thisPkg=CoolTest
else
  echo "ERROR! Unknown project ${thisProj} is neither CORAL nor COOL"
  exit 1
fi

# Check if qmtest exists under CoralTest or CoolTest
theQmtDir=$topdir/${thisPkg}/qmtest
if [ ! -d $theQmtDir ]; then
  echo "ERROR! Directory ${theQmtDir} does not exist"
  exit 1
fi

# Assume you are in the install area or in the build area
ccrun=$topdir/cc-run
if [ ! -f ${ccrun} ]; then 
  echo "ERROR! ${ccrun} does not exist"
78
79
  exit 1
fi
80
81
82
83
84
85
86
87
88
export BINARY_TAG=`${ccrun} printenv BINARY_TAG`

# List tests and exit if --list was specified
if [ "$listonly" == "1" ]; then
  cd $theQmtDir
  ${ccrun} -q qmtest ls -R ${theTests}
  exit 0
fi
echo Will launch \'qmtest run ${theTests}\'
89
90
91

# Define location of the test workdir and of the logs directory
# [TODO? Accept workdir and/or logdir as arguments? Probably no longer needed]
92
if [ -d ${topdir}/../src ]; then
93
94
  # This is most likely a private build directory
  export CORALCOOL_QMTEST_WORKDIR=${theQmtDir}/tmp.${BINARY_TAG}
95
  theLogParentDir=`cd ${topdir}/..; pwd`
96
97
98
else
  # This is most likely a read-only installed release
  # Use a workdir below /tmp named after the last 3 levels of this release area
99
  tmpdir=`cd ${topdir}/..; pwd`
100
101
102
103
104
105
106
  if [ "${tmpdir}" == "/" ]; then
    tmpdir=
  elif [ "${tmpdir%/*/*/*}" != "${tmpdir}" ]; then
    tmpdir=${tmpdir#${tmpdir%/*/*/*}}
  fi
  export CORALCOOL_QMTEST_WORKDIR=/tmp/${USER}${tmpdir}/tmp.${BINARY_TAG}
  theLogParentDir=/tmp/${USER}${tmpdir}
107
  if [ ! -d ${theLogParentDir} ]; then mkdir -p ${theLogParentDir}; fi
108
109
110
111
112
fi

# Check out from SVN the logs directory if it does not exist
# Stop if an older version of logs exist without qmtestCoral or qmtestCool
# Define the qmtest results file
113
cd $theLogParentDir
114
115
116
117
if [ "$?" != "0" ]; then
  echo "ERROR! Could not cd $theLogParentDir"
  exit 1
fi
118
119
if [ "$thisPkg" == "CoralTest" ]; then
  if [ ! -d logs ]; then
120
    echo "WARNING! Missing logs directory ${theLogParentDir}/logs will be checked out from lcgcoral SVN"
121
122
    klist > /dev/null 2>&1
    if [ "$?" == "0" ]; then
123
      svn co -q svn+ssh://svn.cern.ch/reps/lcgcoral/logs
124
    else
125
      svn co -q http://svn.cern.ch/guest/lcgcoral/logs
126
    fi
127
128
129
130
131
132
133
134
  fi
  if [ ! -d logs/qmtestCoral ]; then
    echo "ERROR! Directory ${theLogParentDir}/logs/qmtestCoral does not exist"
    exit 1
  fi
  theQmrDir=${theLogParentDir}/logs/qmtestCoral
else
  if [ ! -d logs ]; then
135
    echo "WARNING! Missing logs directory ${theLogParentDir}/logs will be checked out from lcgcool SVN"
136
137
    klist > /dev/null 2>&1
    if [ "$?" == "0" ]; then
138
      svn co -q svn+ssh://svn.cern.ch/reps/lcgcool/logs
139
    else
140
      svn co -q http://svn.cern.ch/guest/lcgcool/logs
141
    fi
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
  fi
  if [ ! -d logs/qmtestCool ]; then
    echo "ERROR! Directory ${theLogParentDir}/logs/qmtestCool does not exist"
    exit 1
  fi
  theQmrDir=${theLogParentDir}/logs/qmtestCool
fi

# Set a few additional environment variables
# (as in prepare_env in test_functions.sh)
###export CORAL_AUTH_PATH=${HOME}/private
###export CORAL_DBLOOKUP_PATH=${HOME}/private

# Ignore QMTEST timeouts for COOL
export COOL_IGNORE_TIMEOUT=yes

158
159
# Check that QMTEST_CLASS_PATH contains the qmtest directory (bug #86964)
qmtest_class_path=`${ccrun} printenv QMTEST_CLASS_PATH`
160
161
echo "Using QMTEST_CLASS_PATH=$qmtest_class_path"
if [[ :$qmtest_class_path: != *:${theQmtDir}:* ]] ; then
162
163
164
165
166
  theQmtDirP=`cd ${theQmtDir}; pwd -P` # See CORALCOOL-2876
  if [[ :$qmtest_class_path: != *:${theQmtDirP}:* ]] ; then
    echo "ERROR! Expected QMTEST_CLASS_PATH should contain ${theQmtDir} or ${theQmtDirP}"
    exit 1
  fi
167
168
169
170
fi

# Check that valgrind is available if required
if [ "$CORAL_TESTSUITE_VALGRIND" == "1" ]; then
171
  ${ccrun} which valgrind > /dev/null 2>&1
172
173
174
175
176
177
178
179
  if [ "$?" != "0" ]; then
    echo "ERROR! No path to valgrind"
    echo "PATH is:$PATH" | tr ":" "\n"
    exit 1
  fi
  # Fix "valgrind: failed to start tool 'memcheck' for platform 'amd64-linux'"
  # relocatability issues by setting VALGRIND_LIB (thanks to Rolf!)
  # [NB already set via CMT/CMake; redundantly set here for native valgrind use]
180
  binvalgrind=`${ccrun} which valgrind`
181
182
183
184
185
186
187
  binvalgrind=`dirname $binvalgrind`
  if [ ! -d $binvalgrind/../lib/valgrind ]; then
    echo "ERROR! Directory $binvalgrind/../lib/valgrind does not exist!"
    exit 1
  fi
  VALGRIND_LIB=`cd $binvalgrind/../lib/valgrind; pwd`
  # Set the path to the suppression file (no longer set via CMT!)
188
  ${ccrun} which coralValgrindWrapper.sh > /dev/null 2>&1
189
190
191
192
193
  if [ "$?" != "0" ]; then
    echo "ERROR! No path to coralValgrindWrapper.sh"
    echo "PATH is:$PATH" | tr ":" "\n"
    exit 1
  fi
194
  CORAL_TESTSUITE_VALGRIND_SUPP=`${ccrun} which coralValgrindWrapper.sh`
195
196
197
198
199
200
  CORAL_TESTSUITE_VALGRIND_SUPP=`dirname ${CORAL_TESTSUITE_VALGRIND_SUPP}`
  CORAL_TESTSUITE_VALGRIND_SUPP=`cd ${CORAL_TESTSUITE_VALGRIND_SUPP}; pwd`/valgrind.supp
  if [ ! -f "${CORAL_TESTSUITE_VALGRIND_SUPP}" ]; then
    echo "ERROR! Suppression file not found: ${CORAL_TESTSUITE_VALGRIND_SUPP}" 
    exit 1
  fi
201
  CORAL_TESTSUITE_VALGRIND_LOGDIR=${theQmrDir}/valgrind # No trailing '/'
202
203
204
fi

# Run the tests from the qmtest directory
205
echo "Using CORALCOOL_QMTEST_WORKDIR=${CORALCOOL_QMTEST_WORKDIR}"
206
cd $theQmtDir
207
208
209
210
if [ "${BINARY_TAG}" == "" ]; then
  echo "ERROR! BINARY_TAG is not set"
  exit 1
fi
211
theQmr=${theQmrDir}/${BINARY_TAG}.qmr # Drop "-cmake" (CORALCOOL-2842)
212
echo "Launch tests - results will be in ${theQmr}"
213
qmtestRun="qmtest run"
214
215
qmtestSum="qmtest summarize"
if [ `${ccrun} python -c 'import platform; print platform.system()'` == "Darwin" ]; then qmtestRun="python `${ccrun} which qmtest` run"; qmtestSum="python `${ccrun} which qmtest` summarize"; fi # CORALCOOL-2884 and CORALCOOL-2883
216
echo Execute \'${ccrun} ${qmtestRun} ${theTests}\'
217
${ccrun} -q VALGRIND_LIB=$VALGRIND_LIB CORAL_TESTSUITE_VALGRIND_SUPP=$CORAL_TESTSUITE_VALGRIND_SUPP CORAL_TESTSUITE_VALGRIND_LOGDIR=$CORAL_TESTSUITE_VALGRIND_LOGDIR ${qmtestRun} -o ${theQmr} ${theTests} > /dev/null # NB Extra env are needed (and more explicit than "export")!
218
${ccrun} -q ${qmtestSum} -f stats ${theQmr} ${theTests} | awk 'BEGIN{out=0}{if ($2=="STATISTICS") out=1; if (out==1) print}'
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235

# Beautify and move the valgrind logs
if [ "$CORAL_TESTSUITE_VALGRIND" == "1" ]; then
  cd $theQmrDir/valgrind
  valfiles=`ls $BINARY_TAG/valgrind.*`
  if [ "$valfiles" == "" ]; then
    echo "WARNING! No valgrind logs found in $theQmrDir/valgrind/$BINARY_TAG/"
  else
    for valfile in $valfiles; do
      ###echo $valfile
      ${theQmtDir}/sedValgrindLog.sh $valfile
      mv $valfile .
    done
  fi
fi

# Do not attempt to run 'qmtest report/summarize' as "$?" is wrong on OSX?