Commit 3345bda79d2e08c3ad728c4a8e804ccc0a7813d2

Authored by Jürgen Knödlseder
1 parent fd57d4d4

Implement Python coverage measure.

.gitignore
@@ -36,6 +36,8 @@ m4/lt~obsolete.m4 @@ -36,6 +36,8 @@ m4/lt~obsolete.m4
36 *.dvi 36 *.dvi
37 *.idx 37 *.idx
38 *.out 38 *.out
  39 +*.gcda
  40 +*.gcno
39 .DS_Store 41 .DS_Store
40 .libs 42 .libs
41 .deps 43 .deps
@@ -83,6 +85,7 @@ test/*.xml @@ -83,6 +85,7 @@ test/*.xml
83 test/reports/*.xml 85 test/reports/*.xml
84 test/*.trs 86 test/*.trs
85 test/region.reg 87 test/region.reg
  88 +test/test_python.sh
86 89
87 examples/python/*.xml 90 examples/python/*.xml
88 examples/python/*.html 91 examples/python/*.html
Makefile.am
@@ -76,7 +76,8 @@ dynamic-analysis: coverage valgrind @@ -76,7 +76,8 @@ dynamic-analysis: coverage valgrind
76 # Add cppcheck rule 76 # Add cppcheck rule
77 cppcheck: 77 cppcheck:
78 @if type cppcheck >/dev/null 2>&1; then \ 78 @if type cppcheck >/dev/null 2>&1; then \
79 - cppcheck -v --enable=all --xml --suppress=missingIncludeSystem \ 79 + cppcheck -v --enable=all --xml --xml-version=2 \
  80 + --suppress=missingIncludeSystem \
80 -Iinclude -Iinst/lat/include -Iinst/cta/include -Iinst/mwl/include \ 81 -Iinclude -Iinst/lat/include -Iinst/cta/include -Iinst/mwl/include \
81 inst/*/src inst/*/test src test 2> cppcheck-result.xml; \ 82 inst/*/src inst/*/test src test 2> cppcheck-result.xml; \
82 else \ 83 else \
@@ -104,9 +105,15 @@ cppncss: @@ -104,9 +105,15 @@ cppncss:
104 # Add coverage rule 105 # Add coverage rule
105 coverage: 106 coverage:
106 @if type gcovr >/dev/null 2>&1; then \ 107 @if type gcovr >/dev/null 2>&1; then \
107 - gcovr -r . -x -o gcovr-reports-data.xml; \ 108 + gcovr -r . -x -o coverage-report-cxx.xml; \
108 else \ 109 else \
109 echo "gcovr script not found in PATH."; \ 110 echo "gcovr script not found in PATH."; \
  111 + fi; \
  112 + if type coverage >/dev/null 2>&1; then \
  113 + export COVERAGE_FILE=test/.coverage; \
  114 + coverage xml -o coverage-report-python.xml; \
  115 + else \
  116 + echo "coverage script not found in PATH."; \
110 fi 117 fi
111 118
112 # Add Valgrind rule 119 # Add Valgrind rule
configure.ac
@@ -1016,6 +1016,32 @@ fi @@ -1016,6 +1016,32 @@ fi
1016 1016
1017 1017
1018 ############################################################################# 1018 #############################################################################
  1019 +# Checks for coverage option #
  1020 +#############################################################################
  1021 +# Initialise Python coverage with empty string
  1022 +PYTHON_COVERAGE=
  1023 +
  1024 +# Check for coverage option
  1025 +AC_MSG_CHECKING(whether to build GammaLib for code coverage measure)
  1026 +AC_ARG_ENABLE([coverage],
  1027 + AS_HELP_STRING([--enable-coverage],
  1028 + [turn on code coverage measure [default=no]]),
  1029 + [enable_coverage="$enableval"],
  1030 + [enable_coverage="no"])
  1031 +if test "x$enable_coverage" = "xyes"; then
  1032 + CXXFLAGS="--coverage $CXXFLAGS"
  1033 + LDFLAGS="--coverage $LDFLAGS"
  1034 + if test "x$has_python" = "xyes"; then
  1035 + PYTHON_COVERAGE="coverage run --append "
  1036 + fi
  1037 + AC_MSG_RESULT(yes)
  1038 +else
  1039 + AC_MSG_RESULT(no)
  1040 +fi
  1041 +AC_SUBST(PYTHON_COVERAGE)
  1042 +
  1043 +
  1044 +#############################################################################
1019 # Initialise directory path for test environment # 1045 # Initialise directory path for test environment #
1020 ############################################################################# 1046 #############################################################################
1021 TEST_ENV_DIR= 1047 TEST_ENV_DIR=
@@ -1365,11 +1391,13 @@ AC_CONFIG_FILES([Makefile @@ -1365,11 +1391,13 @@ AC_CONFIG_FILES([Makefile
1365 src/gammalib-setup 1391 src/gammalib-setup
1366 include/Makefile 1392 include/Makefile
1367 test/Makefile 1393 test/Makefile
  1394 + test/test_python.sh
1368 pyext/Makefile 1395 pyext/Makefile
1369 pyext/setup.py 1396 pyext/setup.py
1370 gammalib.pc 1397 gammalib.pc
1371 testconf.sh], 1398 testconf.sh],
1372 - [if test -f testconf.sh; then chmod +x testconf.sh; fi]) 1399 + [if test -f test/test_python.sh; then chmod +x test/test_python.sh; fi;
  1400 + if test -f testconf.sh; then chmod +x testconf.sh; fi])
1373 1401
1374 if test "x$with_inst" = "xyes"; then 1402 if test "x$with_inst" = "xyes"; then
1375 AC_CONFIG_FILES([inst/Makefile]) 1403 AC_CONFIG_FILES([inst/Makefile])
test/Makefile.am
@@ -44,7 +44,7 @@ endif @@ -44,7 +44,7 @@ endif
44 44
45 # Optional python bindings 45 # Optional python bindings
46 if WITH_PYTHON 46 if WITH_PYTHON
47 - TEST_PYTHON_SCRIPT = test_python.py 47 + TEST_PYTHON_SCRIPT = test_python.sh
48 TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir)/pyext:$(top_builddir)/pyext/build/gammalib$(TEST_MWL)$(TEST_CTA)$(TEST_LAT)$(TEST_COM):$(PYTHONPATH) 48 TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir)/pyext:$(top_builddir)/pyext/build/gammalib$(TEST_MWL)$(TEST_CTA)$(TEST_LAT)$(TEST_COM):$(PYTHONPATH)
49 endif 49 endif
50 50
test/test_python.sh.in 0 → 100755
  1 +#! /bin/sh
  2 +# ==========================================================================
  3 +# This script tests the GammaLib Python module
  4 +#
  5 +# Copyright (C) 2016 Juergen Knoedlseder
  6 +#
  7 +# This program is free software: you can redistribute it and/or modify
  8 +# it under the terms of the GNU General Public License as published by
  9 +# the Free Software Foundation, either version 3 of the License, or
  10 +# (at your option) any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU General Public License for more details.
  16 +#
  17 +# You should have received a copy of the GNU General Public License
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 +#
  20 +# ==========================================================================
  21 +
  22 +#
  23 +# Remove any existing coverage file
  24 +# =================================
  25 +rm -rf .coverage
  26 +
  27 +#
  28 +# Run the Python test
  29 +# ===================
  30 +@PYTHON_COVERAGE@./test_python.py