mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Run size_of tests with test-stylo.
MozReview-Commit-ID: KapDMqX6OjH
This commit is contained in:
parent
9f44fd2d9d
commit
6744ed1639
8 changed files with 77 additions and 51 deletions
|
@ -211,11 +211,13 @@ class PropertiesData(object):
|
||||||
|
|
||||||
In this situation, the `product` value is ignored while choosing
|
In this situation, the `product` value is ignored while choosing
|
||||||
which shorthands and longhands to generate; and instead all properties for
|
which shorthands and longhands to generate; and instead all properties for
|
||||||
which code exists for either servo or stylo are generated.
|
which code exists for either servo or stylo are generated. Note that we skip
|
||||||
|
this behavior when the style crate is being built in gecko mode, because we
|
||||||
|
need manual glue for such properties and we don't have it.
|
||||||
"""
|
"""
|
||||||
def __init__(self, product, testing):
|
def __init__(self, product, testing):
|
||||||
self.product = product
|
self.product = product
|
||||||
self.testing = testing
|
self.testing = testing and product != "gecko"
|
||||||
self.style_structs = []
|
self.style_structs = []
|
||||||
self.current_style_struct = None
|
self.current_style_struct = None
|
||||||
self.longhands = []
|
self.longhands = []
|
||||||
|
|
|
@ -2387,17 +2387,62 @@ macro_rules! longhand_properties_idents {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retuns all longhands SpecifiedValue sizes. This is used in unit tests.
|
/// Testing function to check the size of a PropertyDeclaration. We implement
|
||||||
|
/// this here so that the code can be used by both servo and stylo unit tests.
|
||||||
|
/// This is important because structs can have different sizes in stylo and
|
||||||
|
/// servo.
|
||||||
#[cfg(feature = "testing")]
|
#[cfg(feature = "testing")]
|
||||||
pub fn specified_value_sizes() -> Vec<(&'static str, usize, bool)> {
|
pub fn test_size_of_property_declaration() {
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
let mut sizes = vec![];
|
|
||||||
|
|
||||||
|
let old = 48;
|
||||||
|
let new = size_of::<PropertyDeclaration>();
|
||||||
|
if new < old {
|
||||||
|
panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \
|
||||||
|
Good work! Please update the size in components/style/properties/properties.mako.rs.",
|
||||||
|
old, new)
|
||||||
|
} else if new > old {
|
||||||
|
panic!("Your changes have increased the stack size of PropertyDeclaration enum from {} to {}. \
|
||||||
|
These enum is present in large quantities in the style, and increasing the size \
|
||||||
|
may negatively affect style system performance. Please consider using `boxed=\"True\"` in \
|
||||||
|
the longhand If you feel that the increase is necessary, update to the new size in \
|
||||||
|
components/style/properties/properties.mako.rs.",
|
||||||
|
old, new)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Testing function to check the size of all SpecifiedValues.
|
||||||
|
#[cfg(feature = "testing")]
|
||||||
|
pub fn test_size_of_specified_values() {
|
||||||
|
use std::mem::size_of;
|
||||||
|
let threshold = 32;
|
||||||
|
|
||||||
|
let mut longhands = vec![];
|
||||||
% for property in data.longhands:
|
% for property in data.longhands:
|
||||||
sizes.push(("${property.name}",
|
longhands.push(("${property.name}",
|
||||||
size_of::<longhands::${property.ident}::SpecifiedValue>(),
|
size_of::<longhands::${property.ident}::SpecifiedValue>(),
|
||||||
${"true" if property.boxed else "false"}));
|
${"true" if property.boxed else "false"}));
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
sizes
|
let mut failing_messages = vec![];
|
||||||
|
|
||||||
|
for specified_value in longhands {
|
||||||
|
if specified_value.1 > threshold && !specified_value.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.",
|
||||||
|
specified_value.0, specified_value.1, threshold));
|
||||||
|
} else if specified_value.1 <= threshold && specified_value.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.",
|
||||||
|
specified_value.0, specified_value.1, threshold));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !failing_messages.is_empty() {
|
||||||
|
panic!("{}", failing_messages.join("\n\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ crate-type = ["staticlib", "rlib"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
bindgen = ["style/use_bindgen"]
|
bindgen = ["style/use_bindgen"]
|
||||||
|
testing = ["style/testing"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
atomic_refcell = "0.1"
|
atomic_refcell = "0.1"
|
||||||
|
|
|
@ -300,7 +300,7 @@ class MachCommands(CommandBase):
|
||||||
release = ["--release"] if release else []
|
release = ["--release"] if release else []
|
||||||
ret = 0
|
ret = 0
|
||||||
with cd(path.join("ports", "geckolib")):
|
with cd(path.join("ports", "geckolib")):
|
||||||
ret = call(["cargo", "test", "-p", "stylo_tests"] + release, env=env)
|
ret = call(["cargo", "test", "-p", "stylo_tests", "--features", "testing"] + release, env=env)
|
||||||
if ret != 0:
|
if ret != 0:
|
||||||
return ret
|
return ret
|
||||||
with cd(path.join("ports", "geckolib")):
|
with cd(path.join("ports", "geckolib")):
|
||||||
|
|
|
@ -2,51 +2,12 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use std::mem::size_of;
|
|
||||||
use style::properties::{PropertyDeclaration, specified_value_sizes};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn size_of_property_declaration() {
|
fn size_of_property_declaration() {
|
||||||
let old = 48;
|
::style::properties::test_size_of_property_declaration();
|
||||||
let new = size_of::<PropertyDeclaration>();
|
|
||||||
if new < old {
|
|
||||||
panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \
|
|
||||||
Good work! Please update the size in tests/unit/style/size_of.rs.",
|
|
||||||
old, new)
|
|
||||||
} else if new > old {
|
|
||||||
panic!("Your changes have increased the stack size of PropertyDeclaration enum from {} to {}. \
|
|
||||||
These enum is present in large quantities in the style, and increasing the size \
|
|
||||||
may negatively affect style system performance. Please consider using `boxed=\"True\"` in \
|
|
||||||
the longhand If you feel that the increase is necessary, update to the new size in \
|
|
||||||
tests/unit/style/size_of.rs.",
|
|
||||||
old, new)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn size_of_specified_values() {
|
fn size_of_specified_values() {
|
||||||
let threshold = 32;
|
::style::properties::test_size_of_specified_values();
|
||||||
let longhands = specified_value_sizes();
|
|
||||||
|
|
||||||
let mut failing_messages = vec![];
|
|
||||||
|
|
||||||
for specified_value in longhands {
|
|
||||||
if specified_value.1 > threshold && !specified_value.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.",
|
|
||||||
specified_value.0, specified_value.1, threshold));
|
|
||||||
} else if specified_value.1 <= threshold && specified_value.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.",
|
|
||||||
specified_value.0, specified_value.1, threshold));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !failing_messages.is_empty() {
|
|
||||||
panic!("{}", failing_messages.join("\n\n"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ name = "stylo_tests"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
|
[features]
|
||||||
|
testing = ["style/testing"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
app_units = "0.4"
|
app_units = "0.4"
|
||||||
atomic_refcell = "0.1"
|
atomic_refcell = "0.1"
|
||||||
|
|
|
@ -19,6 +19,7 @@ extern crate style;
|
||||||
extern crate style_traits;
|
extern crate style_traits;
|
||||||
|
|
||||||
mod sanity_checks;
|
mod sanity_checks;
|
||||||
|
mod size_of;
|
||||||
|
|
||||||
#[path = "../../../ports/geckolib/stylesheet_loader.rs"]
|
#[path = "../../../ports/geckolib/stylesheet_loader.rs"]
|
||||||
mod stylesheet_loader;
|
mod stylesheet_loader;
|
||||||
|
|
13
tests/unit/stylo/size_of.rs
Normal file
13
tests/unit/stylo/size_of.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn size_of_property_declaration() {
|
||||||
|
::style::properties::test_size_of_property_declaration();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn size_of_specified_values() {
|
||||||
|
::style::properties::test_size_of_specified_values();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue