/usr/share/sagemath/bin/sage-runtests is in sagemath-common 8.1-7ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #!/usr/bin/env python
import optparse, os, sys
# Note: the DOT_SAGE and SAGE_STARTUP_FILE environment variables have already been set by sage-env
DOT_SAGE = os.environ['DOT_SAGE']
# Override to not pick up user configuration, see Trac #20270
os.environ['SAGE_STARTUP_FILE'] = os.path.join(DOT_SAGE, 'init-doctests.sage')
if __name__ == "__main__":
parser = optparse.OptionParser()
def optional_argument(option, opt_str, value, parser, typ, default_arg):
assert value is None
try:
next_arg = typ(parser.rargs[0])
except Exception:
next_arg = default_arg
else:
parser.rargs.pop(0)
setattr(parser.values, option.dest, next_arg)
parser.add_option("-p", "--nthreads", dest="nthreads", default=1, action="callback",
callback=optional_argument, callback_args=(int, 0), nargs=0,
metavar="N", help="tests in parallel using N threads with 0 interpreted as max(2, min(8, cpu_count()))")
parser.add_option("-T", "--timeout", type=int, default=-1, help="timeout (in seconds) for doctesting one file, 0 for no timeout")
parser.add_option("-a", "--all", action="store_true", default=False, help="test all files in the Sage library")
parser.add_option("--logfile", metavar="FILE", help="log all output to FILE")
parser.add_option("--sagenb", action="store_true", default=False, help="test all files from the Sage notebook sources")
parser.add_option("-l", "--long", action="store_true", default=False, help="include lines with the phrase 'long time'")
parser.add_option("--warn-long", dest="warn_long", default=None, action="callback",
callback=optional_argument, callback_args=(float, 1.0), nargs=0,
metavar="SECONDS", help="warn if tests take more time than SECONDS")
parser.add_option("--optional", metavar="PKGS", default="sage,optional",
help='only run tests including one of the "# optional" tags listed in PKGS; '
'if "sage" is listed, will also run the standard doctests; '
'if "optional" is listed, will also run tests for installed optional (new-style) packages; '
'if "external" is listed, will also run tests for available external software; '
'if set to "all", then all tests will be run')
parser.add_option("--randorder", type=int, metavar="SEED", help="randomize order of tests")
parser.add_option("--global-iterations", "--global_iterations", type=int, default=0, help="repeat the whole testing process this many times")
parser.add_option("--file-iterations", "--file_iterations", type=int, default=0, help="repeat each file this many times, stopping on the first failure")
parser.add_option("-i", "--initial", action="store_true", default=False, help="only show the first failure in each file")
parser.add_option("--exitfirst", action="store_true", default=False, help="end the test run immediately after the first failure or unexpected exception")
parser.add_option("--force_lib", "--force-lib", action="store_true", default=False, help="do not import anything from the tested file(s)")
parser.add_option("--abspath", action="store_true", default=False, help="print absolute paths rather than relative paths")
parser.add_option("--verbose", action="store_true", default=False, help="print debugging output during the test")
parser.add_option("-d", "--debug", action="store_true", default=False, help="drop into a python debugger when an unexpected error is raised")
parser.add_option("--only-errors", action="store_true", default=False, help="only output failures, not test successes")
parser.add_option("--gdb", action="store_true", default=False, help="run doctests under the control of gdb")
parser.add_option("--valgrind", "--memcheck", action="store_true", default=False,
help="run doctests using Valgrind's memcheck tool. The log "
"files are named sage-memcheck.PID and can be found in " +
os.path.join(DOT_SAGE, "valgrind"))
parser.add_option("--massif", action="store_true", default=False,
help="run doctests using Valgrind's massif tool. The log "
"files are named sage-massif.PID and can be found in " +
os.path.join(DOT_SAGE, "valgrind"))
parser.add_option("--cachegrind", action="store_true", default=False,
help="run doctests using Valgrind's cachegrind tool. The log "
"files are named sage-cachegrind.PID and can be found in " +
os.path.join(DOT_SAGE, "valgrind"))
parser.add_option("--omega", action="store_true", default=False,
help="run doctests using Valgrind's omega tool. The log "
"files are named sage-omega.PID and can be found in " +
os.path.join(DOT_SAGE, "valgrind"))
parser.add_option("-f", "--failed", action="store_true", default=False,
help="doctest only those files that failed in the previous run")
parser.add_option("-n", "--new", action="store_true", default=False,
help="doctest only those files that have been changed in the repository and not yet been committed")
parser.add_option("--show-skipped", "--show_skipped", action="store_true", default=False,
help="print a summary at the end of each file of optional tests that were skipped")
parser.add_option("--stats_path", "--stats-path", default=os.path.join(DOT_SAGE, "timings2.json"),
help="path to a json dictionary for the latest run storing a timing for each file")
# The --serial option is only really for internal use, better not
# document it.
parser.add_option("--serial", action="store_true", default=False, help=optparse.SUPPRESS_HELP)
parser.set_usage("sage -t [options] filenames")
options, args = parser.parse_args()
if len(args) == 0 and not (options.all or options.sagenb or options.new):
parser.print_help()
sys.exit(2)
# Ensure that all doctests can be run with virtual memory limited
# to 3300 MiB. We must set this limit before starting Sage. Note
# that this is a per-process limit, so we do not need to worry about
# running multiple doctest processes in parallel. It is in
# particular doctests in src/sage/schemes/elliptic_curves/heegner.py
# which need this much memory.
memlimit = 3300 << 20
# Python's resource module only supports limits up to sys.maxsize,
# even if the OS does support higher limits.
if memlimit <= sys.maxsize:
import resource
lim, hard = resource.getrlimit(resource.RLIMIT_AS)
if lim == resource.RLIM_INFINITY or lim > memlimit:
try:
resource.setrlimit(resource.RLIMIT_AS, (memlimit, hard))
except ValueError:
if sys.platform != 'cygwin':
# RLIMIT_AS is not currently supported on Cygwin so
# this will probably fail there:
# https://trac.sagemath.org/ticket/23979
raise
# Limit the number of threads to 2 to save system resources.
# See Trac #23713 and #23892
os.environ["OMP_NUM_THREADS"] = "2"
os.environ["SAGE_NUM_THREADS"] = "2"
from sage.doctest.control import DocTestController
DC = DocTestController(options, args)
err = DC.run()
sys.exit(err)
|