diff mbox series

[master] libsdl2: Add tests package and ptest support

Message ID 20250827222051.367093-1-a-christidis@ti.com
State New
Headers show
Series [master] libsdl2: Add tests package and ptest support | expand

Commit Message

Antonios Christidis Aug. 27, 2025, 10:20 p.m. UTC
From: Antonios Christidis <a-christidis@ti.com>

The SDL2 software comes with its own set of tests. Following that
introduce support for ptest.

Signed-off-by: Antonios Christidis <a-christidis@ti.com>
---
 .../distro/include/ptest-packagelists.inc     |  1 +
 .../libsdl2/libsdl2/run-ptest                 | 15 ++++++++++++++
 .../libsdl2/libsdl2_2.32.8.bb                 | 20 +++++++++++++++++--
 3 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 meta/recipes-graphics/libsdl2/libsdl2/run-ptest

Comments

Yoann Congal Aug. 28, 2025, 6:56 a.m. UTC | #1
Hello,

Le jeu. 28 août 2025 à 00:21, Antonios Christidis via lists.openembedded.org
<a-christidis=ti.com@lists.openembedded.org> a écrit :

> From: Antonios Christidis <a-christidis@ti.com>
>
> The SDL2 software comes with its own set of tests. Following that
> introduce support for ptest.
>
> Signed-off-by: Antonios Christidis <a-christidis@ti.com>
> ---
>  .../distro/include/ptest-packagelists.inc     |  1 +
>  .../libsdl2/libsdl2/run-ptest                 | 15 ++++++++++++++
>  .../libsdl2/libsdl2_2.32.8.bb                 | 20 +++++++++++++++++--
>  3 files changed, 34 insertions(+), 2 deletions(-)
>  create mode 100644 meta/recipes-graphics/libsdl2/libsdl2/run-ptest
>
> diff --git a/meta/conf/distro/include/ptest-packagelists.inc
> b/meta/conf/distro/include/ptest-packagelists.inc
> index 9a7b25a916..a5476927b5 100644
> --- a/meta/conf/distro/include/ptest-packagelists.inc
> +++ b/meta/conf/distro/include/ptest-packagelists.inc
> @@ -32,6 +32,7 @@ PTESTS_FAST = "\
>      libgpg-error\
>      libnl \
>      libpcre \
> +    libsdl2 \
>      libssh2 \
>      libtest-fatal-perl \
>      libtest-needs-perl \
> diff --git a/meta/recipes-graphics/libsdl2/libsdl2/run-ptest
> b/meta/recipes-graphics/libsdl2/libsdl2/run-ptest
> new file mode 100644
> index 0000000000..1cd1f9ceaf
> --- /dev/null
> +++ b/meta/recipes-graphics/libsdl2/libsdl2/run-ptest
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +
> +test_array=("testdraw2" "testgeometry" "testsprite2" "testgles2"
> "testoffscreen")
> +
> +test_path="/usr/bin/sdl2_tests/"
> +
> +for test in "${test_array[@]}"
> +do
> +    timeout --preserve-status 10 "$test_path""$test"
> +    if [ $? -eq 0 ]; then
> +        echo "PASS: $test"
> +    else
> +        echo "FAIL: $test"
> +    fi
> +done
>

You should explicitly return 0 (if all tests succeeded) or 1 (if any test
failed).
If I read correctly, your script will always return 0 (success) because the
last command is an 'echo'.

See https://docs.yoctoproject.org/dev/test-manual/ptest.html#running-ptest
(that was added recently)


