mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Make ref tests check the pixels for differences and emit a difference file.
This commit is contained in:
parent
6662fb0c32
commit
28fa9b0069
2 changed files with 28 additions and 8 deletions
|
@ -40,7 +40,7 @@ servo-test: $(DEPS_servo)
|
||||||
|
|
||||||
reftest: $(S)src/test/harness/reftest/reftest.rs servo
|
reftest: $(S)src/test/harness/reftest/reftest.rs servo
|
||||||
@$(call E, compile: $@)
|
@$(call E, compile: $@)
|
||||||
$(Q)$(RUSTC) -o $@ $<
|
$(Q)$(RUSTC) -L$(B)/src/support/png/rust-png/ -o $@ $<
|
||||||
|
|
||||||
contenttest: $(S)src/test/harness/contenttest/contenttest.rs servo
|
contenttest: $(S)src/test/harness/contenttest/contenttest.rs servo
|
||||||
@$(call E, compile: $@)
|
@$(call E, compile: $@)
|
||||||
|
|
|
@ -7,12 +7,14 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
extern mod std;
|
|
||||||
extern mod extra;
|
extern mod extra;
|
||||||
|
extern mod png;
|
||||||
|
extern mod std;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{File, Reader};
|
use std::io::{File, Reader};
|
||||||
use std::io::process::ExitStatus;
|
use std::io::process::ExitStatus;
|
||||||
|
use std::num::abs;
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::run::{Process, ProcessOptions};
|
use std::run::{Process, ProcessOptions};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
@ -45,6 +47,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Eq)]
|
||||||
enum ReftestKind {
|
enum ReftestKind {
|
||||||
Same,
|
Same,
|
||||||
Different,
|
Different,
|
||||||
|
@ -131,12 +134,29 @@ fn check_reftest(reftest: Reftest) {
|
||||||
assert!(retval == ExitStatus(0));
|
assert!(retval == ExitStatus(0));
|
||||||
|
|
||||||
// check the pngs are bit equal
|
// check the pngs are bit equal
|
||||||
let args = ~[left_filename.clone(), right_filename.clone()];
|
let left = png::load_png(&from_str::<Path>(left_filename).unwrap()).unwrap();
|
||||||
let mut process = Process::new("cmp", args, ProcessOptions::new()).unwrap();
|
let right = png::load_png(&from_str::<Path>(right_filename).unwrap()).unwrap();
|
||||||
let retval = process.finish();
|
|
||||||
|
|
||||||
match reftest.kind {
|
let pixels: ~[u8] = left.pixels.iter().zip(right.pixels.iter()).map(|(&a, &b)| {
|
||||||
Same => assert!(retval == ExitStatus(0)),
|
let a_signed = a as i8;
|
||||||
Different => assert!(retval != ExitStatus(0)),
|
let b_signed = b as i8;
|
||||||
|
255-abs(a_signed - b_signed) as u8
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
if pixels.iter().any(|&a| a < 255) {
|
||||||
|
let output = from_str::<Path>(format!("/tmp/servo-reftest-{:06u}-diff.png", reftest.id)).unwrap();
|
||||||
|
|
||||||
|
let img = png::Image {
|
||||||
|
width: left.width,
|
||||||
|
height: left.height,
|
||||||
|
color_type: png::RGBA8,
|
||||||
|
pixels: pixels,
|
||||||
|
};
|
||||||
|
let res = png::store_png(&img, &output);
|
||||||
|
assert!(res.is_ok());
|
||||||
|
|
||||||
|
assert!(reftest.kind == Different);
|
||||||
|
} else {
|
||||||
|
assert!(reftest.kind == Same);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue