Skip to content

Commit b5a998e

Browse files
authored
Merge pull request #4422 from diffblue/manual-fixes2
Minor manual fixes
2 parents 55b8fc0 + fb3a7f5 commit b5a998e

File tree

8 files changed

+132
-111
lines changed

8 files changed

+132
-111
lines changed

doc/cprover-manual/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ the array **dest** with the given value.
146146

147147
#### Uninterpreted Functions
148148

149-
Uninterpreted functions are documented \ref man_modelling-nondet "here".
149+
Uninterpreted functions are documented [here](../modeling/nondeterminism/)).
150150

151151
### Predefined Types and Symbols
152152

doc/cprover-manual/cbmc-assertions.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ informal description of the assertion. It is shown in the list of
3232
properties together with the condition.
3333

3434
The assertion language of the CPROVER tools is identical to the language
35-
used for expressions. Note that \ref man_modelling-nondet
36-
"nondeterminism"
37-
can be exploited in order to check a range of choices. As an example,
38-
the following code fragment asserts that **all** elements of the array
39-
are zero:
35+
used for expressions. Note that
36+
[nondeterminism](../../modeling-nondeterminism/) can be exploited in order
37+
to check a range of choices. As an example, the following code fragment
38+
asserts that **all** elements of the array are zero:
4039

