2013-04-06 03:31:01 +04:00
|
|
|
// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-09-14 17:56:58 +04:00
|
|
|
#![deny(unused_imports, unused_variable)]
|
|
|
|
|
2014-03-19 20:35:17 +04:00
|
|
|
extern crate png;
|
|
|
|
extern crate test;
|
2014-06-22 16:27:01 +04:00
|
|
|
extern crate regex;
|
2014-09-16 23:32:40 +04:00
|
|
|
extern crate url;
|
2013-07-19 02:25:10 +04:00
|
|
|
|
2014-08-21 01:01:56 +04:00
|
|
|
use std::ascii::StrAsciiExt;
|
2014-01-13 07:16:21 +04:00
|
|
|
use std::io;
|
2014-06-05 21:58:44 +04:00
|
|
|
use std::io::{File, Reader, Command};
|
2014-01-13 07:16:21 +04:00
|
|
|
use std::io::process::ExitStatus;
|
2014-09-21 02:35:08 +04:00
|
|
|
use std::io::fs::PathExtensions;
|
2013-07-19 02:25:10 +04:00
|
|
|
use std::os;
|
2014-09-16 23:32:40 +04:00
|
|
|
use std::path::Path;
|
2014-06-28 05:25:07 +04:00
|
|
|
use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn};
|
2014-03-19 20:35:17 +04:00
|
|
|
use test::run_tests_console;
|
2014-06-22 16:27:01 +04:00
|
|
|
use regex::Regex;
|
2014-09-16 23:32:40 +04:00
|
|
|
use url::Url;
|
2013-07-19 02:25:10 +04:00
|
|
|
|
2014-08-22 02:53:27 +04:00
|
|
|
|
|
|
|
bitflags!(
|
|
|
|
flags RenderMode: u32 {
|
|
|
|
static CpuRendering = 0x00000001,
|
|
|
|
static GpuRendering = 0x00000010,
|
|
|
|
static LinuxTarget = 0x00000100,
|
|
|
|
static MacOsTarget = 0x00001000,
|
|
|
|
static AndroidTarget = 0x00010000
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2014-07-28 06:26:18 +04:00
|
|
|
|
2013-07-19 02:25:10 +04:00
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
2014-03-04 21:34:47 +04:00
|
|
|
let mut parts = args.tail().split(|e| "--" == e.as_slice());
|
|
|
|
|
2014-06-22 16:27:01 +04:00
|
|
|
let harness_args = parts.next().unwrap(); // .split() is never empty
|
2014-03-04 21:34:47 +04:00
|
|
|
let servo_args = parts.next().unwrap_or(&[]);
|
|
|
|
|
2014-08-21 01:01:56 +04:00
|
|
|
let (render_mode_string, base_path, testname) = match harness_args {
|
|
|
|
[] | [_] => fail!("USAGE: cpu|gpu base_path [testname regex]"),
|
|
|
|
[ref render_mode_string, ref base_path] => (render_mode_string, base_path, None),
|
|
|
|
[ref render_mode_string, ref base_path, ref testname, ..] => (render_mode_string, base_path, Some(Regex::new(testname.as_slice()).unwrap())),
|
2014-06-22 16:27:01 +04:00
|
|
|
};
|
2012-06-26 09:45:15 +04:00
|
|
|
|
2014-08-22 02:53:27 +04:00
|
|
|
let mut render_mode = match render_mode_string.as_slice() {
|
2014-08-19 23:06:35 +04:00
|
|
|
"cpu" => CpuRendering,
|
|
|
|
"gpu" => GpuRendering,
|
|
|
|
_ => fail!("First argument must specify cpu or gpu as rendering mode")
|
2014-07-28 06:26:18 +04:00
|
|
|
};
|
2014-08-22 02:53:27 +04:00
|
|
|
if cfg!(target_os = "linux") {
|
|
|
|
render_mode.insert(LinuxTarget);
|
|
|
|
}
|
|
|
|
if cfg!(target_os = "macos") {
|
|
|
|
render_mode.insert(MacOsTarget);
|
|
|
|
}
|
|
|
|
if cfg!(target_os = "android") {
|
|
|
|
render_mode.insert(AndroidTarget);
|
|
|
|
}
|
2014-07-28 06:26:18 +04:00
|
|
|
|
2014-08-21 01:01:56 +04:00
|
|
|
let mut all_tests = vec!();
|
|
|
|
println!("Scanning {} for manifests\n", base_path);
|
|
|
|
|
|
|
|
for file in io::fs::walk_dir(&Path::new(base_path.as_slice())).unwrap() {
|
|
|
|
let maybe_extension = file.extension_str();
|
|
|
|
match maybe_extension {
|
|
|
|
Some(extension) => {
|
|
|
|
if extension.to_ascii_lower().as_slice() == "list" && file.is_file() {
|
2014-09-16 23:32:40 +04:00
|
|
|
let tests = parse_lists(&file, servo_args, render_mode, all_tests.len());
|
|
|
|
println!("\t{} [{} tests]", file.display(), tests.len());
|
2014-09-29 20:45:27 +04:00
|
|
|
all_tests.extend(tests.into_iter());
|
2014-08-21 01:01:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-19 02:25:10 +04:00
|
|
|
let test_opts = TestOpts {
|
2014-06-22 16:27:01 +04:00
|
|
|
filter: testname,
|
2012-06-26 09:45:15 +04:00
|
|
|
run_ignored: false,
|
2013-07-19 02:25:10 +04:00
|
|
|
logfile: None,
|
|
|
|
run_tests: true,
|
|
|
|
run_benchmarks: false,
|
2013-08-20 05:19:08 +04:00
|
|
|
ratchet_noise_percent: None,
|
|
|
|
ratchet_metrics: None,
|
|
|
|
save_metrics: None,
|
2013-10-22 20:16:17 +04:00
|
|
|
test_shard: None,
|
2014-05-23 04:14:24 +04:00
|
|
|
nocapture: false,
|
2014-06-28 05:25:07 +04:00
|
|
|
color: AutoColor
|
2013-07-19 02:25:10 +04:00
|
|
|
};
|
2012-06-26 09:45:15 +04:00
|
|
|
|
2014-08-21 01:01:56 +04:00
|
|
|
match run_tests_console(&test_opts, all_tests) {
|
2014-03-23 01:07:46 +04:00
|
|
|
Ok(false) => os::set_exit_status(1), // tests failed
|
|
|
|
Err(_) => os::set_exit_status(2), // I/O-related failure
|
2014-03-19 20:35:17 +04:00
|
|
|
_ => (),
|
2013-07-19 02:25:10 +04:00
|
|
|
}
|
2012-06-26 10:48:11 +04:00
|
|
|
}
|
|
|
|
|
2014-06-28 05:25:07 +04:00
|
|
|
#[deriving(PartialEq)]
|
2013-07-19 02:25:10 +04:00
|
|
|
enum ReftestKind {
|
|
|
|
Same,
|
|
|
|
Different,
|
2012-06-26 10:48:11 +04:00
|
|
|
}
|
|
|
|
|
2013-07-19 02:25:10 +04:00
|
|
|
struct Reftest {
|
2014-06-05 21:58:44 +04:00
|
|
|
name: String,
|
2013-07-19 02:25:10 +04:00
|
|
|
kind: ReftestKind,
|
2014-09-16 23:32:40 +04:00
|
|
|
files: [Path, ..2],
|
2013-11-01 03:34:14 +04:00
|
|
|
id: uint,
|
2014-06-05 21:58:44 +04:00
|
|
|
servo_args: Vec<String>,
|
2014-07-28 06:26:18 +04:00
|
|
|
render_mode: RenderMode,
|
2014-08-22 02:53:27 +04:00
|
|
|
is_flaky: bool,
|
2014-08-27 04:07:45 +04:00
|
|
|
experimental: bool,
|
2014-09-16 23:32:40 +04:00
|
|
|
fragment_identifier: Option<String>,
|
2014-08-01 10:42:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TestLine<'a> {
|
2014-08-19 23:06:35 +04:00
|
|
|
conditions: &'a str,
|
|
|
|
kind: &'a str,
|
|
|
|
file_left: &'a str,
|
|
|
|
file_right: &'a str,
|
2012-08-22 05:07:05 +04:00
|
|
|
}
|
|
|
|
|
2014-09-16 23:32:40 +04:00
|
|
|
fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_offset: uint) -> Vec<TestDescAndFn> {
|
2014-04-05 02:52:50 +04:00
|
|
|
let mut tests = Vec::new();
|
2014-09-16 23:32:40 +04:00
|
|
|
let contents = File::open_mode(file, io::Open, io::Read)
|
2014-08-19 23:06:35 +04:00
|
|
|
.and_then(|mut f| f.read_to_string())
|
|
|
|
.ok().expect("Could not read file");
|
2014-06-22 16:27:01 +04:00
|
|
|
|
|
|
|
for line in contents.as_slice().lines() {
|
2014-08-19 23:06:35 +04:00
|
|
|
// ignore comments or empty lines
|
|
|
|
if line.starts_with("#") || line.is_empty() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let parts: Vec<&str> = line.split(' ').filter(|p| !p.is_empty()).collect();
|
|
|
|
|
|
|
|
let test_line = match parts.len() {
|
|
|
|
3 => TestLine {
|
|
|
|
conditions: "",
|
|
|
|
kind: parts[0],
|
|
|
|
file_left: parts[1],
|
|
|
|
file_right: parts[2],
|
2014-08-01 10:42:10 +04:00
|
|
|
},
|
2014-08-19 23:06:35 +04:00
|
|
|
4 => TestLine {
|
|
|
|
conditions: parts[0],
|
|
|
|
kind: parts[1],
|
|
|
|
file_left: parts[2],
|
|
|
|
file_right: parts[3],
|
2014-08-01 10:42:10 +04:00
|
|
|
},
|
2014-08-19 23:06:35 +04:00
|
|
|
_ => 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)
|
|
|
|
};
|
2014-09-16 23:32:40 +04:00
|
|
|
let base = file.dir_path();
|
|
|
|
let file_left = base.join(test_line.file_left);
|
|
|
|
let file_right = base.join(test_line.file_right);
|
2014-08-19 23:06:35 +04:00
|
|
|
|
|
|
|
let mut conditions_list = test_line.conditions.split(',');
|
2014-08-22 02:53:27 +04:00
|
|
|
let mut flakiness = RenderMode::empty();
|
2014-08-27 04:07:45 +04:00
|
|
|
let mut experimental = false;
|
2014-09-16 23:32:40 +04:00
|
|
|
let mut fragment_identifier = None;
|
2014-08-19 23:06:35 +04:00
|
|
|
for condition in conditions_list {
|
|
|
|
match condition {
|
2014-08-22 02:53:27 +04:00
|
|
|
"flaky_cpu" => flakiness.insert(CpuRendering),
|
|
|
|
"flaky_gpu" => flakiness.insert(GpuRendering),
|
|
|
|
"flaky_linux" => flakiness.insert(LinuxTarget),
|
|
|
|
"flaky_macos" => flakiness.insert(MacOsTarget),
|
2014-08-27 04:07:45 +04:00
|
|
|
"experimental" => experimental = true,
|
2014-08-19 23:06:35 +04:00
|
|
|
_ => (),
|
|
|
|
}
|
2014-09-16 23:32:40 +04:00
|
|
|
if condition.starts_with("fragment=") {
|
|
|
|
fragment_identifier = Some(condition.slice_from("fragment=".len()).to_string());
|
|
|
|
}
|
2014-08-19 23:06:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let reftest = Reftest {
|
2014-08-22 02:53:27 +04:00
|
|
|
name: format!("{} {} {}", test_line.file_left, test_line.kind, test_line.file_right),
|
2014-08-19 23:06:35 +04:00
|
|
|
kind: kind,
|
|
|
|
files: [file_left, file_right],
|
2014-08-25 01:25:13 +04:00
|
|
|
id: id_offset + tests.len(),
|
2014-08-19 23:06:35 +04:00
|
|
|
render_mode: render_mode,
|
|
|
|
servo_args: servo_args.iter().map(|x| x.clone()).collect(),
|
2014-08-22 02:53:27 +04:00
|
|
|
is_flaky: render_mode.intersects(flakiness),
|
2014-08-27 04:07:45 +04:00
|
|
|
experimental: experimental,
|
2014-09-16 23:32:40 +04:00
|
|
|
fragment_identifier: fragment_identifier,
|
2014-08-19 23:06:35 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
tests.push(make_test(reftest));
|
2012-08-22 05:07:05 +04:00
|
|
|
}
|
2013-07-19 02:25:10 +04:00
|
|
|
tests
|
|
|
|
}
|
2012-08-22 05:07:05 +04:00
|
|
|
|
2013-07-19 02:25:10 +04:00
|
|
|
fn make_test(reftest: Reftest) -> TestDescAndFn {
|
|
|
|
let name = reftest.name.clone();
|
|
|
|
TestDescAndFn {
|
|
|
|
desc: TestDesc {
|
|
|
|
name: DynTestName(name),
|
|
|
|
ignore: false,
|
|
|
|
should_fail: false,
|
|
|
|
},
|
2014-01-13 07:16:21 +04:00
|
|
|
testfn: DynTestFn(proc() {
|
|
|
|
check_reftest(reftest);
|
2013-07-19 02:25:10 +04:00
|
|
|
}),
|
2012-08-22 05:07:05 +04:00
|
|
|
}
|
2013-07-19 02:25:10 +04:00
|
|
|
}
|
2012-08-22 05:07:05 +04:00
|
|
|
|
2014-08-27 18:49:40 +04:00
|
|
|
fn capture(reftest: &Reftest, side: uint) -> (u32, u32, Vec<u8>) {
|
2014-09-16 23:32:40 +04:00
|
|
|
let png_filename = format!("/tmp/servo-reftest-{:06u}-{:u}.png", reftest.id, side);
|
|
|
|
let mut command = Command::new("target/servo");
|
|
|
|
command
|
|
|
|
.args(reftest.servo_args.as_slice())
|
|
|
|
// Allows pixel perfect rendering of Ahem font for reftests.
|
|
|
|
.arg("--disable-text-aa")
|
|
|
|
.args(["-f", "-o"])
|
|
|
|
.arg(png_filename.as_slice())
|
|
|
|
.arg({
|
|
|
|
let mut url = Url::from_file_path(&reftest.files[side]).unwrap();
|
|
|
|
url.fragment = reftest.fragment_identifier.clone();
|
|
|
|
url.to_string()
|
|
|
|
});
|
2014-10-22 07:18:33 +04:00
|
|
|
// CPU rendering is the default
|
2014-08-22 02:53:27 +04:00
|
|
|
if reftest.render_mode.contains(CpuRendering) {
|
2014-09-16 23:32:40 +04:00
|
|
|
command.arg("-c");
|
2014-07-28 06:26:18 +04:00
|
|
|
}
|
2014-10-22 07:18:33 +04:00
|
|
|
if reftest.render_mode.contains(GpuRendering) {
|
|
|
|
command.arg("-g");
|
|
|
|
}
|
2014-08-27 04:07:45 +04:00
|
|
|
if reftest.experimental {
|
2014-09-16 23:32:40 +04:00
|
|
|
command.arg("--experimental");
|
2014-08-27 04:07:45 +04:00
|
|
|
}
|
2014-09-16 23:32:40 +04:00
|
|
|
let retval = match command.status() {
|
2014-03-19 20:35:17 +04:00
|
|
|
Ok(status) => status,
|
|
|
|
Err(e) => fail!("failed to execute process: {}", e),
|
|
|
|
};
|
2014-10-15 02:51:30 +04:00
|
|
|
assert_eq!(retval, ExitStatus(0));
|
2013-07-19 02:25:10 +04:00
|
|
|
|
2014-09-16 23:32:40 +04:00
|
|
|
let image = png::load_png(&from_str::<Path>(png_filename.as_slice()).unwrap()).unwrap();
|
2014-08-27 18:49:40 +04:00
|
|
|
let rgba8_bytes = match image.pixels {
|
|
|
|
png::RGBA8(pixels) => pixels,
|
|
|
|
_ => fail!(),
|
|
|
|
};
|
|
|
|
(image.width, image.height, rgba8_bytes)
|
2014-03-04 21:34:47 +04:00
|
|
|
}
|
2013-07-19 02:25:10 +04:00
|
|
|
|
2014-03-04 21:34:47 +04:00
|
|
|
fn check_reftest(reftest: Reftest) {
|
2014-08-27 18:49:40 +04:00
|
|
|
let (left_width, left_height, left_bytes) = capture(&reftest, 0);
|
|
|
|
let (right_width, right_height, right_bytes) = capture(&reftest, 1);
|
|
|
|
|
|
|
|
assert_eq!(left_width, right_width);
|
|
|
|
assert_eq!(left_height, right_height);
|
2014-01-24 12:19:01 +04:00
|
|
|
|
2014-10-15 00:42:33 +04:00
|
|
|
let left_all_white = left_bytes.iter().all(|&p| p == 255);
|
|
|
|
let right_all_white = right_bytes.iter().all(|&p| p == 255);
|
|
|
|
|
|
|
|
if left_all_white && right_all_white {
|
2014-10-18 10:24:25 +04:00
|
|
|
fail!("Both renderings are empty")
|
2014-10-15 00:42:33 +04:00
|
|
|
}
|
|
|
|
|
2014-08-27 18:49:40 +04:00
|
|
|
let pixels = left_bytes.iter().zip(right_bytes.iter()).map(|(&a, &b)| {
|
2014-08-19 23:06:35 +04:00
|
|
|
if a as i8 - b as i8 == 0 {
|
|
|
|
// White for correct
|
|
|
|
0xFF
|
|
|
|
} else {
|
|
|
|
// "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
|
|
|
|
// readable (and distinguishable) than the previous difference-wise
|
|
|
|
// scaling but does not require reconstructing the actual RGBA pixel.
|
|
|
|
0xC0
|
|
|
|
}
|
|
|
|
}).collect::<Vec<u8>>();
|
2014-01-24 12:19:01 +04:00
|
|
|
|
|
|
|
if pixels.iter().any(|&a| a < 255) {
|
2014-05-07 02:13:35 +04:00
|
|
|
let output_str = format!("/tmp/servo-reftest-{:06u}-diff.png", reftest.id);
|
2014-06-05 21:58:44 +04:00
|
|
|
let output = from_str::<Path>(output_str.as_slice()).unwrap();
|
2014-01-24 12:19:01 +04:00
|
|
|
|
2014-08-03 07:41:10 +04:00
|
|
|
let mut img = png::Image {
|
2014-08-27 18:49:40 +04:00
|
|
|
width: left_width,
|
|
|
|
height: left_height,
|
|
|
|
pixels: png::RGBA8(pixels),
|
2014-01-24 12:19:01 +04:00
|
|
|
};
|
2014-08-03 07:41:10 +04:00
|
|
|
let res = png::store_png(&mut img, &output);
|
2014-01-24 12:19:01 +04:00
|
|
|
assert!(res.is_ok());
|
2012-08-22 05:07:05 +04:00
|
|
|
|
2014-08-22 02:53:27 +04:00
|
|
|
match (reftest.kind, reftest.is_flaky) {
|
2014-08-19 23:06:35 +04:00
|
|
|
(Same, true) => println!("flaky test - rendering difference: {}", output_str),
|
|
|
|
(Same, false) => fail!("rendering difference: {}", output_str),
|
|
|
|
(Different, _) => {} // Result was different and that's what was expected
|
2014-08-01 10:42:10 +04:00
|
|
|
}
|
2014-01-24 12:19:01 +04:00
|
|
|
} else {
|
2014-08-22 02:53:27 +04:00
|
|
|
assert!(reftest.is_flaky || reftest.kind == Same);
|
2012-06-26 10:48:11 +04:00
|
|
|
}
|
2013-08-20 05:19:08 +04:00
|
|
|
}
|