test_framework_GRASS_GIS_with_NC.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/bin/bash
  2. ############################################################################
  3. #
  4. # MODULE: Example script to run testsuite
  5. # AUTHOR(S): Markus Neteler, Sören Gebbert, Vaclav Petras
  6. # PURPOSE: Test GRASS GIS using the test framework
  7. # Documentation:
  8. # https://trac.osgeo.org/grass/wiki/GSoC/2014/TestingFrameworkForGRASS
  9. # https://grass.osgeo.org/grass-devel/manuals/libpython/gunittest_running_tests.html#example-bash-script-to-run-be-used-as-a-cron-job
  10. #
  11. # Data:
  12. # We use the full NC dataset (nc_spm_full_v2_alpha.tar.gz)
  13. #
  14. # COPYRIGHT: (C) 2019-2021 by Markus Neteler, and the GRASS Development Team
  15. #
  16. # This program is free software; you can redistribute it and/or modify
  17. # it under the terms of the GNU General Public License as published by
  18. # the Free Software Foundation; either version 2 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU General Public License for more details.
  25. #
  26. ############################################################################
  27. ### Fetch CONFIGURATION
  28. CONF="test_framework_GRASS_GIS_with_NC.conf"
  29. usage_msg(){
  30. echo "Usage:
  31. $0 [conf_file]
  32. Example:
  33. $0 ./${CONF}
  34. "
  35. }
  36. if [ ! -z "$1" ] ; then
  37. case "$1" in
  38. -h | --h | -help | --help)
  39. usage_msg
  40. exit 0
  41. ;;
  42. *)
  43. if [ -f ${1} ] ; then
  44. CONF="$1"
  45. else
  46. echo "ERROR: $1 is not a file"
  47. exit 1
  48. fi
  49. ;;
  50. esac
  51. else
  52. usage_msg
  53. exit 0
  54. fi
  55. source ${CONF}
  56. ######### nothing to change below
  57. set -e # fail fast
  58. # computer architecture:
  59. ARCH=`${GRASSBIN} --config arch`
  60. # here we suppose default compilation settings of GRASS GIS and no make install
  61. GRASSBIN="$GRASSSRC/bin.${ARCH}/${GRASSBIN}"
  62. GRASSDIST="$GRASSSRC/dist.${ARCH}"
  63. # necessary hardcoded GRASS paths
  64. GRASSDIST_PYTHON="$GRASSDIST/etc/python"
  65. GRASS_MULTI_RUNNER="$GRASSSRC/python/grass/gunittest/multirunner.py"
  66. GRASS_MULTI_REPORTER="$GRASSSRC/python/grass/gunittest/multireport.py"
  67. DATE_FLAGS="--utc +%Y-%m-%d-%H-%M"
  68. NOW=$(date $DATE_FLAGS)
  69. # get number of processors of current machine
  70. MYNPROC=`getconf _NPROCESSORS_ONLN`
  71. # leave some free for other tasks
  72. GCCTHREADS=`expr $MYNPROC - $FREECPU`
  73. if [ $GCCTHREADS -lt 1 ] ; then
  74. GCCTHREADS=1
  75. fi
  76. # contains last executed command stdout and stderr
  77. # here were rely on reports being absolute
  78. OUTPUT_LOGFILE="$REPORTS/output-$NOW.txt"
  79. # these are relative to REPORTS
  80. CURRENT_REPORT_BASENAME="reports_for_date-"
  81. FINAL_REPORT_DIR="summary_report"
  82. CURRENT_REPORTS_DIR="$CURRENT_REPORT_BASENAME$NOW"
  83. LOGFILE="$REPORTS/runs.log"
  84. mkdir -p $REPORTS/$CURRENT_REPORTS_DIR
  85. mkdir -p $GRASSDATA
  86. # fetch sample data
  87. SAMPLEDATA=nc_spm_full_v2alpha
  88. (cd $GRASSDATA ; wget -c https://grass.osgeo.org/sampledata/north_carolina/$SAMPLEDATA.tar.gz ; tar xfz $SAMPLEDATA.tar.gz --strip-components 2)
  89. set -x
  90. echo "Testing of GRASS GIS started: $NOW" >> ${LOGFILE}
  91. if [ "$COMPILE" = "yes" ] ; then
  92. ## compile current source code from scratch
  93. cd $GRASSSRC
  94. make distclean -j$GCCTHREADS
  95. git pull
  96. ./$CONFIGURE ... # configure meta script containing all the compiler flags
  97. make -j$GCCTHREADS
  98. fi
  99. # run tests for the current source code
  100. cd $REPORTS/$CURRENT_REPORTS_DIR
  101. $PYTHON $GRASS_MULTI_RUNNER \
  102. --grassbin $GRASSBIN \
  103. --grasssrc $GRASSSRC \
  104. --grassdata $GRASSDATA \
  105. --location $SAMPLEDATA --location-type nc # \
  106. # --location other_location --location-type other_type
  107. # create overall report of all so far executed tests
  108. # the script depends on GRASS but just Python part is enough
  109. export PYTHONPATH="$GRASSDIST_PYTHON:$PYTHONPATH"
  110. $PYTHON $GRASS_MULTI_REPORTER --output $FINAL_REPORT_DIR \
  111. $CURRENT_REPORT_BASENAME*/*
  112. # publish on Web site
  113. if [ "$PUBLISH" = "yes" ] ; then
  114. ## although we cannot be sure the tests were executed was successfully
  115. ## so publish or archive results
  116. rsync -rtvu --delete $REPORTS/ $SERVERDIR
  117. fi
  118. echo "Nightly ($NOW) GRASS GIS test finished: $(date $DATE_FLAGS)" >> ${LOGFILE}
  119. exit 0