Skip to content

Commit

Permalink
Auto merge of #354 - pietroalbini:minicrater-multi, r=pietroalbini
Browse files Browse the repository at this point in the history
Minicrater improvements

* Hidden run output when running the tests locally
* Added a multithreaded run
  • Loading branch information
bors committed Oct 23, 2018
2 parents f252acb + 6ffdecb commit 4b09fcd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 28 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -66,3 +66,4 @@ nix = "0.11.0"
assert_cmd = "0.10.1"
predicates = "1.0.0"
difference = "2.0.0"
num_cpus = "1.8.0"
2 changes: 1 addition & 1 deletion ci/run/minicrater-linux.sh
Expand Up @@ -3,4 +3,4 @@ set -euo pipefail
IFS=$'\n\t'

cargo run -- prepare-local --docker-env=mini
cargo test -- --ignored --nocapture --test-threads 1
MINICRATER_SHOW_OUTPUT=1 cargo test -- --ignored --nocapture --test-threads 1
1 change: 1 addition & 0 deletions tests/integration.rs
@@ -1,5 +1,6 @@
extern crate assert_cmd;
extern crate difference;
extern crate num_cpus;
extern crate predicates;
extern crate rand;
extern crate serde;
Expand Down
72 changes: 45 additions & 27 deletions tests/minicrater/mod.rs
@@ -1,16 +1,34 @@
use assert_cmd::prelude::*;
use common::CommandCraterExt;
use difference::Changeset;
use rand::{self, distributions::Alphanumeric, Rng};
use serde_json::{self, Value};
use std::env;
use std::path::PathBuf;
use std::process::Command;

fn execute(ex: &str, crate_select: &str) {
trait CommandMinicraterExt {
fn minicrater_exec(&mut self);
}

impl CommandMinicraterExt for Command {
fn minicrater_exec(&mut self) {
if env::var_os("MINICRATER_SHOW_OUTPUT").is_some() {
assert!(self.status().unwrap().success());
} else {
self.assert().success();
}
}
}

fn execute(ex: &str, crate_select: &str, multithread: bool) {
let ex_dir = PathBuf::from("tests").join("minicrater").join(ex);
let config_file = ex_dir.join("config.toml");
let expected_file = ex_dir.join("results.expected.json");
let actual_file = ex_dir.join("results.actual.json");

let threads_count = if multithread { ::num_cpus::get() } else { 1 };

let report_dir = ::tempfile::tempdir().expect("failed to create report dir");
let ex_arg = format!(
"--ex=minicrater-{}-{}",
Expand All @@ -22,54 +40,48 @@ fn execute(ex: &str, crate_select: &str) {
);

// Create local list in the temp work dir
let out = Command::crater()
Command::crater()
.args(&["create-lists", "local"])
.env("CRATER_CONFIG", &config_file)
.status()
.unwrap();
assert!(out.success());
.minicrater_exec();

// Define the experiment
let out = Command::crater()
Command::crater()
.args(&[
"define-ex",
&ex_arg,
"stable",
"beta",
&format!("--crate-select={}", crate_select),
]).env("CRATER_CONFIG", &config_file)
.status()
.unwrap();
assert!(out.success());
.minicrater_exec();

// Execute the experiment
let out = Command::crater()
.args(&["run-graph", &ex_arg])
.env("CRATER_CONFIG", &config_file)
.status()
.unwrap();
assert!(out.success());
Command::crater()
.args(&[
"run-graph",
&ex_arg,
"--threads",
&threads_count.to_string(),
]).env("CRATER_CONFIG", &config_file)
.minicrater_exec();

// Generate the report
let out = Command::crater()
Command::crater()
.args(&["gen-report", &ex_arg])
.env("CRATER_CONFIG", &config_file)
.arg(report_dir.path())
.status()
.unwrap();
assert!(out.success());
.minicrater_exec();

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

// Delete the experiment
let out = Command::crater()
Command::crater()
.args(&["delete-ex", &ex_arg])
.env("CRATER_CONFIG", &config_file)
.status()
.unwrap();
assert!(out.success());
.minicrater_exec();

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

#[ignore]
#[test]
fn run_small() {
execute("small", "demo");
fn single_thread_small() {
execute("small", "demo", false);
}

#[ignore]
#[test]
fn single_thread_full() {
execute("full", "local", false);
}

#[ignore]
#[test]
fn run_full() {
execute("full", "local");
fn multi_thread_full() {
execute("full", "local", true);
}

0 comments on commit 4b09fcd

Please sign in to comment.