Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert some insider doc to sphinx, and remove obsolete bits from doxygen sources
[simgrid.git] / docs / source / Developers_Documentation.rst
1 .. _dev_doc:
2
3 Developer's Documentation
4 =========================
5
6 This page describes the software infrastructure for SimGrid potential contributors. This page is particularly interesting if you plan to contribute to the
7 project.
8
9 Enforcing the coding standards
10 ------------------------------
11
12 If you plan to contribute code to the SimGrid project, you must ensure that your changes follow our coding standards. For that, simply install the relevant
13 tools and scripts.
14
15 .. code-block:: console
16
17    # install clang-format
18    sudo apt-get install clang-format # debian/ubuntu
19
20    # tell git to call the script on each commit
21    ln -s $(realpath tools/git-hooks/clang-format.pre-commit) .git/hooks/pre-commit
22
23 This will add an extra verification before integrating any commit that you could prepare. If your code does not respects our formatting code, git will say so,
24 and provide a ready to use patch that you can apply to improve your commit. Just read the error message you get to find how to apply the fix after review.
25
26 If you prefer not to apply the fix on a specific commit (because the formatter fails on this case), then add ``--no-verify`` to your git commit command line.
27
28 Setting up the development environment
29 --------------------------------------
30
31 The :ref:`default build configuration <install_src_config>` is intended for users, but contributors should change these settings for their comfort, and to
32 produce better code. In particular, the default is to build highly optimized binaries, at the price of high compilation time and somewhat harder debug sessions.
33 Instead, contributors want to disable the ``enable_compile_optimizations`` compile option. Likewise, ``enable_compile_warnings`` is off by default to not bother
34 the users, but the contributors should really enable it, as your code will not be integrated if it raises warnings from the compiler.
35
36 .. code-block:: console
37
38    cmake -Denable_compile_optimizations=OFF \
39          -Denable_compile_warnings=ON \
40          -GNinja .
41
42 As you can see, we advise to use Ninja instead of the good old Makefiles. In our experience, Ninja is a bit faster because it does not fork as many external
43 commands as make for basic operations.
44
45 Interacting with the tests
46 --------------------------
47
48 We use unit tests based on `Catch2 <https://github.com/catchorg/Catch2/>`_, but most of our testing is done through integration tests that launch a specific
49 simulation example and enforce that the output remains unchanged. Since SimGrid displays the timestamp of every logged event, such integration tests ensure that
50 every change of the models' prediction will be noticed. We designed a specific tool for these integration tests, called TESH (the TEsting SHell). ``ctest`` is
51 used to run both unit and integration tests. You can :ref:`run only some of the tests <install_src_test>` if you prefer. To launch the unit tests out of ctest,
52 build and execute the ``./unit-tests`` binary (it accepts a ``--help`` parameter). To rebuild and run all tests, use the ``./BuildSimGrid.sh`` script.
53
54 The SimGrid code base contains a lot of tests for a coverage well over 80%. We want the contributors to feel confident, and improve the code without fearing of
55 breaking something without noticing. Tests must be fast (because we run them very often), the should stress many aspects of the code (to actually catch problems) and
56 clear to read (understanding and debugging failures should be easy).
57
58 In fact, our integration tests fall in two categories. The ones located in ``examples/`` are part of the documentation, so readability is utterly important
59 here. The goal is that novice users could grab some of the provided examples and assemble them to constitute a first version of their simulator. We tend to
60 avoid advanced C++ constructs that would hinder the readability of these files. On the other hand, the integration tests located in ``teshsuite/`` are usually
61 torture tests trying to exhaustively cover all cases. They may be less readable and some even rely on a small DSL to describe all test cases and the expected
62 result (check for example ``teshsuite/models/cloud-sharing``), but they should still be rather easy to debug on need. For this reason, we tend to avoid random
63 testing that is difficult to reproduce. For example, the tests under ``teshsuite/models/`` try to be very verbose to make the model intend clear, and the code
64 easier to debug on need. The WiFi tests seem to be a good example of that trend.
65
66 We often say that a feature that is not tested is a feature that could soon disappear. So you want to write tests for the features you add. To add new unit
67 tests, please refer to the end of ``tools/cmake/Tests.cmake``) for some examples. Catch2 comes with a good documentation and many examples online. If you add a
68 new feature, you should add an integration test in ``examples/``. Your code should be instructive, documented, reusable, and its output must be perfectly
69 reproducible. Some debugging information can be hidden when run from TESH with the :c:macro:`XBT_LOG_ISENABLED` macro. You then need to write a tesh file,
70 following the syntax described in this man page: ``man -l manpages/tesh.1`` Finally, you should add your source code and tesh file to the cmake infrastructure
71 by modifying for example the ``examples/cpp/CMakeLists.txt`` file. The test name shall allow the filtering of tests with ``ctest -R``. Do not forget to run
72 ``make distcheck`` once you're done to check that you did not forget to add your new files to the distribution.
73
74 We have many online build bots that launch the tests on various configurations and operating systems. The results are centralized on two Jenkins jobs: `the main
75 one <https://ci.inria.fr/simgrid/job/SimGrid/>`_ runs all tests on a variety of systems for each commit, while `Nightly
76 <https://ci.inria.fr/simgrid/job/SimGrid-Nightly/>`_ runs some additional code analysis every night. Several sister projects built on top of SimGrid regularly
77 test our git too. The FramaGit project gathers some additional `build badges <https://framagit.org/simgrid/simgrid>`_, and results are posted on the `bot-office
78 channel <https://framateam.org/simgrid/channels/bot-office>`_ on Mattermost. Our code quality is tested every night using `SonarQube
79 <https://sonarcloud.io/dashboard?id=simgrid_simgrid>`_ , and the `Debian build daemon <https://buildd.debian.org/status/package.php?p=simgrid>`_ test each
80 release on several CPU architectures. We maintain some scripts to interact with these tools under ``tools/cmake``.
81
82 Breaking tests once in a while is completely OK in SimGrid. We accept temporarily breakages because we want things to evolve, but if you break something, it is
83 your duty to fix it within 24 hours to not hinder the work of others.
84
85 Interacting with git
86 --------------------
87
88 The SimGrid community is relatively small and active. We are not used to maintain long-standing branches but instead, we strive to do our changes in an
89 incremental way, commiting all intermediary steps to the main branch. The only thing is to ensure that you don't break things on the path, i.e. that all tests
90 pass for all commits. If you prefer to do a branch to accumulate some commits in a branch, you should strive to make so for a short period of time to reduce the
91 burden of the branch maintenance. Large changes happen from time to time to the SimGrid source code, and your branch may become hard to rebase.
92
93 It is nice if your commit message could follow the git habits, explained in this `blog post
94 <http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html>`_, or in the `style guide of Atom
95 <https://github.com/atom/atom/blob/master/CONTRIBUTING.md#git-commit-messages>`_.
96
97 Unsorted hints
98 --------------
99
100 * If you break the logs, you want to define XBT_LOG_MAYDAY at the beginning of log.h. It deactivates the whole logging mechanism, switching to printfs instead.
101   SimGrid then becomes incredibly verbose, but it you let you fixing things.