Skip to content
Permalink
Browse files

Make WPT reftests fail if the screenshot is entirely white

The output in that case includes this message:

```
Would screenshot an entirely white PNG with --fail-if-blank
```

This should help recognize instances of #24726
  • Loading branch information
SimonSapin committed Dec 1, 2019
1 parent 5d62131 commit d0785e0ba5b22d9916a49f52e71e4198df9b5cb6
@@ -201,6 +201,7 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
cursor_pos: DevicePoint,

output_file: Option<String>,
fail_if_blank: bool,

is_running_problem_test: bool,

@@ -278,6 +279,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
window: Rc<Window>,
state: InitialCompositorState,
output_file: Option<String>,
fail_if_blank: bool,
is_running_problem_test: bool,
exit_after_load: bool,
convert_mouse_to_touch: bool,
@@ -320,6 +322,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
cursor: Cursor::None,
cursor_pos: DevicePoint::new(0.0, 0.0),
output_file,
fail_if_blank,
is_running_problem_test,
exit_after_load,
convert_mouse_to_touch,
@@ -330,6 +333,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
window: Rc<Window>,
state: InitialCompositorState,
output_file: Option<String>,
fail_if_blank: bool,
is_running_problem_test: bool,
exit_after_load: bool,
convert_mouse_to_touch: bool,
@@ -338,6 +342,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
window,
state,
output_file,
fail_if_blank,
is_running_problem_test,
exit_after_load,
convert_mouse_to_touch,
@@ -1387,6 +1392,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
FramebufferUintLength::new(width),
FramebufferUintLength::new(height),
);
if self.fail_if_blank && crate::image_is_entirely_white(&img) {
eprintln!("Would screenshot an entirely white PNG with --fail-if-blank");
std::process::exit(1);
}
let dynamic_image = DynamicImage::ImageRgb8(img);
if let Err(e) = dynamic_image.write_to(&mut file, ImageFormat::PNG)
{
@@ -36,3 +36,27 @@ pub struct CompositionPipeline {
pub script_chan: IpcSender<ConstellationControlMsg>,
pub layout_chan: IpcSender<LayoutControlMsg>,
}

fn image_is_entirely_white(img: &image::RgbImage) -> bool {
let buffer: &[u8] = img;
// Safety: transmuting an aligned `[u8; size_of::<usize>()]` to `usize` is safe
#[allow(unsafe_code)]
let (before, aligned, after) = unsafe { buffer.align_to::<usize>() };
for &byte in before {
if byte != 0xFF_u8 {
return false;
}
}
for &chunk in aligned {
const FF: usize = !0;
if chunk != FF {
return false;
}
}
for &byte in after {
if byte != 0xFF_u8 {
return false;
}
}
return true;
}
@@ -61,6 +61,7 @@ pub struct Opts {
pub user_stylesheets: Vec<(Vec<u8>, ServoUrl)>,

pub output_file: Option<String>,
pub fail_if_blank: bool,

/// Replace unpaired surrogates in DOM strings with U+FFFD.
/// See <https://github.com/servo/servo/issues/6564>
@@ -527,6 +528,7 @@ pub fn default_opts() -> Opts {
userscripts: None,
user_stylesheets: Vec::new(),
output_file: None,
fail_if_blank: false,
replace_surrogates: false,
gc_profile: false,
load_webfonts_synchronously: false,
@@ -581,6 +583,11 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
opts.optflag("c", "cpu", "CPU painting");
opts.optflag("g", "gpu", "GPU painting");
opts.optopt("o", "output", "Output file", "output.png");
opts.optflag(
"",
"fail-if-blank",
"Exit with an error code if the PNG file for -o/--output would be entirely white pixels",
);
opts.optopt("s", "size", "Size of tiles", "512");
opts.optflagopt(
"p",
@@ -950,6 +957,7 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
userscripts: opt_match.opt_default("userscripts", ""),
user_stylesheets: user_stylesheets,
output_file: opt_match.opt_str("o"),
fail_if_blank: opt_match.opt_present("fail-if-blank"),
replace_surrogates: debug_options.replace_surrogates,
gc_profile: debug_options.gc_profile,
load_webfonts_synchronously: debug_options.load_webfonts_synchronously,
@@ -554,6 +554,7 @@ where
webxr_main_thread,
},
opts.output_file.clone(),
opts.fail_if_blank,
opts.is_running_problem_test,
opts.exit_after_load,
opts.convert_mouse_to_touch,
@@ -1,2 +1,2 @@
[root-box-002.xht]
expected: FAIL
expected: CRASH
@@ -0,0 +1,2 @@
[root-box-003.xht]
expected: CRASH
"support"
],
"tools/wptrunner/wptrunner/executors/executorservo.py": [
"365a1a08653b0175fc4df4050eb9d9aaf8b1d34c",
"6fd45d20c8ae5494ddf2046bac2f254ffbb1ab63",
"support"
],
"tools/wptrunner/wptrunner/executors/executorservodriver.py": [
@@ -198,7 +198,9 @@ def screenshot(self, test, viewport_size, dpi):
debug_args, command = browser_command(
self.binary,
[
"--hard-fail", "--exit",
"--exit",
"--hard-fail",
"--fail-if-blank",
"-u", "Servo/wptrunner",
"-Z", "disable-text-aa,load-webfonts-synchronously,replace-surrogates",
"--output=%s" % output_path, full_url

0 comments on commit d0785e0

Please sign in to comment.
You can’t perform that action at this time.