. "$BST_LIB" # BST-TIMEOUT: 300 # ~15 execs of a wasm module, each a fresh instantiation, # # decoding to 73 kB. Measured well inside 60s on the local # # runner, but 300 is what the ticket gate and the nightly # # already pass, so it costs them nothing and gives a bare # # `brintos-selftest` real headroom on a loaded host. # libtheora 1.1.1 (poky recipes-multimedia/libtheora) -- the Theora VIDEO codec # reference implementation: libtheoradec.a, libtheoraenc.a, the legacy combined # libtheora.a, four headers under /usr/include/theora, three .pc files, and the # two upstream example drivers this image installs as /usr/bin/theora-dump-video # (Ogg/Theora -> YUV4MPEG2) and /usr/bin/theora-dump-psnr (two streams -> PSNR). # Both write to stdout and touch no display, so the whole suite runs offline. # # THE ORACLE IS A STORED REFERENCE DECODE, AND IT WAS MEASURED BEFORE IT WAS # RELIED ON. Two codec suites on this shelf (57-libvorbis, 57-speexdsp) refuse a # stored cross-machine digest and are right about their subjects; libtheora is a # different case, and the difference is the format rather than a judgement about # it. Theora's inverse transform is NORMATIVE and specified in integers -- the # decoder is not free to choose its own arithmetic the way a Vorbis or Speex # decoder is -- and libtheoradec's dequant, iDCT, motion compensation and loop # filter are integer throughout. libm is not linked into theora-dump-video at # all. The measurement, taken on x86-64 before any of this was written: the same # source at gcc -O3 WITH the MMX asm and at gcc -O0 with --disable-asm produces # BYTE-IDENTICAL output, as does a repeat run. So the fixture ships its reference # decode and the gate is `cmp`. # # THE SAME CLAIM IS THEN CHECKED A SECOND TIME THROUGH DIFFERENT CODE. # theora/decode-exact is `cmp` against the shipped .y4m. theora/psnr-self-inf # feeds the freshly decoded frames and that same reference to theora-dump-psnr, # which runs its OWN decoder and its own comparison and prints the exact string # INF when two streams are identical. A fault that could defeat both would have # to corrupt the decode and the comparison the same way; and because INF is a # literal, that case needs no float tolerance despite dump_psnr being the one # tool here that links libm. # # WHAT THE FIXTURE IS, AND WHY IT IS NOT THE OBVIOUS ONE. libtheora-clip.ogv is # 16 frames of 64x48 4:2:0 at 30 fps, built by src/libtheora_mkfixture.py and # encoded with upstream's own encoder_example at -v 8; that file states how to # remake all three payloads. The clip is deliberately NOISY. A first cut was a # smooth ramp plus one moving block and encoded to 4585 bytes, of which ~4.4 kB # was the Theora SETUP HEADER -- Huffman tables and quant matrices, a fixed cost # of the format -- leaving under 200 bytes of coded video. That decoded # byte-exactly and asserted almost nothing, because a stream of skipped and flat # blocks never reaches dequantisation, the inverse DCT, motion compensation or # the loop filter. The shipped clip carries an LCG texture (dense AC # coefficients), a block that walks one macroblock per frame (non-zero motion # vectors) and a flat gradient band (DC-only and skipped blocks), and encodes to # 21786 bytes -- so the coded data now dominates the header block by ~4:1. # # THE .ogv IS NOT REPRODUCIBLE AND NOTHING HERE DEPENDS ON IT BEING SO. Ogg draws # the logical-stream serial number at random per run, so re-encoding gives a # different file -- the same upstream wart 57-speex.test canonicalises around. # The .ogv is a committed artifact; what is reproducible is the DECODE of it. # That is also why theora/stream-geometry matches only the tail of the "Ogg # logical stream is Theora ..." line and never the serial itself. # # READING A RED. A wrong decode-size, decode-frames or any trunc-*-size is # integer and cannot drift: that is a decoder or packaging fault and nothing # else. A red on theora/decode-exact WITH theora/decode-max-deviation green means # last-bit disagreement, which for an integer codec is still a fault and not # something to re-reference away -- unlike the float codecs on this shelf, there # is no legitimate source of drift here. A red on decode-exact with the deviation # cases ALSO red is a substantive miscompile. A red on the presence cases with # every decode case green means the bbappend's example install stopped taking. # theora/empty-header-is-zero-by-zero and theora/junk-* pin UPSTREAM behaviour # that is arguably wrong (see there); a red on those is a behaviour CHANGE, not # necessarily a regression. require theora-dump-video theora/dump-video-present tmp=${TMPDIR:-/tmp}/bst-theora.$$ mkdir -p "$tmp" 2>/dev/null size() { wc -c < "$1" 2>/dev/null | tr -d ' '; } md5of() { md5sum "$1" 2>/dev/null | cut -d' ' -f1; } have_md5=0; command -v md5sum >/dev/null 2>&1 && have_md5=1 OGV=$BST_DATA/libtheora-clip.ogv REF=$BST_DATA/libtheora-clip.ref.y4m SRC=$BST_DATA/libtheora-clip.src.y4m # --------------------------------------------------------------- what shipped --- check theora/dump-psnr-present test -x /usr/bin/theora-dump-psnr check theora/lib-static-theora test -f /usr/lib/libtheora.a check theora/lib-static-dec test -f /usr/lib/libtheoradec.a check theora/lib-static-enc test -f /usr/lib/libtheoraenc.a check theora/header-codec test -f /usr/include/theora/codec.h check theora/header-theora test -f /usr/include/theora/theora.h check theora/header-theoradec test -f /usr/include/theora/theoradec.h check theora/header-theoraenc test -f /usr/include/theora/theoraenc.h check theora/pc-theora test -f /usr/lib/pkgconfig/theora.pc check theora/pc-theoradec test -f /usr/lib/pkgconfig/theoradec.pc check theora/pc-theoraenc test -f /usr/lib/pkgconfig/theoraenc.pc # The distro is --disable-shared image-wide. Asserted rather than assumed: it is # the reason EMCRAFT_TOOLS can name a bare `libtheora` at all (the package would # otherwise be empty and do_rootfs would refuse it), and the reason the two # example drivers had to be installed by the bbappend in the first place. bst_lib_shape theora/static-only "/usr/lib/libtheora*.so*" # ------------------------------------------------------------------ payloads --- # Pinned BEFORE anything is decoded. Without this a later mismatch has two # indistinguishable causes -- the decoder changed, or the payload did -- and the # wrong one gets reported. pin() { # pin if [ "$have_md5" -eq 1 ]; then check_eq "$1" "$2" "$(md5of "$3")" else bst_skip "$1" "no md5sum on this image"; fi } pin theora/fixture-ogv-digest 5904adec3333c01eee5a621f6f078f82 "$OGV" pin theora/fixture-src-digest 5dfa0ba46dbe1ce0f753dd10c639e42c "$SRC" pin theora/reference-digest e6366b6a04b98ac11ecd2ed6503f3b2f "$REF" for f in "$OGV" "$REF" "$SRC"; do if [ ! -f "$f" ]; then bst_notok theora/payloads "missing $f -- remaining cases not run" rm -rf "$tmp"; exit 0 fi done # ------------------------------------------------------------- the decode ----- # This is the ticket's criterion and the whole point of the port. err=$(theora-dump-video "$OGV" 2>&1 > "$tmp/out.y4m"); rc=$? check_eq theora/decode-rc 0 "$rc" check_eq theora/decode-size 73865 "$(size "$tmp/out.y4m")" # 73865 is not a magic number: 41 bytes of Y4M stream header, then 16 frames of # ("FRAME\n" = 6) + (64*48 luma + 2*32*24 chroma = 4608) = 4614. It is asserted # as a constant because a decoder that dropped or duplicated a frame lands on a # different one, and that is the cheapest possible detector for it. check_eq theora/decode-header "YUV4MPEG2 C420jpeg W64 H48 F30:1 Ip A1:1" \ "$(head -n 1 "$tmp/out.y4m")" # The frame count comes off the tool's own summary line rather than by counting # FRAME markers: the payload is binary, so a line-oriented count of "^FRAME$" # reads 1 rather than 16 -- measured, not assumed. check_eq theora/decode-frames 16 \ "$(printf '%s\n' "$err" | sed -n 's/^\([0-9][0-9]*\) frames$/\1/p')" case "$err" in *"Encoded by Xiph.Org libtheora 1.1"*) bst_ok theora/encoder-banner ;; *) bst_notok theora/encoder-banner "$(_bst_1line "$err")" ;; esac # Matched from "is Theora" onward: the serial number earlier in that line is # random per encode and must never be asserted. case "$err" in *"is Theora 64x48 30.00 fps video"*) bst_ok theora/stream-geometry ;; *) bst_notok theora/stream-geometry "$(_bst_1line "$err")" ;; esac case "$err" in *"Encoded frame content is 64x48 with 0x0 offset"*) bst_ok theora/frame-content ;; *) bst_notok theora/frame-content "$(_bst_1line "$err")" ;; esac # ---- the assertion the port exists to make ------------------------------------- if cmp -s "$tmp/out.y4m" "$REF"; then bst_ok theora/decode-exact bst_ok theora/decode-max-deviation bst_ok theora/decode-differing-bytes echo "==LIBTHEORA-AGREE byte-identical to reference==" else bst_notok theora/decode-exact "decoded frames differ from libtheora-clip.ref.y4m" # Only now pay for the byte-level walk, and bound the damage so the design doc # can say WHAT went wrong rather than only that something did. od -An -v -tu1 -w1 "$tmp/out.y4m" > "$tmp/a.txt" 2>/dev/null od -An -v -tu1 -w1 "$REF" > "$tmp/b.txt" 2>/dev/null set -- $(awk 'NR==FNR{a[FNR]=$1;next} {d=a[FNR]-$1; if(d<0)d=-d; if(d>m)m=d; if(d)n++} END{print m+0, n+0, FNR}' "$tmp/a.txt" "$tmp/b.txt") echo "==LIBTHEORA-AGREE max=${1:-?} ndiff=${2:-?} of ${3:-?}==" if [ -n "$1" ] && [ "$1" -le 1 ] 2>/dev/null; then bst_ok theora/decode-max-deviation else bst_notok theora/decode-max-deviation "max |delta| ${1:-unknown} > 1"; fi if [ -n "$2" ] && [ "$2" -le 64 ] 2>/dev/null; then bst_ok theora/decode-differing-bytes else bst_notok theora/decode-differing-bytes "${2:-unknown} of ${3:-?} bytes differ, bound 64"; fi fi # ---------------------------------------------------------- determinism ------- # What makes a stored reference an oracle at all, so it is asserted, not assumed. theora-dump-video "$OGV" > "$tmp/again.y4m" 2>/dev/null check theora/determinism cmp -s "$tmp/out.y4m" "$tmp/again.y4m" # dump_video reads stdin when given no path. Same bytes, different I/O path -- # and on this target the interesting half is that the stdin path is a pipe on the # virtiofs root rather than a seekable file. ( theora-dump-video < "$OGV" > "$tmp/stdin.y4m" 2>/dev/null ) check theora/stdin-equals-argv cmp -s "$tmp/stdin.y4m" "$tmp/out.y4m" # ------------------------------------------------------------- theora-dump-psnr --- if command -v theora-dump-psnr >/dev/null 2>&1; then # The independent second oracle. Identical streams give the literal INF, so # this corroborates theora/decode-exact through dump_psnr's own decoder and its # own comparison, with no float tolerance anywhere. p=$(theora-dump-psnr -s "$tmp/out.y4m" "$REF" 2>&1 | awk '/^Total:/{print $2}') check_eq theora/psnr-self-inf INF "$p" # And the real measurement: the source clip against the encoded stream. This # one IS float, so it is asserted as a band. Measured 39.8572 total / 38.2615 # luma on x86-64; the bands are wide enough to absorb a last-ulp libm # disagreement and far too narrow to admit a decode that went wrong. t=$(theora-dump-psnr -s "$SRC" "$OGV" 2>&1 | awk '/^Total:/{print int($2)}') y=$(theora-dump-psnr -s -y "$SRC" "$OGV" 2>&1 | awk '/^Total:/{print int($2)}') if [ -n "$t" ] && [ "$t" -ge 37 ] 2>/dev/null && [ "$t" -le 42 ] 2>/dev/null then bst_ok theora/psnr-total; else bst_notok theora/psnr-total "total PSNR = ${t:-} dB (want 37..42)"; fi if [ -n "$y" ] && [ "$y" -ge 36 ] 2>/dev/null && [ "$y" -le 41 ] 2>/dev/null then bst_ok theora/psnr-luma; else bst_notok theora/psnr-luma "luma PSNR = ${y:-} dB (want 36..41)"; fi # Both input paths must agree: y4m-vs-ogv above and y4m-vs-y4m here decode # through different front ends and must land on the same figure. t2=$(theora-dump-psnr -s "$SRC" "$REF" 2>&1 | awk '/^Total:/{print int($2)}') check_eq theora/psnr-input-paths-agree "$t" "$t2" check_rc theora/psnr-missing-rc 1 theora-dump-psnr -s "$SRC" "$tmp/no-such-file.ogv" else bst_notok theora/dump-psnr-runnable "theora-dump-psnr is not on PATH" fi # ------------------------------------------------------- malformed input ------ # Each of these pins CURRENT upstream behaviour. Two are wrong in upstream's own # terms and are pinned anyway, because an unpinned wrong is indistinguishable # from a port defect the first time someone meets it. theora-dump-video "$tmp/no-such-file.ogv" > /dev/null 2>"$tmp/miss.err"; rc=$? check_eq theora/missing-rc 1 "$rc" case "$(cat "$tmp/miss.err")" in *"for extraction"*) bst_ok theora/missing-diagnostic ;; *) bst_notok theora/missing-diagnostic "$(_bst_1line "$(cat "$tmp/miss.err")")" ;; esac # An EMPTY input exits 0 and still writes a Y4M stream header -- one declaring a # 0x0 picture at 0 fps. A caller checking only the status believes it has a valid # clip. That is upstream's behaviour, it is deterministic, and it is pinned here # rather than corrected, because the suite's job is to notice it changing. : > "$tmp/empty.ogv" theora-dump-video "$tmp/empty.ogv" > "$tmp/empty.y4m" 2>"$tmp/empty.err"; rc=$? check_eq theora/empty-rc 0 "$rc" check_eq theora/empty-size 38 "$(size "$tmp/empty.y4m")" check_eq theora/empty-header-is-zero-by-zero "YUV4MPEG2 C420jpeg W0 H0 F0:0 Ip A0:0" \ "$(head -n 1 "$tmp/empty.y4m")" check_eq theora/empty-frames 0 \ "$(sed -n 's/^\([0-9][0-9]*\) frames$/\1/p' "$tmp/empty.err")" # Data that is not Ogg at all: same shape, same 0x0 header, exit 0. dd if=/dev/zero bs=1 count=400 2>/dev/null | tr '\0' 'X' > "$tmp/junk.ogv" theora-dump-video "$tmp/junk.ogv" > "$tmp/junk.y4m" 2>/dev/null; rc=$? check_eq theora/junk-rc 0 "$rc" check_eq theora/junk-size 38 "$(size "$tmp/junk.y4m")" check theora/junk-equals-empty cmp -s "$tmp/junk.y4m" "$tmp/empty.y4m" # A stream cut inside the header block cannot be decoded at all, and says so. # 6000 of 21786 bytes is past the info and comment headers and inside the setup # header, which is ~4.4 kB of this file on its own. head -c 6000 "$OGV" > "$tmp/thead.ogv" 2>/dev/null theora-dump-video "$tmp/thead.ogv" > "$tmp/thead.y4m" 2>"$tmp/thead.err"; rc=$? check_eq theora/trunc-headers-rc 1 "$rc" check_eq theora/trunc-headers-size 0 "$(size "$tmp/thead.y4m")" case "$(cat "$tmp/thead.err")" in *"searching for codec headers"*) bst_ok theora/trunc-headers-diagnostic ;; *) bst_notok theora/trunc-headers-diagnostic "$(_bst_1line "$(cat "$tmp/thead.err")")" ;; esac # A stream cut AFTER the headers decodes the whole frames it has and exits 0 -- # and what it produces is a byte-exact PREFIX of the full reference. That prefix # property is the strongest statement in this suite after decode-exact itself: # it says the decoder lands on exact frame boundaries and that no state carried # across the cut perturbs an earlier frame. Sizes are 41 + N*4614. trunc() { # trunc head -c "$2" "$OGV" > "$tmp/t.ogv" 2>/dev/null _e=$(theora-dump-video "$tmp/t.ogv" 2>&1 > "$tmp/t.y4m"); _rc=$? check_eq theora/$1-rc 0 "$_rc" check_eq theora/$1-size "$4" "$(size "$tmp/t.y4m")" check_eq theora/$1-frames "$3" "$(printf '%s\n' "$_e" | sed -n 's/^\([0-9][0-9]*\) frames$/\1/p')" head -c "$(size "$tmp/t.y4m")" "$REF" > "$tmp/prefix.y4m" 2>/dev/null check theora/$1-prefix-of-reference cmp -s "$tmp/t.y4m" "$tmp/prefix.y4m" } trunc trunc-4frames 10000 4 18497 trunc trunc-8frames 16000 8 36953 trunc trunc-12frames 21000 12 55409 rm -rf "$tmp"