Files
reims-vgpu/guest/bundle/tests/bundle_log_check.sh
T
Anees Iqbal da4748c0f1 🐛 Log the bundle's os_log lines on a subsystem of their own
Every os_log line of the Metal bundle went to OS_LOG_DEFAULT, which has no
subsystem, so no `log config` mode could keep its debug lines: on macOS
26.7.2 the system mode persists none, `log config --process PID` refused
the pid, and a debug stream dropped every line under load (26.7.2, 12.7.6).
The resource-wait counter ("RGFX: resource waits so far", RgfxResource.mm)
could not be read there.

The bundle's os_log lines now go to one os_log object, made once a process
with os_log_create on the subsystem ai.aneesiqbal.reims-graphics, the
bundle's CFBundleIdentifier, and the category "bundle" (RgfxLog.hpp),
defined outside ARC so nothing releases it. In the guest each line keeps
its text and level and now carries that subsystem, so `log config
--subsystem ai.aneesiqbal.reims-graphics` sets the level its lines are kept
and persisted at, on every release. Reads that match a line's message see
the same lines. Its NSLog lines, at the default level the log store keeps,
are as they were.

tests/bundle_log_check.sh, in `make test`, keeps the bundle off
OS_LOG_DEFAULT (no _os_log_default import), its log object linked rather
than left to -undefined dynamic_lookup, and the subsystem equal to
Info.plist's identifier.
2026-11-12 02:35:28 -08:00

32 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# bundle_log_check.sh BUNDLE PLIST HEADER: that the bundle's os_log lines go to its own subsystem.
# A line on OS_LOG_DEFAULT has no subsystem, and no mode of `log config` persists its debug lines
# (docs/lessons.md), so the bundle's executable imports no _os_log_default, the object
# OS_LOG_DEFAULT names; it links its log object (src/RgfxLog.cpp) rather than importing it, which
# its -undefined dynamic_lookup would let through to fail in the guest; and the subsystem HEADER
# names is PLIST's CFBundleIdentifier, the name `log config --subsystem` takes. Part of
# `make test`.
set -euo pipefail
exe=$1
[ -f "$exe" ] || exe=$1/Contents/MacOS/reims-graphics
fails=0
imports=$(nm -u "$exe")
if grep -qx '__os_log_default' <<<"$imports"; then
echo "bundle_log_check: FAIL: $exe logs on OS_LOG_DEFAULT (it imports _os_log_default)"
fails=1
fi
if grep -q 'rgfxLog' <<<"$imports"; then
echo "bundle_log_check: FAIL: $exe imports its log object instead of linking it:" \
$(grep 'rgfxLog' <<<"$imports")
fails=1
fi
id=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$2")
subsystem=$(sed -n 's/^#define RGFX_LOG_SUBSYSTEM "\(.*\)"$/\1/p' "$3")
if [ "$subsystem" != "$id" ]; then
echo "bundle_log_check: FAIL: the log subsystem \"$subsystem\" ($3) is not the bundle's" \
"identifier \"$id\" ($2)"
fails=1
fi
[ $fails = 0 ] || exit 1
echo "bundle_log_check: $exe logs on subsystem $id, not on OS_LOG_DEFAULT"