diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3909efc90..1c512f18a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -140,6 +140,7 @@ ADD_HEYOKA_TESTCASE(model_fixed_centres) ADD_HEYOKA_TESTCASE(model_rotating) ADD_HEYOKA_TESTCASE(model_mascon) ADD_HEYOKA_TESTCASE(step_callback) +ADD_HEYOKA_TESTCASE(llvm_state_mem_cache) if(HEYOKA_WITH_MPPP AND mp++_WITH_MPFR) ADD_HEYOKA_TESTCASE(event_detection_mp) diff --git a/test/llvm_state_mem_cache.cpp b/test/llvm_state_mem_cache.cpp new file mode 100644 index 000000000..9a67855f8 --- /dev/null +++ b/test/llvm_state_mem_cache.cpp @@ -0,0 +1,55 @@ +// Copyright 2020, 2021, 2022, 2023 Francesco Biscani (bluescarni@gmail.com), Dario Izzo (dario.izzo@gmail.com) +// +// This file is part of the heyoka library. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include +#include +#include + +#include "catch.hpp" + +using namespace heyoka; + +TEST_CASE("basic") +{ + REQUIRE(llvm_state::get_memcache_size() == 0u); + REQUIRE(llvm_state::get_memcache_limit() > 0u); + + auto ta = taylor_adaptive{model::pendulum(), {1., 0.}}; + + auto cache_size = llvm_state::get_memcache_size(); + REQUIRE(cache_size > 0u); + + ta = taylor_adaptive{model::pendulum(), {1., 0.}}; + + REQUIRE(llvm_state::get_memcache_size() == cache_size); + + ta = taylor_adaptive{model::pendulum(), {1., 0.}, kw::opt_level = 2u}; + + REQUIRE(llvm_state::get_memcache_size() > cache_size); + cache_size = llvm_state::get_memcache_size(); + + ta = taylor_adaptive{model::pendulum(), {1., 0.}, kw::opt_level = 2u, kw::tol = 1e-12}; + REQUIRE(llvm_state::get_memcache_size() > cache_size); + + llvm_state::clear_memcache(); + REQUIRE(llvm_state::get_memcache_size() == 0u); + + ta = taylor_adaptive{model::pendulum(), {1., 0.}}; + cache_size = llvm_state::get_memcache_size(); + + llvm_state::set_memcache_limit(cache_size); + ta = taylor_adaptive{model::pendulum(), {1., 0.}, kw::tol = 1e-12}; + + REQUIRE(llvm_state::get_memcache_size() < cache_size); + + llvm_state::set_memcache_limit(0); + + ta = taylor_adaptive{model::pendulum(), {1., 0.}, kw::tol = 1e-11}; + + REQUIRE(llvm_state::get_memcache_size() == 0u); +}