diff mbox series

[scarthgap] imagemagick: adds ptest for imagemagick recipe

Message ID 20251027045701.3396903-1-ashishkumar.mishra@bmwtechworks.in
State New
Headers show
Series [scarthgap] imagemagick: adds ptest for imagemagick recipe | expand

Commit Message

AshishKumar Mishra Oct. 27, 2025, 4:57 a.m. UTC
The logic used is :
- We check if the required tools are present or not
- We used convert to create an raw RGB file
- The created RGB is then converted to PNG using convert
- We re-gerenate RGB from PNG and compare the original and re-generated RGB

Signed-off-by: AshishKumar Mishra <ashishkumar.mishra@bmwtechworks.in>
---
 .../imagemagick/imagemagick-ptest.sh          | 128 ++++++++++++++++++
 .../imagemagick/imagemagick/run-ptest         |  43 ++++++
 .../imagemagick/imagemagick_7.1.1.bb          |  14 +-
 3 files changed, 183 insertions(+), 2 deletions(-)
 create mode 100755 meta-oe/recipes-support/imagemagick/imagemagick/imagemagick-ptest.sh
 create mode 100644 meta-oe/recipes-support/imagemagick/imagemagick/run-ptest

Comments

AshishKumar Mishra Oct. 27, 2025, 5:44 a.m. UTC | #1
Will share the patch for master branch seprately as :
1) In latest version of imagemagick , "convert " utility is replaced by "magick"
2) The "S" has been changed

Thanks
Ashish Kumar Mishra
Gyorgy Sarvari Oct. 27, 2025, 9:30 a.m. UTC | #2
In general I think this is a very good patch, but I'd like to add a
couple of notes:

1. Could it include the official test suite also? I would not remove the
current tests, but rather extend them - actually I think it's a good
idea to exercise the artifacts in a way you do.
2. The recipe should be also added to the
conf/include/ptest-packagelists-meta-oe.inc file
3. The test suite should return results in a strict form:
PASS: $testname_or_something_like_that
or
FAIL: $testname_or_something_like_that

Other logs can be present between these lines, but the test status
should be reported like this (not [FAIL]/[PASS])

Just to give some background to the last two points:
If point 2 is done, then you can do things like "bitbake
meta-oe-image-ptest-imagemagick" which will build a minimal image that
contains the ptest with its requirements.
If you also add "testimage" to IMAGE_CLASSES variable, then you can
automate the whole thing like "bitbake meta-oe-image-ptest-imagemagick
-c testimage", which will run the tests automatically, and also evaluate
them for you - this requires the PASS/FAIL output form, this is how
failures recognized automatically.

