Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion 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 config.toml.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
parallel_difftest = true
bb_max_len = 32
max_switch_targets = 8
max_bb_count = 50
Expand Down
1 change: 1 addition & 0 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub fn load(path: impl AsRef<Path>) -> Config {

#[derive(Deserialize, Clone)]
pub struct Config {
pub parallel_difftest: bool,
#[serde(flatten)]
pub generation: GenerationConfig,
#[serde(flatten)]
Expand Down
1 change: 0 additions & 1 deletion difftest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ colored = "2.0.0"
env_logger = "0.11.3"
log = "0.4.17"
rayon = "1.7.0"
serde = { version = "1", features = ["derive"] }
tempfile = "3.3.0"
30 changes: 20 additions & 10 deletions difftest/src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,14 @@ impl LLVM {

impl Backend for LLVM {
fn compile(&self, source: &Source, target: &Path) -> ProcessOutput {
let mut command = Command::new("rustc");

command.arg(format!("+{}", self.toolchain));
let mut command = if let Ok(path) = std::env::var("RUSTLANTIS_RUSTC_PATH") {
debug!("Compiling with rustc from RUSTLANTIS_RUSTC_PATH");
Command::new(path)
} else {
let mut command = Command::new("rustc");
command.arg(format!("+{}", self.toolchain));
command
};

command
.args(["-o", target.to_str().unwrap()])
Expand Down Expand Up @@ -307,13 +312,18 @@ impl Miri {

impl Backend for Miri {
fn execute(&self, source: &Source, _: &Path) -> ExecResult {
debug!("Executing with Miri {source}");
let mut command = match &self.miri {
BackendSource::Path(binary) => Command::new(binary),
BackendSource::Rustup(toolchain) => {
let mut cmd = Command::new("rustup");
cmd.args(["run", &toolchain, "miri"]);
cmd
let mut command = if let Ok(path) = std::env::var("RUSTLANTIS_MIRI_PATH") {
debug!("Executing with Miri from RUSTLANTIS_MIRI_PATH");
Command::new(path)
} else {
debug!("Executing with Miri {source}");
match &self.miri {
BackendSource::Path(binary) => Command::new(binary),
BackendSource::Rustup(toolchain) => {
let mut cmd = Command::new("rustup");
cmd.args(["run", &toolchain, "miri"]);
cmd
}
}
};
command.args(self.flags.clone());
Expand Down
38 changes: 21 additions & 17 deletions difftest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,28 @@ impl fmt::Display for ExecResults {
pub fn run_diff_test<'a>(
source: &Source,
backends: HashMap<String, Box<dyn Backend + 'a>>,
parallel: bool,
) -> ExecResults {
let target_dir = tempfile::tempdir().unwrap();
let exec_results: HashMap<String, ExecResult> = backends
.into_par_iter()
.map(|(name, b)| {
let target_path = target_dir.path().join(&name);
let result = if log_enabled!(log::Level::Debug) {
let time = Instant::now();
let result = b.execute(source, &target_path);
let dur = time.elapsed();
debug!("{name} took {}s", dur.as_secs_f32());
result
} else {
b.execute(source, &target_path)
};
(name.clone(), result)
})
.collect();

ExecResults::from_exec_results(exec_results.into_iter())
let run_test = |(name, backend): (String, Box<dyn Backend>)| -> (String, ExecResult) {
let target_path = target_dir.path().join(&name);
let result = if log_enabled!(log::Level::Debug) {
let time = Instant::now();
let result = backend.execute(source, &target_path);
let dur = time.elapsed();
debug!("{name} took {}s", dur.as_secs_f32());
result
} else {
backend.execute(source, &target_path)
};
(name, result)
};

let results: HashMap<String, ExecResult> = if parallel {
backends.into_par_iter().map(run_test).collect()
} else {
backends.into_iter().map(run_test).collect()
};
ExecResults::from_exec_results(results.into_iter())
}
3 changes: 2 additions & 1 deletion difftest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn main() -> ExitCode {

let config_path = std::env::var("RUSTLANTIS_CONFIG").unwrap_or("config.toml".to_string());
let config = config::load(config_path);
let parallel = config.parallel_difftest;
let backends = backends::from_config(config);

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

let results = run_diff_test(&source, backends);
let results = run_diff_test(&source, backends, parallel);
if results.all_same() && results.all_success() {
info!("{} is all the same", source);
debug!("{}", results);
Expand Down
1 change: 1 addition & 0 deletions difftest/tests/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
parallel_difftest = true
max_fn_count = 100
max_args_count = 0

Expand Down
5 changes: 3 additions & 2 deletions difftest/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn correct_mir() {
let config = config::load("tests/config.toml");
let backends = backends::from_config(config);

let results = run_diff_test(&Source::File("tests/inputs/simple.rs".into()), backends);
let results = run_diff_test(&Source::File("tests/inputs/simple.rs".into()), backends, true);
println!("{}", results);
assert!(results.all_same());
assert!(
Expand All @@ -24,6 +24,7 @@ fn invalid_mir() {
let results = run_diff_test(
&Source::File("tests/inputs/invalid_mir.rs".into()),
backends,
false,
);
println!("{}", results);
assert!(results.all_same());
Expand All @@ -36,7 +37,7 @@ fn ub() {
let config = config::load("tests/config.toml");
let backends = backends::from_config(config);

let results = run_diff_test(&Source::File("tests/inputs/ub.rs".into()), backends);
let results = run_diff_test(&Source::File("tests/inputs/ub.rs".into()), backends, false);
println!("{}", results);
assert_eq!(results.has_ub(), Some(true));
}
21 changes: 0 additions & 21 deletions fuzz-one.sh

This file was deleted.

19 changes: 19 additions & 0 deletions fuzz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -eu

cargo build --release
export MIRI_SYSROOT=$(cargo +nightly miri setup --print-sysroot)
export RUSTLANTIS_MIRI_PATH="$(rustup run nightly miri --print sysroot)/bin/miri"
export RUSTLANTIS_RUSTC_PATH="$(rustup run nightly rustc --print sysroot)/bin/rustc"

function cleanup {
kill $(jobs -p)
}
trap cleanup EXIT

proc=$(nproc)
for job in $(seq 0 $((proc-1))); do
nice -n 19 ./job.sh &> $job.out &
done

wait
10 changes: 0 additions & 10 deletions fuzz10.sh

This file was deleted.

14 changes: 14 additions & 0 deletions job.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -eu

while true
do
seed=$(python3 -c "print(int.from_bytes(open('/dev/urandom', 'rb').read(8), 'little'))")
code=$(target/release/generate $seed)
if ! target/release/difftest - <<< $code
then
mkdir -p out
printf "%s" "$code" > out/$seed.rs
fi
done