nixpkgs-suyu/pkgs/applications/science/math/sage/sage-tests.nix

62 lines
2 KiB
Nix
Raw Normal View History

2018-11-12 23:28:29 +01:00
{ stdenv
, lib
2018-11-12 23:28:29 +01:00
, sage-with-env
, makeWrapper
, files ? null # "null" means run all tests
2018-11-24 22:59:51 +01:00
, longTests ? true # run tests marked as "long time" (roughly doubles runtime)
# Run as many tests as possible in approximately n seconds. This will give each
# file to test a "time budget" and stop tests if it is exceeded. 300 is the
# upstream default value.
# https://trac.sagemath.org/ticket/25270 for details.
, timeLimit ? null
2018-11-12 23:28:29 +01:00
}:
# for a quick test of some source files:
# nix-build -E 'with (import ./. {}); sage.tests.override { files = [ "src/sage/misc/cython.py" ];}'
let
src = sage-with-env.env.lib.src;
runAllTests = files == null;
testArgs = if runAllTests then "--all" else testFileList;
patienceSpecifier = if longTests then "--long" else "";
2018-11-24 22:59:51 +01:00
timeSpecifier = if timeLimit == null then "" else "--short ${toString timeLimit}";
relpathToArg = relpath: lib.escapeShellArg "${src}/${relpath}"; # paths need to be absolute
testFileList = lib.concatStringsSep " " (map relpathToArg files);
in
2019-08-13 23:52:01 +02:00
stdenv.mkDerivation {
2018-11-12 23:28:29 +01:00
version = src.version;
pname = "sage-tests";
inherit src;
2018-11-12 23:28:29 +01:00
buildInputs = [
makeWrapper
sage-with-env
2018-11-12 23:28:29 +01:00
];
2019-06-19 17:45:34 +02:00
dontUnpack = true;
2018-11-12 23:28:29 +01:00
configurePhase = "#do nothing";
buildPhase = "#do nothing";
installPhase = ''
# This output is not actually needed for anything, the package just
# exists to decouple the sage build from its t ests.
mkdir -p "$out/bin"
# Like a symlink, but make sure that $0 points to the original.
makeWrapper "${sage-with-env}/bin/sage" "$out/bin/sage"
'';
doInstallCheck = true;
installCheckPhase = ''
export HOME="$TMPDIR/sage-home"
mkdir -p "$HOME"
# avoid running out of memory with many threads in subprocesses, see
# https://github.com/NixOS/nixpkgs/pull/65802
export GLIBC_TUNABLES=glibc.malloc.arena_max=4
2018-11-24 22:59:51 +01:00
echo "Running sage tests with arguments ${timeSpecifier} ${patienceSpecifier} ${testArgs}"
"sage" -t --timeout=0 --nthreads "$NIX_BUILD_CORES" --optional=sage ${timeSpecifier} ${patienceSpecifier} ${testArgs}
2018-11-12 23:28:29 +01:00
'';
}