4140
```C
4241
int a[100], i;

doc/cprover-manual/cbmc-tutorial.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ to detect this problem and reports that the "upper bound property" of
2828
the buffer has been violated. CBMC is capable of checking these
2929
lower and upper bounds, even for arrays with dynamic size. A detailed
3030
discussion of the properties that CBMC can check
31-
automatically is \ref man_instrumentation-properties "here".
31+
automatically is [here](../../properties/).
3232

3333
### First Steps
3434

@@ -53,6 +53,7 @@ int puts(const char *s)
5353
int main(int argc, char **argv)
5454
{
5555
puts(argv[2]);
56+
return 0;
5657
}
5758
```
5859
@@ -74,7 +75,7 @@ preliminary static analysis, which relies on computing a fixed point on
7475
various [abstract
7576
domains](http://en.wikipedia.org/wiki/Abstract_interpretation). More
7677
detail on automatically generated properties is provided
77-
\ref man_instrumentation-properties "here".
78+
[here](../../properties/).
7879
7980
Note that these automatically generated properties need not necessarily
8081
correspond to bugs – these are just *potential* flaws, as abstract
@@ -109,7 +110,7 @@ hold and which do not. Using the SAT solver, CBMC detects that the
109110
property for the object bounds of `argv` does not hold, and will display:
110111
111112
```plaintext
112-
[main.pointer_dereference.6] dereference failure: pointer outside object bounds in argv[(signed long int)2]: FAILURE
113+
[main.pointer_dereference.6] line 7 dereference failure: pointer outside object bounds in argv[(signed long int)2]: FAILURE
113114
```
114115

115116
### Counterexample Traces
@@ -135,16 +136,18 @@ In the example above, we used a program that starts with a `main`
135136
function. However, CBMC is aimed at embedded software, and these kinds
136137
of programs usually have different entry points. Furthermore, CBMC is
137138
also useful for verifying program modules. Consider the following
138-
example, called file2.c:
139+
example, called [file2.c](https://raw.githubusercontent.com/diffblue/cbmc/develop/doc/cprover-manual/file2.c):
139140

140141
```C
141142
int array[10];
142-
int sum() {
143+
144+
int sum()
145+
{
143146
unsigned i, sum;
144147

145-
sum=0;
146-
for(i=0; i<10; i++)
147-
sum+=array[i];
148+
sum = 0;
149+
for(i = 0; i < 10; i++)
150+
sum += array[i];
148151

149152
return sum;
150153
}
@@ -281,7 +284,7 @@ violates an assertion. Without unwinding assertions, or when using the
281284
`--depth` command line switch, CBMC does not prove the program correct,
282285
but it can be helpful to find program bugs. The various command line
283286
options that CBMC offers for loop unwinding are described in the section
284-
on \ref man_cbmc-loops "understanding loop unwinding".
287+
on [understanding loop unwinding](../../cbmc-unwinding/).
285288

286289
### A Note About Compilers and the ANSI-C Library
287290

@@ -319,7 +322,7 @@ be found in the menu *Visual Studio Tools*.
319322
Note that in both cases, only header files are available. CBMC only
320323
comes with a small set of definitions, which includes functions such as
321324
`malloc`. Detailed information about the built-in definitions is
322-
\ref man_instrumentation-libraries "here".
325+
[here](../../goto-cc/).
323326

324327
### Further Reading
325328

doc/cprover-manual/file1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ int puts(const char *s)
55
int main(int argc, char **argv)
66
{
77
puts(argv[2]);
8+
return 0;
89
}

doc/cprover-manual/file2.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
int array[10];
2+
3+
int sum()
4+
{
5+
unsigned i, sum;
6+
7+
sum = 0;
8+
for(i = 0; i < 10; i++)
9+
sum += array[i];
10+
11+
return sum;
12+
}

doc/cprover-manual/goto-cc.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,25 @@ This example assumes a Unix-like machine.
2929
1. Download the sources of wu-ftpd from
3030
[here](ftp://ftp.wu-ftpd.org/pub/wu-ftpd/wu-ftpd-current.tar.gz).
3131

32-
2. Unpack the sources by running ` tar xfz wu-ftpd-current.tar.gz`.
32+
2. Unpack the sources by running
33+
34+
tar xfz wu-ftpd-current.tar.gz
3335

3436
3. Change to the source directory, for example by entering,
35-
`cd wu-ftpd-2.6.2`.
37+
38+
cd wu-ftpd-2.6.2
3639

3740
4. Configure the project for verification by running:
3841

39-
`./configure YACC=byacc CC=goto-cc --host=none-none-none`
42+
./configure YACC=byacc CC=goto-cc --host=none-none-none
4043

4144
5. Build the project by running `make`. This creates multiple model
4245
files in the `src` directory. Among them is a model for the main
4346
executable `ftpd`.
4447

4548
6. Run a model-checker, for example CBMC, on the model file:
4649

47-
`cbmc src/ftpd`
50+
cbmc src/ftpd
4851

4952
CBMC automatically recognizes that the file is a goto binary.
5053

@@ -68,7 +71,9 @@ A helpful command that accomplishes this task successfully for many
6871
projects is:
6972

7073
```plaintext
71-
for i in `find . -name Makefile`; do sed -e 's/^\(\s*CC[ \t]*=\)\(.*$\)/\1goto-cc/g' -i $i done
74+
for i in `find . -name Makefile`; do
75+
sed -e 's/^\(\s*CC[ \t]*=\)\(.*$\)/\1goto-cc/g' -i $i
76+
done
7277
```
7378

7479
Here are additional examples on how to use goto-cc:

doc/cprover-manual/properties.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ program, or it is desirable to replace bodies of functions with certain
136136
predetermined stubs (for example to confirm that these functions are never
137137
called, or to indicate that these functions will never return). For this purpose
138138
goto-instrument provides the `--generate-function-body` option, that takes a
139-
regular expression (in [ECMAScript syntax]
140-
(http://en.cppreference.com/w/cpp/regex/ecmascript)) that describes the names of
139+
regular expression (in [ECMAScript
140+
syntax](http://en.cppreference.com/w/cpp/regex/ecmascript)) that describes the names of
141141
the functions to generate. Note that this will only generate bodies for
142142
functions that do not already have one; If one wishes to replace the body of a
143143
function with an existing definition, the `--remove-function-body` option can be
@@ -193,14 +193,14 @@ Now, we can compile the program and detect that the error functions are indeed
193193
called by invoking these commands:
194194

195195
```
196-
goto-cc error_example.c -o error_example.goto
197-
# Replace all functions ending with _error
198-
# (Excluding those starting with __)
199-
# With ones that have an assert(false) body
200-
goto-instrument error_example.goto error_example_replaced.goto \
201-
--generate-function-body '(?!__).*_error' \
202-
--generate-function-body-options assert-false
203-
cbmc error_example_replaced.goto
196+
goto-cc error_example.c -o error_example.goto
197+
# Replace all functions ending with _error
198+
# (Excluding those starting with __)
199+
# With ones that have an assert(false) body
200+
goto-instrument error_example.goto error_example_replaced.goto \
201+
--generate-function-body '(?!__).*_error' \
202+
--generate-function-body-options assert-false
203+
cbmc error_example_replaced.goto
204204
```
205205

206206
Which gets us the output

doc/cprover-manual/test-suite.md

Lines changed: 81 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
[CPROVER Manual TOC](../../)
1+
[CPROVER Manual TOC](../)
22

33
## Test Suite Generation with CBMC
44

55
### A Small Tutorial with a Case Study
66

77
We assume that CBMC is installed on your system. If not, follow
8-
\ref man_install-cbmc "these instructions".
8+
[these instructions](../../installation/).
99

1010
CBMC can be used to automatically generate test cases that satisfy a
1111
certain [code coverage](https://en.wikipedia.org/wiki/Code_coverage)
@@ -36,83 +36,83 @@ the figure below.
3636
![The pid controller](https://github.com/diffblue/cbmc/raw/develop/doc/assets/pid.png "The pid controller")
3737

3838
```
39-
01: // CONSTANTS:
40-
02: #define MAX_CLIMB_SUM_ERR 10
41-
03: #define MAX_CLIMB 1
42-
04:
43-
05: #define CLOCK 16
44-
06: #define MAX_PPRZ (CLOCK*600)
45-
07:
46-
08: #define CLIMB_LEVEL_GAZ 0.31
47-
09: #define CLIMB_GAZ_OF_CLIMB 0.75
48-
10: #define CLIMB_PITCH_OF_VZ_PGAIN 0.05
49-
11: #define CLIMB_PGAIN -0.03
50-
12: #define CLIMB_IGAIN 0.1
51-
13:
52-
14: const float pitch_of_vz_pgain=CLIMB_PITCH_OF_VZ_PGAIN;
53-
15: const float climb_pgain=CLIMB_PGAIN;
54-
16: const float climb_igain=CLIMB_IGAIN;
55-
17: const float nav_pitch=0;
56-
18:
57-
19: /** PID function INPUTS */
58-
20: // The user input: target speed in vertical direction
59-
21: float desired_climb;
60-
22: // Vertical speed of the UAV detected by GPS sensor
61-
23: float estimator_z_dot;
62-
24:
63-
25: /** PID function OUTPUTS */
64-
26: float desired_gaz;
65-
27: float desired_pitch;
66-
28:
67-
29: /** The state variable: accumulated error in the control */
68-
30: float climb_sum_err=0;
69-
31:
70-
32: /** Computes desired_gaz and desired_pitch */
71-
33: void climb_pid_run()
72-
34: {
73-
35:
74-
36: float err=estimator_z_dot-desired_climb;
75-
37:
76-
38: float fgaz=climb_pgain*(err+climb_igain*climb_sum_err)+CLIMB_LEVEL_GAZ+CLIMB_GAZ_OF_CLIMB*desired_climb;
77-
39:
78-
40: float pprz=fgaz*MAX_PPRZ;
79-
41: desired_gaz=((pprz>=0 && pprz<=MAX_PPRZ) ? pprz : (pprz>MAX_PPRZ ? MAX_PPRZ : 0));
80-
42:
81-
43: /** pitch offset for climb */
82-
44: float pitch_of_vz=(desired_climb>0) ? desired_climb*pitch_of_vz_pgain : 0;
83-
45: desired_pitch=nav_pitch+pitch_of_vz;
84-
46:
85-
47: climb_sum_err=err+climb_sum_err;
86-
48: if (climb_sum_err>MAX_CLIMB_SUM_ERR) climb_sum_err=MAX_CLIMB_SUM_ERR;
87-
49: if (climb_sum_err<-MAX_CLIMB_SUM_ERR) climb_sum_err=-MAX_CLIMB_SUM_ERR;
88-
50:
89-
51: }
90-
52:
91-
53: int main()
92-
54: {
93-
55:
94-
56: while(1)
95-
57: {
96-
58: /** Non-deterministic input values */
97-
59: desired_climb=nondet_float();
98-
60: estimator_z_dot=nondet_float();
99-
61:
100-
62: /** Range of input values */
101-
63: __CPROVER_assume(desired_climb>=-MAX_CLIMB && desired_climb<=MAX_CLIMB);
102-
64: __CPROVER_assume(estimator_z_dot>=-MAX_CLIMB && estimator_z_dot<=MAX_CLIMB);
103-
65:
104-
66: __CPROVER_input("desired_climb", desired_climb);
105-
67: __CPROVER_input("estimator_z_dot", estimator_z_dot);
106-
68:
107-
69: climb_pid_run();
108-
70:
109-
71: __CPROVER_output("desired_gaz", desired_gaz);
110-
72: __CPROVER_output("desired_pitch", desired_pitch);
111-
73:
112-
74: }
113-
75:
114-
76: return 0;
115-
77: }
39+
01: // CONSTANTS:
40+
02: #define MAX_CLIMB_SUM_ERR 10
41+
03: #define MAX_CLIMB 1
42+
04:
43+
05: #define CLOCK 16
44+
06: #define MAX_PPRZ (CLOCK*600)
45+
07:
46+
08: #define CLIMB_LEVEL_GAZ 0.31
47+
09: #define CLIMB_GAZ_OF_CLIMB 0.75
48+
10: #define CLIMB_PITCH_OF_VZ_PGAIN 0.05
49+
11: #define CLIMB_PGAIN -0.03
50+
12: #define CLIMB_IGAIN 0.1
51+
13:
52+
14: const float pitch_of_vz_pgain=CLIMB_PITCH_OF_VZ_PGAIN;
53+
15: const float climb_pgain=CLIMB_PGAIN;
54+
16: const float climb_igain=CLIMB_IGAIN;
55+
17: const float nav_pitch=0;
56+
18:
57+
19: /** PID function INPUTS */
58+
20: // The user input: target speed in vertical direction
59+
21: float desired_climb;
60+
22: // Vertical speed of the UAV detected by GPS sensor
61+
23: float estimator_z_dot;
62+
24:
63+
25: /** PID function OUTPUTS */
64+
26: float desired_gaz;
65+
27: float desired_pitch;
66+
28:
67+
29: /** The state variable: accumulated error in the control */
68+
30: float climb_sum_err=0;
69+
31:
70+
32: /** Computes desired_gaz and desired_pitch */
71+
33: void climb_pid_run()
72+
34: {
73+
35:
74+
36: float err=estimator_z_dot-desired_climb;
75+
37:
76+
38: float fgaz=climb_pgain*(err+climb_igain*climb_sum_err)+CLIMB_LEVEL_GAZ+CLIMB_GAZ_OF_CLIMB*desired_climb;
77+
39:
78+
40: float pprz=fgaz*MAX_PPRZ;
79+
41: desired_gaz=((pprz>=0 && pprz<=MAX_PPRZ) ? pprz : (pprz>MAX_PPRZ ? MAX_PPRZ : 0));
80+
42:
81+
43: /** pitch offset for climb */
82+
44: float pitch_of_vz=(desired_climb>0) ? desired_climb*pitch_of_vz_pgain : 0;
83+
45: desired_pitch=nav_pitch+pitch_of_vz;
84+
46:
85+
47: climb_sum_err=err+climb_sum_err;
86+
48: if (climb_sum_err>MAX_CLIMB_SUM_ERR) climb_sum_err=MAX_CLIMB_SUM_ERR;
87+
49: if (climb_sum_err<-MAX_CLIMB_SUM_ERR) climb_sum_err=-MAX_CLIMB_SUM_ERR;
88+
50:
89+
51: }
90+
52:
91+
53: int main()
92+
54: {
93+
55:
94+
56: while(1)
95+
57: {
96+
58: /** Non-deterministic input values */
97+
59: desired_climb=nondet_float();
98+
60: estimator_z_dot=nondet_float();
99+
61:
100+
62: /** Range of input values */
101+
63: __CPROVER_assume(desired_climb>=-MAX_CLIMB && desired_climb<=MAX_CLIMB);
102+
64: __CPROVER_assume(estimator_z_dot>=-MAX_CLIMB && estimator_z_dot<=MAX_CLIMB);
103+
65:
104+
66: __CPROVER_input("desired_climb", desired_climb);
105+
67: __CPROVER_input("estimator_z_dot", estimator_z_dot);
106+
68:
107+
69: climb_pid_run();
108+
70:
109+
71: __CPROVER_output("desired_gaz", desired_gaz);
110+
72: __CPROVER_output("desired_pitch", desired_pitch);
111+
73:
112+
74: }
113+
75:
114+
76: return 0;
115+
77: }
116116
```
117117

118118
To test the PID controller, we construct a main control loop,
@@ -196,7 +196,8 @@ instrumented goals in the PID function `climb_pid_run`, the loop must be
196196
unwound enough times. For example, `climb_pid_run` needs to
197197
be called at least six times for evaluating the condition
198198
`climb_sum_err>MAX_CLIMB_SUM_ERR` in line 48 to *true*. This corresponds
199-
to Test 5. To learn more about loop unwinding take a look at [Understanding Loop Unwinding](cbmc-loops.shtml).
199+
to Test 5. To learn more about loop unwinding take a look at [Understanding Loop
200+
Unwinding](../../cbmc-unwinding/).
200201

201202
In this tutorial, we present the automatic test suite generation
202203
functionality of CBMC, by applying the MC/DC code coverage criterion to

0 commit comments

Comments
 (0)