Tests: the CSS, glow and .ai Zstandard guards count work instead of timing it

Three tests failed on a loaded machine because they asserted elapsed
time. Each now counts the work that the slow behavior it guards
against would repeat, with a counter compiled only into tests:

- The CSS cascade test counts selector tests, at most two per element
  (testing every rule against every element tests N x N). It styles
  5,000 elements, so the slow behavior fails on the count rather than
  on the hang guard, which now waits 300 s.
- The stacked-glow test counts the silhouettes drawn, 30 for 30 glows
  with and without the shadow cache.
- The Zstandard frames test counts the bytes looked at to find the
  zero padding.

The hang guards for invalid dash patterns, text layout and script
checks of a pipe wait 300 s instead of 20 s.
This commit is contained in:
dotCooCoo
2026-11-08 12:21:06 +07:00
committed by bflatastic
parent 0ce3147aab
commit 1d32aff63f
9 changed files with 83 additions and 18 deletions
+24
View File
@@ -10,6 +10,26 @@ use super::{
effects, fill_rule, peniko,
};
#[cfg(test)]
thread_local! {
/// How many silhouettes of drop shadows and outer glows renderers on this thread have drawn:
/// one per shadow or glow raster made ([`Renderer::shadow_raster`]) and per one drawn through a
/// filter layer ([`Renderer::draw_shadow_filter`]).
static SILHOUETTES: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
}
/// [`SILHOUETTES`] of this thread.
#[cfg(test)]
pub(super) fn silhouettes() -> u64 {
SILHOUETTES.get()
}
/// Adds one to [`SILHOUETTES`].
#[cfg(test)]
fn note_silhouette() {
SILHOUETTES.set(SILHOUETTES.get().saturating_add(1));
}
impl Renderer {
/// Drop shadow / outer glow `fx` (shadow-cache slot `i` of `n`) as a cached raster: the
/// silhouette `paint` draws is rendered once into a small crop, blurred and tinted on the CPU,
@@ -125,6 +145,8 @@ impl Renderer {
let decoded = crate::paint::decode_failures();
let outer_image_left_out = self.image_left_out.replace(false);
let pattern_images_left_out = crate::pattern::images_left_out();
#[cfg(test)]
note_silhouette();
self.inside_layer(|r| paint(r, &mut off, &shifted(&crop, dx, dy)));
let failed = crate::paint::decode_failures() - decoded;
let image_left_out = self.image_left_out.unwrap_or(false) || crate::pattern::images_left_out() > pattern_images_left_out;
@@ -230,6 +252,8 @@ impl Renderer {
// The offset moves the content rather than the filter: vello_cpu drops layer content
// that lies entirely outside the viewport before filtering.
let reach = reach + Vec2::new(dx, dy);
#[cfg(test)]
note_silhouette();
self.with_filters(ctx, f, reach, blur, Some((mode, opacity)), |r, c, fr, comp| {
c.set_transform(fr.view);
c.push_layer(None, comp.map(|m| blend_mode(m.0)), comp.map(|m| m.1), None, Some(filter));
+5 -3
View File
@@ -467,9 +467,10 @@ fn a_glow_too_large_for_a_full_size_raster_keeps_its_solid_silhouette() {
}
#[test]
fn thirty_stacked_glows_draw_quickly_cached_or_not() {
fn thirty_stacked_glows_draw_thirty_silhouettes_cached_or_not() {
// GUARDS: each glow is of the content with the glows before it; drawing those again for every glow costs 2^n.
// A shape draws through the shadow cache, a symbol instance without it (the filter layers).
// Each glow's silhouette is drawn once.
let glows: Vec<(&str, serde_json::Value)> =
(0..30).map(|k| ("stylize.outerGlow", json!({"color": "#ff0000", "mode": "normal", "opacity": 20, "blur": 1 + k % 4}))).collect();
let shape = doc_with(Rect::new(30.0, 30.0, 70.0, 70.0), Color::BLACK, glows.clone());
@@ -486,9 +487,10 @@ fn thirty_stacked_glows_draw_quickly_cached_or_not() {
let l = instanced.layers[0].id;
instanced.insert(Some(l), 0, instance).unwrap();
for d in [&shape, &instanced] {
let start = std::time::Instant::now();
let before = super::renderer::silhouettes();
let p = render(d).pixel(25, 50);
assert!(start.elapsed() < std::time::Duration::from_secs(20), "{:?}", start.elapsed());
let drawn = super::renderer::silhouettes() - before;
assert_eq!(drawn, 30, "silhouettes drawn for 30 glows");
assert!(p[1] < 250, "the glows show: {p:?}");
}
}
+1 -1
View File
@@ -1333,7 +1333,7 @@ fn invalid_dash_pattern_strokes_solid() {
let d = line(Some(pattern.clone()));
let (tx, rx) = std::sync::mpsc::channel();
std::thread::spawn(move || tx.send(render(&d)).ok());
let img = rx.recv_timeout(std::time::Duration::from_secs(20)).unwrap_or_else(|_| panic!("rendering dash {pattern:?} did not finish"));
let img = rx.recv_timeout(std::time::Duration::from_secs(300)).unwrap_or_else(|_| panic!("rendering dash {pattern:?} did not finish"));
assert_eq!(img.pixels, solid.pixels, "dash {pattern:?}");
}
}