Cleanup formatting in reftest.rs.

This commit is contained in:
Ms2ger 2014-08-19 16:43:33 +02:00
parent 5c3b8f99d1
commit 2123fb4238

View file

@ -33,15 +33,15 @@ fn main() {
let servo_args = parts.next().unwrap_or(&[]); let servo_args = parts.next().unwrap_or(&[]);
let (render_mode_string, manifest, testname) = match harness_args { let (render_mode_string, manifest, testname) = match harness_args {
[] | [_] => fail!("USAGE: cpu|gpu manifest [testname regex]"), [] | [_] => fail!("USAGE: cpu|gpu manifest [testname regex]"),
[ref render_mode_string, ref manifest] => (render_mode_string, manifest, None), [ref render_mode_string, ref manifest] => (render_mode_string, manifest, None),
[ref render_mode_string, ref manifest, ref testname, ..] => (render_mode_string, manifest, Some(Regex::new(testname.as_slice()).unwrap())), [ref render_mode_string, ref manifest, ref testname, ..] => (render_mode_string, manifest, Some(Regex::new(testname.as_slice()).unwrap())),
}; };
let render_mode = match render_mode_string.as_slice() { let render_mode = match render_mode_string.as_slice() {
"cpu" => CpuRendering, "cpu" => CpuRendering,
"gpu" => GpuRendering, "gpu" => GpuRendering,
_ => fail!("First argument must specify cpu or gpu as rendering mode") _ => fail!("First argument must specify cpu or gpu as rendering mode")
}; };
let tests = parse_lists(manifest, servo_args, render_mode); let tests = parse_lists(manifest, servo_args, render_mode);
@ -83,10 +83,10 @@ struct Reftest {
} }
struct TestLine<'a> { struct TestLine<'a> {
conditions: &'a str, conditions: &'a str,
kind: &'a str, kind: &'a str,
file_left: &'a str, file_left: &'a str,
file_right: &'a str, file_right: &'a str,
} }
fn parse_lists(file: &String, servo_args: &[String], render_mode: RenderMode) -> Vec<TestDescAndFn> { fn parse_lists(file: &String, servo_args: &[String], render_mode: RenderMode) -> Vec<TestDescAndFn> {
@ -98,72 +98,62 @@ fn parse_lists(file: &String, servo_args: &[String], render_mode: RenderMode) ->
.ok().expect("Could not read file"); .ok().expect("Could not read file");
for line in contents.as_slice().lines() { for line in contents.as_slice().lines() {
// ignore comments or empty lines // ignore comments or empty lines
if line.starts_with("#") || line.is_empty() { if line.starts_with("#") || line.is_empty() {
continue; continue;
} }
let parts: Vec<&str> = line.split(' ').filter(|p| !p.is_empty()).collect(); let parts: Vec<&str> = line.split(' ').filter(|p| !p.is_empty()).collect();
let test_line = match parts.len() { let test_line = match parts.len() {
3 => { 3 => TestLine {
TestLine { conditions: "",
conditions: "", kind: parts[0],
kind: parts[0], file_left: parts[1],
file_left: parts[1], file_right: parts[2],
file_right: parts[2],
}
},
4 => {
TestLine {
conditions: parts[0],
kind: parts[1],
file_left: parts[2],
file_right: parts[3],
}
},
_ => {
fail!("reftest line: '{:s}' doesn't match '[CONDITIONS] KIND LEFT RIGHT'", line);
}
};
let kind = match test_line.kind {
"==" => Same,
"!=" => Different,
part => fail!("reftest line: '{:s}' has invalid kind '{:s}'", line, part)
};
let src_path = file_path.dir_path();
let src_dir = src_path.display().to_string();
let file_left = src_dir.clone().append("/").append(test_line.file_left);
let file_right = src_dir.append("/").append(test_line.file_right);
let mut conditions_list = test_line.conditions.split(',');
let mut flakiness = 0;
for condition in conditions_list {
match condition {
"flaky_cpu" => {
flakiness |= CpuRendering as uint;
}, },
"flaky_gpu" => { 4 => TestLine {
flakiness |= GpuRendering as uint; conditions: parts[0],
kind: parts[1],
file_left: parts[2],
file_right: parts[3],
}, },
_ => {} _ => fail!("reftest line: '{:s}' doesn't match '[CONDITIONS] KIND LEFT RIGHT'", line),
} };
}
let reftest = Reftest { let kind = match test_line.kind {
name: test_line.file_left.to_string().append(" / ").append(test_line.file_right), "==" => Same,
kind: kind, "!=" => Different,
files: [file_left, file_right], part => fail!("reftest line: '{:s}' has invalid kind '{:s}'", line, part)
id: next_id, };
render_mode: render_mode, let src_path = file_path.dir_path();
servo_args: servo_args.iter().map(|x| x.clone()).collect(), let src_dir = src_path.display().to_string();
flakiness: flakiness, let file_left = src_dir.clone().append("/").append(test_line.file_left);
}; let file_right = src_dir.append("/").append(test_line.file_right);
next_id += 1; let mut conditions_list = test_line.conditions.split(',');
let mut flakiness = 0;
for condition in conditions_list {
match condition {
"flaky_cpu" => flakiness |= CpuRendering as uint,
"flaky_gpu" => flakiness |= GpuRendering as uint,
_ => (),
}
}
tests.push(make_test(reftest)); let reftest = Reftest {
name: test_line.file_left.to_string().append(" / ").append(test_line.file_right),
kind: kind,
files: [file_left, file_right],
id: next_id,
render_mode: render_mode,
servo_args: servo_args.iter().map(|x| x.clone()).collect(),
flakiness: flakiness,
};
next_id += 1;
tests.push(make_test(reftest));
} }
tests tests
} }
@ -186,8 +176,8 @@ fn capture(reftest: &Reftest, side: uint) -> png::Image {
let filename = format!("/tmp/servo-reftest-{:06u}-{:u}.png", reftest.id, side); let filename = format!("/tmp/servo-reftest-{:06u}-{:u}.png", reftest.id, side);
let mut args = reftest.servo_args.clone(); let mut args = reftest.servo_args.clone();
match reftest.render_mode { match reftest.render_mode {
CpuRendering => args.push("-c".to_string()), CpuRendering => args.push("-c".to_string()),
_ => {} // GPU rendering is the default _ => {} // GPU rendering is the default
} }
args.push_all_move(vec!("-f".to_string(), "-o".to_string(), filename.clone(), reftest.files[side].clone())); args.push_all_move(vec!("-f".to_string(), "-o".to_string(), filename.clone(), reftest.files[side].clone()));
@ -204,18 +194,18 @@ fn check_reftest(reftest: Reftest) {
let left = capture(&reftest, 0); let left = capture(&reftest, 0);
let right = capture(&reftest, 1); let right = capture(&reftest, 1);
let pixels: Vec<u8> = left.pixels.iter().zip(right.pixels.iter()).map(|(&a, &b)| { let pixels = left.pixels.iter().zip(right.pixels.iter()).map(|(&a, &b)| {
if a as i8 - b as i8 == 0 { if a as i8 - b as i8 == 0 {
// White for correct // White for correct
0xFF 0xFF
} else { } else {
// "1100" in the RGBA channel with an error for an incorrect value // "1100" in the RGBA channel with an error for an incorrect value
// This results in some number of C0 and FFs, which is much more // This results in some number of C0 and FFs, which is much more
// readable (and distinguishable) than the previous difference-wise // readable (and distinguishable) than the previous difference-wise
// scaling but does not require reconstructing the actual RGBA pixel. // scaling but does not require reconstructing the actual RGBA pixel.
0xC0 0xC0
} }
}).collect(); }).collect::<Vec<u8>>();
let test_is_flaky = (reftest.render_mode as uint & reftest.flakiness) != 0; let test_is_flaky = (reftest.render_mode as uint & reftest.flakiness) != 0;
@ -233,9 +223,9 @@ fn check_reftest(reftest: Reftest) {
assert!(res.is_ok()); assert!(res.is_ok());
match (reftest.kind, test_is_flaky) { match (reftest.kind, test_is_flaky) {
(Same, true) => println!("flaky test - rendering difference: {}", output_str), (Same, true) => println!("flaky test - rendering difference: {}", output_str),
(Same, false) => fail!("rendering difference: {}", output_str), (Same, false) => fail!("rendering difference: {}", output_str),
(Different, _) => {} // Result was different and that's what was expected (Different, _) => {} // Result was different and that's what was expected
} }
} else { } else {
assert!(test_is_flaky || reftest.kind == Same); assert!(test_is_flaky || reftest.kind == Same);