diff mbox series

[v1] libffi: add ptest support

Message ID 20260507085242.39646-1-pratik.farkase@est.tech
State Under Review
Headers show
Series [v1] libffi: add ptest support | expand

Commit Message

Pratik Farkase May 7, 2026, 8:52 a.m. UTC
Add ptest support for libffi using the upstream bhaible test suite which
validates FFI call and callback interfaces across various calling
conventions and data types.

Tests are compiled on-target against the installed libffi. Headers and a
linker symlink are installed in the ptest directory to avoid depending on
libffi-dev.

Tested on qemux86-64 with ptest-runner: 2 PASS, 0 FAIL (29s).

Signed-off-by: Pratik Farkase <pratik.farkase@est.tech>
---
 meta/conf/distro/include/ptest-packagelists.inc |  1 +
 meta/recipes-support/libffi/libffi/run-ptest    | 16 ++++++++++++++++
 meta/recipes-support/libffi/libffi_3.5.2.bb     | 16 +++++++++++++++-
 3 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100755 meta/recipes-support/libffi/libffi/run-ptest
diff mbox series

Patch

diff --git a/meta/conf/distro/include/ptest-packagelists.inc b/meta/conf/distro/include/ptest-packagelists.inc
index 566445187d..0918507ce5 100644
--- a/meta/conf/distro/include/ptest-packagelists.inc
+++ b/meta/conf/distro/include/ptest-packagelists.inc
@@ -36,6 +36,7 @@  PTESTS_FAST = "\
     libconfig \
     libconvert-asn1-perl \
     libexif \
+    libffi \
     libgpg-error\
     libksba \
     libmd \
diff --git a/meta/recipes-support/libffi/libffi/run-ptest b/meta/recipes-support/libffi/libffi/run-ptest
new file mode 100755
index 0000000000..9617977b00
--- /dev/null
+++ b/meta/recipes-support/libffi/libffi/run-ptest
@@ -0,0 +1,16 @@ 
+#!/bin/sh
+# SPDX-License-Identifier: MIT
+
+PTEST_DIR=$(cd "$(dirname "$0")" && pwd)
+cd "$PTEST_DIR/testsuite/libffi.bhaible" || exit 1
+
+for test in test-call test-callback; do
+    gcc -O2 -Wall -I$PTEST_DIR/include -L$PTEST_DIR/lib -o $test $test.c -lffi
+    if ./$test > $test.out 2>&1 && ! LC_ALL=C uniq -u < $test.out | grep -q .; then
+        echo "PASS: $test"
+    else
+        echo "FAIL: $test"
+        LC_ALL=C uniq -u < $test.out 2>/dev/null
+    fi
+    rm -f $test $test.out
+done
diff --git a/meta/recipes-support/libffi/libffi_3.5.2.bb b/meta/recipes-support/libffi/libffi_3.5.2.bb
index d3aa90d429..719c46865a 100644
--- a/meta/recipes-support/libffi/libffi_3.5.2.bb
+++ b/meta/recipes-support/libffi/libffi_3.5.2.bb
@@ -12,6 +12,7 @@  LIC_FILES_CHKSUM = "file://LICENSE;md5=ce4763670c5b7756000561f9af1ab178"
 
 SRC_URI = "${GITHUB_BASE_URI}/download/v${PV}/${BPN}-${PV}.tar.gz \
            file://not-win32.patch \
+           file://run-ptest \
            "
 SRC_URI[sha256sum] = "f3a3082a23b37c293a4fcd1053147b371f2ff91fa7ea1b2a52e335676bac82dc"
 
@@ -19,7 +20,7 @@  EXTRA_OECONF = "--disable-builddir"
 EXTRA_OECONF:class-native += "--with-gcc-arch=generic"
 EXTRA_OEMAKE:class-target = "LIBTOOLFLAGS='--tag=CC'"
 
-inherit autotools texinfo multilib_header github-releases
+inherit autotools texinfo multilib_header github-releases ptest
 
 do_install:append() {
 	oe_multilib_header ffi.h ffitarget.h
@@ -30,3 +31,16 @@  do_install:append() {
 MIPS_INSTRUCTION_SET = "mips"
 
 BBCLASSEXTEND = "native nativesdk"
+
+RDEPENDS:${PN}-ptest += "packagegroup-core-buildessential"
+
+do_install_ptest() {
+    install -d ${D}${PTEST_PATH}/testsuite
+    cp -r ${S}/testsuite/libffi.bhaible ${D}${PTEST_PATH}/testsuite/
+
+    install -d ${D}${PTEST_PATH}/include
+    install -m 0644 ${B}/include/ffi.h ${D}${PTEST_PATH}/include/
+    install -m 0644 ${B}/include/ffitarget.h ${D}${PTEST_PATH}/include/
+    install -d ${D}${PTEST_PATH}/lib
+    ln -sf ${libdir}/libffi.so.8 ${D}${PTEST_PATH}/lib/libffi.so
+}