Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/hop/blob/main/Omega/tests/check-mac.sh # hop Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key. Brought by drakestapleton Sign in to star 1 stars 1 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `hop / Omega / tests / check-mac.sh` 78 lines ยท 4792 bytes Raw Blame History 1 #!/bin/sh 2 # Light macOS arm64 native-ABI check of the hopfact core as Hop links it (no app build, no install). 3 # Usage, from the Hop tree: sh Omega/tests/check-mac.sh 4 # 1. Generated/ matches its SHA256SUMS and records Omega/hopfact.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/hopfact.bin), and it never names x18/w18 (with a control that must be found). 7 # 3. swiftc links Omega/tests/HopFactCheck.swift the way Hop does (-import-objc-header) and runs it. 8 # 4. Negative control: the unknown->idle mutant binding is told apart by the byte check and 9 # fails the Swift checks. 10 # Last line: HOPFACT-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}/hopfact.XXXXXX") 16 fails=0 17 pass() { echo "PASS $1"; } 18 fail() { echo "FAIL $1"; fails=$((fails + 1)); } 19 [ "$(uname -sm)" = "Darwin arm64" ] || { echo "HOPFACT-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/ and Omega/hopfact.om match Generated/SHA256SUMS" 23 else fail "SHA256SUMS mismatch"; cat "$B/sums.log"; fi 24 src=$(shasum -a 256 Omega/hopfact.om | cut -d' ' -f1) 25 if grep -q "src=$src omc=$OMC_PIN path=Omega/hopfact.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_hopfact 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_hopfact"{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/hopfact.bin; then pass "embedded code == omc output ($(wc -c < Generated/hopfact.bin | tr -d ' ') bytes)" 44 else fail "embedded code differs from Generated/hopfact.bin"; fi 45 s=$(nm "$B/omega_native.o" | awk '$3=="_ombr_code_hopfact"{print $1}') 46 objdump -d --no-show-raw-insn --start-address=$((0x$s)) --stop-address=$((0x$s + $(wc -c < Generated/hopfact.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/HopFactCheck.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 obj Omega/tests/mutant/omega_native.c "$B/mut.o" 70 if embeq "$B/mut.o" Generated/hopfact.bin; then fail "byte check missed the mutant" 71 elif embeq "$B/mut.o" Omega/tests/mutant/hopfact.bin; then pass "byte check: mutant object holds the mutant code, not Generated/hopfact.bin" 72 else fail "mutant not embedded as generated"; fi 73 swiftbin "$B/mut.o" "$B/mutcheck" 74 if "$B/mutcheck" > "$B/mut.log" 2>&1; then fail "unknown->idle mutant not caught" 75 else pass "unknown->idle mutant caught: $(grep '^FAIL' "$B/mut.log" | cut -c1-90 | tr '\n' ';')"; fi 76 rm -rf "$B" 77 if [ "$fails" -ne 0 ]; then echo "HOPFACT-MACOS FAIL $fails"; exit 1; fi 78 echo "HOPFACT-MACOS PASS"