Test suite

python3 tests/run_tests.py

The suite runs short calculations and checks them against things that must be true, rather than against stored output. A golden-file test tells you that something changed. These tell you whether the answer is right.

Test

Checks

virial

A relaxed \(n=1.5\) polytrope satisfies \(W = -\frac{3}{5-n}\frac{GM^2}{R}\), and \(U = -W/2\).

energy

Total energy is conserved through the run.

quiet

A relaxed star stays put: kinetic energy remains negligible.

ranks

The answer does not depend on how many MPI ranks are used.

cpu_gpu

The CPU and GPU builds agree.

block_cpu_gpu

With block timesteps, where gravity is computed on the active particles only, the CPU and GPU builds agree.

gpu_hilo

GPU gravity with and without the float remainders of the positions (ngravhilo) agrees for a single star.

gpu_tree

The tree gravity on the GPU (ngravtree = 2) agrees with the tree on the CPUs (ngravtree = 1) for the same opening angle and leaf size: energies, accelerations and potentials of a relaxed star; a second GPU run has the threshold of the leaves with a very long list so low that most leaves are divided in chunks.

gravity_auto

ngravtree = -1 chooses the gravity from the number of particles (the direct sum below ngravtreeauto and the tree on the GPU from it up with a GPU, the tree on the CPUs in the CPU build), writes the choice in log0.sph, and gives exactly the energies of the value it chose, set by hand.

guard_ngravprocs

Asking for more gravity processes than there are GPUs is clamped rather than fatal.

startfiles

Bodies are read from the file names given in sph.input, not from names compiled into the code.

periodic

A fully periodic box conserves momentum to round-off and energy closely, keeps every particle inside the box, and shows no density seam at its faces.

periodic_block

Block timesteps in a periodic box, with a hot half on shorter steps, give the same densities as shared timesteps to within 1% and keep every particle inside the box.

guard_periodic

A periodic box too small for the kernel (2h beyond half a period) stops the run with a message rather than missing neighbours.

hdf5_dump

With nhdf5=1 the out*.h5 snapshots hold exactly the numbers of the out*.sph ones, bit for bit, in every column and every entry of the header; with nhdf5=2 the same files appear without out*.sph; restartrad.sph stays native. Skipped unless the build has HDF5 and h5py is installed.

Options:

python3 tests/run_tests.py --list            # what exists
python3 tests/run_tests.py virial energy     # named tests only
python3 tests/run_tests.py --np 2            # fewer ranks
python3 tests/run_tests.py --exe /path/to/..._sph   # skip the build
python3 tests/run_tests.py --with-cpu        # also build the CPU version
python3 tests/run_tests.py --quick           # smaller star, same assertions
python3 tests/run_tests.py --hdf5            # build with make HDF5=1, so that hdf5_dump runs

Each build happens in a copy of the source under the suite’s own scratch directory, so a test run leaves the repository untouched.

Adding a test

Write a function taking a context and returning a one-line description of what it verified, raise Fail with the numbers when it does not hold, and add it to the TESTS dictionary in tests/run_tests.py. Prefer an invariant that has to be true over a value that happened to be produced.