forked from model-checking/kani
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Property class comment expect fail (model-checking#925)
* Adding Property Class and Comments, through expect_fail tracer bullet
- Loading branch information
Showing
10 changed files
with
201 additions
and
3 deletions.
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
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
59 changes: 59 additions & 0 deletions
59
src/kani-compiler/src/codegen_cprover_gotoc/codegen/assert.rs
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,59 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! This file contains the code that acts as a wrapper to create the new assert and related statements | ||
use crate::codegen_cprover_gotoc::GotocCtx; | ||
use cbmc::goto_program::{Expr, Location, Stmt}; | ||
use std::str::FromStr; | ||
|
||
/// The Property Class enum stores all viable options for classifying asserts, cover assume and other related statements | ||
#[derive(Copy, Debug, Clone)] | ||
pub enum PropertyClass { | ||
ExpectFail, | ||
UnsupportedStructs, | ||
DefaultAssertion, | ||
} | ||
|
||
impl FromStr for PropertyClass { | ||
type Err = &'static str; | ||
|
||
fn from_str(input: &str) -> Result<PropertyClass, Self::Err> { | ||
match input { | ||
"expect_fail" => Ok(PropertyClass::ExpectFail), | ||
"unsupported_struct" => Ok(PropertyClass::UnsupportedStructs), | ||
"assertion" => Ok(PropertyClass::DefaultAssertion), | ||
_ => Err("No such property class"), | ||
} | ||
} | ||
} | ||
|
||
impl PropertyClass { | ||
pub fn as_str(&self) -> &str { | ||
match self { | ||
PropertyClass::ExpectFail => "expect_fail", | ||
PropertyClass::UnsupportedStructs => "unsupported_struct", | ||
PropertyClass::DefaultAssertion => "assertion", | ||
} | ||
} | ||
} | ||
|
||
impl<'tcx> GotocCtx<'tcx> { | ||
pub fn codegen_assert( | ||
&self, | ||
cond: Expr, | ||
property_class: PropertyClass, | ||
message: &str, | ||
loc: Location, | ||
) -> Stmt { | ||
assert!(cond.typ().is_bool()); | ||
|
||
let property_name = property_class.as_str(); | ||
|
||
// Create a Property Location Variant from any given Location type | ||
let property_location = | ||
Location::create_location_with_property(message, property_name, loc); | ||
|
||
Stmt::assert_statement(cond, property_name, message, property_location) | ||
} | ||
} |
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,3 @@ | ||
Check 1: main.expect_fail.1 | ||
Status: FAILURE | ||
Description: "EXPECTED FAIL: Blocked by assumption above." |
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,11 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// | ||
// Check if expect_fail uses new property class and description in it's check id | ||
|
||
#[kani::proof] | ||
fn main() { | ||
let i: i32 = kani::any(); | ||
kani::assume(i < 10); | ||
kani::expect_fail(i > 20, "Blocked by assumption above."); | ||
} |