This repository was archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Add lang_tester framework for Miri tests #38
Closed
jacob-hughes
wants to merge
1
commit into
softdevteam:master
from
jacob-hughes:add_miri_test_framework
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
set -e; | ||
|
||
PROJECTDIR=$1 | ||
TMPDIR=$2 | ||
|
||
# Miri deps cause breakages when used with non-miri targets. So we copy gcmalloc | ||
# sources over to a tempdir to compile with miri flags so we can nuke it | ||
# afterwards. | ||
rsync -a --partial --info=progress2 --exclude .git --exclude target --exclude gc_tests $PROJECTDIR/ $TMPDIR | ||
|
||
mkdir -p "$TMPDIR/src/bin/" | ||
|
||
# Running this dummy binary forces cargo-miri to compile gcmalloc with miri | ||
# flags as a dependency. | ||
echo "extern crate gcmalloc; fn main() {}" > $TMPDIR/src/bin/miri.rs | ||
(cd $TMPDIR && cargo-miri miri setup) | ||
(cd $TMPDIR && cargo-miri miri run -- -Zmiri-ignore-leaks) | ||
|
||
rm $TMPDIR/src/bin/miri.rs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use std::{ | ||
env, | ||
path::{Path, PathBuf}, | ||
process::Command, | ||
}; | ||
|
||
use lang_tester::LangTester; | ||
use tempdir::TempDir; | ||
|
||
fn proj_dir() -> Box<Path> { | ||
let mut p = PathBuf::new(); | ||
p.push(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
p.into_boxed_path() | ||
} | ||
|
||
fn test_dir() -> Box<Path> { | ||
let mut p = PathBuf::new(); | ||
p.push(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
p.push("gc_tests"); | ||
p.push("tests"); | ||
p.push("."); | ||
p.into_boxed_path() | ||
} | ||
|
||
fn main() { | ||
let projd = proj_dir(); | ||
let testsd = test_dir(); | ||
|
||
let tmpd = TempDir::new("miri_tests").unwrap(); | ||
let mut binsd = PathBuf::new(); | ||
binsd.push(tmpd.path()); | ||
binsd.push("src"); | ||
binsd.push("bin"); | ||
|
||
let mut setup = Command::new("./gc_tests/miri_test_setup.sh") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered if it would be better to inline what |
||
.args(&[&*projd, tmpd.path()]) | ||
.spawn() | ||
.unwrap(); | ||
|
||
if !setup.wait().unwrap().success() { | ||
panic!("Miri setup failed"); | ||
} | ||
|
||
::std::env::set_current_dir(&tmpd).expect("Couldn't change dir"); | ||
|
||
LangTester::new() | ||
.test_dir(testsd.to_str().unwrap()) | ||
.test_file_filter(|p| { | ||
p.extension().unwrap().to_str().unwrap() == "rs" | ||
&& p.file_stem().unwrap().to_str().unwrap().starts_with("miri") | ||
}) | ||
.test_extract(|s| { | ||
Some( | ||
s.lines() | ||
.take_while(|l| l.starts_with("//")) | ||
.map(|l| &l[2..]) | ||
.collect::<Vec<_>>() | ||
.join("\n"), | ||
) | ||
}) | ||
.test_cmds(move |p| { | ||
let mut cp = Command::new("cp"); | ||
cp.args(&[p, binsd.as_path()]); | ||
|
||
let mut runtime = Command::new("cargo-miri"); | ||
runtime.args(&["miri", "run", "--", "-Zmiri-ignore-leaks"]); | ||
|
||
let mut rm_path = PathBuf::new(); | ||
rm_path.push(&binsd); | ||
rm_path.push(p.file_name().unwrap().to_str().unwrap()); | ||
|
||
let mut rm = Command::new("rm"); | ||
rm.args(&[rm_path.to_str().unwrap()]); | ||
|
||
vec![("cp", cp), ("Miri", runtime), ("rm", rm)] | ||
}) | ||
.run(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Miri: | ||
// status: success | ||
|
||
extern crate gcmalloc; | ||
|
||
use gcmalloc::Gc; | ||
|
||
fn main() { | ||
let hello = Gc::new("Hello World"); | ||
println!("{}", hello) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rsync
?!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be
cp
now. I usedrsync
while developing because there was a lot of trial-and-error testing and I wanted to speed up transfer of targets. I'm curious, is the "?!" a comment on the overkill or poor platform compatibility. If the latter, I'm afraid there's plenty more where that came from with this approach to getting Miri running.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
cp
is more portable thanrsync
, and given that we copy to a fresh directory each time, I thinkcp
is sufficient.