Skip to content

Commit 4b09fcd

Browse files
committed
Auto merge of #354 - pietroalbini:minicrater-multi, r=pietroalbini
Minicrater improvements * Hidden run output when running the tests locally * Added a multithreaded run
2 parents f252acb + 6ffdecb commit 4b09fcd

File tree

5 files changed

+49
-28
lines changed

5 files changed

+49
-28
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ nix = "0.11.0"
6666
assert_cmd = "0.10.1"
6767
predicates = "1.0.0"
6868
difference = "2.0.0"
69+
num_cpus = "1.8.0"

ci/run/minicrater-linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ set -euo pipefail
33
IFS=$'\n\t'
44

55
cargo run -- prepare-local --docker-env=mini
6-
cargo test -- --ignored --nocapture --test-threads 1
6+
MINICRATER_SHOW_OUTPUT=1 cargo test -- --ignored --nocapture --test-threads 1

tests/integration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
extern crate assert_cmd;
22
extern crate difference;
3+
extern crate num_cpus;
34
extern crate predicates;
45
extern crate rand;
56
extern crate serde;

tests/minicrater/mod.rs

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1+
use assert_cmd::prelude::*;
12
use common::CommandCraterExt;
23
use difference::Changeset;
34
use rand::{self, distributions::Alphanumeric, Rng};
45
use serde_json::{self, Value};
6+
use std::env;
57
use std::path::PathBuf;
68
use std::process::Command;
79

8-
fn execute(ex: &str, crate_select: &str) {
10+
trait CommandMinicraterExt {
11+
fn minicrater_exec(&mut self);
12+
}
13+
14+
impl CommandMinicraterExt for Command {
15+
fn minicrater_exec(&mut self) {
16+
if env::var_os("MINICRATER_SHOW_OUTPUT").is_some() {
17+
assert!(self.status().unwrap().success());
18+
} else {
19+
self.assert().success();
20+
}
21+
}
22+
}
23+
24+
fn execute(ex: &str, crate_select: &str, multithread: bool) {
925
let ex_dir = PathBuf::from("tests").join("minicrater").join(ex);
1026
let config_file = ex_dir.join("config.toml");
1127
let expected_file = ex_dir.join("results.expected.json");
1228
let actual_file = ex_dir.join("results.actual.json");
1329

30+
let threads_count = if multithread { ::num_cpus::get() } else { 1 };
31+
1432
let report_dir = ::tempfile::tempdir().expect("failed to create report dir");
1533
let ex_arg = format!(
1634
"--ex=minicrater-{}-{}",
@@ -22,54 +40,48 @@ fn execute(ex: &str, crate_select: &str) {
2240
);
2341

2442
// Create local list in the temp work dir
25-
let out = Command::crater()
43+
Command::crater()
2644
.args(&["create-lists", "local"])
2745
.env("CRATER_CONFIG", &config_file)
28-
.status()
29-
.unwrap();
30-
assert!(out.success());
46+
.minicrater_exec();
3147

3248
// Define the experiment
33-
let out = Command::crater()
49+
Command::crater()
3450
.args(&[
3551
"define-ex",
3652
&ex_arg,
3753
"stable",
3854
"beta",
3955
&format!("--crate-select={}", crate_select),
4056
]).env("CRATER_CONFIG", &config_file)
41-
.status()
42-
.unwrap();
43-
assert!(out.success());
57+
.minicrater_exec();
4458

4559
// Execute the experiment
46-
let out = Command::crater()
47-
.args(&["run-graph", &ex_arg])
48-
.env("CRATER_CONFIG", &config_file)
49-
.status()
50-
.unwrap();
51-
assert!(out.success());
60+
Command::crater()
61+
.args(&[
62+
"run-graph",
63+
&ex_arg,
64+
"--threads",
65+
&threads_count.to_string(),
66+
]).env("CRATER_CONFIG", &config_file)
67+
.minicrater_exec();
5268

5369
// Generate the report
54-
let out = Command::crater()
70+
Command::crater()
5571
.args(&["gen-report", &ex_arg])
5672
.env("CRATER_CONFIG", &config_file)
5773
.arg(report_dir.path())
58-
.status()
59-
.unwrap();
60-
assert!(out.success());
74+
.minicrater_exec();
6175

6276
// Read the JSON report
6377
let json_report = ::std::fs::read(report_dir.path().join("results.json"))
6478
.expect("failed to read json report");
6579

6680
// Delete the experiment
67-
let out = Command::crater()
81+
Command::crater()
6882
.args(&["delete-ex", &ex_arg])
6983
.env("CRATER_CONFIG", &config_file)
70-
.status()
71-
.unwrap();
72-
assert!(out.success());
84+
.minicrater_exec();
7385

7486
// Load the generated JSON report
7587
let parsed_report: Value = serde_json::from_slice(&json_report).expect("invalid json report");
@@ -105,12 +117,18 @@ fn execute(ex: &str, crate_select: &str) {
105117

106118
#[ignore]
107119
#[test]
108-
fn run_small() {
109-
execute("small", "demo");
120+
fn single_thread_small() {
121+
execute("small", "demo", false);
122+
}
123+
124+
#[ignore]
125+
#[test]
126+
fn single_thread_full() {
127+
execute("full", "local", false);
110128
}
111129

112130
#[ignore]
113131
#[test]
114-
fn run_full() {
115-
execute("full", "local");
132+
fn multi_thread_full() {
133+
execute("full", "local", true);
116134
}

0 commit comments

Comments
 (0)