2
2
3
3
## Test Suite Generation with CBMC
4
4
5
- ### A Small Tutorial with A Case Study
5
+ ### A Small Tutorial with a Case Study
6
6
7
- We assume that CBMC is installed on your system. If not so , follow
7
+ We assume that CBMC is installed on your system. If not, follow
8
8
\ref man_install-cbmc "these instructions".
9
9
10
10
CBMC can be used to automatically generate test cases that satisfy a
@@ -24,14 +24,14 @@ suite generation functionality in CBMC, by means of a case study. The
24
24
following program is an excerpt from a real-time embedded benchmark
25
25
[ PapaBench] ( https://www.irit.fr/recherches/ARCHI/MARCH/rubrique.php3?id_rubrique=97 ) ,
26
26
and implements part of a fly-by-wire autopilot for an Unmanned Aerial
27
- Vehicle (UAV). It is adjusted mildly for our purposes.
27
+ Vehicle (UAV). We have adjusted it slightly for our purposes.
28
28
29
29
The aim of function ` climb_pid_run ` is to control the vertical climb of
30
30
the UAV. Details on the theory behind this operation are documented in
31
31
the [ wiki] ( https://wiki.paparazziuav.org/wiki/Theory_of_Operation ) for
32
- the Paparazzi UAV project. The behaviour of this simple controller,
32
+ the Paparazzi UAV project. The behavior of this simple controller,
33
33
supposing that the desired speed is 0.5 meters per second, is plotted in
34
- the Figure below.
34
+ the figure below.
35
35
36
36
![ The pid controller] ( https://github.com/diffblue/cbmc/raw/develop/doc/assets/pid.png " The pid controller ")
37
37
@@ -115,7 +115,7 @@ the Figure below.
115
115
77: }
116
116
```
117
117
118
- In order to test the PID controller, we construct a main control loop,
118
+ To test the PID controller, we construct a main control loop,
119
119
which repeatedly invokes the function ` climb_pid_run ` (line 69). This
120
120
PID function has two input variables: the desired speed ` desired_climb `
121
121
and the estimated speed ` estimated_z_dot ` . In the beginning of each loop
@@ -126,26 +126,27 @@ guarantees that both values are bounded within a valid range. The
126
126
and outputs of interest for generating test suites.
127
127
128
128
To demonstrate the automatic test suite generation in CBMC, we call the
129
- following command and we are going to explain the command line options
130
- one by one.
129
+ following command:
131
130
132
131
cbmc pid.c --cover mcdc --unwind 6 --xml-ui
133
132
134
- The option ` --cover mcdc ` specifies the code coverage criterion. There
135
- are four conditional statements in the PID function: in line 41, line
136
- 44, line 48 and line 49. To satisfy MC/DC, the test suite has to meet
133
+ We'll describe those command line options one by one. The option ` --cover mcdc `
134
+ specifies the code coverage criterion. There
135
+ are four conditional statements in the PID function: in lines 41,
136
+ 44, 48, and 49. To satisfy MC/DC, the test suite has to meet
137
137
multiple requirements. For instance, each conditional statement needs to
138
138
evaluate to * true* and * false* . Consider the condition
139
139
` "pprz>=0 && pprz<=MAX_PPRZ" ` in line 41. CBMC instruments three
140
140
coverage goals to control the respective evaluated results of
141
- ` "pprz>=0" ` and ` "pprz<=MAX_PPRZ" ` . We list them in below and they
142
- satisfy the MC/DC rules. Note that ` MAX_PPRZ ` is defined as 16 \* 600 in
143
- line 06 of the program.
141
+ ` "pprz>=0" ` and ` "pprz<=MAX_PPRZ" ` . They
142
+ satisfy the MC/DC rules.
144
143
145
144
!(pprz >= (float)0) && pprz <= (float)(16 * 600) id="climb_pid_run.coverage.1"
146
145
pprz >= (float)0 && !(pprz <= (float)(16 * 600)) id="climb_pid_run.coverage.2"
147
146
pprz >= (float)0 && pprz <= (float)(16 * 600) id="climb_pid_run.coverage.3"
148
147
148
+ Note that ` MAX_PPRZ ` is defined as 16 \* 600 in line 06 of the program.
149
+
149
150
The "id" of each coverage goal is automatically assigned by CBMC. For
150
151
every coverage goal, a test suite (if there exists) that satisfies such
151
152
a goal is printed out in XML format, as the parameter ` --xml-ui ` is
@@ -190,18 +191,17 @@ the coverage goals it is for are clearly described.
190
191
(iteration 6) desired_climb=-1.000000f, estimator_z_dot=1.000000f
191
192
192
193
The option ` --unwind 6 ` unwinds the loop inside the main function body
193
- six times. In order to achieve the complete coverage on all the
194
+ six times. To achieve complete coverage on all the
194
195
instrumented goals in the PID function ` climb_pid_run ` , the loop must be
195
- unwound sufficient enough times. For example, ` climb_pid_run ` needs to
196
+ unwound enough times. For example, ` climb_pid_run ` needs to
196
197
be called at least six times for evaluating the condition
197
198
` climb_sum_err>MAX_CLIMB_SUM_ERR ` in line 48 to * true* . This corresponds
198
- to the Test 5. An introduction to the use of loop unwinding can be found
199
- in [ Understanding Loop Unwinding] ( cbmc-loops.shtml ) .
199
+ to Test 5. To learn more about loop unwinding take a look at [ Understanding Loop Unwinding] ( cbmc-loops.shtml ) .
200
200
201
- In this small tutorial, we present the automatic test suite generation
201
+ In this tutorial, we present the automatic test suite generation
202
202
functionality of CBMC, by applying the MC/DC code coverage criterion to
203
203
a PID controller case study. In addition to ` --cover mcdc ` , other
204
- coverage criteria like ` branch ` , ` decision ` , ` path ` etc . are also
204
+ coverage criteria such as ` branch ` , ` decision ` , and ` path ` . are also
205
205
available when calling CBMC.
206
206
207
207
### Coverage Criteria
0 commit comments