-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Boogie Backend] Add two Boogie tests (#2914)
Add a new script-based suite for running Boogie tests. Since we don't have Boogie integrated in our CI or the Kani driver, this suite just checks that the generated Boogie file contains certain lines that we're expecting. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
- Loading branch information
1 parent
62517ed
commit 3c4289c
Showing
10 changed files
with
146 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
script: gen_boogie_and_dump.sh | ||
expected: expected |
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 @@ | ||
procedure | ||
var x: bv32; | ||
var y: bv32; | ||
x := 1bv32; | ||
y := x; | ||
x := 2bv32; | ||
assert |
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,13 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
set +e | ||
|
||
# Delete any leftover Boogie files | ||
rm *.bpl | ||
|
||
echo "[TEST] Run verification..." | ||
kani -Zboogie test.rs | ||
|
||
cat *.bpl |
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,38 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! A simple test that checks that assignment statements and asserts are | ||
//! translated to Boogie correctly. | ||
//! | ||
//! The `expected` file checks some elements of the expected output Boogie. | ||
//! | ||
//! This is a possible Boogie output (which may change with MIR changes): | ||
//! ``` | ||
//! // Procedures: | ||
//! procedure _RNvCshNorBqfmMTU_4test19check_assign_assert() | ||
//! { | ||
//! var x: bv32; | ||
//! var y: bv32; | ||
//! var _4: bool; | ||
//! var _5: bv32; | ||
//! var _7: bool; | ||
//! x := 1bv32; | ||
//! y := x; | ||
//! x := 2bv32; | ||
//! _5 := x; | ||
//! _4 := (_5 == 2bv32); | ||
//! assert _4; | ||
//! _7 := (y == 1bv32); | ||
//! assert _7; | ||
//! return; | ||
//! } | ||
//! ``` | ||
|
||
#[kani::proof] | ||
fn check_assign_assert() { | ||
let mut x = 1; | ||
let y = x; | ||
x = 2; | ||
kani::assert(x == 2, ""); | ||
kani::assert(y == 1, ""); | ||
} |
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,4 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
script: gen_boogie_and_dump.sh | ||
expected: expected |
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,19 @@ | ||
function {:bvbuiltin "bvslt"} $BvSignedLessThan<T>(lhs: T, rhs: T) returns (bool); | ||
|
||
function {:bvbuiltin "bvsgt"} $BvSignedGreaterThan<T>(lhs: T, rhs: T) returns (bool); | ||
|
||
function {:bvbuiltin "bvor"} $BvOr<T>(lhs: T, rhs: T) returns (T); | ||
|
||
procedure | ||
var _1: bv32; | ||
var _2: bv32; | ||
var _4: bool; | ||
var z: bv32; | ||
var _7: bool; | ||
_1 := 1bv32; | ||
_2 := 2bv32; | ||
_4 := $BvSignedGreaterThan(_2, _1); | ||
assert _4; | ||
z := $BvOr(_1, _2); | ||
_7 := $BvSignedLessThan(_1, z); | ||
assert _7; |
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,13 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
set +e | ||
|
||
# Delete any leftover Boogie files | ||
rm *.bpl | ||
|
||
echo "[TEST] Run verification..." | ||
kani -Zboogie test.rs | ||
|
||
cat *.bpl |
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,44 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! A simple test that checks that binary operations are translated to a | ||
//! function call to an SMT bv operator | ||
//! | ||
//! The `expected` file checks some elements of the expected output Boogie. | ||
//! | ||
//! This is a possible Boogie output (which may change with MIR changes): | ||
//! ``` | ||
//! function {:bvbuiltin "bvslt"} $BvSignedLessThan<T>(lhs: T, rhs: T) returns (bool); | ||
//! | ||
//! function {:bvbuiltin "bvsgt"} $BvSignedGreaterThan<T>(lhs: T, rhs: T) returns (bool); | ||
//! | ||
//! function {:bvbuiltin "bvor"} $BvOr<T>(lhs: T, rhs: T) returns (T); | ||
//! | ||
//! // Procedures: | ||
//! procedure _RNvCshNorBqfmMTU_4test14check_binop_gt() | ||
//! { | ||
//! var _1: bv32; | ||
//! var _2: bv32; | ||
//! var _4: bool; | ||
//! var z: bv32; | ||
//! var _7: bool; | ||
//! _1 := 1bv32; | ||
//! _2 := 2bv32; | ||
//! _4 := $BvSignedGreaterThan(_2, _1); | ||
//! assert _4; | ||
//! z := $BvAnd(_1, _2); | ||
//! _7 := $BvSignedLessThan(_1, z); | ||
//! assert _7; | ||
//! return; | ||
//! } | ||
//! | ||
//! ```` | ||
|
||
#[kani::proof] | ||
fn check_binop_gt() { | ||
let x = 1; | ||
let y = 2; | ||
kani::assert(y > x, ""); | ||
let z = x | y; | ||
kani::assert(x < z, ""); | ||
} |