Skip to content

Commit d621529

Browse files
bdalrhmadpaco-aws
authored andcommitted
Move 1 rust-test to compiletest. (rust-lang#163)
* Copy 1 rust-test to compiletest. * Add comments and address other concerns. * Modify comments. Co-authored-by: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com>
1 parent dc6d2c0 commit d621529

File tree

8 files changed

+51
-3
lines changed

8 files changed

+51
-3
lines changed

scripts/rmc-regression.sh

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ popd
3838

3939
# run-make tests
4040
./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/bootstrap.py

+1
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ def bootstrap(help_triggered):
11911191
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
11921192
env["BOOTSTRAP_PYTHON"] = sys.executable
11931193
env["BUILD_DIR"] = build.build_dir
1194+
env["RMC_DIR"] = os.path.join(build.rust_root, 'scripts')
11941195
env["RUSTC_BOOTSTRAP"] = '1'
11951196
if toml_path:
11961197
env["BOOTSTRAP_CONFIG"] = toml_path

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ impl<'a> Builder<'a> {
464464
test::Bootstrap,
465465
// Run run-make last, since these won't pass without make on Windows
466466
test::RunMake,
467+
test::CBMC,
467468
),
468469
Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
469470
Kind::Doc => describe!(

src/bootstrap/test.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,8 @@ host_test!(RunMakeFullDeps {
12001200

12011201
default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
12021202

1203+
default_test!(CBMC { path: "src/test/cbmc", mode: "rmc", suite: "cbmc" });
1204+
12031205
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
12041206
struct Compiletest {
12051207
compiler: Compiler,
@@ -1278,6 +1280,12 @@ note: if you're sure you want to do this, please open an issue as to why. In the
12781280
cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
12791281
cmd.arg("--rustc-path").arg(builder.rustc(compiler));
12801282

1283+
// Pass the path to the RMC script directory as an option to compiletest.
1284+
if let Ok(path) = env::var("RMC_DIR") {
1285+
cmd.arg("--rmc-dir-path")
1286+
.arg(Path::new(&path).components().collect::<PathBuf>().to_str().unwrap());
1287+
}
1288+
12811289
let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
12821290

12831291
// Avoid depending on rustdoc when we don't need it.

src/tools/compiletest/src/common.rs

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum Mode {
2323
JsDocTest,
2424
MirOpt,
2525
Assembly,
26+
RMC,
2627
}
2728

2829
impl Mode {
@@ -53,6 +54,7 @@ impl FromStr for Mode {
5354
"js-doc-test" => Ok(JsDocTest),
5455
"mir-opt" => Ok(MirOpt),
5556
"assembly" => Ok(Assembly),
57+
"rmc" => Ok(RMC),
5658
_ => Err(()),
5759
}
5860
}
@@ -74,6 +76,7 @@ impl fmt::Display for Mode {
7476
JsDocTest => "js-doc-test",
7577
MirOpt => "mir-opt",
7678
Assembly => "assembly",
79+
RMC => "rmc",
7780
};
7881
fmt::Display::fmt(s, f)
7982
}
@@ -192,6 +195,9 @@ pub struct Config {
192195
/// The rustc executable.
193196
pub rustc_path: PathBuf,
194197

198+
/// The path to the directory where the RMC executable is located
199+
pub rmc_dir_path: PathBuf,
200+
195201
/// The rustdoc executable.
196202
pub rustdoc_path: Option<PathBuf>,
197203

src/tools/compiletest/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
5858
opts.reqopt("", "compile-lib-path", "path to host shared libraries", "PATH")
5959
.reqopt("", "run-lib-path", "path to target shared libraries", "PATH")
6060
.reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH")
61+
.reqopt("", "rmc-dir-path", "path to directory where rmc is located", "PATH")
6162
.optopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH")
6263
.optopt("", "rust-demangler-path", "path to rust-demangler to use in tests", "PATH")
6364
.reqopt("", "lldb-python", "path to python to use for doc tests", "PATH")
@@ -75,7 +76,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
7576
"mode",
7677
"which sort of compile tests to run",
7778
"run-pass-valgrind | pretty | debug-info | codegen | rustdoc \
78-
| rustdoc-json | codegen-units | incremental | run-make | ui | js-doc-test | mir-opt | assembly",
79+
| rustdoc-json | codegen-units | incremental | run-make | ui | js-doc-test | mir-opt | assembly | rmc",
7980
)
8081
.reqopt(
8182
"",
@@ -217,6 +218,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
217218
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
218219
run_lib_path: make_absolute(opt_path(matches, "run-lib-path")),
219220
rustc_path: opt_path(matches, "rustc-path"),
221+
rmc_dir_path: opt_path(matches, "rmc-dir-path"),
220222
rustdoc_path: matches.opt_str("rustdoc-path").map(PathBuf::from),
221223
rust_demangler_path: matches.opt_str("rust-demangler-path").map(PathBuf::from),
222224
lldb_python: matches.opt_str("lldb-python").unwrap(),

src/tools/compiletest/src/runtest.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT};
44
use crate::common::{output_base_dir, output_base_name, output_testname_unique};
5-
use crate::common::{Assembly, Incremental, JsDocTest, MirOpt, RunMake, RustdocJson, Ui};
5+
use crate::common::{Assembly, Incremental, JsDocTest, MirOpt, RunMake, RustdocJson, Ui, RMC};
66
use crate::common::{Codegen, CodegenUnits, DebugInfo, Debugger, Rustdoc};
77
use crate::common::{CompareMode, FailMode, PassMode};
88
use crate::common::{Config, TestPaths};
@@ -351,6 +351,7 @@ impl<'test> TestCx<'test> {
351351
MirOpt => self.run_mir_opt_test(),
352352
Assembly => self.run_assembly_test(),
353353
JsDocTest => self.run_js_doc_test(),
354+
RMC => self.run_rmc_test(),
354355
}
355356
}
356357

@@ -2021,7 +2022,7 @@ impl<'test> TestCx<'test> {
20212022
rustc.arg(dir_opt);
20222023
}
20232024
RunPassValgrind | Pretty | DebugInfo | Codegen | Rustdoc | RustdocJson | RunMake
2024-
| CodegenUnits | JsDocTest | Assembly => {
2025+
| CodegenUnits | JsDocTest | Assembly | RMC => {
20252026
// do not use JSON output
20262027
}
20272028
}
@@ -2385,6 +2386,34 @@ impl<'test> TestCx<'test> {
23852386
}
23862387
}
23872388

2389+
/// Adds rmc scripts directory to the `PATH` environment variable.
2390+
fn add_rmc_dir_to_path(&self, rmc: &mut Command) {
2391+
// If the PATH enviornment variable is already defined,
2392+
if let Some((key, val)) = env::vars().find(|(key, _)| key == "PATH") {
2393+
// Add the RMC scripts directory to the PATH.
2394+
rmc.env(key, format!("{}:{}", self.config.rmc_dir_path.to_str().unwrap(), val));
2395+
} else {
2396+
// Otherwise, insert PATH as a new enviornment variable and set its value to the RMC scripts directory.
2397+
rmc.env(String::from("PATH"), String::from(self.config.rmc_dir_path.to_str().unwrap()));
2398+
}
2399+
}
2400+
2401+
/// Runs RMC on the test file specified by `self.testpaths.file`.
2402+
/// An error message is printed to stdout if verfication fails.
2403+
fn run_rmc_test(&self) {
2404+
// Other modes call self.compile_test(...). However, we cannot call it here for two reasons:
2405+
// 1. It calls rustc instead of RMC
2406+
// 2. It may pass some options that do not make sense for RMC
2407+
// So we create our own command to execute RMC and pass it to self.compose_and_run_compiler(...) directly.
2408+
let mut rmc = Command::new("rmc");
2409+
self.add_rmc_dir_to_path(&mut rmc);
2410+
rmc.arg(&self.testpaths.file);
2411+
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);
2414+
}
2415+
}
2416+
23882417
fn charset() -> &'static str {
23892418
// FreeBSD 10.1 defaults to GDB 6.1.1 which doesn't support "auto" charset
23902419
if cfg!(target_os = "freebsd") { "ISO-8859-1" } else { "UTF-8" }

0 commit comments

Comments
 (0)