Skip to contentSkip to conversation

libpng: Add ptest for libpng

PATCH In review Sana Kazi 2 participants 2 messages Jan 3, 2025

lore
Share & tools
lore

Sana Kazi

author
#0 lore raw

PATCH 1/1 libpng: Add ptest for libpng

libpng is a platform-independent library which
supports all PNG features.
This ptest executes the below binaries, parses
the png image and prints the image features.

1. pngfix - provides information about PNG image
copyrights details.

2. pngtest - tests, optimizes and optionally fixes the zlib header in PNG files.

3. pngstest - verifies the integrity of PNG image by dumping chunk level information.

4. timepng - provides details about PNG image chunks.

---
 .../distro/include/ptest-packagelists.inc     |  1 +
 .../recipes-multimedia/libpng/files/run-ptest | 29 +++++++++++++++++++
 .../libpng/libpng_1.6.42.bb                   | 14 +++++++--
 3 files changed, 42 insertions(+), 2 deletions(-)
 create mode 100644 meta/recipes-multimedia/libpng/files/run-ptest
meta/conf/distro/include/ptest-packagelists.inc +1 -0
index 5975db25cc..8878af92ff 100644
@@ -31,6 +31,7 @@ PTESTS_FAST = "\
     libgpg-error\
     libnl \
     libpcre \
+    libpng \
     libssh2 \
     libtimedate-perl \
     libtest-fatal-perl \
meta/recipes-multimedia/libpng/files/run-ptest new file +29 -0
new file mode 100644
index 0000000000..9ab5d0c1f4
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+set -eux
+
+./pngfix pngtest.png &> log.txt  2>&1
+
+if grep -i "OK" log.txt 2>&1 ; then
+   echo "PASS: pngfix passed"
+else
+   echo "FAIL: pngfix failed"
+fi
+rm -f log.txt
+
+./pngtest pngtest.png &> log.txt 2>&1
+
+if grep -i "PASS" log.txt 2>&1 ; then
+   echo "PASS: pngtest passed"
+else
+   echo "FAIL: pngtest failed"
+fi
+rm -f log.txt
+
+for i in pngstest timepng; do
+    if "./${i}" pngtest.png 2>&1; then
+        echo "PASS: $i"
+    else
+        echo "FAIL: $i"
+    fi
+done
meta/recipes-multimedia/libpng/libpng_1.6.42.bb +12 -2
index 673133bb4a..6438bf190e 100644
@@ -10,7 +10,9 @@ DEPENDS = "zlib"
 
 LIBV = "16"
 
-SRC_URI = "${SOURCEFORGE_MIRROR}/project/${BPN}/${BPN}${LIBV}/${PV}/${BP}.tar.xz"
+SRC_URI = "${SOURCEFORGE_MIRROR}/project/${BPN}/${BPN}${LIBV}/${PV}/${BP}.tar.xz \
+           file://run-ptest \
+"
 SRC_URI[sha256sum] = "c919dbc11f4c03b05aba3f8884d8eb7adfe3572ad228af972bb60057bdb48450"
 
 MIRRORS += "${SOURCEFORGE_MIRROR}/project/${BPN}/${BPN}${LIBV}/ ${SOURCEFORGE_MIRROR}/project/${BPN}/${BPN}${LIBV}/older-releases/"
@@ -19,7 +21,7 @@ UPSTREAM_CHECK_URI = "http://libpng.org/pub/png/libpng.html"
 
 BINCONFIG = "${bindir}/libpng-config ${bindir}/libpng16-config"
 
-inherit autotools binconfig-disabled pkgconfig
+inherit autotools binconfig-disabled pkgconfig ptest
 
 # Work around missing symbols
 ARMNEON = "${@bb.utils.contains("TUNE_FEATURES", "neon", "--enable-arm-neon=on", "--enable-arm-neon=off", d)}"
@@ -30,4 +32,12 @@ PACKAGES =+ "${PN}-tools"
 
 FILES:${PN}-tools = "${bindir}/png-fix-itxt ${bindir}/pngfix ${bindir}/pngcp"
 
+do_install_ptest() {
+    install -m644 "${S}/pngtest.png" "${D}${PTEST_PATH}"
+    install -m755 "${B}/.libs/pngfix" "${D}${PTEST_PATH}"
+    install -m755 "${B}/.libs/pngtest" "${D}${PTEST_PATH}"
+    install -m755 "${B}/.libs/pngstest" "${D}${PTEST_PATH}"
+    install -m755 "${B}/.libs/timepng" "${D}${PTEST_PATH}"
+}
+
 BBCLASSEXTEND = "native nativesdk"
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Sana Kazi via lists.openembedded.org

libpng is a platform-independent library which supports all PNG features.
This ptest executes the below binaries, parses the png image and prints the image features.

1. pngfix - provides information about PNG image copyrights details.

Quoted 7 lines

2. pngtest - tests, optimizes and optionally fixes the zlib header in PNG files.

3. pngstest - verifies the integrity of PNG image by dumping chunk level information.

4. timepng - provides details about PNG image chunks.

Thanks for working in this. There are more tests provided by libpng, why only these four are picked? E.g. in Makefile.am:

if ENABLE_TESTS
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage pngcp if HAVE_CLOCK_GETTIME
check_PROGRAMS += timepng

Quoted 19 lines
meta/recipes-multimedia/libpng/files/run-ptest new file +19 -0
+#!/bin/sh
+
+set -eux
+
+./pngfix pngtest.png &> log.txt  2>&1
+
+if grep -i "OK" log.txt 2>&1 ; then
+   echo "PASS: pngfix passed"
+else
+   echo "FAIL: pngfix failed"
+fi
+rm -f log.txt
+
+./pngtest pngtest.png &> log.txt 2>&1
+
+if grep -i "PASS" log.txt 2>&1 ; then
+   echo "PASS: pngtest passed"
+else
+   echo "FAIL: pngtest failed"

meta/recipes-multimedia/libpng/files/run-ptest line 29

Quoted 10 lines
meta/recipes-multimedia/libpng/files/run-ptest new file +10 -0
+fi
+rm -f log.txt
+
+for i in pngstest timepng; do
+    if "./${i}" pngtest.png 2>&1; then
+        echo "PASS: $i"
+    else
+        echo "FAIL: $i"
+    fi
+done

There are several problems here:
- hardcoding the list of test executables is prone to getting out of date as libpng is updated to newer versions. As pointed above, it is already incomplete.
- checking the logs for things like 'OK' is prone to incorrect test results if the test prints OK somewhere unrelated. The correct thing to do is to check the return code.
- removing the logs makes investigating failures more difficult

All of the above issues can be addressed by installing Makefile from ${B} and running 'make check' from run-ptest. We do this in several other ptests.

Alex