Skip to content

Commit 7617391

Browse files
celinvaltedinski
authored andcommitted
Simplify how we invoke compiletest (rust-lang#784)
* Simplify how we invoke compiletest I removed stuff that wasn't needed and I have also added default values for stuff that doesn't really change for Kani. Now only --suite and --mode are requied. This will make it easier for us to manually invoke a single test suite.
1 parent ed27046 commit 7617391

File tree

6 files changed

+32
-76
lines changed

6 files changed

+32
-76
lines changed

scripts/kani-regression.sh

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ fi
88
set -o pipefail
99
set -o nounset
1010

11-
# Test for platform
12-
PLATFORM=$(uname -sp)
13-
if [[ $PLATFORM == "Linux x86_64" ]]
14-
then
15-
TARGET="x86_64-unknown-linux-gnu"
16-
elif [[ $PLATFORM == "Darwin i386" ]]
17-
then
18-
TARGET="x86_64-apple-darwin"
19-
fi
20-
2111
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
2212
export PATH=$SCRIPT_DIR:$PATH
2313
EXTRA_X_PY_BUILD_ARGS="${EXTRA_X_PY_BUILD_ARGS:-}"
@@ -55,15 +45,10 @@ for testp in "${TESTS[@]}"; do
5545
testl=($testp)
5646
suite=${testl[0]}
5747
mode=${testl[1]}
58-
echo "Check compiletest suite=$suite mode=$mode ($TARGET -> $TARGET)"
48+
echo "Check compiletest suite=$suite mode=$mode"
5949
# Note: `cargo-kani` tests fail if we do not add `$(pwd)` to `--build-base`
6050
# Tracking issue: https://github.com/model-checking/kani/issues/755
61-
cargo run -p compiletest -- --kani-dir-path scripts --src-base tests/$suite \
62-
--build-base $(pwd)/build/$TARGET/tests/$suite \
63-
--stage-id stage1-$TARGET \
64-
--suite $suite --mode $mode \
65-
--target $TARGET --host $TARGET \
66-
--quiet --channel dev
51+
cargo run -p compiletest --quiet -- --suite $suite --mode $mode --quiet
6752
done
6853

6954
# Check codegen for the standard library

tools/compiletest/src/common.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ pub struct Config {
8888
/// The directory where programs should be built
8989
pub build_base: PathBuf,
9090

91-
/// The name of the stage being built (stage1, etc)
92-
pub stage_id: String,
93-
9491
/// The test mode, e.g. ui or debuginfo.
9592
pub mode: Mode,
9693

@@ -135,9 +132,6 @@ pub struct Config {
135132
/// Whether to use colors in test.
136133
pub color: ColorConfig,
137134

138-
/// The current Rust channel
139-
pub channel: String,
140-
141135
/// The default Rust edition
142136
pub edition: Option<String>,
143137

tools/compiletest/src/header.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::fs::File;
77
use std::io::prelude::*;
88
use std::io::BufReader;
9-
use std::path::{Path, PathBuf};
9+
use std::path::Path;
1010

1111
use tracing::*;
1212

@@ -176,22 +176,6 @@ impl Config {
176176
}
177177
}
178178

179-
/// This function finds the root source of the repository by starting at the source base for
180-
/// compiletest. It will then visit its parent folder and check if we found the root by
181-
/// checking if it can find the compiletest `Cargo.toml` file in the path relative to the root.
182-
pub fn find_rust_src_root(&self) -> Option<PathBuf> {
183-
let mut path = self.src_base.clone();
184-
let path_postfix = Path::new("tools/compiletest/Cargo.toml");
185-
186-
while path.pop() {
187-
if path.join(&path_postfix).is_file() {
188-
return Some(path);
189-
}
190-
}
191-
192-
None
193-
}
194-
195179
fn parse_edition(&self, line: &str) -> Option<String> {
196180
self.parse_name_value_directive(line, "edition")
197181
}

tools/compiletest/src/main.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ extern crate test;
1212

1313
use crate::common::{output_base_dir, output_relative_path, PanicStrategy};
1414
use crate::common::{Config, Mode, TestPaths};
15-
use crate::util::logv;
15+
use crate::util::{logv, top_level};
1616
use getopts::Options;
1717
use std::env;
1818
use std::ffi::OsString;
1919
use std::fs;
20-
use std::io::{self, ErrorKind};
20+
use std::io::{self};
2121
use std::path::{Path, PathBuf};
2222
use std::time::SystemTime;
2323
use test::ColorConfig;
@@ -60,7 +60,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
6060
.optopt("", "llvm-filecheck", "path to LLVM's FileCheck binary", "DIR")
6161
.optopt("", "src-base", "directory to scan for test files", "PATH")
6262
.optopt("", "build-base", "directory to deposit test outputs", "PATH")
63-
.optopt("", "stage-id", "the target-stage identifier", "stageN-TARGET")
6463
.optopt(
6564
"",
6665
"mode",
@@ -137,7 +136,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
137136
)
138137
.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged")
139138
.optflag("h", "help", "show this message")
140-
.optopt("", "channel", "current Rust channel", "CHANNEL")
141139
.optopt("", "edition", "default Rust edition", "EDITION");
142140

143141
let (argv0, args_) = args.split_first().unwrap();
@@ -160,10 +158,16 @@ pub fn parse_config(args: Vec<String>) -> Config {
160158
panic!()
161159
}
162160

163-
fn opt_path(m: &getopts::Matches, nm: &str) -> PathBuf {
161+
fn opt_path(m: &getopts::Matches, nm: &str, default: &[&str]) -> PathBuf {
164162
match m.opt_str(nm) {
165163
Some(s) => PathBuf::from(&s),
166-
None => panic!("no option (=path) found for {}", nm),
164+
None => {
165+
let mut root_folder = top_level().expect(
166+
format!("Cannot find root directory. Please provide --{} option.", nm).as_str(),
167+
);
168+
default.into_iter().for_each(|f| root_folder.push(f));
169+
root_folder
170+
}
167171
}
168172
}
169173

@@ -175,17 +179,17 @@ pub fn parse_config(args: Vec<String>) -> Config {
175179
Some(x) => panic!("argument for --color must be auto, always, or never, but found `{}`", x),
176180
};
177181

178-
let src_base = opt_path(matches, "src-base");
182+
let suite = matches.opt_str("suite").unwrap();
183+
let src_base = opt_path(matches, "src-base", &["tests", suite.as_str()]);
179184
let run_ignored = matches.opt_present("ignored");
180185
let mode = matches.opt_str("mode").unwrap().parse().expect("invalid mode");
181186

182187
Config {
183-
kani_dir_path: opt_path(matches, "kani-dir-path"),
188+
kani_dir_path: opt_path(matches, "kani-dir-path", &["scripts"]),
184189
src_base,
185-
build_base: opt_path(matches, "build-base"),
186-
stage_id: matches.opt_str("stage-id").unwrap(),
190+
build_base: opt_path(matches, "build-base", &["build", "tests", suite.as_str()]),
187191
mode,
188-
suite: matches.opt_str("suite").unwrap(),
192+
suite,
189193
run_ignored,
190194
filters: matches.free.clone(),
191195
filter_exact: matches.opt_present("exact"),
@@ -202,7 +206,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
202206
verbose: matches.opt_present("verbose"),
203207
quiet: matches.opt_present("quiet"),
204208
color,
205-
channel: matches.opt_str("channel").unwrap(),
206209
edition: matches.opt_str("edition"),
207210

208211
force_rerun: matches.opt_present("force-rerun"),
@@ -214,7 +217,6 @@ pub fn log_config(config: &Config) {
214217
logv(c, "configuration:".to_string());
215218
logv(c, format!("src_base: {:?}", config.src_base.display()));
216219
logv(c, format!("build_base: {:?}", config.build_base.display()));
217-
logv(c, format!("stage_id: {}", config.stage_id));
218220
logv(c, format!("mode: {}", config.mode));
219221
logv(c, format!("run_ignored: {}", config.run_ignored));
220222
logv(c, format!("filters: {:?}", config.filters));
@@ -324,14 +326,14 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
324326

325327
pub fn make_tests(config: &Config, tests: &mut Vec<test::TestDescAndFn>) {
326328
debug!("making tests from {:?}", config.src_base.display());
327-
let inputs = common_inputs_stamp(config);
329+
let inputs = common_inputs_stamp();
328330
collect_tests_from_dir(config, &config.src_base, &PathBuf::new(), &inputs, tests)
329331
.unwrap_or_else(|_| panic!("Could not read tests from {}", config.src_base.display()));
330332
}
331333

332334
/// Returns a stamp constructed from input files common to all test cases.
333-
fn common_inputs_stamp(config: &Config) -> Stamp {
334-
let rust_src_dir = config.find_rust_src_root().expect("Could not find Rust source root");
335+
fn common_inputs_stamp() -> Stamp {
336+
let rust_src_dir = top_level().expect("Could not find Rust source root");
335337
let kani_bin_path = &rust_src_dir.join("target/debug/kani-compiler");
336338

337339
// Create stamp based on the `kani-compiler` binary
@@ -453,16 +455,6 @@ fn is_up_to_date(
453455
inputs: &Stamp,
454456
) -> bool {
455457
let stamp_name = stamp(config, testpaths, revision);
456-
// Check hash.
457-
let contents = match fs::read_to_string(&stamp_name) {
458-
Ok(f) => f,
459-
Err(ref e) if e.kind() == ErrorKind::InvalidData => panic!("Can't read stamp contents"),
460-
Err(_) => return false,
461-
};
462-
let expected_hash = runtest::compute_stamp_hash(config);
463-
if contents != expected_hash {
464-
return false;
465-
}
466458
// Check timestamps.
467459
let inputs = inputs.clone();
468460

tools/compiletest/src/runtest.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ use crate::read2::read2_abbreviated;
1515
use crate::util::logv;
1616
use regex::Regex;
1717

18-
use std::collections::hash_map::DefaultHasher;
1918
use std::env;
2019
use std::fs::{self, create_dir_all};
21-
use std::hash::{Hash, Hasher};
2220
use std::path::PathBuf;
2321
use std::process::{Command, ExitStatus, Output, Stdio};
2422
use std::str;
@@ -49,13 +47,6 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) {
4947
cx.create_stamp();
5048
}
5149

52-
pub fn compute_stamp_hash(config: &Config) -> String {
53-
let mut hash = DefaultHasher::new();
54-
config.stage_id.hash(&mut hash);
55-
56-
format!("{:x}", hash.finish())
57-
}
58-
5950
#[derive(Copy, Clone)]
6051
struct TestCx<'test> {
6152
config: &'test Config,
@@ -411,7 +402,7 @@ impl<'test> TestCx<'test> {
411402

412403
fn create_stamp(&self) {
413404
let stamp = crate::stamp(&self.config, self.testpaths, self.revision);
414-
fs::write(&stamp, compute_stamp_hash(&self.config)).unwrap();
405+
fs::write(&stamp, "we only support one configuration").unwrap();
415406
}
416407
}
417408

tools/compiletest/src/util.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::common::Config;
77
use std::ffi::OsStr;
88
use std::path::PathBuf;
99

10+
use std::process::Command;
1011
use tracing::*;
1112

1213
pub fn logv(config: &Config, s: String) {
@@ -35,3 +36,12 @@ impl PathBufExt for PathBuf {
3536
}
3637
}
3738
}
39+
40+
pub(crate) fn top_level() -> Option<PathBuf> {
41+
match Command::new("git").arg("rev-parse").arg("--show-toplevel").output() {
42+
Ok(out) if out.status.success() => {
43+
Some(PathBuf::from(String::from_utf8(out.stdout).unwrap().trim()))
44+
}
45+
_ => None,
46+
}
47+
}

0 commit comments

Comments
 (0)