Skip to content

Commit

Permalink
auto merge of #610 : metajack/servo/fix-reftest, r=pcwalton
Browse files Browse the repository at this point in the history
This adds a sha1 hash to the output filenames based on the test. Rust runs
tests in parallel by default, so the test files were stomping on each other.
  • Loading branch information
bors-servo committed Jul 20, 2013
2 parents 841b91f + 4598149 commit ddbe1c9
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/test/harness/reftest/reftest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,30 @@ fn make_test(reftest: Reftest) -> TestDescAndFn {
}

fn check_reftest(reftest: Reftest) {
let id = gen_id(&reftest);
let left_filename = fmt!("/tmp/%s-left.png", id);
let right_filename = fmt!("/tmp/%s-right.png", id);
let left_path = Path(left_filename);
let right_path = Path(right_filename);

let options = run::ProcessOptions::new();
let args = ~[~"-o", ~"/tmp/reftest-left.png", reftest.left.clone()];
let args = ~[~"-o", left_filename.clone(), reftest.left.clone()];
let mut process = run::Process::new("./servo", args, options);
let _retval = process.finish();
// assert!(retval == 0);

let args = ~[~"-o", ~"/tmp/reftest-right.png", reftest.right.clone()];
let args = ~[~"-o", right_filename.clone(), reftest.right.clone()];
let mut process = run::Process::new("./servo", args, options);
let _retval = process.finish();
// assert!(retval == 0);

// check the pngs are bit equal
let left_sha = calc_hash(&Path("/tmp/reftest-left.png"));
let right_sha = calc_hash(&Path("/tmp/reftest-right.png"));
let left_sha = calc_hash(&left_path);
os::remove_file(&left_path);

let right_sha = calc_hash(&right_path);
os::remove_file(&right_path);

assert!(left_sha.is_some());
assert!(right_sha.is_some());
match reftest.kind {
Expand All @@ -132,6 +142,17 @@ fn check_reftest(reftest: Reftest) {
}
}

fn gen_id(reftest: &Reftest) -> ~str {
let mut sha = Sha1::new();
match reftest.kind {
Same => sha.input_str("=="),
Different => sha.input_str("!="),
}
sha.input_str(reftest.left);
sha.input_str(reftest.right);
sha.result_str()
}

fn calc_hash(path: &Path) -> Option<~str> {
match io::file_reader(path) {
Err(*) => None,
Expand Down

0 comments on commit ddbe1c9

Please sign in to comment.