Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit cf0c05c

Browse files
committed
Trac #31395: eliminate the --memlimit option to the doctest runner.
Testing is currently impossible on Gentoo because the default memory limit imposed by the doctest runner is too low for sage to function. Rather than increase the limit once again, this commit removes the memory limit entirely. This is not as huge of a change as it seems, and the choice was made for three reasons: * Having a default limit occasionally breaks all testing on some platforms and requires the limit to be increased manually. * Setting a limit only works reliably on Linux where there are easier, more standard ways to set one (like ulimit -v). * There's only one test in the sage library that requires a memory limit to be set, and having one global memory limit would probably not be the correct approach if more tests requiring one were added. This commit removes the --memlimit option, the corresponding code to set a soft limit, and the support for the "optional - memlimit" tag. The default memory limit was also thereby eliminated. The one test that requires a memory limit was refactored to set its own memory limit on linux. This reintroduces some boilerplate to the lone test that requires a memory limit, but eliminates a recurring problem (the default limit being too low) in the doctest runner at large. In the future, the memory limit in that one test may need to be updated, but the absence of a global limit should allow the doctest runner to function normally up until that point.
1 parent 5cb72aa commit cf0c05c

File tree

6 files changed

+21
-70
lines changed

6 files changed

+21
-70
lines changed

src/bin/sage-runtests

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ if __name__ == "__main__":
4343
callback=optional_argument, callback_args=(int, 0), nargs=0,
4444
metavar="N", help="tests in parallel using N threads with 0 interpreted as max(2, min(8, cpu_count()))")
4545
parser.add_option("-T", "--timeout", type=int, default=-1, help="timeout (in seconds) for doctesting one file, 0 for no timeout")
46-
parser.add_option("-m", "--memlimit", type=int, default=3300,
47-
help='maximum virtual memory to allow each test '
48-
'process, in megabytes; no limit if zero or less, '
49-
'but tests tagged "optional - memlimit" are '
50-
'skipped if no limit is set (default: 3300 MB)')
5146
parser.add_option("-a", "--all", action="store_true", default=False, help="test all files in the Sage library")
5247
parser.add_option("--logfile", metavar="FILE", help="log all output to FILE")
5348

@@ -135,39 +130,6 @@ if __name__ == "__main__":
135130
parser.print_help()
136131
sys.exit(2)
137132

138-
# Ensure that all doctests can be run with virtual memory limited to 3300
139-
# MiB (or a user-provided value). We must set this limit before starting
140-
# Sage. Note that this is a per-process limit, so we do not need to worry
141-
# about running multiple doctest processes in parallel. It is in
142-
# particular doctests in src/sage/schemes/elliptic_curves/heegner.py
143-
# which need this much memory.
144-
memlimit = options.memlimit << 20
145-
146-
# Python's resource module only supports limits up to sys.maxsize,
147-
# even if the OS does support higher limits.
148-
if 0 < memlimit <= sys.maxsize:
149-
import resource
150-
lim, hard = resource.getrlimit(resource.RLIMIT_AS)
151-
if lim == resource.RLIM_INFINITY or lim > memlimit:
152-
try:
153-
resource.setrlimit(resource.RLIMIT_AS, (memlimit, hard))
154-
except ValueError:
155-
options.memlimit = -1
156-
if sys.platform != 'cygwin':
157-
# RLIMIT_AS is not currently supported on Cygwin so
158-
# this will probably fail there:
159-
# https://trac.sagemath.org/ticket/23979
160-
raise
161-
else:
162-
if resource.RLIMIT_AS == getattr(resource, 'RLIMIT_RSS', None):
163-
# On some platforms (e.g. OSX) RLIMIT_AS is just an alias
164-
# for RLIMIT_RSS (see
165-
# https://trac.sagemath.org/ticket/24190)
166-
# In this case we still call setrlimit, but then disable
167-
# high mem tests since we don't want such tests to actually
168-
# cause us to run out of physical memory, leading to system
169-
# instability (as opposed to virtual memory allocs failing)
170-
options.memlimit = -1
171133
# Limit the number of threads to 2 to save system resources.
172134
# See Trac #23713, #23892, #30351
173135
if sys.platform == 'darwin':

src/sage/doctest/control.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def __init__(self, **kwds):
9696
self.nthreads = 1
9797
self.serial = False
9898
self.timeout = -1
99-
self.memlimit = 0
10099
self.all = False
101100
self.logfile = None
102101
self.long = False
@@ -381,10 +380,6 @@ def __init__(self, options, args):
381380