> diff --git a/meta/recipes-graphics/libsdl2/libsdl2_2.32.8.bb
> b/meta/recipes-graphics/libsdl2/libsdl2_2.32.8.bb
> index 98291e0f80..5aeb333bc7 100644
> --- a/meta/recipes-graphics/libsdl2/libsdl2_2.32.8.bb
> +++ b/meta/recipes-graphics/libsdl2/libsdl2_2.32.8.bb
> @@ -21,13 +21,15 @@ LIC_FILES_CHKSUM:append = "
> ${@bb.utils.contains('PACKAGECONFIG', 'arm-neon', 'f
>
>  PROVIDES = "virtual/libsdl2"
>
> -SRC_URI = "https://www.libsdl.org/release/SDL2-${PV}.tar.gz"
> +SRC_URI = "https://www.libsdl.org/release/SDL2-${PV}.tar.gz \
> +          file://run-ptest \
> +          "
>
>  S = "${UNPACKDIR}/SDL2-${PV}"
>
>  SRC_URI[sha256sum] =
> "0ca83e9c9b31e18288c7ec811108e58bac1f1bb5ec6577ad386830eac51c787e"
>
> -inherit cmake lib_package binconfig-disabled pkgconfig
> upstream-version-is-even
> +inherit cmake lib_package binconfig-disabled pkgconfig
> upstream-version-is-even ptest
>  UPSTREAM_CHECK_REGEX = "SDL2-(?P<pver>\d+\.(\d*[02468])+(\.\d+)+)\.tar"
>
>  BINCONFIG = "${bindir}/sdl2-config"
> @@ -48,6 +50,7 @@ EXTRA_OECMAKE = "-DSDL_OSS=OFF -DSDL_ESD=OFF
> -DSDL_ARTS=OFF \
>                   -DSDL_X11_XRANDR=OFF \
>                   -DSDL_X11_XSCRNSAVER=OFF \
>                   -DSDL_X11_XSHAPE=OFF \
> +                -DSDL_TESTS=ON \
>  "
>
>  # opengl packageconfig factored out to make it easy for distros
> @@ -80,8 +83,21 @@ PACKAGECONFIG[vulkan]    =
> "-DSDL_VULKAN=ON,-DSDL_VULKAN=OFF"
>  PACKAGECONFIG[wayland]    =
> "-DSDL_WAYLAND=ON,-DSDL_WAYLAND=OFF,wayland-native wayland
> wayland-protocols libxkbcommon"
>  PACKAGECONFIG[x11]        = "-DSDL_X11=ON,-DSDL_X11=OFF,virtual/libx11
> libxext libxrandr libxrender"
>
> +do_install:append() {
> +       install -d ${D}${bindir}/sdl2_tests
> +       cp -r ${B}/test/* ${D}${bindir}/sdl2_tests
> +
> +       # Delete any leftover cmake files within the sdl2_tests dir
> +       find ${D}${bindir}/sdl2_tests -type f -name "*.cmake" -delete
> +}
> +
>  CFLAGS:append:class-native = " -DNO_SHARED_MEMORY"
>
> +PACKAGE_BEFORE_PN = "${PN}-tests"
> +
>  FILES:${PN} += "${datadir}/licenses/SDL2/LICENSE.txt"
> +FILES:${PN}-tests += "${bindir}/sdl2_tests"
> +
> +RDEPENDS:${PN}-ptest = "${PN}-tests"
>

Why not put the tests directly in the -ptest package?
(This is mostly out of curiosity. I like the simplicity of a single -ptest
package but I may have missed a reason for the split)

Thanks!


>
>  BBCLASSEXTEND = "native nativesdk"
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#222542):
> https://lists.openembedded.org/g/openembedded-core/message/222542
> Mute This Topic: https://lists.openembedded.org/mt/114926113/4316185
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> yoann.congal@smile.fr]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>
Alexander Kanavin Aug. 28, 2025, 12:51 p.m. UTC | #2
On Thu, 28 Aug 2025 at 08:56, Yoann Congal via lists.openembedded.org
<yoann.congal=smile.fr@lists.openembedded.org> wrote:
> You should explicitly return 0 (if all tests succeeded) or 1 (if any test failed).
> If I read correctly, your script will always return 0 (success) because the last command is an 'echo'.
>
> See https://docs.yoctoproject.org/dev/test-manual/ptest.html#running-ptest (that was added recently)

The documentation does not impose such requirements on run-ptest. It
can exit with 0 even if something failed (and many run-ptest examples
in core do exactly that). I think you misread the exit codes for
ptest-runner.

The only requirement on run-ptest is that it prints PASS and FAIL markers.

Alex
Alexander Kanavin Aug. 28, 2025, 12:51 p.m. UTC | #3
On Thu, 28 Aug 2025 at 00:21, Antonios Christidis via
lists.openembedded.org <a-christidis=ti.com@lists.openembedded.org>
wrote:
> +test_array=("testdraw2" "testgeometry" "testsprite2" "testgles2" "testoffscreen")
> +
> +test_path="/usr/bin/sdl2_tests/"

I know this somewhat contradicts what I said before, but now I think
we should just keep this simple and install these under
/usr/lib/libsdl2/ptest/tests, and package them in $PN-ptest. Putting
something executable in a sub-directory under /usr/bin is very
non-standard.

Also run-ptest should not hardcode the list of tests, and just run
everything in a directory.

> @@ -48,6 +50,7 @@ EXTRA_OECMAKE = "-DSDL_OSS=OFF -DSDL_ESD=OFF -DSDL_ARTS=OFF \
>                   -DSDL_X11_XRANDR=OFF \
>                   -DSDL_X11_XSCRNSAVER=OFF \
>                   -DSDL_X11_XSHAPE=OFF \
> +                -DSDL_TESTS=ON \

This should stay as PACKAGECONFIG, and be enabled subject to ptest in
DISTRO_FEATURES.

Alex
diff mbox series

Patch

diff --git a/meta/conf/distro/include/ptest-packagelists.inc b/meta/conf/distro/include/ptest-packagelists.inc
index 9a7b25a916..a5476927b5 100644
--- a/meta/conf/distro/include/ptest-packagelists.inc
+++ b/meta/conf/distro/include/ptest-packagelists.inc
@@ -32,6 +32,7 @@  PTESTS_FAST = "\
     libgpg-error\
     libnl \
     libpcre \
+    libsdl2 \
     libssh2 \
     libtest-fatal-perl \
     libtest-needs-perl \
diff --git a/meta/recipes-graphics/libsdl2/libsdl2/run-ptest b/meta/recipes-graphics/libsdl2/libsdl2/run-ptest
new file mode 100644
index 0000000000..1cd1f9ceaf
--- /dev/null
+++ b/meta/recipes-graphics/libsdl2/libsdl2/run-ptest
@@ -0,0 +1,15 @@ 
+#!/bin/sh
+
+test_array=("testdraw2" "testgeometry" "testsprite2" "testgles2" "testoffscreen")
+
+test_path="/usr/bin/sdl2_tests/"
+
+for test in "${test_array[@]}"
+do
+    timeout --preserve-status 10 "$test_path""$test"
+    if [ $? -eq 0 ]; then
+        echo "PASS: $test"
+    else
+        echo "FAIL: $test"
+    fi
+done
diff --git a/meta/recipes-graphics/libsdl2/libsdl2_2.32.8.bb b/meta/recipes-graphics/libsdl2/libsdl2_2.32.8.bb
index 98291e0f80..5aeb333bc7 100644
--- a/meta/recipes-graphics/libsdl2/libsdl2_2.32.8.bb
+++ b/meta/recipes-graphics/libsdl2/libsdl2_2.32.8.bb
@@ -21,13 +21,15 @@  LIC_FILES_CHKSUM:append = " ${@bb.utils.contains('PACKAGECONFIG', 'arm-neon', 'f
 
 PROVIDES = "virtual/libsdl2"
 
-SRC_URI = "https://www.libsdl.org/release/SDL2-${PV}.tar.gz"
+SRC_URI = "https://www.libsdl.org/release/SDL2-${PV}.tar.gz \
+	   file://run-ptest \
+	   "
 
 S = "${UNPACKDIR}/SDL2-${PV}"
 
 SRC_URI[sha256sum] = "0ca83e9c9b31e18288c7ec811108e58bac1f1bb5ec6577ad386830eac51c787e"
 
-inherit cmake lib_package binconfig-disabled pkgconfig upstream-version-is-even
+inherit cmake lib_package binconfig-disabled pkgconfig upstream-version-is-even ptest
 UPSTREAM_CHECK_REGEX = "SDL2-(?P<pver>\d+\.(\d*[02468])+(\.\d+)+)\.tar"
 
 BINCONFIG = "${bindir}/sdl2-config"
@@ -48,6 +50,7 @@  EXTRA_OECMAKE = "-DSDL_OSS=OFF -DSDL_ESD=OFF -DSDL_ARTS=OFF \
                  -DSDL_X11_XRANDR=OFF \
                  -DSDL_X11_XSCRNSAVER=OFF \
                  -DSDL_X11_XSHAPE=OFF \
+		 -DSDL_TESTS=ON \
 "
 
 # opengl packageconfig factored out to make it easy for distros
@@ -80,8 +83,21 @@  PACKAGECONFIG[vulkan]    = "-DSDL_VULKAN=ON,-DSDL_VULKAN=OFF"
 PACKAGECONFIG[wayland]    = "-DSDL_WAYLAND=ON,-DSDL_WAYLAND=OFF,wayland-native wayland wayland-protocols libxkbcommon"
 PACKAGECONFIG[x11]        = "-DSDL_X11=ON,-DSDL_X11=OFF,virtual/libx11 libxext libxrandr libxrender"
 
+do_install:append() {
+	install -d ${D}${bindir}/sdl2_tests
+	cp -r ${B}/test/* ${D}${bindir}/sdl2_tests
+
+	# Delete any leftover cmake files within the sdl2_tests dir
+	find ${D}${bindir}/sdl2_tests -type f -name "*.cmake" -delete
+}
+
 CFLAGS:append:class-native = " -DNO_SHARED_MEMORY"
 
+PACKAGE_BEFORE_PN = "${PN}-tests"
+
 FILES:${PN} += "${datadir}/licenses/SDL2/LICENSE.txt"
+FILES:${PN}-tests += "${bindir}/sdl2_tests"
+
+RDEPENDS:${PN}-ptest = "${PN}-tests"
 
 BBCLASSEXTEND = "native nativesdk"