Skip to content

Commit 81fbf89

Browse files
committed
Parallel driver script and optimizations to reduce system time
1 parent 2be7c5a commit 81fbf89

File tree

13 files changed

+82
-63
lines changed

13 files changed

+82
-63
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.toml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
parallel_difftest = true
12
bb_max_len = 32
23
max_switch_targets = 8
34
max_bb_count = 50

config/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub fn load(path: impl AsRef<Path>) -> Config {
99

1010
#[derive(Deserialize, Clone)]
1111
pub struct Config {
12+
pub parallel_difftest: bool,
1213
#[serde(flatten)]
1314
pub generation: GenerationConfig,
1415
#[serde(flatten)]

difftest/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ colored = "2.0.0"
1212
env_logger = "0.11.3"
1313
log = "0.4.17"
1414
rayon = "1.7.0"
15-
serde = { version = "1", features = ["derive"] }
1615
tempfile = "3.3.0"

difftest/src/backends.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,14 @@ impl LLVM {
174174

175175
impl Backend for LLVM {
176176
fn compile(&self, source: &Source, target: &Path) -> ProcessOutput {
177-
let mut command = Command::new("rustc");
178-
179-
command.arg(format!("+{}", self.toolchain));
177+
let mut command = if let Ok(path) = std::env::var("RUSTLANTIS_RUSTC_PATH") {
178+
debug!("Compiling with rustc from RUSTLANTIS_RUSTC_PATH");
179+
Command::new(path)
180+
} else {
181+
let mut command = Command::new("rustc");
182+
command.arg(format!("+{}", self.toolchain));
183+
command
184+
};
180185

181186
command
182187
.args(["-o", target.to_str().unwrap()])
@@ -307,13 +312,18 @@ impl Miri {
307312

308313
impl Backend for Miri {
309314
fn execute(&self, source: &Source, _: &Path) -> ExecResult {
310-
debug!("Executing with Miri {source}");
311-
let mut command = match &self.miri {
312-
BackendSource::Path(binary) => Command::new(binary),
313-
BackendSource::Rustup(toolchain) => {
314-
let mut cmd = Command::new("rustup");
315-
cmd.args(["run", &toolchain, "miri"]);
316-
cmd
315+
let mut command = if let Ok(path) = std::env::var("RUSTLANTIS_MIRI_PATH") {
316+
debug!("Executing with Miri from RUSTLANTIS_MIRI_PATH");
317+
Command::new(path)
318+
} else {
319+
debug!("Executing with Miri {source}");
320+
match &self.miri {
321+
BackendSource::Path(binary) => Command::new(binary),
322+
BackendSource::Rustup(toolchain) => {
323+
let mut cmd = Command::new("rustup");
324+
cmd.args(["run", &toolchain, "miri"]);
325+
cmd
326+
}
317327
}
318328
};
319329
command.args(self.flags.clone());

difftest/src/lib.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,28 @@ impl fmt::Display for ExecResults {
155155
pub fn run_diff_test<'a>(
156156
source: &Source,
157157
backends: HashMap<String, Box<dyn Backend + 'a>>,
158+
parallel: bool,
158159
) -> ExecResults {
159160
let target_dir = tempfile::tempdir().unwrap();
160-
let exec_results: HashMap<String, ExecResult> = backends
161-
.into_par_iter()
162-
.map(|(name, b)| {
163-
let target_path = target_dir.path().join(&name);
164-
let result = if log_enabled!(log::Level::Debug) {
165-
let time = Instant::now();
166-
let result = b.execute(source, &target_path);
167-
let dur = time.elapsed();
168-
debug!("{name} took {}s", dur.as_secs_f32());
169-
result
170-
} else {
171-
b.execute(source, &target_path)
172-
};
173-
(name.clone(), result)
174-
})
175-
.collect();
176161

177-
ExecResults::from_exec_results(exec_results.into_iter())
162+
let run_test = |(name, backend): (String, Box<dyn Backend>)| -> (String, ExecResult) {
163+
let target_path = target_dir.path().join(&name);
164+
let result = if log_enabled!(log::Level::Debug) {
165+
let time = Instant::now();
166+
let result = backend.execute(source, &target_path);
167+
let dur = time.elapsed();
168+
debug!("{name} took {}s", dur.as_secs_f32());
169+
result
170+
} else {
171+
backend.execute(source, &target_path)
172+
};
173+
(name, result)
174+
};
175+
176+
let results: HashMap<String, ExecResult> = if parallel {
177+
backends.into_par_iter().map(run_test).collect()
178+
} else {
179+
backends.into_iter().map(run_test).collect()
180+
};
181+
ExecResults::from_exec_results(results.into_iter())
178182
}

difftest/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() -> ExitCode {
2222

2323
let config_path = std::env::var("RUSTLANTIS_CONFIG").unwrap_or("config.toml".to_string());
2424
let config = config::load(config_path);
25+
let parallel = config.parallel_difftest;
2526
let backends = backends::from_config(config);
2627

2728
let source = if source == "-" {
@@ -44,7 +45,7 @@ fn main() -> ExitCode {
4445
.collect::<String>()
4546
);
4647

47-
let results = run_diff_test(&source, backends);
48+
let results = run_diff_test(&source, backends, parallel);
4849
if results.all_same() && results.all_success() {
4950
info!("{} is all the same", source);
5051
debug!("{}", results);

difftest/tests/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
parallel_difftest = true
12
max_fn_count = 100
23
max_args_count = 0
34

difftest/tests/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn correct_mir() {
66
let config = config::load("tests/config.toml");
77
let backends = backends::from_config(config);
88

9-
let results = run_diff_test(&Source::File("tests/inputs/simple.rs".into()), backends);
9+
let results = run_diff_test(&Source::File("tests/inputs/simple.rs".into()), backends, true);
1010
println!("{}", results);
1111
assert!(results.all_same());
1212
assert!(
@@ -24,6 +24,7 @@ fn invalid_mir() {
2424
let results = run_diff_test(
2525
&Source::File("tests/inputs/invalid_mir.rs".into()),
2626
backends,
27+
false,
2728
);
2829
println!("{}", results);
2930
assert!(results.all_same());
@@ -36,7 +37,7 @@ fn ub() {
3637
let config = config::load("tests/config.toml");
3738
let backends = backends::from_config(config);
3839

39-
let results = run_diff_test(&Source::File("tests/inputs/ub.rs".into()), backends);
40+
let results = run_diff_test(&Source::File("tests/inputs/ub.rs".into()), backends, false);
4041
println!("{}", results);
4142
assert_eq!(results.has_ub(), Some(true));
4243
}

fuzz-one.sh

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

0 commit comments

Comments
 (0)