Standalone Objective-C tests for the macOS texture, built against
FlutterMacOS.framework of the active Flutter SDK by macos/test/run_tests.sh
(optionally with ASan or TSan). The plugin sources are compiled into the
test; the plugin registers through a fake plugin registrar and is driven
through handleMethodCall:result:. The fake engine follows
FlutterTextureRegistrar.mm and FlutterExternalTexture.mm of engine a18df97c:
the texture id is the texture's address, the registrar keeps registered
textures, and copyPixelBuffer is wrapped into a Metal texture whose
CVMetalTexture and pixel buffer are released at once while the Metal texture
stays drawn. Frames come through FlutterRgbaRendererPluginOnRgba on a thread
without an autorelease pool. Memory is the task's phys_footprint, which counts
IOSurfaces, read after the engine's CVMetalTextureCache has let go of what it
wrapped (it keeps that until it makes a texture a second later, measured);
it is not checked under ASan, whose shadow of each new IOSurface mapping
counts in it. No app, window or screen capture.
On 50efc18e ten of the thirteen tests fail (Mac mini M4, macOS 26.5.2):
every frame gets a new IOSurface (60 for 60 frames), the raster thread waits
for the copy (median 0.9 to 1.1 ms in three runs, up to 537 of 600 calls over
1 ms, with 4K frames), frames are announced off the main thread, closed
textures keep their last frame (634 MB more after 20 4K textures) and still
take and announce late frames, a texture closed with recycle is never freed,
and rows of another stride than the pixel buffer's are copied in one piece
(shifted rows for 1366, 1001, 1279 and 3838 pixels wide with stride_align 1,
and 1001 with 256), short frames included. The two tests on frames the engine
was handed pass, as no buffer is ever written twice yet.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.9 KiB
Bash
Executable file
65 lines
2.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Kitedesk fork, 2026: builds macos/test/texture_rgba_renderer_plugin_test.m with
|
|
# the plugin sources of macos/Classes against FlutterMacOS.framework, by default
|
|
# the darwin-x64 engine artifacts of the Flutter SDK on PATH (or FLUTTER_ROOT) as
|
|
# `flutter precache --macos` leaves them, and runs each test in its own process.
|
|
# Swift 5 mode, as the podspec. No app, window or screen capture; Metal is used
|
|
# without a display.
|
|
# run_tests.sh plain build
|
|
# run_tests.sh --asan the same with AddressSanitizer
|
|
# run_tests.sh --tsan the same with ThreadSanitizer
|
|
# FLUTTER_MACOS_FRAMEWORKS: the directory holding FlutterMacOS.framework.
|
|
# OUT_DIR (default: a new temporary directory) receives the build.
|
|
set -euo pipefail
|
|
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
classes=$here/../Classes
|
|
if [ -z "${FLUTTER_MACOS_FRAMEWORKS:-}" ]; then
|
|
root=${FLUTTER_ROOT:-$(dirname "$(dirname "$(readlink -f "$(command -v flutter)")")")}
|
|
FLUTTER_MACOS_FRAMEWORKS=$root/bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.xcframework/macos-arm64_x86_64
|
|
fi
|
|
frameworks=$FLUTTER_MACOS_FRAMEWORKS
|
|
[ -f "$frameworks/FlutterMacOS.framework/Headers/FlutterTexture.h" ] || {
|
|
echo "no FlutterMacOS.framework in $frameworks" \
|
|
"(flutter precache --macos, or set FLUTTER_MACOS_FRAMEWORKS)" >&2
|
|
exit 2
|
|
}
|
|
out=${OUT_DIR:-$(mktemp -d)}
|
|
mkdir -p "$out/include/texture_rgba_renderer"
|
|
sanitizer=()
|
|
case "${1:-}" in
|
|
"") ;;
|
|
--asan) sanitizer=(-sanitize=address) ;;
|
|
--tsan)
|
|
sanitizer=(-sanitize=thread)
|
|
export TSAN_OPTIONS=${TSAN_OPTIONS:-halt_on_error=1}
|
|
;;
|
|
*) echo "usage: $0 [--asan | --tsan]" >&2; exit 2 ;;
|
|
esac
|
|
clang_sanitizer=()
|
|
[ ${#sanitizer[@]} -eq 0 ] || clang_sanitizer=("-f${sanitizer[0]#-}" -fno-omit-frame-pointer)
|
|
cache=$out/module-cache
|
|
xcrun swiftc -c -wmo -g -O -swift-version 5 -parse-as-library -module-name texture_rgba_renderer \
|
|
${sanitizer[@]+"${sanitizer[@]}"} -F "$frameworks" -module-cache-path "$cache" \
|
|
-emit-objc-header-path "$out/include/texture_rgba_renderer/texture_rgba_renderer-Swift.h" \
|
|
"$classes"/*.swift -o "$out/plugin.o"
|
|
objc=(xcrun clang -c -g -O1 -fobjc-arc -fmodules -fmodules-cache-path="$cache"
|
|
${clang_sanitizer[@]+"${clang_sanitizer[@]}"} -F "$frameworks" -I "$out/include")
|
|
"${objc[@]}" "$classes/TextureRgbaApi.m" -o "$out/api.o"
|
|
"${objc[@]}" -Wall -Werror "$here/texture_rgba_renderer_plugin_test.m" -o "$out/test.o"
|
|
bin=$out/texture_rgba_renderer_plugin_test
|
|
xcrun swiftc ${sanitizer[@]+"${sanitizer[@]}"} -F "$frameworks" -framework FlutterMacOS \
|
|
-framework CoreVideo -framework IOSurface -framework Metal -Xlinker -rpath -Xlinker "$frameworks" \
|
|
"$out/plugin.o" "$out/api.o" "$out/test.o" -o "$bin"
|
|
count=0
|
|
failed=0
|
|
for test in $("$bin" --list); do
|
|
count=$((count + 1))
|
|
if "$bin" "$test"; then
|
|
echo "PASS $test"
|
|
else
|
|
echo "FAIL $test"
|
|
failed=$((failed + 1))
|
|
fi
|
|
done
|
|
echo "$count tests, $((count - failed)) passed, $failed failed"
|
|
[ "$failed" -eq 0 ]
|