| 1 |
# Kani |
| 2 |
This document describes how to **locally** install and use Kani, along |
| 3 |
with its experimental PropProof feature. Because of instability in |
| 4 |
Kani internals, the GitHub action is the recommended option if you are |
| 5 |
running in CI. |
| 6 |
|
| 7 |
Kani is a software verification tool that complements testing by |
| 8 |
proving the absence of certain classes of bugs like unwrap exceptions, |
| 9 |
overflows, and assertion failures. See the [Kani |
| 10 |
book](https://model-checking.github.io/kani/) for a full list of |
| 11 |
capabilities and limitations. |
| 12 |
|
| 13 |
## Installing Kani and PropProof |
| 14 |
- The install instructions for Kani can be [found |
| 15 |
here](https://model-checking.github.io/kani/install-guide.html). Once |
| 16 |
Kani is installed, you can run with `cargo kani` for projects or |
| 17 |
`kani` for individual Rust files. |
| 18 |
- **[UNSTABLE]** To use PropProof, first download the source code |
| 19 |
from the Kani repository. |
| 20 |
```bash |
| 21 |
git clone https://github.com/model-checking/kani.git --branch features/proptest propproof |
| 22 |
cd propproof; git submodule update --init |
| 23 |
``` |
| 24 |
|
| 25 |
Then, use `.cargo/config.toml` enable it in the local directory you |
| 26 |
want to run Kani in. This will override the `proptest` import in |
| 27 |
your repo. |
| 28 |
|
| 29 |
```bash |
| 30 |
cd $YOUR_REPO_LOCAL_PATH |
| 31 |
mkdir '.cargo' |
| 32 |
echo "paths =[\"$PATH_TO_PROPPROOF\"]" > .cargo/config.toml |
| 33 |
``` |
| 34 |
|
| 35 |
**Please Note**: |
| 36 |
- `features/proptest` branch under Kani is likely not the final |
| 37 |
location for this code. If these instructions stop working, please |
| 38 |
consult the Kani documentation and file an issue on [the Kani |
| 39 |
repo](https://github.com/model-checking/kani.git). |
| 40 |
- The cargo config file will force cargo to always use PropProof. To |
| 41 |
use `proptest`, delete the file. |
| 42 |
|
| 43 |
## Running Kani |
| 44 |
After installing Kani and PropProof, `cargo kani --tests` should |
| 45 |
automatically run `proptest!` harnesses inside your crate. Use |
| 46 |
`--harness` to run a specific harness, and `-p` for a specific |
| 47 |
sub-crate. |
| 48 |
|
| 49 |
If Kani returns with an error, you can use the concrete playback |
| 50 |
feature using `--enable-unstable --concrete-playback print` and paste |
| 51 |
in the code to your repository. Running this harness with `cargo test` |
| 52 |
will replay the input found by Kani that produced this crash. Please |
| 53 |
note that this feature is unstable and using `--concrete-playback |
| 54 |
inplace` to automatically inject a replay harness is not supported |
| 55 |
when using PropProof. |
| 56 |
|
| 57 |
## Debugging CI Failure |
| 58 |
```yaml |
| 59 |
- name: Verify with Kani |
| 60 |
uses: model-checking/[email protected] |
| 61 |
with: |
| 62 |
enable-propproof: true |
| 63 |
args: | |
| 64 |
$KANI_ARGUMENTS |
| 65 |
``` |
| 66 |
|
| 67 |
The above GitHub CI workflow is equivalent to `cargo kani |
| 68 |
$KANI_ARGUMENTS` with PropProof installed. To replicate issues |
| 69 |
locally, run `cargo kani` with the same arguments. |