There are three layers: the .NET test projects, Python tests for the build and harness scripts, and a game harness that runs real games for a bounded time and records evidence. Only the first two run in CI. The game harness needs game dumps that are not in the repository.
dotnet test SharpEmu.slnx -c Release| Project | Covers |
|---|---|
tests/SharpEmu.Libs.Tests |
HLE and shared GPU engine: command stream, image requests, pipeline cache, video out. |
tests/SharpEmu.Gpu.Metal.Tests |
The Metal backend: image cache, transfers, guest windows, command-stream ordering, pipelines. macOS only. |
tests/SharpEmu.Gpu.Metal.LeakTests |
Native memory growth across many flushes, with tiered compilation off. macOS only. |
tests/SharpEmu.ShaderCompiler.Metal.Tests |
MSL translation, numerical execution of translated shaders, golden MSL output, and an RDNA2 ALU conformance suite. macOS only. |
tests/SharpEmu.ShaderCompiler.Tests |
The shared shader decoder and IR. |
tests/SharpEmu.Core.Memory.Tests, tests/SharpEmu.Host.Memory.Tests |
Guest memory and the macOS host memory layer. |
tests/SharpEmu.Application.Tests, tests/SharpEmu.Fonts.Tests, tests/SharpEmu.SourceGenerators.Tests |
Launcher logic, fonts, source generators. |
tests/Fixtures holds data the tests read, and tests/SharpEmu.Application.Persistence.Worker
is a helper process, not a test project.
Many tests that encode work on the Metal device, or use native host memory, run
only when SHARPEMU_TEST_REQUIRE_DEVICE=1. Without it such a test is skipped or
returns early and counts as passed, so a plain dotnet test stays green on a
machine without a usable GPU but does not exercise the device paths. To run them:
SHARPEMU_TEST_REQUIRE_DEVICE=1 dotnet test tests/SharpEmu.Gpu.Metal.Tests -c Release
SHARPEMU_TEST_REQUIRE_DEVICE=1 dotnet test tests/SharpEmu.ShaderCompiler.Metal.Tests -c ReleaseThe device tests share one default Metal device, so their collections run one at
a time. Other gating variables, such as SHARPEMU_TEST_REQUIRE_OWNED_NATIVE
for the native host memory workers, are named in the test that reads them.
Variables for the conformance suite and the throughput tests:
| Variable | Effect |
|---|---|
SHARPEMU_CONFORMANCE_REPORT=<dir> |
Writes the per-opcode table and failures of the ALU conformance run. |
SHARPEMU_CONFORMANCE_CATEGORY=<a,b> |
Runs only those opcode categories. |
SHARPEMU_TEST_THROUGHPUT_ROUNDS=<n> |
Repeats the image-transfer throughput measurement. |
python3 -m unittest discover -s tests/scripts -vThese test the macOS build tooling: build metadata and provenance, the output
policy script, and place-host-stack.py.
The harness scripts have their own tests, run directly:
python3 -I scripts/macos/test-input-plan.py
python3 -I scripts/macos/test-ds-metrics.py
python3 -I scripts/macos/test-memstat.py
python3 -I scripts/macos/test-native-fault-trace.pytools/SharpEmu.DebuggerFrontend/tests tests the debugger frontend.
.github/workflows/workflow.yml runs, on every push and pull request, in this
order:
- REUSE compliance (
reuse lint). - On a macOS runner:
dotnet restore SharpEmu.slnx, thenpython3 -m unittest discover -s tests/scripts -v, thendotnet build SharpEmu.slnx -c Release, thendotnet test SharpEmu.slnx -c Release. - A CLI publish for
osx-x64, thenscripts/macos/build-app.sh, and an upload of the app bundle zip.
Pushes that only change Markdown or images do not start the workflow. CI does not
set SHARPEMU_TEST_REQUIRE_DEVICE, so the device-gated tests do not exercise the
device there. Run them locally before changing the Metal backend. Tags that match v* also
publish a release; see Release use.
The scripts below are developer tools. They launch a built SharpEmu.app, so
build one first (Building).
scripts/macos/run-game.sh <game|path/to/eboot.bin> <tag> <seconds> [keyplan] [ENV=VALUE ...]It runs one game for a bounded time and writes
artifacts/runs/<timestamp>-<game>-<tag>/:
game.log, andgame.tlog(the same lines prefixed with seconds since launch),result.txt(how the run ended),run.env(the settings used),keys.log(keys sent),binary-provenance.json,footprint.log(physical footprint and resident size once a second),system-mem.log(paging and memory pressure),frame-times.txt(one line per guest flip),- screenshots, when a window-id helper is available (
SHARPEMU_WINID).
Details:
- The build under test is
SHARPEMU_APP_DIR(defaultartifacts/macos/SharpEmu.app/Contents/MacOS). - The game aliases
ds,sarah,octo,poppy,quake,sh,superl,oregonandvoidmap to fixed folder names underSHARPEMU_GAMES_DIR(default/Volumes/Untitled/games). Pass a path to aneboot.binto run any game. secondsis capped at 150.SHARPEMU_GAME_ENTRY_RUN=1raises the cap to 600 andSHARPEMU_GAME_SESSION_RUN=1to 2400.- The key plan is a comma list of
t:key[:hold]entries, or-for none. It is delivered throughSHARPEMU_INPUT_FILE, so the game needs no focus. Phases anchored to log lines or flip counts, and named markers, are described inscripts/macos/input-plan.py. - Only one game runs at a time on the machine. The script takes a lock
directory (
SHARPEMU_GAME_LOCK), waits for otherSharpEmuprocesses, and waits for the one-minute load average to drop belowSHARPEMU_MAX_LOAD(default: the CPU count) for up toSHARPEMU_LOAD_WAIT_SECONDS(default 1800). SHARPEMU_MEM_LIMIT_MB(default 12288) stops the run when the physical footprint exceeds it.- The game is stopped with SIGTERM, and with SIGKILL only if it is still alive 10 seconds later. The script notes that a SIGKILL with GPU work in flight has been linked to an IOGPU kernel panic, so do not kill a running game by hand.
SHARPEMU_MEMSTAT=1adds a de-duplicated memory breakdown (memstat.log). It needstask_for_pid: either a bundle built withSHARPEMU_MAC_GET_TASK_ALLOW=1or passwordlesssudo. Thememstattool is built on demand (scripts/macos/build-memstat.sh).
SHARPEMU_APP_DIR=<build> scripts/macos/regress.sh <tag> [game ...]Runs a fixed set of games (default sarah quake void oregon) through
run-game.sh with fixed key plans and prints one line per game: the median guest
frame rate over the second half of the run, the result, and the run directory.
Run a baseline build and a candidate build with the same games and compare the
lines and the final screenshots (shot-final.png).
scripts/macos/perf-bench.sh <app-dir> <tag> [plain|prof] [ENV=VALUE ...]One run of the sh game through run-game.sh with a fixed key plan, followed
by perf_report.py over the run directory. It writes perf-report.md and
perf-report.json for the measured window, and per-segment reports. prof mode
adds SHARPEMU_PROFILE_RENDER=1 and SHARPEMU_METAL_V2_PROFILE_PASSES=1, which
cost frame time, so compare prof runs only with prof runs. The script waits
until no dotnet build, dotnet test, MSBuild or compiler server is busy, so
do not start a build while it measures.
| Tool | Purpose |
|---|---|
scripts/macos/games/ds.sh |
Scripted Demon's Souls runs on a private copy of a save, ending in metrics.json and metrics.md (ds-metrics.py). |
scripts/macos/perf_report.py |
Turns a run directory into the performance table; --baseline adds a before and after comparison. |
scripts/macos/analyze_pass_profile.py |
Aggregates [METAL-V2][PASS-PROF] lines from a game.log. |
scripts/macos/analyze_dstrace.py |
Analyses a DSTRACE run directory. |
scripts/macos/footprint.py, memstat.py, memstat.c |
Physical footprint and de-duplicated memory sampling. |
scripts/macos/hud-detect.py |
Detects whether the Demon's Souls in-world HUD is on screen, from a screenshot. |
scripts/macos/read-native-fault-trace.py |
Reads the native fault trace of a stopped process. |
scripts/macos/metal-submit-latency.m |
Standalone probe of Metal command-buffer scheduling latency. |
tools/SharpEmu.Tools.ShaderDump |
Shader decode and dump tool; check-corpus.sh retranslates a recorded shader corpus through the Metal path and xcrun metal. |
tools/SharpEmu.Tools.ShaderCompileBench |
Shader compile benchmark. |
tools/SharpEmu.Tools.MacWindowSmoke |
Manual smoke test of the native window and CAMetalLayer. |