From 561f7e594e13dd52764abcc75c97cc3b1e039cc1 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 21 Mar 2015 12:18:23 +0100 Subject: [PATCH 1/4] Update rust-png. --- components/servo/Cargo.lock | 4 ++-- ports/cef/Cargo.lock | 4 ++-- ports/gonk/Cargo.lock | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 1702516ae80..3e289cf5f2a 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -686,7 +686,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "png" version = "0.1.0" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" dependencies = [ "gcc 0.3.1 (git+https://github.com/alexcrichton/gcc-rs)", "png-sys 1.6.16 (git+https://github.com/servo/rust-png)", @@ -695,7 +695,7 @@ dependencies = [ [[package]] name = "png-sys" version = "1.6.16" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" [[package]] name = "rand" diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 18cc8ae41ed..555abedf97c 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -692,7 +692,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "png" version = "0.1.0" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" dependencies = [ "gcc 0.3.1 (git+https://github.com/alexcrichton/gcc-rs)", "png-sys 1.6.16 (git+https://github.com/servo/rust-png)", @@ -701,7 +701,7 @@ dependencies = [ [[package]] name = "png-sys" version = "1.6.16" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" [[package]] name = "rand" diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index d0f15a159ae..47ec887aa88 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -616,7 +616,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "png" version = "0.1.0" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" dependencies = [ "gcc 0.3.1 (git+https://github.com/alexcrichton/gcc-rs)", "png-sys 1.6.16 (git+https://github.com/servo/rust-png)", @@ -625,7 +625,7 @@ dependencies = [ [[package]] name = "png-sys" version = "1.6.16" -source = "git+https://github.com/servo/rust-png#da851d68159fe0a7dba81dfbee594e5226b72884" +source = "git+https://github.com/servo/rust-png#1d9c59c97598014860077f372443ae98b35ff4d9" [[package]] name = "rand" From 2fde574b391689f0690d246e81621fc2972aeb7a Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 21 Mar 2015 13:29:28 +0100 Subject: [PATCH 2/4] Pass path strings to {load,store}_png directly. This has been made possible by using the AsPath trait upstream. --- tests/reftest.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/reftest.rs b/tests/reftest.rs index 978a8f45318..4dfe41530cf 100644 --- a/tests/reftest.rs +++ b/tests/reftest.rs @@ -277,8 +277,7 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec) { }; assert_eq!(retval, ExitStatus(0)); - let path = png_filename.parse::().unwrap(); - let image = png::load_png(&path).unwrap(); + let image = png::load_png(&png_filename).unwrap(); let rgba8_bytes = match image.pixels { png::PixelsByColorType::RGBA8(pixels) => pixels, _ => panic!(), @@ -319,8 +318,7 @@ fn check_reftest(reftest: Reftest) { }).collect::>(); if pixels.iter().any(|&a| a < 255) { - let output_str = format!("/tmp/servo-reftest-{:06}-diff.png", reftest.id); - let output = output_str.parse::().unwrap(); + let output = format!("/tmp/servo-reftest-{:06}-diff.png", reftest.id); let mut img = png::Image { width: left_width, @@ -331,8 +329,8 @@ fn check_reftest(reftest: Reftest) { assert!(res.is_ok()); match (reftest.kind, reftest.is_flaky) { - (ReftestKind::Same, true) => println!("flaky test - rendering difference: {}", output_str), - (ReftestKind::Same, false) => panic!("rendering difference: {}", output_str), + (ReftestKind::Same, true) => println!("flaky test - rendering difference: {}", output), + (ReftestKind::Same, false) => panic!("rendering difference: {}", output), (ReftestKind::Different, _) => {} // Result was different and that's what was expected } } else { From 061d0c94ecdfd6e07d9f5f6fdc24629d01c0a035 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 21 Mar 2015 13:29:49 +0100 Subject: [PATCH 3/4] Move to new path and io APIs in reftest.rs. --- tests/reftest.rs | 54 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/tests/reftest.rs b/tests/reftest.rs index 4dfe41530cf..23de22a0a57 100644 --- a/tests/reftest.rs +++ b/tests/reftest.rs @@ -7,25 +7,24 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(collections, core, env, io, hash, os, path, std_misc, test)] +#![feature(collections, core, exit_status, fs_walk, io, old_io, path, path_ext, std_misc, test)] #[macro_use] extern crate bitflags; extern crate png; extern crate test; extern crate url; -use std::ascii::AsciiExt; use std::env; -use std::old_io as io; -use std::old_io::{File, Reader, Command, IoResult}; -use std::old_io::process::ExitStatus; -use std::old_io::fs::PathExtensions; -use std::old_path::Path; +use std::ffi::OsStr; +use std::fs::{PathExt, File, walk_dir}; +use std::io::Read; +use std::old_io::{Reader, IoResult}; +use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; use std::thunk::Thunk; use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn, ShouldPanic}; use test::run_tests_console; use url::Url; - bitflags!( flags RenderMode: u32 { const CPU_RENDERING = 0x00000001, @@ -68,11 +67,12 @@ fn main() { let mut all_tests = vec!(); println!("Scanning {} for manifests\n", base_path); - for file in io::fs::walk_dir(&Path::new(base_path)).unwrap() { - let maybe_extension = file.extension_str(); + for file in walk_dir(base_path).unwrap() { + let file = file.unwrap().path(); + let maybe_extension = file.extension(); match maybe_extension { Some(extension) => { - if extension.to_ascii_lowercase().as_slice() == "list" && file.is_file() { + if extension == OsStr::from_str("list") && file.is_file() { let mut tests = parse_lists(&file, servo_args, render_mode, all_tests.len()); println!("\t{} [{} tests]", file.display(), tests.len()); all_tests.append(&mut tests); @@ -106,12 +106,11 @@ fn run(test_opts: TestOpts, all_tests: Vec, // Verify that we're passing in valid servo arguments. Otherwise, servo // will exit before we've run any tests, and it will appear to us as if // all the tests are failing. - let mut command = match Command::new(servo_path()) - .args(servo_args.as_slice()).spawn() { + let output = match Command::new(&servo_path()).args(&servo_args).output() { Ok(p) => p, Err(e) => panic!("failed to execute process: {}", e), }; - let stderr = command.stderr.as_mut().unwrap().read_to_string().unwrap(); + let stderr = String::from_utf8(output.stderr).unwrap(); if stderr.as_slice().contains("Unrecognized") { println!("Servo: {}", stderr.as_slice()); @@ -130,7 +129,7 @@ enum ReftestKind { struct Reftest { name: String, kind: ReftestKind, - files: [Path; 2], + files: [PathBuf; 2], id: usize, servo_args: Vec, render_mode: RenderMode, @@ -149,9 +148,12 @@ struct TestLine<'a> { fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_offset: usize) -> Vec { let mut tests = Vec::new(); - let contents = File::open_mode(file, io::Open, io::Read) - .and_then(|mut f| f.read_to_string()) - .ok().expect("Could not read file"); + let contents = { + let mut f = File::open(file).unwrap(); + let mut contents = String::new(); + f.read_to_string(&mut contents).unwrap(); + contents + }; for line in contents.as_slice().lines() { // ignore comments or empty lines @@ -183,7 +185,7 @@ fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_o part => panic!("reftest line: '{}' has invalid kind '{}'", line, part) }; - let base = Path::new(env::current_dir().unwrap().to_str().unwrap()).join(file.dir_path()); + let base = env::current_dir().unwrap().join(file.parent().unwrap()); let file_left = base.join(test_line.file_left); let file_right = base.join(test_line.file_right); @@ -244,16 +246,18 @@ fn make_test(reftest: Reftest) -> TestDescAndFn { fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec) { let png_filename = format!("/tmp/servo-reftest-{:06}-{}.png", reftest.id, side); - let mut command = Command::new(servo_path()); + let mut command = Command::new(&servo_path()); command + .stdout(Stdio::null()) + .stderr(Stdio::null()) .args(&reftest.servo_args[..]) // Allows pixel perfect rendering of Ahem font for reftests. .arg("-Z") .arg("disable-text-aa") .args(["-f", "-o"].as_slice()) .arg(png_filename.as_slice()) - .arg({ - let mut url = Url::from_file_path(&reftest.files[side]).unwrap(); + .arg(&{ + let mut url = Url::from_file_path(&*reftest.files[side]).unwrap(); url.fragment = reftest.fragment_identifier.clone(); url.to_string() }); @@ -275,7 +279,7 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec) { Ok(status) => status, Err(e) => panic!("failed to execute process: {}", e), }; - assert_eq!(retval, ExitStatus(0)); + assert!(retval.success()); let image = png::load_png(&png_filename).unwrap(); let rgba8_bytes = match image.pixels { @@ -285,9 +289,9 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec) { (image.width, image.height, rgba8_bytes) } -fn servo_path() -> Path { +fn servo_path() -> PathBuf { let current_exe = env::current_exe().ok().expect("Could not locate current executable"); - Path::new(current_exe.to_str().unwrap()).dir_path().join("servo") + current_exe.parent().unwrap().join("servo") } fn check_reftest(reftest: Reftest) { From 8dcded5f4d022e1da5f8535f4d75c9312d9937b8 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 21 Mar 2015 13:24:26 +0100 Subject: [PATCH 4/4] Remove the core feature from reftests. --- tests/reftest.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/reftest.rs b/tests/reftest.rs index 23de22a0a57..4ce8a96cdcb 100644 --- a/tests/reftest.rs +++ b/tests/reftest.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(collections, core, exit_status, fs_walk, io, old_io, path, path_ext, std_misc, test)] +#![feature(collections, exit_status, fs_walk, io, old_io, path, path_ext, std_misc, test)] #[macro_use] extern crate bitflags; extern crate png; extern crate test; @@ -38,7 +38,7 @@ bitflags!( fn main() { let args: Vec = env::args().collect(); - let mut parts = args.tail().split(|e| "--" == e.as_slice()); + let mut parts = args.tail().split(|e| &**e == "--"); let harness_args = parts.next().unwrap(); // .split() is never empty let servo_args = parts.next().unwrap_or(&[]); @@ -49,7 +49,7 @@ fn main() { [ref render_mode_string, ref base_path, ref testname, ..] => (render_mode_string, base_path, Some(testname.clone())), }; - let mut render_mode = match render_mode_string.as_slice() { + let mut render_mode = match &**render_mode_string { "cpu" => CPU_RENDERING, "gpu" => GPU_RENDERING, _ => panic!("First argument must specify cpu or gpu as rendering mode") @@ -112,8 +112,8 @@ fn run(test_opts: TestOpts, all_tests: Vec, }; let stderr = String::from_utf8(output.stderr).unwrap(); - if stderr.as_slice().contains("Unrecognized") { - println!("Servo: {}", stderr.as_slice()); + if stderr.contains("Unrecognized") { + println!("Servo: {}", stderr); return Ok(false); } @@ -155,7 +155,7 @@ fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_o contents }; - for line in contents.as_slice().lines() { + for line in contents.lines() { // ignore comments or empty lines if line.starts_with("#") || line.is_empty() { continue; @@ -254,8 +254,8 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec) { // Allows pixel perfect rendering of Ahem font for reftests. .arg("-Z") .arg("disable-text-aa") - .args(["-f", "-o"].as_slice()) - .arg(png_filename.as_slice()) + .args(&["-f", "-o"]) + .arg(&png_filename) .arg(&{ let mut url = Url::from_file_path(&*reftest.files[side]).unwrap(); url.fragment = reftest.fragment_identifier.clone();