aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / evidence / own-gpu-driver / rung2 / reproduce-pipefail.sh
| 1 | #!/usr/bin/env bash |
| 2 | # reproduce-pipefail.sh: deterministic reproduction of the SIGPIPE (exit 141) |
| 3 | # race in window1-package.sh when using `tail | head` under `set -eo pipefail`, |
| 4 | # and verification that `dd if=... of=... bs=64k iflag=skip_bytes,count_bytes` |
| 5 | # exits 0 and produces byte-identical slices without pipes. |
| 6 | set -eu |
| 7 | FW=${FW:-/lib/firmware/nvidia/580.173.02/gsp_ga10x.bin} |
| 8 | T=$(mktemp -d /tmp/repro-pipefail.XXXXXX) |
| 9 | trap 'rm -rf "$T"' EXIT |
| 10 | |
| 11 | if [[ -r "$FW" ]]; then |
| 12 | SRC="$FW" |
| 13 | off=64 |
| 14 | size=74969088 |
| 15 | echo "Using real GSP firmware: $FW (size $(stat -c %s "$FW") bytes)" |
| 16 | else |
| 17 | SRC="$T/synthetic.bin" |
| 18 | dd if=/dev/urandom of="$SRC" bs=1M count=16 status=none |
| 19 | off=64 |
| 20 | size=8388608 |
| 21 | echo "Using synthetic binary payload: $SRC (size $(stat -c %s "$SRC") bytes)" |
| 22 | fi |
| 23 | |
| 24 | echo "--- 1. Demonstrating SIGPIPE (exit 141) with tail | head under pipefail ---" |
| 25 | old_141_count=0 |
| 26 | trials=20 |
| 27 | for i in $(seq 1 "$trials"); do |
| 28 | rc=0 |
| 29 | ( |
| 30 | set -euo pipefail |
| 31 | tail -c +$((off + 1)) "$SRC" | head -c "$size" > /dev/null |
| 32 | ) || rc=$? |
| 33 | if [[ $rc -eq 141 ]]; then |
| 34 | old_141_count=$((old_141_count + 1)) |
| 35 | fi |
| 36 | done |
| 37 | echo "tail | head under pipefail: $old_141_count / $trials runs exited with 141 (SIGPIPE)" |
| 38 | |
| 39 | echo "--- 2. Demonstrating exit 0 with dd (no pipe, direct seek and slice) ---" |
| 40 | new_fail_count=0 |
| 41 | for i in $(seq 1 "$trials"); do |
| 42 | rc=0 |
| 43 | ( |
| 44 | set -euo pipefail |
| 45 | dd if="$SRC" of=/dev/null bs=64k iflag=skip_bytes,count_bytes skip="$off" count="$size" status=none |
| 46 | ) || rc=$? |
| 47 | if [[ $rc -ne 0 ]]; then |
| 48 | new_fail_count=$((new_fail_count + 1)) |
| 49 | fi |
| 50 | done |
| 51 | echo "dd with skip_bytes,count_bytes: $new_fail_count / $trials failures (all passed with rc 0)" |
| 52 | |
| 53 | echo "--- 3. Verifying byte-for-byte identity against reference ---" |
| 54 | python3 -c " |
| 55 | with open('$SRC', 'rb') as f: |
| 56 | f.seek($off) |
| 57 | chunk = f.read($size) |
| 58 | with open('$T/reference.bin', 'wb') as f: |
| 59 | f.write(chunk) |
| 60 | " |
| 61 | dd if="$SRC" of="$T/dd.bin" bs=64k iflag=skip_bytes,count_bytes skip="$off" count="$size" status=none |
| 62 | |
| 63 | cmp "$T/reference.bin" "$T/dd.bin" |
| 64 | echo "BYTE-IDENTICAL: Reference and dd outputs match exactly ($size bytes)" |
| 65 | |
| 66 | if [[ $old_141_count -gt 0 && $new_fail_count -eq 0 ]]; then |
| 67 | echo "REPRODUCTION SUCCESS: tail|head exited 141; dd exited 0 with byte-identical output" |
| 68 | exit 0 |
| 69 | else |
| 70 | echo "REPRODUCTION FAILED unexpected counts: old_141=$old_141_count new_fail=$new_fail_count" |
| 71 | exit 1 |
| 72 | fi |