From 6bbab7570134379aca32722350da6690f999d6cc Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 25 Aug 2025 00:12:16 +0200 Subject: Detect leaks in test suite with Asan Leaks from libfontconfig.so are excluded for now, as it doesn't seem to be our fault. The gcc mechanism to suppress leaks doesn't seem to be working, so we fallback to awk. In the presence of leaks, that specific test will fail by returning non-zero, but this will not be what we want for those tests that are currently failing with XPASS. We will only consider the ones that are passing as those targeted for leak detection. --- test/html/Makefile.am | 1 + test/html/driver.sh | 15 ++++++++++++--- test/html/leakfilter.awk | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/html/leakfilter.awk diff --git a/test/html/Makefile.am b/test/html/Makefile.am index 29fb39f3..648d96c9 100644 --- a/test/html/Makefile.am +++ b/test/html/Makefile.am @@ -7,6 +7,7 @@ LOG_COMPILER = $(srcdir)/driver.sh EXTRA_DIST = \ driver.sh \ + leakfilter.awk \ manual \ render diff --git a/test/html/driver.sh b/test/html/driver.sh index e4fbc739..de753196 100755 --- a/test/html/driver.sh +++ b/test/html/driver.sh @@ -2,7 +2,7 @@ # # File: driver.sh # -# Copyright (C) 2023-2024 Rodrigo Arias Mallo +# Copyright (C) 2023-2025 Rodrigo Arias Mallo # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -13,6 +13,10 @@ set -e set -x DILLOBIN=${DILLOBIN:-$TOP_BUILDDIR/src/dillo} +LEAKFILTER=${LEAKFILTER:-$TOP_SRCDIR/test/html/leakfilter.awk} + +# Clean asan options if set +unset ASAN_OPTIONS if [ ! -e $DILLOBIN ]; then echo missing dillo binary, set DILLOBIN with the path to dillo @@ -28,7 +32,7 @@ function render_page() { htmlfile="$1" outpic="$2" - "$DILLOBIN" -f "$htmlfile" & + "$DILLOBIN" -f "$htmlfile" 2> dillo.err & dillopid=$! # TODO: We need a better system to determine when the page loaded @@ -53,7 +57,12 @@ function render_page() { fi xwd -id "$winid" -silent | ${magick_bin} xwd:- png:${outpic} - kill "$dillopid" + # Exit cleanly + kill -USR2 "$dillopid" + + # Dillo may fail due to leaks, but we will check them manually + wait "$dillopid" || true + awk -f "$LEAKFILTER" < dillo.err } function test_file() { diff --git a/test/html/leakfilter.awk b/test/html/leakfilter.awk new file mode 100644 index 00000000..381ed0a7 --- /dev/null +++ b/test/html/leakfilter.awk @@ -0,0 +1,14 @@ +# Detect beginning of leak message +/^Direct leak/ { msg=msg "\n" $0; inleak=1; next } + +# Ignore anything coming from libfontconfig.so +inleak && /libfontconfig.so/ { inleak=0; msg="" } + +# Store leak line +inleak && /^ +#/ { msg=msg "\n" $0; next } + +# End of the leak lines, print and finish +inleak { inleak=0; print msg; msg=""; nleaks++ } + +# At exit count filtered leaks and fail accordingly +END { printf "\n==== Total leaks after filter: %d ====\n\n", nleaks; if (nleaks > 0) { exit 1 } } -- cgit v1.2.3