Bug 1551611 - Introduce a ReftestEnvironment. r=Gankro
☠☠ backed out by bfddd8606240 ☠ ☠
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 15 May 2019 14:06:33 +0000
changeset 473956 df4a76b3e6ce045afbe647a2a99fbe6386fe296d
parent 473955 b41a2b5161801565b04b3bb41a1a1e77154b49e2
child 473957 85ac4e68a63e4cf49def39381105131d3520e813
push id113119
push userdvarga@mozilla.com
push dateWed, 15 May 2019 21:35:00 +0000
treeherdermozilla-inbound@0e8d68920793 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGankro
bugs1551611
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551611 - Introduce a ReftestEnvironment. r=Gankro This moves the existing constants into a ReftestEnvironment which encapsulates it a bit better. Also this fixes the incorrect "debug" cfg check to "debug_assertions" which is more correct. Differential Revision: https://phabricator.services.mozilla.com/D31181
gfx/wr/wrench/src/reftest.rs
--- a/gfx/wr/wrench/src/reftest.rs
+++ b/gfx/wr/wrench/src/reftest.rs
@@ -17,31 +17,16 @@ use std::path::{Path, PathBuf};
 use std::sync::mpsc::Receiver;
 use webrender::RenderResults;
 use webrender::api::*;
 use webrender::api::units::*;
 use crate::wrench::{Wrench, WrenchThing};
 use crate::yaml_frame_reader::YamlFrameReader;
 
 
-#[cfg(target_os = "windows")]
-const PLATFORM: &str = "win";
-#[cfg(target_os = "linux")]
-const PLATFORM: &str = "linux";
-#[cfg(target_os = "macos")]
-const PLATFORM: &str = "mac";
-#[cfg(target_os = "android")]
-const PLATFORM: &str = "android";
-#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "android")))]
-const PLATFORM: &str = "other";
-#[cfg(debug)]
-const MODE: &str = "debug";
-#[cfg(not(debug))]
-const MODE: &str = "release";
-
 const OPTION_DISABLE_SUBPX: &str = "disable-subpixel";
 const OPTION_DISABLE_AA: &str = "disable-aa";
 const OPTION_DISABLE_DUAL_SOURCE_BLENDING: &str = "disable-dual-source-blending";
 const OPTION_ALLOW_MIPMAPS: &str = "allow-mipmaps";
 
 pub struct ReftestOptions {
     // These override values that are lower.
     pub allow_max_difference: usize,
@@ -197,17 +182,17 @@ impl ReftestImage {
         format!("data:image/png;base64,{}", png_base64)
     }
 }
 
 struct ReftestManifest {
     reftests: Vec<Reftest>,
 }
 impl ReftestManifest {
-    fn new(manifest: &Path, options: &ReftestOptions) -> ReftestManifest {
+    fn new(manifest: &Path, environment: &ReftestEnvironment, options: &ReftestOptions) -> ReftestManifest {
         let dir = manifest.parent().unwrap();
         let f =
             File::open(manifest).expect(&format!("couldn't open manifest: {}", manifest.display()));
         let file = BufReader::new(&f);
 
         let mut reftests = Vec::new();
 
         for line in file.lines() {
@@ -235,32 +220,32 @@ impl ReftestManifest {
             let mut paths = vec![];
             for (i, token) in tokens.iter().enumerate() {
                 match *token {
                     "include" => {
                         assert!(i == 0, "include must be by itself");
                         let include = dir.join(tokens[1]);
 
                         reftests.append(
-                            &mut ReftestManifest::new(include.as_path(), options).reftests,
+                            &mut ReftestManifest::new(include.as_path(), environment, options).reftests,
                         );
 
                         break;
                     }
                     platform if platform.starts_with("skip_on") => {
                         // e.g. skip_on(android,debug) will skip only when
                         // running on a debug android build.
                         let (_, args, _) = parse_function(platform);
-                        if args.iter().all(|arg| arg == &PLATFORM || arg == &MODE) {
+                        if args.iter().all(|arg| environment.has(arg)) {
                             break;
                         }
                     }
                     platform if platform.starts_with("platform") => {
                         let (_, args, _) = parse_function(platform);
-                        if !args.iter().any(|arg| arg == &PLATFORM) {
+                        if !args.iter().any(|arg| arg == &environment.platform) {
                             // Skip due to platform not matching
                             break;
                         }
                     }
                     function if function.starts_with("zoom") => {
                         let (_, args, _) = parse_function(function);
                         zoom_factor = args[0].parse().unwrap();
                     }
@@ -357,28 +342,70 @@ impl ReftestManifest {
     }
 }
 
 struct YamlRenderOutput {
     image: ReftestImage,
     results: RenderResults,
 }
 
+struct ReftestEnvironment {
+    pub platform: &'static str,
+    pub mode: &'static str,
+}
+
+impl ReftestEnvironment {
+    fn new() -> Self {
+        Self {
+            platform: Self::platform(),
+            mode: Self::mode(),
+        }
+    }
+
+    fn has(&self, condition: &str) -> bool {
+        self.platform == condition || self.mode == condition
+    }
+
+    fn platform() -> &'static str {
+        if cfg!(target_os = "windows") {
+            "win"
+        } else if cfg!(target_os = "linux") {
+            "linux"
+        } else if cfg!(target_os = "macos") {
+            "mac"
+        } else if cfg!(target_os = "android") {
+            "android"
+        } else {
+            "other"
+        }
+    }
+
+    fn mode() -> &'static str {
+        if cfg!(debug_assertions) {
+            "debug"
+        } else {
+            "release"
+        }
+    }
+}
+
 pub struct ReftestHarness<'a> {
     wrench: &'a mut Wrench,
     window: &'a mut WindowWrapper,
     rx: &'a Receiver<NotifierEvent>,
+    environment: ReftestEnvironment,
 }
 impl<'a> ReftestHarness<'a> {
     pub fn new(wrench: &'a mut Wrench, window: &'a mut WindowWrapper, rx: &'a Receiver<NotifierEvent>) -> Self {
-        ReftestHarness { wrench, window, rx }
+        let environment = ReftestEnvironment::new();
+        ReftestHarness { wrench, window, rx, environment }
     }
 
     pub fn run(mut self, base_manifest: &Path, reftests: Option<&Path>, options: &ReftestOptions) -> usize {
-        let manifest = ReftestManifest::new(base_manifest, options);
+        let manifest = ReftestManifest::new(base_manifest, &self.environment, options);
         let reftests = manifest.find(reftests.unwrap_or(&PathBuf::new()));
 
         let mut total_passing = 0;
         let mut failing = Vec::new();
 
         for t in reftests {
             if self.run_reftest(t) {
                 total_passing += 1;