The functions with a zero count, by file, are the list to start from:
llvm-cov export build/cov/scarletnx -instr-profile=work/cov/ep.profdata -skip-expansions > work/cov/ep.json
python3 - work/cov/ep.json src/nx/hle/services/ <<'EOF'
import collections, json, os, sys
d = json.load(open(sys.argv[1]))['data'][0]
cold, total, names = collections.Counter(), collections.Counter(), collections.defaultdict(list)
for f in d['functions']:
path = f['filenames'][0]
if sys.argv[2] not in path: continue
name = os.path.basename(path); total[name] += 1
if not f['count']:
cold[name] += 1; names[name].append(f['name'].split(':')[-1])
for name, n in cold.most_common(): print(f'{n:4d}/{total[name]:4d} {name} {", ".join(names[name][:4])}')
EOF
From the Amberlith run above, part of what it printed:
219/ 231 misc.c apm_configuration, apm_set_configuration, apm_cpu_boost, ...
153/ 179 am.c am_display_mode_changed, new_appletae, am_user_account_switch_lock, ...
129/ 133 gsv.c new_gsv_session, gsv_native_memory_cpu, gsv_native_image_reserve, ...
105/ 105 acc.c acc_playing, new_acc, new_acc_system, ...
70/ 111 nvdrv.c nvmap_addr_by_id, gmmu_translate, gmmu_run, ...
68/ 70 bsd.c network_set_room, network_interface, network_online, ...
65/ 65 ssl.c new_ssl, new_ssl_system, nn_ssl_sf_ISslService_CreateContext, ...
Read each in three ways:
acc.c, ssl.c): Amberlith never asks for them. A game does (acc is the user
account), so a game's profile covers them, but nothing checks them.am.c, misc.c): the handlers the generated dispatcher calls
(nn_<service>_sf_<interface>_<command>) for commands no case sends. Each is a command whose answer nobody holds
against the console's.-show-branches=count in llvm-cov show). The kernel's and the SVCs' are the important ones: what a wrong
handle, an unaligned address or a full table answers.Not every gap needs a case. Code for another host (#ifdef _WIN32), debug settings and the GUI are reached by
other means. The point is to know which gaps are deliberate.
Two profiles, each exported to JSON, and the functions the second runs that the first never does:
"""covdiff.py A.json B.json [PATH]: the functions B runs and A never does (llvm-cov export), by file"""
import collections, json, sys
def ran(path, under):
d = json.load(open(path))['data'][0]
return {(f['filenames'][0], f['name']) for f in d['functions'] if f['count'] and under in f['filenames'][0]}
under = sys.argv[3] if len(sys.argv) > 3 else '/src/'
only = ran(sys.argv[2], under) - ran(sys.argv[1], under)
by = collections.defaultdict(list)
for path, name in only: by[path.split('/src/', 1)[-1]].append(name.split(':')[-1])
for path in sorted(by, key=lambda p: -len(by[p])):
print(f'{len(by[path]):4d} {path}: {", ".join(sorted(by[path])[:4])}')
python3 work/cov/covdiff.py work/cov/checks.json work/cov/game.json /src/nx/ # what a game needs that no check runs
python3 work/cov/covdiff.py work/cov/before.json work/cov/after.json # what a new case or word added
For example, an Amberlith run with the words quick notime kernel hooks against the full CI words: the CI words
add the VP9 decoder (nx/gpu/video/vp9_rebuild.cpp, 55 functions), nvdrv's control device (nvdrv.c, 38), the
audio renderer's DSP (audren_dsp.c, 34), Vulkan command recording (vk/cmd.c, vk/record.c) and the GPU's hold on
guest memory (vk/owned.c, memory/own.c). That is how to tell which mode word or which case pays for which part
of the runtime.
The useful pairs:
| A | B | What B minus A is |
|---|---|---|
| Amberlith and the tests | a game, or several merged | runtime paths a game depends on that no check holds: candidates for new Amberlith cases or tests |
| a game, before a fix | the same game, after it | what the fix made the game reach (a service it now gets past, a renderer path it now takes) |
| one setting's value | another's (--setting) | the code that setting switches, which the baseline runs only one side of |
origin/main | a branch | new code the branch's checks do not run |
Coverage shows the code that ran. The runtime also logs the code that does not exist: what a program asked for and found nothing behind. Read the run's logs beside the coverage report:
| Log line | What is missing | Where it comes from |
|---|---|---|
[undeclared] <service> cmd N -> ok | a command the service's .swipc does not declare, answered with success and zeros | stub_ok in hle/kernel/ipc.c; auto_stub_ipc=1, the default |
[unknown] <service> cmd N -> UnknownCommandId | the same, answered as the console answers an unknown command | ipc_unknown; auto_stub_ipc=0, or an interface's @fallback(ipc_unknown) |
sm: <name> is not implemented, its commands answer without doing anything | a whole service | hle/services/sm.c |
svc NN (<Name>): not implemented ..., NotImplemented | an SVC still marked stub in hos.svc | hle/svc/svc.c |
nvn: the game resolved NAME, which nvn doesn't implement | an NVN function the game looked up; the game stops if it calls it | gpu/nvn/nvn_loader.c |
@stub commands in a .swipc file answer success with no handler and no log line
(IPC interfaces): grep -n '@stub' src/nx/hle/services/*.swipc lists them.
--auto-stub-ipc=0 turns every undeclared command into the console's error, which makes a game fail where it
makes the call instead of later. --log=2 adds the ipc: lines, the service commands served and their times.
grep -hE '\[(undeclared|unknown)\]|not implemented|doesn.t implement' work/cov/ep/launch-*.log | sort | uniq -c
The CI Amberlith run logs none of these: its cases only ask for what the runtime has. A game's log is where they appear.
What a game could call, from its code and without running it, is in the census tools (pure Python, over the
modules scarletnx --dump-modules reads; their output names the game's functions, so it stays local):
python3 tools/nvn_missing.py work/Game # the NVN procedures the game's driver has that nvn does not implement
python3 tools/export_census.py report work/exefs/<title> # the module's SDK imports and exports no hook runs yet
python3 tools/hook_census.py work/Game # how many of a game's calls a hook could reach
python3 tools/nvn_census.py work/Game # the game's NVN driver: procedure table, command memory writers
The censuses say what exists to be called; coverage says what was called; the log says what was called and missing. A function in all three lists (the game imports it, the runtime has it, no check runs it) is the strongest candidate for a check.
amberlith_scaffold, amberlith_check, amberlith_run, amberlith_finding). Rerun the coverage
afterwards: the diff against the run before says the case reaches what it was meant to.tests/CMakeLists.txt.graphics) or behind a setting the baseline leaves at one value.Made from docs/dev/coverage.md at 69237645142c. GPL-3.0-or-later.