Commit bd79c7e15cfb25a9245bc39494cb5ed646748314
1 parent
c86aaf34
Add testing of example C++ executables to unit test (#1806)
Showing
12 changed files
with
312 additions
and
32 deletions
.gitignore
| ... | ... | @@ -86,15 +86,14 @@ test/reports/*.xml |
| 86 | 86 | test/*.trs |
| 87 | 87 | test/region.reg |
| 88 | 88 | test/test_python.sh |
| 89 | +test/test_examples.sh | |
| 89 | 90 | test/test_csv*.dat |
| 90 | 91 | |
| 91 | 92 | examples/python/*.xml |
| 92 | 93 | examples/python/*.html |
| 93 | -examples/cpp/*.fits | |
| 94 | 94 | examples/cpp/createfits |
| 95 | 95 | examples/cpp/createskymap |
| 96 | 96 | examples/cpp/createxml |
| 97 | -examples/cpp/my_xml_file.xml | |
| 98 | 97 | examples/cpp/readmodel |
| 99 | 98 | examples/cpp/numerics |
| 100 | 99 | examples/cpp/optimize | ... | ... |
ChangeLog
| 1 | -2016-06-22 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 1 | +2016-06-23 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 2 | 2 | |
| 3 | 3 | * Version 1.1.0 released |
| 4 | 4 | ========================= |
| 5 | 5 | |
| 6 | + Correct Makefile for example executables (#1806) | |
| 6 | 7 | Handle additional columns in GArf class |
| 7 | 8 | GCTAAeff2D no longer extrapolates beyond response table (#1784) |
| 8 | 9 | Add GWcsSIN projection class (#1798) | ... | ... |
NEWS
README.md
| 1 | 1 | GammaLib information |
| 2 | 2 | ==================== |
| 3 | -* Version: 1.1.0.dev1 (22 June 2016) | |
| 3 | +* Version: 1.1.0.dev1 (23 June 2016) | |
| 4 | 4 | * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) |
| 5 | 5 | |
| 6 | 6 | [](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) | ... | ... |
configure.ac
| ... | ... | @@ -1396,9 +1396,11 @@ AC_CONFIG_FILES([Makefile |
| 1396 | 1396 | pyext/setup.py |
| 1397 | 1397 | examples/Makefile |
| 1398 | 1398 | examples/cpp/Makefile |
| 1399 | + test/test_examples.sh | |
| 1399 | 1400 | gammalib.pc |
| 1400 | 1401 | testconf.sh], |
| 1401 | 1402 | [if test -f test/test_python.sh; then chmod +x test/test_python.sh; fi; |
| 1403 | + if test -f test/test_examples.sh; then chmod +x test/test_examples.sh; fi; | |
| 1402 | 1404 | if test -f testconf.sh; then chmod +x testconf.sh; fi]) |
| 1403 | 1405 | |
| 1404 | 1406 | if test "x$with_inst" = "xyes"; then | ... | ... |
examples/cpp/Makefile.am
| 1 | 1 | ## Process this file with automake to produce Makefile.in |
| 2 | 2 | |
| 3 | +# Darwin support | |
| 4 | +MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@ | |
| 5 | +@EXPORT_MACOSX_DEPLOYMENT_TARGET@export MACOSX_DEPLOYMENT_TARGET | |
| 6 | + | |
| 7 | +# Include files | |
| 3 | 8 | INCLUDES = -I$(top_srcdir)/include |
| 4 | 9 | |
| 5 | 10 | # Program name | ... | ... |
examples/cpp/optimize.cpp
| ... | ... | @@ -47,13 +47,13 @@ protected: |
| 47 | 47 | }; |
| 48 | 48 | void parabola::eval(const GOptimizerPars& pars) |
| 49 | 49 | { |
| 50 | - const double a = 2.0; | |
| 51 | - const double b = -4.0; | |
| 52 | - const double c = 2.0; | |
| 53 | - double x = pars[0]->value(); | |
| 54 | - m_value = a*x*x + b*x + c; | |
| 55 | - m_gradient[0] = 2.0*a*x + b; | |
| 56 | - m_curvature(0,0) = m_gradient[0] * m_gradient[0]; | |
| 50 | + const double a = 2.0; | |
| 51 | + const double b = -4.0; | |
| 52 | + const double c = 2.0; | |
| 53 | + double x = pars[0]->value(); | |
| 54 | + m_value = a*x*x + b*x + c; | |
| 55 | + m_gradient[0] = 2.0*a*x + b; | |
| 56 | + m_curvature(0,0) = m_gradient[0] * m_gradient[0]; | |
| 57 | 57 | }; |
| 58 | 58 | |
| 59 | 59 | |
| ... | ... | @@ -69,7 +69,6 @@ int main(void) { |
| 69 | 69 | log.cout(true); |
| 70 | 70 | |
| 71 | 71 | // Allocate optimizer |
| 72 | - //GOptimizerLM opt(log); | |
| 73 | 72 | GOptimizerLM opt; |
| 74 | 73 | |
| 75 | 74 | // Allocate function | ... | ... |
examples/cpp/readmodel.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * readmodel.cpp - Illustrates how to read a model * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2013-2016 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -26,15 +26,68 @@ |
| 26 | 26 | |
| 27 | 27 | /* __ Includes ___________________________________________________________ */ |
| 28 | 28 | #include <iostream> |
| 29 | +#include <fstream> | |
| 29 | 30 | #include "GammaLib.hpp" |
| 30 | 31 | |
| 31 | 32 | |
| 32 | 33 | /***********************************************************************//** |
| 33 | - * @brief Dummy read model test | |
| 34 | + * @brief Create XML file | |
| 35 | + * | |
| 36 | + * Creates XML file that should be read back to avoid shipping of a test | |
| 37 | + * XML file. | |
| 34 | 38 | ***************************************************************************/ |
| 35 | -int main(void) { | |
| 36 | - GModels models("source.xml"); | |
| 39 | +void create_xml_file(void) | |
| 40 | +{ | |
| 41 | + // Open ASCII file | |
| 42 | + std::ofstream file("example_source.xml"); | |
| 43 | + | |
| 44 | + // Write file if file is open | |
| 45 | + if (file.is_open()) { | |
| 46 | + | |
| 47 | + // Write XML file | |
| 48 | + file << "<?xml version=\"1.0\" standalone=\"no\"?>\n"; | |
| 49 | + file << "<source_library title=\"source library\">\n"; | |
| 50 | + file << " <source name=\"1FGL J0005.7+3815\" type=\"PointSource\">\n"; | |
| 51 | + file << " <spectrum type=\"PowerLaw\">\n"; | |
| 52 | + file << " <parameter scale=\"1e-07\" name=\"Prefactor\""; | |
| 53 | + file << " min=\"1e-07\" max=\"1000.0\" value=\"1.73\" free=\"1\"/>\n"; | |
| 54 | + file << " <parameter scale=\"1.0\" name=\"Index\" min=\"-5.0\""; | |
| 55 | + file << " max=\"+5.0\" value=\"-2.1\" free=\"1\"/>\n"; | |
| 56 | + file << " <parameter scale=\"1.0\" name=\"Scale\" min=\"10.0\""; | |
| 57 | + file << " max=\"1000000.0\" value=\"100.0\" free=\"0\"/>\n"; | |
| 58 | + file << " </spectrum>\n"; | |
| 59 | + file << " <spatialModel type=\"SkyDirFunction\">\n"; | |
| 60 | + file << " <parameter free=\"0\" max=\"360\" min=\"-360\""; | |
| 61 | + file << " name=\"RA\" scale=\"1\" value=\"83.6331\"/>\n"; | |
| 62 | + file << " <parameter free=\"0\" max=\"90\" min=\"-90\""; | |
| 63 | + file << " name=\"DEC\" scale=\"1\" value=\"22.0145\" />\n"; | |
| 64 | + file << " </spatialModel>\n"; | |
| 65 | + file << " </source>\n"; | |
| 66 | + file << "</source_library>\n"; | |
| 67 | + | |
| 68 | + // Close file | |
| 69 | + file.close(); | |
| 70 | + | |
| 71 | + } // endif: file was open | |
| 72 | + | |
| 73 | + // Return | |
| 74 | + return; | |
| 75 | +} | |
| 76 | + | |
| 77 | + | |
| 78 | +/***********************************************************************//** | |
| 79 | + * @brief Read XML model | |
| 80 | + ***************************************************************************/ | |
| 81 | +int main(void) | |
| 82 | +{ | |
| 83 | + // Create XML file | |
| 84 | + create_xml_file(); | |
| 85 | + | |
| 86 | + // Read XML model | |
| 87 | + GModels models("example_source.xml"); | |
| 37 | 88 | std::cout << models << std::endl; |
| 89 | + | |
| 90 | + // Return | |
| 38 | 91 | return 0; |
| 39 | 92 | } |
| 40 | 93 | ... | ... |
examples/cpp/source.xml deleted
| 1 | -<?xml version="1.0" standalone="no"?> | |
| 2 | -<source_library title="source library"> | |
| 3 | - <source name="1FGL J0005.7+3815" type="PointSource"> | |
| 4 | - <spectrum type="PowerLaw"> | |
| 5 | - <parameter scale="1e-07" name="Prefactor" min="1e-07" max="1000.0" value="1.73" free="1"/> | |
| 6 | - <parameter scale="1.0" name="Index" min="-5.0" max="+5.0" value="-2.1" free="1"/> | |
| 7 | - <parameter scale="1.0" name="Scale" min="10.0" max="1000000.0" value="100.0" free="0"/> | |
| 8 | - </spectrum> | |
| 9 | - <spatialModel type="SkyDirFunction"> | |
| 10 | - <parameter free="0" max="360" min="-360" name="RA" scale="1" value="83.6331" /> | |
| 11 | - <parameter free="0" max="90" min="-90" name="DEC" scale="1" value="22.0145" /> | |
| 12 | - </spatialModel> | |
| 13 | - </source> | |
| 14 | -</source_library> |
test/Makefile.am
| ... | ... | @@ -44,7 +44,7 @@ endif |
| 44 | 44 | |
| 45 | 45 | # Optional python bindings |
| 46 | 46 | if WITH_PYTHON |
| 47 | - TEST_PYTHON_SCRIPT = test_python.sh | |
| 47 | + TEST_PYTHON_SCRIPT = test_python.sh test_examples.sh | |
| 48 | 48 | TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir)/pyext:$(top_builddir)/pyext/build/gammalib$(TEST_MWL)$(TEST_CTA)$(TEST_LAT)$(TEST_COM):$(PYTHONPATH) |
| 49 | 49 | endif |
| 50 | 50 | ... | ... |
test/test_examples.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This scripts performs unit tests for the example executables | |
| 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 | +import gammalib | |
| 22 | +import sys | |
| 23 | +import os | |
| 24 | + | |
| 25 | + | |
| 26 | +# =============================================== # | |
| 27 | +# Test class for example executables unit testing # | |
| 28 | +# =============================================== # | |
| 29 | +class Test(gammalib.GPythonTestSuite): | |
| 30 | + """ | |
| 31 | + Test class for GammaLib example executables | |
| 32 | + """ | |
| 33 | + # Constructor | |
| 34 | + def __init__(self): | |
| 35 | + """ | |
| 36 | + Constructor. | |
| 37 | + """ | |
| 38 | + # Call base class constructor | |
| 39 | + gammalib.GPythonTestSuite.__init__(self) | |
| 40 | + | |
| 41 | + # Examples directory | |
| 42 | + self._dir = '../examples/cpp/' | |
| 43 | + | |
| 44 | + # Return | |
| 45 | + return | |
| 46 | + | |
| 47 | + # Execute binary | |
| 48 | + def _execute_binary(self, name): | |
| 49 | + """ | |
| 50 | + Execute binary | |
| 51 | + | |
| 52 | + Parameters | |
| 53 | + ---------- | |
| 54 | + name : str | |
| 55 | + Binary executable name. | |
| 56 | + """ | |
| 57 | + # Setup command | |
| 58 | + cmd = self._dir + name | |
| 59 | + | |
| 60 | + # Execute binary, make sure we catch any exception | |
| 61 | + try: | |
| 62 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 63 | + except: | |
| 64 | + pass | |
| 65 | + | |
| 66 | + # Check if execution was successful | |
| 67 | + self.test_assert(rc == 0, 'Check "'+name+'" execution on command line') | |
| 68 | + | |
| 69 | + # Return | |
| 70 | + return | |
| 71 | + | |
| 72 | + # Set test functions | |
| 73 | + def set(self): | |
| 74 | + """ | |
| 75 | + Set all test functions | |
| 76 | + """ | |
| 77 | + # Set test name | |
| 78 | + self.name("examples") | |
| 79 | + | |
| 80 | + # Append tests | |
| 81 | + self.append(self.test_createfits, "Test createfits") | |
| 82 | + self.append(self.test_createskymap, "Test createskymap") | |
| 83 | + self.append(self.test_createxml, "Test createxml") | |
| 84 | + self.append(self.test_interpolate, "Test interpolate") | |
| 85 | + self.append(self.test_numerics, "Test numerics") | |
| 86 | + self.append(self.test_optimize, "Test optimize") | |
| 87 | + self.append(self.test_readmodel, "Test readmodel") | |
| 88 | + | |
| 89 | + # Return | |
| 90 | + return | |
| 91 | + | |
| 92 | + # Test createfits | |
| 93 | + def test_createfits(self): | |
| 94 | + """ | |
| 95 | + Test createfits | |
| 96 | + """ | |
| 97 | + # Execute binary | |
| 98 | + self._execute_binary('createfits') | |
| 99 | + | |
| 100 | + #TODO: Do any testing | |
| 101 | + | |
| 102 | + # Return | |
| 103 | + return | |
| 104 | + | |
| 105 | + # Test createskymap | |
| 106 | + def test_createskymap(self): | |
| 107 | + """ | |
| 108 | + Test createskymap | |
| 109 | + """ | |
| 110 | + # Execute binary | |
| 111 | + self._execute_binary('createskymap') | |
| 112 | + | |
| 113 | + #TODO: Do any testing | |
| 114 | + | |
| 115 | + # Return | |
| 116 | + return | |
| 117 | + | |
| 118 | + # Test createxml | |
| 119 | + def test_createxml(self): | |
| 120 | + """ | |
| 121 | + Test createxml | |
| 122 | + """ | |
| 123 | + # Execute binary | |
| 124 | + self._execute_binary('createxml') | |
| 125 | + | |
| 126 | + #TODO: Do any testing | |
| 127 | + | |
| 128 | + # Return | |
| 129 | + return | |
| 130 | + | |
| 131 | + # Test interpolate | |
| 132 | + def test_interpolate(self): | |
| 133 | + """ | |
| 134 | + Test interpolate | |
| 135 | + """ | |
| 136 | + # Execute binary | |
| 137 | + self._execute_binary('interpolate') | |
| 138 | + | |
| 139 | + #TODO: Do any testing | |
| 140 | + | |
| 141 | + # Return | |
| 142 | + return | |
| 143 | + | |
| 144 | + # Test numerics | |
| 145 | + def test_numerics(self): | |
| 146 | + """ | |
| 147 | + Test numerics | |
| 148 | + """ | |
| 149 | + # Execute binary | |
| 150 | + self._execute_binary('numerics') | |
| 151 | + | |
| 152 | + #TODO: Do any testing | |
| 153 | + | |
| 154 | + # Return | |
| 155 | + return | |
| 156 | + | |
| 157 | + # Test optimize | |
| 158 | + def test_optimize(self): | |
| 159 | + """ | |
| 160 | + Test optimize | |
| 161 | + """ | |
| 162 | + # Execute binary | |
| 163 | + self._execute_binary('optimize') | |
| 164 | + | |
| 165 | + #TODO: Do any testing | |
| 166 | + | |
| 167 | + # Return | |
| 168 | + return | |
| 169 | + | |
| 170 | + # Test readmodel | |
| 171 | + def test_readmodel(self): | |
| 172 | + """ | |
| 173 | + Test readmodel | |
| 174 | + """ | |
| 175 | + # Execute binary | |
| 176 | + self._execute_binary('readmodel') | |
| 177 | + | |
| 178 | + #TODO: Do any testing | |
| 179 | + | |
| 180 | + # Return | |
| 181 | + return | |
| 182 | + | |
| 183 | + | |
| 184 | +# ======================== # | |
| 185 | +# Main routine entry point # | |
| 186 | +# ======================== # | |
| 187 | +if __name__ == '__main__': | |
| 188 | + | |
| 189 | + # Allocate test suites | |
| 190 | + suites = gammalib.GTestSuites('Examples testing') | |
| 191 | + | |
| 192 | + # Allocate test suite, setup tests and append them to the container | |
| 193 | + suite = Test() | |
| 194 | + suite.set() | |
| 195 | + suites.append(suite) | |
| 196 | + | |
| 197 | + # Run test suite | |
| 198 | + success = suites.run() | |
| 199 | + | |
| 200 | + # Save test results | |
| 201 | + suites.save('reports/examples.xml') | |
| 202 | + | |
| 203 | + # Set return code | |
| 204 | + if success: | |
| 205 | + rc = 0 | |
| 206 | + else: | |
| 207 | + rc = 1 | |
| 208 | + | |
| 209 | + # Exit with return code | |
| 210 | + sys.exit(rc) | ... | ... |
test/test_examples.sh.in
0 → 100755
| 1 | +#! /bin/sh | |
| 2 | +# ========================================================================== | |
| 3 | +# This script launches the examples unit tests | |
| 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 | +# Run the examples test | |
| 24 | +# ===================== | |
| 25 | +@PYTHON_COVERAGE@./test_examples.py | ... | ... |