interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

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.
11set -eu
12cd "$(dirname "$0")/../.."
13export LC_ALL=C
14OMC_PIN=734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61
15B=$(mktemp -d "${TMPDIR:-/tmp}/hopfact.XXXXXX")
16fails=0
17pass() { echo "PASS $1"; }
18fail() { echo "FAIL $1"; fails=$((fails + 1)); }
19[ "$(uname -sm)" = "Darwin arm64" ] || { echo "HOPFACT-MACOS NOT_RUN (host is $(uname -sm))"; exit 1; }
20echo "host $(uname -sm) $(sw_vers -productVersion); $(clang --version | head -n 1)"
21
22if shasum -a 256 -c Generated/SHA256SUMS > "$B/sums.log" 2>&1; then pass "Generated/ and Omega/hopfact.om match Generated/SHA256SUMS"
23else fail "SHA256SUMS mismatch"; cat "$B/sums.log"; fi
24src=$(shasum -a 256 Omega/hopfact.om | cut -d' ' -f1)
25if grep -q "src=$src omc=$OMC_PIN path=Omega/hopfact.om" Generated/ident.txt
26then pass "binding identity: src $src, omc $OMC_PIN (bytes tie to the C through the embedded-code check)"
27else fail "Generated/ident.txt does not name this source and the omc pin"; fi
28
29# Hop's integration flags (see Omega/README.md).
30obj() { clang -std=gnu11 -O2 -Wall -Wextra -Werror -target arm64-apple-macos14.0 \
31 -include Generated/omega_native.h -c "$1" -o "$2"; }
32obj Generated/omega_native.c "$B/omega_native.o"
33pass "clang built omega_native.o"
34# embeq OBJ BIN: the bytes at _ombr_code_hopfact in OBJ's __TEXT,__text equal BIN.
35embeq() {
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}
43if embeq "$B/omega_native.o" Generated/hopfact.bin; then pass "embedded code == omc output ($(wc -c < Generated/hopfact.bin | tr -d ' ') bytes)"
44else fail "embedded code differs from Generated/hopfact.bin"; fi
45s=$(nm "$B/omega_native.o" | awk '$3=="_ombr_code_hopfact"{print $1}')
46objdump -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
48printf '.text\n.globl _x\n_x:\nmov x18, x0\nret\n' > "$B/x18.s"; clang -c -o "$B/x18.o" "$B/x18.s"
49ctl=$(objdump -d --no-show-raw-insn "$B/x18.o" | grep -wE '[xw]18' || true)
50if ! 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)"
51else fail "x18 check"; fi
52
53EXTRA=""
54if [ -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"
58fi
59swiftbin() {
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}
64swiftbin "$B/omega_native.o" "$B/check"
65if "$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: //')"
66else fail "swift caller"; fi
67cat "$B/check.log"
68
69obj Omega/tests/mutant/omega_native.c "$B/mut.o"
70if embeq "$B/mut.o" Generated/hopfact.bin; then fail "byte check missed the mutant"
71elif embeq "$B/mut.o" Omega/tests/mutant/hopfact.bin; then pass "byte check: mutant object holds the mutant code, not Generated/hopfact.bin"
72else fail "mutant not embedded as generated"; fi
73swiftbin "$B/mut.o" "$B/mutcheck"
74if "$B/mutcheck" > "$B/mut.log" 2>&1; then fail "unknown->idle mutant not caught"
75else pass "unknown->idle mutant caught: $(grep '^FAIL' "$B/mut.log" | cut -c1-90 | tr '\n' ';')"; fi
76rm -rf "$B"
77if [ "$fails" -ne 0 ]; then echo "HOPFACT-MACOS FAIL $fails"; exit 1; fi
78echo "HOPFACT-MACOS PASS"