Centralize memory/valgrind cleanup code

This commit is contained in:
Dane Springmeyer 2015-06-12 19:52:58 -07:00
parent a9712ed081
commit 2b02677cb5
4 changed files with 50 additions and 60 deletions

View file

@ -4,6 +4,7 @@
// mapnik // mapnik
#include <mapnik/params.hpp> #include <mapnik/params.hpp>
#include <mapnik/value_types.hpp> #include <mapnik/value_types.hpp>
#include "../test/cleanup.hpp"
// stl // stl
#include <chrono> #include <chrono>
@ -73,6 +74,7 @@ void handle_args(int argc, char** argv, mapnik::parameters & params)
std::clog << ex.what() << "\n"; \ std::clog << ex.what() << "\n"; \
return -1; \ return -1; \
} \ } \
testing::run_cleanup(); \
} \ } \
template <typename T> template <typename T>

44
test/cleanup.hpp Normal file
View file

@ -0,0 +1,44 @@
#ifndef TEST_MEMORY_CLEANUP
#define TEST_MEMORY_CLEANUP
#include <libxml/parser.h>
#if defined(HAVE_CAIRO)
#include <cairo.h>
#endif
#include <unicode/uclean.h>
#ifdef MAPNIK_USE_PROJ4
#include <proj_api.h>
#endif
namespace testing {
void run_cleanup()
{
// only call this once, on exit
// to make sure valgrind output is clean
// http://xmlsoft.org/xmlmem.html
xmlCleanupCharEncodingHandlers();
xmlCleanupParser();
#if defined(HAVE_CAIRO)
// http://cairographics.org/manual/cairo-Error-handling.html#cairo-debug-reset-static-data
cairo_debug_reset_static_data();
#endif
// http://icu-project.org/apiref/icu4c/uclean_8h.html#a93f27d0ddc7c196a1da864763f2d8920
u_cleanup();
#ifdef MAPNIK_USE_PROJ4
// http://trac.osgeo.org/proj/ticket/149
#if PJ_VERSION >= 480
pj_clear_initcache();
#endif
// https://trac.osgeo.org/proj/wiki/ProjAPI#EnvironmentFunctions
pj_deallocate_grids();
#endif
}
}
#endif

View file

@ -1,41 +1,13 @@
#define CATCH_CONFIG_RUNNER #define CATCH_CONFIG_RUNNER
#include "catch.hpp" #include "catch.hpp"
#include <libxml/parser.h> // for xmlInitParser(), xmlCleanupParser() #include "cleanup.hpp" // run_cleanup()
#if defined(HAVE_CAIRO)
#include <cairo.h>
#endif
#include <unicode/uclean.h>
#ifdef MAPNIK_USE_PROJ4
#include <proj_api.h>
#endif
int main (int argc, char* const argv[]) int main (int argc, char* const argv[])
{ {
int result = Catch::Session().run( argc, argv ); int result = Catch::Session().run( argc, argv );
// only call this once, on exit
// to make sure valgrind output is clean
// http://xmlsoft.org/xmlmem.html
xmlCleanupParser();
#if defined(HAVE_CAIRO) testing::run_cleanup();
// http://cairographics.org/manual/cairo-Error-handling.html#cairo-debug-reset-static-data
cairo_debug_reset_static_data();
#endif
// http://icu-project.org/apiref/icu4c/uclean_8h.html#a93f27d0ddc7c196a1da864763f2d8920
u_cleanup();
#ifdef MAPNIK_USE_PROJ4
// http://trac.osgeo.org/proj/ticket/149
#if PJ_VERSION >= 480
pj_clear_initcache();
#endif
// https://trac.osgeo.org/proj/wiki/ProjAPI#EnvironmentFunctions
pj_deallocate_grids();
#endif
return result; return result;
} }

View file

@ -29,15 +29,7 @@
// boost // boost
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <libxml/parser.h> // for xmlInitParser(), xmlCleanupParser() #include "cleanup.hpp" // run_cleanup()
#if defined(HAVE_CAIRO)
#include <cairo.h>
#endif
#include <unicode/uclean.h>
#ifdef MAPNIK_USE_PROJ4
#include <proj_api.h>
#endif
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -113,27 +105,7 @@ int main(int argc, char** argv)
html_summary(results, output_dir); html_summary(results, output_dir);
} }
// only call this once, on exit testing::run_cleanup();
// to make sure valgrind output is clean
// http://xmlsoft.org/xmlmem.html
xmlCleanupParser();
#if defined(HAVE_CAIRO)
// http://cairographics.org/manual/cairo-Error-handling.html#cairo-debug-reset-static-data
cairo_debug_reset_static_data();
#endif
// http://icu-project.org/apiref/icu4c/uclean_8h.html#a93f27d0ddc7c196a1da864763f2d8920
u_cleanup();
#ifdef MAPNIK_USE_PROJ4
// http://trac.osgeo.org/proj/ticket/149
#if PJ_VERSION >= 480
pj_clear_initcache();
#endif
// https://trac.osgeo.org/proj/wiki/ProjAPI#EnvironmentFunctions
pj_deallocate_grids();
#endif
return failed_count; return failed_count;
} }