Skip to content

Commit 3d9bfe0

Browse files
authored
Improve assess and regression time (rust-lang#2478)
The per-reachability analysis can have a overhead on the compilation time when assessing a project that has lots of tests. Disable it for now when analyzing tests. Despite that improvement, assessing the firecracker still takes a long time, even with --only-codegen, due to the number of calls done to goto-cc. Thus, don't use assess here.
1 parent c6e9169 commit 3d9bfe0

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,26 @@ impl CodegenBackend for GotocCodegenBackend {
256256
false
257257
}
258258
});
259+
// Codegen still takes a considerable amount, thus, we only generate one model for
260+
// all harnesses and copy them for each harness.
261+
// We will be able to remove this once we optimize all calls to CBMC utilities.
262+
// https://github.com/model-checking/kani/issues/1971
263+
let model_path = base_filename.with_extension(ArtifactType::SymTabGoto);
264+
let (gcx, items) =
265+
self.codegen_items(tcx, &harnesses, &model_path, &results.machine_model);
266+
results.extend(gcx, items, None);
267+
259268
for (test_fn, test_desc) in harnesses.iter().zip(descriptions.iter()) {
260269
let instance =
261270
if let MonoItem::Fn(instance) = test_fn { instance } else { continue };
262271
let metadata = gen_test_metadata(tcx, *test_desc, *instance, &base_filename);
263-
let model_path = &metadata.goto_file.as_ref().unwrap();
264-
let (gcx, items) =
265-
self.codegen_items(tcx, &[*test_fn], model_path, &results.machine_model);
266-
results.extend(gcx, items, Some(metadata));
272+
let test_model_path = &metadata.goto_file.as_ref().unwrap();
273+
std::fs::copy(&model_path, &test_model_path).expect(&format!(
274+
"Failed to copy {} to {}",
275+
model_path.display(),
276+
test_model_path.display()
277+
));
278+
results.harnesses.push(metadata);
267279
}
268280
}
269281
ReachabilityType::None => {}

scripts/codegen-firecracker.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ set -eu
66

77
# Test for platform
88
PLATFORM=$(uname -sp)
9-
if [[ $PLATFORM != "Linux x86_64" ]]; then
9+
10+
if [[ $PLATFORM == "Linux x86_64" ]]
11+
then
12+
TARGET="x86_64-unknown-linux-gnu"
13+
# 'env' necessary to avoid bash built-in 'time'
14+
WRAPPER="env time -v"
15+
else
1016
echo
1117
echo "Firecracker codegen regression only works on Linux x86 platform, skipping..."
1218
echo
@@ -23,11 +29,27 @@ echo
2329

2430
# At the moment, we only test codegen for the virtio module
2531
cd $KANI_DIR/firecracker/src/devices/src/virtio/
32+
33+
# Clean first
34+
cargo clean
35+
2636
export KANI_LOG=error
2737
export RUSTC_LOG=error
2838
export RUST_BACKTRACE=1
29-
# Use cargo assess since this is now our default way of assessing Kani suitability to verify a crate.
30-
cargo kani --enable-unstable --only-codegen assess
39+
40+
# Compile rust to iRep
41+
RUST_FLAGS=(
42+
"--kani-compiler"
43+
"-Cpanic=abort"
44+
"-Zalways-encode-mir"
45+
"-Cllvm-args=--goto-c"
46+
"-Cllvm-args=--ignore-global-asm"
47+
"-Cllvm-args=--reachability=pub_fns"
48+
"--sysroot=${KANI_DIR}/target/kani"
49+
)
50+
export RUSTFLAGS="${RUST_FLAGS[@]}"
51+
export RUSTC="$KANI_DIR/target/kani/bin/kani-compiler"
52+
$WRAPPER cargo build --verbose --lib --target $TARGET
3153

3254
echo
3355
echo "Finished Firecracker codegen regression successfully..."

0 commit comments

Comments
 (0)