. "$BST_LIB" # BST-TIMEOUT: 3000 # ELEVEN python3 starts, and they are the whole cost. # # Every other assertion below reads the filesystem or dpkg # # with shell builtins, greps what one of those starts printed, # # or runs the image's own `zstd' CLI on a 300 kB file. # # # # The eleven are: a bare `import' (the platform gate); the # # probe, which takes ONE start for 128 measurements; one # # reverse cross-check against the zstd CLI's own frame; SIX # # calling-convention arms, which CANNOT share a start # # because a refused vectorcall traps the interpreter rather # # than raising (see the calling-convention section); and two # # `python3 -m pyzstd' runs, the shipped CLI. # # # # The whole suite has measured 59s to 91s on target, so # # 3000 is generous many times over, and it is 600s clear of # # the runner's 3600s ceiling -- a declared bound sitting ON the ceiling # # silently becomes the ceiling. Nothing below is quadratic # # in anything: the largest fixture is 307200 bytes and the # # tightest loop feeds it 97 bytes at a time to a compressor. # # # # A suite-timeout red is a batch-wide cost, so if the # # starts prove slower than that on target the RIGHT fix is # # this number, not fewer arms. # # python3-pyzstd 0.15.10 (meta-openembedded/meta-python # recipes-devtools/python/python3-pyzstd_0.15.10.bb, `inherit pypi setuptools3', # PyPI sdist sha256 83603a97fdbcf2139f475c940789f09e32703f931f29f4a8ddf3551e6700108b) # on the wasm32-hwjs glibc image. # # ============================================================================ # WHAT THE PACKAGE DOES. # ============================================================================ # # Python bindings to Facebook's Zstandard. It VENDORS zstd -- the sdist carries # the whole C library under zstd/ and setup.py links it statically -- so this # package does NOT depend on the image's own `zstd' 1.5.5. The recipe names no # DEPENDS at all, and the built .deb's control # stanza carries `Depends: python3-core' and nothing else. # # That independence is what makes the cross-check below worth having: the image # carries TWO implementations of the same format, from different builds, and # either one can be used as an oracle for the other. # # ============================================================================ # THE PLATFORM GATE: A PURE C EXTENSION WITH NO USABLE PYTHON HALF. # ============================================================================ # # pyzstd/__init__.py tries `from .c import *' (the C extension), falls back to # `from .cffi import *', and otherwise raises its own "Can't import compiled # .so/.pyd file". The cffi backend is NOT a pure-Python fallback -- it is # out-of-line CFFI API mode (build_script/pyzstd_build_cffi.py calls # ffibuilder.set_source), so it is a compiled extension too, needing # _cffi_backend, which this image does not have. The recipe builds the C # backend only. Every name in pyzstd's __all__ comes from the extension, so the # port either loads a side module or it delivers nothing. # # MEASURED AT BUILD TIME on this arm, from the built artifact rather than the # source: # # * The extension links and packages. `bitbake python3-pyzstd' completed with # zero ERROR lines and produced # /usr/lib/python3.12/site-packages/pyzstd/c/_zstd.cpython-312.so, a # genuine wasm side module carrying `dylink.0' and this arm's `hwjs.abi' # section. # # * Its `dylink.0' declares NO NEEDED entries -- it depends on no other shared # library -- and its imports include CPython API symbols # (PyType_FromModuleAndSpec, PyModuleDef_Init, PyObject_VectorcallMethod, # PyEval_SaveThread, the four PyThread_* and so on). # # * It reaches the link as bitcode only because the recipe's bbappend narrows # setup.py's source glob from '*.[cCsS]' to '*.[cC]'. Unnarrowed, the glob # assembles zstd/lib/decompress/huf_decompress_amd64.S -- an x86-64 assembly # file compiled on EVERY unix arm -- which arrives at the side-module link as # native wasm among 30 bitcode inputs and is refused. # # ============================================================================ # THE CALLING CONVENTIONS: a regression guard for work item 186. # ============================================================================ # # CPython calls a `METH_NOARGS' method as meth(self, NULL), while extensions # commonly declare it with one parameter. Until brintos/linux-in-the-browser # work item 186 was fixed, the HWJS F152 open-world dispatch consult refused that # call into a `dlopen'd extension (E8-REFUSE, unregistered-target) and the guest # executed `unreachable': rc=132, and NOT an exception -- no `try' catches it and # the interpreter is gone. On the image before the fix, this suite's four # METH_NOARGS arms trapped and every other case passed. # # Its shipped method tables carry all three conventions -- # METH_VARARGS (decompress, get_frame_size, ZstdCompressor.compress, ...), # METH_O (ZstdCompressor._set_pledged_input_size, ZstdFileReader.readinto) and # METH_NOARGS (ZstdDecompressor._reset_session, ZstdFileReader.readall and # .reset_session, __reduce__ on five types). The six `conv/' cases below take # one arm each, ONE INTERPRETER START EACH, so a regression takes only its own # arm with it. # # THE MAIN PROBE DELIBERATELY CALLS NO METH_NOARGS METHOD. Every file read it # makes passes an explicit size, which routes through readinto (METH_O); a bare # read() would route through readall (METH_NOARGS), and a regression there would # take all 128 measurements down with it. # # ============================================================================ # WHERE THE EXPECTED VALUES COME FROM. # ============================================================================ # # An x86-64 CONTROL built from the same sdist, run at the same version. Nothing # below is read off the source. Three of the ticket's own clauses did not # survive that control and are narrowed here rather than shipped red -- each is # marked THE TICKET ASKED at its case. # # The five frames the probe decompresses are that control's OUTPUT, embedded as # literals: they are frames THIS ARM DID NOT PRODUCE, which is an assertion a # round trip cannot make, because a compressor and a decompressor wrong in the # same way agree with each other perfectly. # # COMPRESSED OUTPUT IS NOT PINNED BY ITS BYTES, on purpose. This arm is 32-bit # where the control is 64-bit; zstd's format is fixed but its dictionary trainer # and internal sizing are `size_t'-shaped, so a byte-level pin would report a # legitimate difference as a regression. The compressor is pinned instead by the # `xcheck/' cases, which play it against the image's own `zstd' CLI -- an # independent implementation of the same format, on the same arm. P=python3-pyzstd require python3 $P/python3-present SITE=/usr/lib/python3.12/site-packages PKG=$SITE/pyzstd SO=$PKG/c/_zstd.cpython-312.so DI=$SITE/pyzstd-0.15.10.dist-info PKGLIST=/var/lib/dpkg/info/python3-pyzstd.list PROBE=$BST_DATA/python3-pyzstd-probe.py NOARGS=$BST_DATA/python3-pyzstd-noargs.py tmp=${TMPDIR:-/tmp} W=$tmp/bst-pyzstd.$$ mkdir -p "$W" || { bst_notok $P/workdir "cannot create $W"; exit 0; } # ---------------------------------------------------------------- packaging -- # WHERE THE PACKAGING SAYS THE MODULE LANDS. These run before any import, so a # red here says the .deb is wrong rather than that the module misbehaves -- which # matters more than usual for this port, because a missing .so and an unloadable # one both end at the same ImportError. check $P/site-packages-dir test -d "$SITE" check $P/package-dir test -d "$PKG" check $P/c-backend-dir test -d "$PKG/c" check $P/extension-present test -f "$SO" check $P/extension-nonempty test -s "$SO" # THE SONAME CARRIES NO PLATFORM TRIPLE. Upstream names an extension # `_zstd.cpython-312-.so'; poky's python3 reports an empty EXT_SUFFIX # triple on this arm, so the file is plain `_zstd.cpython-312.so'. The import # resolves through importlib.machinery.EXTENSION_SUFFIXES, so the two must # agree -- and if a future poky restored the triple, this case reds before the # import does and says why. check_eq $P/extension-name "_zstd.cpython-312.so" \ "$(cd "$PKG/c" 2>/dev/null && echo _zstd.cpython-312*.so)" # THE PURE-PYTHON HALF IS SHIPPED TOO, and it is not a fallback. zstdfile.py and # seekable_zstdfile.py are Python built ON TOP of the extension -- they import it # and cannot work without it -- so their presence is part of what "ported" means # here and their absence would silently remove ZstdFile and open(). check $P/py-init test -s "$PKG/__init__.py" check $P/py-zstdfile test -s "$PKG/zstdfile.py" check $P/py-seekable test -s "$PKG/seekable_zstdfile.py" check $P/py-main test -s "$PKG/__main__.py" check $P/py-c-init test -s "$PKG/c/__init__.py" # TYPE MARKERS. Unlike several of its neighbours this package DOES ship py.typed # and a stub, so a type checker treats it as typed. py.typed is legitimately # zero bytes -- it is a marker, not content -- so it is asserted with -f and not # -s, which is the trap in copying a neighbouring suite's line. check $P/py-typed-marker test -f "$PKG/py.typed" check $P/py-stub test -s "$PKG/__init__.pyi" # THE CFFI BACKEND IS NOT BUILT. setup.py ships both, and picks between them # with --cffi; the recipe takes the default, so pyzstd/cffi/ must be absent. # Asserted so a recipe that flipped it is visible: the cffi backend is ALSO a # compiled extension (out-of-line API mode) and additionally needs # _cffi_backend, which this image does not carry -- so shipping it would turn a # working port into an ImportError. check $P/no-cffi-backend test ! -d "$PKG/cffi" # NO EXECUTABLE. setup.py declares no console_scripts; the CLI is reached as # `python3 -m pyzstd'. Asserted so a future release that started shipping one is # noticed rather than discovered. check $P/no-bin-script test ! -e /usr/bin/pyzstd # --------------------------------------------------------------- dist-info --- check $P/dist-info-dir test -d "$DI" check $P/dist-info-metadata test -f "$DI/METADATA" check_out $P/dist-info-version "Version: 0.15.10" cat "$DI/METADATA" check_out $P/dist-info-name "Name: pyzstd" cat "$DI/METADATA" check $P/dist-info-wheel test -f "$DI/WHEEL" check $P/dist-info-license test -s "$DI/LICENSE" check_out $P/dist-info-toplevel "pyzstd" cat "$DI/top_level.txt" # NOT PURELIB, stated by the packaging itself. `Root-Is-Purelib: false' is the # wheel's own claim that it contains something architecture-specific -- the # opposite of what every pure-Python port here asserts, and the one-line summary # of why this port needed a toolchain that can link a side module at all. check_out $P/dist-info-not-purelib "Root-Is-Purelib: false" cat "$DI/WHEEL" # THE WHEEL TAG IS WRONG, AND IT IS UPSTREAM SETUPTOOLS RATHER THAN THIS PORT. # bdist_wheel computes the tag from the BUILD HOST and the cross build never # tells it otherwise, so the wheel says `cp312-cp312-linux_x86_64' for a wasm32 # module. Nothing reads it at runtime -- the .deb installs the file and dpkg has # the right architecture -- so this is pinned rather than repaired, exactly as # 99-python3-crc32c pins it, so that a poky which started setting the tag # correctly is a visible change and not a silent one. check_out $P/dist-info-tag-is-host "Tag: cp312-cp312-linux_x86_64" cat "$DI/WHEEL" # ------------------------------------------------------------ the .deb file --- # The installed file list. check $P/pkg-list-present test -s "$PKGLIST" # EXACTLY ONE SHARED OBJECT SHIPS. Everything else in the package is Python or # dist-info metadata. A second .so would mean the build produced something this # port did not expect and did not measure -- the cffi backend being the obvious # candidate. check_eq $P/pkg-one-so "1" "$(grep -c '\.so$' "$PKGLIST" 2>/dev/null)" # Every payload path is under site-packages and is one of the shapes above. _bad="" while IFS= read -r _f; do case "$_f" in ''|/usr/lib/python3.12/site-packages) continue ;; */) continue ;; esac [ -d "$_f" ] && continue case "$_f" in *.so|*.py|*.pyc|*.pyi) ;; */py.typed) ;; */METADATA|*/WHEEL|*/RECORD|*/INSTALLER|*/LICENSE|*/LICENSE.*) ;; */entry_points.txt|*/top_level.txt) ;; *) _bad="$_bad $_f" ;; esac done < "$PKGLIST" check_eq $P/pkg-only-expected "" "$_bad" # ------------------------------------------------------------- dpkg status --- sed -n '/^Package: python3-pyzstd$/,/^$/p' /var/lib/dpkg/status > "$W/st" 2>/dev/null check $P/pkg-known test -s "$W/st" check_out $P/pkg-installed "Status: install ok installed" cat "$W/st" check_out $P/pkg-arch "Architecture: wasm32" cat "$W/st" # THE DEPENDENCY SET IS THE PORT'S CLAIM THAT IT WAITS ON NOTHING. The recipe # carries no DEPENDS, the sdist vendors zstd, and the wasm shlibs pass derived # nothing further -- the extension's dylink.0 declares no NEEDED entry, so there # is no library dependency to derive. python3-core is the whole of it, and it is # asserted BY NAME: a control stanza that had lost it would surface as an # ImportError that looked like this port's fault. grep '^Depends:' "$W/st" > "$W/dep" 2>/dev/null || : > "$W/dep" check $P/pkg-depends-line test -s "$W/dep" check_out $P/pkg-depends-python3-core "python3-core" cat "$W/dep" # AND IT DOES NOT DEPEND ON THE IMAGE'S zstd. The vendored copy is the whole # point; a `Depends: ... zstd' would mean the recipe had been switched to # --dynamic-link-zstd, which changes what this port is. check $P/pkg-no-zstd-dep sh -c 'grep -q "zstd" '"$W"'/dep && exit 1 || exit 0' # ------------------------------------------------------------------ import --- # THE PLATFORM GATE, and the first of eleven python3 starts. A dlopen of a side # module in site-packages whose CPython API imports must resolve against a # statically linked dynamic main. check $P/import python3 -c 'import pyzstd' # ------------------------------------------------------------------- probe --- if [ ! -f "$PROBE" ]; then bst_notok $P/probe-present "probe missing at $PROBE" exit 0 fi bst_ok $P/probe-present # THE SECOND START, and the one that carries most of the suite. Bounded at 900s # inside the 3000s suite budget so a hung probe is reported as a probe overrun # with the last line it printed, rather than as a suite timeout that says nothing # about where it stopped. # # The probe EXITS 0 even when the import fails, so this case passing means "the # probe ran", not "the module works" -- `import-ok' below is what carries that. bst_probe $P/probe-run "$W/probe" 900 python3 "$PROBE" "$W" OUT="$W/probe" # pv : the value the probe emitted for , or empty. `head -n 1' # because a key is emitted once and a duplicate would otherwise concatenate; # `cut -f2-' because a value may legitimately contain `='. pv() { grep "^$1=" "$OUT" 2>/dev/null | head -n 1 | cut -d= -f2-; } # The probe reached its end. Every case below reads a value it printed, so a # probe that stopped early would otherwise turn into a run of empty-string # mismatches that all name the wrong thing. check_eq $P/probe-complete "yes" "$(pv probe_done)" # ------------------------------------------------------- the gate's verdict --- _imp=$(pv import_ok) check_eq $P/import-ok "yes" "$_imp" if [ "$_imp" != "yes" ]; then # The extension did not load. Skip -- not red -- every behavioural case, each # with the reason attached: they are all one fact, and a hundred reds would # bury it rather than report it. `import' and `import-ok' above are the two # reds that carry the verdict. _why="pyzstd/c/_zstd.cpython-312.so did not load: $(pv import_error)" for _c in probe-count module-answered version all-count backend-answered \ ext-is-so no-cffi-dir zstd-version zstd-version-info \ config-bitness config-impl config-static-link \ clevel-default clevel-min clevel-max cstream-sizes dstream-sizes \ support-multithread nbworkers-lower nbworkers-max-positive \ windowlog-bounds dparam-windowlogmax \ len-empty len-one len-allbytes len-run len-rand len-big \ rt-empty rt-one rt-allbytes rt-run rt-rand rt-big \ clen-empty clen-one clen-allbytes rand-expands run-collapses \ fi-dsize-empty fi-dsize-one fi-dsize-allbytes fi-dsize-run \ fi-dsize-rand fi-dsize-big fi-dictid-run fsize-run fsize-allbytes \ inc-rt-allbytes inc-rt-run inc-rt-big inc-rt-rand \ inc-nosize-allbytes inc-nosize-run inc-nosize-big inc-nosize-rand \ dec-chunked-rt dec-eof dec-needs-input endless-rt \ single-stops-at-frame \ vec-empty vec-one vec-run vec-stream vec-cksum vec-stream-nosize \ cksum-detects-flip \ lvl-differ-run lvl-differ-big lvl-agree-run lvl-agree-big \ lvl19-not-larger-run lvl19-not-larger-big lvl-same-allbytes \ cparam-matches-level-1 cparam-matches-level-19 \ cparam-huge-level cparam-huge-level-rt cparam-bad-key \ dict-trained dict-id-nonzero dict-smaller dict-smaller-margin \ dict-rt dict-frame-id-matches dict-missing-refused \ finalize-dict-ok finalize-dict-id-differs \ err-truncated err-header-only err-corrupt-body err-garbage \ err-empty-input zstderror-is-exception \ partial-not-eof partial-shorter \ arg-str arg-none arg-int-level \ buf-bytes buf-bytearray buf-memoryview \ file-written file-smaller file-rt-sized file-readable \ file-seekable file-first16 file-text-line \ xcheck-fixtures xcheck-pyzstd-to-zstd xcheck-zstd-to-pyzstd \ conv-varargs conv-meth-o conv-noargs-reset conv-noargs-reduce \ conv-noargs-readall conv-noargs-seekback \ conv-varargs-result conv-meth-o-result conv-noargs-reset-result \ conv-noargs-reduce-result conv-noargs-readall-result \ conv-noargs-seekback-result noargs-present cli-runs cli-version; do bst_skip $P/$_c "$_why" done rm -rf "$W" exit 0 fi check_eq $P/probe-count "128" "$(pv emitted_count)" # ---------------------------------------------------------------- identity --- # WHICH COPY ANSWERED, and which BACKEND. Without these every measurement below # would be a statement about whatever was first on sys.path. check_eq $P/module-answered "$PKG/__init__.py" "$(pv module_file)" check_eq $P/version "0.15.10" "$(pv version)" check_eq $P/all-count "26" "$(pv all_count)" check_eq $P/backend-answered "$PKG/c/__init__.py" "$(pv backend_file)" check_eq $P/ext-is-so "yes" "$(pv ext_is_so)" check_eq $P/no-cffi-dir "no" "$(pv has_cffi_backend)" # ------------------------------------------------------- the vendored zstd --- # The version the sdist vendors, not the image's `zstd' package -- which happens # to be 1.5.5 as well, and the two are independent. check_eq $P/zstd-version "1.5.5" "$(pv zstd_version)" check_eq $P/zstd-version-info "1.5.5" "$(pv zstd_version_info)" # THE ONE VALUE THAT MUST DIFFER FROM THE x86-64 CONTROL. PYZSTD_CONFIG[0] is # the pointer width the extension was compiled at: 32 here, 64 there. It is the # cheapest positive evidence in the suite that the module under test is this # arm's build and not a host artifact that leaked into the rootfs -- the failure # a green run can otherwise hide. check_eq $P/config-bitness "32" "$(pv config_bitness)" check_eq $P/config-impl "c" "$(pv config_impl)" check_eq $P/config-static-link "yes" "$(pv config_static_link)" # Compile-time constants of the vendored library. A toolchain change that # altered any of them would silently change what "level 3" means. check_eq $P/clevel-default "3" "$(pv clevel_default)" check_eq $P/clevel-min "-131072" "$(pv clevel_min)" check_eq $P/clevel-max "22" "$(pv clevel_max)" check_eq $P/cstream-sizes "131072,131591" "$(pv cstream_sizes)" check_eq $P/dstream-sizes "131075,131072" "$(pv dstream_sizes)" # ZSTD_MULTITHREAD is defined by setup.py's static-link branch on every arm, so # the parameter EXISTS and has a non-degenerate bound. This says nbWorkers is # accepted, not that the guest ever runs a second thread. check_eq $P/support-multithread "yes" "$(pv support_multithread)" check_eq $P/nbworkers-lower "0" "$(pv nbworkers_lower)" check_eq $P/nbworkers-max-positive "yes" "$(pv nbworkers_max_positive)" # 30, NOT the control's 31, and that is the SECOND independent statement in # this suite that the arm is 32-bit. zstd defines ZSTD_WINDOWLOG_MAX as # ZSTD_WINDOWLOG_MAX_32 (30) where a pointer is 32 bits and # ZSTD_WINDOWLOG_MAX_64 (31) where it is 64, so the upper bound is a # compile-time fact about the width rather than a preference. Measured on # target 2026-09-10 as `10,30' against the x86-64 control's `10,31'; the # expectation was carried over from the control and is corrected here. # `config-bitness' is the other one, and two independent readings of the # same fact are worth more than one. check_eq $P/windowlog-bounds "10,30" "$(pv windowlog_bounds)" check_eq $P/dparam-windowlogmax "10" "$(pv dparam_windowlogmax_lower)" # ------------------------------------------------------------- the corpus ---- # The ticket's own list, asserted by length so a fixture that changed shape is a # red here rather than a puzzle three cases later. check_eq $P/len-empty "0" "$(pv len_empty)" check_eq $P/len-one "1" "$(pv len_one)" check_eq $P/len-allbytes "256" "$(pv len_allbytes)" check_eq $P/len-run "200000" "$(pv len_run)" check_eq $P/len-rand "65536" "$(pv len_rand)" check_eq $P/len-big "307200" "$(pv len_big)" # --------------------------------------------------- one-shot round trips ---- for _n in empty one allbytes run rand big; do check_eq $P/rt-$_n "yes" "$(pv rt_$_n)" done # The three frame lengths that are small enough to be stable statements about the # format rather than about the match finder: an empty frame is a header and an # end marker, a one-byte frame adds one literal, and 256 distinct bytes are # stored raw with a 10-byte wrapper. Measured on the control. check_eq $P/clen-empty "9" "$(pv c_len_empty)" check_eq $P/clen-one "10" "$(pv c_len_one)" check_eq $P/clen-allbytes "266" "$(pv c_len_allbytes)" # THE TWO BOUNDS THAT SHOW THE COMPRESSOR RAN. Incompressible input must expand # -- 65536 bytes of Mersenne Twister at a named seed goes to 65546 -- and a # 200000-byte single-byte run must collapse under 1 kB. Without these, a # compressor that emitted every block raw would pass every round trip above. check_eq $P/rand-expands "yes" "$(pv rand_expands)" check_eq $P/run-collapses "yes" "$(pv run_ratio_under_1k)" # ------------------------------------------------------- frame introspection -- # get_frame_info reads the HEADER without decompressing, so it is an independent # statement about what the compressor wrote. check_eq $P/fi-dsize-empty "0" "$(pv fi_dsize_empty)" check_eq $P/fi-dsize-one "1" "$(pv fi_dsize_one)" check_eq $P/fi-dsize-allbytes "256" "$(pv fi_dsize_allbytes)" check_eq $P/fi-dsize-run "200000" "$(pv fi_dsize_run)" check_eq $P/fi-dsize-rand "65536" "$(pv fi_dsize_rand)" check_eq $P/fi-dsize-big "307200" "$(pv fi_dsize_big)" check_eq $P/fi-dictid-run "0" "$(pv fi_dictid_run)" check_eq $P/fsize-run "26" "$(pv fsize_run)" check_eq $P/fsize-allbytes "266" "$(pv fsize_allbytes)" # ---------------------------------------------- the incremental compressor ---- # THE TICKET ASKED that the incremental compressor's output be "asserted equal to # the one-shot result". That is FALSE on a correct port and was measured false # on the x86-64 control: `compress(data)' hands the whole input to one # FLUSH_FRAME call and can write the content size into the header, while a # chunk-fed compressor cannot know the size when the header goes out and omits # the field. The streaming frame is therefore a few bytes SHORTER (265 vs 266 on # allbytes, 23 vs 26 on the run) and cannot be byte-equal. # # Narrowed to the claim the requirement was reaching for -- the incremental path # must produce a frame that decompresses to the same bytes -- and the omitted # content size is asserted in its own right, so the reason the byte equality # fails is itself pinned rather than merely explained here. for _n in allbytes run big rand; do check_eq $P/inc-rt-$_n "yes" "$(pv inc_rt_$_n)" check_eq $P/inc-nosize-$_n "yes" "$(pv inc_nosize_$_n)" done # -------------------------------------------- the incremental decompressor ---- # Fed 13 bytes at a time, smaller than a frame header, so the decompressor holds # state across calls that produce no output at all. check_eq $P/dec-chunked-rt "yes" "$(pv dec_chunked_rt)" check_eq $P/dec-eof "yes" "$(pv dec_eof)" check_eq $P/dec-needs-input "no" "$(pv dec_needs_input)" # ZstdDecompressor stops at the first frame's end; EndlessZstdDecompressor does # not. Two concatenated frames tell them apart, and getting this backwards is a # silent truncation rather than an error. check_eq $P/endless-rt "yes" "$(pv endless_rt)" check_eq $P/single-stops-at-frame "yes" "$(pv single_stops_at_frame)" # ------------------------------------------------------- external vectors ----- # FRAMES THIS ARM DID NOT PRODUCE, from the x86-64 control. Five shapes: an # empty frame, a single literal, 26 bytes that expand to 200000, the same run # written with NO content size so the decompressor cannot preallocate, and the # run again with an XXH64 checksum trailer to verify. check_eq $P/vec-empty "yes" "$(pv vec_empty)" check_eq $P/vec-one "yes" "$(pv vec_one)" check_eq $P/vec-run "yes" "$(pv vec_run)" check_eq $P/vec-stream "yes" "$(pv vec_stream)" check_eq $P/vec-cksum "yes" "$(pv vec_cksum)" check_eq $P/vec-stream-nosize "yes" "$(pv vec_stream_nosize)" # A FLIPPED CHECKSUM BYTE MUST RAISE. The frame's content still decodes # perfectly; only the trailer disagrees. A decompressor that skipped the trailer # would return the right bytes, and this is the only case that would notice. check_eq $P/cksum-detects-flip "ZstdError" "$(pv cksum_detects_flip)" # ------------------------------------------------------------- the levels ----- # THE TICKET ASKED that levels 1 and 19 "differ in output". True of a # compressible payload, FALSE of `allbytes' -- 256 distinct bytes have nothing to # find, so the control emits byte-identical output at 1, 3 and 19. Asserted on # the two payloads that do compress, and the allbytes identity is kept as the # NEGATIVE CONTROL rather than dropped: a level knob that started changing # incompressible output would be worth knowing about. check_eq $P/lvl-differ-run "yes" "$(pv lvl_differ_run)" check_eq $P/lvl-differ-big "yes" "$(pv lvl_differ_big)" check_eq $P/lvl-agree-run "yes" "$(pv lvl_agree_run)" check_eq $P/lvl-agree-big "yes" "$(pv lvl_agree_big)" check_eq $P/lvl19-not-larger-run "yes" "$(pv lvl19_not_larger_run)" check_eq $P/lvl19-not-larger-big "yes" "$(pv lvl19_not_larger_big)" check_eq $P/lvl-same-allbytes "yes" "$(pv lvl_same_allbytes)" # THE ADVANCED API MUST REPRODUCE THE LEVEL ARGUMENT EXACTLY. Two different # paths into ZSTD_CCtx_setParameter must land on the same frame byte for byte. # This is an equality between two results of THIS build, so unlike a cross-arm # hash it can be asserted as bytes. check_eq $P/cparam-matches-level-1 "yes" "$(pv cparam_matches_level_1)" check_eq $P/cparam-matches-level-19 "yes" "$(pv cparam_matches_level_19)" # AN OUT-OF-RANGE LEVEL IS CLAMPED; AN UNKNOWN PARAMETER KEY IS REFUSED. The # pair is measured rather than reasoned: they look like one rule and are not. # ZSTD_CCtx_setParameter bounds compressionLevel silently, so 10**9 compresses at # the maximum and round-trips; a key naming no parameter has nothing to bound. check_eq $P/cparam-huge-level "accepted" "$(pv cparam_huge_level)" check_eq $P/cparam-huge-level-rt "yes" "$(pv cparam_huge_level_rt)" check_eq $P/cparam-bad-key "ZstdError" "$(pv cparam_bad_key)" # ------------------------------------------------------------- dictionary ----- # THE TICKET ASKED that a trained dictionary compress a matching sample smaller # than the dictionary-free call. True, and only for inputs small enough that the # compressor cannot build its own statistics -- which is what a zstd dictionary # is FOR. The first attempt at this fixture used long repetitive samples and # measured `dict_smaller=no' on the control, with plain compression already at # the floor; the shipped fixture is 1000 short JSON-shaped records and one more # of the same, where the control measures 320 bytes plain against 155 with the # dictionary. # # THE DICTIONARY'S CONTENT AND ID ARE NOT PINNED. ZDICT_trainFromBuffer runs a # parameter search over `size_t' sizes, and this arm is 32-bit where the control # is 64-bit, so the trained bytes may legitimately differ. What is asserted is # the property the ticket asked for, plus the round trip, both of which hold # whatever the trainer produced. check_eq $P/dict-trained "yes" "$(pv dict_trained)" check_eq $P/dict-id-nonzero "yes" "$(pv dict_id_nonzero)" check_eq $P/dict-smaller "yes" "$(pv dict_smaller)" check_eq $P/dict-smaller-margin "yes" "$(pv dict_smaller_margin_2x)" check_eq $P/dict-rt "yes" "$(pv dict_rt)" # A DICTIONARY FRAME NAMES ITS DICTIONARY, and decompressing it without one must # FAIL rather than return plausible rubbish. check_eq $P/dict-frame-id-matches "yes" "$(pv dict_frame_id_matches)" check_eq $P/dict-missing-refused "ZstdError" "$(pv dict_missing_refused)" # finalize_dict needs zstd >= 1.4.5, which the vendored 1.5.5 satisfies. Its # size argument is a FLOOR, not a maximum -- finalizing an 8192-byte basis into # 4096 raises "Destination buffer is too small", measured on the control. check_eq $P/finalize-dict-ok "yes" "$(pv finalize_dict_ok)" check_eq $P/finalize-dict-id-differs "yes" "$(pv finalize_dict_id_differs)" # ------------------------------------------------------------- error paths ---- # TRUNCATED AND CORRUPTED FRAMES MUST RAISE, NOT RETURN SHORT. A decompressor # that returned what it had decoded so far would pass every round trip in this # file and lose the tail of every damaged frame in production. check_eq $P/err-truncated "ZstdError" "$(pv err_truncated)" check_eq $P/err-header-only "ZstdError" "$(pv err_header_only)" check_eq $P/err-corrupt-body "ZstdError" "$(pv err_corrupt_body)" check_eq $P/err-garbage "ZstdError" "$(pv err_garbage)" # EMPTY INPUT IS ACCEPTED and returns b'' -- it is not an error. Measured on the # control; pinned because "decompress refuses invalid input" reads as though it # should cover this case and does not. check_eq $P/err-empty-input "accepted" "$(pv err_empty_input)" check_eq $P/zstderror-is-exception "yes" "$(pv zstderror_is_exception)" # THE INCREMENTAL PATH TREATS THE SAME TRUNCATION DIFFERENTLY, and it is right # to: the one-shot call knows the frame ended early, while the incremental one # cannot know the caller has no more to give. So `eof' stays false and what came # back is short -- an unfinished stream, not an error. check_eq $P/partial-not-eof "yes" "$(pv partial_not_eof)" check_eq $P/partial-shorter "yes" "$(pv partial_shorter)" # Argument-type refusals. `str' has no defined encoding to compress. check_eq $P/arg-str "TypeError" "$(pv arg_str)" check_eq $P/arg-none "TypeError" "$(pv arg_none)" check_eq $P/arg-int-level "TypeError" "$(pv arg_int_level)" # --------------------------------------------------- the buffer protocol ------ check_eq $P/buf-bytes "yes" "$(pv buf_bytes)" check_eq $P/buf-bytearray "yes" "$(pv buf_bytearray)" check_eq $P/buf-memoryview "yes" "$(pv buf_memoryview)" # ------------------------------------------------------ ZstdFile and open() --- # Every read here passed an explicit SIZE, which routes through readinto # (METH_O). The size-less read is `conv/noargs-readall' below, on purpose. check_eq $P/file-written "yes" "$(pv file_written)" check_eq $P/file-smaller "yes" "$(pv file_smaller_than_input)" check_eq $P/file-rt-sized "yes" "$(pv file_rt_sized)" check_eq $P/file-readable "yes" "$(pv file_readable)" check_eq $P/file-seekable "yes" "$(pv file_seekable)" check_eq $P/file-first16 "000102030405060708090a0b0c0d0e0f" "$(pv file_first16)" check_eq $P/file-text-line "brintOS pyzstd text mode" "$(pv file_text_line)" # ============================================================================ # CROSS-CHECK AGAINST THE IMAGE'S OWN zstd CLI. # ============================================================================ # # THE ASSERTION A ROUND TRIP CANNOT MAKE. Everything above that involves # compression is checked by decompressing it again with the same code, and a # compressor and a decompressor wrong in the same way agree with each other # perfectly -- they would produce a frame no other zstd on earth could read and # pass every case in this file. The image carries an INDEPENDENT implementation # of the same format, `zstd' 1.5.5 from poky, built separately and linked # separately, so it can be the oracle. # # Compressed output is NOT pinned by a byte hash anywhere in this suite, and this # pair of cases is what stands in for that: pinning a hash would compare a # 32-bit build against a 64-bit control and report a legitimate difference as a # regression, while this compares two implementations on the SAME arm. # # A `zstd' that is absent or cannot run is a legitimate SKIP rather than a red: # it is the oracle that is missing, not the subject. 56-zstd owns that binary. check_eq $P/xcheck-fixtures "yes" "$(pv xcheck_fixtures)" if command -v zstd >/dev/null 2>&1 && zstd --version >/dev/null 2>&1; then # FORWARD: pyzstd compressed it, zstd must decompress it to the original bytes. zstd -q -d -c "$W/xc-pyzstd.zst" > "$W/xc-out.bin" 2>"$W/xc-fwd.err" check $P/xcheck-pyzstd-to-zstd cmp -s "$W/xc-plain.bin" "$W/xc-out.bin" # REVERSE: zstd compressed it, pyzstd must decompress it to the original bytes. # This is the third start, and it is worth its cost: it is the only case in # the suite that feeds the decompressor a frame produced by a DIFFERENT zstd # build on this same arm. zstd -q -c "$W/xc-plain.bin" > "$W/xc-zstd.zst" 2>"$W/xc-rev.err" check_out $P/xcheck-zstd-to-pyzstd "XCHECK=ok" python3 -c 'import pyzstd, sys d = open(sys.argv[1], "rb").read() p = open(sys.argv[2], "rb").read() print("XCHECK=ok" if pyzstd.decompress(d) == p else "XCHECK=mismatch")' \ "$W/xc-zstd.zst" "$W/xc-plain.bin" else _zw="zstd CLI not usable on this image; pyzstd vendors its own zstd and does not need it" bst_skip $P/xcheck-pyzstd-to-zstd "$_zw" bst_skip $P/xcheck-zstd-to-pyzstd "$_zw" fi # ============================================================================ # THE CALLING-CONVENTION TABLE. # ============================================================================ # # ONE INTERPRETER START PER ARM, because a refused vectorcall traps the # interpreter (rc=132, `RuntimeError: unreachable') rather than raising, so a # shared start would report the first refusal and lose every arm after it. # # Each arm emits TWO cases: `conv/' is bst_probe's own verdict on the # process -- ok iff it exited 0, and the red carries rc=132 when the vectorcall # was refused -- and `conv/-result' asserts the word the arm printed, which # is what separates "ran and did the wrong thing" from "was refused". # # EVERY ARM IS ASSERTED TO SUCCEED: a correct platform passes all six, so a red # here is a true statement about a dispatch regression. if [ ! -f "$NOARGS" ]; then bst_notok $P/noargs-present "convention probe missing at $NOARGS" else bst_ok $P/noargs-present # varargs first: it is the CONTROL. If this arm is refused, the refusal is not # convention-specific and the five arms after it say nothing at all. for _arm in varargs meth_o noargs_reset noargs_reduce noargs_readall \ noargs_seekback; do _id=$(echo "$_arm" | tr '_' '-') bst_probe $P/conv-$_id "$W/conv-$_arm" 240 python3 "$NOARGS" "$_arm" "$W" _want=ok [ "$_arm" = noargs_reduce ] && _want=TypeError check_eq $P/conv-$_id-result "$_want" \ "$(grep '^RESULT=' "$W/conv-$_arm" 2>/dev/null | head -n 1 | cut -d= -f2-)" done fi # ============================================================================ # THE SHIPPED CLI. # ============================================================================ # # pyzstd ships an 18 kB __main__.py, so `python3 -m pyzstd' is part of what this # package delivers and nothing above exercises it. It is asserted on its banner # rather than on a compression run: the banner names BOTH versions -- the module's # and the vendored library's -- in one line, which is the whole of what a user # checking their install looks at. # # NOTE this route reaches ZstdFile for any real work, so if the NOARGS arms above # are refused this case tells you whether the CLI gets as far as printing. check_out $P/cli-version "pyzstd module v0.15.10" \ sh -c 'python3 -m pyzstd --help 2>&1 | head -n 3; exit 0' check_out $P/cli-runs "zstd library v1.5.5" \ sh -c 'python3 -m pyzstd --help 2>&1 | head -n 3; exit 0' rm -rf "$W"