summaryrefslogtreecommitdiff
path: root/tests/memory.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-06-09 11:51:52 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-06-09 11:51:52 +0000
commit02571b05f694673c75ce656572685f4ac422c0d5 (patch)
tree90a79abd6fdd043d73fdddec12a9f8d26b6d826d /tests/memory.c
parentbbd084c4b3e5c4802bf872afe11371a682713fdb (diff)
downloadmpfr-02571b05f694673c75ce656572685f4ac422c0d5.tar.gz
[tests/memory.c] The MPFR_TESTS_MEMORY_LIMIT environment variable can
now contain an integer specifying the memory limit for the tests, or 0 for unlimited, the default still being 2^22 = 4 MB. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10459 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/memory.c')
-rw-r--r--tests/memory.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/tests/memory.c b/tests/memory.c
index ac478117d..0a52b7799 100644
--- a/tests/memory.c
+++ b/tests/memory.c
@@ -42,6 +42,7 @@ struct header {
static struct header *tests_memory_list;
static size_t tests_total_size = 0;
+static size_t tests_memory_limit = 1UL << 22; /* default memory limit */
MPFR_LOCK_DECL(mpfr_lock_memory)
static void *
@@ -103,14 +104,11 @@ tests_memory_valid (void *ptr)
}
*/
-/* FIXME: we might have an environment variable MPFR_TESTS_NO_MEMORY_LIMIT
- to disable the memory limit check, for example if we want to compute
- zillions of digits of Pi with ./tconst_pi 1000000000000 */
static void
tests_addsize (size_t size)
{
tests_total_size += size;
- if (tests_total_size > 1UL << 22)
+ if (tests_total_size > tests_memory_limit)
{
/* The total size taken by MPFR on the heap is more than 4 MB:
either a bug or a huge inefficiency. */
@@ -244,8 +242,23 @@ tests_free (void *ptr, size_t size)
void
tests_memory_start (void)
{
+ char *p;
+
tests_memory_list = NULL;
mp_set_memory_functions (tests_allocate, tests_reallocate, tests_free);
+
+ /* The memory limit can be changed with the MPFR_TESTS_MEMORY_LIMIT
+ environment variable. This is normally not necessary (a failure
+ would mean a bug), thus not recommended, for "make check". But
+ some test programs can take arguments for particular tests, which
+ may need more memory. */
+ p = getenv ("MPFR_TESTS_MEMORY_LIMIT");
+ if (p != NULL)
+ {
+ tests_memory_limit = strtoul (p, NULL, 0);
+ if (tests_memory_limit == 0)
+ tests_memory_limit = (size_t) -1; /* no memory limit */
+ }
}
void