Collecting a profile

LLVM_PROFILE_FILE names where each process writes. Use %p (the process ID) so the driver and every launch get files of their own, and %c for continuous mode. Use an absolute path, since the runtime changes folder.

From Amberlith

Amberlith is the broadest single workload: hundreds of cases over the CPU, the kernel's scheduler, the filesystem, video, display, audio and the SDK hooks, each judged against the console. scripts/amberlith.py passes its environment to the recompile and to each launch, so the variable is all it takes (REFS, the baselines' package, as amberlith.md finds it):

mkdir -p work/cov/prof
LLVM_PROFILE_FILE="$PWD/work/cov/prof/%c%p.profraw" \
python3 scripts/amberlith.py run --runtime build/cov/scarletnx --nro work/cov/amberlith.nro --out work/cov/ep \
    --mode "quick notime cpu fs video display kernel audio hooks" \
    --baseline "$REFS/amberlith/linux-x86_64.txt" --timeout 1200

Use the release CI pins (AMBERLITH_VERSION and AMBERLITH_SHA256 in .github/workflows/build.yml), so the baseline holds. A build older than 0.13.0 opens time:u itself and stops in sm at its first launch. With CI's words, v0.16.1 passed its 826 cases (2 skip (banned)) on the instrumented runtime, in a 12-second launch after a 28-second recompile. It left two .profraw files, one from the recompile and one from the launch.

What the words reach, by folder (lines run, of the lines in that folder):

FolderLinesRun
nx/hle/kernel268952.5%
nx/hle/svc159745.0%
nx/memory261841.4%
common/cpu (mostly the recompile)2244636.8%
nx/loader417833.2%
nx/nn379326.9%
nx/hle/services1409617.7%
nx/gpu/vk4294011.3%
nx/hle/hook (now in nx/nn)34979.2%
nx/gpu/nvn96170.3%
nx/gpu/shader204400.3%

The last two rows follow from the words. CI's words leave out graphics, Amberlith's drawing suites (The mode words), so the shader translator and NVN are barely touched. Each word is a lever on the surface. A run per word set, merged, shows what each adds; --setting KEY=VALUE runs the same cases through another path of the runtime (vk_memory=2, auto_stub_ipc=0, nce=0, ...).

The Android build of Amberlith (--apk) runs the same way on scarletnx-android and covers src/android.

From the tests

ctest runs each test as its own program. Build the test targets in build/cov too, and run them with the same variable:

cmake --build build/cov                                   # every target, the tests among them
LLVM_PROFILE_FILE="$PWD/work/cov/prof-tests/%c%p.profraw" ctest --test-dir build/cov -j6

Each test binary has its own coverage mapping, so llvm-cov needs every binary that wrote a profile, the first as the object and the rest as -object (some tests are scripts that run scarletnx, snx-shaderc or another driver, hence the wide pattern):

objs=$(find build/cov -type f -perm -u+x \( -name 'snx-*' -o -name 'scarletnx*' \) | sed '2,$s/^/-object=/')
llvm-cov report $objs -instr-profile=work/cov/tests.profdata

The tests reach what Amberlith cannot (the shader translator through its corpora, the Vulkan renderer through vulkan_headless, the 3DS, Vita and NDS drivers, the GUI's logic), and Amberlith reaches what the tests do not (whole SVC and service sequences as a program makes them). Their union is the project's checked surface.

From a game or a homebrew program

Any run through build/cov/scarletnx collects the same way:

LLVM_PROFILE_FILE="$PWD/work/cov/prof-game/%c%p.profraw" \
    build/cov/scarletnx --game="$games/<id>" --seconds=120 --input-replay=1

A game's profile says which runtime paths real software reaches. Diffed against the checks' profile, it gives the paths that games depend on and no check holds (Code one run reaches and another does not). The profile names only the runtime's functions, not the game's, but which services and NVN paths a game uses is still the game's behaviour: keep game profiles local.


Made from docs/dev/coverage.md at 69237645142c. GPL-3.0-or-later.