From e9b90e4ec9ac1d0b3c6e7d4541a34af9285b8931 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 9 Mar 2016 22:18:53 +0100 Subject: [PATCH] Add cscripts and Python coverage measure. --- .gitignore | 3 +++ Makefile.am | 8 +++++++- configure.ac | 28 ++++++++++++++++++++++++++++ test/Makefile.am | 2 +- test/test_cscripts.sh.in | 48 ++++++++++++++++++++++++------------------------ test/test_python.sh.in | 25 +++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 26 deletions(-) create mode 100755 test/test_python.sh.in diff --git a/.gitignore b/.gitignore index 6608ac2..d0f24c7 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ stamp-h1 depcomp test-driver testconf.sh +coverage-report-python.xml doc/html doc/man @@ -77,6 +78,8 @@ test/reports/*.xml test/butterfly.txt test/model.reg test/obs.reg +test/.coverage +test/test_python.sh examples/*.fits examples/*.xml examples/*.dat diff --git a/Makefile.am b/Makefile.am index 70a5374..50abc64 100644 --- a/Makefile.am +++ b/Makefile.am @@ -93,9 +93,15 @@ cppncss: # Add coverage rule coverage: @if type gcovr >/dev/null 2>&1; then \ - gcovr -r . -x -o gcovr-reports-data.xml; \ + gcovr -r . -x -o coverage-report-cxx.xml; \ else \ echo "gcovr script not found in PATH."; \ + fi; \ + if type coverage >/dev/null 2>&1; then \ + export COVERAGE_FILE=test/.coverage; \ + coverage xml --omit=**/gammalib/** -o coverage-report-python.xml; \ + else \ + echo "coverage script not found in PATH."; \ fi # Add Valgrind rule diff --git a/configure.ac b/configure.ac index 80dcdbf..a3adf22 100644 --- a/configure.ac +++ b/configure.ac @@ -754,6 +754,32 @@ fi ############################################################################# +# Checks for coverage option # +############################################################################# +# Initialise Python coverage with empty string +PYTHON_COVERAGE= + +# Check for coverage option +AC_MSG_CHECKING(whether to build ctools for code coverage measure) +AC_ARG_ENABLE([coverage], + AS_HELP_STRING([--enable-coverage], + [turn on code coverage measure [default=no]]), + [enable_coverage="$enableval"], + [enable_coverage="no"]) +if test "x$enable_coverage" = "xyes"; then + CXXFLAGS="--coverage $CXXFLAGS" + LDFLAGS="--coverage $LDFLAGS" + if test "x$has_python" = "xyes"; then + PYTHON_COVERAGE="coverage run --append " + fi + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +AC_SUBST(PYTHON_COVERAGE) + + +############################################################################# # Checks for GammaLib library # ############################################################################# # Initialise GammaLib availability @@ -971,6 +997,7 @@ AC_CONFIG_FILES([Makefile src/ctools-setup test/Makefile test/test_cscripts.sh + test/test_python.sh pyext/Makefile pyext/setup.py pyext/ctools/__init__.py @@ -982,6 +1009,7 @@ AC_CONFIG_FILES([Makefile ctools.pc testconf.sh], [if test -f test/test_cscripts.sh; then chmod +x test/test_cscripts.sh; fi; + if test -f test/test_python.sh; then chmod +x test/test_python.sh; fi; if test -f testconf.sh; then chmod +x testconf.sh; fi]) AC_OUTPUT diff --git a/test/Makefile.am b/test/Makefile.am index 86be925..ca0c00a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -7,7 +7,7 @@ MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@ # Optional python bindings if WITH_PYTHON TEST_CSCRIPTS = test_cscripts.sh - TEST_PYTHON_SCRIPT = test_python.py + TEST_PYTHON_SCRIPT = test_python.sh TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir):$(top_builddir)/pyext:$(top_builddir)/pyext/build/ctools/ctools:$(pythondir):$(pyexecdir):$(PYTHONPATH) endif diff --git a/test/test_cscripts.sh.in b/test/test_cscripts.sh.in index 673d345..9ca0a90 100755 --- a/test/test_cscripts.sh.in +++ b/test/test_cscripts.sh.in @@ -36,7 +36,7 @@ $ECHO "*****************" # # Remove any existing result files # ================================ -rm -rf *.fits *.xml *.dat *.reg +rm -rf *.fits *.xml *.dat *.reg .coverage # @@ -56,7 +56,7 @@ mkdir -p $CALDB # ================ $ECHO -n "Test csobs2caldb: " chmod +x @abs_top_srcdir@/cscripts/csobs2caldb.py -@abs_top_srcdir@/cscripts/csobs2caldb.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csobs2caldb.py \ inobs="data/obs_unbinned.xml" \ rspname="test_irfs" \ chatter=4 > csobs2caldb.log @@ -76,7 +76,7 @@ $ECHO " ok" # ============= $ECHO -n "Test csobsdef: " chmod +x @abs_top_srcdir@/cscripts/csobsdef.py -@abs_top_srcdir@/cscripts/csobsdef.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csobsdef.py \ inpnt="data/pntdef.dat" \ outobs="obs.xml" \ caldb="irf" \ @@ -101,7 +101,7 @@ $ECHO " ok" # ============== $ECHO -n "Test csobsinfo: " chmod +x @abs_top_srcdir@/cscripts/csobsinfo.py -@abs_top_srcdir@/cscripts/csobsinfo.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csobsinfo.py \ inobs="obs.xml" \ ds9file="obs.reg" \ offset=yes \ @@ -123,7 +123,7 @@ $ECHO " ok" # ================ $ECHO -n "Test csmodelinfo: " chmod +x @abs_top_srcdir@/cscripts/csmodelinfo.py -@abs_top_srcdir@/cscripts/csmodelinfo.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csmodelinfo.py \ inmodel="data/crab.xml" \ ds9file="model.reg" > csmodelinfo.log $ECHO -n "." @@ -143,7 +143,7 @@ $ECHO " ok" $ECHO -n "Test csmodelmerge: " # === space-separated === chmod +x @abs_top_srcdir@/cscripts/csmodelmerge.py -@abs_top_srcdir@/cscripts/csmodelmerge.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csmodelmerge.py \ inmodels="data/crab.xml data/source1.xml" \ outmodel="merged_models.xml" > csmodelmerge.log $ECHO -n "." @@ -155,7 +155,7 @@ else exit 1 fi # === comma-separated === -@abs_top_srcdir@/cscripts/csmodelmerge.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csmodelmerge.py \ inmodels="data/crab.xml,data/source1.xml" \ outmodel="merged_models2.xml" > csmodelmerge.log $ECHO -n "." @@ -167,7 +167,7 @@ else exit 1 fi # === wildcard string === -@abs_top_srcdir@/cscripts/csmodelmerge.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csmodelmerge.py \ inmodels="data/model_cube_background*.xml" \ outmodel="merged_models3.xml" > csmodelmerge.log $ECHO -n "." @@ -180,7 +180,7 @@ else fi # === ascii-file === ls data/model_cube_background* > models.txt -@abs_top_srcdir@/cscripts/csmodelmerge.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csmodelmerge.py \ inmodels="@models.txt" \ outmodel="merged_models4.xml" > csmodelmerge.log $ECHO -n "." @@ -201,7 +201,7 @@ rm models.txt $ECHO -n "Test cstsmapmerge: " # === comma-separated === chmod +x @abs_top_srcdir@/cscripts/cstsmapmerge.py -@abs_top_srcdir@/cscripts/cstsmapmerge.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cstsmapmerge.py \ inmaps="data/tsmap_0.fits,data/tsmap_1.fits" \ outmap="merged_tsmap1.fits" > cstsmapmerge.log $ECHO -n "." @@ -213,7 +213,7 @@ else exit 1 fi # === space-separated === -@abs_top_srcdir@/cscripts/cstsmapmerge.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cstsmapmerge.py \ inmaps="data/tsmap_0.fits data/tsmap_1.fits" \ outmap="merged_tsmap2.fits" > cstsmapmerge.log $ECHO -n "." @@ -225,7 +225,7 @@ else exit 1 fi # === wildcard string === -@abs_top_srcdir@/cscripts/cstsmapmerge.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cstsmapmerge.py \ inmaps="data/tsmap_*.fits" \ outmap="merged_tsmap3.fits" > cstsmapmerge.log $ECHO -n "." @@ -238,7 +238,7 @@ else fi # === ascii-file === ls data/tsmap_*.fits > tsmaps.txt -@abs_top_srcdir@/cscripts/cstsmapmerge.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cstsmapmerge.py \ inmaps="@tsmaps.txt" \ outmap="merged_tsmap4.fits" > cstsmapmerge.log $ECHO -n "." @@ -258,7 +258,7 @@ rm tsmaps.txt # =========== $ECHO -n "Test cspull: " chmod +x @abs_top_srcdir@/cscripts/cspull.py -@abs_top_srcdir@/cscripts/cspull.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cspull.py \ inmodel="data/crab.xml" \ outfile="pull.dat" \ ntrials="3" \ @@ -291,7 +291,7 @@ $ECHO " ok" # =========== $ECHO -n "Test cssens: " chmod +x @abs_top_srcdir@/cscripts/cssens.py -@abs_top_srcdir@/cscripts/cssens.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cssens.py \ inmodel="data/crab.xml" \ srcname="Crab" \ caldb="irf" \ @@ -317,7 +317,7 @@ $ECHO " ok" # ============= $ECHO -n "Test cstsdist: " chmod +x @abs_top_srcdir@/cscripts/cstsdist.py -@abs_top_srcdir@/cscripts/cstsdist.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cstsdist.py \ inmodel="data/crab.xml" \ srcname="Crab" \ outfile="ts.dat" \ @@ -349,7 +349,7 @@ $ECHO " ok" # ============= $ECHO -n "Test csresmap: " chmod +x @abs_top_srcdir@/cscripts/csresmap.py -@abs_top_srcdir@/cscripts/csresmap.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csresmap.py \ inobs="data/crab_events.fits" \ outmap="resmap.fits" \ inmodel="data/crab.xml" \ @@ -381,7 +381,7 @@ $ECHO " ok" $ECHO -n "Test csspec: " # === Unbinned === chmod +x @abs_top_srcdir@/cscripts/csspec.py -@abs_top_srcdir@/cscripts/csspec.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csspec.py \ inobs="data/crab_events.fits" \ inmodel="data/crab.xml" \ caldb="irf" \ @@ -401,7 +401,7 @@ else exit 1 fi # === Binned === -@abs_top_srcdir@/cscripts/csspec.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csspec.py \ inobs="data/crab_cntmap_small.fits.gz" \ expcube="data/crab_expcube.fits.gz" \ psfcube="data/crab_psfcube.fits.gz" \ @@ -431,7 +431,7 @@ $ECHO " ok" $ECHO -n "Test cslightcrv: " # === unbinned === chmod +x @abs_top_srcdir@/cscripts/cslightcrv.py -@abs_top_srcdir@/cscripts/cslightcrv.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cslightcrv.py \ inobs="data/crab_events.fits" \ inmodel="data/crab.xml" \ srcname="Crab" \ @@ -454,7 +454,7 @@ else exit 1 fi # === binned === -@abs_top_srcdir@/cscripts/cslightcrv.py \ +@PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cslightcrv.py \ inobs="data/crab_events.fits" \ inmodel="data/crab.xml" \ srcname="Crab" \ @@ -494,7 +494,7 @@ if [ $python_version -ge 26 ]; then # ============== $ECHO -n "Test csfindobs: " chmod +x @abs_top_srcdir@/cscripts/csfindobs.py - @abs_top_srcdir@/cscripts/csfindobs.py \ + @PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csfindobs.py \ datapath="iactdata/" \ prodname="unit-test" \ ra="83.6331" \ @@ -517,7 +517,7 @@ if [ $python_version -ge 26 ]; then # =============== $ECHO -n "Test csiactcopy: " chmod +x @abs_top_srcdir@/cscripts/csiactcopy.py - @abs_top_srcdir@/cscripts/csiactcopy.py \ + @PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csiactcopy.py \ remote_master="iactdata/master.json" \ outpath="iactdata_test" \ prodname="unit-test" > csiactcopy.log @@ -537,7 +537,7 @@ if [ $python_version -ge 26 ]; then # ============== $ECHO -n "Test csiactobs: " chmod +x @abs_top_srcdir@/cscripts/csiactobs.py - @abs_top_srcdir@/cscripts/csiactobs.py \ + @PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/csiactobs.py \ datapath="iactdata/" \ prodname="unit-test" \ infile="iactrunlist.dat" \ diff --git a/test/test_python.sh.in b/test/test_python.sh.in new file mode 100755 index 0000000..9165ce5 --- /dev/null +++ b/test/test_python.sh.in @@ -0,0 +1,25 @@ +#! /bin/sh +# ========================================================================== +# This script tests the ctools Python module +# +# Copyright (C) 2016 Juergen Knoedlseder +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# ========================================================================== + +# +# Run the Python test +# =================== +@PYTHON_COVERAGE@./test_python.py -- libgit2 0.21.4