Skip to content

Commit 192cf87

Browse files
authored
Update concrete playback documentation (rust-lang#2465)
Update the description of how to use concrete playback to incorporate the recent changes, including PR rust-lang#2464
1 parent d2101c7 commit 192cf87

File tree

1 file changed

+23
-35
lines changed

1 file changed

+23
-35
lines changed

docs/src/debugging-verification-failures.md

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,46 @@ enumerates the execution steps leading to the check failure.
99

1010
## Concrete playback
1111

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.
1314

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.
2916

3017
### Usage
3118

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.
3320
After getting a verification failure, Kani will generate a Rust unit test case that plays back a failing
3421
proof harness with a concrete counterexample.
3522
The concrete playback modes mean the following:
3623
* `print`: Kani will just print the unit test to stdout.
3724
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.
3826
* `inplace`: Kani will automatically copy the unit test into your source code.
3927
Before running this mode, you might find it helpful to have your existing code committed to `git`.
4028
That way, you can easily remove the unit test with `git revert`.
4129
Note that Kani will not copy the unit test into your source code if it detects
4230
that the exact same test already exists.
4331

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.
4533
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.
4836
* 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`.
5248

5349
### Example
5450

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:
5652
```rust
5753
#[kani::proof]
5854
fn proof_harness() {
@@ -62,7 +58,7 @@ fn proof_harness() {
6258
b / 2 * 2 == b);
6359
}
6460
```
65-
yields this concrete playback Rust unit test:
61+
yields a concrete playback Rust unit test similar to the one below:
6662
```rust
6763
#[test]
6864
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
7975
cause an assertion failure.
8076
`vec![135, 137]` is the byte array representation of `35207`.
8177

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-
8878
### Request for comments
8979

9080
This feature is experimental and is therefore subject to change.
@@ -101,7 +91,5 @@ Kani generates warning messages for this.
10191
* This feature does not support generating unit tests for multiple assertion failures within the same harness.
10292
This limitation might be removed in the future.
10393
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

Comments
 (0)