Skip to contentSkip to conversation

libxpm: add ptest support

PATCH In review Enoch Ng 2 participants 2 messages Jul 13 – Jul 22

lore
Share & tools
lore

Enoch Ng

author
#0 lore raw

PATCH 1/1 libxpm: add ptest support

Add ptest support by wrapping existing tests for libxpm.

The tests use GLib for various checks:
* Read and parse input files
* Write images, read them back, and compare the results
* Parse RGB color names and check for the correct values

As such, add glib-2.0 as a build dependency (only if ptest is enabled).

Also add libxpm to ptest-packagelists.inc. Test execution takes <3s on my machine, so add it to PTESTS_FAST.

[YOCTO #16330]

---
 .../distro/include/ptest-packagelists.inc     |  1 +
 .../xorg-lib/libxpm/run-ptest                 | 48 +++++++++++++++++++
 .../xorg-lib/libxpm_3.5.19.bb                 | 22 ++++++++-
 3 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-graphics/xorg-lib/libxpm/run-ptest
meta/conf/distro/include/ptest-packagelists.inc +1 -0
index 2badb56c48..08bf8e48ee 100644
@@ -58,6 +58,7 @@ PTESTS_FAST = "\
     libxml-simple-perl \
     libxml2 \
     libxmlb \
+    libxpm \
     libxslt \
     libyaml \
     logrotate \
meta/recipes-graphics/xorg-lib/libxpm/run-ptest new file +48 -0

48 lines not on this page · raw message

meta/recipes-graphics/xorg-lib/libxpm_3.5.19.bb +21 -1
index 32e052fd42..9ba96b39a0 100644
@@ -1,7 +1,7 @@
 require xorg-lib-common.inc
 
 # libxpm requires xgettext to build
-inherit gettext
+inherit gettext ptest
 
 SUMMARY = "Xpm: X Pixmap extension library"
 
@@ -13,15 +13,35 @@ protocol."
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://COPYING;md5=903942ebc9d807dfb68540f40bae5aff"
 DEPENDS += "libxext libsm libxt gettext-native"
+DEPENDS += "${@bb.utils.contains('DISTRO_FEATURES', 'ptest', 'glib-2.0', '', d)}"
 PE = "1"
 
 XORG_PN = "libXpm"
 EXTRA_OECONF += "--disable-open-zfile"
+EXTRA_OECONF += "${@bb.utils.contains('DISTRO_FEATURES', 'ptest', '--enable-unit-tests', '--disable-unit-tests', d)}"
 
 PACKAGES =+ "sxpm cxpm"
 FILES:cxpm = "${bindir}/cxpm"
 FILES:sxpm = "${bindir}/sxpm"
 
+SRC_URI += " file://run-ptest"
+
 SRC_URI[sha256sum] = "ad3576d689221a39dc728f0e0dc02ca7bb6a0d724c9a77fd1bfa1e9af83be900"
 
+TEST_TARGETS = "XpmCreate XpmMisc XpmRead XpmWrite rgb"
+
+do_compile_ptest() {
+    oe_runmake -C ${B}/test ${TEST_TARGETS}
+}
+
+do_install_ptest() {
+    for test_bin in ${TEST_TARGETS}; do
+        ${B}/libtool --mode=install install ${B}/test/${test_bin} ${D}${PTEST_PATH}/
+    done
+
+    cp -r ${S}/test/pixmaps ${D}${PTEST_PATH}/
+
+    install -m 0644 ${S}/test/rgb.txt ${D}${PTEST_PATH}/
+}
+
 BBCLASSEXTEND = "native"
#1 lore raw

meta/recipes-graphics/xorg-lib/libxpm/run-ptest line 3

Quoted 9 lines · Enoch Ng via lists.openembedded.org
meta/recipes-graphics/xorg-lib/libxpm/run-ptest new file +3 -0
new file mode 100644
index 0000000000..0ba4e788d3
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+TESTS="XpmCreate XpmMisc XpmRead XpmWrite rgb"

Duplicated list from the recipe, better to sed this in.

meta/recipes-graphics/xorg-lib/libxpm/run-ptest line 12

Quoted 8 lines
meta/recipes-graphics/xorg-lib/libxpm/run-ptest new file +8 -0
+for test in $TESTS; do
+    if [ ! -x "./$test" ]; then
+        echo "SKIP: $test"
+        continue
+    fi
+
+    ./"$test" | \
+    while IFS= read -r line; do

[ snip ]

Here you’re implementing a TAP parser in shell. There’s a good case to be made for having TAP support in the ptest runner somehow, but we’re in luck. The tests are written with GLib’s GTest framework, which gnome-desktop-testing can run and emit ptest-compatible summaries of.

Usually all you need to do is inherit ptest-gnome and just call "gnome-desktop-testing-runner libxpm” in run-ptest. This package doesn’t install the required .test files as it isn’t designed to install the tests, but you can easily write those in do_install_ptest. https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests has more details.

meta/recipes-graphics/xorg-lib/libxpm/run-ptest line 13

Quoted 2 lines
meta/recipes-graphics/xorg-lib/libxpm/run-ptest new file +2 -0
+DEPENDS += "${@bb.utils.contains('DISTRO_FEATURES', 'ptest', 'glib-2.0', '', d)}"
+EXTRA_OECONF += "${@bb.utils.contains('DISTRO_FEATURES', 'ptest', '--enable-unit-tests', '--disable-unit-tests', d)}”

Have a PACKAGECONFIG[tests] that is enabled on PTEST_ENABLED instead, to consolidate these.

meta/recipes-graphics/xorg-lib/libxpm/run-ptest line 24

Quoted 11 lines
meta/recipes-graphics/xorg-lib/libxpm/run-ptest new file +11 -0
+TEST_TARGETS = "XpmCreate XpmMisc XpmRead XpmWrite rgb"
+
+do_compile_ptest() {
+    oe_runmake -C ${B}/test ${TEST_TARGETS}
+}
+
+do_install_ptest() {
+    for test_bin in ${TEST_TARGETS}; do
+        ${B}/libtool --mode=install install ${B}/test/${test_bin} ${D}${PTEST_PATH}/
+    done
+

Instead of hardcoding TEST_TARGETS, inline a call to makefile-getvar to get the value of TESTS.

Cheers,
Ross