forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

check-aom-oracle-rungs.sh225 lines, 11.7 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# Anti-regression check for the aomdec dump rungs that
3# scripts/instrument-aom-oracle.sh derives.
4#
5# Why this exists: the four u8-narrowing rungs (PREFILT, POSTDEBLOCK,
6# PREFILT_WIDE, POSTCDEF) shipped with `fwrite(plane + r*stride, 1, w, f)`,
7# which on a 10/12-bit stream reads a HALVED plane pointer
8# (CONVERT_TO_BYTEPTR in aom_ports/mem.h) and SIGSEGVs with a 0-byte file
9# (lanes/av1oraclehbd.report.md). A rung defect that only shows up as an
10# aomdec crash during a decode is found late; this reds on the DERIVATION
11# instead, in seconds, without a build.
12#
13# The same class of loss applies to the prediction rungs: EC_PREDOUT8 (rung
14# 16) and EC_PREDND (rung 17) lived only in the hand-patched oracle tree, so
15# a rebuild from the script dropped the only probe that prints on a 10/12-bit
16# stream (both, and the pre-existing EC_PREDOUT, sit after an `is_hbd` early
17# return). Those are asserted here too, from a PRISTINE reconintra.c.
18#
19# What it does: copies the oracle source tree to a scratch dir, replaces
20# av1/decoder/decodeframe.c and av1/common/reconintra.c with the PRISTINE
21# upstream files, runs the instrument script over the copy, and asserts the
22# derived files' shape. The real oracle tree is never written to.
23#
24# EXIT CONTRACT (lane-av1stagegaps). A staging driver must be able to tell the
25# three states apart, because "checker passed", "checker failed" and "checker
26# never ran" all printed as `rungs_exit=1` (or as nothing at all) and the suite
27# ran anyway. Measured 2026-09-30 on host host-d: the driver log showed
28# === ORACLE RUNG CHECKER
29# rungs_exit=1 ok_count=0 <- no detail line at all
30# === SUITE
31# while the real reason, with stderr visible, was a missing PREREQUISITE:
32# no oracle source at /home/user/.cache/aom-oracle/src/av1/decoder/decodeframe.c
33# $ ls ~/.cache/aom-oracle/
34# build <- binaries only, no src/ tree
35# 0 GREEN every assertion below held.
36# 3 NOTRUN a PREREQUISITE is absent (no oracle source tree, or the base ref
37# is not in it). Nothing was asserted: this is NOT a pass and NOT a
38# defect. scripts/av1-suite-preflight.sh maps it to `not-run` and
39# BLOCKS the suite unless a waiver names the host.
40# 1 FAIL a derived file violates the rung contract, or the instrument
41# script errored / was not idempotent.
42
43#
44# Usage:
45# scripts/check-aom-oracle-rungs.sh [SRC_DIR] [BASE_REF]
46# Defaults: $AOM_ORACLE_SRC or ~/.cache/aom-oracle/src, and base ref v3.13.3
47# (override with AOM_ORACLE_BASE_REF). Exit 0 = all assertions hold.
48set -euo pipefail
49
50SRC="${1:-${AOM_ORACLE_SRC:-$HOME/.cache/aom-oracle/src}}"
51BASE="${2:-${AOM_ORACLE_BASE_REF:-v3.13.3}}"
52HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
53DERIVED="$SRC/av1/decoder/decodeframe.c"
54RECONINTRA="$SRC/av1/common/reconintra.c"
55die_prereq() { echo "PREREQ-ABSENT: $*" >&2; exit 3; }
56
57
58[ -f "$DERIVED" ] || die_prereq "no oracle source at $DERIVED (provision it: git clone -b v3.13.3 --depth 1 aom at $SRC)"
59[ -f "$RECONINTRA" ] || die_prereq "no oracle source at $RECONINTRA (provision it: git clone -b v3.13.3 --depth 1 aom at $SRC)"
60git -C "$SRC" rev-parse --verify "$BASE^{commit}" >/dev/null 2>&1 || {
61 die_prereq "base ref '$BASE' is not a commit in $SRC"
62}
63
64# systemd-run's --setenv=TMPDIR points at a per-suite dir; if staging created
65# the unit but not the dir, mktemp fails with an error that reads like a
66# checker bug. It is the same class as a missing oracle tree: not asserted.
67probe="$(mktemp -d "${TMPDIR:-$HOME/.cache/tmp}/aom-rung-check.XXXXXX" 2>/dev/null)" ||
68 die_prereq "scratch dir ${TMPDIR:-$HOME/.cache/tmp} does not exist (staging must mkdir it)"
69rmdir "$probe"
70WORK="$(mktemp -d "${TMPDIR:-$HOME/.cache/tmp}/aom-rung-check.XXXXXX")"
71trap 'rm -rf "$WORK"' EXIT
72cp -a "$SRC" "$WORK/src"
73git -C "$SRC" show "$BASE:av1/decoder/decodeframe.c" > "$WORK/src/av1/decoder/decodeframe.c"
74git -C "$SRC" show "$BASE:av1/common/reconintra.c" > "$WORK/src/av1/common/reconintra.c"
75
76AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/derive.log" 2>&1 || {
77 echo "FAIL: instrument-aom-oracle.sh errored on a pristine tree:" >&2
78 tail -20 "$WORK/derive.log" >&2
79 exit 1
80}
81cp "$WORK/src/av1/decoder/decodeframe.c" "$WORK/derived.c"
82cp "$WORK/src/av1/common/reconintra.c" "$WORK/derived-intra.c"
83
84# Re-running must be a no-op, or the repair pass is not idempotent and a
85# second run would rewrite a tree under someone's feet.
86AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/rerun.log" 2>&1
87cmp -s "$WORK/derived.c" "$WORK/src/av1/decoder/decodeframe.c" || {
88 echo "FAIL: a second instrument-aom-oracle.sh run changed the derived file" >&2
89 exit 1
90}
91cmp -s "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" || {
92 echo "FAIL: a second instrument-aom-oracle.sh run changed reconintra.c" >&2
93 exit 1
94}
95
96fail=0
97check() { # description, actual, expected
98 if [ "$2" = "$3" ]; then
99 printf 'ok %-58s %s\n' "$1" "$2"
100 else
101 printf 'FAIL %-58s got %s, want %s\n' "$1" "$2" "$3" >&2
102 fail=1
103 fi
104}
105
106legacy=$(grep -c 'fwrite(ec_b->[yuv]_buffer + ec_r \* ec_b->' "$WORK/derived.c" || true)
107check "legacy u8 row loops left in the derived file" "$legacy" "0"
108
109rows=$(grep -c 'ec_dump_narrow_row(ec_f, ec_b, ec_b->[yuv]_buffer' "$WORK/derived.c" || true)
110check "ec_dump_narrow_row call sites (4 rungs x 3 planes)" "$rows" "12"
111
112fin=$(grep -c 'ec_dump_finish(ec_f, "EC_AV1_' "$WORK/derived.c" || true)
113check "ec_dump_finish call sites (one per narrowing rung)" "$fin" "4"
114
115for rung in EC_AV1_PREFILT_DUMP EC_AV1_POSTDEBLOCK_DUMP EC_AV1_PREFILT_WIDE_DUMP \
116 EC_AV1_POSTCDEF_DUMP; do
117 n=$(grep -c "ec_dump_finish(ec_f, \"$rung\"" "$WORK/derived.c" || true)
118 check "byte-count check wired into $rung" "$n" "1"
119done
120
121# Rung 12 (EC_AV1_FINAL_DUMP) is the depth-correct one and must stay that way:
122# it converts, it writes 2 bytes per sample, and it is not routed through the
123# narrowing checker.
124conv=$(grep -c 'CONVERT_TO_SHORTPTR(ec_p8\[ec_pl\])' "$WORK/derived.c" || true)
125check "rung 12 still converts plane pointers" "$conv" "1"
126r12=$(grep -c 'ec_dump_finish(ec_f, "EC_AV1_FINAL_DUMP"' "$WORK/derived.c" || true)
127check "rung 12 not routed through the narrowing checker" "$r12" "0"
128
129# --- rungs 16/17: the prediction rungs (lane-av1rungs17) --------------------
130# EC_PREDOUT8 must be installed at BOTH 8-bit prediction sites in
131# reconintra.c -- the non-directional early return (DC, SMOOTH*, PAETH) and
132# the directional / filter-intra tail. A one-site install would look fine on
133# the directional arm and print nothing at all for every non-directional
134# block, which is most of an intra frame.
135p8=$(grep -c 'EC_PREDOUT8 mi_row=%d' "$WORK/derived-intra.c" || true)
136check "rung 16 EC_PREDOUT8 install sites (both 8-bit paths)" "$p8" "2"
137
138# `mode=` is what makes a non-directional diff attributable at all; a rebuild
139# that lost it would still install two sites and still pass the count above.
140p8m=$(grep -c 'EC_PREDOUT8 mi_row=%d.*txh=%d mode=%d sum=%ld' "$WORK/derived-intra.c" || true)
141check "rung 16 EC_PREDOUT8 sites carry mode= (EC_PREDND field order)" "$p8m" "2"
142
143# EC_PREDND is the hbd twin and the ONLY prediction probe that fires on a
144# 10/12-bit stream. One site, at the non-directional early return.
145pnd=$(grep -c 'EC_PREDND mi_row=%d' "$WORK/derived-intra.c" || true)
146check "rung 17 EC_PREDND install sites (hbd non-directional)" "$pnd" "1"
147pndm=$(grep -c 'txw=%d txh=%d mode=%d n_top=%d n_left=%d' "$WORK/derived-intra.c" || true)
148check "rung 17 EC_PREDND site carries mode=" "$pndm" "1"
149
150# --- rungs 19/20: the intra-prediction IDENTITY + DC INPUTS rungs ---------
151# EC_PREDOUT8/EC_PREDND print only SOME of the writes inside
152# `av1_predict_intra_block`: the palette branch returns before either, and so
153# do the two non-directional early returns' opposite number. A chroma region
154# where no rung fires was therefore un-attributable -- three lanes of 4:2:2
155# work stalled on exactly that (lanes/av1422ctrigger §5b). EC_PIB prints the
156# CALL IDENTITY before any early return, so "did a call happen and did it
157# return early" is readable from the trace.
158pib=$(grep -c 'EC_PIB mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d' "$WORK/derived-intra.c" || true)
159check "rung 19 EC_PIB install sites (av1_predict_intra_block prologue)" "$pib" "1"
160
161pibb=$(grep -c 'txw=%d txh=%d mode=%d use_palette=%d' "$WORK/derived-intra.c" || true)
162check "rung 19 EC_PIB carries use_palette= (the early-return bit)" "$pibb" "1"
163
164# EC_DCIN is what makes the DC VARIANT a printed field instead of an
165# inference from the predicted value: four lanes read "libaom used dc_top"
166# out of the number 202 without the availability operands being visible.
167dcin=$(grep -c 'EC_DCIN mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d' "$WORK/derived-intra.c" || true)
168check "rung 20 EC_DCIN install sites (8-bit + hbd non-directional)" "$dcin" "2"
169
170dcina=$(grep -c 'n_left=%d atop=%ld aleft=%ld dcv=%d up=%d left=%d cup=%d' "$WORK/derived-intra.c" || true)
171check "rung 20 EC_DCIN prints availability operands + dcv + availability bits" "$dcina" "2"
172
173# --- rung 21: EC_DP, the branch decode_token_recon_block takes --------------
174# The inter arm (`predict_inter_block_visit`) prints NO intra rung, and the
175# intra arm itself skips chroma on `!xd->is_chroma_ref`, so a block that
176# emits no prediction rung is consistent with three different writers.
177# EC_DP is what separates them -- it is how the INTRABC writer at the 4:2:2
178# seed was named (lanes/av1422ctattr §4).
179dp=$(grep -c 'EC_DP mi_row=%d mi_col=%d bsize=%d inter=%d chroma_ref=%d' "$WORK/derived.c" || true)
180check "rung 21 EC_DP install sites (decode_token_recon_block)" "$dp" "1"
181
182dpa=$(grep -c 'skip_txfm=%d bw=%d bh=%d planes=%d is_intrabc=%d' "$WORK/derived.c" || true)
183check "rung 21 EC_DP carries is_intrabc= (the intra/inter branch bit)" "$dpa" "1"
184
185# Rung 16 claims to be idempotent in BOTH directions: an install on a
186# pristine file, AND an upgrade of the no-`mode=` form the oracle tree's git
187# HEAD carries. Rebuild the no-mode form, re-derive, and require the result to
188# land back on the same bytes -- an upgrade path that silently no-ops (or
189# double-writes) is exactly what a rebuild would hit.
190python3 - "$WORK/derived-intra.c" "$WORK/nomode-intra.c" <<'PYUP'
191import sys
192s = open(sys.argv[1]).read()
193# Strip `mode=` from the format string and `mode` from the argument list at
194# both EC_PREDOUT8 sites only; EC_PREDND's own mode= must survive untouched.
195for fmt_old, fmt_new in (
196 ('txw=%d txh=%d mode=%d sum=%ld row0=", xd->mi_row',
197 'txw=%d txh=%d sum=%ld row0=", xd->mi_row'),
198 ('txw=%d txh=%d mode=%d sum=%ld row0=", mi_row',
199 'txw=%d txh=%d sum=%ld row0=", mi_row'),
200):
201 assert fmt_old in s, "upgrade fixture: %r not found" % fmt_old
202 s = s.replace(fmt_old, fmt_new, 1)
203assert s.count('col_off, txwpx, txhpx, mode, ec_sum);') == 2, "upgrade fixture: args"
204s = s.replace('col_off, txwpx, txhpx, mode, ec_sum);',
205 'col_off, txwpx, txhpx, ec_sum);')
206assert 'EC_PREDOUT8 mi_row=%d' in s and s.count('txw=%d txh=%d sum=%ld row0=') == 2
207open(sys.argv[2], 'w').write(s)
208PYUP
209cp "$WORK/nomode-intra.c" "$WORK/src/av1/common/reconintra.c"
210AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/upgrade.log" 2>&1 || {
211 echo "FAIL: instrument-aom-oracle.sh errored on the no-mode reconintra.c:" >&2
212 tail -20 "$WORK/upgrade.log" >&2
213 exit 1
214}
215cmp -s "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" || {
216 echo "FAIL: re-deriving the no-mode EC_PREDOUT8 form did not land back on the derived bytes" >&2
217 diff -u "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" | head -30 >&2
218 exit 1
219}
220
221if [ "$fail" -ne 0 ]; then
222 echo "FAIL: a derived file violates the rung contract (base $BASE)" >&2
223 exit 1
224fi
225echo "ok instrument-aom-oracle.sh derives the depth-correct, byte-checked rungs (base $BASE)"