Skip to content

Commit

Permalink
Integrate latest s2n-quic proofs in Kani CI (rust-lang#1862)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhassan-aws authored Nov 9, 2022
1 parent 328e49c commit 5e7095c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 46 deletions.
2 changes: 1 addition & 1 deletion scripts/kani-perf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for overlay_dir in ${PERF_DIR}/overlays/*/; do
done

suite="perf"
mode="cargo-kani"
mode="cargo-kani-test"
echo "Check compiletest suite=$suite mode=$mode"
cargo run -p compiletest -- --suite $suite --mode $mode
exit_code=$?
Expand Down
1 change: 1 addition & 0 deletions tests/perf/overlays/s2n-quic/quic/s2n-quic-core/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
successfully verified harnesses, 0 failures

This file was deleted.

2 changes: 1 addition & 1 deletion tests/perf/s2n-quic
Submodule s2n-quic updated 484 files
8 changes: 3 additions & 5 deletions tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Mode {
Kani,
KaniFixme,
CargoKani,
CargoKaniTest, // `cargo kani --tests`. This is temporary and should be removed when s2n-quic moves --tests to `Cargo.toml`.
Expected,
Stub,
}
Expand All @@ -29,6 +30,7 @@ impl FromStr for Mode {
"kani" => Ok(Kani),
"kani-fixme" => Ok(KaniFixme),
"cargo-kani" => Ok(CargoKani),
"cargo-kani-test" => Ok(CargoKaniTest),
"expected" => Ok(Expected),
"stub-tests" => Ok(Stub),
_ => Err(()),
Expand All @@ -42,6 +44,7 @@ impl fmt::Display for Mode {
Kani => "kani",
KaniFixme => "kani-fixme",
CargoKani => "cargo-kani",
CargoKaniTest => "cargo-kani-test",
Expected => "expected",
Stub => "stub-tests",
};
Expand Down Expand Up @@ -131,11 +134,6 @@ pub struct Config {

/// Whether we will run the tests or not.
pub dry_run: bool,

/// Allow us to run the regression with the mir linker enabled by default. For that, set
/// `RUSTFLAGS=--cfg=mir_linker` while compiling `compiletest`.
/// Remove this as part of <https://github.com/model-checking/kani/issues/1677>
pub mir_linker: bool,
}

#[derive(Debug, Clone)]
Expand Down
6 changes: 2 additions & 4 deletions tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
color,
edition: matches.opt_str("edition"),
force_rerun: matches.opt_present("force-rerun"),
mir_linker: cfg!(mir_linker),
dry_run: matches.opt_present("dry-run"),
timeout,
}
Expand All @@ -176,7 +175,6 @@ pub fn log_config(config: &Config) {
logv(c, format!("host: {}", config.host));
logv(c, format!("verbose: {}", config.verbose));
logv(c, format!("quiet: {}", config.quiet));
logv(c, format!("mir_linker: {}", config.mir_linker));
logv(c, format!("timeout: {:?}", config.timeout));
logv(
c,
Expand Down Expand Up @@ -329,7 +327,7 @@ fn collect_tests_from_dir(
tests: &mut Vec<test::TestDescAndFn>,
) -> io::Result<()> {
match config.mode {
Mode::CargoKani => {
Mode::CargoKani | Mode::CargoKaniTest => {
collect_expected_tests_from_dir(config, dir, relative_dir_path, inputs, tests)
}
_ => collect_rs_tests_from_dir(config, dir, relative_dir_path, inputs, tests),
Expand Down Expand Up @@ -357,7 +355,7 @@ fn collect_expected_tests_from_dir(
// output directory corresponding to each to avoid race conditions during
// the testing phase. We immediately return after adding the tests to avoid
// treating `*.rs` files as tests.
assert_eq!(config.mode, Mode::CargoKani);
assert!(config.mode == Mode::CargoKani || config.mode == Mode::CargoKaniTest);

let has_cargo_toml = dir.join("Cargo.toml").exists();
for file in fs::read_dir(dir)? {
Expand Down
21 changes: 8 additions & 13 deletions tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use crate::common::KaniFailStep;
use crate::common::{output_base_dir, output_base_name};
use crate::common::{CargoKani, Expected, Kani, KaniFixme, Stub};
use crate::common::{CargoKani, CargoKaniTest, Expected, Kani, KaniFixme, Stub};
use crate::common::{Config, TestPaths};
use crate::header::TestProps;
use crate::json;
Expand Down Expand Up @@ -63,7 +63,8 @@ impl<'test> TestCx<'test> {
match self.config.mode {
Kani => self.run_kani_test(),
KaniFixme => self.run_kani_test(),
CargoKani => self.run_cargo_kani_test(),
CargoKani => self.run_cargo_kani_test(false),
CargoKaniTest => self.run_cargo_kani_test(true),
Expected => self.run_expected_test(),
Stub => self.run_stub_test(),
}
Expand Down Expand Up @@ -291,9 +292,10 @@ impl<'test> TestCx<'test> {
}

/// Runs cargo-kani on the function specified by the stem of `self.testpaths.file`.
/// The `test` parameter controls whether to specify `--tests` to `cargo kani`.
/// An error message is printed to stdout if verification output does not
/// contain the expected output in `self.testpaths.file`.
fn run_cargo_kani_test(&self) {
fn run_cargo_kani_test(&self, test: bool) {
// We create our own command for the same reasons listed in `run_kani_test` method.
let mut cargo = Command::new("cargo");
// We run `cargo` on the directory where we found the `*.expected` file
Expand All @@ -305,15 +307,13 @@ impl<'test> TestCx<'test> {
.arg("--target-dir")
.arg(self.output_base_dir().join("target"))
.current_dir(&parent_dir);
if test {
cargo.arg("--tests");
}
if "expected" != self.testpaths.file.file_name().unwrap() {
cargo.args(["--harness", function_name]);
}

if self.config.mir_linker {
// Allow us to run the regression with the mir linker enabled by default.
cargo.arg("--enable-unstable").arg("--mir-linker");
}

let proc_res = self.compose_and_run(cargo);
let expected = fs::read_to_string(self.testpaths.file.clone()).unwrap();
self.verify_output(&proc_res, &expected);
Expand All @@ -334,11 +334,6 @@ impl<'test> TestCx<'test> {
kani.env("RUSTFLAGS", self.props.compile_flags.join(" "));
}

if self.config.mir_linker {
// Allow us to run the regression with the mir linker enabled by default.
kani.arg("--enable-unstable").arg("--mir-linker");
}

// Pass the test path along with Kani and CBMC flags parsed from comments at the top of the test file.
kani.arg(&self.testpaths.file).args(&self.props.kani_flags);

Expand Down

0 comments on commit 5e7095c

Please sign in to comment.