hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
hop / Omega / tests / check-fuse-mac.sh
| 1 | #!/bin/sh |
| 2 | # Light macOS arm64 native-ABI check of the hopfuse core as Hop links it (no app build, no install). |
| 3 | # Usage, from the Hop tree: sh Omega/tests/check-fuse-mac.sh |
| 4 | # 1. Generated/ matches its SHA256SUMS and records Omega/hopfuse.om's hash and the omc pin. |
| 5 | # 2. clang builds Generated/omega_native.c with Hop's flags; the embedded code is omc's bytes |
| 6 | # (Generated/hopfuse.bin), and it never names x18/w18 (with a control that must be found). |
| 7 | # 3. swiftc links Omega/tests/HopFuseCheck.swift the way Hop does (-import-objc-header) and runs it. |
| 8 | # 4. Negative control: the unknown->trivial mutant binding is told apart by the byte check and |
| 9 | # fails the Swift checks. |
| 10 | # Last line: HOPFUSE-MACOS PASS or FAIL n; only PASS exits 0. Scratch goes to a temp dir. |
| 11 | set -eu |
| 12 | cd "$(dirname "$0")/../.." |
| 13 | export LC_ALL=C |
| 14 | OMC_PIN=734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61 |
| 15 | B=$(mktemp -d "${TMPDIR:-/tmp}/hopfuse.XXXXXX") |
| 16 | fails=0 |
| 17 | pass() { echo "PASS $1"; } |
| 18 | fail() { echo "FAIL $1"; fails=$((fails + 1)); } |
| 19 | [ "$(uname -sm)" = "Darwin arm64" ] || { echo "HOPFUSE-MACOS NOT_RUN (host is $(uname -sm))"; exit 1; } |
| 20 | echo "host $(uname -sm) $(sw_vers -productVersion); $(clang --version | head -n 1)" |
| 21 | |
| 22 | if shasum -a 256 -c Generated/SHA256SUMS > "$B/sums.log" 2>&1; then pass "Generated/, Omega/hopfact.om and Omega/hopfuse.om match Generated/SHA256SUMS" |
| 23 | else fail "SHA256SUMS mismatch"; cat "$B/sums.log"; fi |
| 24 | src=$(shasum -a 256 Omega/hopfuse.om | cut -d' ' -f1) |
| 25 | if grep -q "src=$src omc=$OMC_PIN path=Omega/hopfuse.om" Generated/ident.txt |
| 26 | then pass "binding identity: src $src, omc $OMC_PIN (bytes tie to the C through the embedded-code check)" |
| 27 | else fail "Generated/ident.txt does not name this source and the omc pin"; fi |
| 28 | |
| 29 | # Hop's integration flags (see Omega/README.md). |
| 30 | obj() { clang -std=gnu11 -O2 -Wall -Wextra -Werror -target arm64-apple-macos14.0 \ |
| 31 | -include Generated/omega_native.h -c "$1" -o "$2"; } |
| 32 | obj Generated/omega_native.c "$B/omega_native.o" |
| 33 | pass "clang built omega_native.o" |
| 34 | # embeq OBJ BIN: the bytes at _ombr_code_hopfuse in OBJ's __TEXT,__text equal BIN. |
| 35 | embeq() { |
| 36 | sect=$(otool -l "$1" | awk '/sectname __text$/{t=1} t&&$1=="addr"{a=$2} t&&$1=="offset"{print a, $2; exit}') |
| 37 | s=$(nm "$1" | awk '$3=="_ombr_code_hopfuse"{print $1}') |
| 38 | [ -n "$s" ] && [ -n "$sect" ] || return 1 |
| 39 | off=$((0x$s - ${sect% *} + ${sect#* })) |
| 40 | dd if="$1" bs=1 skip="$off" count="$(wc -c < "$2")" 2> /dev/null > "$B/emb.bin" |
| 41 | cmp -s "$2" "$B/emb.bin" |
| 42 | } |
| 43 | if embeq "$B/omega_native.o" Generated/hopfuse.bin; then pass "embedded code == omc output ($(wc -c < Generated/hopfuse.bin | tr -d ' ') bytes)" |
| 44 | else fail "embedded code differs from Generated/hopfuse.bin"; fi |
| 45 | s=$(nm "$B/omega_native.o" | awk '$3=="_ombr_code_hopfuse"{print $1}') |
| 46 | objdump -d --no-show-raw-insn --start-address=$((0x$s)) --stop-address=$((0x$s + $(wc -c < Generated/hopfuse.bin))) \ |
| 47 | "$B/omega_native.o" | grep -E '^ *[0-9a-f]+:' > "$B/dis.txt" || true |
| 48 | printf '.text\n.globl _x\n_x:\nmov x18, x0\nret\n' > "$B/x18.s"; clang -c -o "$B/x18.o" "$B/x18.s" |
| 49 | ctl=$(objdump -d --no-show-raw-insn "$B/x18.o" | grep -wE '[xw]18' || true) |
| 50 | if ! grep -qwE '[xw]18' "$B/dis.txt" && [ -n "$ctl" ]; then pass "no x18/w18 in $(wc -l < "$B/dis.txt" | tr -d ' ') instructions (control found)" |
| 51 | else fail "x18 check"; fi |
| 52 | |
| 53 | EXTRA="" |
| 54 | if [ -f /Library/Developer/CommandLineTools/usr/include/swift/module.modulemap ] && \ |
| 55 | [ -f /Library/Developer/CommandLineTools/usr/include/swift/bridging.modulemap ]; then |
| 56 | sed "s#HOP_DIR#$PWD#" toolchain/overlay.yaml > "$B/overlay.yaml" |
| 57 | EXTRA="-vfsoverlay $B/overlay.yaml -Xcc -ivfsoverlay -Xcc $B/overlay.yaml" |
| 58 | fi |
| 59 | swiftbin() { |
| 60 | # shellcheck disable=SC2086 |
| 61 | swiftc -O -swift-version 5 -target arm64-apple-macos14.0 $EXTRA -import-objc-header Generated/omega_native.h \ |
| 62 | Omega/tests/HopFuseCheck.swift "$1" -o "$2" 2> "$B/swiftc.log" || { cat "$B/swiftc.log"; return 1; } |
| 63 | } |
| 64 | swiftbin "$B/omega_native.o" "$B/check" |
| 65 | if "$B/check" > "$B/check.log" 2>&1; then pass "swift caller: $(grep -c '^PASS' "$B/check.log") checks; $(grep 'latency' "$B/check.log" | sed 's/^PASS latency: //')" |
| 66 | else fail "swift caller"; fi |
| 67 | cat "$B/check.log" |
| 68 | |
| 69 | # The mutant binding holds only hopfuse; the header still declares both cores, which is allowed. |
| 70 | obj Omega/tests/mutant-fuse/omega_native.c "$B/mut.o" |
| 71 | if embeq "$B/mut.o" Generated/hopfuse.bin; then fail "byte check missed the mutant" |
| 72 | elif embeq "$B/mut.o" Omega/tests/mutant-fuse/hopfuse.bin; then pass "byte check: mutant object holds the mutant code, not Generated/hopfuse.bin" |
| 73 | else fail "mutant not embedded as generated"; fi |
| 74 | swiftbin "$B/mut.o" "$B/mutcheck" |
| 75 | if "$B/mutcheck" > "$B/mut.log" 2>&1; then fail "unknown->trivial mutant not caught" |
| 76 | else pass "unknown->trivial mutant caught: $(grep '^FAIL' "$B/mut.log" | cut -c1-90 | tr '\n' ';')"; fi |
| 77 | rm -rf "$B" |
| 78 | if [ "$fails" -ne 0 ]; then echo "HOPFUSE-MACOS FAIL $fails"; exit 1; fi |
| 79 | echo "HOPFUSE-MACOS PASS" |