@@ -13,9 +13,10 @@ having to manually construct an appropriate environment.
13
13
14
14
We have two types of harnesses we can generate for now:
15
15
16
- * The ` memory-snapshot ` harness. TODO: Daniel can document this.
17
16
* The ` function-call ` harness, which automatically synthesises an environment
18
17
without having any information about the program state.
18
+ * The ` memory-snapshot ` harness, which loads an existing program state (in form
19
+ of a JSON file) and selectively _ havoc-ing_ some variables.
19
20
20
21
It is used similarly to how ` goto-instrument ` is used by modifying an existing
21
22
GOTO binary, as produced by ` goto-cc ` .
@@ -309,4 +310,57 @@ main.c function function
309
310
310
311
** 0 of 1 failed (1 iterations)
311
312
VERIFICATION SUCCESSFUL
312
- ```
313
+ ```
314
+
315
+ ### The memory snapshot harness
316
+
317
+ The `function-call` harness is used in situations when we want the analysed
318
+ function to work in arbitrary environment. If we want a more restricted
319
+ environment or if we have the program in which our function will only be called,
320
+ we call the `memory-snapshot` harness instead.
321
+
322
+ Furthermore, the program state of interest may be taken a particular location
323
+ within a function. In that case we do not want the harness to instrument the
324
+ whole function but rather to allow starting the execution from a specific
325
+ initial location (specified via `--initial-location func[:<n>]`).
326
+
327
+ Say we want to check the assertion in the following code:
328
+
329
+ ```C
330
+ // main.c
331
+ unsigned int x;
332
+ unsigned int y;
333
+
334
+ unsigned int complex_function_which_returns_one() {
335
+ unsinged int i = 0;
336
+ while (i < 1000000000) {
337
+ if (y)
338
+ break;
339
+ }
340
+ return i & 2;
341
+ }
342
+
343
+ int main() {
344
+ x = complex_function_which_returns_one();
345
+ assert(y + 2 > x);
346
+ return 0;
347
+ }
348
+ ```
349
+
350
+ But are not particularly interested in the analysing the complex function, since
351
+ we trust that its implementation is correct. Hence we run the above program
352
+ stopping after the assignment to ` x ` and storing the program state, e.g. using
353
+ the ` memory-analyzer ` , in a JSON file ` snapshot.json ` . Then run the harness and
354
+ verify the assertion with:
355
+
356
+ ```
357
+ $ goto-cc -o main.gb main.c
358
+ $ goto-harness \
359
+ --harness-function-name harness \
360
+ --harness-type initialise-with-memory-snapshot \
361
+ --memory-snapshot snapshot.json \
362
+ --initial-location main:1 \
363
+ --havoc-variables x \
364
+ main.gb main-mod.gb
365
+ $ cbmc --function harness main-mod.gb
366
+ ```
0 commit comments