Skip to content
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

Support concrete playback for arrays of length 65 or greater #3888

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion kani-driver/src/cbmc_output_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,20 @@ pub struct TraceItem {
/// Struct that represents a trace value.
///
/// Note: this struct can have a lot of different fields depending on the value type.
/// The fields included right now are relevant to primitive types.
/// The fields included right now are relevant to primitive types and arrays.
#[derive(Clone, Debug, Deserialize)]
pub struct TraceValue {
pub binary: Option<String>,
pub data: Option<TraceData>,
pub width: Option<u32>,
// Invariant: elements is Some iff binary, data, and width are None.
pub elements: Option<Vec<TraceArrayValue>>,
}

/// Struct that represents an element of an array in a trace.
#[derive(Clone, Debug, Deserialize)]
pub struct TraceArrayValue {
pub value: TraceValue,
}

/// Enum that represents a trace data item.
Expand Down
431 changes: 346 additions & 85 deletions kani-driver/src/concrete_playback/test_generator.rs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/script-based-pre/cargo_playback_array/config.yml
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: playback_target.sh
expected: playback_target.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Failed Checks: index out of bounds: the length is less than or equal to the given index

VERIFICATION:- FAILED

INFO: Now modifying the source code to include the concrete playback unit test:

running 1 test

index out of bounds: the len is 65 but the index is
27 changes: 27 additions & 0 deletions tests/script-based-pre/cargo_playback_array/playback_target.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

set +e

function check_playback {
local OUTPUT=output.log
cargo kani playback "${@}" >& $OUTPUT
# Sort output so we can rely on the order.
echo "$(grep "test verify::.* ok" $OUTPUT | sort)"
echo
echo "======= Raw Output ======="
cat $OUTPUT
echo "=========================="
echo
rm $OUTPUT
}

pushd sample_crate > /dev/null
cargo clean

cargo kani --concrete-playback inplace -Z concrete-playback
check_playback -Z concrete-playback

cargo clean
popd > /dev/null
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
[package]
name = "sample_crate"
version = "0.1.0"
edition = "2021"
doctest = false

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kani)'] }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Test that concrete playback generates concrete values for arrays over the length of 64
//! and that playback can run those tests and find the index out of bounds bug,
//! c.f. https://github.com/model-checking/kani/issues/3787

#[cfg(kani)]
mod verify {
#[kani::proof]
fn index_array_65() {
let arr: [u16; 65] = kani::any();
let idx: usize = kani::any();
arr[idx];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod verify {
}
}
#[test]
fn kani_concrete_playback_try_nz_u8_17663051139329126359() {
fn kani_concrete_playback_try_nz_u8_1592364891838466833() {
let concrete_vals: Vec<Vec<u8>> = vec![
// 0
vec![0],
Expand Down
Loading