-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A few output improvements #976
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7bdbba2
Disable reach assertions in visualize mode
celinval 5c3a8b4
Make file location relative to current dir.
celinval 9ab8d90
Add test for this.
celinval 157695a
Fix regression
celinval 25bca14
Remove check if file exists and added unit tests
celinval 8202aba
Update expected file
celinval 0a00fe2
Making one test more reliable
celinval e6c52de
Rename test script
celinval 78b77fd
Merge branch 'main' into output-improvements
celinval File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
import unittest | ||
import os | ||
import tempfile | ||
from cbmc_json_parser import SourceLocation | ||
|
||
|
||
def source_json(filename=None, function=None, line=None, column=None): | ||
result = dict() | ||
if filename: | ||
result["file"] = filename | ||
if function: | ||
result["function"] = function | ||
if column: | ||
result["column"] = column | ||
if line: | ||
result["line"] = line | ||
return result | ||
|
||
|
||
class SourceLocationTest(unittest.TestCase): | ||
""" Unit tests for SourceLocation """ | ||
|
||
def test_source_location_valid_path(self): | ||
"""Path returned by filepath() works for valid paths | ||
|
||
Note: Check is loose because I couldn't find a reliable way to control a real path location. | ||
""" | ||
path = tempfile.gettempdir() | ||
json = source_json(path) | ||
src_loc = SourceLocation(json) | ||
possible_output = {path, os.path.relpath(path), os.path.relpath(path, os.path.expanduser("~"))} | ||
self.assertIn(src_loc.filepath(), possible_output) | ||
|
||
def test_source_location_invalid_path(self): | ||
"""Path returned by filepath() returns the input path if it doesn't exist""" | ||
path = "/rust/made/up/path/lib.rs" | ||
json = source_json(path) | ||
src_loc = SourceLocation(json) | ||
self.assertEqual(src_loc.filepath(), path) | ||
|
||
def test_source_location_relative_path(self): | ||
"""Path returned by filepath() is relative if the input is also relative""" | ||
relpath = "dummy/target.rs" | ||
json = source_json(relpath) | ||
src_loc = SourceLocation(json) | ||
self.assertEqual(src_loc.filepath(), relpath) | ||
|
||
def test_source_location_absolute_cwd_path(self): | ||
"""Path returned by filepath() is relative to current directory | ||
|
||
Note that the file may not exist that this should still hold. | ||
""" | ||
relpath = "dummy/target.rs" | ||
path = os.path.join(os.getcwd(), relpath) | ||
self.assertNotEqual(relpath, path) | ||
|
||
json = source_json(path) | ||
src_loc = SourceLocation(json) | ||
self.assertEqual(src_loc.filepath(), relpath) | ||
|
||
def test_source_location_absolute_user_path(self): | ||
"""Path returned by filepath() is relative to current directory | ||
|
||
Note that the file may not exist that this should still hold. | ||
""" | ||
relpath = "~/dummy/target.rs" | ||
path = os.path.expanduser(relpath) | ||
self.assertNotEqual(relpath, path) | ||
|
||
json = source_json(path) | ||
src_loc = SourceLocation(json) | ||
self.assertEqual(src_loc.filepath(), relpath) | ||
|
||
def test_source_location_relative_user_path(self): | ||
"""Path returned by filepath() is relative to current directory | ||
|
||
Note that the file may not exist that this should still hold. | ||
""" | ||
relpath = "~/dummy/target.rs" | ||
json = source_json(relpath) | ||
src_loc = SourceLocation(json) | ||
self.assertEqual(src_loc.filepath(), relpath) | ||
|
||
def test_source_location_with_no_path(self): | ||
"""Function filepath() is None if no file is given in the input""" | ||
json = source_json(function="main") | ||
src_loc = SourceLocation(json) | ||
self.assertIsNone(src_loc.filepath()) | ||
|
||
def test_source_location_output_format(self): | ||
"""Check that output includes all the information provided""" | ||
path = "/rust/made/up/path/lib.rs" | ||
function = "harness" | ||
line = 10 | ||
column = 8 | ||
json = source_json(path, function, line, column) | ||
src_loc = str(SourceLocation(json)) | ||
self.assertIn(path, src_loc) | ||
self.assertIn(f"{path}:{line}:{column}", src_loc) | ||
self.assertIn(function, src_loc) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,11 @@ impl KaniArgs { | |
self.restrict_vtable | ||
// if we flip the default, this will become: !self.no_restrict_vtable | ||
} | ||
|
||
pub fn assertion_reach_checks(&self) -> bool { | ||
// Turn them off when visualizing an error trace. | ||
!self.no_assertion_reach_checks && !self.visualize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I've been meaning to fix that. |
||
} | ||
} | ||
|
||
arg_enum! { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module/mod.rs:10:5 in function module::not_empty | ||
main.rs:13:5 in function same_file | ||
/toolchains/ | ||
alloc/src/vec/mod.rs:2821:81 in function <std::vec::Vec<T, A> as std::ops::Drop>::drop | ||
|
||
VERIFICATION:- SUCCESSFUL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// | ||
// kani-flags: --function harness | ||
// | ||
//! This test is to check how file names are displayed in the Kani output. | ||
|
||
mod module; | ||
|
||
use module::not_empty; | ||
|
||
fn same_file(cond: bool) { | ||
assert!(cond); | ||
} | ||
|
||
#[kani::proof] | ||
fn harness() { | ||
let x = true; | ||
same_file(x); | ||
|
||
let v = vec![1]; | ||
not_empty(&v); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
VERIFICATION:- SUCCESSFUL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// kani-flags: --function empty_harness | ||
|
||
// This file is to be used as a module on a different test, but the compiletest will still run | ||
// kani on this file. Use an empty harness instead. | ||
|
||
pub fn not_empty(v: &[i32]) { | ||
assert!(!v.is_empty()); | ||
} | ||
|
||
#[kani::proof] | ||
fn empty_harness() { | ||
// No-op to overcome compile test. | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much needed! Thanks for adding this unit test module!
Nit: should we renamed it to
test_cbmc_parser.py
to make it more clear?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure