diff mbox series

[v1] zstd: add ptest support

Message ID 20260508083451.11094-1-pratik.farkase@est.tech
State New
Headers show
Series [v1] zstd: add ptest support | expand

Commit Message

Pratik Farkase May 8, 2026, 8:34 a.m. UTC
Add comprehensive ptest support for zstd running the full upstream test
suite covering compression correctness, streaming, dictionaries, CLI
behavior, and fuzz testing.

Tests included:
  - fullbench: validates all internal compression/decompression functions
  - poolTests: thread pool ordering and synchronization
  - invalidDictionaries: dictionary error handling
  - legacy: legacy format (v0.4+) compatibility
  - fuzzer: randomized compression/decompression (200s, ~700+ rounds)
  - zstreamtest: streaming API fuzzer (90s, ~250+ rounds)
  - decodecorpus: random frame generation and decode (30s, ~450+ rounds)
  - playTests.sh: comprehensive CLI validation including compression,
    decompression, multithreading, dictionaries, sparse files, frame
    concatenation, long distance matching, benchmarks, and round-trips
  - cli-tests: 36 Python-based CLI integration tests covering
    compression, decompression, progress, file-stat, dictionaries,
    symlinks, and file handling

Tests excluded from cli-tests (environment limitations):
  - compression/levels.sh: requires >8GB for --ultra/--max levels
  - compression/window-resize.sh: requires >4GB for 1GB window
  - file-stat/compress-file-to-dir-without-write-perm.sh: ptest runs
    as root which bypasses permission checks
  - cltools/: requires GNU grep (--label), unavailable with BusyBox

Source .c/.h files from tests/ and programs/ are installed as training
corpus for the dictionary builder tests.

zstreamtest requires 4096MB RAM for (hashLog=29 allocates ~2.8GB).
Set QB_MEM:virtclass-mcextend-zstd = "-m 4096" in core-image-ptest.

Tested on qemux86-64 (4GB) with ptest-runner: 9 PASS, 0 FAIL. Runtime is ~13 min.

Signed-off-by: Pratik Farkase <pratik.farkase@est.tech>
---
 .../distro/include/ptest-packagelists.inc     |  1 +
 meta/recipes-core/images/core-image-ptest.bb  |  1 +
 meta/recipes-extended/zstd/zstd/run-ptest     | 27 +++++++++++
 meta/recipes-extended/zstd/zstd_1.5.7.bb      | 48 ++++++++++++++++++-
 4 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100755 meta/recipes-extended/zstd/zstd/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 0918507ce5..ccac8e3bb3 100644
--- a/meta/conf/distro/include/ptest-packagelists.inc
+++ b/meta/conf/distro/include/ptest-packagelists.inc
@@ -151,6 +151,7 @@  PTESTS_SLOW = "\
     tcl \
     tcl8 \
     util-linux \
+    zstd \
 "
 
 # python3 ptests hang on qemuriscv64
diff --git a/meta/recipes-core/images/core-image-ptest.bb b/meta/recipes-core/images/core-image-ptest.bb
index 166b4ded63..1c82a9042f 100644
--- a/meta/recipes-core/images/core-image-ptest.bb
+++ b/meta/recipes-core/images/core-image-ptest.bb
@@ -44,6 +44,7 @@  QB_MEM:virtclass-mcextend-python3-cryptography = "-m 5100"
 QB_MEM:virtclass-mcextend-python3-numpy = "-m 4096"
 QB_MEM:virtclass-mcextend-tcl = "-m 5100"
 QB_MEM:virtclass-mcextend-go = "-m 4096"
+QB_MEM:virtclass-mcextend-zstd = "-m 4096"
 
 TEST_SUITES = "ping ssh parselogs ptest"
 
diff --git a/meta/recipes-extended/zstd/zstd/run-ptest b/meta/recipes-extended/zstd/zstd/run-ptest
new file mode 100755
index 0000000000..fe503ce8c9
--- /dev/null
+++ b/meta/recipes-extended/zstd/zstd/run-ptest
@@ -0,0 +1,27 @@ 
+#!/bin/sh
+# SPDX-License-Identifier: MIT
+
+cd "$(dirname "$0")/tests" || exit 1
+
+run_test() {
+    name=$1; shift
+    if "$@"; then echo "PASS: $name"; else echo "FAIL: $name"; fi
+}
+
+run_test fullbench            ./fullbench -i1
+run_test poolTests            ./poolTests
+run_test invalidDictionaries  ./invalidDictionaries
+run_test legacy               ./legacy
+run_test fuzzer               ./fuzzer -v -T200s
+run_test zstreamtest          ./zstreamtest -v -T90s
+run_test decodecorpus         ./decodecorpus -t -T30
+
+ZSTD_BIN=$(command -v zstd) DATAGEN_BIN=./datagen ZSTDRTTEST= ./playTests.sh
+run_test playTests test $? -eq 0
+
+if [ -d cli-tests ] && command -v python3 >/dev/null 2>&1; then
+    ./cli-tests/run.py --exec-prefix="" --zstd="$(command -v zstd)" --datagen=./datagen
+    run_test cli-tests test $? -eq 0
+else
+    echo "SKIP: cli-tests"
+fi
diff --git a/meta/recipes-extended/zstd/zstd_1.5.7.bb b/meta/recipes-extended/zstd/zstd_1.5.7.bb
index 0e872b95aa..66e326f386 100644
--- a/meta/recipes-extended/zstd/zstd_1.5.7.bb
+++ b/meta/recipes-extended/zstd/zstd_1.5.7.bb
@@ -10,7 +10,9 @@  LIC_FILES_CHKSUM = "file://LICENSE;md5=0822a32f7acdbe013606746641746ee8 \
                     file://COPYING;md5=39bba7d2cf0ba1036f2a6e2be52fe3f0 \
                     "
 
-SRC_URI = "git://github.com/facebook/zstd.git;branch=release;protocol=https"
+SRC_URI = "git://github.com/facebook/zstd.git;branch=release;protocol=https \
+           file://run-ptest \
+           "
 
 SRCREV = "f8745da6ff1ad1e7bab384bd1f9d742439278e99"
 UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>\d+(\.\d+)+)"
@@ -42,3 +44,47 @@  PACKAGE_BEFORE_PN = "libzstd"
 FILES:libzstd = "${libdir}/libzstd${SOLIBS}"
 
 BBCLASSEXTEND = "native nativesdk"
+
+inherit ptest
+
+PTEST_BINARIES = "datagen fullbench poolTests fuzzer zstreamtest \
+                  invalidDictionaries legacy decodecorpus"
+
+do_compile_ptest() {
+    oe_runmake -C ${S}/tests ${PTEST_BINARIES} \
+        ZSTD_LEGACY_SUPPORT=${ZSTD_LEGACY_SUPPORT}
+}
+
+do_install_ptest() {
+    install -d ${D}${PTEST_PATH}/tests ${D}${PTEST_PATH}/programs
+
+    # Test binaries and shell script
+    for t in ${PTEST_BINARIES} playTests.sh; do
+        install -m 0755 ${S}/tests/$t ${D}${PTEST_PATH}/tests/
+    done
+
+    # Test data and cli-tests
+    for d in golden-decompression golden-decompression-errors \
+             golden-compression golden-dictionaries dict-files cli-tests; do
+        cp -r ${S}/tests/$d ${D}${PTEST_PATH}/tests/
+    done
+
+    # Source files used as dictionary training corpus
+    install -m 0644 ${S}/tests/*.c ${D}${PTEST_PATH}/tests/
+    install -m 0644 ${S}/programs/*.c ${S}/programs/*.h ${D}${PTEST_PATH}/programs/
+    install -m 0755 ${S}/programs/zstdgrep ${S}/programs/zstdless ${D}${PTEST_PATH}/programs/
+
+    # Remove tests incompatible with ptest environment:
+    # levels.sh: --ultra/--max levels require >8GB RAM for allocation
+    rm -f ${D}${PTEST_PATH}/tests/cli-tests/compression/levels.sh
+    # window-resize.sh: 1GB window size requires >4GB RAM
+    rm -f ${D}${PTEST_PATH}/tests/cli-tests/compression/window-resize.sh
+    # compress-file-to-dir-without-write-perm.sh: ptest runs as root,
+    # which bypasses filesystem permission checks
+    rm -f ${D}${PTEST_PATH}/tests/cli-tests/file-stat/compress-file-to-dir-without-write-perm.sh
+    # cltools/: zstdgrep requires GNU grep --label option not available
+    # in BusyBox grep
+    rm -rf ${D}${PTEST_PATH}/tests/cli-tests/cltools
+}
+
+RDEPENDS:${PN}-ptest += "bash coreutils python3-core python3-io"