aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / om / allen-audio / check.sh
| 1 | #!/bin/sh |
| 2 | # Regenerate Allen's startup sound (public/audio/allen-chirp.wav) and its browser |
| 3 | # controller (public/js/allen-audio.js) with the pinned arm64 omc, then, when an |
| 4 | # aienux clone is given, check the Omega synthesis byte for byte against the |
| 5 | # original C it ports. |
| 6 | # |
| 7 | # The compiler is the one vendored for the Hive page; its pin is recorded once, |
| 8 | # in ../hive-page/omc.sha256. OMEGA_OMC overrides the compiler path, never its pin. |
| 9 | # OMEGA_ACCEPT_CHANGE=1 accepts rewritten artifacts; otherwise stale output exits 4. |
| 10 | # |
| 11 | # Oracle (AIENUX_SRC=<aienux clone holding commit $PIN>): extracts native/kernel/ui |
| 12 | # at $PIN, checks the blob ids of the sound's sources, builds aienux's own host |
| 13 | # test ui/tests/chirp_test.c with chirp.c (HOSTCC, default cc), and requires |
| 14 | # 1. its chirp.wav to equal native.om's output byte for byte (whole night, |
| 15 | # stereo, 590400 frames); |
| 16 | # 2. the web asset's samples to equal that file's left channel over frames |
| 17 | # 545280..590400, and right to equal left there; |
| 18 | # 3. a mutant oracle (CK_CHIRP_PEAK 22937 -> 22936) to differ (negative control). |
| 19 | # Without AIENUX_SRC the oracle prints ORACLE NOT_RUN; that is not a pass. |
| 20 | # |
| 21 | # Exit 2: missing compiler; 3: wrong pin; 4: stale artifact rewritten; |
| 22 | # 5: nondeterministic output; 6: empty output; 7: oracle mismatch; |
| 23 | # 8: negative control accepted; 9: oracle source missing or not the pinned blobs. |
| 24 | # Compile/run failures propagate. |
| 25 | set -eu |
| 26 | cd "$(dirname "$0")" |
| 27 | PIN=da55660ea7337f2b6a42095fcd1fb6ddebe1cc7c |
| 28 | omc=${OMEGA_OMC:-$PWD/../hive-page/omc} |
| 29 | pin=$(tr -d ' \n' < ../hive-page/omc.sha256) |
| 30 | if [ ! -f "$omc" ]; then |
| 31 | printf 'No compiler at %s; set OMEGA_OMC to the pinned omc (%s)\n' "$omc" "$pin" >&2 |
| 32 | exit 2 |
| 33 | fi |
| 34 | have=$(sha256sum "$omc" | cut -d' ' -f1) |
| 35 | if [ "$have" != "$pin" ]; then |
| 36 | printf 'Compiler sha256 mismatch: recorded %s, found %s\n' "$pin" "$have" >&2 |
| 37 | exit 3 |
| 38 | fi |
| 39 | work=$(mktemp -d "${TMPDIR:-/tmp}/allen-audio.XXXXXX") |
| 40 | trap 'rm -rf "$work"' EXIT HUP INT TERM |
| 41 | # Concatenation composes Omega units; it does not implement generation in shell. |
| 42 | cat chirp.om asset.om > "$work/asset.om" |
| 43 | cat chirp.om native.om > "$work/native.om" |
| 44 | "$omc" < "$work/asset.om" > "$work/asset" |
| 45 | "$omc" < "$work/native.om" > "$work/native" |
| 46 | chmod +x "$work/asset" "$work/native" |
| 47 | "$work/asset" > "$work/first.wav" 3> "$work/first.js" |
| 48 | "$work/asset" > "$work/second.wav" 3> "$work/second.js" |
| 49 | stale=0 |
| 50 | publish() { |
| 51 | first=$1 |
| 52 | second=$2 |
| 53 | artifact=$3 |
| 54 | sidecar=$4 |
| 55 | if ! cmp -s "$first" "$second"; then |
| 56 | printf '%s: generator output differs between runs\n' "$artifact" >&2 |
| 57 | exit 5 |
| 58 | fi |
| 59 | if [ ! -s "$first" ]; then |
| 60 | printf '%s: generator wrote nothing\n' "$artifact" >&2 |
| 61 | exit 6 |
| 62 | fi |
| 63 | if [ ! -f "$artifact" ] || ! cmp -s "$artifact" "$first"; then |
| 64 | stale=1 |
| 65 | fi |
| 66 | cp "$first" "$artifact" |
| 67 | hash=$(sha256sum "$artifact" | cut -d' ' -f1) |
| 68 | printf '%s %s\n' "$hash" "$artifact" > "$sidecar" |
| 69 | printf '%s %s bytes sha256 %s\n' "$artifact" "$(wc -c < "$artifact" | tr -d ' ')" "$hash" |
| 70 | } |
| 71 | mkdir -p ../../public/audio |
| 72 | publish "$work/first.wav" "$work/second.wav" ../../public/audio/allen-chirp.wav allen-chirp.wav.sha256 |
| 73 | publish "$work/first.js" "$work/second.js" ../../public/js/allen-audio.js allen-audio.js.sha256 |
| 74 | printf 'omc sha256 %s\n' "$have" |
| 75 | |
| 76 | if [ -z "${AIENUX_SRC:-}" ]; then |
| 77 | printf 'ORACLE NOT_RUN: set AIENUX_SRC to an aienux clone holding %s\n' "$PIN" |
| 78 | else |
| 79 | if ! git -C "$AIENUX_SRC" cat-file -e "$PIN^{commit}" 2>/dev/null; then |
| 80 | printf 'ORACLE: %s has no commit %s\n' "$AIENUX_SRC" "$PIN" >&2 |
| 81 | exit 9 |
| 82 | fi |
| 83 | for want in \ |
| 84 | d3e732908a72a372816584d0fe3d62a3db256f1b:native/kernel/ui/chirp.c \ |
| 85 | 359f0f4e63e5c194b005906d3bd7b03cfb7e8703:native/kernel/ui/chirp.h \ |
| 86 | 4cecf8f2afcd8828915a87cefe2cbefab5ef7251:native/kernel/ui/night.h \ |
| 87 | 7032fee2ca584587981297ffa22ade4c72560a76:native/kernel/ui/tests/chirp_test.c; do |
| 88 | blob=${want%%:*} |
| 89 | path=${want#*:} |
| 90 | if [ "$(git -C "$AIENUX_SRC" rev-parse "$PIN:$path")" != "$blob" ]; then |
| 91 | printf 'ORACLE: %s at %s is not blob %s\n' "$path" "$PIN" "$blob" >&2 |
| 92 | exit 9 |
| 93 | fi |
| 94 | done |
| 95 | mkdir "$work/src" "$work/out" "$work/mut" "$work/mutout" |
| 96 | git -C "$AIENUX_SRC" archive "$PIN" native/kernel/ui | tar -x -C "$work/src" |
| 97 | ui=$work/src/native/kernel/ui |
| 98 | cc=${HOSTCC:-cc} |
| 99 | "$cc" -std=c11 -O2 -Wall -Wextra -Werror -o "$work/oracle" "$ui/tests/chirp_test.c" "$ui/chirp.c" |
| 100 | "$work/oracle" "$work/out" |
| 101 | "$work/native" > "$work/native.wav" |
| 102 | if ! cmp "$work/out/chirp.wav" "$work/native.wav"; then |
| 103 | printf 'ORACLE FAIL: Omega night differs from aienux chirp_test.c chirp.wav\n' >&2 |
| 104 | exit 7 |
| 105 | fi |
| 106 | # Frame 545280 of the stereo file starts at byte 44 + 545280 * 4; 45120 frames follow. |
| 107 | od -An -v -td2 -w4 -j 2181164 -N 180480 "$work/out/chirp.wav" > "$work/pairs.txt" |
| 108 | od -An -v -td2 -w2 -j 44 ../../public/audio/allen-chirp.wav > "$work/mono.txt" |
| 109 | awk '{ print $1 }' "$work/pairs.txt" > "$work/left.txt" |
| 110 | awk '$1 != $2 { bad = 1 } END { exit bad }' "$work/pairs.txt" || { |
| 111 | printf 'ORACLE FAIL: left and right differ in the chirp\n' >&2 |
| 112 | exit 7 |
| 113 | } |
| 114 | awk '{ print $1 }' "$work/mono.txt" > "$work/mono1.txt" |
| 115 | if ! cmp -s "$work/left.txt" "$work/mono1.txt"; then |
| 116 | printf 'ORACLE FAIL: allen-chirp.wav is not the oracle left channel at frames 545280..590400\n' >&2 |
| 117 | exit 7 |
| 118 | fi |
| 119 | # Negative control: the same oracle with the peak one step lower must not match. |
| 120 | git -C "$AIENUX_SRC" archive "$PIN" native/kernel/ui | tar -x -C "$work/mut" |
| 121 | mui=$work/mut/native/kernel/ui |
| 122 | sed 's/^#define CK_CHIRP_PEAK 22937 /#define CK_CHIRP_PEAK 22936 /' "$mui/chirp.h" > "$work/chirp.h" |
| 123 | if cmp -s "$work/chirp.h" "$mui/chirp.h"; then |
| 124 | printf 'NEGATIVE CONTROL: the mutation did not apply\n' >&2 |
| 125 | exit 8 |
| 126 | fi |
| 127 | cp "$work/chirp.h" "$mui/chirp.h" |
| 128 | "$cc" -std=c11 -O2 -Wall -Wextra -Werror -o "$work/mutant" "$mui/tests/chirp_test.c" "$mui/chirp.c" |
| 129 | "$work/mutant" "$work/mutout" > /dev/null || true |
| 130 | if cmp -s "$work/mutout/chirp.wav" "$work/native.wav"; then |
| 131 | printf 'NEGATIVE CONTROL FAIL: a mutated oracle also matched\n' >&2 |
| 132 | exit 8 |
| 133 | fi |
| 134 | printf 'ORACLE PASS: aienux %s chirp_test.c chirp.wav == Omega night (%s bytes); web asset == its left channel, frames 545280..590400; mutant oracle differs\n' \ |
| 135 | "$PIN" "$(wc -c < "$work/native.wav" | tr -d ' ')" |
| 136 | fi |
| 137 | |
| 138 | if [ "$stale" = 1 ]; then |
| 139 | printf 'Generated artifacts were rewritten; commit them with their Omega sources\n' >&2 |
| 140 | if [ "${OMEGA_ACCEPT_CHANGE:-0}" != 1 ]; then |
| 141 | exit 4 |
| 142 | fi |
| 143 | fi |