382381
self.options = options
383382

384-
if options.memlimit > 0:
385-
# Allow tests that require a virtual memory limit to be set
386-
options.optional.add('memlimit')
387-
388383
self.files = args
389384
if options.logfile:
390385
try:
@@ -1013,7 +1008,7 @@ def _assemble_cmd(self):
10131008
for o in ("all", "long", "force_lib", "verbose", "failed", "new"):
10141009
if o in opt:
10151010
cmd += "--%s "%o
1016-
for o in ("timeout", "memlimit", "randorder", "stats_path"):
1011+
for o in ("timeout", "randorder", "stats_path"):
10171012
if o in opt:
10181013
cmd += "--%s=%s "%(o, opt[o])
10191014
if "optional" in opt:

src/sage/doctest/reporting.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,6 @@ def report(self, source, timeout, return_code, results, output, pid=None):
488488
if not self.controller.options.long:
489489
if self.controller.options.show_skipped:
490490
log(" %s not run"%(count_noun(nskipped, "long test")))
491-
elif tag == "memlimit":
492-
if self.controller.options.memlimit <= 0:
493-
seen_other = True
494-
log(" %s not run"%(count_noun(nskipped, "memlimit")))
495491
elif tag == "not tested":
496492
if self.controller.options.show_skipped:
497493
log(" %s not run"%(count_noun(nskipped, "not tested test")))

src/sage/doctest/test.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -511,20 +511,6 @@
511511
....: except OSError:
512512
....: pass
513513
514-
Test the ``--memlimit`` option and ``# optional - memlimit``
515-
(but only on Linux). If this test fails, the memory needed to
516-
run it may have increased. Try increasing the limit. ::
517-
518-
sage: from platform import system
519-
sage: ok = True
520-
sage: from sage.cpython.string import bytes_to_str
521-
sage: if system() == "Linux":
522-
....: P = subprocess.Popen(["sage", "-t", "--warn-long", "0", "--random-seed=0", "--memlimit=2000", "memlimit.rst"], stdout=subprocess.PIPE, **kwds)
523-
....: out, err = P.communicate()
524-
....: ok = ("MemoryError: failed to allocate" in bytes_to_str(out))
525-
sage: ok or out
526-
True
527-
528514
Test that random tests are reproducible::
529515
530516
sage: subprocess.call(["sage", "-t", "--warn-long", "0", "--random-seed=0", "random_seed.rst"], **kwds) # long time
@@ -558,5 +544,4 @@
558544
----------------------------------------------------------------------
559545
...
560546
0
561-
562547
"""

src/sage/doctest/tests/memlimit.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/sage/matrix/matrix_mod2_dense.pyx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
168168
169169
Large matrices fail gracefully::
170170
171-
sage: MatrixSpace(GF(2), 2^30)(1) # optional - memlimit
172-
Traceback (most recent call last):
173-
...
174-
RuntimeError: matrix allocation failed
175171
sage: MatrixSpace(GF(2), 1, 2^40).zero()
176172
Traceback (most recent call last):
177173
...
@@ -180,6 +176,26 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
180176
Traceback (most recent call last):
181177
...
182178
OverflowError: ...
179+
180+
Allocation fails if a memory limit is set (Linux only) lower
181+
than is needed to construct a matrix but still high enough
182+
that it doesn't crash the rest of SageMath::
183+
184+
sage: from platform import system
185+
sage: import resource
186+
sage: orig_soft, orig_hard = resource.getrlimit(resource.RLIMIT_AS)
187+
sage: if system() != "Linux":
188+
....: raise RuntimeError("matrix allocation failed")
189+
....: else:
190+
....: four_GiB = 4*1024^3
191+
....: resource.setrlimit(resource.RLIMIT_AS, (four_GiB, orig_hard))
192+
....: MatrixSpace(GF(2), 2^30)(1)
193+
Traceback (most recent call last):
194+
...
195+
RuntimeError: matrix allocation failed
196+
sage: resource.setrlimit(resource.RLIMIT_AS, (orig_soft, orig_hard))
197+
sage: (orig_soft, orig_hard) == resource.getrlimit(resource.RLIMIT_AS)
198+
True
183199
"""
184200
# m4ri assumes that nrows and ncols are of type rci_t:
185201
# check for overflow

0 commit comments

Comments
 (0)