blob: 01378f69cb64df268ba9e160b8d0418a20befb72 [file] [log] [blame]
Mate Toth-Pal5176cb82023-10-18 17:35:57 +02001.. SPDX-License-Identifier: BSD-3-Clause
2.. SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
3
4****
5CBMC
6****
7
8CBMC is a Bounded Model Checker for C and C++ programs. For details see
9`CBMC Home`_
10
11CBMC in RMM
12===========
13
14CBMC needs to be run on a C program that has a single entry point. To test all
15the RMM ABI commands, for each command a testbench file is created. These files
16are generated by a script offline from the RMM MRS (Machine Readable
17Specification), and committed to the RMM repository under the folder
18``tools/cbmc/testbenches``
19
20.. note::
21
22 Currently only a subset of the ABI calls have a testbench implemented. Also
23 there are errors reported by CBMC for some of the testbenches. Further
24 testbenches and fixes are expected to be added later.
25
26These files contain asserts that correspond to
27the Faliure and Success conditions defined in the RMM specification. To read on
28further how such a file should be defined please refer to
29`Writing a good proof`_
30
31The recommended way for installing CBMC is via the pre-built package found at
32the `github release page`_. The same page contains the instructions for
33installing the different release packages.
34
35An example install command for Ubuntu linux is
36
37.. code-block:: bash
38
39 dpkg -i ubuntu-20.04-cbmc-5.95.1-Linux.deb
40
41The invocation of CBMC tool is integrated in the RMM CMake system. CBMC analysis
42can be run by passing specific targets (detailed later) to the build command. to
43make the targets available the RMM build must be configured with
44``-DRMM_CONFIG=host_defcfg -DHOST_VARIANT=host_cbmc`` options.
45
46The results of a CBMC run are generated in the
47``${RMM_BUILD_DIR}/tools/cbmc/cbmc_${MODE}_results`` directory. There are 3
48files, ``${TESTBENCH_FILE_NAME}.${MODE}.[cmd|error|output]`` generated for each
49RMM ABI under test, each one containing the CBMC command line, the CBMC
50executable's output to the standard error, and the output to the standard out
51respectively. There is also a single ``SUMMARY.${MODE}`` file is generated for
52each build.
53
54For an example build command please refer to :ref:`RMM Build Examples`
55
56The CMake system provides different modes in which CBMC can be called, along
57with their respective build targets.
58
59CBMC Assert
60===========
61
62In this mode CBMC is configured, so that it tries to find inputs that makes an
63assertion in the code to fail. If there is such an input, then CBMC provides a
64trace that leads to that assertion failure.
65
66To use this mode the target ``cbmc-assert`` must be passed to the build command.
67
68CBMC Analysis
69=============
70
71In this mode CBMC is configured to generate assertions for certain properties in
72the code. The properties are selected so that for example no buffer overflows,
73or arithmetic overflow errors can happen in the code. For more details please
74refer to `Automatically Generating Properties`_.
75Then CBMC is run in a configuration similar to the Assert mode, except that this
76time traces are not generated.
77
78To use this mode the target ``cbmc-analysis`` must be passed to the build
79command.
80
81CBMC Coverage
82=============
83
84This mode checks whether all the conditions for an ABI function are covered.
85The pre and post conditions for the command are expressed as boolean values in
86the testbench, and a ``__CPROVER_cover()`` macro is added for each condition
87that is expressed with the pre and post conditions. CBMC is configured to try
88to generate an input for each ``__CPROVER_cover()`` call that makes the code
89reach that call.
90
91To use this mode the target ``cbmc-coverage`` must be passed to the build
92command.
93
94.. note::
95
96 For all the modes the summary files are committed in the source tree as
97 baseline in ``tools/cbmc/testbenches_results/BASELINE.${MODE}``.
98
99-----
100
101.. _CBMC Home: https://www.cprover.org/cbmc/
102.. _Writing a good proof: https://model-checking.github.io/cbmc-training/management/Write-a-good-proof.html
103.. _github release page: https://github.com/diffblue/cbmc/releases
104.. _Automatically Generating Properties: https://www.cprover.org/cprover-manual/properties/
105