diff --git a/meta-multimedia/conf/include/ptest-packagelists-meta-multimedia.inc b/meta-multimedia/conf/include/ptest-packagelists-meta-multimedia.inc
index 0b1b4afba8..483786e617 100644
--- a/meta-multimedia/conf/include/ptest-packagelists-meta-multimedia.inc
+++ b/meta-multimedia/conf/include/ptest-packagelists-meta-multimedia.inc
@@ -18,6 +18,7 @@ PTESTS_FAST_META_MULTIMEDIA = "\
 
 PTESTS_SLOW_META_MULTIMEDIA = "\
     gupnp \
+    libupnp \
 "
 
 PTESTS_PROBLEMS_META_MULTIMEDIA = "\
diff --git a/meta-multimedia/recipes-connectivity/libupnp/libupnp/run-ptest b/meta-multimedia/recipes-connectivity/libupnp/libupnp/run-ptest
new file mode 100755
index 0000000000..6735fff5be
--- /dev/null
+++ b/meta-multimedia/recipes-connectivity/libupnp/libupnp/run-ptest
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+cd "$(dirname "$0")"
+
+ctest --timeout 300 --output-on-failure 2>&1 | awk '
+/Test +#[0-9]+: / {
+    name = $0
+    sub(/.*Test +#[0-9]+: /, "", name)
+    sub(/ .*/, "", name)
+    if ($0 ~ /Passed/)
+        print "PASS: " name
+    else if ($0 ~ /Skipped/)
+        print "SKIP: " name
+    else
+        print "FAIL: " name
+    next
+}
+{ print }'
diff --git a/meta-multimedia/recipes-connectivity/libupnp/libupnp_22.2.2.bb b/meta-multimedia/recipes-connectivity/libupnp/libupnp_22.2.2.bb
index 252f5cf478..9d81805d90 100644
--- a/meta-multimedia/recipes-connectivity/libupnp/libupnp_22.2.2.bb
+++ b/meta-multimedia/recipes-connectivity/libupnp/libupnp_22.2.2.bb
@@ -10,9 +10,10 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=394a0f17b97f33426275571e15920434"
 
 SRCREV = "fac0494691434c35243131f66a0b27ea0c29f700"
 SRC_URI = "git://github.com/pupnp/pupnp.git;protocol=https;branch=main;tag=release-${PV} \
+           file://run-ptest \
           "
 
-inherit cmake pkgconfig
+inherit cmake pkgconfig ptest python3native
 
 EXTRA_OECMAKE = "\
     -DCMAKE_BUILD_TYPE=Release \
@@ -26,3 +27,50 @@ EXTRA_OECMAKE = "\
 
 PACKAGECONFIG ??= ""
 PACKAGECONFIG[openssl] = "-DUPNP_ENABLE_OPEN_SSL=ON,-DUPNP_ENABLE_OPEN_SSL=OFF,openssl"
+
+DEPENDS += "${@bb.utils.contains('PTEST_ENABLED', '1', 'googletest python3-pytest-native', '', d)}"
+
+# Most tests use internal symbols and only link against the static
+# libraries, which share a CMake export set with the shared ones, so the
+# tests get a separate build tree and the installed library stays
+# shared-only.
+PTEST_B = "${B}/ptest"
+
+do_configure_ptest() {
+    mkdir -p ${PTEST_B}
+    cd ${PTEST_B}
+    cmake ${OECMAKE_GENERATOR_ARGS} ${OECMAKE_SOURCEPATH} ${OECMAKE_ARGS} \
+        ${EXTRA_OECMAKE} -Wno-dev \
+        -DUPNP_BUILD_STATIC=ON \
+        -DUPNP_ENABLE_TESTING=ON \
+        -DPython3_EXECUTABLE=${PYTHON}
+}
+
+do_compile_ptest() {
+    cmake --build ${PTEST_B} -- ${EXTRA_OECMAKE_BUILD}
+}
+
+do_install_ptest() {
+    cd ${PTEST_B}
+    find . -name CTestTestfile.cmake | while read f; do
+        install -D -m 0644 $f ${D}${PTEST_PATH}/$f
+        sed -i -e 's# _BACKTRACE_TRIPLES "[^"]*"##' \
+            -e 's#${PTEST_B}#${PTEST_PATH}#g' -e 's#${S}#${PTEST_PATH}#g' \
+            -e 's#${PYTHON}#${bindir}/python3#g' ${D}${PTEST_PATH}/$f
+    done
+    find . -path '*/CMakeFiles' -prune -o -type f -perm -u+x ! -name '*.so*' -print | while read f; do
+        install -D -m 0755 $f ${D}${PTEST_PATH}/$f
+    done
+
+    install -d ${D}${PTEST_PATH}/ixml/test ${D}${PTEST_PATH}/tests ${D}${PTEST_PATH}/upnp/inc
+    cp -r ${S}/ixml/test/testdata ${D}${PTEST_PATH}/ixml/test/
+    install -m 0644 ${S}/tests/*.py ${D}${PTEST_PATH}/tests/
+    install -m 0755 ${S}/upnp/test/check_symbol_visibility.sh ${D}${PTEST_PATH}/upnp/test/
+    # The Python and symbol visibility tests look for the library in the
+    # build tree; point them at the installed one.
+    install -m 0644 ${PTEST_B}/upnp/inc/upnpconfig.h ${D}${PTEST_PATH}/upnp/inc/
+    ln -sf ${libdir}/libupnp.so.${PV} ${D}${PTEST_PATH}/upnp/libupnp.so
+    ln -sf ${libdir}/libupnp.so.${PV} ${D}${PTEST_PATH}/upnp/libupnp.so.${PV}
+}
+
+RDEPENDS:${PN}-ptest += "cmake python3-core python3-ctypes python3-fcntl python3-io python3-pytest"
