diff mbox series

[2/2] librsvg: add ptest support

Message ID 20250805063925.771875-2-skandigraun@gmail.com
State New
Headers show
Series [1/2] librsvg: upgrade 2.59.2 -> 2.60.0 | expand

Commit Message

Gyorgy Sarvari Aug. 5, 2025, 6:39 a.m. UTC
The tests execution is quick, on my machine it's ~5 seconds.

One test looks broken, for which a patch was submitted upstream:
the test tries to load a file using a local URL, however it uses
a relative path (including ".."), while the base is not root, but
the current directory. Strictly speaking this is not a valid
file:// url, and Rust's url crate does transforms it by removing
the ".." and "." sections, thus pointing to a non-existing file.

To solve it, the change detects the absolute path of the resource before
loading it as a url.

One note about the installation location: the test executable
looks for the other resources by a hardcoded relative path always,
which starts with "../..", so the test binary needs to be 2 directory
deep compared to the testdata folder, this is why it is embedded in
./tests/bin folder (the naming is arbitrary, but the depth is specific).

Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
---
 .../distro/include/ptest-packagelists.inc     |  1 +
 ...01-fix-handle_new_from_file-api-test.patch | 56 +++++++++++++++++++
 meta/recipes-gnome/librsvg/librsvg/run-ptest  |  2 +
 meta/recipes-gnome/librsvg/librsvg_2.60.0.bb  | 30 +++++++++-
 4 files changed, 86 insertions(+), 3 deletions(-)
 create mode 100644 meta/recipes-gnome/librsvg/librsvg/0001-fix-handle_new_from_file-api-test.patch
 create mode 100644 meta/recipes-gnome/librsvg/librsvg/run-ptest

Comments

