Testing π§ͺο
Tests live in the tests directory. For c++ tests we use Googles GoogleTest framework and for python tests we use pytest in order to organise our tests and more easily track them. Tests are run as part of our continuous integration and generally for every pull request all tests should pass (i.e. your new change should not break the behaviour of existing code).
If you are adding a new feature to nuTens, you should also include some tests of your new feature. These tests should ideally cover all of the new code that you are adding and should be as βsimpleβ as possible i.e. they should rely as little as possible on other parts of the code. Try to test the smallest possible βunitsβ of your code on their own, ideally against externally calculated values (unit tests), and also the overall behaviour of your new feature (integration tests).
If your new feature has a python interface, new python tests should also be added.
Coverageο
The coverage (how much of the source code appears in tests) of our test suite is tracked using CodeCov. We would ideally like for this to be as close as possible to 100% (though as you can see we arenβt quite there yet).
For this reason, new features should be covered as close as possible to 100%. You will be able to see the coverage of added code in any pull request. Unless there is a good reason for not doing so, new code should only be merged if it is fully covered by new tests.
Profiling πο
nuTens is instrumented with a custom profiler. Compiling with the cmake option
-D NT_PROFILING=ON
will enable the profiling information. You can then profile an application by adding the following to the start of the main() function:
int main()
{
NT_PROFILE_BEGINSESSION("<name of the profile>");
NT_PROFILE();
// ...
// the rest of your application
// ...
and adding the NT_PROFILE_ENDSESSION() to the end:
// ...
// the rest of your application
// ...
NT_PROFILE_ENDSESSION()
}
Now after running that application, a file will be produced called β<name of the profile>.jsonβ containing profile information.
You can view the contents of this file in a browser.
If using firefox, go to
If using chrome, open chrome and type
chrome://tracing
You can then drag and drop the json profile into the profiler.
Benchmarking πο
nuTens uses Googles benchmark library to perform benchmarking.
To compile the benchmark executable you will need to configure nuTens with the cmake option
-DNT_ENABLE_BENCHMARK=ON
Then after make installing, there will be a benchmarks/
directory in the build directory containing the benchmark
executable.
You can run this with all command line options available that are specified in the benchmark user guide.
This is useful to run to compare speed after your changes to the code with the main branch (see below). In fact, this is done as part of the continuous integration process.
Code that causes serious performance regressions in the benchmarks should be very carefully considered before being committed to the main branch.
Resultsο
the main branch is benchmarked every time there is a commit, and the results are tracked uing Bencher. Each benchmark consists of calculating neutrino oscillations for 1024 random variations of parameters in the 3 flavour formalism for 1024 neutrino energies in vacuum and in constant density matter:
Precompiled Headers πΏο
nuTens has the option to use precompiled headers which can significantyly speed up build times.
To enable this feature use the NT_USE_PCH
cmake option:
cmake [other options] -DNT_USE_PCH=ON <path to src>