.. _testing: 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: Profiling ๐Ÿ“Š ============ nuTens is instrumented with a custom profiler. Compiling with the cmake option .. code:: -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: .. code:: int main() { NT_PROFILE_BEGINSESSION(""); NT_PROFILE(); // ... // the rest of your application // ... and adding the NT_PROFILE_ENDSESSION() to the end: .. code:: // ... // the rest of your application // ... NT_PROFILE_ENDSESSION() } Now after running that application, a file will be produced called ".json" containing profile information. You can view the contents of this file in a browser. If using firefox, go to https://profiler.firefox.com/ If using chrome, open chrome and type .. code:: chrome://tracing You can then drag and drop the json profile into the profiler. .. _benchmarking: Benchmarking ๐Ÿ“‰ =============== nuTens uses `Googles benchmark library `_ to perform benchmarking. To compile the benchmark executable you will need to configure nuTens with the cmake option .. code:: -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: .. raw:: html

Const Density Osc Benchmark for nuTens - Bencher

Vacuum Osc Benchmark for nuTens - Bencher

Precompiled Headers ๐Ÿ—ฟ ====================== nuTens has the option to use precompiled headers which can significantyly speed up build times. To enable this feature use the :code:`NT_USE_PCH` cmake option: .. code:: cmake [other options] -DNT_USE_PCH=ON