Skip to content

Commit 0a9f612

Browse files
bdalrhmtedinski
authored andcommitted
Move all tests under rust-tests to compiletest. (rust-lang#168)
* Move all tests under rust-tests to compiletest. * Remove execute permissions for a regression. * Address concerns.
1 parent b6349f5 commit 0a9f612

File tree

213 files changed

+99
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+99
-68
lines changed

rust-tests/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

rust-tests/run.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

scripts/rmc-regression.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,14 @@ check-cbmc-version.py --major 5 --minor 30
2323
# Standalone rmc tests
2424
pushd $RUST_DIR
2525
./x.py build -i --stage 1 library/std ${EXTRA_X_PY_BUILD_ARGS}
26-
cd rust-tests
27-
for TEST_DIR in cbmc-reg smack-regressions prusti-regressions; do
28-
./run.sh $TEST_DIR
29-
done
30-
./run.sh firecracker-like 2
26+
./x.py test -i --stage 1 cbmc firecracker prusti smack
3127

3228
# Standalone cargo-rmc tests
33-
cd ../cargo-rmc-tests
29+
cd cargo-rmc-tests
3430
for DIR in */; do
3531
./run.py $DIR
3632
done
3733
popd
3834

3935
# run-make tests
4036
./x.py test -i --stage 1 src/test/run-make --test-args gotoc
41-
./x.py test -i --stage 1 src/test/cbmc

src/bootstrap/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,14 @@ impl<'a> Builder<'a> {
462462
test::HtmlCheck,
463463
// Run bootstrap close to the end as it's unlikely to fail
464464
test::Bootstrap,
465+
// RMC regression tests
466+
test::CBMC,
467+
test::Firecracker,
468+
test::Prusti,
469+
test::Serial,
470+
test::SMACK,
465471
// Run run-make last, since these won't pass without make on Windows
466472
test::RunMake,
467-
test::CBMC,
468473
),
469474
Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
470475
Kind::Doc => describe!(

src/bootstrap/test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,14 @@ default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "as
12021202

12031203
default_test!(CBMC { path: "src/test/cbmc", mode: "rmc", suite: "cbmc" });
12041204

1205+
default_test!(Firecracker { path: "src/test/firecracker", mode: "rmc", suite: "firecracker" });
1206+
1207+
default_test!(Prusti { path: "src/test/prusti", mode: "rmc", suite: "prusti" });
1208+
1209+
default_test!(Serial { path: "src/test/serial", mode: "rmc", suite: "serial" });
1210+
1211+
default_test!(SMACK { path: "src/test/smack", mode: "rmc", suite: "smack" });
1212+
12051213
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
12061214
struct Compiletest {
12071215
compiler: Compiler,
File renamed without changes.

src/test/cbmc/Bool-BoolOperators/main.rs

100755100644
File mode changed.
File renamed without changes.
File renamed without changes.
File renamed without changes.

rust-tests/cbmc-reg/Count/Unstable/Ctlz/bounds_fail.rs renamed to src/test/cbmc/Count/Unstable/Ctlz/bounds_fail.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// cbmc-flags: --bounds-check
5+
36
#![feature(core_intrinsics)]
47
use std::intrinsics::ctlz_nonzero;
58

6-
/// rmc bounds_fail.rs -- --bounds-check
79
fn main() {
810
let uv8: u8 = 0;
911
let uv16: u16 = 0;

rust-tests/cbmc-reg/Count/Unstable/Cttz/bounds_fail.rs renamed to src/test/cbmc/Count/Unstable/Cttz/bounds_fail.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// cbmc-flags: --bounds-check
5+
36
#![feature(core_intrinsics)]
47
use std::intrinsics::cttz_nonzero;
58

6-
/// rmc bounds_fail.rs -- --bounds-check
79
fn main() {
810
let uv8: u8 = 0;
911
let uv16: u16 = 0;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

rust-tests/cbmc-reg/FunctionCall_Ret-Param/main.rs renamed to src/test/cbmc/FunctionCall_Ret-Param/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// cbmc-flags: --unwind 10
5+
36
fn __nondet<T>() -> T {
47
unimplemented!()
58
}

rust-tests/cbmc-reg/LoopLoop_NonReturning/main.rs renamed to src/test/cbmc/LoopLoop_NonReturning/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// cbmc-flags: --unwind 10 --unwinding-assertions
5+
36
fn __nondet<T>() -> T {
47
unimplemented!()
58
}

rust-tests/cbmc-reg/LoopWhile_NonReturning/main.rs renamed to src/test/cbmc/LoopWhile_NonReturning/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// cbmc-flags: --unwind 11 --unwinding-assertions
5+
36
fn __nondet<T>() -> T {
47
unimplemented!()
58
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

rust-tests/cbmc-reg/Slice/main.rs renamed to src/test/cbmc/Slice/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3-
/// rmc main.rs -- --unwind 6 --unwinding-assertions
3+
4+
// cbmc-flags: --unwind 6 --unwinding-assertions
5+
46
fn main() {
57
let name: &str = "hello";
68
assert!(name == "hello");
File renamed without changes.
File renamed without changes.
File renamed without changes.

rust-tests/cbmc-reg/SwitchInt/main.rs renamed to src/test/cbmc/SwitchInt/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// cbmc-flags: --unwind 2 --unwinding-assertions
5+
36
fn doswitch_int() -> i32 {
47
for i in [99].iter() {
58
if *i == 99 {
File renamed without changes.

rust-tests/cbmc-reg/Whitespace/main.rs renamed to src/test/cbmc/Whitespace/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// cbmc-flags: --unwind 2 --unwinding-assertions
5+
36
fn main() {
47
let mut iter = "A few words".split_whitespace();
58
match iter.next() {

rust-tests/prusti-regressions/Binary_search_fail.rs renamed to src/test/prusti/Binary_search_fail.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// cbmc-flags: --unwind 4 --unwinding-assertions
5+
36
use std::cmp::Ordering::*;
47

58
/// this is interestingly a wrong implementation at
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

rust-tests/smack-regressions/loops/gauss_sum_nondet.rs renamed to src/test/smack/loops/gauss_sum_nondet.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// @flag --no-memory-splitting --unroll=4
44
// @expect verified
55

6+
// cbmc-flags: --unwind 5 --unwinding-assertions
7+
68
fn __nondet<T>() -> T {
79
unimplemented!()
810
}

rust-tests/smack-regressions/loops/gauss_sum_nondet_fail.rs renamed to src/test/smack/loops/gauss_sum_nondet_fail.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// @flag --no-memory-splitting --unroll=10
44
// @expect error
55

6+
// cbmc-flags: --unwind 5 --unwinding-assertions
7+
68
fn __nondet<T>() -> T {
79
unimplemented!()
810
}

rust-tests/smack-regressions/loops/iterator.rs renamed to src/test/smack/loops/iterator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// @flag --no-memory-splitting --unroll=4
44
// @expect verified
55

6+
// cbmc-flags: --unwind 5 --unwinding-assertions
7+
68
fn fac(n: u64) -> u64 {
79
match n {
810
0 => 1,

rust-tests/smack-regressions/loops/iterator_fail.rs renamed to src/test/smack/loops/iterator_fail.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// @flag --no-memory-splitting --unroll=10
44
// @expect error
55

6+
// cbmc-flags: --unwind 5 --unwinding-assertions
7+
68
fn fac(n: u64) -> u64 {
79
match n {
810
0 => 1,

src/tools/compiletest/src/header.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub struct TestProps {
5959
pub error_patterns: Vec<String>,
6060
// Extra flags to pass to the compiler
6161
pub compile_flags: Vec<String>,
62+
// Extra flags to pass to RMC
63+
pub rmc_flags: Vec<String>,
64+
// Extra flags to pass to CBMC
65+
pub cbmc_flags: Vec<String>,
6266
// Extra flags to pass when the compiled code is run (such as --bench)
6367
pub run_flags: Option<String>,
6468
// If present, the name of a file that this test should match when
@@ -142,6 +146,8 @@ impl TestProps {
142146
TestProps {
143147
error_patterns: vec![],
144148
compile_flags: vec![],
149+
rmc_flags: vec![],
150+
cbmc_flags: vec![],
145151
run_flags: None,
146152
pp_exact: None,
147153
aux_builds: vec![],
@@ -222,6 +228,14 @@ impl TestProps {
222228
self.compile_flags.extend(flags.split_whitespace().map(|s| s.to_owned()));
223229
}
224230

231+
if let Some(flags) = config.parse_rmc_flags(ln) {
232+
self.rmc_flags.extend(flags.split_whitespace().map(|s| s.to_owned()));
233+
}
234+
235+
if let Some(flags) = config.parse_cbmc_flags(ln) {
236+
self.cbmc_flags.extend(flags.split_whitespace().map(|s| s.to_owned()));
237+
}
238+
225239
if let Some(edition) = config.parse_edition(ln) {
226240
self.compile_flags.push(format!("--edition={}", edition));
227241
if edition == "2021" {
@@ -512,6 +526,16 @@ impl Config {
512526
self.parse_name_value_directive(line, "compile-flags")
513527
}
514528

529+
/// Parses strings of the form `// rmc-flags: ...` and returns the options listed after `rmc-flags:`
530+
fn parse_rmc_flags(&self, line: &str) -> Option<String> {
531+
self.parse_name_value_directive(line, "rmc-flags")
532+
}
533+
534+
/// Parses strings of the form `// cbmc-flags: ...` and returns the options listed after `cbmc-flags:`
535+
fn parse_cbmc_flags(&self, line: &str) -> Option<String> {
536+
self.parse_name_value_directive(line, "cbmc-flags")
537+
}
538+
515539
fn parse_and_update_revisions(&self, line: &str, existing: &mut Vec<String>) {
516540
if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
517541
let mut duplicates: HashSet<_> = existing.iter().cloned().collect();
@@ -852,6 +876,13 @@ pub fn make_test_description<R: Read>(
852876
.join("gcc-ld")
853877
.join(if config.host.contains("windows") { "ld.exe" } else { "ld" })
854878
.exists();
879+
880+
if config.mode == Mode::RMC {
881+
// If the path to the test contains "fixme" or "ignore", skip it.
882+
let file_path = path.to_str().unwrap();
883+
ignore |= file_path.contains("fixme") || file_path.contains("ignore");
884+
}
885+
855886
iter_header(path, src, &mut |revision, ln| {
856887
if revision.is_some() && revision != cfg {
857888
return;

src/tools/compiletest/src/runtest.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ impl<'test> TestCx<'test> {
396396
panic!("revision name must begin with rpass, rfail, or cfail");
397397
}
398398
}
399+
RMC => !self.testpaths.file.to_str().unwrap().contains("fail"),
399400
mode => panic!("unimplemented for mode {:?}", mode),
400401
}
401402
}
@@ -2398,19 +2399,30 @@ impl<'test> TestCx<'test> {
23982399
}
23992400
}
24002401

2401-
/// Runs RMC on the test file specified by `self.testpaths.file`.
2402-
/// An error message is printed to stdout if verfication fails.
2402+
/// Runs RMC on the test file specified by `self.testpaths.file`. An error
2403+
/// message is printed to stdout if verification result is not expected.
24032404
fn run_rmc_test(&self) {
24042405
// Other modes call self.compile_test(...). However, we cannot call it here for two reasons:
24052406
// 1. It calls rustc instead of RMC
24062407
// 2. It may pass some options that do not make sense for RMC
24072408
// So we create our own command to execute RMC and pass it to self.compose_and_run_compiler(...) directly.
24082409
let mut rmc = Command::new("rmc");
2410+
// Pass the test path along with RMC and CBMC flags parsed from comments at the top of the test file.
2411+
rmc.args(&self.props.rmc_flags)
2412+
.arg(&self.testpaths.file)
2413+
.arg("--")
2414+
.args(&self.props.cbmc_flags);
24092415
self.add_rmc_dir_to_path(&mut rmc);
2410-
rmc.arg(&self.testpaths.file);
24112416
let proc_res = self.compose_and_run_compiler(rmc, None);
2412-
if !proc_res.status.success() {
2413-
self.fatal_proc_rec("verification failed!", &proc_res);
2417+
// Print an error if the verification result is not expected.
2418+
if self.should_compile_successfully(self.pass_mode()) {
2419+
if !proc_res.status.success() {
2420+
self.fatal_proc_rec("test failed: expected success, got failure", &proc_res);
2421+
}
2422+
} else {
2423+
if proc_res.status.success() {
2424+
self.fatal_proc_rec("test failed: expected failure, got success", &proc_res);
2425+
}
24142426
}
24152427
}
24162428

0 commit comments

Comments
 (0)