gunittest_running_tests.rst 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Running the tests of GRASS GIS
  2. ==============================
  3. This is an advanced guide to running tests of GRASS GIS using GRASS
  4. testing framework (`gunittest`).
  5. Example Bash script to run be used as a cron job
  6. ------------------------------------------------
  7. .. code-block:: bash
  8. #!/bin/bash
  9. set -e # fail fast
  10. REPORTS=".../testreports"
  11. GRASSSRC=".../grass-src"
  12. # here we suppose default compilation settings of GRASS and no make install
  13. GRASSBIN="$GRASSSRC/bin.../grass71"
  14. GRASSDIST="$GRASSSRC/dist..."
  15. # necessary hardcoded GRASS paths
  16. GRASSDIST_PYTHON="$GRASSDIST/etc/python"
  17. GRASS_MULTI_RUNNER="$GRASSSRC/lib/python/gunittest/multirunner.py"
  18. GRASS_MULTI_REPORTER="$GRASSSRC/lib/python/gunittest/multireport.py"
  19. DATE_FLAGS="--utc +%Y-%m-%d-%H-%M"
  20. NOW=$(date $DATE_FLAGS)
  21. # contains last executed command stdout and stderr
  22. # here were rely on reports being absolute
  23. OUTPUT_LOGFILE="$REPORTS/output-$NOW.txt"
  24. # these are relative to REPORTS
  25. CURRENT_REPORT_BASENAME="reports_for_date-"
  26. FINAL_REPORT_DIR="summary_report"
  27. CURRENT_REPORTS_DIR="$CURRENT_REPORT_BASENAME$NOW"
  28. LOGFILE="$REPORTS/runs.log"
  29. GRASSDATA="/grassdata/tests-grassdata"
  30. echo "Nightly GRASS GIS test started: $NOW" >> $LOGFILE
  31. # compile current source code from scratch
  32. cd $GRASSSRC
  33. make distclean -j4
  34. svn up
  35. ./configure ... # or a script containing all the flags
  36. make -j4
  37. # run tests for the current source code
  38. cd $REPORTS
  39. mkdir $CURRENT_REPORTS_DIR
  40. cd $CURRENT_REPORTS_DIR
  41. python $GRASS_MULTI_RUNNER \
  42. --grassbin $GRASSBIN \
  43. --grasssrc $GRASSSRC \
  44. --grassdata $GRASSDATA \
  45. --location nc_spm_08_grass7 --location-type nc \
  46. --location other_location --location-type other_type
  47. # create overall report of all so far executed tests
  48. # the script depends on GRASS but just Python part is enough
  49. export PYTHONPATH="$GRASSDIST_PYTHON:$PYTHONPATH"
  50. python $GRASS_MULTI_REPORTER --output $FINAL_REPORT_DIR \
  51. $CURRENT_REPORT_BASENAME*/*
  52. # although we cannot be sure the tests were executed was successfully
  53. # so publish or archive results
  54. rsync -rtvu --delete $REPORTS/ "/var/www/html/grassgistestreports"
  55. echo "Nightly ($NOW) GRASS GIS test finished: $(date $DATE_FLAGS)" >> $LOGFILE
  56. A script similar to this one can be used as a cron job, on most Linux systems
  57. using ``crontab -e`` and adding the following line::
  58. 0 4 * * 1 /home/vpetras/grasstests/test_grass_gis.sh
  59. Which will perform the tests every Monday at 4 in the morning.