Skip to content

Executable trace feature#1409

Merged
sanjit-bhat merged 104 commits intomodel-checking:mainfrom
sanjit-bhat:execute-trace
Aug 10, 2022
Merged

Executable trace feature#1409
sanjit-bhat merged 104 commits intomodel-checking:mainfrom
sanjit-bhat:execute-trace

Conversation

@sanjit-bhat
Copy link
Copy Markdown
Contributor

@sanjit-bhat sanjit-bhat commented Jul 25, 2022

Description of changes:

This PR adds the executable trace feature for improving users' debugging experience after verification failures. With the --gen-exe-trace flag, Kani will print out a Rust unit test that contains 1) concrete values for all calls to kani::any and 2) a call to the failed proof harness. The user can then debug their failing proof harness like they would with any normal Rust unit test. With an optional --add-exe-trace-to-src flag, Kani will even add the unit test directly to the user's source code.

To use this feature on a test crate:

  1. Add this to your Cargo.toml:
[dev-dependencies]
kani = { path = "{path_to_kani}/library/kani", features = ["exe_trace"] }
  1. Make sure your code isn't hidden under a cfg(kani) feature flag.

Resolved issues:

Implements recommended approach in #1388. Closes #1253. Closes #1317. Closes #1392. Closes #1443. Closes #1444. Closes #1445.

Call-outs:

  1. New any_raw: After Deprecate any_raw and Invariant #1415, any_raw_internal will only be called on primitive types. These show up nicely in the CBMC output trace, removing the need for a complicated parser or changing the lowest level non-determinism to a byte array.
  2. Performance: On the verification side, performance should stay the exact same. On the post-processing side, we only add the --trace flag to CBMC when the user runs with --gen-exe-trace. This flag adds a bit more overhead to CBMC post-processing, which scales with the length of the trace. We have been able to run this feature on fairly large traces (100s of states) without much of a noticeable performance difference.
  3. slice-formula: Currently, if a variable uses a kani::any assignment, but that variable isn't present in the verification conditions, CBMC doesn't have a concrete value for it in the output trace. To fix this, we would likely need to disable --slice-formula when we run CBMC with --trace. See Enable CBMC's equation-level slicer #1252.
  4. generic_const_expr: We needed this incomplete feature to take the size_of a generic type. However, after Deprecate any_raw and Invariant #1415, if we only call any_raw_internal using macros on primitive types, we could remove this and add the size as a type parameter to any_raw_internal.

Testing:

This change has an end-to-end UI test that checks to see if the correct concrete values are parsed and placed into a test case. We also manually tested this feature on a few different test harnesses. In the future, we plan to add the following tests:

  1. A custom test that uses the --add-exe-trace-to-src feature and runs the unit test to verify that assertions actually fail. For now, we manually test this.
  2. Unit tests for the exe_trace module in the kani-driver.

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@sanjit-bhat sanjit-bhat self-assigned this Jul 25, 2022
Copy link
Copy Markdown
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass. Thanks for doing this! :)

@sanjit-bhat sanjit-bhat changed the title Executable trace feature [WIP, do not review] Executable trace feature Jul 25, 2022
Copy link
Copy Markdown
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I know this is not ready yet for review, but I just have two comments that hopefully will help you refine this.

  1. I think you still need to add implementation for some of our library functions, e.g., the kani::assert() is empty today.
  2. Improve the interface to initialize the test values. See comment below.

This was formed by squashing the following commits:

feat: exec-trace POC that gets kani::any assignments

feat: init work making exec_trace a Kani command line flag

feat: make trace parsing more precise

feat: allow for multiple extracted values

feat: Move parsing code into the driver

refactor: move functions outside KaniSession

test: add basic UI test for det val

feat: change any_raw to make it easier to parse trace

feat: update any_raw to use byte array

feat: update parser to take in byte array

chore: run rustfmt

test: add constant generic bound to func abstraction tests

test: fix remaining test issues to pass regression

feat: update any_raw_inner to return bytes

chore: remove spurious results file

feat: update any_raw_inner to read from det_vals file

feat: add exec_trace flag to kani-compiler

refactor(kani-compiler): rename vars to increase readability

feat(kani-compiler): specify different Kani lib paths

feat: prototype E2E mechanism for gen det vals & running exec trace

fix: add generic const trait bounds to any_vec

feat: add print out to get debug command

chore: remove det vals from tmp file list for demo
Copy link
Copy Markdown
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. It's almost there.

I tried to only post comments on things that are user visible. I created #1481 to track the outstanding work.

Thank you!

@sanjit-bhat
Copy link
Copy Markdown
Contributor Author

@adpaco-aws can you take a look at the changes to kani-driver/src/cbmc_output_parser.rs?

@sanjit-bhat sanjit-bhat requested a review from celinval August 10, 2022 16:13
Copy link
Copy Markdown
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! We should create a section in our documentation about this feature and how to try it out. Thanks

Copy link
Copy Markdown
Contributor

@adpaco-aws adpaco-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've kept the changes to the parser to a minimum. Great work!

@sanjit-bhat sanjit-bhat merged commit 88aace3 into model-checking:main Aug 10, 2022
@sanjit-bhat sanjit-bhat deleted the execute-trace branch August 10, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

4 participants