New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrench Reftests #695
Merged
+157
−3
Merged
Wrench Reftests #695
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Add reftesting framework
- Loading branch information
commit bf3993b60c422c86aeaf761df3344e5f789a1046
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| root: | ||
| items: | ||
| - | ||
| bounds: [0, 0, 95, 88] | ||
| type: rect | ||
| color: green |
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| root: | ||
| items: | ||
| - | ||
| bounds: [0, 0, 95, 88] | ||
| items: | ||
| - | ||
| bounds: [9, 9, 10, 10] | ||
| type: rect | ||
| color: blue | ||
| type: stacking_context |
Binary file not shown.
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| root: | ||
| items: | ||
| - | ||
| bounds: [0, 0, 95, 88] | ||
| clip: | ||
| image_mask: | ||
| image: "mask.png" | ||
| rect: [0, 0, 35, 35] | ||
| repeat: false | ||
| rect: [0, 0, 95, 88] | ||
| items: | ||
| - | ||
| bounds: [0, 0, 95, 88] | ||
| type: rect | ||
| color: blue | ||
| type: stacking_context |
| @@ -0,0 +1,2 @@ | ||
| == mask.yaml mask-ref.yaml | ||
| != mask.yaml green.yaml |
| @@ -0,0 +1,106 @@ | ||
| use std::io::BufReader; | ||
| use std::io::BufRead; | ||
| use std::fs::File; | ||
| use wrench::{Wrench, WrenchThing}; | ||
| use std::path::Path; | ||
| use gleam::gl; | ||
| use std::sync::mpsc::{channel, Sender, Receiver}; | ||
|
|
||
| use yaml_frame_reader::YamlFrameReader; | ||
| use webrender_traits::*; | ||
|
|
||
| use WindowWrapper; | ||
|
|
||
| pub enum ReftestOp { | ||
| Equal, | ||
| NotEqual, | ||
| } | ||
|
|
||
| pub struct Reftest<'a> { | ||
| op: ReftestOp, | ||
| test: &'a Path, | ||
| reference: &'a Path, | ||
| } | ||
|
|
||
| pub fn parse_reftests<F>(filename: &str, mut runner: F) | ||
| where F: FnMut(Reftest) | ||
| { | ||
|
||
| let manifest = Path::new(filename); | ||
| let dir = manifest.parent().unwrap(); | ||
| let f = File::open(manifest).unwrap(); | ||
| let file = BufReader::new(&f); | ||
| for line in file.lines() { | ||
| let l = line.unwrap(); | ||
|
|
||
| // strip the comments | ||
| let s = &l[0..l.find("#").unwrap_or(l.len())]; | ||
| let s = s.trim(); | ||
|
||
| if s.len() == 0 { | ||
| continue; | ||
| } | ||
|
|
||
| let mut items = s.split_whitespace(); | ||
| let kind = match items.next() { | ||
| Some("==") => ReftestOp::Equal, | ||
| Some("!=") => ReftestOp::NotEqual, | ||
| _ => panic!(), | ||
| }; | ||
| let test = dir.join(items.next().unwrap()); | ||
| let reference = dir.join(items.next().unwrap()); | ||
| runner(Reftest { | ||
| op: kind, | ||
| test: test.as_path(), | ||
| reference: reference.as_path(), | ||
| }); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| fn render_yaml(wrench: &mut Wrench, | ||
| window: &mut WindowWrapper, | ||
| filename: &Path, | ||
| rx: &Receiver<()>) | ||
| -> Vec<u8> { | ||
| let mut reader = YamlFrameReader::new(filename); | ||
| reader.do_frame(wrench); | ||
| // wait for the frame | ||
| rx.recv().unwrap(); | ||
| wrench.render(); | ||
|
|
||
| let size = window.get_inner_size(); | ||
| let pixels = gl::read_pixels(0, | ||
| 0, | ||
| size.0 as gl::GLsizei, | ||
| size.1 as gl::GLsizei, | ||
| gl::RGBA, | ||
| gl::UNSIGNED_BYTE); | ||
| window.swap_buffers(); | ||
| pixels | ||
| } | ||
|
|
||
| pub fn run_reftests(wrench: &mut Wrench, window: &mut WindowWrapper, filename: &str) { | ||
| // setup a notifier so we can wait for frames to be finished | ||
| struct Notifier { | ||
| tx: Sender<()>, | ||
| }; | ||
| impl RenderNotifier for Notifier { | ||
| fn new_frame_ready(&mut self) { | ||
| self.tx.send(()).unwrap(); | ||
| } | ||
| fn new_scroll_frame_ready(&mut self, _composite_needed: bool) {} | ||
| fn pipeline_size_changed(&mut self, _: PipelineId, _: Option<LayoutSize>) {} | ||
| } | ||
| let (tx, rx) = channel(); | ||
| wrench.renderer.set_render_notifier(Box::new(Notifier { tx: tx })); | ||
|
|
||
| parse_reftests(filename, |t: Reftest| { | ||
| println!("{} {}", t.test.display(), t.reference.display()); | ||
| let test = render_yaml(wrench, window, t.test, &rx); | ||
| let reference = render_yaml(wrench, window, t.reference, &rx); | ||
| match t.op { | ||
| ReftestOp::Equal => assert!(test == reference), | ||
| ReftestOp::NotEqual => assert!(test != reference), | ||
| } | ||
| }); | ||
| } | ||
ProTip!
Use n and p to navigate between commits in a pull request.
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.
non-conventional formatting here (and in other function definitions)