@@ -9,50 +9,46 @@ enumerates the execution steps leading to the check failure.
9
9
10
10
## Concrete playback
11
11
12
- This section describes the concrete playback feature in more detail.
12
+ When concrete playback is enabled, Kani will generate unit tests for assertions that failed during verification,
13
+ as well as cover statements that are reachable.
13
14
14
- ### Setup
15
-
16
- The Kani library needs to be linked as a dev dependency to the crate you're trying to debug.
17
- This requires adding the following lines to your ` Cargo.toml ` file,
18
- which differ depending on what version of the Kani library you would like to use:
19
- * The latest version:
20
- ``` toml
21
- [dev-dependencies ]
22
- kani = { git = " https://github.com/model-checking/kani" , features = [" concrete_playback" ] }
23
- ```
24
- * A specific version of the Kani library (v0.9+) that's already downloaded:
25
- ``` toml
26
- [dev-dependencies ]
27
- kani = { path = " {path_to_kani_root}/library/kani" , features = [" concrete_playback" ] }
28
- ```
15
+ These tests can then be executed using Kani's playback subcommand.
29
16
30
17
### Usage
31
18
32
- In order to enable this feature, run Kani with the ` --enable-unstable --concrete-playback=[print|inplace] ` flag.
19
+ In order to enable this feature, run Kani with the ` -Z concrete-playback --concrete-playback=[print|inplace] ` flag.
33
20
After getting a verification failure, Kani will generate a Rust unit test case that plays back a failing
34
21
proof harness with a concrete counterexample.
35
22
The concrete playback modes mean the following:
36
23
* ` print ` : Kani will just print the unit test to stdout.
37
24
You will then need to copy this unit test into the same module as your proof harness.
25
+ This is also helpful if you just want to quickly find out which values were assigned by ` kani::any() ` calls.
38
26
* ` inplace ` : Kani will automatically copy the unit test into your source code.
39
27
Before running this mode, you might find it helpful to have your existing code committed to ` git ` .
40
28
That way, you can easily remove the unit test with ` git revert ` .
41
29
Note that Kani will not copy the unit test into your source code if it detects
42
30
that the exact same test already exists.
43
31
44
- After the unit test is in your source code, you can run it with ` cargo test ` .
32
+ After the unit test is in your source code, you can run it with the ` playback ` subcommand .
45
33
To debug it, there are a couple of options:
46
- * If you have certain IDEs, there are extensions (e.g., ` rust-analyzer ` for ` VS Code ` )
47
- that support UI elements like a ` Run Test | Debug ` button next to all unit tests .
34
+ * You can try [ Kani's experimental extension ] ( https://github.com/model-checking/kani-vscode-extension )
35
+ provided for VSCode .
48
36
* Otherwise, you can debug the unit test on the command line.
49
- To do this, you first run ` cargo test {unit_test_func_name} ` .
50
- The output from this will have a line in the beginning like ` Running unittests {files} ({binary}) ` .
51
- You can then debug the binary with tools like ` rust-gdb ` or ` lldb ` .
37
+
38
+ To manually compile and run the test, you can use Kani's ` playback ` subcommand:
39
+ ```
40
+ cargo kani playback -Z concrete-playback -- ${unit_test_func_name}
41
+ ```
42
+
43
+ The output from this command is similar to ` cargo test ` .
44
+ The output will have a line in the beginning like
45
+ ` Running unittests {files} ({binary}) ` .
46
+
47
+ You can further debug the binary with tools like ` rust-gdb ` or ` lldb ` .
52
48
53
49
### Example
54
50
55
- Running ` kani --enable-unstable --concrete-playback=print ` on the following source file:
51
+ Running ` kani -Z concrete-playback --concrete-playback=print ` on the following source file:
56
52
``` rust
57
53
#[kani:: proof]
58
54
fn proof_harness () {
@@ -62,7 +58,7 @@ fn proof_harness() {
62
58
b / 2 * 2 == b );
63
59
}
64
60
```
65
- yields this concrete playback Rust unit test:
61
+ yields a concrete playback Rust unit test similar to the one below :
66
62
``` rust
67
63
#[test]
68
64
fn kani_concrete_playback_proof_harness_16220658101615121791 () {
@@ -79,12 +75,6 @@ Here, `133` and `35207` are the concrete values that, when substituted for `a` a
79
75
cause an assertion failure.
80
76
` vec![135, 137] ` is the byte array representation of ` 35207 ` .
81
77
82
- ### Common issues
83
-
84
- * ` error[E0425]: cannot find function x in this scope ` :
85
- this is usually caused by having ` #[cfg(kani)] ` somewhere in the control flow path of the user's proof harness.
86
- To fix this, remove ` #[cfg(kani)] ` from those paths.
87
-
88
78
### Request for comments
89
79
90
80
This feature is experimental and is therefore subject to change.
@@ -101,7 +91,5 @@ Kani generates warning messages for this.
101
91
* This feature does not support generating unit tests for multiple assertion failures within the same harness.
102
92
This limitation might be removed in the future.
103
93
Kani generates warning messages for this.
104
- * This feature requires that you do not change your code or runtime configurations between when Kani generates the unit test and when you run it.
105
- For instance, if you linked with library A during unit test generation and library B during unit test play back,
106
- that might cause unintended errors in the unit test counterexample.
107
- Kani currently has no way to detect this issue.
94
+ * This feature requires that you use the same Kani version to generate the test and to playback.
95
+ Any extra compilation option used during verification must be used during playback.
0 commit comments