On 10/27/25 05:57, AshishKumar Mishra via lists.openembedded.org wrote:
> The logic used is :
> - We check if the required tools are present or not
> - We used convert to create an raw RGB file
> - The created RGB is then converted to PNG using convert
> - We re-gerenate RGB from PNG and compare the original and re-generated RGB
>
> Signed-off-by: AshishKumar Mishra <ashishkumar.mishra@bmwtechworks.in>
> ---
>  .../imagemagick/imagemagick-ptest.sh          | 128 ++++++++++++++++++
>  .../imagemagick/imagemagick/run-ptest         |  43 ++++++
>  .../imagemagick/imagemagick_7.1.1.bb          |  14 +-
>  3 files changed, 183 insertions(+), 2 deletions(-)
>  create mode 100755 meta-oe/recipes-support/imagemagick/imagemagick/imagemagick-ptest.sh
>  create mode 100644 meta-oe/recipes-support/imagemagick/imagemagick/run-ptest
>
> diff --git a/meta-oe/recipes-support/imagemagick/imagemagick/imagemagick-ptest.sh b/meta-oe/recipes-support/imagemagick/imagemagick/imagemagick-ptest.sh
> new file mode 100755
> index 0000000000..fbb26d2741
> --- /dev/null
> +++ b/meta-oe/recipes-support/imagemagick/imagemagick/imagemagick-ptest.sh
> @@ -0,0 +1,128 @@
> +#!/bin/sh
> +#
> +# ImageMagick ptest:
> +# We ceate an BASERGB file for our usage using "convert"
> +# We convert this RGB file to BASEPNG
> +# Using BASEPNG we recreate RGB named REGENERATEDRGB
> +#
> +# BASERGB to BASEPNG to REGENERATEDRGB
> +# - Then compare  BASERGB with REGENERATEDRGB
> +#
> +# 1) We are checking if the binaries are present in RFS or not
> +# 2) We Created an RBG of size : WIDTH x HEIGHT pixels
> +# 3) Return value is captured after every major actio to capture the status
> +# 4) cmp -s is used to compare binary byte by byte data and
> +#    capture only exit status
> +# 5) Important parametsrs used are :
> +#    -depth                     : How many bits for each colour pixel
> +#    -alpha off  		: Don't consider transparency
> +#    -define png:color-type=2   : Make PNG work with truecolour RGB
> +#    -strip 			: Remove all non-pixel metadata og PNG
> +#                                 so file is reproducible
> +#    -set gamma 1.0             : No PNG brightness correction
> +#     gradient:red-blue         : Data moves liberly from RED to Blue vertically
> +
> +
> +WIDTH=16
> +HEIGHT=16
> +BASERGB=base.rgb
> +BASEPNG=base.png
> +REGENERATEDRGB=roundtrip.rgb
> +
> +echo "[TEST ] Starting ImageMagick Ptest with ${WIDTH}x${HEIGHT} pixels "
> +
> +# Verify required binaries
> +for bin in convert cmp wc rm; do
> +    if [ -z "$(command -v "$bin" 2>/dev/null)" ]; then
> +        echo "[ERROR] Required binary '$bin' not found $PATH"
> +        exit 127
> +    fi
> +done
> +
> +# Generate raw RGB
> +convert -size ${WIDTH}x${HEIGHT} -depth 8 -type TrueColor \
> +    -alpha off -define png:color-type=2 \
> +    -strip -set gamma 1.0 \
> +    gradient:red-blue rgb:${BASERGB}
> +
> +returnvalue=$?
> +if [ "$returnvalue" -ne 0 ]; then
> +    echo "[FAIL] Failed to generate RGB pattern "
> +    exit 1
> +else
> +    echo "[DEBUG] Generated raw RGB ${BASERGB} for test case"
> +fi
> +
> +
> +
> +# Convert raw RGB to PNG
> +convert -size ${WIDTH}x${HEIGHT} -depth 8 -type TrueColor \
> +    -alpha off -define png:color-type=2 \
> +    -strip -set gamma 1.0 \
> +    rgb:${BASERGB} ${BASEPNG}
> +
> +returnvalue=$?
> +if [ $returnvalue -ne 0 ]; then
> +    echo "[FAIL] Failed to convert RGB to PNG"
> +    rm -f ${BASERGB}
> +    exit 1
> +else
> +    echo "[DEBUG] ${BASEPNG}  generated from ${BASERGB}"
> +fi
> +
> +
> +
> +# Regenrate raw RGB from PNG
> +convert -size ${WIDTH}x${HEIGHT} -depth 8 -type TrueColor \
> +    -alpha off -define png:color-type=2 \
> +    -strip -set gamma 1.0 \
> +    ${BASEPNG} rgb:${REGENERATEDRGB}
> +
> +returnvalue=$?
> +if [ $returnvalue -ne 0 ]; then
> +    echo "[FAIL] Failed to re generate RGB from PNG "
> +    rm -f ${BASERGB} ${BASEPNG}
> +    exit 1
> +else
> +    echo "[DEBUG] ${REGENERATEDRGB} generated from ${BASEPNG}"
> +fi
> +
> +
> +
> +# Compare original and recreated RGB
> +if cmp -s ${BASERGB} ${REGENERATEDRGB}; then
> +    echo "[PASS] RGB data identical after PNG round-trip"
> +    RESULT=0
> +else
> +    echo "[FAIL] RGB mismatch detected, printing their size "
> +    echo "[INFO] Base RGB size: $(wc -c < ${BASERGB}) bytes"
> +    echo "[INFO] Round-trip RGB size: $(wc -c < ${REGENERATEDRGB}) bytes"
> +    RESULT=1
> +fi
> +
> +
> +
> +# Checking the identify tool from imagemagick to get the PNG metadata
> +# True is added in end to ensure that test script doesnt fail even if
> +# identify fails for any reason
> +echo "[DEBUG] PNG file info:"
> +identify -verbose ${BASEPNG} | grep -E "Depth|Type|Colorspace" || true
> +
> +
> +
> +# Cleanup of files create by test code
> +echo "[DEBUG] Cleaning up temporary files"
> +rm -f ${BASERGB} ${BASEPNG} ${REGENERATEDRGB}
> +returnvalue=$?
> +echo "[DEBUG] Cleanup exit=$returnvalue"
> +
> +
> +# Logging the final result
> +if [ ${RESULT} -eq 0 ]; then
> +    echo "[DONE] ImageMagick Ptest completed successfully"
> +else
> +    echo "[DONE] ImageMagick Ptest completed with FAILURE"
> +fi
> +
> +
> +exit ${RESULT}
> diff --git a/meta-oe/recipes-support/imagemagick/imagemagick/run-ptest b/meta-oe/recipes-support/imagemagick/imagemagick/run-ptest
> new file mode 100644
> index 0000000000..70c0dd8cb8
> --- /dev/null
> +++ b/meta-oe/recipes-support/imagemagick/imagemagick/run-ptest
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +#
> +# run-ptest — ImageMagick ptest harness
> +# POSIX-safe and BusyBox compatible
> +
> +PTDIR=$(dirname "$0")
> +TESTDIR="$PTDIR"
> +PASSCOUNT=0
> +FAILCOUNT=0
> +TOTAL=0
> +
> +echo "======================================="
> +echo "ImageMagick ptest: Runtime Validation"
> +echo "======================================="
> +
> +for t in "$TESTDIR"/*.sh; do
> +    [ -x "$t" ] || chmod +x "$t"
> +    TOTAL=$((TOTAL + 1))
> +    echo "[TEST $TOTAL] Executing: $(basename "$t")"
> +    echo "[DEBUG] Launching test script $t"
> +
> +    if sh "$t" 2>&1; then
> +        echo "[RESULT] PASS: $(basename "$t")"
> +        PASSCOUNT=$((PASSCOUNT + 1))
> +    else
> +        rc=$?
> +        if [ "$rc" -eq 77 ]; then
> +            echo "[RESULT] SKIP: $(basename "$t")"
> +        else
> +            echo "[RESULT] FAIL (exit=$rc): $(basename "$t")"
> +            FAILCOUNT=$((FAILCOUNT + 1))
> +        fi
> +    fi
> +
> +    echo "[DEBUG] Completed test $(basename "$t")"
> +done
> +
> +echo "======================================="
> +echo "[SUMMARY] Total: $TOTAL | PASS: $PASSCOUNT | FAIL: $FAILCOUNT"
> +echo "======================================="
> +
> +[ "$FAILCOUNT" -eq 0 ]
> +
> diff --git a/meta-oe/recipes-support/imagemagick/imagemagick_7.1.1.bb b/meta-oe/recipes-support/imagemagick/imagemagick_7.1.1.bb
> index 752fef303b..dd199902bd 100644
> --- a/meta-oe/recipes-support/imagemagick/imagemagick_7.1.1.bb
> +++ b/meta-oe/recipes-support/imagemagick/imagemagick_7.1.1.bb
> @@ -11,12 +11,15 @@ DEPENDS = "lcms bzip2 jpeg libpng tiff zlib fftw freetype libtool"
>  
>  BASE_PV := "${PV}"
>  PV .= "-26"
> -SRC_URI = "git://github.com/ImageMagick/ImageMagick.git;branch=main;protocol=https"
> +SRC_URI = "git://github.com/ImageMagick/ImageMagick.git;branch=main;protocol=https \
> +           file://run-ptest \
> +           file://imagemagick-ptest.sh \
> +"
>  SRCREV = "570a9a048bb0e3a5c221ca87be9408ae35f711e2"
>  
>  S = "${WORKDIR}/git"
>  
> -inherit autotools pkgconfig update-alternatives
> +inherit autotools pkgconfig update-alternatives ptest
>  export ac_cv_sys_file_offset_bits="64"
>  
>  EXTRA_OECONF = "--program-prefix= --program-suffix=.im7 --without-perl --enable-largefile"
> @@ -56,6 +59,13 @@ do_install:append:class-target() {
>      fi
>  }
>  
> +do_install_ptest() {
> +    install -d ${D}${PTEST_PATH}
> +    install -m 0755 ${WORKDIR}/run-ptest ${D}${PTEST_PATH}/
> +    install -m 0755 ${WORKDIR}/imagemagick-ptest.sh ${D}${PTEST_PATH}/
> +}
> +
> +
>  FILES:${PN} += "${libdir}/ImageMagick-${BASE_PV}/config-Q16* \
>                  ${datadir}/ImageMagick-7"
>  
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#121023): https://lists.openembedded.org/g/openembedded-devel/message/121023
> Mute This Topic: https://lists.openembedded.org/mt/115970043/6084445
> Group Owner: openembedded-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [skandigraun@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
AshishKumar Mishra Oct. 27, 2025, 10:18 a.m. UTC | #3
Thanks Gyorgy Sarvari , for insight
Will re-look at these suggestions and re-share the patch

The problem with test cases in imagemagick were that it would require manual verification of files generated
Example they require user to manually open the output file and then check if the drawing are proper or not .

That i thought might not be usage for ptest , hence created an simple test which generates the source and then use that source for test

Point-2 & Point-3 , i will work again on patch and share them shortly

Thanks ,
Ashish Kumar Mishra
Gyorgy Sarvari Oct. 27, 2025, 10:22 a.m. UTC | #4
On 10/27/25 11:18, AshishKumar Mishra via lists.openembedded.org wrote:
> Thanks Gyorgy Sarvari , for insight
> Will re-look at these suggestions and re-share the patch 
>
> The problem with test cases in imagemagick were that it would require
> manual verification of files generated 

I see. If the official testsuite requires human intervention, that
sounds like a good reason to me to do it your way only - could you
please include a note about this in the commit message?

> Example they require user to manually open the output file and then
> check if the drawing are proper or not . 
>
> That i thought might not be usage for ptest , hence created an simple
> test which generates the source and then use that source for test 
>
> Point-2 & Point-3 , i will work again on patch and share them shortly 
>
> Thanks ,
> Ashish Kumar Mishra
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#121031): https://lists.openembedded.org/g/openembedded-devel/message/121031
> Mute This Topic: https://lists.openembedded.org/mt/115970043/6084445
> Group Owner: openembedded-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [skandigraun@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
AshishKumar Mishra Oct. 27, 2025, 10:25 a.m. UTC | #5
Sure will add them in commit message.

Thanks ,
Ashish
diff mbox series

Patch

diff --git a/meta-oe/recipes-support/imagemagick/imagemagick/imagemagick-ptest.sh b/meta-oe/recipes-support/imagemagick/imagemagick/imagemagick-ptest.sh
new file mode 100755
index 0000000000..fbb26d2741
--- /dev/null
+++ b/meta-oe/recipes-support/imagemagick/imagemagick/imagemagick-ptest.sh
@@ -0,0 +1,128 @@ 
+#!/bin/sh
+#
+# ImageMagick ptest:
+# We ceate an BASERGB file for our usage using "convert"
+# We convert this RGB file to BASEPNG
+# Using BASEPNG we recreate RGB named REGENERATEDRGB
+#
+# BASERGB to BASEPNG to REGENERATEDRGB
+# - Then compare  BASERGB with REGENERATEDRGB
+#
+# 1) We are checking if the binaries are present in RFS or not
+# 2) We Created an RBG of size : WIDTH x HEIGHT pixels
+# 3) Return value is captured after every major actio to capture the status
+# 4) cmp -s is used to compare binary byte by byte data and
+#    capture only exit status
+# 5) Important parametsrs used are :
+#    -depth                     : How many bits for each colour pixel
+#    -alpha off  		: Don't consider transparency
+#    -define png:color-type=2   : Make PNG work with truecolour RGB
+#    -strip 			: Remove all non-pixel metadata og PNG
+#                                 so file is reproducible
+#    -set gamma 1.0             : No PNG brightness correction
+#     gradient:red-blue         : Data moves liberly from RED to Blue vertically
+
+
+WIDTH=16
+HEIGHT=16
+BASERGB=base.rgb
+BASEPNG=base.png
+REGENERATEDRGB=roundtrip.rgb
+
+echo "[TEST ] Starting ImageMagick Ptest with ${WIDTH}x${HEIGHT} pixels "
+
+# Verify required binaries
+for bin in convert cmp wc rm; do
+    if [ -z "$(command -v "$bin" 2>/dev/null)" ]; then
+        echo "[ERROR] Required binary '$bin' not found $PATH"
+        exit 127
+    fi
+done
+
+# Generate raw RGB
+convert -size ${WIDTH}x${HEIGHT} -depth 8 -type TrueColor \
+    -alpha off -define png:color-type=2 \
+    -strip -set gamma 1.0 \
+    gradient:red-blue rgb:${BASERGB}
+
+returnvalue=$?
+if [ "$returnvalue" -ne 0 ]; then
+    echo "[FAIL] Failed to generate RGB pattern "
+    exit 1
+else
+    echo "[DEBUG] Generated raw RGB ${BASERGB} for test case"
+fi
+
+
+
+# Convert raw RGB to PNG
+convert -size ${WIDTH}x${HEIGHT} -depth 8 -type TrueColor \
+    -alpha off -define png:color-type=2 \
+    -strip -set gamma 1.0 \
+    rgb:${BASERGB} ${BASEPNG}
+
+returnvalue=$?
+if [ $returnvalue -ne 0 ]; then
+    echo "[FAIL] Failed to convert RGB to PNG"
+    rm -f ${BASERGB}
+    exit 1
+else
+    echo "[DEBUG] ${BASEPNG}  generated from ${BASERGB}"
+fi
+
+
+
+# Regenrate raw RGB from PNG
+convert -size ${WIDTH}x${HEIGHT} -depth 8 -type TrueColor \
+    -alpha off -define png:color-type=2 \
+    -strip -set gamma 1.0 \
+    ${BASEPNG} rgb:${REGENERATEDRGB}
+
+returnvalue=$?
+if [ $returnvalue -ne 0 ]; then
+    echo "[FAIL] Failed to re generate RGB from PNG "
+    rm -f ${BASERGB} ${BASEPNG}
+    exit 1
+else
+    echo "[DEBUG] ${REGENERATEDRGB} generated from ${BASEPNG}"
+fi
+
+
+
+# Compare original and recreated RGB
+if cmp -s ${BASERGB} ${REGENERATEDRGB}; then
+    echo "[PASS] RGB data identical after PNG round-trip"
+    RESULT=0
+else
+    echo "[FAIL] RGB mismatch detected, printing their size "
+    echo "[INFO] Base RGB size: $(wc -c < ${BASERGB}) bytes"
+    echo "[INFO] Round-trip RGB size: $(wc -c < ${REGENERATEDRGB}) bytes"
+    RESULT=1
+fi
+
+
+
+# Checking the identify tool from imagemagick to get the PNG metadata
+# True is added in end to ensure that test script doesnt fail even if
+# identify fails for any reason
+echo "[DEBUG] PNG file info:"
+identify -verbose ${BASEPNG} | grep -E "Depth|Type|Colorspace" || true
+
+
+
+# Cleanup of files create by test code
+echo "[DEBUG] Cleaning up temporary files"
+rm -f ${BASERGB} ${BASEPNG} ${REGENERATEDRGB}
+returnvalue=$?
+echo "[DEBUG] Cleanup exit=$returnvalue"
+
+
+# Logging the final result
+if [ ${RESULT} -eq 0 ]; then
+    echo "[DONE] ImageMagick Ptest completed successfully"
+else
+    echo "[DONE] ImageMagick Ptest completed with FAILURE"
+fi
+
+
+exit ${RESULT}
diff --git a/meta-oe/recipes-support/imagemagick/imagemagick/run-ptest b/meta-oe/recipes-support/imagemagick/imagemagick/run-ptest
new file mode 100644
index 0000000000..70c0dd8cb8
--- /dev/null
+++ b/meta-oe/recipes-support/imagemagick/imagemagick/run-ptest
@@ -0,0 +1,43 @@ 
+#!/bin/sh
+#
+# run-ptest — ImageMagick ptest harness
+# POSIX-safe and BusyBox compatible
+
+PTDIR=$(dirname "$0")
+TESTDIR="$PTDIR"
+PASSCOUNT=0
+FAILCOUNT=0
+TOTAL=0
+
+echo "======================================="
+echo "ImageMagick ptest: Runtime Validation"
+echo "======================================="
+
+for t in "$TESTDIR"/*.sh; do
+    [ -x "$t" ] || chmod +x "$t"
+    TOTAL=$((TOTAL + 1))
+    echo "[TEST $TOTAL] Executing: $(basename "$t")"
+    echo "[DEBUG] Launching test script $t"
+
+    if sh "$t" 2>&1; then
+        echo "[RESULT] PASS: $(basename "$t")"
+        PASSCOUNT=$((PASSCOUNT + 1))
+    else
+        rc=$?
+        if [ "$rc" -eq 77 ]; then
+            echo "[RESULT] SKIP: $(basename "$t")"
+        else
+            echo "[RESULT] FAIL (exit=$rc): $(basename "$t")"
+            FAILCOUNT=$((FAILCOUNT + 1))
+        fi
+    fi
+
+    echo "[DEBUG] Completed test $(basename "$t")"
+done
+
+echo "======================================="
+echo "[SUMMARY] Total: $TOTAL | PASS: $PASSCOUNT | FAIL: $FAILCOUNT"
+echo "======================================="
+
+[ "$FAILCOUNT" -eq 0 ]
+
diff --git a/meta-oe/recipes-support/imagemagick/imagemagick_7.1.1.bb b/meta-oe/recipes-support/imagemagick/imagemagick_7.1.1.bb
index 752fef303b..dd199902bd 100644
--- a/meta-oe/recipes-support/imagemagick/imagemagick_7.1.1.bb
+++ b/meta-oe/recipes-support/imagemagick/imagemagick_7.1.1.bb
@@ -11,12 +11,15 @@  DEPENDS = "lcms bzip2 jpeg libpng tiff zlib fftw freetype libtool"
 
 BASE_PV := "${PV}"
 PV .= "-26"
-SRC_URI = "git://github.com/ImageMagick/ImageMagick.git;branch=main;protocol=https"
+SRC_URI = "git://github.com/ImageMagick/ImageMagick.git;branch=main;protocol=https \
+           file://run-ptest \
+           file://imagemagick-ptest.sh \
+"
 SRCREV = "570a9a048bb0e3a5c221ca87be9408ae35f711e2"
 
 S = "${WORKDIR}/git"
 
-inherit autotools pkgconfig update-alternatives
+inherit autotools pkgconfig update-alternatives ptest
 export ac_cv_sys_file_offset_bits="64"
 
 EXTRA_OECONF = "--program-prefix= --program-suffix=.im7 --without-perl --enable-largefile"
@@ -56,6 +59,13 @@  do_install:append:class-target() {
     fi
 }
 
+do_install_ptest() {
+    install -d ${D}${PTEST_PATH}
+    install -m 0755 ${WORKDIR}/run-ptest ${D}${PTEST_PATH}/
+    install -m 0755 ${WORKDIR}/imagemagick-ptest.sh ${D}${PTEST_PATH}/
+}
+
+
 FILES:${PN} += "${libdir}/ImageMagick-${BASE_PV}/config-Q16* \
                 ${datadir}/ImageMagick-7"