1 | #!/bin/bash |
---|
2 | # Script for running JModelica.org test suites. |
---|
3 | # Copy this file to somewhere in your PATH. |
---|
4 | # You may need to change variables below (in the copy) to match your system. |
---|
5 | # Type "tests -h" for usage. |
---|
6 | # Requires Unix-like system with bash, grep, dc, mktemp, uname and sed. |
---|
7 | |
---|
8 | merge_path() { |
---|
9 | if [ "$1" = "" ]; then |
---|
10 | if [ "$3" = "" ]; then |
---|
11 | echo $2 |
---|
12 | else |
---|
13 | echo $3@SEP@$2 |
---|
14 | fi |
---|
15 | else |
---|
16 | echo $1@SEP@$2 |
---|
17 | fi |
---|
18 | } |
---|
19 | |
---|
20 | # ====== Variables to set ====== |
---|
21 | |
---|
22 | # Memory allocation for the ant process |
---|
23 | ANT_OPTS="-Xmx4g" |
---|
24 | |
---|
25 | # Default tests - run if no tests are chosen |
---|
26 | # Possible values: modelica, optimica, python or combination (e.g. "modelica optimica") |
---|
27 | DEFAULT_TESTS="optimica python" |
---|
28 | |
---|
29 | # Default arguments - always parse these arguments before command line |
---|
30 | DEFAULT_ARGS="" |
---|
31 | |
---|
32 | # Variables set by configure script |
---|
33 | JMODELICA_HOME="@prefix@" |
---|
34 | JMODELICA_SRC="@abs_top_srcdir@" |
---|
35 | IPOPT_HOME="@IPOPT_HOME@" |
---|
36 | IPOPT32_HOME="@IPOPT_HOME@" |
---|
37 | IPOPT64_HOME="@IPOPT64_HOME@" |
---|
38 | PYTHON64_HOME="@PYTHON64_HOME@" |
---|
39 | PYTHON32_HOME="@PYTHON_HOME@" |
---|
40 | SUNDIALS_HOME="@prefix@/ThirdParty/Sundials" |
---|
41 | CASADI_HOME="@prefix@/ThirdParty/CasADi" |
---|
42 | CASADI64_HOME="@prefix@/ThirdParty/CasADi64" |
---|
43 | CASADI_INTERFACE_HOME="@prefix@/lib/casadi_interface" |
---|
44 | CASADI_INTERFACE_HOME64="@prefix@/lib/casadi_interface64" |
---|
45 | CASADI_INTERFACE_HOME32=${CASADI_INTERFACE_HOME} |
---|
46 | ECLIPSE_HOME="@ECLIPSE_HOME@" |
---|
47 | JPYPE32_JVM="@JVMDLL_HOME@/jvm.dll" |
---|
48 | JPYPE64_JVM="@JVMDLL64_HOME@/jvm.dll" |
---|
49 | ORIG_PATH="@ORIG_PATH@" |
---|
50 | BUILD="@abs_builddir@" |
---|
51 | if [[ "${JAVA_HOME}" == "" ]]; then |
---|
52 | JAVA_HOME="@_JAVA_HOME_@" |
---|
53 | fi |
---|
54 | |
---|
55 | if [[ "${PYTHON64_HOME}" != "" ]]; then |
---|
56 | DEFAULT_TESTS="${DEFAULT_TESTS} python64" |
---|
57 | fi |
---|
58 | |
---|
59 | # ====== End variables to set ====== |
---|
60 | |
---|
61 | # Configure Bash |
---|
62 | set -o pipefail |
---|
63 | |
---|
64 | PYTHONPATH64="${JMODELICA_HOME}/Python_64/" |
---|
65 | PYTHONPATH32="$(merge_path "${PYTHONPATH}" "${JMODELICA_HOME}/Python/")" |
---|
66 | PYTHONPATH="$PYTHONPATH32" |
---|
67 | |
---|
68 | # To know if we are running python 64 tests |
---|
69 | PYTHON64=0 |
---|
70 | |
---|
71 | # Default paths to ant files used for unit tests |
---|
72 | if [[ -z "${MC_ANT_ARGS}" ]]; then |
---|
73 | MC_ANT_ARGS=${JMODELICA_SRC}/Compiler/ModelicaCompiler/build.xml |
---|
74 | fi |
---|
75 | if [[ -z "${OC_ANT_ARGS}" ]]; then |
---|
76 | OC_ANT_ARGS=${JMODELICA_SRC}/Compiler/OptimicaCompiler/build.xml |
---|
77 | fi |
---|
78 | |
---|
79 | # Find operating system |
---|
80 | SYS="$(uname -s)" |
---|
81 | if [[ "${SYS}" == "Darwin" ]]; then |
---|
82 | SYS=Mac |
---|
83 | elif [[ "${SYS:0:5}" == "MINGW" ]]; then |
---|
84 | SYS=Win |
---|
85 | fi |
---|
86 | |
---|
87 | # Update library path |
---|
88 | if [[ "${SUNDIALS_HOME}" != "" ]]; then |
---|
89 | LIB_PATH="${SUNDIALS_HOME}/lib" |
---|
90 | fi |
---|
91 | if [[ "${IPOPT_HOME}" != "" ]]; then |
---|
92 | LIB_PATH="$(merge_path "${LIB_PATH}" "${IPOPT_HOME}/lib")" |
---|
93 | fi |
---|
94 | if [[ "${CASADI_HOME}" != "" ]]; then |
---|
95 | LIB_PATH="$(merge_path "${LIB_PATH}" "${CASADI_HOME}/lib")" |
---|
96 | fi |
---|
97 | if [[ "${LIB_PATH}" != "" ]]; then |
---|
98 | LD_LIBRARY_PATH="$(merge_path "${LD_LIBRARY_PATH}" "${LIB_PATH}" /lib)" |
---|
99 | fi |
---|
100 | |
---|
101 | # Test sets |
---|
102 | if [[ "${PYTHON64_HOME}" != "" ]]; then |
---|
103 | test_set_a="modelica optimica python python64" |
---|
104 | tests="modelica optimica python python64" |
---|
105 | else |
---|
106 | test_set_a="modelica optimica python" |
---|
107 | tests="modelica optimica python" |
---|
108 | fi |
---|
109 | test_set_j="modelica optimica" |
---|
110 | test_set_m="modelica" |
---|
111 | test_set_o="optimica" |
---|
112 | test_set_p="python" |
---|
113 | test_set_z="python64" |
---|
114 | |
---|
115 | # Standard set of tags |
---|
116 | TAGS="-a stddist_base -a noncompliantfmi" |
---|
117 | if [[ "${IPOPT_HOME}" != "" ]]; then |
---|
118 | TAGS="${TAGS} -a ipopt" |
---|
119 | if [[ "${SYS}" == Win ]]; then |
---|
120 | TAGS="${TAGS} -a windows_base" |
---|
121 | fi |
---|
122 | if [[ -e "${JMODELICA_HOME}/Python/casadi" ]]; then |
---|
123 | TAGS="${TAGS} -a casadi_base" |
---|
124 | else |
---|
125 | echo Skipping casadi tests, since CasADi does not seem to be installed. |
---|
126 | fi |
---|
127 | fi |
---|
128 | |
---|
129 | # Standard set of tags |
---|
130 | TAGS64="-a stddist_base -a noncompliantfmi" |
---|
131 | if [[ "${IPOPT64_HOME}" != "" ]]; then |
---|
132 | TAGS64="${TAGS64} -a ipopt" |
---|
133 | if [[ "${SYS}" == Win ]]; then |
---|
134 | TAGS64="${TAGS64} -a windows_base" |
---|
135 | fi |
---|
136 | if [[ -e "${JMODELICA_HOME}/Python_64/casadi" ]]; then |
---|
137 | TAGS64="${TAGS64} -a casadi_base" |
---|
138 | else |
---|
139 | echo Skipping casadi tests, since CasADi does not seem to be installed. |
---|
140 | fi |
---|
141 | fi |
---|
142 | |
---|
143 | # Extend with all tests for default version of Python/bitness |
---|
144 | if [[ "${PYTHON64_HOME}" != "" ]]; then |
---|
145 | TAGS64="${TAGS64} -a stddist_full" |
---|
146 | if [[ "${IPOPT64_HOME}" != "" ]]; then |
---|
147 | if [[ "${SYS}" == Win ]]; then |
---|
148 | TAGS64="${TAGS64} -a windows_full" |
---|
149 | fi |
---|
150 | if [[ -e "${JMODELICA_HOME}/Python_64/casadi" ]]; then |
---|
151 | TAGS64="${TAGS64} -a casadi_full" |
---|
152 | fi |
---|
153 | fi |
---|
154 | else |
---|
155 | TAGS="${TAGS} -a stddist_full" |
---|
156 | if [[ "${IPOPT_HOME}" != "" ]]; then |
---|
157 | if [[ "${SYS}" == Win ]]; then |
---|
158 | TAGS="${TAGS} -a windows_full" |
---|
159 | fi |
---|
160 | if [[ -e "${JMODELICA_HOME}/Python/casadi" ]]; then |
---|
161 | TAGS="${TAGS} -a casadi_full" |
---|
162 | else |
---|
163 | echo Skipping casadi tests, since CasADi does not seem to be installed. |
---|
164 | fi |
---|
165 | fi |
---|
166 | fi |
---|
167 | |
---|
168 | # Functions for running specific tests |
---|
169 | function modelica_tests() { |
---|
170 | junit_test Modelica |
---|
171 | } |
---|
172 | |
---|
173 | function optimica_tests() { |
---|
174 | echo "in optimica_tests()" |
---|
175 | junit_test Optimica |
---|
176 | } |
---|
177 | |
---|
178 | TESTS_DIR="${JMODELICA_HOME}/Python/tests_jmodelica" |
---|
179 | function find_python_tests() { |
---|
180 | if [[ "${TESTS}" == "" ]]; then |
---|
181 | TESTS="$(find ${TESTS_DIR} -name \*.py | grep test_)" |
---|
182 | fi |
---|
183 | } |
---|
184 | |
---|
185 | function python_tests() { |
---|
186 | if [ "${KEEP_PYTHON}" == 1 ]; then |
---|
187 | TEST_DIR="$(pwd)/tests_$(date "+%F_%H-%M-%S")" |
---|
188 | mkdir ${TEST_DIR} |
---|
189 | else |
---|
190 | TEST_DIR=$(mktemp -dq /tmp/jm_tests.XXXXXX) |
---|
191 | fi |
---|
192 | print_name Python |
---|
193 | res=0 |
---|
194 | case ${OUTPUT} in |
---|
195 | v) |
---|
196 | if build_jmodelica 2>&1 | log; then |
---|
197 | find_python_tests |
---|
198 | cd ${TEST_DIR} |
---|
199 | python_tests_v || res=1 |
---|
200 | fi |
---|
201 | ;; |
---|
202 | q) |
---|
203 | if build_jmodelica 2>&1 | log > /dev/null; then |
---|
204 | find_python_tests |
---|
205 | cd ${TEST_DIR} |
---|
206 | python_tests_q | filter_python_separate || res=1 |
---|
207 | else |
---|
208 | echo BUILD FAILED |
---|
209 | fi |
---|
210 | ;; |
---|
211 | n) |
---|
212 | if [[ "${NO_BUILD_JMODELICA}" != "1" ]]; then |
---|
213 | echo "OUTPUT=${OUTPUT}" |
---|
214 | echo "NO_BUILD_JMODELICA=${NO_BUILD_JMODELICA}" |
---|
215 | echo Building... |
---|
216 | fi |
---|
217 | if build_jmodelica | log > /dev/null; then |
---|
218 | find_python_tests |
---|
219 | cd ${TEST_DIR} |
---|
220 | python_tests_n | filter_python_separate || res=1 |
---|
221 | fi |
---|
222 | ;; |
---|
223 | esac |
---|
224 | if [ ! "${KEEP_PYTHON}" == 1 ]; then |
---|
225 | cd .. |
---|
226 | rm -rf ${TEST_DIR} |
---|
227 | fi |
---|
228 | return $res |
---|
229 | } |
---|
230 | |
---|
231 | TESTS64_DIR="${JMODELICA_HOME}/Python_64/tests_jmodelica" |
---|
232 | function python64_tests() { |
---|
233 | # Set necessary paths etc to run 64 bit tests |
---|
234 | PYTHONPATH=${PYTHONPATH64} |
---|
235 | PYTHONHOME=${PYTHON64_HOME} |
---|
236 | JPYPE_JVM=${JPYPE64_JVM} |
---|
237 | CASADI_LIB_HOME=${CASADI64_HOME}/lib |
---|
238 | CASADI_INTERFACE_HOME=${CASADI_INTERFACE_HOME64} |
---|
239 | PATH=${PYTHON64_HOME}:${PYTHON64_HOME}/Scripts:${PYTHON64_HOME}/Lib:${IPOPT64_HOME}/bin:${CASADI_LIB_HOME}:"${PATH}" |
---|
240 | TESTS32=$TESTS |
---|
241 | TESTS=$TESTS64 |
---|
242 | TAGS32=$TAGS |
---|
243 | TAGS=$TAGS64 |
---|
244 | TESTS_DIR=${TESTS64_DIR} |
---|
245 | PYTHON64=1 |
---|
246 | # Call python_tests |
---|
247 | res=0 |
---|
248 | python_tests || res=1 |
---|
249 | # Reset to original paths etc that was for original Python |
---|
250 | TESTS=$TESTS32 |
---|
251 | TAGS=$TAGS32 |
---|
252 | PYTHON64=0 |
---|
253 | PYTHONPATH=${PYTHONPATH32} |
---|
254 | PYTHONHOME=${PYTHON32_HOME} |
---|
255 | JPYPE_JVM=${JPYPE32_JVM} |
---|
256 | CASADI_LIB_HOME=${CASADI_HOME}/lib |
---|
257 | CASADI_INTERFACE_HOME=${CASADI_INTERFACE_HOME32} |
---|
258 | PATH="${ORIG_PATH}" |
---|
259 | TESTS_DIR="${JMODELICA_HOME}/Python/tests_jmodelica" |
---|
260 | return $res |
---|
261 | } |
---|
262 | |
---|
263 | function python_tests_v() { |
---|
264 | res=0 |
---|
265 | for TEST in ${TESTS}; do |
---|
266 | echo "" |
---|
267 | echo ${TEST} | sed -e 's!^.*jmodelica.!Running !' |
---|
268 | nose_test ${TEST} \ |
---|
269 | | log \ |
---|
270 | || res=1 |
---|
271 | done |
---|
272 | return $res |
---|
273 | } |
---|
274 | |
---|
275 | function python_tests_q() { |
---|
276 | res=0 |
---|
277 | for TEST in ${TESTS}; do |
---|
278 | echo "" | log > /dev/null |
---|
279 | echo ${TEST} | sed -e 's!^.*jmodelica.!Running !' | log > /dev/null |
---|
280 | nose_test ${TEST} 2>&1 \ |
---|
281 | | log \ |
---|
282 | | sed -n -e 's!^OK$!PASSED!ip' -e 's!^FAILED !TEST FAILED!p' \ |
---|
283 | || (res=1 && echo NOSETESTS_NOT_OK) |
---|
284 | done |
---|
285 | return $res |
---|
286 | } |
---|
287 | |
---|
288 | function python_tests_n() { |
---|
289 | PATTERN="[-=]{40,}" |
---|
290 | res=0 |
---|
291 | for TEST in ${TESTS}; do |
---|
292 | echo "" | log |
---|
293 | echo ${TEST} | sed -e 's!^.*jmodelica.!Running !' | log |
---|
294 | nose_test ${TEST} 2>&1 \ |
---|
295 | | log \ |
---|
296 | | egrep -v '^Exception .* ignored$' \ |
---|
297 | | egrep -A500 "${PATTERN}" \ |
---|
298 | | sed -e 's!^OK$!PASSED!' -e 's!^FAILED !TEST FAILED!' \ |
---|
299 | || (res=1 && echo NOSETESTS_NOT_OK) |
---|
300 | done |
---|
301 | return $res |
---|
302 | } |
---|
303 | |
---|
304 | # Helper functions |
---|
305 | function print_name() { |
---|
306 | if [[ "${OUTPUT}" == q ]]; then |
---|
307 | echo -n "$1... " |
---|
308 | else |
---|
309 | echo ======= $1 ======= |
---|
310 | fi |
---|
311 | } |
---|
312 | |
---|
313 | function log() { |
---|
314 | if [ "${LOG}" == 1 ]; then |
---|
315 | tee -a "${LOGFILE}" |
---|
316 | else |
---|
317 | cat |
---|
318 | fi |
---|
319 | } |
---|
320 | |
---|
321 | function filter_python_separate() { |
---|
322 | TMP=$(mktemp -q /tmp/jm_tests.XXXXXX 2>/dev/null) |
---|
323 | tee ${TMP} | egrep -v "(PASSED|TEST FAILED|NOSETESTS_NOT_OK)" |
---|
324 | cat ${TMP} \ |
---|
325 | | sed -n \ |
---|
326 | -e '1 i\ |
---|
327 | 0 0 0' \ |
---|
328 | -e 's!^TEST FAILED(errors=\([0-9]*\))!\1+!p' \ |
---|
329 | -e 's!^TEST FAILED(failures=\([0-9]*\))!r\1+r!p' \ |
---|
330 | -e 's!^TEST FAILED(errors=\([0-9]*\), failures=\([0-9]*\))!\1+r\2+r!p' \ |
---|
331 | -e 's!^NOSETESTS_NOT_OK!sar1+rla!p' \ |
---|
332 | -e '$ a\ |
---|
333 | n[ ]nn[ ]np' \ |
---|
334 | | dc \ |
---|
335 | | sed \ |
---|
336 | -e 's!0 0 [1-9].*!CRASHED!' \ |
---|
337 | -e 's!0 0 0!PASSED!' \ |
---|
338 | -e 's!\([0-9]\+\) \([0-9]\+\) .*!TEST FAILED (errors=\1, failures=\2)!' |
---|
339 | rm -f ${TMP} |
---|
340 | } |
---|
341 | |
---|
342 | function junit_test() { |
---|
343 | print_name $1 |
---|
344 | cd ${BUILD}/java |
---|
345 | echo "doing ls..." |
---|
346 | ls -la |
---|
347 | res=0 |
---|
348 | case ${OUTPUT} in |
---|
349 | v) junit_test_v $1 || res=1 ;; |
---|
350 | q) junit_test_q $1 || res=1 ;; |
---|
351 | n) junit_test_n $1 || res=1 ;; |
---|
352 | esac |
---|
353 | if [ -n "${XML_RES_PATH:-}" ]; then |
---|
354 | cp "${BUILD}/doc/junit-reports/TESTS-TestSuites.xml" "${XML_RES_PATH}" |
---|
355 | fi |
---|
356 | return $res |
---|
357 | } |
---|
358 | |
---|
359 | function junit_test_v() { |
---|
360 | res=0 |
---|
361 | ant_test $1 2>&1 \ |
---|
362 | | log \ |
---|
363 | || res=1 |
---|
364 | return $res |
---|
365 | } |
---|
366 | |
---|
367 | function junit_test_q() { |
---|
368 | res=0 |
---|
369 | ant_test $1 2>&1 \ |
---|
370 | | log \ |
---|
371 | | egrep "(\[(jastadd|junit)\]|BUILD FAILED|\[java\] Error when parsing file:)" \ |
---|
372 | | sed -n \ |
---|
373 | -e '1 i\ |
---|
374 | 0 0' \ |
---|
375 | -e 's!^.*\[jastadd\] \(Semantic errors\|Syntax error\).*$!BUILD FAILED!' \ |
---|
376 | -e 's!^.*\[java\] Error when parsing file:.*$!BUILD FAILED!' \ |
---|
377 | -e 's!^.*Failures: \([0-9]*\), Errors: \([0-9]*\),.*$!r\1+r\2+!p' \ |
---|
378 | -e 's!^.*\(BUILD FAILED\).*$![\1]pq!p' \ |
---|
379 | -e '$ a\ |
---|
380 | [errors=]nn[, failures=]np' \ |
---|
381 | | dc \ |
---|
382 | | sed \ |
---|
383 | -e 's!errors=0, failures=0!PASSED!' \ |
---|
384 | -e 's!\(errors=.*, failures=.*\)!TEST FAILED (\1)!' \ |
---|
385 | || res=1 |
---|
386 | return $res |
---|
387 | } |
---|
388 | |
---|
389 | function junit_test_n() { |
---|
390 | echo "in junit_test_n" |
---|
391 | res=0 |
---|
392 | ant_test $1 \ |
---|
393 | | log \ |
---|
394 | | egrep "(\[junit\]|\[(java|jastadd)\].*([Ee]rror|[A-Za-z.]*:[1-9][0-9]*))" \ |
---|
395 | || res=1 |
---|
396 | return $res |
---|
397 | } |
---|
398 | |
---|
399 | function nose_test() { |
---|
400 | nosetests `compute_nose_extra_args "${TEST}"` ${TAGS} -v $1 |
---|
401 | } |
---|
402 | |
---|
403 | function ant_test() { |
---|
404 | echo "MC_ANT_ARGS=${MC_ANT_ARGS}" |
---|
405 | echo "OC_ANT_ARGS=${OC_ANT_ARGS}" |
---|
406 | echo "BUILD=${BUILD}" |
---|
407 | echo "CLEAN_JUNIT=${CLEAN_JUNIT}" |
---|
408 | if [[ "$1" == "Modelica" ]]; then |
---|
409 | ant ${ANT_OPTS} -f ${MC_ANT_ARGS} -Dtarget=${BUILD} ${CLEAN_JUNIT} test |
---|
410 | else |
---|
411 | ant ${ANT_OPTS} -f ${OC_ANT_ARGS} -Dtarget=${BUILD} ${CLEAN_JUNIT} test |
---|
412 | fi |
---|
413 | echo "about to ls" |
---|
414 | ls -la ${BUILD} |
---|
415 | } |
---|
416 | |
---|
417 | function build_jmodelica() { |
---|
418 | if [[ "${NO_BUILD_JMODELICA}" != "1" ]]; then |
---|
419 | if [[ -d ${BUILD} ]]; then |
---|
420 | cd ${BUILD} |
---|
421 | ${CLEAN_BUILD} |
---|
422 | make && make install |
---|
423 | else |
---|
424 | echo Cannot build, build dir does not exist! |
---|
425 | exit 1 |
---|
426 | fi |
---|
427 | fi |
---|
428 | } |
---|
429 | |
---|
430 | function switch_test_flags() { |
---|
431 | STATE=0 |
---|
432 | for a in $*; do |
---|
433 | if [[ "${test[${!a}]}" != 1 ]]; then |
---|
434 | STATE=1 |
---|
435 | fi |
---|
436 | done |
---|
437 | for a in $*; do |
---|
438 | test[${!a}]=${STATE} |
---|
439 | done |
---|
440 | } |
---|
441 | |
---|
442 | function compute_nose_extra_args() { # Argument is test name |
---|
443 | if [ -n "${XML_RES_PATH:-}" ]; then |
---|
444 | RES_FILE_NAME=`echo $1 | sed -e 's!^.*jmodelica.!!g' -e 's!/!_!g'` |
---|
445 | if [[ "$PYTHON64" = 1 ]]; then |
---|
446 | RES_FILE_NAME="python64_${RES_FILE_NAME}" |
---|
447 | fi |
---|
448 | echo --with-xunit --xunit-file=${XML_RES_PATH}/${RES_FILE_NAME}.xml |
---|
449 | fi |
---|
450 | } |
---|
451 | |
---|
452 | function read_args() { |
---|
453 | TESTS= |
---|
454 | TESTS64= |
---|
455 | ARG_TYPE=flag |
---|
456 | echo "DEFAULT_ARGS=${DEFAULT_ARGS}" |
---|
457 | for a in ${DEFAULT_ARGS} "$@"; do |
---|
458 | echo a=$a |
---|
459 | if [[ "$(echo $a | head -c1)" == "-" ]]; then |
---|
460 | ARG_TYPE=flag |
---|
461 | fi |
---|
462 | FLAG=0 |
---|
463 | case ${ARG_TYPE} in |
---|
464 | flag) |
---|
465 | FLAG=1 |
---|
466 | echo FLAG=$FLAG |
---|
467 | ;; |
---|
468 | tag) |
---|
469 | TAGS="${TAGS} -a ${a}" |
---|
470 | ;; |
---|
471 | tag64) |
---|
472 | TAGS64="${TAGS64} -a ${a}" |
---|
473 | ;; |
---|
474 | file) |
---|
475 | if [[ -f "${a}" ]]; then |
---|
476 | FILE="$(readlink -f ${a})" |
---|
477 | else |
---|
478 | FILE="${TESTS_DIR}/${a}" |
---|
479 | FILE64="${TESTS64_DIR}/${a}" |
---|
480 | fi |
---|
481 | if [[ -f ${FILE} ]]; then |
---|
482 | TESTS="${TESTS} ${FILE}" |
---|
483 | else |
---|
484 | echo "Cannot find test file ${a}" |
---|
485 | exit |
---|
486 | fi |
---|
487 | if [[ "${PYTHON64_HOME}" != "" ]]; then |
---|
488 | if [[ -f ${FILE64} ]]; then |
---|
489 | TESTS64="${TESTS64} ${FILE64}" |
---|
490 | else |
---|
491 | echo "Cannot find test file ${a}" |
---|
492 | exit |
---|
493 | fi |
---|
494 | fi |
---|
495 | ;; |
---|
496 | xmlResPath) |
---|
497 | XML_RES_PATH=${a} |
---|
498 | ARG_TYPE=flag |
---|
499 | ;; |
---|
500 | esac |
---|
501 | if [[ ${FLAG} == 1 ]]; then |
---|
502 | echo "In flag == 1 with a=${a}" |
---|
503 | a_split="" |
---|
504 | for ((i=0; i<${#a}; i++)); do a_split="$a_split ${a:$i:1}"; done |
---|
505 | echo a_split="$a_split" |
---|
506 | for b in $a_split; do |
---|
507 | HAVE_READ_ARGS=1 |
---|
508 | echo b=${b} |
---|
509 | case ${b} in |
---|
510 | -) |
---|
511 | ;; |
---|
512 | v|q|n) |
---|
513 | OUTPUT=${b} |
---|
514 | ;; |
---|
515 | a|j|m|o|p) |
---|
516 | test_set="test_set_${b}" |
---|
517 | switch_test_flags ${!test_set} |
---|
518 | ;; |
---|
519 | z) |
---|
520 | if ! [[ "${PYTHON64_HOME}" != "" ]]; then |
---|
521 | echo "Python 64 bit tests not supported!" |
---|
522 | exit |
---|
523 | fi |
---|
524 | test_set="test_set_${b}" |
---|
525 | switch_test_flags ${!test_set} |
---|
526 | ;; |
---|
527 | c|C) |
---|
528 | CLEAN_JUNIT=clean |
---|
529 | if [[ "${b}" == C ]]; then |
---|
530 | CLEAN_BUILD="make clean" |
---|
531 | fi |
---|
532 | ;; |
---|
533 | i) |
---|
534 | NO_BUILD_JMODELICA=1 |
---|
535 | ;; |
---|
536 | k) |
---|
537 | KEEP_PYTHON=1 |
---|
538 | ;; |
---|
539 | l) |
---|
540 | LOG=$((1-LOG)) |
---|
541 | ;; |
---|
542 | f) |
---|
543 | ARG_TYPE=file |
---|
544 | ;; |
---|
545 | t) |
---|
546 | TAGS="" |
---|
547 | ARG_TYPE=tag |
---|
548 | ;; |
---|
549 | u) |
---|
550 | if ! [[ "${PYTHON64_HOME}" != "" ]]; then |
---|
551 | echo "Python 64 bit tests not supported!" |
---|
552 | exit |
---|
553 | fi |
---|
554 | TAGS64="" |
---|
555 | ARG_TYPE=tag64 |
---|
556 | ;; |
---|
557 | g) |
---|
558 | if ! [[ "${PYTHON64_HOME}" != "" ]]; then |
---|
559 | echo "Python 64 bit tests not supported!" |
---|
560 | exit |
---|
561 | fi |
---|
562 | ARG_TYPE=tag |
---|
563 | ;; |
---|
564 | r) |
---|
565 | ARG_TYPE=tag64 |
---|
566 | ;; |
---|
567 | x) |
---|
568 | ARG_TYPE=xmlResPath |
---|
569 | ;; |
---|
570 | e) |
---|
571 | ERROR_ON_TEST_FAIL=1 |
---|
572 | ;; |
---|
573 | h) |
---|
574 | echo "usage: tests [-ajmopzvnqcCh] { [-(t|u|g|r) [tag1 ...]] } [-f file1 ...] [-x path]" |
---|
575 | echo "The -ajmopz options each control a set of tests, and select all tests in set " |
---|
576 | echo "for running, or, if all in set are already selected, deselects them. " |
---|
577 | echo "Thus, \"tests -am\" runs all tests except modelica. If no tests are chosen, " |
---|
578 | echo "a default set is run (${DEFAULT_TESTS})." |
---|
579 | echo " -a Select/deselect all tests" |
---|
580 | echo " -j Select/deselect junit tests" |
---|
581 | echo " -m Select/deselect modelica tests" |
---|
582 | echo " -o Select/deselect optimca tests" |
---|
583 | echo " -p Select/deselect python tests" |
---|
584 | echo " -z Select/deselect python 64 bit tests (not always a valid option)" |
---|
585 | echo " -v Verbose output, show everything" |
---|
586 | echo " -n Normal output, only show results and compilation errors" |
---|
587 | echo " -q Quiet output, only show brief results" |
---|
588 | echo " -c Do a clean before junit tests" |
---|
589 | echo " -C Do a clean before each test suite" |
---|
590 | echo " -i Do not re-build before python tests" |
---|
591 | echo " -k Keep generated files from python tests" |
---|
592 | echo " -l Toggle creating log file with the equivalent of the output with -v" |
---|
593 | echo " (on by default)" |
---|
594 | echo " -t When running python tests, only run tests marked with one of the " |
---|
595 | echo " listed tags. If given without tags, all tests are run. If -t is " |
---|
596 | echo " given several times, only the last one will be used (not always a valid option)" |
---|
597 | echo " -u When running python64 tests, only run tests marked with one of the " |
---|
598 | echo " listed tags. If given without tags, all tests are run. If -u is " |
---|
599 | echo " given several times, only the last one will be used" |
---|
600 | echo " -g When running python tests, add the listed tags to the tags to use" |
---|
601 | echo " -r When running python 64tests, add the listed tags to the tags to use" |
---|
602 | echo " -f When running python tests, only run tests from the listed files. " |
---|
603 | echo " Paths relative to the tests directory are accepted, as well as " |
---|
604 | echo " absolute or relative to current directory" |
---|
605 | echo " -x Path to folder where jUnit like xml files are written. The xml files" |
---|
606 | echo " contains the results of the tests. Currently doesn't handle spaces" |
---|
607 | echo " in the supplied path!" |
---|
608 | echo " -e When enabled, exit with error code (after running all " |
---|
609 | echo " tests) if any test suite return with an error code or a test fails" |
---|
610 | echo " regular failures or errors). Default behaviour is exit 0.". |
---|
611 | echo " Requires -x". |
---|
612 | echo " -h Print this help and exit" |
---|
613 | exit |
---|
614 | ;; |
---|
615 | *) |
---|
616 | echo "Unknown flag -${b}" |
---|
617 | exit |
---|
618 | ;; |
---|
619 | esac |
---|
620 | done |
---|
621 | else |
---|
622 | HAVE_READ_ARGS=1 |
---|
623 | fi |
---|
624 | done |
---|
625 | } |
---|
626 | |
---|
627 | # === Main === |
---|
628 | OUTPUT=n |
---|
629 | LOGFILE="$(pwd)/tests.log" |
---|
630 | LOG=1 |
---|
631 | i=0 |
---|
632 | for a in ${tests}; do |
---|
633 | test[${i}]=0 |
---|
634 | (( ${a}=i++ )) |
---|
635 | done |
---|
636 | export JAVA_HOME JMODELICA_HOME IPOPT_HOME PYTHONPATH LD_LIBRARY_PATH ANT_OPTS SUNDIALS_HOME |
---|
637 | TIME=$(date +%s) |
---|
638 | |
---|
639 | echo "TIME = ${TIME}" |
---|
640 | echo "before read_args" |
---|
641 | HAVE_READ_ARGS=0 |
---|
642 | echo "PATH=${PATH}" |
---|
643 | echo "args $@" |
---|
644 | read_args "$@" |
---|
645 | if [[ $HAVE_READ_ARGS == 0 ]]; then |
---|
646 | echo "Reading args to jm_tests failed, retrying..." |
---|
647 | read_args "$@" |
---|
648 | fi |
---|
649 | echo "after read_args" |
---|
650 | echo "Writing to LOGFILE=${LOGFILE}" |
---|
651 | if [[ $ERROR_ON_TEST_FAIL == 1 ]]; then |
---|
652 | if [[ -z $XML_RES_PATH ]]; then |
---|
653 | echo "-e needs -x" |
---|
654 | exit 1 |
---|
655 | fi |
---|
656 | fi |
---|
657 | |
---|
658 | if [ "${LOG}" == 1 ]; then |
---|
659 | echo "Log of jm_tests $(date):" > "${LOGFILE}" |
---|
660 | echo "Finished writing log..." |
---|
661 | fi |
---|
662 | |
---|
663 | ANY_ON=0 |
---|
664 | for a in ${tests}; do |
---|
665 | if [[ "${test[${!a}]}" == 1 ]]; then |
---|
666 | ANY_ON=1 |
---|
667 | fi |
---|
668 | done |
---|
669 | |
---|
670 | echo "ANY_ON=${ANY_ON}" |
---|
671 | echo "DEFAULT_TESTS=${DEFAULT_TESTS}" |
---|
672 | if [[ "${ANY_ON}" == 0 ]]; then |
---|
673 | switch_test_flags ${DEFAULT_TESTS} |
---|
674 | fi |
---|
675 | |
---|
676 | # If on Windows, inform user about bug in ticket #766 |
---|
677 | if [[ ${SYS} == Win ]]; then |
---|
678 | echo Note: If modelica or optimica tests seem to hang, press enter a couple of times. |
---|
679 | fi |
---|
680 | |
---|
681 | res=0 |
---|
682 | |
---|
683 | for a in ${tests}; do |
---|
684 | if [[ "${test[${!a}]}" == 1 ]]; then |
---|
685 | echo "Printing going with ${a}_tests" |
---|
686 | fi |
---|
687 | done |
---|
688 | for a in ${tests}; do |
---|
689 | if [[ "${test[${!a}]}" == 1 ]]; then |
---|
690 | echo "going with ${a}_tests" |
---|
691 | ${a}_tests || res=1 |
---|
692 | fi |
---|
693 | done |
---|
694 | |
---|
695 | if [[ "${OUTPUT}" != q ]]; then |
---|
696 | echo ======================== |
---|
697 | fi |
---|
698 | echo $(date +%s) ${TIME}"-[Total time: ]nd60/n[:]n60%[0n]sxd10>xp" | dc |
---|
699 | |
---|
700 | # Rename test names in xml when run with 64 bit python |
---|
701 | if [ -n "${XML_RES_PATH:-}" ]; then |
---|
702 | for f in ${XML_RES_PATH}/*; do |
---|
703 | if [[ "${f}" == *"python64_"* ]]; then |
---|
704 | sed -e 's#classname=\"#classname=\"python64.#g' $f > temp.xml |
---|
705 | mv -f temp.xml $f |
---|
706 | fi |
---|
707 | done |
---|
708 | fi |
---|
709 | |
---|
710 | if [[ "${ERROR_ON_TEST_FAIL}" == 1 ]]; then |
---|
711 | if [[ $res == 0 ]]; then |
---|
712 | grep -R testsuite $XML_RES_PATH | sed -n -e "/.*errors=\"[0]*[1-9][0-9]*\".*/ q1" -e "/.*failures=\"[0]*[1-9][0-9]*\".*/ q1" |
---|
713 | exit $? |
---|
714 | fi |
---|
715 | exit $res |
---|
716 | else |
---|
717 | exit 0 |
---|
718 | fi |
---|