summaryrefslogtreecommitdiffstats
path: root/servo/ports/geckolib/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--servo/ports/geckolib/tests/Cargo.toml27
-rw-r--r--servo/ports/geckolib/tests/lib.rs33
-rw-r--r--servo/ports/geckolib/tests/size_of.rs81
-rw-r--r--servo/ports/geckolib/tests/specified_values.rs50
4 files changed, 191 insertions, 0 deletions
diff --git a/servo/ports/geckolib/tests/Cargo.toml b/servo/ports/geckolib/tests/Cargo.toml
new file mode 100644
index 0000000000..663b205333
--- /dev/null
+++ b/servo/ports/geckolib/tests/Cargo.toml
@@ -0,0 +1,27 @@
+[package]
+name = "stylo_tests"
+version = "0.0.1"
+authors = ["The Servo Project Developers"]
+license = "MPL-2.0"
+
+[lib]
+name = "stylo_tests"
+path = "lib.rs"
+doctest = false
+
+[dependencies]
+atomic_refcell = "0.1"
+cssparser = "0.28"
+cstr = "0.2"
+env_logger = { version = "0.8", default-features = false }
+geckoservo = {path = "../../../ports/geckolib"}
+libc = "0.2"
+log = {version = "0.4", features = ["release_max_level_info"]}
+malloc_size_of = {path = "../../../components/malloc_size_of"}
+num-traits = "0.2"
+selectors = {path = "../../../components/selectors"}
+size_of_test = {path = "../../../components/size_of_test"}
+smallvec = "1.0"
+style_traits = {path = "../../../components/style_traits"}
+style = {path = "../../../components/style", features = ["gecko"]}
+to_shmem = {path = "../../../components/to_shmem"}
diff --git a/servo/ports/geckolib/tests/lib.rs b/servo/ports/geckolib/tests/lib.rs
new file mode 100644
index 0000000000..0addec4ab3
--- /dev/null
+++ b/servo/ports/geckolib/tests/lib.rs
@@ -0,0 +1,33 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+// Disable this entire crate on Windows when Gecko symbols are not available
+// as linking would fail:
+// https://github.com/rust-lang/rust/pull/44603#issuecomment-338807312
+//
+// On Linux and OS X linking succeeds anyway.
+// Presumably these symbol declarations don’t need to be resolved
+// as they’re not used in any code called from this crate.
+#![cfg(any(linking_with_gecko, not(windows)))]
+
+extern crate atomic_refcell;
+extern crate cssparser;
+extern crate cstr;
+extern crate geckoservo;
+extern crate log;
+extern crate malloc_size_of;
+extern crate num_traits;
+extern crate selectors;
+extern crate smallvec;
+#[cfg(target_pointer_width = "64")]
+#[macro_use]
+extern crate size_of_test;
+#[cfg_attr(target_pointer_width = "64", macro_use)]
+extern crate style;
+extern crate style_traits;
+extern crate to_shmem;
+
+#[cfg(target_pointer_width = "64")]
+mod size_of;
+mod specified_values;
diff --git a/servo/ports/geckolib/tests/size_of.rs b/servo/ports/geckolib/tests/size_of.rs
new file mode 100644
index 0000000000..d19522a2e2
--- /dev/null
+++ b/servo/ports/geckolib/tests/size_of.rs
@@ -0,0 +1,81 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+use selectors;
+use style;
+use style::applicable_declarations::ApplicableDeclarationBlock;
+use style::data::{ElementData, ElementStyles};
+use style::gecko::selector_parser::{self, SelectorImpl};
+use style::properties::ComputedValues;
+use style::rule_tree::{RULE_NODE_SIZE, StrongRuleNode};
+use style::servo_arc::Arc;
+use style::values::computed;
+use style::values::specified;
+
+size_of_test!(
+ size_of_selector,
+ selectors::parser::Selector<SelectorImpl>,
+ 8
+);
+size_of_test!(size_of_pseudo_element, selector_parser::PseudoElement, 16);
+
+size_of_test!(
+ size_of_component,
+ selectors::parser::Component<SelectorImpl>,
+ 24
+);
+size_of_test!(size_of_pseudo_class, selector_parser::NonTSPseudoClass, 16);
+
+// The size of this is critical to performance on the bloom-basic microbenchmark.
+// When iterating over a large Rule array, we want to be able to fast-reject
+// selectors (with the inline hashes) with as few cache misses as possible.
+size_of_test!(test_size_of_rule, style::stylist::Rule, 32);
+
+// Large pages generate tens of thousands of ComputedValues.
+size_of_test!(test_size_of_cv, ComputedValues, 224);
+
+size_of_test!(test_size_of_option_arc_cv, Option<Arc<ComputedValues>>, 8);
+size_of_test!(test_size_of_option_rule_node, Option<StrongRuleNode>, 8);
+
+size_of_test!(test_size_of_element_styles, ElementStyles, 16);
+size_of_test!(test_size_of_element_data, ElementData, 24);
+
+size_of_test!(
+ test_size_of_property_declaration,
+ style::properties::PropertyDeclaration,
+ 32
+);
+
+size_of_test!(
+ test_size_of_application_declaration_block,
+ ApplicableDeclarationBlock,
+ 16
+);
+
+#[test]
+fn test_size_of_rule_node() {
+ assert_eq!(RULE_NODE_SIZE, 80, "RuleNode size changed");
+}
+
+// This is huge, but we allocate it on the stack and then never move it,
+// we only pass `&mut SourcePropertyDeclaration` references around.
+size_of_test!(
+ test_size_of_parsed_declaration,
+ style::properties::SourcePropertyDeclaration,
+ 600
+);
+
+size_of_test!(test_size_of_computed_image, computed::image::Image, 16);
+size_of_test!(test_size_of_specified_image, specified::image::Image, 16);
+
+size_of_test!(
+ test_size_of_computed_image_layer,
+ computed::image::Image,
+ 16
+);
+size_of_test!(
+ test_size_of_specified_image_layer,
+ specified::image::Image,
+ 16
+);
diff --git a/servo/ports/geckolib/tests/specified_values.rs b/servo/ports/geckolib/tests/specified_values.rs
new file mode 100644
index 0000000000..744bf1fd80
--- /dev/null
+++ b/servo/ports/geckolib/tests/specified_values.rs
@@ -0,0 +1,50 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#[cfg(all(test, target_pointer_width = "64"))]
+#[test]
+fn size_of_specified_values() {
+ use std::mem::size_of;
+ use style;
+
+ let threshold = 24;
+
+ let mut bad_properties = vec![];
+
+ macro_rules! check_property {
+ ( $( { $name: ident, $boxed: expr } )+ ) => {
+ $(
+ let size = size_of::<style::properties::longhands::$name::SpecifiedValue>();
+ let is_boxed = $boxed;
+ if (!is_boxed && size > threshold) || (is_boxed && size <= threshold) {
+ bad_properties.push((stringify!($name), size, is_boxed));
+ }
+ )+
+ }
+ }
+
+ longhand_properties_idents!(check_property);
+
+ let mut failing_messages = vec![];
+
+ for bad_prop in bad_properties {
+ if !bad_prop.2 {
+ failing_messages.push(
+ format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \
+ currently {}. SpecifiedValues affect size of PropertyDeclaration enum and \
+ increasing the size may negative affect style system performance. Please consider \
+ using `boxed=\"True\"` in this longhand.",
+ bad_prop.0, bad_prop.1, threshold));
+ } else if bad_prop.2 {
+ failing_messages.push(
+ format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \
+ The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.",
+ bad_prop.0, bad_prop.1, threshold));
+ }
+ }
+
+ if !failing_messages.is_empty() {
+ panic!("{}", failing_messages.join("\n\n"));
+ }
+}