. "$BST_LIB" # BST-TIMEOUT: 1800 # the interpreter is one ~N-MB static image and the two # # comparison scripts each start it once more; on a loaded # # guest a start-up alone has been minutes, and the runner's # # 60s default would report the port as broken when what ran # # out was the clock. # # python3 3.12 (poky meta/recipes-devtools/python) on wasm32-hwjs -- ONE # STATIC INTERPRETER, and this suite is what says so out loud. # # HOW THE LANGUAGE CASES ARE PINNED. They are not pinned here at all. Two # scripts under $BST_DATA are run by the interpreter under test and their output # compared, line for line, against the SAME SCRIPTS' output on an x86-64 control # -- the Yocto native CPython 3.12.13 from this build's own sysroot, so every # library it linked is the version the target recipes build. Recorded # 2026-08-25. THE CONTROL IS STILL AT 3.12.13 AND THAT IS DELIBERATE: the # interpreter under test has moved on with poky's scarthgap branch and every # lang-* and stdlib-* case stayed GREEN against the 3.12.13 recording. # Re-record the control only when a case actually diverges. # Nothing in either script may depend on pointer width, byte order, # the platform string, the clock, the filesystem or hash randomisation; anything # that legitimately differs between the arms is asserted BELOW instead, at its # wasm32 value, with the control's value written beside it. That division is # what makes "identical to x86-64" a real claim rather than a transcription of # whatever this arm happened to do. # # WHAT DIFFERS FROM THE CONTROL, and why each is a property of the arm: # # - sys.maxsize / pointer size: 2**31-1 and 4 here, 2**63-1 and 8 there. # - sys.int_info: 15 bits per digit and 2 bytes per digit here, 30 and 4 # there. CPython picks PYLONG_BITS_IN_DIGIT from SIZEOF_VOID_P, so this is # the same fact as the line above wearing different clothes. # - lib-dynload is EMPTY here and full of .so files there. configure selects # MODULE_BUILDTYPE=static from host_cpu=wasm32, so every extension module is # inside the binary. This is the single most load-bearing difference and it # gets its own case. # - ctypes CALLS and CALLBACKS work on both: calls since BRINTOS-2269, through # libffi's compiled trampoline table, and callbacks since BRINTOS-2663, # through its closure pool. See the ctypes section below. # # NOT COVERED HERE, on purpose: the REPL. python3 has an interactive prompt and # it is not the deliverable -- this port closes on scripts. require python3 python3/present PY=/usr/bin/python3 SCRATCH=${TMPDIR:-/tmp}/bst-python3.$$ mkdir -p "$SCRATCH" 2>/dev/null # --------------------------------------------------------- the deliverable --- check python3/binary test -x $PY check python3/stdlib-dir test -d /usr/lib/python3.12 check python3/os-module test -f /usr/lib/python3.12/os.py check python3/sysconfigdata \ sh -c 'ls /usr/lib/python3.12/_sysconfigdata*.py >/dev/null 2>&1' # Expected: python3-core's dpkg Version ([PE:]PV-PR), so it moves with the recipe; # with no dpkg database, only the 3.12 series every path in this file names. PYPV=$(awk '/^Package: /{p=($2=="python3-core")} p&&/^Version: /{v=$2; sub(/^[0-9]+:/,"",v); sub(/-[^-]*$/,"",v); print v; exit}' /var/lib/dpkg/status 2>/dev/null) if [ ! -f /var/lib/dpkg/status ]; then PYV=$(python3 -V 2>&1) check_eq python3/version "Python 3.12" "${PYV%.*}" check_eq python3/version-tuple "3 12" \ "$(python3 -c 'import sys; print(*sys.version_info[:2])' 2>&1)" elif [ -z "$PYPV" ]; then bst_notok python3/version "/var/lib/dpkg/status has no Version for python3-core" bst_notok python3/version-tuple "/var/lib/dpkg/status has no Version for python3-core" else check_eq python3/version "Python $PYPV" "$(python3 -V 2>&1)" check_eq python3/version-tuple "$(echo "$PYPV" | tr . ' ')" \ "$(python3 -c 'import sys; print(*sys.version_info[:3])' 2>&1)" fi check_eq python3/implementation "cpython" \ "$(python3 -c 'import sys; print(sys.implementation.name)' 2>&1)" # --------------------------------------------------- the arm's own numbers --- # Each of these differs from the x86-64 control, which is why it is here rather # than in the compared scripts. The control's value is in the comment. check_eq python3/platform "linux" \ "$(python3 -c 'import sys; print(sys.platform)' 2>&1)" check_eq python3/maxsize "2147483647" \ "$(python3 -c 'import sys; print(sys.maxsize)' 2>&1)" # x86-64: 9223372036854775807 check_eq python3/pointer-size "4" \ "$(python3 -c 'import struct; print(struct.calcsize("P"))' 2>&1)" # x86-64: 8 # 30/4 on EVERY platform, and this row is not arm-specific. CPython 3.12 sets # the default in Include/pyport.h -- `#ifndef PYLONG_BITS_IN_DIGIT / #define # PYLONG_BITS_IN_DIGIT 30` -- with NO dependence on pointer size, and its own # comment says "defaulting to 30. The 15-bit digit option may be removed in the # future." configure leaves it undefined here (_sysconfigdata reports # PYLONG_BITS_IN_DIGIT: 0, SIZEOF_VOID_P: 4), so the header default stands. The # older rule that a 32-bit platform implies 15-bit digits is gone; expecting # "15 2" made this red against a correct build. check_eq python3/int-digits "30 4" \ "$(python3 -c 'import sys; print(sys.int_info.bits_per_digit, sys.int_info.sizeof_digit)' 2>&1)" # x86-64: same check_eq python3/soabi "cpython-312" \ "$(python3 -c 'import sysconfig; print(sysconfig.get_config_var("SOABI"))' 2>&1)" # x86-64: cpython-312-x86_64-linux-gnu check_eq python3/byteorder "little" \ "$(python3 -c 'import sys; print(sys.byteorder)' 2>&1)" check_eq python3/prefix "/usr /usr" \ "$(python3 -c 'import sys; print(sys.prefix, sys.exec_prefix)' 2>&1)" # THE BUILD CONFIGURATION, COMPARED AGAINST WHAT IS ON THE IMAGE. The recipe # builds either way (BRINTOS_PS_CONVERT): converted, the interpreter lives in # libpython3.12.so.1.0 and python3.12 is a launcher that NEEDs it; otherwise it # is one static image and no libpython .so may ship. The interpreter's own # answer and the files must agree -- a disagreement is a launcher with no # library, or a library nothing loads. LIBPY=/usr/lib/libpython3.12.so.1.0 pyshared=$(python3 -c 'import sysconfig; print(sysconfig.get_config_var("Py_ENABLE_SHARED"))' 2>&1) if [ -e "$LIBPY" ]; then check_eq python3/not-shared "1" "$pyshared" check_eq python3/no-shared-lib "$LIBPY" "$(ls /usr/lib/libpython3*.so.1.0 2>/dev/null)" else check_eq python3/not-shared "0" "$pyshared" check_eq python3/no-shared-lib "" "$(ls /usr/lib/libpython3*.so* 2>/dev/null)" fi # THE STATIC ARCHIVE IS NOT ON THE IMAGE. It is a link input and belongs in # libpython3-staticdev, which the image does not install. LIBPL carries no # platform suffix on this arm (configure appends -${PLATFORM_TRIPLET} only when # it resolved one), so poky's config-3.12-* glob misses it and the recipe claims # config-3.12 by name; the 17 MB archive back on target means that claim stopped # matching. Globbed, so a triplet-suffixed LIBPL would be caught too. check_eq python3/no-static-lib "" \ "$(ls /usr/lib/python3.12/config-3.12*/libpython3.12.a 2>/dev/null)" # lib-dynload MUST BE EMPTY. This is the case that catches a poky which narrowed # configure's wasm32 case to Emscripten: every module would become a .so, the # directory would fill up, and this interpreter would import almost nothing. check_eq python3/lib-dynload-empty "" \ "$(ls -A /usr/lib/python3.12/lib-dynload 2>/dev/null)" # ...and the modules are consequently BUILTIN rather than merely importable. # sys.builtin_module_names is the interpreter's own answer, so a module that # somehow arrived as a file would not be counted. check_eq python3/builtin-modules "yes" \ "$(python3 -c ' import sys need = {"_json","_sre","_sqlite3","_ssl","_hashlib","_bz2","_lzma","zlib", "_curses","_uuid","pyexpat","_socket","select","_struct","math", "binascii","_datetime","_decimal","unicodedata","_csv","fcntl","termios"} missing = sorted(need - set(sys.builtin_module_names)) print("yes" if not missing else "missing:" + ",".join(missing))' 2>&1)" # THE SIZE OF THE ONE IMAGE, as the recipe measured it in the packaged file # (do_compile measures the link, the packaging passes shorten it, and # do_package takes the number again). Asserted as # a range rather than a literal so an ordinary code-size drift does not go red, # and asserted at all because "one static binary" is a claim with a number # behind it: a build that silently produced a 2 MB stub, or a 400 MB image the # exec-image staging ceiling would refuse on a small guest, is the failure this # case exists to catch. The ceiling itself is a function of guest RAM # (BRINTOS-1474: 329 MiB at --ram 1024), so it is not a fixed bound to test. sz=$(cat /usr/libexec/python3-brintos/size.txt 2>/dev/null) # -L: $PY is /usr/bin/python3, a SYMLINK to python3.12. Without it `stat -c %s` # reports the LINK's own size -- 10, the length of "python3.12" -- and the case # compares that against the recorded 63467644 and goes red on a correct image. ondisk=$(stat -Lc %s $PY 2>/dev/null) # Converted, the recorded size is the launcher's and the range belongs to the # library that carries the interpreter. interp=$sz [ -e "$LIBPY" ] && interp=$(stat -Lc %s "$LIBPY" 2>/dev/null) if [ -z "$sz" ]; then bst_notok python3/size-recorded "the recipe's size measurement is not installed" elif [ "$interp" -gt 4000000 ] && [ "$interp" -lt 200000000 ]; then bst_ok python3/size-recorded else bst_notok python3/size-recorded "interpreter size $interp bytes is outside the 4 MB..200 MB sanity range" fi # The number is taken from the packaged file, so this compares that file with # itself as installed: it catches a size.txt and an interpreter from two # different do_package runs, and a change to the program after packaging. check_eq python3/size-matches-installed "$sz" "$ondisk" # ------------------------------------------------- language, vs the control --- # One run of the script, then one case per area the ticket names. Grouping keeps # a red pointing at the area that failed instead of at a 113-line blob, and # keeps the case list stable when a case is added inside an area. CORE_OUT=$SCRATCH/core.out CORE_EXP=$BST_DATA/python3-core.expected ( python3 "$BST_DATA/python3-core.py" > "$CORE_OUT" 2>&1 ) core_rc=$? if [ $core_rc -ne 0 ]; then bst_notok python3/core-run "rc=$core_rc $(_bst_1line "$(cat "$CORE_OUT" 2>/dev/null)")" else bst_ok python3/core-run fi cmp_group() { # cmp_group check_eq "$1" \ "$(grep -E "^($2)[.=]" "$CORE_EXP" 2>/dev/null)" \ "$(grep -E "^($2)[.=]" "$CORE_OUT" 2>/dev/null)" } cmp_group python3/lang-arithmetic 'int|float' cmp_group python3/lang-strings 'str|uni' cmp_group python3/lang-containers 'dict|set|list|tuple|slice|bytes|memoryview' cmp_group python3/lang-exceptions 'exc' cmp_group python3/lang-closures 'closure' cmp_group python3/lang-generators 'gen|itertools' cmp_group python3/lang-classes 'cls|dataclass|enum|abc|property|functools' cmp_group python3/stdlib-json 'json' cmp_group python3/stdlib-re 're' cmp_group python3/stdlib-pure 'base64|hashlib|textwrap|collections|decimal|fractions|struct|binascii|string|difflib|copy|pickle|pprint|heapq|bisect|array|operator' cmp_group python3/interp-sys 'sys' # The count is its own case: a script that died halfway would otherwise match # every group it had already printed and report as a pass. cmp_group python3/core-case-count 'CASES' # ---------------------------------- native-dependency stdlib, vs the control -- # These are the modules the port exists to deliver: each is a C extension linked # into the interpreter against a library this image already carries. STD_OUT=$SCRATCH/stdlib.out STD_EXP=$BST_DATA/python3-stdlib.expected ( python3 "$BST_DATA/python3-stdlib.py" "$SCRATCH" > "$STD_OUT" 2>&1 ) std_rc=$? if [ $std_rc -ne 0 ]; then bst_notok python3/stdlib-run "rc=$std_rc $(_bst_1line "$(cat "$STD_OUT" 2>/dev/null)")" else bst_ok python3/stdlib-run fi std_group() { check_eq "python3/$1" \ "$(grep -E "^$2=" "$STD_EXP" 2>/dev/null)" \ "$(grep -E "^$2=" "$STD_OUT" 2>/dev/null)" } std_group mod-zlib 'zlib' std_group mod-bz2 'bz2' std_group mod-lzma 'lzma' std_group mod-hashlib 'hashlib' std_group mod-ssl 'ssl' std_group mod-sqlite3 'sqlite3' std_group mod-expat 'xml\.etree' std_group mod-uuid 'uuid' std_group mod-curses 'curses' std_group mod-fileio 'fileio' std_group mod-codecs 'codecs' std_group stdlib-case-count 'CASES' # THE VERSIONS THE MODULES REPORT, which the compared scripts deliberately do # not print. Pinned here against what this image's recipes build, so an # openssl/sqlite bump that silently dropped the module back to a bundled or # older copy is visible. check_out python3/ssl-openssl "OpenSSL 3." python3 -c 'import ssl; print(ssl.OPENSSL_VERSION)' check_out python3/expat-version "expat_" python3 -c 'import pyexpat; print("expat_%d.%d.%d" % pyexpat.version_info)' check python3/sqlite-version python3 -c ' import sqlite3, sys sys.exit(0 if sqlite3.sqlite_version_info >= (3, 40) else 1)' check python3/zlib-version python3 -c ' import zlib, sys sys.exit(0 if zlib.ZLIB_VERSION.startswith("1.") else 1)' # ------------------------------------------------------- the ctypes boundary -- # _ctypes is built in since BRINTOS-2269 (libffi's ffi_call works here through # its trampoline table), and these cases assert calls through the module into # libc.so -- another wasm module, reached by dlopen/dlsym and # ffi_call. Until then _ctypes was configured out and this section was a red # witness asserting `ModuleNotFoundError: No module named '_ctypes'`. check_eq python3/ctypes-builtin "present" \ "$(python3 -c 'import sys; print("present" if "_ctypes" in sys.builtin_module_names else "absent")' 2>&1)" check_eq python3/ctypes-import "ok" "$(python3 -c 'import ctypes; print("ok")' 2>&1 | tail -1)" # find_library answers with a path on this arm (the recipe's wasm32 branch): # ldconfig cannot read a wasm shared object and dlopen does not search a bare # name, so a path is what CDLL can open. libc is installed under its # content-addressed name with a plain libc.so link to it, and find_library # prefers a plain name, so the answer is the link, which resolves to that file. check_eq python3/ctypes-find-library-c "/lib/libc.so" \ "$(python3 -c 'import ctypes.util; print(ctypes.util.find_library("c"))' 2>&1)" check_eq python3/libc-so-link "$(ls /lib/libc.so.* 2>/dev/null)" "$(readlink -f /lib/libc.so 2>/dev/null)" check_eq python3/find-library-c-one-file "1" "$(ls /lib/libc.so.* 2>/dev/null | wc -l)" # Real foreign calls into libc: an i32 result (strlen), an f64 result # (strtod), and a variadic call that writes through a pointer (snprintf). # snprintf's fixed arguments are declared, as on Apple arm64: a wasm variadic # callee takes its variadic tail as one pointer, so an undeclared call would # hand it the first extra argument in that slot. libc is reached through the # process's own handle, CDLL(None), which is where it already is. check_eq python3/ctypes-call-libc "5|2.5|n=42" "$(python3 -c ' import ctypes c = ctypes.CDLL(None) c.strlen.restype = ctypes.c_size_t c.strtod.restype = ctypes.c_double c.strtod.argtypes = [ctypes.c_char_p, ctypes.c_void_p] c.snprintf.argtypes = [ctypes.c_char_p, ctypes.c_size_t, ctypes.c_char_p] buf = ctypes.create_string_buffer(16) c.snprintf(buf, 16, b"n=%d", 42) print("%d|%s|%s" % (c.strlen(b"hello"), c.strtod(b"2.5", None), buf.value.decode())) ' 2>&1 | tail -1)" # Variadic calls through ctypes, fixed arguments declared. More arguments than # argtypes makes ctypes prepare a variadic cif (ffi_prep_cif_var), and the # variadic tail travels in libffi's buffer: an int, a long long, a double and a # pointer, as clang lays them out. Called with only its fixed arguments the # same function gets a fixed cif, and libffi's type test hands it an empty # variadic buffer -- the call CPython's test_bytes and test_capi make, which # trapped (rc 132) before the test. check_eq python3/ctypes-variadic-from-format "b'x5y'" "$(python3 -c ' import ctypes f = ctypes.pythonapi.PyBytes_FromFormat f.argtypes = (ctypes.c_char_p,) f.restype = ctypes.py_object print(f(b"x%dy", ctypes.c_int(5))) ' 2>&1 | tail -1)" check_eq python3/ctypes-variadic-fixed-only "b'format'" "$(python3 -c ' import ctypes f = ctypes.pythonapi.PyBytes_FromFormat f.argtypes = (ctypes.c_char_p,) f.restype = ctypes.py_object print(f(b"format")) ' 2>&1 | tail -1)" check_eq python3/ctypes-variadic-snprintf "32|-3|1234567890123|0.50|str|0x1234" "$(python3 -c ' import ctypes c = ctypes.CDLL(None) c.snprintf.argtypes = (ctypes.c_char_p, ctypes.c_size_t, ctypes.c_char_p) b = ctypes.create_string_buffer(64) n = c.snprintf(b, 64, b"%d|%lld|%.2f|%s|%p", ctypes.c_int(-3), ctypes.c_longlong(1234567890123), ctypes.c_double(0.5), b"str", ctypes.c_void_p(0x1234)) print("%d|%s" % (n, b.value.decode())) ' 2>&1 | tail -1)" # A void C function called with ctypes' default restype, c_int: natively the # caller reads a register the callee never wrote; here libffi calls the callee # in its own, void, form and the call returns 0. srand is a fixed call; # PySys_FormatStdout is variadic, the shape of test_capi.test_sys, which ended # the interpreter before. restype None on a function that returns a value # drops the value, as natively. check_eq python3/ctypes-void-default-restype "0|same" "$(python3 -c ' import ctypes c = ctypes.CDLL(None) r = c.srand(7); a = c.rand(); c.srand(7); b = c.rand() print("%s|%s" % (r, "same" if a == b else "differ")) ' 2>&1 | tail -1)" check_eq python3/ctypes-void-variadic-default-restype "n=5|0" "$(python3 -c ' import ctypes, sys w = ctypes.pythonapi.PySys_FormatStdout w.argtypes = (ctypes.c_char_p,) r = w(b"n=%d|", ctypes.c_int(5)) sys.stdout.flush() print(r) ' 2>&1 | tail -1)" check_eq python3/ctypes-restype-none-drops-value "None" "$(python3 -c ' import ctypes c = ctypes.CDLL(None) c.strlen.restype = None print(c.strlen(b"abc")) ' 2>&1 | tail -1)" # By path, libc must be the resident copy (brintos/hardwarejs#42): a second # instance, were one admitted, would keep its own environ and miss this setenv. check_eq python3/ctypes-libc-by-path "strlen=5|getenv=same" "$(python3 -c ' import ctypes, ctypes.util p = ctypes.CDLL(ctypes.util.find_library("c")) p.setenv.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int) g = ctypes.CDLL(None).getenv g.argtypes = (ctypes.c_char_p,) g.restype = ctypes.c_char_p p.setenv(b"BST_PY_RESIDENT", b"same", 1) print("strlen=%d|getenv=%s" % (p.strlen(b"hello"), (g(b"BST_PY_RESIDENT") or b"None").decode())) ' 2>&1 | tail -1)" # ctypes' own helpers are foreign calls too: memmove and string_at go through # ffi_call to libc.so. check_eq python3/ctypes-memmove "abc" "$(python3 -c ' import ctypes dst = ctypes.create_string_buffer(4) ctypes.memmove(dst, b"abc", 3) print(ctypes.string_at(dst).decode()) ' 2>&1 | tail -1)" # CFUNCTYPE callbacks: a closure from libffi's per-signature slot pool # (BRINTOS-2663). Called three ways -- directly from Python through ffi_call, # and from inside libc.so by qsort, which is the shape every real consumer has # (a library in another module calling back into the interpreter). Until # BRINTOS-2663 this was a red witness asserting ffi_prep_closure_loc's abort. check_eq python3/ctypes-callback-direct "42" "$(python3 -c ' import ctypes f = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_int)(lambda a, b: a * b) print(f(6, 7)) ' 2>&1 | tail -1)" check_eq python3/ctypes-callback-qsort "-7,0,3,19,42" "$(python3 -c ' import ctypes, ctypes.util c = ctypes.CDLL(ctypes.util.find_library("c")) CMP = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)) a = (ctypes.c_int * 5)(42, -7, 19, 0, 3) c.qsort.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_size_t, CMP] c.qsort.restype = None c.qsort(a, 5, ctypes.sizeof(ctypes.c_int), CMP(lambda x, y: (x[0] > y[0]) - (x[0] < y[0]))) print(",".join(map(str, a))) ' 2>&1 | tail -1)" # 200 callbacks created and dropped one at a time, far past any signature's # pool. A smoke test of the cycle only: malloc may re-issue a freed closure's # block, and a re-prep of one address reuses its own slot, so this can pass # without the release. 99-libffi's closure-rebind-new-address pins that. check_eq python3/ctypes-callback-slots-reused "200" "$(python3 -c ' import ctypes, gc F = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int) n = 0 for i in range(200): n += F(lambda x: 1)(i) gc.collect() print(n) ' 2>&1 | tail -1)" # Outside the pool is a Python exception at instantiation, never a crash at the # call: double(double, double, double) is not a pooled signature. check_eq python3/ctypes-callback-uncovered "RuntimeError: ffi_prep_closure failed with 1" "$(python3 -c ' import ctypes D = ctypes.c_double try: ctypes.CFUNCTYPE(D, D, D, D)(lambda a, b, c: 0.0) print("CREATED") except RuntimeError as e: print("RuntimeError: %s" % e) ' 2>&1 | tail -1)" # The pure-Python half ships at its usual path. check python3/ctypes-package-present test -f /usr/lib/python3.12/ctypes/__init__.py # ------------------------------------------------------------------- threads -- # The interpreter and its extension modules share the image's one libc.so, which # is lane-addressed, so a started thread runs. Each case is a separate start, so # a thread that never runs reds its own case and leaves the rest standing. check python3/threading-imports python3 -c 'import threading; threading.Lock()' check_eq python3/thread-runs "RAN" \ "$(python3 -c ' import threading done = [] t = threading.Thread(target=lambda: done.append(1)) try: t.start() except Exception as e: print("REFUSED: %s" % e); raise SystemExit t.join(10) print("RAN" if done else "NOT-RUN")' 2>&1 | tail -1)" check_eq python3/threads-four-workers "4:2000000" "$(python3 -c ' import threading r = [0] * 4 def w(i): s = 0 for k in range(1000000): s += k & 1 r[i] = s ts = [threading.Thread(target=w, args=(i,)) for i in range(4)] [t.start() for t in ts]; [t.join(60) for t in ts] print("%d:%d" % (sum(1 for x in r if x), sum(r)))' 2>&1 | tail -1)" check_eq python3/threads-lock-contention "40000" "$(python3 -c ' import threading n = [0]; L = threading.Lock() def w(): for _ in range(10000): with L: n[0] += 1 ts = [threading.Thread(target=w) for _ in range(4)] [t.start() for t in ts]; [t.join(60) for t in ts] print(n[0])' 2>&1 | tail -1)" check_eq python3/threads-pool-map "[0, 1, 4, 9, 16, 25, 36, 49]" "$(python3 -c ' from concurrent.futures import ThreadPoolExecutor with ThreadPoolExecutor(4) as ex: print(list(ex.map(lambda x: x * x, range(8))))' 2>&1 | tail -1)" check_eq python3/threads-queue "4950" "$(python3 -c ' import threading, queue q = queue.Queue(); out = [0] def c(): while True: x = q.get() if x is None: return out[0] += x t = threading.Thread(target=c); t.start() for i in range(100): q.put(i) q.put(None); t.join(30); print(out[0])' 2>&1 | tail -1)" check_eq python3/threads-timer-event "SET" "$(python3 -c ' import threading e = threading.Event(); threading.Timer(0.2, e.set).start() print("SET" if e.wait(10) else "TIMEOUT")' 2>&1 | tail -1)" # CPython releases the GIL around SSL_CTX_new, so this enters libcrypto from # three threads at once. A libcrypto that takes no locks corrupts the malloc # heap here and the interpreter aborts in free() or malloc(). check_eq python3/ssl-context-two-threads "DONE" "$(bst_bound 300 python3 -c ' import ssl, threading err = [] def w(): try: for _ in range(200): ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) except Exception as e: err.append(repr(e)) ts = [threading.Thread(target=w) for _ in range(2)] [t.start() for t in ts] for _ in range(200): ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) [t.join(240) for t in ts] alive = sum(t.is_alive() for t in ts) print("DONE" if not err and not alive else "ERR %s alive=%d" % (err[:1], alive))' 2>&1 | tail -1)" # ------------------------------------------------------------- runnable-ness -- # The interpreter as a user meets it: a script file, a module entry point, stdin, # and a non-zero exit that actually propagates. echo 'import sys; print("script-ok", len(sys.argv))' > "$SCRATCH/hello.py" check_out python3/run-script "script-ok 2" python3 "$SCRATCH/hello.py" arg1 check_out python3/run-module '{"a": 1}' python3 -c 'import json,sys; json.dump({"a":1}, sys.stdout)' check_out python3/run-stdin "stdin-ok" sh -c 'echo "print(\"stdin-ok\")" | python3 -' check_rc python3/exit-status 3 python3 -c 'raise SystemExit(3)' # An uncaught exception must print a traceback AND exit non-zero. check_out # requires rc=0, so the exit status is asserted separately and the text is read # from a wrapper that swallows it -- an uncaught traceback that exited 0 would # otherwise pass this file's exit-status case and never be looked at again. check_rc python3/traceback-exit-status 1 python3 -c '1/0' check_out python3/traceback-to-stderr "ZeroDivisionError: division by zero" \ sh -c 'python3 -c "1/0" 2>&1; exit 0' check_out python3/utf8-argv "é中" python3 -c 'import sys; print(sys.argv[1])' 'é中' check_out python3/compileall "compiled" python3 -c ' import py_compile, sys py_compile.compile(sys.argv[1], doraise=True); print("compiled")' "$SCRATCH/hello.py" rm -rf "$SCRATCH" 2>/dev/null