[meta-virtualization][wrynose][PATCH 2/2] libvirt: re-add ptest support for meson build system
Haitao Liu <[email protected]> Fri, 29 May 2026 11:00:40 +0800
| Newsgroups | org.yoctoproject.lists.meta-virtualization |
|---|---|
| Message-ID | <[email protected]> |
libvirt has switched its build system from Makefile to meson, so the original run-ptest which relied on "make -C tests -k check-TESTS" no longer works. Re-add ptest support based on the meson build system: - Rewrite run-ptest to directly execute the compiled test binaries instead of invoking make. - Patch meson.build at configure time to replace absolute build/source paths with the ptest install paths, removing the need for separate path-stripping patches. - Install test binaries and their required data files into the ptest directory. Test results on genericx86-64: All 120 tests passed (0 failures, 0 skips). root@genericx86-64:/usr/lib/libvirt/ptest# ./run-ptest PASS: chxml2xmltest PASS: nssguestlinktest PASS: virbuftest PASS: viracpitest PASS: esxutilstest PASS: ssh PASS: storagepoolxml2xmltest PASS: commandtest ... ... PASS: nwfilterebiptablestest PASS: cputest === Test Summary === PASS: 120 FAIL: 0 SKIP: 0 TOTAL: 120 Signed-off-by: Haitao Liu <[email protected]> --- recipes-extended/libvirt/libvirt/run-ptest | 32 ++++++++++++++- recipes-extended/libvirt/libvirt_git.bb | 45 ++++++++++++++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/recipes-extended/libvirt/libvirt/run-ptest b/recipes-extended/libvirt/libvirt/run-ptest index a434b186..dd1f94d3 100644 --- a/recipes-extended/libvirt/libvirt/run-ptest +++ b/recipes-extended/libvirt/libvirt/run-ptest @@ -1,3 +1,33 @@ #!/bin/sh -make -C tests -k check-TESTS +PTEST_DIR="/usr/lib/libvirt/ptest/tests" +export LD_LIBRARY_PATH="${PTEST_DIR}:${LD_LIBRARY_PATH}" +PASS=0 +FAIL=0 +SKIP=0 + +run_test() { + tname="$1" + tpath="$2" + "$tpath" >/dev/null 2>&1 + rc=$? + case $rc in + 0) echo "PASS: $tname"; PASS=$((PASS + 1)) ;; + 77) echo "SKIP: $tname"; SKIP=$((SKIP + 1)) ;; + *) echo "FAIL: $tname"; FAIL=$((FAIL + 1)) ;; + esac +} + +# Skip run-ptest (self), commandhelper and qemucapsprobe are middleware +# used by other test cases, not test cases themselves. +for t in $(find ${PTEST_DIR} -maxdepth 1 -type f -executable ! -name "*.so" ! -name "run-ptest" ! -name "commandhelper" ! -name "qemucapsprobe"); do + run_test "$(basename $t)" "$t" +done + +# Summary +echo "" +echo "=== Test Summary ===" +echo "PASS: $PASS" +echo "FAIL: $FAIL" +echo "SKIP: $SKIP" +echo "TOTAL: $((PASS + FAIL + SKIP))" diff --git a/recipes-extended/libvirt/libvirt_git.bb b/recipes-extended/libvirt/libvirt_git.bb index cb5d3482..0052f527 100644 --- a/recipes-extended/libvirt/libvirt_git.bb +++ b/recipes-extended/libvirt/libvirt_git.bb @@ -34,17 +34,16 @@ PV = "v${LIBVIRT_VERSION}+git" SRC_URI = "gitsm://github.com/libvirt/libvirt.git;name=libvirt;protocol=https;branch=master \ file://libvirtd.sh \ file://libvirtd.conf \ + file://run-ptest \ file://dnsmasq.conf \ file://hook_support.py \ file://gnutls-helper.py;subdir=${BP} \ file://libvirt-qemu.conf \ file://0001-prevent-gendispatch.pl-generating-build-path-in-code.patch \ - file://0001-messon.build-remove-build-path-information-to-avoid-.patch \ - file://0001-tests-meson-clear-absolute-directory-paths.patch \ file://0001-qemu_nbdkit.c-use-llu-to-print-time_t.patch \ " -inherit meson gettext update-rc.d pkgconfig systemd useradd perlnative +inherit meson gettext update-rc.d pkgconfig systemd useradd perlnative ptest USERADD_PACKAGES = "${PN}" GROUPADD_PARAM:${PN} = "-r qemu; -r kvm; -r libvirt; -r virtlogin" USERADD_PARAM:${PN} = "-r -g qemu -G kvm qemu" @@ -188,6 +187,46 @@ CVE_STATUS[CVE-2023-3750] = "fixed-version: Fixed in 9.6.0, NVD tracks this as v # Enable the Python tool support require libvirt-python.inc +do_configure:prepend() { + sed -i \ + -e "s|meson.current_build_dir()|'${PTEST_PATH}/tests'|g" \ + -e "s|meson.project_build_root()|'${PTEST_PATH}'|g" \ + -e "s|meson.current_source_dir()|'${PTEST_PATH}/datas/tests'|g" \ + -e "s|meson.project_source_root()|'${PTEST_PATH}/datas'|g" \ + ${S}/tests/meson.build ${S}/scripts/rpcgen/tests/meson.build ${S}/tests/schemas/meson.build +} + +# Guard abs_top_builddir/abs_top_srcdir defines with #ifndef to avoid +# -Werror redefinition conflict when tests pass them via -D compile flags. +do_configure:append() { + sed -i '/^#define abs_top_builddir/c\#ifndef abs_top_builddir\n#define abs_top_builddir " "\n#endif' ${B}/meson-config.h + sed -i '/^#define abs_top_srcdir/c\#ifndef abs_top_srcdir\n#define abs_top_srcdir " "\n#endif' ${B}/meson-config.h +} + + +do_install_ptest() { + install -d ${D}${PTEST_PATH}/tests + install -d ${D}${PTEST_PATH}/datas/tests + # The virshtest expects virsh at ${PTEST_PATH}/tests/tools/virsh, but it is + # installed to /usr/bin/virsh by libvirt-virsh. Create a symlink to satisfy + # the test's expected path. + install -d ${D}${PTEST_PATH}/tools + ln -sf /usr/bin/virsh ${D}${PTEST_PATH}/tools/virsh + find ${B}/tests/ -type f -executable -print -maxdepth 1 | xargs -i cp {} ${D}${PTEST_PATH}/tests -rf + cd ${S}/tests && find . -mindepth 1 -maxdepth 1 -type d | xargs -i cp {} ${D}${PTEST_PATH}/datas/tests -a + install -m 0755 ${B}/scripts/rpcgen/tests/test_demo ${D}${PTEST_PATH}/tests + install -m 0644 ${S}/scripts/rpcgen/tests/*.bin ${D}${PTEST_PATH}/datas/tests + install -D -m 0644 -t ${D}${PTEST_PATH}/datas/examples/xml/test/ ${S}/examples/xml/test/*.xml + install -D -m 0644 -t ${D}${PTEST_PATH}/datas/examples/xml/storage/ ${S}/examples/xml/storage/*.xml + install -D -m 0644 -t ${D}${PTEST_PATH}/datas/src/conf/schemas/ ${S}/src/conf/schemas/*.rng + install -D -m 0644 -t ${D}${PTEST_PATH}/datas/src/nwfilter/xml/ ${S}/src/nwfilter/xml/*.xml + install -D -m 0644 -t ${D}${PTEST_PATH}/tests/schemas/ ${B}/tests/schemas/*.rng + install -m 0644 ${S}/tests/openvzutilstest.conf ${D}${PTEST_PATH}/datas/tests + install -d ${D}${PTEST_PATH}/datas/src/network +} + +RDEPENDS:${PN}-ptest += " ${PN}-virsh" + do_compile() { cd ${B}/src # There may be race condition, but without creating these directories -- 2.34.1