Alexander Kanavin Aug. 5, 2025, 8:43 a.m. UTC | #1
On Tue, 5 Aug 2025 at 08:39, Gyorgy Sarvari via lists.openembedded.org
<skandigraun=gmail.com@lists.openembedded.org> wrote:
> +do_install_ptest(){
> +       install -d  ${D}${PTEST_PATH}/tests/bin \
> +                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/api \
> +                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions \
> +                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading
> +
> +       install ${B}/librsvg-c/tests-c/api ${D}${PTEST_PATH}/tests/bin/
> +       install ${S}/rsvg/tests/fixtures/api/* ${D}${PTEST_PATH}/rsvg/tests/fixtures/api/
> +
> +       install ${S}/rsvg/tests/fixtures/dimensions/bug608102.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
> +       install ${S}/rsvg/tests/fixtures/dimensions/bug612951.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
> +       install ${S}/rsvg/tests/fixtures/dimensions/bug614018.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
> +       install ${S}/rsvg/tests/fixtures/dimensions/sub-rect-no-unit.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
> +       install ${S}/rsvg/tests/fixtures/dimensions/bug521-with-viewbox.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
> +       install ${S}/rsvg/tests/fixtures/dimensions/bug823-position-sub.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
> +
> +       install ${S}/rsvg/tests/fixtures/loading/bar.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
> +       install ${S}/rsvg/tests/fixtures/loading/gnome-cool.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
> +       install ${S}/rsvg/tests/fixtures/loading/gnome-cool.svgz ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
> +}

Cherry-picking particular files from tests/ is prone to regressions
(for example if new tests are added, they won't be installed). Is it
possible to just install all of ${S}/rsvg/tests/ ?

Better yet, add a patch to install tests to upstream. Gnome components
are generally doing that already, and there are examples (e.g.
installed_tests option in glib or gstreamer that is used by respective
recipes).

Alex
Gyorgy Sarvari Aug. 5, 2025, 9:02 a.m. UTC | #2
On 8/5/25 10:43, Alexander Kanavin wrote:
> On Tue, 5 Aug 2025 at 08:39, Gyorgy Sarvari via lists.openembedded.org
> <skandigraun=gmail.com@lists.openembedded.org> wrote:
>> +do_install_ptest(){
>> +       install -d  ${D}${PTEST_PATH}/tests/bin \
>> +                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/api \
>> +                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions \
>> +                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading
>> +
>> +       install ${B}/librsvg-c/tests-c/api ${D}${PTEST_PATH}/tests/bin/
>> +       install ${S}/rsvg/tests/fixtures/api/* ${D}${PTEST_PATH}/rsvg/tests/fixtures/api/
>> +
>> +       install ${S}/rsvg/tests/fixtures/dimensions/bug608102.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
>> +       install ${S}/rsvg/tests/fixtures/dimensions/bug612951.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
>> +       install ${S}/rsvg/tests/fixtures/dimensions/bug614018.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
>> +       install ${S}/rsvg/tests/fixtures/dimensions/sub-rect-no-unit.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
>> +       install ${S}/rsvg/tests/fixtures/dimensions/bug521-with-viewbox.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
>> +       install ${S}/rsvg/tests/fixtures/dimensions/bug823-position-sub.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
>> +
>> +       install ${S}/rsvg/tests/fixtures/loading/bar.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
>> +       install ${S}/rsvg/tests/fixtures/loading/gnome-cool.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
>> +       install ${S}/rsvg/tests/fixtures/loading/gnome-cool.svgz ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
>> +}
> Cherry-picking particular files from tests/ is prone to regressions
> (for example if new tests are added, they won't be installed). Is it
> possible to just install all of ${S}/rsvg/tests/ ?

I think this shouldn't be a problem. Will include that in v2, at least.

> Better yet, add a patch to install tests to upstream. Gnome components
> are generally doing that already, and there are examples (e.g.
> installed_tests option in glib or gstreamer that is used by respective
> recipes).
I have take a look at this during the day. Looking at what the gstreamer
patches do, it looks doable - will take a stab at it, and see if I can
make it get anywhere.

> Alex
diff mbox series

Patch

diff --git a/meta/conf/distro/include/ptest-packagelists.inc b/meta/conf/distro/include/ptest-packagelists.inc
index e3099439f4..a85f4c8a5d 100644
--- a/meta/conf/distro/include/ptest-packagelists.inc
+++ b/meta/conf/distro/include/ptest-packagelists.inc
@@ -33,6 +33,7 @@  PTESTS_FAST = "\
     libgpg-error\
     libnl \
     libpcre \
+    librsvg \
     libssh2 \
     libtest-fatal-perl \
     libtest-needs-perl \
diff --git a/meta/recipes-gnome/librsvg/librsvg/0001-fix-handle_new_from_file-api-test.patch b/meta/recipes-gnome/librsvg/librsvg/0001-fix-handle_new_from_file-api-test.patch
new file mode 100644
index 0000000000..1e0d9e3d96
--- /dev/null
+++ b/meta/recipes-gnome/librsvg/librsvg/0001-fix-handle_new_from_file-api-test.patch
@@ -0,0 +1,56 @@ 
+From 061a87860995f89f091ca63fe88b630549f78b0f Mon Sep 17 00:00:00 2001
+From: Gyorgy Sarvari <skandigraun@gmail.com>
+Date: Sun, 3 Aug 2025 20:50:30 +0200
+Subject: [PATCH] fix handle_new_from_file api test
+
+The test that verifies that files can be loaded using an url (file://)
+constructs a url using relative path, using the current directory as
+the base (e.g. file://./tests/bin/../../rsvg/tests/foo..svg).
+
+Since the base is not "/", this makes this url invalid, and the test fails.
+
+Instead of the relative path, determine the absolute path of the test file,
+and construct the url from that.
+
+Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/1122]
+
+Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
+---
+ librsvg-c/tests-c/api.c | 10 +++++++++-
+ 1 file changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/librsvg-c/tests-c/api.c b/librsvg-c/tests-c/api.c
+index 79b5357d..7b0e1295 100644
+--- a/librsvg-c/tests-c/api.c
++++ b/librsvg-c/tests-c/api.c
+@@ -13,6 +13,7 @@
+ #include <stdio.h>
+ #include <glib.h>
+ #include <cairo.h>
++#include <stdlib.h>
+ 
+ #define RSVG_DISABLE_DEPRECATION_WARNINGS /* so we can test deprecated API */
+ #include <librsvg/rsvg.h>
+@@ -426,7 +427,13 @@ static void
+ handle_new_from_file (void)
+ {
+     char *filename = get_test_filename ("dpi.svg");
+-    char *uri = g_strconcat ("file://", filename, NULL);
++#ifdef _WIN32
++    char abs_path[1024];
++    _fullpath(abs_path, filename, 1024);
++#else
++    char *abs_path = realpath(filename, NULL);
++#endif
++    char *uri = g_strconcat ("file://", abs_path, NULL);
+ 
+     RsvgHandle *handle;
+     GError *error = NULL;
+@@ -444,6 +451,7 @@ handle_new_from_file (void)
+     g_object_unref (handle);
+ 
+     g_free (filename);
++    g_free (abs_path);
+     g_free (uri);
+ }
+ 
diff --git a/meta/recipes-gnome/librsvg/librsvg/run-ptest b/meta/recipes-gnome/librsvg/librsvg/run-ptest
new file mode 100644
index 0000000000..c2daf916b0
--- /dev/null
+++ b/meta/recipes-gnome/librsvg/librsvg/run-ptest
@@ -0,0 +1,2 @@ 
+#!/bin/sh
+./tests/bin/api
diff --git a/meta/recipes-gnome/librsvg/librsvg_2.60.0.bb b/meta/recipes-gnome/librsvg/librsvg_2.60.0.bb
index 5cf0a46fd1..5d049a6871 100644
--- a/meta/recipes-gnome/librsvg/librsvg_2.60.0.bb
+++ b/meta/recipes-gnome/librsvg/librsvg_2.60.0.bb
@@ -13,7 +13,7 @@  SECTION = "x11/utils"
 DEPENDS = "cairo gdk-pixbuf glib-2.0 libxml2 pango python3-docutils-native cargo-c-native"
 BBCLASSEXTEND = "native nativesdk"
 
-inherit cargo_common gnomebase pixbufcache gobject-introspection rust vala gi-docgen cargo-update-recipe-crates
+inherit cargo_common gnomebase pixbufcache gobject-introspection rust vala gi-docgen cargo-update-recipe-crates ptest
 GIR_MESON_ENABLE_FLAG = 'enabled'
 GIR_MESON_DISABLE_FLAG = 'disabled'
 GIDOCGEN_MESON_OPTION = 'docs'
@@ -22,7 +22,9 @@  GIDOCGEN_MESON_DISABLE_FLAG = 'disabled'
 
 require ${BPN}-crates.inc
 
-SRC_URI += "file://0001-query-rustc-append-RUSTFLAGS-to-rustc-executable.patch"
+SRC_URI += "file://0001-query-rustc-append-RUSTFLAGS-to-rustc-executable.patch \
+            file://0001-fix-handle_new_from_file-api-test.patch \
+            file://run-ptest"
 
 SRC_URI[archive.sha256sum] = "0b6ffccdf6e70afc9876882f5d2ce9ffcf2c713cbaaf1ad90170daa752e1eec3"
 
@@ -58,17 +60,39 @@  LDFLAGS += " -L${B}/rsvg"
 # needed on ubuntu 20.04/debian 11 to avoid 'undefined reference to `dlsym'' errors
 BUILD_LDFLAGS += " -ldl"
 
-PACKAGECONFIG ??= "gdkpixbuf"
+PACKAGECONFIG ??= "gdkpixbuf ${@bb.utils.contains('PTEST_ENABLED', '1', 'tests', '', d)}"
 PACKAGECONFIG:append:class-target = " ${@bb.utils.contains('GI_DATA_ENABLED', 'True', 'vala', '', d)}"
 # The gdk-pixbuf loader
 PACKAGECONFIG[gdkpixbuf] = "-Dpixbuf-loader=enabled,-Dpixbuf-loader=disabled,gdk-pixbuf-native"
 PACKAGECONFIG[vala] = "-Dvala=enabled,-Dvala=disabled"
+PACKAGECONFIG[tests] = "-Dtests=true,-Dtests=false"
 
 do_install:append() {
 	# Loadable modules don't need .a or .la on Linux
 	rm -f ${D}${libdir}/gdk-pixbuf-2.0/*/loaders/*.a ${D}${libdir}/gdk-pixbuf-2.0/*/loaders/*.la
 }
 
+do_install_ptest(){
+       install -d  ${D}${PTEST_PATH}/tests/bin \
+                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/api \
+                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions \
+                   ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading
+
+       install ${B}/librsvg-c/tests-c/api ${D}${PTEST_PATH}/tests/bin/
+       install ${S}/rsvg/tests/fixtures/api/* ${D}${PTEST_PATH}/rsvg/tests/fixtures/api/
+
+       install ${S}/rsvg/tests/fixtures/dimensions/bug608102.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
+       install ${S}/rsvg/tests/fixtures/dimensions/bug612951.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
+       install ${S}/rsvg/tests/fixtures/dimensions/bug614018.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
+       install ${S}/rsvg/tests/fixtures/dimensions/sub-rect-no-unit.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
+       install ${S}/rsvg/tests/fixtures/dimensions/bug521-with-viewbox.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
+       install ${S}/rsvg/tests/fixtures/dimensions/bug823-position-sub.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/dimensions
+
+       install ${S}/rsvg/tests/fixtures/loading/bar.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
+       install ${S}/rsvg/tests/fixtures/loading/gnome-cool.svg ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
+       install ${S}/rsvg/tests/fixtures/loading/gnome-cool.svgz ${D}${PTEST_PATH}/rsvg/tests/fixtures/loading/
+}
+
 PACKAGES =+ "librsvg-gtk rsvg"
 FILES:rsvg = "${bindir}/rsvg* \
 	      ${datadir}/pixmaps/svg-viewer.svg \