. "$BST_LIB" # BST-TIMEOUT: 1200 # THREE python3 starts, and they are very nearly the whole # # cost. Everything else below reads the filesystem or dpkg # # with shell builtins, or greps the output of one of those # # starts. # # # # They are: a bare `import' (the platform gate), the probe, # # which takes ONE start for seventy-odd measurements AND for # # the package's own unit suite (500 cases on this arm), run # # in-process, and `import-quiet' at the end. # # # # The work inside each start is bit operations over at most # # 256 bits plus that unit suite, which measured 0.215s on # # the x86-64 control -- both microseconds-to-a-fraction-of- # # a-second beside an interpreter start on this arm, which is # # tens of seconds before the first line of the program runs. # # # # 1200 is 400s per start, the budget 99-python3-crc32c gives # # its three. Measured on target: the whole suite in 67s. # # Nothing below is quadratic in anything. # # # # 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 cases. # # python3-bitarray 2.9.2 (meta-openembedded/meta-python # recipes-devtools/python/python3-bitarray_2.9.2.bb, `inherit setuptools3 pypi', # PyPI sdist) on the wasm32-hwjs glibc image. # # ============================================================================ # WHAT THE PACKAGE DOES. # ============================================================================ # # An array of booleans stored ONE BIT PER ELEMENT, as a C extension: the # sequence protocol (indexing, slicing with a step, count, search), the bitwise # operators (&, |, ^, ~, <<, >>), conversion to and from bytes in either bit # order, and `bitarray.util''s conversions to and from integers and hex. # # Because the storage is bits inside bytes, almost every operation is a SHIFT # and a MASK. That is the whole risk surface of this port: a miscompiled shift # does not crash, it writes the wrong bits -- so the cases below compare against # literals rather than against another call on the same object, and the two # operations where a wrong shift is completely silent (unaligned slice # assignment and `bytereverse') get cases of their own. # # ============================================================================ # THE PLATFORM GATE: THE EXTENSION *IS* THE MODULE. # ============================================================================ # # bitarray has NO pure-Python half, and this is not an inference from the file # list -- it is two unconditional import statements in the shipped source: # # bitarray/__init__.py:14 from bitarray._bitarray import (bitarray, ...) # bitarray/util.py:15 from bitarray._util import (...) # # Neither is wrapped in a try/except and neither has a fallback path. So the # port either loads TWO side modules or it delivers nothing at all. # # `_bitarray.cpython-312.so' carries 115 wasm imports, ~100 of them # `env.Py*'/`_Py*' plus GOT.mem DATA imports (PyType_Type, PyExc_TypeError, # _Py_NoneStruct, PyBool_Type, PySlice_Type), which bind against the CPython C # API the dynamic main publishes through wasmld's WASMLD_DYN_EXPORT_LIBC. So # `import bitarray' is a dlopen whose every one of those must bind, followed by # the module's own init on the hwjs coroutine runtime. # # SO THE SUITE IS BUILT TO BE INFORMATIVE EITHER WAY, which is the same choice # 99-python3-crc32c makes and for the same reason. If the import fails, the probe # reports `import_ok=no' with the exception, the import cases red carrying it, # and every behavioural case is SKIPPED with that reason attached -- seventy reds # all naming one platform fact would bury it rather than report it. If it # succeeds, every behavioural case runs. # # ============================================================================ # WHERE THE EXPECTED VALUES COME FROM. # ============================================================================ # # MEASURED ON AN x86-64 CONTROL AT THE SAME VERSION. bitarray 2.9.2 was built # from the very sdist this recipe fetches -- downloads/bitarray-2.9.2.tar.gz, # sha256 a8f286a5... , the one named in the recipe's SRC_URI[sha256sum] -- and # `data/python3-bitarray-probe.py', the same file the target runs, was run # against it. Every literal below is that run's OUTPUT. # # It is not a reading of the source and not a value computed in the probe: a # probe that computed its own expectations would agree with itself no matter # what the extension did. The control ran CPython 3.10 against the target's # 3.12; every value asserted here is a property of the bit layout or of the C # code, neither of which the interpreter version reaches. # # Two control results are worth naming because they are not what the source # reads like: # # * `ba2hex' of the SAME twelve bits gives `d2f' big-endian and `b4f' # little-endian -- the nibbles are not merely reversed, because the bit # order changes within each byte and the trailing four bits are padding in # one case and not the other. # # * `buffer_info()[3]' -- the unused padding bits -- is 0 for an EMPTY # bitarray, not 8. Zero bits in zero bytes leaves nothing unused, which is # the boundary a `(8 - n % 8)' written without the modulo gets wrong. # # The packaging values come from the .deb this recipe produced # (python3-bitarray_2.9.2-r0_wasm32.deb), read with dpkg-deb. P=python3-bitarray # ============================================================================ # The suite proper. # ============================================================================ require python3 $P/python3-present SITE=/usr/lib/python3.12/site-packages PKG=$SITE/bitarray SO=$PKG/_bitarray.cpython-312.so USO=$PKG/_util.cpython-312.so DI=$SITE/bitarray-2.9.2.dist-info PKGLIST=/var/lib/dpkg/info/python3-bitarray.list PROBE=$BST_DATA/python3-bitarray-probe.py tmp=${TMPDIR:-/tmp} W=$tmp/bst-bitarray.$$ 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, since 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" # BOTH extensions ship. `bitarray' and `bitarray.util' are two separate side # modules behind two separate unconditional imports, so an image carrying one # and not the other is a real outcome and is asserted rather than assumed. check $P/ext-bitarray-present test -f "$SO" check $P/ext-bitarray-nonempty test -s "$SO" check $P/ext-util-present test -f "$USO" check $P/ext-util-nonempty test -s "$USO" # THE SONAMES CARRY NO PLATFORM TRIPLE. Upstream names an extension # `_bitarray.cpython-312-.so'; poky's python3 reports an empty # EXT_SUFFIX triple on this arm, so the files are plain `_bitarray.cpython-312.so' # and `_util.cpython-312.so'. The import resolves through # importlib.machinery.EXTENSION_SUFFIXES, so the two must agree -- and if a # future poky restored the triple, these cases red before the import does and # say why. check_eq $P/ext-bitarray-name "_bitarray.cpython-312.so" \ "$(cd "$PKG" 2>/dev/null && echo _bitarray.cpython-312*.so)" check_eq $P/ext-util-name "_util.cpython-312.so" \ "$(cd "$PKG" 2>/dev/null && echo _util.cpython-312*.so)" # THE PYTHON HALVES ARE PRESENT AND ARE NOT A FALLBACK. `__init__.py' and # `util.py' DO ship -- unlike crc32c, which has no .py at all -- so their # presence must not be read as this package having a pure-Python path. What # makes it extension-only is that each is an unconditional `from bitarray._* # import', asserted by name below. check $P/py-init-present test -s "$PKG/__init__.py" check $P/py-util-present test -s "$PKG/util.py" check_out $P/py-init-imports-ext "from bitarray._bitarray import" \ cat "$PKG/__init__.py" check_out $P/py-util-imports-ext "from bitarray._util import" \ cat "$PKG/util.py" # NO try/except IN `__init__.py' -- the mechanical form of "there is no # fallback" for the import every user makes. A release that grew one would change # what this port is and wants noticing, and it would do so silently: every # behavioural case below would keep passing on a pure-Python path. `util.py' is # not counted: it has function-level `try:' blocks of its own, and its extension # import is the module-level line `py-util-imports-ext' asserts. check_eq $P/py-init-no-try "0" \ "$(grep -c '^[[:space:]]*try:' "$PKG/__init__.py" 2>/dev/null)" # THE SHIPPED UNIT TESTS ARE IN THE MODULE, which is why this port needs no # `-ptest' and no python3-pytest. They are the substance of the port and the # probe runs them in-process. check $P/tests-bitarray-present test -s "$PKG/test_bitarray.py" check $P/tests-util-present test -s "$PKG/test_util.py" # Their two pickle fixtures ship too; `test_bitarray' loads them by name and # would error rather than fail if they were packaged away. check $P/tests-pickle-150 test -f "$PKG/test_150.pickle" check $P/tests-pickle-281 test -f "$PKG/test_281.pickle" # NO EXECUTABLE. setup.py declares no console_scripts, so nothing lands in # /usr/bin. Asserted so a future release that started shipping one is noticed. check $P/no-bin-script test ! -e /usr/bin/bitarray # --------------------------------------------------------------- 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: 2.9.2" cat "$DI/METADATA" check_out $P/dist-info-name "Name: bitarray" 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-top-level "bitarray" 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 is different. 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 is what installs the files and # dpkg has the right architecture -- so this is recorded rather than repaired: # fixing it means patching the tag out of a metadata file no consumer on this # image opens. The case pins the current value so that a poky which started # setting the tag correctly is a visible change and not a silent one. Identical # to python3-crc32c's `dist-info-tag-is-host'. check_out $P/dist-info-tag-is-host "Tag: cp312-cp312-linux_x86_64" cat "$DI/WHEEL" # ------------------------------------------------------------ the .deb file --- check $P/pkg-list-present test -s "$PKGLIST" # EXACTLY TWO SHARED OBJECTS SHIP. A third would mean the build produced # something this port did not expect and did not measure. check_eq $P/pkg-two-so "2" "$(grep -c '\.so$' "$PKGLIST" 2>/dev/null)" # Every payload path is under site-packages and is one of the shapes this port # ships, in the directory it ships in. # THIS dpkg WRITES DIRECTORY ENTRIES WITHOUT A TRAILING SLASH, unlike a # `dpkg -L' on a Debian host: the list file carries `/.', `/usr', `/usr/lib', # `/usr/lib/python3.12' and the two package directories as bare paths. So the # parent directories are excluded by name, and a NEW directory appearing in the # payload still reds this case, which is what it is for. check_eq $P/pkg-only-expected "" \ "$(grep -v '/$' "$PKGLIST" 2>/dev/null \ | grep -vxE '/\.|/usr|/usr/lib|/usr/lib/python3\.12|/usr/lib/python3\.12/site-packages' \ | grep -vxE '/usr/lib/python3\.12/site-packages/bitarray(-2\.9\.2\.dist-info|/__pycache__)?' \ | grep -vxE '/usr/lib/python3\.12/site-packages/bitarray/(__pycache__/)?[A-Za-z0-9_.-]+\.(so|py|pyi|pyc|h|pickle)|/usr/lib/python3\.12/site-packages/bitarray/py\.typed' \ | grep -vxE '/usr/lib/python3\.12/site-packages/bitarray-2\.9\.2\.dist-info/(METADATA|WHEEL|RECORD|INSTALLER|LICENSE|top_level\.txt)' \ | tr '\n' ' ' | sed 's/ *$//')" # ------------------------------------------------------------- dpkg status --- sed -n '/^Package: python3-bitarray$/,/^$/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" # THE DEPENDENCY SET IS THE PORT'S CLAIM THAT IT WAITS ON NOTHING. The recipe # carries no DEPENDS and no third-party RDEPENDS, and the wasm shlibs pass # derived nothing further, so python3-core is the whole of it -- read from the # built .deb, whose Depends field is exactly `python3-core'. 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" # The package's architecture is this arm's, which is the half the wrong wheel tag # above might otherwise be read as contradicting. check_out $P/pkg-arch "Architecture: wasm32" cat "$W/st" # ------------------------------------------------------------------ import --- # THE PLATFORM GATE, and the first of two python3 starts. See the header: this is # a dlopen of a side module in site-packages whose ~100 CPython API imports must # bind against the dynamic main, and which must then survive its own module init # on the hwjs coroutine runtime. check $P/import python3 -c 'import bitarray' # ------------------------------------------------------------------- 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 the suite. Bounded at 900s inside # the 1200s 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" _prc=$? 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 --- # ONE case for each of the two side modules, each carrying its own exception. _imp=$(pv import_ok) _uimp=$(pv util_import_ok) check_eq $P/import-ok "yes" "$_imp" check_eq $P/util-import-ok "yes" "$_uimp" if [ "$_imp" != "yes" ] || [ "$_uimp" != "yes" ]; then # An extension did not load. Skip -- not red -- every behavioural case, each # with the reason attached: they are all one fact, and seventy reds would bury # it rather than report it. `import', `import-ok' and `util-import-ok' above # are the reds that carry the verdict, and the design doc attributes them. # An EMPTY verdict is not a failed import: the probe stopped before printing # one, and `probe-run' above carries why. if [ -z "$_imp" ] || { [ "$_imp" = "yes" ] && [ -z "$_uimp" ]; }; then _why="the probe stopped before its import verdict (rc=$_prc; probe-run carries its stderr)" elif [ "$_imp" != "yes" ]; then _why="_bitarray.cpython-312.so did not load: $(pv import_error)" else _why="_util.cpython-312.so did not load: $(pv util_import_error)" fi for _c in probe-count module-answered ext-answered util-ext-answered \ is-extension version-attr dist-version \ tobytes-big-110 tobytes-lit-110 tobytes-big-1101001 \ tobytes-lit-1101001 frombytes-big-c0 frombytes-lit-03 \ ba2int-big-1101 ba2int-lit-1101 int2ba-big-13-4 int2ba-lit-13-4 \ ba2int-big-10110 int2ba-big-22-5 ba2hex-big-12 ba2hex-lit-12 \ hex2ba-big-d2f \ bi-size-0 bi-unused-0 bi-endian-0 bi-size-1 bi-unused-1 \ bi-endian-1 bi-size-7 bi-unused-7 bi-endian-7 bi-size-8 \ bi-unused-8 bi-endian-8 bi-size-9 bi-unused-9 bi-endian-9 \ bi-size-12 bi-unused-12 bi-endian-12 bi-size-16 bi-unused-16 \ bi-endian-16 \ idx-0 idx-1 idx-last slice-1-6 slice-step2 slice-1-step3 \ count-1 count-0 search-10 search-1 invert \ bit-and bit-or bit-xor bit-shl2 bit-shr2 bit-not \ unaligned-assign strided-assign bytereverse \ shipped-tests-ran shipped-tests-count shipped-tests-errors \ shipped-tests-failures shipped-tests-ok \ huffman-symbols huffman-length-order huffman-prefix-free \ err-bad-char err-index err-int2ba-short err-hex-badchar \ hex-odd-len hex-odd-bits seq-reversed bytereverse-one \ import-quiet; do bst_skip $P/$_c "$_why" done exit 0 fi check_eq $P/probe-count "86" "$(pv emitted_count)" # ---------------------------------------------------------------- identity --- # WHICH COPY ANSWERED. Without this every value 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/ext-answered "$SO" "$(pv bitarray_ext_file)" check_eq $P/util-ext-answered "$USO" "$(pv util_ext_file)" check_eq $P/is-extension "yes" "$(pv bitarray_is_ext)" check_eq $P/version-attr "2.9.2" "$(pv version_attr)" check_eq $P/dist-version "2.9.2" "$(pv dist_version)" # ------------------------------------------------- bit and byte ordering --- # THE TICKET'S FIRST QUESTION, and the surface where a wrong answer is silent. # `110' big-endian fills from the MSB -- 0xc0 -- and little-endian from the LSB # -- 0x03. `1101001' straddles nothing at seven bits but exercises the padding: # 0xd2 big, 0x4b little. `frombytes' reverses `tobytes' rather than being # compared against another call on the same object. check_eq $P/tobytes-big-110 "c0" "$(pv tobytes_big_110)" check_eq $P/tobytes-lit-110 "03" "$(pv tobytes_lit_110)" check_eq $P/tobytes-big-1101001 "d2" "$(pv tobytes_big_1101001)" check_eq $P/tobytes-lit-1101001 "4b" "$(pv tobytes_lit_1101001)" check_eq $P/frombytes-big-c0 "11000000" "$(pv frombytes_big_c0)" check_eq $P/frombytes-lit-03 "11000000" "$(pv frombytes_lit_03)" # ------------------------------- bitarray.util: int and hex, non-byte lengths --- # 4, 5 and 12 bits -- deliberately NOT a whole number of bytes, which is where # the padding and the shift interact. The same four bits read 13 big-endian and # 11 little-endian, and `int2ba' inverts each within its own bit order. check_eq $P/ba2int-big-1101 "13" "$(pv ba2int_big_1101)" check_eq $P/ba2int-lit-1101 "11" "$(pv ba2int_lit_1101)" check_eq $P/int2ba-big-13-4 "1101" "$(pv int2ba_big_13_4)" check_eq $P/int2ba-lit-13-4 "1011" "$(pv int2ba_lit_13_4)" check_eq $P/ba2int-big-10110 "22" "$(pv ba2int_big_10110)" check_eq $P/int2ba-big-22-5 "10110" "$(pv int2ba_big_22_5)" # The SAME twelve bits, both bit orders: `d2f' and `b4f'. Not merely reversed # nibbles -- the order changes within each byte and the trailing four bits are # padding in one case and not the other, which is why both are pinned. check_eq $P/ba2hex-big-12 "d2f" "$(pv ba2hex_big_12)" check_eq $P/ba2hex-lit-12 "b4f" "$(pv ba2hex_lit_12)" check_eq $P/hex2ba-big-d2f "110100101111" "$(pv hex2ba_big_d2f)" # --------------------------------------------------- buffer_info() padding --- # The padding the documentation specifies: 7 unused bits for one bit, 0 for # eight, 4 for twelve. The EMPTY case is the boundary worth having -- zero bits # in zero bytes leaves 0 unused, not 8, which is what a `(8 - n % 8)' written # without the modulo gets wrong. check_eq $P/bi-size-0 "0" "$(pv bi_size_0)" check_eq $P/bi-unused-0 "0" "$(pv bi_unused_0)" check_eq $P/bi-endian-0 "big" "$(pv bi_endian_0)" check_eq $P/bi-size-1 "1" "$(pv bi_size_1)" check_eq $P/bi-unused-1 "7" "$(pv bi_unused_1)" check_eq $P/bi-endian-1 "big" "$(pv bi_endian_1)" check_eq $P/bi-size-7 "1" "$(pv bi_size_7)" check_eq $P/bi-unused-7 "1" "$(pv bi_unused_7)" check_eq $P/bi-endian-7 "big" "$(pv bi_endian_7)" check_eq $P/bi-size-8 "1" "$(pv bi_size_8)" check_eq $P/bi-unused-8 "0" "$(pv bi_unused_8)" check_eq $P/bi-endian-8 "big" "$(pv bi_endian_8)" check_eq $P/bi-size-9 "2" "$(pv bi_size_9)" check_eq $P/bi-unused-9 "7" "$(pv bi_unused_9)" check_eq $P/bi-endian-9 "big" "$(pv bi_endian_9)" check_eq $P/bi-size-12 "2" "$(pv bi_size_12)" check_eq $P/bi-unused-12 "4" "$(pv bi_unused_12)" check_eq $P/bi-endian-12 "big" "$(pv bi_endian_12)" check_eq $P/bi-size-16 "2" "$(pv bi_size_16)" check_eq $P/bi-unused-16 "0" "$(pv bi_unused_16)" check_eq $P/bi-endian-16 "big" "$(pv bi_endian_16)" # ------------------------------------------------------- the sequence surface --- # `11010010' throughout, each answer a hand-checked literal rather than another # call on the same object. The strided slices are the ones a wrong stride walks # off quietly: `[::2]' takes bits 0,2,4,6 and `[1::3]' bits 1,4,7. check_eq $P/idx-0 "1" "$(pv idx_0)" check_eq $P/idx-1 "1" "$(pv idx_1)" check_eq $P/idx-last "0" "$(pv idx_last)" check_eq $P/slice-1-6 "10100" "$(pv slice_1_6)" check_eq $P/slice-step2 "1001" "$(pv slice_step2)" check_eq $P/slice-1-step3 "100" "$(pv slice_1_step3)" check_eq $P/count-1 "4" "$(pv count_1)" check_eq $P/count-0 "4" "$(pv count_0)" # `search' returns every start offset, overlapping included -- so `1' matches at # four positions and `10' at three, which a non-overlapping scan would get wrong. check_eq $P/search-10 "1,3,6" "$(pv search_10)" check_eq $P/search-1 "0,1,3,6" "$(pv search_1)" check_eq $P/invert "00101101" "$(pv invert)" # ------------------------------------------------------- the bitwise surface --- # Two operands whose set bits straddle the byte boundary. `<<' and `>>' are the # pair a miscompiled shift breaks silently and they shift the WHOLE array, not # each byte -- bits shifted past either end are dropped and zeros come in. check_eq $P/bit-and "10010000" "$(pv bit_and)" check_eq $P/bit-or "11110111" "$(pv bit_or)" check_eq $P/bit-xor "01100111" "$(pv bit_xor)" check_eq $P/bit-shl2 "01001000" "$(pv bit_shl2)" check_eq $P/bit-shr2 "00110100" "$(pv bit_shr2)" check_eq $P/bit-not "00101101" "$(pv bit_not)" # ------------------------------ unaligned slice assignment, and bytereverse --- # THE TWO OPERATIONS A MISCOMPILED SHIFT BREAKS COMPLETELY SILENTLY: neither # raises, both simply write the wrong bits. The slices start at bit 3 # deliberately -- a byte-aligned assignment is a memcpy and would not exercise # the shift at all -- and `bytereverse' reverses the bits WITHIN each byte # without moving the bytes, which is the operation a wrong table gets backwards. check_eq $P/unaligned-assign "0001111110000000" "$(pv unaligned_assign)" check_eq $P/strided-assign "0001010101010000" "$(pv strided_assign)" check_eq $P/bytereverse "0100101100001101" "$(pv bytereverse)" # ------------------------------------------- the package's own shipped tests --- # THE SUBSTANCE OF THE PORT. `bitarray.test()' runs test_bitarray.py AND # test_util.py in-process -- both ship inside the installed module, which is why # this port needs no `-ptest' and no python3-pytest. # # The COUNT is asserted `not less than' rather than pinned: 500 is what this arm # runs at 2.9.2 and it is exact for this version, but a case tally is the field # that goes false the day upstream adds a test, and this port would then red for # a reason that is not a regression. Errors and failures are pinned at zero, # which is the assertion that actually matters. # # 500, not the x86-64 control's 502: test_bitarray.py sets # `pyodide = platform.machine() == 'wasm32'', and its own `skipIf' returns None # for a decorated test instead of skipping it, so on this arm `test_shelve' and # `test_mmap_2' are never defined. Two fewer cases, not two lost ones. check_eq $P/shipped-tests-ran "yes" "$(pv tests_ran)" _tc=$(pv tests_run_count) if [ "${_tc:-0}" -ge 500 ] 2>/dev/null; then bst_ok $P/shipped-tests-count else bst_notok $P/shipped-tests-count "ran $_tc, want not less than 500" fi # test_mmap maps its file through mmap's default access, a writable MAP_SHARED # mapping, which this arm refuses with ENODEV. The other mmap cases are # read-only or leave the arm (test_mmap_2, above) and pass. The issue is named # only when test_mmap's ENODEV is the ONE bad case: a second error or any # failure is a different fact, and it reds with no attribution. ISSUE_MMAP="held by brintos/linux#30 (mmap(MAP_SHARED) of a regular file fails with ENODEV whenever PROT_WRITE is requested)" _tbad=$(pv tests_first_bad) _terr=$(pv tests_first_err) _te=$(pv tests_errors) _tattr="" case "$_te|$(pv tests_failures)|$_tbad|$_terr" in "1|0|test_mmap "*"|"*"[Errno 19]"*) _tattr=" -- $ISSUE_MMAP" ;; esac if [ "$_te" = "0" ]; then bst_ok $P/shipped-tests-errors else bst_notok $P/shipped-tests-errors "want:'0' got:'$_te', first: $_tbad: $_terr$_tattr" fi check_eq $P/shipped-tests-failures "0" "$(pv tests_failures)" # Carries the first failing case by name, so a red says WHICH assertion broke. _tok=$(pv tests_ok) if [ "$_tok" = "yes" ]; then bst_ok $P/shipped-tests-ok else bst_notok $P/shipped-tests-ok "first bad: $_tbad: $_terr$_tattr" fi # --------------------------------------------------------- huffman helper ---- # `bitarray.util' ships a Huffman-code helper, and nothing above reaches it. The # code assignment is not unique -- two equally-optimal # tables differ in which symbol takes which code -- so these assert the # properties that are: every symbol present, the frequent symbol's code no # longer than the rare one's, and the set prefix-free. A literal code table # would redden on a tie-break change that is not a defect. check_eq $P/huffman-symbols "a,b,c" "$(pv huffman_symbols)" check_eq $P/huffman-length-order "yes" "$(pv huffman_a_le_c)" check_eq $P/huffman-prefix-free "yes" "$(pv huffman_prefix_free)" # ------------------------------------------------------ documented errors ---- # THE BOUNDARY CASES OF THE CONVERSIONS ASSERTED ABOVE, by exception TYPE so a # reworded message cannot redden them. A build that returned a wrong answer # instead of raising would pass every conversion case above and fail only here. check_eq $P/err-bad-char "ValueError" "$(pv err_bad_char)" check_eq $P/err-index "IndexError" "$(pv err_index)" check_eq $P/err-int2ba-short "OverflowError" "$(pv err_int2ba_short)" check_eq $P/err-hex-badchar "ValueError" "$(pv err_hex_badchar)" # AN ODD-LENGTH HEX LITERAL IS ACCEPTED -- four bits per character, so an odd # multiple of four bits -- rather than refused. Written as the resulting length # because a refusal is what the documentation reads like, and the control # measured otherwise. check_eq $P/hex-odd-len "12" "$(pv hex_odd_len)" check_eq $P/hex-odd-bits "101010111100" "$(pv hex_odd_bits)" # ------------------------------------------- reverse slice, partial bytereverse # A negative-step slice walks the buffer backwards, and `bytereverse(i)' touches # ONE byte of several. Both are places an implementation correct on the forward, # whole-array path can still be wrong, and the cases above cover neither. check_eq $P/seq-reversed "1000011101001011" "$(pv seq_reversed)" check_eq $P/bytereverse-one "1101001001101101" "$(pv bytereverse_one)" # ------------------------------------------------------------ import-quiet --- # A THIRD python3 START, whose assertion is STDERR. An import that succeeds # while printing a warning is a different fact from a clean one, and no case # above can see it -- the probe's own `import_ok' reads the exception, not the # stream. check_eq $P/import-quiet "" \ "$(python3 -c 'import bitarray' 2>&1 >/dev/null)"