PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/run_tests.ksh

https://gitlab.com/ECCC_CMDN/vgrid
Korn Shell | 114 lines | 97 code | 8 blank | 9 comment | 22 complexity | a39671c26243798e4d267298f865e383 MD5 | raw file
  1. #!/bin/ksh
  2. eval `cclargs \
  3. -ONLY "" "" "[Test to run, leave blank to run all tests]"\
  4. ++ $*`
  5. # Get list of tests
  6. if [ "${ONLY}" = "" ] ; then
  7. set -A tests $(ls -1 src_tests/*.F90 | perl -p -e 's|src_tests/(.+)\.F90|$1|g') $(ls -1 src_tests/*.c | perl -p -e 's|src_tests/(.+)\.c|$1|g')
  8. else
  9. set -A tests ${ONLY}
  10. fi
  11. which gmake && MAKE=gmake || MAKE=make
  12. #==============
  13. function Other_Tests {
  14. result_o=' ok'
  15. if [ ${test} = get_quiet ];then
  16. . ksh/other_test.dot
  17. fi
  18. }
  19. #==============
  20. # Compile all tests
  21. printf "Compiling tests\n"
  22. template=Makefile.tmpl
  23. compile_log=compile.log
  24. rm -f ${compile_log}
  25. for test in ${tests[*]} ; do
  26. # OpenMP ?
  27. if echo ${test} | grep -q OMP ;then
  28. OPENMP=-openmp
  29. OPENMP_MESSAGE='OPENMP=-openmp'
  30. else
  31. OPENMP=''
  32. OPENMP_MESSAGE=''
  33. fi
  34. # Fortran or C ?
  35. if echo ${test} | grep -q '^c_' ;then
  36. IS_C=yes
  37. EXT=.c
  38. else
  39. IS_C=no
  40. EXT=.F90
  41. fi
  42. printf "Building ${test} ${OPENMP} ..."
  43. ln -sf src_tests/${test}${EXT} .
  44. if [ ${IS_C} = yes ] ;then
  45. perl -p -e "s/UNIT_TEST_C/${test}/g" ${template} >Makefile.test
  46. else
  47. perl -p -e "s/UNIT_TEST_F/${test}/g" ${template} >Makefile.test
  48. fi
  49. echo "Compiling ${test}" >>${compile_log} 2>&1
  50. ${MAKE} -f Makefile.test ${test} OPENMP=${OPENMP} >>${compile_log} 2>&1
  51. if [ ! $? -eq 0 ] ; then
  52. printf "\n ERROR compiling test ${test} ... aborting (try '${MAKE} -f Makefile.test ${test} ${OPENMP_MESSAGE}' for details)\n"
  53. exit 1
  54. fi
  55. rm -f ${test}${EXT}
  56. ${MAKE} -f Makefile.test clean >/dev/null 2>&1
  57. printf " ok\n"
  58. done
  59. printf " * All Builds Succeeded\n"
  60. #==============
  61. # Run all tests
  62. printf "Running tests\n"
  63. report_file=test_report.txt
  64. passed=0
  65. failed=0
  66. for test in ${tests[*]} ; do
  67. if echo ${test} | grep -q OMP ;then
  68. if [ ${BASE_ARCH} != Linux ];then
  69. export OMP_NUM_THREADS=12
  70. MESSAGE=" with OMP_NUM_THREADS=${OMP_NUM_THREADS} "
  71. else
  72. export OMP_NUM_THREADS=1
  73. MESSAGE=''
  74. fi
  75. else
  76. export OMP_NUM_THREADS=1
  77. MESSAGE=''
  78. fi
  79. printf "Testing ${test} ${MESSAGE}..."
  80. ./${test} >${test}.out 2>&1
  81. result=`cat ${report_file}`
  82. Other_Tests
  83. if [[ ${result} == ' ok' && ${result_o} == ' ok' ]] ; then
  84. passed=$((passed + 1))
  85. printf "${result}\n"
  86. rm -f ${test} ${test}.out
  87. else
  88. failed=$((failed + 1))
  89. if [ "${result}" != ' ok' ];then
  90. printf "${result} (see ${test}.out for details)\n"
  91. else
  92. printf " Shell script test failled, see reason above"
  93. fi
  94. fi
  95. rm -f ${report_file}
  96. done
  97. rm -f fort.* test.bin
  98. total=$((passed + failed))
  99. if [[ ${failed} > 0 ]] ; then
  100. printf " * Failed ${failed}/${total} Tests\n"
  101. exit 1
  102. else
  103. printf " * All Tests Succeeded\n"
  104. rm -f Makefile.test
  105. rm -f compile.log
  106. fi