From da7c2e7ef43ac1d4659faa7eb5f5a1f6e42af536 Mon Sep 17 00:00:00 2001 From: AO55 Date: Sat, 7 Nov 2026 23:41:00 -0300 Subject: [PATCH 1/4] [tracer] Runs of edenprobe as reports of their own A report whose first log holds a run of edenprobe (ScarletNX's log of it, alone or in the Share Log zip, Eden's or rEden's log, or report.jsonl) keeps the machine, the emulator, the mode and every case, apart from the games, and the reply says the counts and the suites that failed. The detail of the service, net and pad cases and the net notes, which can name the player, is taken out of every kept log first; a run sent twice by one person is kept once, and the next start makes the reports kept before into runs. Signed-off-by: AO55 --- docs/TESTING.md | 11 +- docs/TRACER.md | 54 +- tracer/Makefile | 23 +- tracer/src/files.c | 41 +- tracer/src/files.h | 18 +- tracer/src/probe.c | 982 +++++++++++++++++++++++++++++++++++++ tracer/src/probe.h | 130 +++++ tracer/src/report.c | 223 ++++++++- tracer/src/report.h | 9 +- tracer/src/site.c | 12 +- tracer/src/store.c | 323 +++++++++++- tracer/src/store.h | 53 +- tracer/src/worker.c | 14 +- tracer/tests/test_tracer.c | 551 +++++++++++++++++++++ 14 files changed, 2391 insertions(+), 53 deletions(-) create mode 100644 tracer/src/probe.c create mode 100644 tracer/src/probe.h diff --git a/docs/TESTING.md b/docs/TESTING.md index ea8d54b..948d746 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -73,7 +73,16 @@ temporary folder: environment before the bot keeps it from its user's debuggers and not after, the bot's descriptors closed in it, no worker for a message without files; - the MCP server over that site: its handshake and protocol versions, notifications, broken and unknown requests, each - tool's filters, limits and errors, and a query's 16 words at most. + tool's filters, limits and errors, and a query's 16 words at most; +- runs of edenprobe: edenprobe's families and which lose their detail, the drivers by the ban table's names and by + their own, each driver's version numbering both ways, the system's family; the cut of a log (the service, net, pad + and unknown suites' details and the net notes, every other byte as it was); ScarletNX's log, Eden's, rEden's and a + report.jsonl read, two copies of a run, a run cut short, a launch that went on after a crash, lines edenprobe does + not write; a run through JSON and the answers refused (another emulator, a detail the cut takes out, a case that is + none); the run in a Share Log zip, a run begun, none; whole runs as reports (the reply's counts and what was left + out, the database and the kept log without the player, no game's list, the same run again from one person and from + another, Eden's and the console's, deleted with their message, a resumed launch kept as a log, one through the + worker), and a report kept before made the run's at the next start. ## The docs diff --git a/docs/TRACER.md b/docs/TRACER.md index 7b56a1b..1b73051 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -9,6 +9,7 @@ * [What a report keeps](#what-a-report-keeps) * [Adding to a report](#adding-to-a-report) * [A log sent without the mention](#a-log-sent-without-the-mention) + * [A run of edenprobe](#a-run-of-edenprobe) * [Deleting, and the hourly limit](#deleting-and-the-hourly-limit) * [Summarized and named again](#summarized-and-named-again) * [Commands](#commands) @@ -49,13 +50,13 @@ for it). The worker's answer is checked before any of its files moves from the w ### What a report keeps -- Its logs (`.log`, `.txt`, or one packed in a `.gz` or a `.zip`; 3 at most, 64 MiB each) are downloaded from Discord, - each home folder in them written as `~` (`/home/`, `C:\Users\`, Android's app folders), the crash +- Its logs (`.log`, `.txt`, `.jsonl`, or one packed in a `.gz` or a `.zip`; 3 at most, 64 MiB each) are downloaded from + Discord, each home folder in them written as `~` (`/home/`, `C:\Users\`, Android's app folders), the crash report's code and memory dumps and registers left out (the game's own bytes, which the summary leaves out too), each - IPv4 address but the loopback's written as `[ip]` and each e-mail address as `[email]` (a network game's log names - the player's address and the other players'), and summarized: the game, its title ID and version, the build, the - system and GPU, how the run ended and where, the service commands and what else the runtime missed, the last lines. - A file that is no ScarletNX log is named in the reply and not kept. + IPv4 address but the loopback's written as `[ip]` and each e-mail address as `[email]` (a network game's log names the + player's address and the other players'), and summarized: the game, its title ID and version, the build, the system + and GPU, how the run ended and where, the service commands and what else the runtime missed, the last lines. A file + that is no ScarletNX log, nor a run of edenprobe, is named in the reply and not kept. - Its screenshots (PNG, JPEG, WebP, GIF or PPM, read from their bytes; 8 at most, 25 MiB each) lose their metadata: EXIF and its place and camera, XMP, PNG's text and time, JPEG's and GIF's comments, a GIF's applications' data but its loop, and what follows a JPEG's or a GIF's end (a phone's motion photo video, a maker's trailer). A PPM, the @@ -105,6 +106,39 @@ log line says which. A reply that brings files makes a report of those, as any m is part of a report already gets that report's link; a message of another channel or server, a bot's or a webhook's, one that is gone and one with no log are refused, each with why. +### A run of edenprobe + +[edenprobe](https://github.com/scarletnx/edenprobe) checks an emulator against the console, case by case. A report +whose first log holds a run of it is the run's, kept apart from the games: in no game's list, nor `all.html` and +`api/reports.json`. A run comes in three forms: + +- ScarletNX's log of the run, alone or in the launcher's Share Log zip, whose entry that holds a whole run is the one + kept (else one a run begins in, else its first log, as for any zip): the machine from its header (`system:`, the + driver's `vulkan: the driver that runs: radv, Mesa 26.1.8 (driver ID 3)`, and the GPU's line with the driver's + version), the report's lines as `[game] {...}`; +- Eden's log of it, or rEden's: the machine from its `Driver:`, `Device:`, `Vulkan:` and `Host OS:` lines, the report's + lines as `Debug.Emulated` ones. Eden logs no driver ID: it is read from the driver's name, and the reply says so; +- the report itself, `report.jsonl`, which names no machine: it is kept as the console's reference. + +A run begins at its note `edenprobe 0.9.0 (v0.9.0) starting`; of several in one file (the Share Log's `summary.txt` +holds a run's output and its log), the last whole one is read, one with its summary, else the last one. Kept of it: +the machine (the system and its family, the GPU, the driver's VkDriverId, name and version as its vendor numbers it, +which are ScarletNX's ban table's), the emulator and its build, edenprobe's version, the words its mode note says ran +(`cpu graphics net notime`), and each case's suite, name, tier, result, reason, detail (its first 300 bytes) and time, +10000 cases at most. + +The detail of the cases of edenprobe's service, net and pad families, and of a suite its table does not have, is left +out, and so is the text of the net family's notes: the account cases name a user's id and nickname, the network ones +the addresses and sessions the net file names. They are taken out of every log a report keeps, wherever such a line +is, before anything reads it, so neither the database nor the site has them. + +The reply gives the counts and the suites that failed most, `edenprobe 0.9.0 on radv, Mesa 26.1.8 (Linux): 1034 +passed, 26 failed (astc 15, astcimage 9, tex8k 2), 6 skipped, 3 crashed`, and what the run lacks: no summary line, a +summary that counts more cases than the file has (a launch that went on after a crash logs its own cases alone), lines +edenprobe does not write, a report.jsonl's machine. The same run sent again by the same person, line for line, is +answered with the first report's link and kept no more. A log whose lines of edenprobe have no run's start, a launch +that went on after a crash, is kept as the game's log, and the reply says why it is no run. + ### Deleting, and the hourly limit `@Tracer delete 12`, or a reply with `@Tracer delete`, deletes a report, for the person who sent it, the owner and @@ -117,9 +151,11 @@ counts, and so does one deleted since (its files were downloaded); a message wit ### Summarized and named again -When the log summary or the list of names changes (`scripts/sync-logscan.sh`, `scripts/make-titles.py`), the next -start summarizes each kept log again, draws each report's facts again from its first log, files a report whose first -log now names another game under that game, and names one its logs don't name from the list. +When the log summary or the list of names changes (`scripts/sync-logscan.sh`, `scripts/make-titles.py`), or what a +report keeps of its logs (`TR_FACTS`), the next start summarizes each kept log again, draws each report's facts again +from its first log, files a report whose first log now names another game under that game, names one its logs don't +name from the list, makes a report whose first log holds a run of edenprobe the run's, and takes out of each kept log +what a run's lines would say of the player. ## Commands diff --git a/tracer/Makefile b/tracer/Makefile index dd2bc99..b49e751 100644 --- a/tracer/Makefile +++ b/tracer/Makefile @@ -31,8 +31,9 @@ DEFS = -D_POSIX_C_SOURCE=200809L -DREI_NAME=\"tracer\" -DTR_LOGSCAN=\"`cat $(LOG OURS = $(WARN) $(DEFS) -Isrc -I$(REI)/src -I$(REI)/third_party/cjson -Ithird_party/logscan LIBS = $(SQLITE_LIBS) $(ARCHIVE_LIBS) $(ZLIB_LIBS) $(CXXRT) -lpthread -lm -LOGIC = src/message.o src/files.o src/store.o src/site.o src/report.o src/titles.o src/channels.o src/worker.o \ - src/issues.o src/age.o src/mcp.o src/rei_util.o third_party/cjson.o third_party/logscan.o third_party/demangle.o +LOGIC = src/message.o src/files.o src/probe.o src/store.o src/site.o src/report.o src/titles.o src/channels.o \ + src/worker.o src/issues.o src/age.o src/mcp.o src/rei_util.o third_party/cjson.o third_party/logscan.o \ + third_party/demangle.o all: tracer tracer-mcp @@ -57,24 +58,26 @@ tests/test_tracer: $(LOGIC) tests/test_tracer.c src/message.o: src/message.c src/message.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/message.c -src/files.o: src/files.c src/files.h src/tracer.h +src/files.o: src/files.c src/files.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/files.c -src/store.o: src/store.c src/store.h src/tracer.h +src/probe.o: src/probe.c src/probe.h src/files.h src/tracer.h + $(CC) $(CFLAGS) $(OURS) -c -o $@ src/probe.c +src/store.o: src/store.c src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) $(SQLITE_CFLAGS) -c -o $@ src/store.c -src/site.o: src/site.c src/site.h src/files.h src/store.h src/tracer.h +src/site.o: src/site.c src/site.h src/files.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/site.c -src/worker.o: src/worker.c src/worker.h src/report.h src/age.h src/tracer.h +src/worker.o: src/worker.c src/worker.h src/report.h src/age.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/worker.c -src/issues.o: src/issues.c src/issues.h src/store.h src/tracer.h +src/issues.o: src/issues.c src/issues.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/issues.c -src/age.o: src/age.c src/age.h src/store.h src/tracer.h +src/age.o: src/age.c src/age.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/age.c src/channels.o: src/channels.c src/channels.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/channels.c src/titles.o: src/titles.c src/titles.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/titles.c src/report.o: src/report.c src/report.h src/age.h src/issues.h src/titles.h src/files.h src/site.h src/store.h \ - src/message.h src/tracer.h + src/probe.h src/message.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/report.c src/mcp.o: src/mcp.c src/mcp.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/mcp.c @@ -84,7 +87,7 @@ src/fetch.o: src/fetch.c src/fetch.h src/tracer.h $(CC) $(CFLAGS) $(OURS) $(CURL_CFLAGS) -c -o $@ src/fetch.c # Concord's headers are not ours: their warnings are theirs src/main.o: src/main.c $(LOGSCAN_FILES) src/age.h src/channels.h src/issues.h src/worker.h src/fetch.h src/report.h \ - src/site.h src/store.h src/message.h src/tracer.h $(REI)/src/watch.h + src/site.h src/store.h src/probe.h src/message.h src/tracer.h $(REI)/src/watch.h $(CC) $(CFLAGS) $(OURS) $(CURL_CFLAGS) -isystem $(CONCORD)/include/concord -c -o $@ src/main.c src/rei_util.o: $(REI)/src/util.c $(REI)/src/rei.h $(CC) $(CFLAGS) $(OURS) -c -o $@ $(REI)/src/util.c diff --git a/tracer/src/files.c b/tracer/src/files.c index 4a7bfeb..0a909a4 100644 --- a/tracer/src/files.c +++ b/tracer/src/files.c @@ -8,13 +8,18 @@ #include #include +#include "probe.h" + +/* the bytes a zip's entries are unpacked to at most in looking for the one that holds a run of edenprobe */ +#define ZIP_SCAN (TR_LOG_MAX * 4) + static int ends(const char* name, const char* ext) { size_t n = strlen(name), e = strlen(ext); return n > e && !strcasecmp(name + n - e, ext); } TrKind tr_kind(const char* name, const char* type) { - static const char* const logs[] = {".log", ".txt", ".gz", ".zip"}; + static const char* const logs[] = {".log", ".txt", ".jsonl", ".gz", ".zip"}; static const char* const images[] = {".png", ".jpg", ".jpeg", ".webp", ".gif", ".ppm"}; static const char* const videos[] = {".mp4", ".m4v", ".webm"}; size_t i; @@ -371,22 +376,40 @@ int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out buf_addn(out, data, n); return 0; } - if (zip) { /* the first .log or .txt, else the first file */ + if (zip) { /* an entry holding a whole run of edenprobe, else one a run begins in, else the first .log, .txt or + .jsonl, else the first file: a Share Log zip holds many logs, one of which may be the run */ + int text = -1, started = -1; + size_t read = 0; if (!(a = opened(1, data, n))) goto broken; for (at = 0; archive_read_next_header(a, &e) == ARCHIVE_OK; ++at) { const char* inner = archive_entry_pathname(e); + int marks, whole = 1; if (archive_entry_filetype(e) != AE_IFREG) continue; if (wanted < 0) wanted = at; - if (inner && (ends(inner, ".log") || ends(inner, ".txt"))) { - wanted = at; - break; + if (!inner || (!ends(inner, ".log") && !ends(inner, ".txt") && !ends(inner, ".jsonl"))) continue; + if (text < 0) text = at; + if (read >= ZIP_SCAN) continue; /* past what is read in looking for a run: the order above holds */ + buf_free(out); + while ((got = archive_read_data(a, piece, sizeof piece)) > 0 && whole) { + read += (size_t)got; + whole = (size_t)got <= max - out->len; + if (whole) buf_addn(out, piece, (size_t)got); + } + if (got < 0 || !whole) continue; + marks = probe_marks(out->text ? out->text : "", out->len); + if (marks == 2) { /* this one: read whole already */ + archive_read_free(a); + return 0; } + if (marks == 1 && started < 0) started = at; } archive_read_free(a); + buf_free(out); if (wanted < 0) { *why = rei_format("%s holds no file", name); return -1; } + wanted = started >= 0 ? started : text >= 0 ? text : wanted; } if (!(a = opened(zip, data, n))) goto broken; for (at = 0; archive_read_next_header(a, &e) == ARCHIVE_OK; ++at) { @@ -417,7 +440,7 @@ char* tr_unpacked_name(const char* name) { if (ends(name, ".gz")) { char* rest = rei_format("%.*s", (int)(n - 3), name); char* named; - if (ends(rest, ".log") || ends(rest, ".txt")) return rest; + if (ends(rest, ".log") || ends(rest, ".txt") || ends(rest, ".jsonl")) return rest; named = rei_format("%s.log", rest); free(rest); return named; @@ -465,9 +488,7 @@ char* tr_utf8(const char* text, size_t n) { return buf_take(&b); } -/* "[ 2.25] " before a line, the time the runtime prints (its point a comma under some locales): its length, 0 without - one. As logscan.c's stamp(), it takes one space after the bracket, so a dump's indent is what follows */ -static size_t stamp(const char* s, size_t n) { +size_t tr_stamp(const char* s, size_t n) { size_t i = 1, d; if (!n || s[0] != '[') return 0; while (i < n && s[i] == ' ') ++i; @@ -484,7 +505,7 @@ static size_t stamp(const char* s, size_t n) { static int dump_line(const char* s, size_t n) { static const char* const prefixes[] = { "code ", "mem ", "vtable:", "-> ", "pc=", "cpsr=", "info+", "data:", "(the rest"}; - size_t i = stamp(s, n), indent, k, d; + size_t i = tr_stamp(s, n), indent, k, d; for (indent = i; i < n && (s[i] == ' ' || s[i] == '\t'); ++i) continue; if (i == indent) return 0; s += i; diff --git a/tracer/src/files.h b/tracer/src/files.h index 3bdb507..5d05a1f 100644 --- a/tracer/src/files.h +++ b/tracer/src/files.h @@ -8,8 +8,8 @@ #include "tracer.h" typedef enum { TR_OTHER, TR_LOG, TR_IMAGE, TR_VIDEO } TrKind; -/* by the file's name (.log, .txt, .gz, .zip; .png, .jpg, .jpeg, .webp, .gif, .ppm; .mp4, .m4v, .webm) or Discord's - content type */ +/* by the file's name (.log, .txt, .jsonl, .gz, .zip; .png, .jpg, .jpeg, .webp, .gif, .ppm; .mp4, .m4v, .webm) or + Discord's content type */ TrKind tr_kind(const char* name, const char* type); /* the image's kind from its first bytes: "png", "jpg", "gif", "webp" or "ppm" (a binary PPM, P6, which ScarletNX's @@ -33,14 +33,20 @@ size_t tr_strip_video(char* data, size_t n); a PPM that isn't whole or is bigger than 16384 pixels a side */ int tr_ppm_png(const char* data, size_t n, Buf* out); -/* a log as text: a .gz's or a .zip's (its first .log or .txt, else its first file) unpacked, any other name's bytes - as they are, max bytes at most. 0, or -1 with why (owned) */ +/* a log as text: a .gz's or a .zip's unpacked, any other name's bytes as they are, max bytes at most. Of a .zip, the + entry that holds a whole run of edenprobe (probe.h), else one a run begins in, else its first .log, .txt or .jsonl, + else its first file; its entries are read in looking for the run up to 256 MiB in all. 0, or -1 with why (owned) */ int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out, char** why); /* the name the text tr_unpack made of name is saved as: a .gz's without its .gz ("game.log.gz" as "game.log"), with - .log after it when what is left is no .log or .txt; a .zip's with .log for its .zip ("logs.zip" as "logs.log"); any - other name as it is. The site keeps the text, never the archive. Owned */ + .log after it when what is left is no .log, .txt or .jsonl; a .zip's with .log for its .zip ("logs.zip" as + "logs.log"); any other name as it is. The site keeps the text, never the archive. Owned */ char* tr_unpacked_name(const char* name); +/* "[ 2.25] " before a line, the time the runtime prints (its point a comma under some locales), or Eden's + "[ 12.345678] ": its length, 0 without one. As logscan.c's stamp(), it takes one space after the bracket, so a + dump's indent is what follows */ +size_t tr_stamp(const char* s, size_t n); + /* the n bytes of text with each byte that is not part of valid UTF-8 as U+FFFD, and each NUL left out; owned */ char* tr_utf8(const char* text, size_t n); diff --git a/tracer/src/probe.c b/tracer/src/probe.c new file mode 100644 index 0000000..636fd65 --- /dev/null +++ b/tracer/src/probe.c @@ -0,0 +1,982 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + Copyright 2026 the ScarletNX contributors */ +#include "probe.h" +#include +#include +#include +#include +#include +#include + +#include "files.h" + +/* ---- edenprobe's families ---- */ + +/* which family each suite is of, by the name its lines carry: edenprobe's ui.c, FAMILIES (edenprobe 86e1d11) */ +static const struct { + const char* suite; + ProbeFamily family; +} FAMILIES[] = { + {"selfcheck", PROBE_JUDGE}, + {"support", PROBE_JUDGE}, + {"reference", PROBE_JUDGE}, + {"cpu", PROBE_CPU}, + {"pad", PROBE_PAD}, + {"touch", PROBE_PAD}, + {"clear", PROBE_GRAPHICS}, + {"format", PROBE_GRAPHICS}, + {"raster", PROBE_GRAPHICS}, + {"intmath", PROBE_GRAPHICS}, + {"blend", PROBE_GRAPHICS}, + {"depth", PROBE_GRAPHICS}, + {"fixed", PROBE_GRAPHICS}, + {"texture", PROBE_GRAPHICS}, + {"coherence", PROBE_GRAPHICS}, + {"fmath", PROBE_GRAPHICS}, + {"order", PROBE_GRAPHICS}, + {"index", PROBE_GRAPHICS}, + {"instance", PROBE_GRAPHICS}, + {"bindless", PROBE_GRAPHICS}, + {"astc", PROBE_GRAPHICS}, + {"astcimage", PROBE_GRAPHICS}, + {"eac", PROBE_GRAPHICS}, + {"etc2", PROBE_GRAPHICS}, + {"bcn", PROBE_GRAPHICS}, + {"zeta", PROBE_GRAPHICS}, + {"swizzle", PROBE_GRAPHICS}, + {"texel", PROBE_GRAPHICS}, + {"stream", PROBE_GRAPHICS}, + {"fill", PROBE_GRAPHICS}, + {"ring", PROBE_GRAPHICS}, + {"occlusion", PROBE_GRAPHICS}, + {"drawtex", PROBE_GRAPHICS}, + {"geometry", PROBE_GRAPHICS}, + {"query", PROBE_GRAPHICS}, + {"dma", PROBE_GRAPHICS}, + {"blit2d", PROBE_GRAPHICS}, + {"tex8k", PROBE_GRAPHICS}, + {"fs", PROBE_FS}, + {"sched", PROBE_KERNEL}, + {"binder", PROBE_DISPLAY}, + {"vic", PROBE_VIDEO}, + {"nvdec", PROBE_VIDEO}, + {"audio", PROBE_AUDIO}, + {"hwopus", PROBE_SERVICE}, + {"am", PROBE_SERVICE}, + {"fsp", PROBE_SERVICE}, + {"account", PROBE_SERVICE}, + {"ldn", PROBE_SERVICE}, + {"set", PROBE_SERVICE}, + {"csrng", PROBE_SERVICE}, + {"apm", PROBE_SERVICE}, + {"nfp", PROBE_SERVICE}, + {"aoc", PROBE_SERVICE}, + {"time", PROBE_SERVICE}, + {"pl", PROBE_SERVICE}, + {"profile", PROBE_SERVICE}, + {"am-state", PROBE_SERVICE}, + {"am-self", PROBE_SERVICE}, + {"am-functions", PROBE_SERVICE}, + {"auddev", PROBE_SERVICE}, + {"fsdir", PROBE_SERVICE}, + {"am-audio", PROBE_SERVICE}, + {"am-channel", PROBE_SERVICE}, + {"am-storage", PROBE_SERVICE}, + {"mii", PROBE_SERVICE}, + {"am-mode", PROBE_SERVICE}, + {"bsd-local", PROBE_SERVICE}, + {"ipc", PROBE_SERVICE}, + {"hid", PROBE_SERVICE}, + {"time-snap", PROBE_SERVICE}, + {"vi", PROBE_SERVICE}, + {"renderer", PROBE_SERVICE}, + {"ngc", PROBE_SERVICE}, + {"am-lock", PROBE_SERVICE}, + {"set-sys", PROBE_SERVICE}, + {"time-zone", PROBE_SERVICE}, + {"time-perm", PROBE_SERVICE}, + {"audout", PROBE_SERVICE}, + {"fs-file", PROBE_SERVICE}, + {"acc-app", PROBE_SERVICE}, + {"nifm", PROBE_NET}, + {"dns", PROBE_NET}, + {"bsd", PROBE_NET}, + {"ssl", PROBE_NET}, + {"acc", PROBE_NET}, + {"friend", PROBE_NET}, + {"game", PROBE_GAME}, +}; + +ProbeFamily probe_family(const char* suite) { + size_t i; + for (i = 0; suite && i < sizeof FAMILIES / sizeof *FAMILIES; ++i) + if (!strcmp(FAMILIES[i].suite, suite)) return FAMILIES[i].family; + return PROBE_OTHER; +} + +const char* probe_family_name(ProbeFamily f) { + static const char* const names[] = {"judge", "cpu", "pad", "graphics", "fs", "kernel", "display", + "video", "audio", "service", "net", "game", "other"}; + return f >= PROBE_JUDGE && f <= PROBE_OTHER ? names[f] : "other"; +} + +int probe_keeps_detail(const char* suite) { + ProbeFamily f = probe_family(suite); + return f != PROBE_SERVICE && f != PROBE_NET && f != PROBE_PAD && f != PROBE_OTHER; +} + +/* ---- the drivers: ScarletNX's ban table's names and numbering (src/nx/gpu/vk/extension_bans.c, #1390) ---- */ + +static const char* const DRIVER_NAMES[] = { + NULL, "amd-proprietary", "amdvlk", "radv", "nvidia", "intel-windows", "anv", + "powervr", "qualcomm", "mali", "swiftshader", "ggp", "broadcom", "lavapipe", + "moltenvk", "coreavi", "juice", "verisilicon", "turnip", "v3dv", "panvk", + "samsung", "venus", "dozen", "nvk", "powervr-mesa", "honeykrisp", "vulkansc", + "kosmickrisp", "gfxstream", "apesoft"}; +static const char* const DRIVER_LABELS[] = {NULL, + "AMD's proprietary driver", + "AMDVLK", + "RADV", + "NVIDIA's driver", + "Intel's Windows driver", + "ANV", + "Imagination's PowerVR driver", + "Qualcomm's driver", + "Arm's Mali driver", + "SwiftShader", + "GGP's driver", + "Broadcom's driver", + "lavapipe", + "MoltenVK", + "CoreAVI's driver", + "Juice's driver", + "VeriSilicon's driver", + "Turnip", + "v3dv", + "PanVK", + "Samsung's Xclipse driver", + "Venus", + "Dozen", + "NVK", + "Imagination's Mesa driver", + "Honeykrisp", + "Vulkan SC emulation", + "KosmicKrisp", + "gfxstream", + "APE Soft's driver"}; +#define DRIVERS ((int)(sizeof DRIVER_NAMES / sizeof *DRIVER_NAMES)) +enum { DRV_NVIDIA = 4, DRV_INTEL_WINDOWS = 5, DRV_MOLTENVK = 14 }; + +const char* probe_driver_name(int id) { return id > 0 && id < DRIVERS ? DRIVER_NAMES[id] : NULL; } +const char* probe_driver_label(int id) { return id > 0 && id < DRIVERS ? DRIVER_LABELS[id] : NULL; } +int probe_driver_id(const char* name) { + int id; + for (id = 1; name && id < DRIVERS; ++id) + if (!strcmp(DRIVER_NAMES[id], name)) return id; + return 0; +} + +static int has_word(const char* text, const char* word) { + size_t n = strlen(word); + const char* s; + for (s = text; *s; ++s) + if (!strncasecmp(s, word, n)) return 1; + return 0; +} +int probe_driver_of_name(const char* driver_name) { + /* the words in the drivers' own names, each more particular one before the word it holds: NVK before NVIDIA */ + static const struct { + const char* word; + int id; + } words[] = {{"radv", 3}, + {"nvk", 24}, + {"nvidia", 4}, + {"turnip", 18}, + {"qualcomm", 8}, + {"adreno", 8}, + {"mali", 9}, + {"amd proprietary", 1}, + {"amd open-source", 2}, + {"amdvlk", 2}, + {"intel open-source", 6}, + {"anv", 6}, + {"intel", 5}, + {"llvmpipe", 13}, + {"lavapipe", 13}, + {"moltenvk", 14}, + {"xclipse", 21}, + {"samsung", 21}, + {"panvk", 20}, + {"v3dv", 19}, + {"venus", 22}, + {"dozen", 23}, + {"swiftshader", 10}, + {"honeykrisp", 26}, + {"kosmickrisp", 28}, + {"powervr", 7}}; + size_t i; + for (i = 0; driver_name && i < sizeof words / sizeof *words; ++i) + if (has_word(driver_name, words[i].word)) return words[i].id; + return 0; +} + +void probe_version_text(int id, unsigned long v, char* out, size_t n) { + if (id == DRV_NVIDIA) + snprintf(out, n, "%lu.%lu.%02lu", v >> 22, v >> 14 & 0xffu, v >> 6 & 0xffu); + else if (id == DRV_INTEL_WINDOWS) + snprintf(out, n, "%lu.%lu", v >> 14, v & 0x3fffu); + else if (id == DRV_MOLTENVK) + snprintf(out, n, "%lu.%lu.%lu", v / 10000u, v / 100u % 100u, v % 100u); + else /* VK_MAKE_VERSION's fields: a major of 10 bits, as Qualcomm's 512 needs */ + snprintf(out, n, "%lu.%lu.%lu", v >> 22, v >> 12 & 0x3ffu, v & 0xfffu); +} + +int probe_version_parse(int id, const char* text, unsigned long* v) { + unsigned long part[4] = {0}; + int parts = 0; + const char* s = text; + while (*s) { + unsigned long value = 0; + int digits = 0; + while (*s >= '0' && *s <= '9' && digits < 10) value = value * 10 + (unsigned long)(*s++ - '0'), ++digits; + if (!digits || value > 0xffffffffUL || parts == 4 || (*s && *s != '.') || (*s == '.' && !s[1])) return 0; + part[parts++] = value; + s += *s == '.'; + } + if (id == DRV_NVIDIA) { /* A.B[.C[.D]] */ + if (parts < 2 || part[0] > 1023 || part[1] > 255 || part[2] > 255 || part[3] > 63) return 0; + *v = part[0] << 22 | part[1] << 14 | part[2] << 6 | part[3]; + } else if (id == DRV_INTEL_WINDOWS) { /* the last two of its four numbers */ + if ((parts != 2 && parts != 4) || part[parts - 2] > 0x3ffffUL || part[parts - 1] > 0x3fffUL) return 0; + *v = part[parts - 2] << 14 | part[parts - 1]; + } else if (id == DRV_MOLTENVK) { + if (parts < 2 || parts > 3 || part[0] > 429495 || part[1] > 99 || part[2] > 99) return 0; + *v = part[0] * 10000 + part[1] * 100 + part[2]; + } else { + if (parts < 2 || parts > 3 || part[0] > 1023 || part[1] > 1023 || part[2] > 4095) return 0; + *v = part[0] << 22 | part[1] << 12 | part[2]; + } + return 1; +} + +const char* probe_os(const char* system) { + /* Android before Linux, as its line names its kernel: "Android 15 (Linux 6.1...)" */ + static const struct { + const char *word, *os; + } systems[] = {{"android", "android"}, {"windows", "windows"}, {"macos", "macos"}, {"mac os", "macos"}, + {"darwin", "macos"}, {"ipados", "ios"}, {"ios ", "ios"}, {"freebsd", "freebsd"}, + {"openbsd", "openbsd"}, {"netbsd", "netbsd"}, {"linux", "linux"}}; + size_t i; + for (i = 0; system && i < sizeof systems / sizeof *systems; ++i) + if (has_word(system, systems[i].word)) return systems[i].os; + return "unknown"; +} + +/* ---- the lines ---- */ + +/* the forms a report line comes in */ +enum { FORM_SCARLETNX = 1, FORM_EDEN, FORM_REPORT }; +static const char* find_in(const char* s, size_t n, const char* lit); +/* the report line's JSON object in a line of the n bytes at s: after "[game] " (ScarletNX), after Eden's + "Debug.Emulated file:line:function: ", or the line itself (report.jsonl), its form in *form. Its offset, or + -1 for none */ +static long json_at(const char* s, size_t n, int* form) { + size_t i = tr_stamp(s, n); + const char *emulated, *colon; + if (n - i >= 8 && !memcmp(s + i, "[game] {", 8)) { + *form = FORM_SCARLETNX; + return (long)(i + 7); + } + if (i == 0 && n && s[0] == '{') { + *form = FORM_REPORT; + return 0; + } + emulated = find_in(s, n, "Debug.Emulated <"); + colon = emulated ? find_in(emulated, n - (size_t)(emulated - s), ": {") : NULL; + if (!colon) return -1; + *form = FORM_EDEN; + return (long)(colon + 2 - s); +} +/* the line from at: its length without its \r\n, *next the next one's offset */ +static size_t line_of(const char* text, size_t n, size_t at, size_t* next) { + const char* nl = memchr(text + at, '\n', n - at); + size_t len = nl ? (size_t)(nl - (text + at)) : n - at; + *next = at + len + (nl != NULL); + if (len && text[at + len - 1] == '\r') --len; + return len; +} +/* the object at s, n bytes, when it is one of edenprobe's lines ({"type":...}); owned, NULL else */ +static cJSON* report_line(const char* s, size_t n) { + cJSON* o; + if (n < 10 || memcmp(s, "{\"type\":\"", 9)) return NULL; + o = cJSON_ParseWithLength(s, n); + if (!cJSON_IsObject(o) || !jstr(o, "type")) { + cJSON_Delete(o); + return NULL; + } + return o; +} + +/* the note that begins a run: "edenprobe 0.9.0 (v0.9.0) starting", its version and describe owned when wanted */ +static int starting(const cJSON* o, char** version, char** describe) { + const char *t = jstr(o, "text"), *open, *close; + size_t n; + if (!t || strcmp(jstr(o, "type"), "note") || strncmp(t, "edenprobe ", 10)) return 0; + n = strlen(t); + if (n < 21 || strcmp(t + n - 10, ") starting")) return 0; + open = strstr(t + 10, " ("); + close = t + n - 10; + if (!open || open > close || open == t + 10) return 0; + if (version) *version = rei_format("%.*s", (int)(open - (t + 10)), t + 10); + if (describe) *describe = rei_format("%.*s", (int)(close - (open + 2)), open + 2); + return 1; +} + +char* probe_cut(const char* text, size_t n, size_t* size, int* cases, int* notes) { + Buf b = {0}; + size_t at = 0, next; + *cases = *notes = 0; + while (at < n) { + size_t len = line_of(text, n, at, &next), whole = next - at; + int form = 0; + long j = json_at(text + at, len, &form); + cJSON* o = j >= 0 ? report_line(text + at + j, len - (size_t)j) : NULL; + int changed = 0; + if (o && !strcmp(jstr(o, "type"), "case") && !probe_keeps_detail(jstr(o, "suite")) && jstr(o, "detail") && + *jstr(o, "detail")) { + cJSON_ReplaceItemInObjectCaseSensitive(o, "detail", cJSON_CreateString("")); + ++*cases; + changed = 1; + } else if (o && !strcmp(jstr(o, "type"), "note") && jstr(o, "text") && !strncmp(jstr(o, "text"), "net:", 4)) { + cJSON_ReplaceItemInObjectCaseSensitive( + o, "text", + cJSON_CreateString("net: left out by Tracer, as the net family's notes name the player's sessions, " + "accounts and servers")); + ++*notes; + changed = 1; + } + if (changed) { + char* line = cJSON_PrintUnformatted(o); + buf_addn(&b, text + at, (size_t)j); + buf_add(&b, line ? line : "{}"); + buf_addn(&b, text + at + len, whole - len); /* its \r\n as it was */ + free(line); + } else + buf_addn(&b, text + at, whole); + cJSON_Delete(o); + at = next; + } + *size = b.len; + return buf_take(&b); +} + +int probe_marks(const char* text, size_t n) { + size_t at = 0, next; + int marks = 0; + while (at < n) { + size_t len = line_of(text, n, at, &next); + int form = 0; + long j = json_at(text + at, len, &form); + if (j >= 0 && len - (size_t)j > 30) { + const char* s = text + at + j; + size_t k = len - (size_t)j; + if (k > 35 && !memcmp(s, "{\"type\":\"note\",\"text\":\"edenprobe ", 33)) { + cJSON* o = report_line(s, k); + if (o && starting(o, NULL, NULL)) marks = 1; + cJSON_Delete(o); + } else if (marks && !memcmp(s, "{\"type\":\"summary\"", 17)) + marks = 2; + } + at = next; + } + return marks; +} + +/* ---- a run ---- */ + +void probe_free(Probe* p) { + int i; + free(p->emulator); + free(p->emulator_version); + free(p->commit); + free(p->version); + free(p->describe); + free(p->words); + free(p->system); + free(p->os); + free(p->gpu); + free(p->device); + free(p->driver_name); + free(p->driver_info); + free(p->driver_text); + free(p->vulkan); + free(p->extensions); + for (i = 0; i < p->ncases; ++i) { + free(p->cases[i].suite); + free(p->cases[i].name); + free(p->cases[i].tier); + free(p->cases[i].result); + free(p->cases[i].reason); + free(p->cases[i].detail); + } + free(p->cases); + memset(p, 0, sizeof *p); +} + +static void replace(char** field, const char* s, size_t n) { + free(*field); + while (n && isspace((unsigned char)s[n - 1])) --n; + *field = rei_format("%.*s", (int)n, s); +} +static int starts(const char* s, size_t n, const char* lit) { + size_t k = strlen(lit); + return n >= k && !memcmp(s, lit, k); +} +static const char* find_in(const char* s, size_t n, const char* lit) { + size_t k = strlen(lit), i; + for (i = 0; i + k <= n; ++i) + if (!memcmp(s + i, lit, k)) return s + i; + return NULL; +} +/* a YYYY-MM-DD day as seconds since the epoch (UTC), 0 for text that is none */ +static double day_of(const char* s, size_t n) { + int y, m, d, k; + if (n < 10) return 0; + for (k = 0; k < 10; ++k) + if ((k == 4 || k == 7) ? s[k] != '-' : !isdigit((unsigned char)s[k])) return 0; + y = atoi(s); + m = atoi(s + 5); + d = atoi(s + 8); + if (m < 1 || m > 12 || d < 1 || d > 31 || y < 1970) return 0; + { /* days from the civil date (Howard Hinnant's), so no time zone or timegm is needed */ + long yy = y - (m <= 2), era = (yy >= 0 ? yy : yy - 399) / 400, yoe = yy - era * 400; + long doy = (153 * (m + (m > 2 ? -3 : 9)) + 2) / 5 + d - 1, doe = yoe * 365 + yoe / 4 - yoe / 100 + doy; + return (double)(era * 146097 + doe - 719468) * 86400.0; + } +} + +/* a ScarletNX header line of the n bytes at s (its time stamp left out), into p */ +static void scarletnx_line(Probe* p, const char* s, size_t n) { + const char* v; + if (starts(s, n, "system: ")) { + replace(&p->system, s + 8, n - 8); + return; + } + if (starts(s, n, "build: ScarletNX ")) { /* "build: ScarletNX [, committed ] (...)" */ + const char *b = s + 17, *sp = memchr(b, ' ', n - 17), *end, *at; + if (!sp) return; + end = find_in(sp + 1, n - (size_t)(sp + 1 - s), " ("); + if (!end) return; + at = find_in(sp + 1, (size_t)(end - (sp + 1)), ", committed "); + free(p->emulator_version); + p->emulator_version = rei_format("%.*s %.*s", (int)(sp - b), b, (int)((at ? at : end) - (sp + 1)), sp + 1); + replace(&p->commit, sp + 1, (size_t)((at ? at : end) - (sp + 1))); + p->built = at ? day_of(at + 12, (size_t)(end - (at + 12))) : 0; + return; + } + if (starts(s, n, "vulkan: the driver that runs: ")) { /* ", (driver ID )[, device :]" */ + const char *b = s + 30, *comma = find_in(b, n - 30, ", "), *id = find_in(b, n - 30, " (driver ID "), *dev; + if (!comma || !id || comma > id) return; + replace(&p->driver_name, b, (size_t)(comma - b)); + replace(&p->driver_info, comma + 2, (size_t)(id - (comma + 2))); + p->driver_id = atoi(id + 12); + p->inferred = 0; + dev = find_in(id, n - (size_t)(id - s), "), device "); + if (dev) replace(&p->device, dev + 10, n - (size_t)(dev + 10 - s)); + return; + } + if (starts(s, n, "vulkan: optional extensions on: ")) { /* ", ; banned here: ..." */ + const char *b = s + 32, *end = find_in(b, n - 32, "; "); + replace(&p->extensions, b, end ? (size_t)(end - b) : n - 32); + return; + } + if (starts(s, n, "vulkan: ") && (v = find_in(s, n, ", Vulkan ")) != NULL) { /* ", Vulkan , driver " */ + const char* d = find_in(v + 9, n - (size_t)(v + 9 - s), ", driver "); + const char *hex, *h; + if (!d) return; + replace(&p->gpu, s + 8, (size_t)(v - (s + 8))); + replace(&p->vulkan, v + 9, (size_t)(d - (v + 9))); + hex = d + 9; + for (h = hex; h < s + n && isxdigit((unsigned char)*h); ++h) continue; + if (h > hex && h - hex <= 8) p->driver_version = strtoul(hex, NULL, 16); + } +} +/* an Eden log line of the n bytes at s (its time stamp left out), " file:line:function: ", + into p */ +static void eden_line(Probe* p, const char* s, size_t n) { + const char* msg = find_in(s, n, "> "); + msg = msg ? find_in(msg, n - (size_t)(msg - s), ": ") : NULL; + if (!msg) return; + msg += 2; + n -= (size_t)(msg - s); + if (starts(msg, n, "Driver: ")) { /* driverName then its version, as Eden numbers it */ + const char* last = msg + n; + while (last > msg + 8 && last[-1] != ' ') --last; + if (last == msg + 8) return; + replace(&p->driver_name, msg + 8, (size_t)(last - 1 - (msg + 8))); + replace(&p->driver_info, last, (size_t)(msg + n - last)); + p->driver_id = probe_driver_of_name(p->driver_name); + p->inferred = 1; + } else if (starts(msg, n, "Device: ")) + replace(&p->gpu, msg + 8, n - 8); + else if (starts(msg, n, "Vulkan: ")) + replace(&p->vulkan, msg + 8, n - 8); + else if (starts(msg, n, "Eden Version: ")) { + replace(&p->emulator_version, msg + 14, n - 14); + if (find_in(msg + 14, n - 14, "rEden")) { /* rEden logs as Eden does, its build named in this line */ + free(p->emulator); + p->emulator = rei_strdup("rEden"); + } + } else if (starts(msg, n, "Host OS: ")) { + char* was = p->system; + p->system = rei_format("%.*s", (int)(n - 9), msg + 9); + free(was); + } +} +/* a machine line of the n bytes at s, of a log of the form, into p */ +static void machine_line(Probe* p, int form, const char* s, size_t n) { + size_t i = tr_stamp(s, n); + if (form == FORM_EDEN) + eden_line(p, s + i, n - i); + else + scarletnx_line(p, s + i, n - i); +} + +/* the words of a mode note: "mode: quick, from the mode file; pictures of failures only; families cpu graphics; no + timing passes; ..." as "cpu graphics notime" */ +static char* words_of(const char* note) { + Buf b = {0}; + const char *s = note, *fam = strstr(note, "; families "); + int fatal = 0, hang = 0, notime = 0, retry = 0, stress = 0; + long frames = 0; + if (fam) { + const char* end = strchr(fam + 11, ';'); + size_t n = end ? (size_t)(end - (fam + 11)) : strlen(fam + 11); + if (n != 4 || memcmp(fam + 11, "none", 4)) buf_addn(&b, fam + 11, n); + } + while ((s = strstr(s, "; ")) != NULL) { + s += 2; + fatal |= !strncmp(s, "the cases that may crash", 24); + hang |= !strncmp(s, "the cases that hang", 19); + notime |= !strncmp(s, "no timing passes", 16); + retry |= !strncmp(s, "the crash list's cases again", 28); + stress |= !strncmp(s, "stress cases", 12); + if (!strncmp(s, "frames ", 7)) frames = strtol(s + 7, NULL, 10); + } + if (fatal) buf_printf(&b, "%sfatal", b.len ? " " : ""); + if (frames > 0) buf_printf(&b, "%sframes=%ld", b.len ? " " : "", frames); + if (hang) buf_printf(&b, "%shang", b.len ? " " : ""); + if (notime) buf_printf(&b, "%snotime", b.len ? " " : ""); + if (retry) buf_printf(&b, "%sretry", b.len ? " " : ""); + if (stress) buf_printf(&b, "%sstress", b.len ? " " : ""); + return buf_take(&b); +} + +static char* cut_text(const char* s, size_t max) { + size_t n = strlen(s); + if (n > max) { + n = max; + while (n && ((unsigned char)s[n] & 0xc0) == 0x80) --n; + } + return rei_format("%.*s", (int)n, s); +} +/* a word of edenprobe's (a suite, a tier, a result, a reason): letters, digits, '-' and spaces, 1 to max bytes */ +static int word(const char* s, size_t max) { + size_t n = s ? strlen(s) : 0, i; + if (!n || n > max) return 0; + for (i = 0; i < n; ++i) + if (!isalnum((unsigned char)s[i]) && s[i] != '-' && s[i] != ' ' && s[i] != '_') return 0; + return 1; +} +/* case o into p, in place of one of the same suite and name: 0, or -1 for a case line that is not one */ +static int add_case(Probe* p, const cJSON* o, int* cap) { + const char *suite = jstr(o, "suite"), *name = jstr(o, "name"), *tier = jstr(o, "tier"), *result = jstr(o, "result"), + *reason = jstr(o, "reason"), *detail = jstr(o, "detail"); + const cJSON* us = cJSON_GetObjectItemCaseSensitive(o, "us"); + ProbeCase* c; + int i; + if (!word(suite, 32) || !name || !*name || strlen(name) > 512 || (tier && !word(tier, 16)) || !result || + (strcmp(result, "pass") && strcmp(result, "fail") && strcmp(result, "skip")) || + (reason && *reason && !word(reason, 32))) + return -1; + for (i = 0; i < p->ncases; ++i) /* a line again (two copies of one run): the later one */ + if (!strcmp(p->cases[i].suite, suite) && !strcmp(p->cases[i].name, name)) break; + if (i == p->ncases) { + if (p->ncases == PROBE_CASES) { + ++p->over; + return 0; + } + if (p->ncases == *cap) { + *cap = *cap ? *cap * 2 : 256; + p->cases = realloc(p->cases, (size_t)*cap * sizeof *p->cases); + if (!p->cases) { + fputs(REI_NAME ": out of memory\n", stderr); + abort(); + } + } + memset(&p->cases[p->ncases++], 0, sizeof *p->cases); + } else { + free(p->cases[i].suite); + free(p->cases[i].name); + free(p->cases[i].tier); + free(p->cases[i].result); + free(p->cases[i].reason); + free(p->cases[i].detail); + } + c = &p->cases[i]; + c->suite = rei_strdup(suite); + c->name = rei_strdup(name); + c->tier = rei_strdup(tier ? tier : "none"); + c->result = rei_strdup(result); + c->reason = rei_strdup(reason ? reason : ""); + c->detail = cut_text(detail ? detail : "", PROBE_DETAIL); + c->us = cJSON_IsNumber(us) && us->valuedouble >= 0 ? us->valuedouble : -1; + return 0; +} + +int probe_parse(const char* text, size_t n, Probe* p, char** why) { + size_t at = 0, next, start = 0, end = n, run_start = 0, run_end = n; + int runs = 0, chosen_whole = 0, lines = 0, resumed = 0, cap = 0, open_run = 0, open_whole = 0, open_form = 0, + chosen_form = 0; + *why = NULL; + memset(p, 0, sizeof *p); + /* the runs: each from its starting note to the next one; the last whole one, else the last one */ + while (at < n) { + size_t len = line_of(text, n, at, &next); + int form = 0; + long j = json_at(text + at, len, &form); + cJSON* o = j >= 0 ? report_line(text + at + j, len - (size_t)j) : NULL; + if (o) { + const char* type = jstr(o, "type"); + ++lines; + if (starting(o, NULL, NULL)) { + if (open_run && (open_whole || !chosen_whole)) { + run_start = start; + run_end = at; + chosen_whole = open_whole; + chosen_form = open_form; + } + open_run = 1; + open_whole = 0; + open_form = form; + start = at; + ++runs; + } else if (!strcmp(type, "summary")) + open_whole = open_run; + else if (!open_run && !strcmp(type, "note") && jstr(o, "text") && + !strncmp(jstr(o, "text"), "journal: launch ", 16)) + resumed = 1; + } + cJSON_Delete(o); + at = next; + } + if (open_run && (open_whole || !chosen_whole)) { + run_start = start; + run_end = n; + chosen_whole = open_whole; + chosen_form = open_form; + } + if (!runs) { + if (lines && resumed) { + *why = rei_strdup("its edenprobe lines are a launch that went on with a run after a crash (its first note " + "says \"journal: launch\"), without the run's start: send the run's report.jsonl, or the " + "log of the run's first launch"); + return -1; + } + return 0; + } + start = run_start; + end = run_end; + p->passed = p->failed = p->skipped = p->crashed = -1; + p->whole = chosen_whole; + /* the emulator by the form its run's lines come in: a report.jsonl alone names no machine, the console's + reference */ + p->emulator = rei_strdup(chosen_form == FORM_SCARLETNX ? "ScarletNX" + : chosen_form == FORM_EDEN ? "Eden" + : "console"); + /* the machine: the lines before the run's start, the last of each; a report.jsonl's has none */ + for (at = 0; chosen_form != FORM_REPORT && at < start; at = next) { + size_t len = line_of(text, n, at, &next); + if (len) machine_line(p, chosen_form, text + at, len); + } + p->os = rei_strdup(probe_os(p->system)); + if (p->driver_id && !p->driver_version && p->driver_info && strcmp(p->emulator, "ScarletNX")) + probe_version_parse(p->driver_id, p->driver_info, &p->driver_version); /* Eden's, as its vendor numbers it */ + if (p->driver_id && p->driver_version) { /* ScarletNX logs driverVersion as it is, in hex */ + char v[32]; + probe_version_text(p->driver_id, p->driver_version, v, sizeof v); + p->driver_text = rei_strdup(v); + } + /* the run's lines */ + for (at = start; at < end; at = next) { + size_t len = line_of(text, n, at, &next); + int form = 0; + long j = json_at(text + at, len, &form); + cJSON* o = j >= 0 ? report_line(text + at + j, len - (size_t)j) : NULL; + const char* type = o ? jstr(o, "type") : NULL; + if (!o) continue; + if (starting(o, &p->version, &p->describe)) + ; + else if (!strcmp(type, "case")) { + if (add_case(p, o, &cap)) ++p->unread; + } else if (!strcmp(type, "summary")) { + p->passed = (long)jnum(o, "passed"); + p->failed = (long)jnum(o, "failed"); + p->skipped = (long)jnum(o, "skipped"); + p->crashed = (long)jnum(o, "crashed"); + } else if (!strcmp(type, "note")) { + const char* t = jstr(o, "text"); + if (t && !strncmp(t, "mode: ", 6) && !p->words) p->words = words_of(t); + } else if (strcmp(type, "perf") && strcmp(type, "baseline") && strcmp(type, "baseline_summary")) + ++p->unread; + cJSON_Delete(o); + } + if (!p->words) p->words = rei_strdup(""); + return 1; +} + +/* ---- as JSON ---- */ + +static void put_number(cJSON* o, const char* key, double v) { cJSON_AddNumberToObject(o, key, v); } + +cJSON* probe_json(const Probe* p) { + cJSON *o = cJSON_CreateObject(), *list; + int i; + jset(o, "emulator", p->emulator); + jset(o, "emulator_version", p->emulator_version); + jset(o, "commit", p->commit); + put_number(o, "built", p->built); + jset(o, "version", p->version); + jset(o, "describe", p->describe); + jset(o, "words", p->words); + jset(o, "system", p->system); + jset(o, "os", p->os); + jset(o, "gpu", p->gpu); + jset(o, "device", p->device); + jset(o, "driver_name", p->driver_name); + jset(o, "driver_info", p->driver_info); + put_number(o, "driver_id", p->driver_id); + cJSON_AddBoolToObject(o, "inferred", p->inferred); + put_number(o, "driver_version", (double)p->driver_version); + jset(o, "driver_text", p->driver_text); + jset(o, "vulkan", p->vulkan); + jset(o, "extensions", p->extensions); + put_number(o, "passed", (double)p->passed); + put_number(o, "failed", (double)p->failed); + put_number(o, "skipped", (double)p->skipped); + put_number(o, "crashed", (double)p->crashed); + cJSON_AddBoolToObject(o, "whole", p->whole); + put_number(o, "cut_cases", p->cut_cases); + put_number(o, "cut_notes", p->cut_notes); + put_number(o, "unread", p->unread); + put_number(o, "over", p->over); + list = cJSON_AddArrayToObject(o, "cases"); + for (i = 0; i < p->ncases; ++i) { + const ProbeCase* c = &p->cases[i]; + cJSON* e = cJSON_CreateObject(); + jset(e, "suite", c->suite); + jset(e, "name", c->name); + jset(e, "tier", c->tier); + jset(e, "result", c->result); + if (*c->reason) jset(e, "reason", c->reason); + if (*c->detail) jset(e, "detail", c->detail); + if (c->us >= 0) put_number(e, "us", c->us); + cJSON_AddItemToArray(list, e); + } + return o; +} + +/* key's string of o, cut to max bytes, owned; NULL when o has none */ +static char* field(const cJSON* o, const char* key, size_t max) { + const char* s = jstr(o, key); + return s ? cut_text(s, max) : NULL; +} +static long count_of(const cJSON* o, const char* key) { + const cJSON* v = cJSON_GetObjectItemCaseSensitive(o, key); + double d = cJSON_IsNumber(v) ? v->valuedouble : -1; + return d < 0 || d > 1e7 ? -1 : (long)d; +} + +int probe_of_json(const cJSON* o, Probe* p, char** why) { + const cJSON *list = cJSON_GetObjectItemCaseSensitive(o, "cases"), *e; + const char* emulator = jstr(o, "emulator"); + int cap = 0; + double id = jnum(o, "driver_id"), version = jnum(o, "driver_version"); + *why = NULL; + memset(p, 0, sizeof *p); + if (!cJSON_IsObject(o) || !emulator || + (strcmp(emulator, "ScarletNX") && strcmp(emulator, "Eden") && strcmp(emulator, "rEden") && + strcmp(emulator, "console"))) { + *why = rei_format("its probe names no emulator it may (%.40s)", emulator ? emulator : "none"); + return -1; + } + if (!jstr(o, "version") || !*jstr(o, "version") || strlen(jstr(o, "version")) > 40 || !jstr(o, "words") || + !cJSON_IsArray(list) || id < 0 || id >= DRIVERS || version < 0 || version > 4294967295.0) { + *why = rei_strdup("its probe has no edenprobe version, mode or cases, or a driver that is none"); + return -1; + } + p->emulator = rei_strdup(emulator); + p->emulator_version = field(o, "emulator_version", 200); + p->commit = field(o, "commit", 64); + p->built = jnum(o, "built") > 0 ? jnum(o, "built") : 0; + p->version = field(o, "version", 40); + p->describe = field(o, "describe", 80); + p->words = field(o, "words", 200); + p->system = field(o, "system", 300); + p->os = rei_strdup(probe_os(p->system)); /* drawn again here, not taken from the answer */ + p->gpu = field(o, "gpu", 200); + p->device = field(o, "device", 20); + p->driver_name = field(o, "driver_name", 120); + p->driver_info = field(o, "driver_info", 200); + p->driver_id = (int)id; + p->inferred = jbool(o, "inferred"); + p->driver_version = (unsigned long)version; + if (p->driver_id && p->driver_version) { /* drawn again too */ + char text[32]; + probe_version_text(p->driver_id, p->driver_version, text, sizeof text); + p->driver_text = rei_strdup(text); + } + p->vulkan = field(o, "vulkan", 40); + p->extensions = field(o, "extensions", 4000); + p->passed = count_of(o, "passed"); + p->failed = count_of(o, "failed"); + p->skipped = count_of(o, "skipped"); + p->crashed = count_of(o, "crashed"); + p->whole = jbool(o, "whole"); + p->cut_cases = (int)(count_of(o, "cut_cases") > 0 ? count_of(o, "cut_cases") : 0); + p->cut_notes = (int)(count_of(o, "cut_notes") > 0 ? count_of(o, "cut_notes") : 0); + p->unread = (int)(count_of(o, "unread") > 0 ? count_of(o, "unread") : 0); + p->over = (int)(count_of(o, "over") > 0 ? count_of(o, "over") : 0); + cJSON_ArrayForEach(e, list) { + if (add_case(p, e, &cap)) { + *why = rei_format("its probe's case %d is not one edenprobe writes", p->ncases + 1); + probe_free(p); + return -1; + } + if (!probe_keeps_detail(p->cases[p->ncases - 1].suite) && *p->cases[p->ncases - 1].detail) { + *why = rei_format("its probe's case %d keeps a detail of a family that loses it (%s)", p->ncases, + p->cases[p->ncases - 1].suite); + probe_free(p); + return -1; + } + } + return 0; +} + +/* ---- marks and words ---- */ + +typedef struct { + unsigned long long h; +} Fnv; +static void fnv(Fnv* f, const char* s) { + for (; s && *s; ++s) f->h = (f->h ^ (unsigned char)*s) * 1099511628211ULL; + f->h = (f->h ^ 0x1f) * 1099511628211ULL; /* a separator, so "ab"+"c" is not "a"+"bc" */ +} + +void probe_digest(const Probe* p, char out[17]) { + Fnv f = {14695981039346656037ULL}; + char num[32]; + int i; + const char* fields[] = {p->emulator, p->emulator_version, p->version, p->words, p->system, + p->gpu, p->driver_name, p->driver_info}; + size_t k; + for (k = 0; k < sizeof fields / sizeof *fields; ++k) fnv(&f, fields[k]); + snprintf(num, sizeof num, "%d %lu %ld %ld %ld %ld", p->driver_id, p->driver_version, p->passed, p->failed, + p->skipped, p->crashed); + fnv(&f, num); + for (i = 0; i < p->ncases; ++i) { + const ProbeCase* c = &p->cases[i]; + fnv(&f, c->suite); + fnv(&f, c->name); + fnv(&f, c->result); + fnv(&f, c->reason); + fnv(&f, c->detail); + snprintf(num, sizeof num, "%.0f", c->us); + fnv(&f, num); + } + snprintf(out, 17, "%016llx", f.h); +} + +void probe_case_key(const char* suite, const char* name, char out[17]) { + Fnv f = {14695981039346656037ULL}; + fnv(&f, suite); + fnv(&f, name); + snprintf(out, 17, "%016llx", f.h); +} + +char* probe_counts(const Probe* p) { + long passed = 0, failed = 0, skipped = 0, crashed = 0; + Buf b = {0}; + int i, k, nsuites = 0, shown; + struct { + const char* suite; + int fails; + } suites[64]; + int more = 0; + for (i = 0; i < p->ncases; ++i) { + const ProbeCase* c = &p->cases[i]; + if (!strcmp(c->result, "pass")) + ++passed; + else if (!strcmp(c->result, "fail")) { + ++failed; + for (k = 0; k < nsuites && strcmp(suites[k].suite, c->suite); ++k) continue; + if (k == nsuites && nsuites < 64) { + suites[nsuites].suite = c->suite; + suites[nsuites++].fails = 0; + } else if (k == nsuites) + continue; + ++suites[k].fails; + } else if (!strcmp(c->reason, "crashed")) + ++crashed; + else + ++skipped; + } + if (p->passed >= 0) { /* the summary's own counts, when it has them */ + passed = p->passed; + failed = p->failed; + skipped = p->skipped; + crashed = p->crashed; + } + for (i = 1; i < nsuites; ++i) /* the most failures first, then by name */ + for (k = i; + k > 0 && (suites[k].fails > suites[k - 1].fails || + (suites[k].fails == suites[k - 1].fails && strcmp(suites[k].suite, suites[k - 1].suite) < 0)); + --k) { + const char* s = suites[k].suite; + int f = suites[k].fails; + suites[k] = suites[k - 1]; + suites[k - 1].suite = s; + suites[k - 1].fails = f; + } + buf_printf(&b, "%ld passed, %ld failed", passed, failed); + shown = nsuites < 8 ? nsuites : 8; + for (i = 0; i < shown; ++i) buf_printf(&b, "%s%s %d", i ? ", " : " (", suites[i].suite, suites[i].fails); + more = nsuites - shown; + if (more) buf_printf(&b, " and %d more suite%s", more, more == 1 ? "" : "s"); + if (shown) buf_add(&b, ")"); + buf_printf(&b, ", %ld skipped, %ld crashed", skipped, crashed); + return buf_take(&b); +} + +static const char* os_label(const char* os) { + static const char* const names[][2] = {{"android", "Android"}, {"windows", "Windows"}, {"macos", "macOS"}, + {"ios", "iOS"}, {"freebsd", "FreeBSD"}, {"openbsd", "OpenBSD"}, + {"netbsd", "NetBSD"}, {"linux", "Linux"}}; + size_t i; + for (i = 0; os && i < sizeof names / sizeof *names; ++i) + if (!strcmp(names[i][0], os)) return names[i][1]; + return "system unknown"; +} +char* probe_machine(const Probe* p) { + Buf b = {0}; + if (!strcmp(p->emulator, "console") && !p->driver_name) + return rei_strdup("the console (a report.jsonl alone names no machine)"); + if (p->driver_name) { + buf_add(&b, p->driver_name); + if (p->driver_info) buf_printf(&b, "%s%s", strcmp(p->emulator, "ScarletNX") ? " " : ", ", p->driver_info); + } else + buf_add(&b, "a driver its log does not name"); + if (p->inferred) buf_add(&b, p->driver_id ? ", driver ID inferred" : ", driver ID unknown"); + buf_printf(&b, " (%s)", os_label(p->os)); + return buf_take(&b); +} diff --git a/tracer/src/probe.h b/tracer/src/probe.h new file mode 100644 index 0000000..68edb4b --- /dev/null +++ b/tracer/src/probe.h @@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + Copyright 2026 the ScarletNX contributors */ +/* A run of edenprobe (github.com/scarletnx/edenprobe, the probe program that checks an emulator against the console) + found in a file a report brought, in any of the three forms one comes in: + - ScarletNX's log of the run: the machine in its header lines, each line of the report as "[game] {...}"; + - Eden's log (rEden's too): the machine in its "Driver:", "Device:", "Host OS:" lines, each line of the report as + "Debug.Emulated ...: {...}" (the debug string service, svc_debug_string.cpp); + - the report itself, report.jsonl, a JSON object a line, which names no machine: the console's reference. + A run begins at its note "edenprobe 0.9.0 (v0.9.0) starting" and ends at its summary. What is read of it: the + machine (system, GPU, the driver's VkDriverId, name and version), the emulator and its build, edenprobe's version and + mode, and each case's suite, name, tier, result, reason and detail. + The detail of the cases of edenprobe's service, net and pad families, and the net family's notes, can name the + player (an account's id and nickname, a network's addresses, a session); probe_cut leaves them out of the text before + it is kept or read. The driver's names and version numbering are ScarletNX's ban table's (extension_bans.c) */ +#ifndef TR_PROBE_H +#define TR_PROBE_H +#include "tracer.h" + +#define PROBE_CASES 10000 /* the case lines one run keeps at most: a full run has about 2000 */ +#define PROBE_DETAIL 300 /* the bytes of a case's detail kept */ +#define PROBE_KEY "probe" /* the reports' key (store.h's game) of a report that is a run of edenprobe */ + +/* edenprobe's families, as its ui.c groups the suites (FAMILIES, edenprobe 86e1d11) */ +typedef enum { + PROBE_JUDGE, + PROBE_CPU, + PROBE_PAD, + PROBE_GRAPHICS, + PROBE_FS, + PROBE_KERNEL, + PROBE_DISPLAY, + PROBE_VIDEO, + PROBE_AUDIO, + PROBE_SERVICE, + PROBE_NET, + PROBE_GAME, + PROBE_OTHER +} ProbeFamily; +ProbeFamily probe_family(const char* suite); +/* the family's name: "judge", "graphics", ... "other" */ +const char* probe_family_name(ProbeFamily f); +/* whether a case of suite keeps its detail: the families whose cases name nothing of the player (the judge, cpu, + graphics, fs, kernel, display, video, audio, game). service, net and pad lose it, and so does a suite edenprobe's + table does not have, as nothing says what it holds */ +int probe_keeps_detail(const char* suite); + +/* the ban table's name of a VkDriverId ("radv", "nvidia"), NULL for one it has none for; its label ("RADV", "NVIDIA's + driver"); the VkDriverId of a table's name, 0 for none */ +const char* probe_driver_name(int id); +const char* probe_driver_label(int id); +int probe_driver_id(const char* name); +/* the VkDriverId a driver's own name (VkPhysicalDeviceDriverProperties.driverName, as Eden's log says it) points at: + "radv" 3, "NVIDIA" 4, "Qualcomm Technologies Inc. Adreno Vulkan Driver" 8, ... 0 for one it knows nothing of. An + inference: Eden logs no driver ID */ +int probe_driver_of_name(const char* driver_name); +/* driverVersion v of a driver of VkDriverId id as its vendor numbers it, into out: NVIDIA's 580.119.02, Intel's Windows + 101.4502, MoltenVK's 1.2.11, any other's as a Vulkan version (Mesa's 26.1.8) */ +void probe_version_text(int id, unsigned long v, char* out, size_t n); +/* text as a version of a driver of VkDriverId id, in that numbering, into *v: 1, or 0 for text that is none */ +int probe_version_parse(int id, const char* text, unsigned long* v); + +/* the system's family from a log's system line or Eden's Host OS: "android", "windows", "macos", "ios", "freebsd", + "openbsd", "netbsd", "linux" (the ban table's names), or "unknown" */ +const char* probe_os(const char* system); + +/* the n bytes of text with the detail of each case of a family probe_keeps_detail refuses emptied, and the text of + each note of the net family ("net: ...") said to be left out: owned, its length in *size, and how many of each were + cut in *cases and *notes. Every other byte stays as it is */ +char* probe_cut(const char* text, size_t n, size_t* size, int* cases, int* notes); + +/* what text holds of a run: 0 nothing, 1 a run's start, 2 a run's start and a summary after it */ +int probe_marks(const char* text, size_t n); + +typedef struct { + char *suite, *name, *tier, *result, *reason, *detail; /* owned; reason and detail "" for none */ + double us; /* the time it took, -1 for none */ +} ProbeCase; + +typedef struct { + char* emulator; /* "ScarletNX", "Eden", "rEden", or "console" for a report.jsonl alone */ + char* emulator_version; /* its build: "main 3e7ffeb", "Eden Development Build | master-abc"; NULL for none */ + char* commit; /* ScarletNX's commit, NULL for none */ + double built; /* the day that commit was made (UTC, seconds since the epoch), 0 for none */ + char *version, *describe; /* edenprobe's: "0.9.0", "v0.9.0" */ + char* words; /* what ran, from its mode note: the families, then fatal, hang, notime, retry, stress, frames=N */ + char* system; /* the machine's system line; NULL for none */ + char* os; /* probe_os's */ + char* gpu; /* the GPU's name, NULL for none */ + char* device; /* vendorID:deviceID ("1002:73df"), NULL where the log does not say */ + char* driver_name; /* driverName, NULL for none */ + char* driver_info; /* driverInfo ("Mesa 26.1.8"), NULL for none */ + int driver_id; /* VkDriverId, 0 for none */ + int inferred; /* the driver ID is probe_driver_of_name's, not the log's */ + unsigned long driver_version; /* driverVersion, 0 for none */ + char* driver_text; /* it as its vendor numbers it ("26.1.8"), NULL for none */ + char* vulkan; /* the device's Vulkan version, NULL for none */ + char* extensions; /* the optional extensions on, as the log's line lists them (comma separated), NULL for none */ + long passed, failed, skipped, crashed; /* the summary's counts, -1 each without one */ + int whole; /* the run has its summary */ + int cut_cases, cut_notes; /* the details and the net notes probe_cut left out */ + int unread; /* report lines that were no case, note or summary edenprobe writes */ + int over; /* case lines past PROBE_CASES, not kept */ + ProbeCase* cases; + int ncases; +} Probe; + +/* the last whole run in the n bytes of text (else the last run begun), as probe_cut left it, into *p, with the + machine its log names before the run begins (the last of each line). 1 for a run, 0 for none, -1 for report lines + with no run's start in front of them (a launch that went on with a run after a crash, which says so in its first + note): *why (owned) says which */ +int probe_parse(const char* text, size_t n, Probe* p, char** why); +void probe_free(Probe* p); + +/* p as JSON, for the worker's answer and the site; owned */ +cJSON* probe_json(const Probe* p); +/* p from JSON a worker answered, each field checked as what strangers send is: 0, or -1 with why (owned) */ +int probe_of_json(const cJSON* o, Probe* p, char** why); + +/* the run's mark: FNV-1a over its machine, emulator, version, words and every case as kept, 16 hex digits (out holds + 17 bytes). Two runs with the same lines have the same */ +void probe_digest(const Probe* p, char out[17]); +/* a case's mark, FNV-1a of its suite and name, 16 hex digits: its page's name (out holds 17 bytes) */ +void probe_case_key(const char* suite, const char* name, char out[17]); +/* the counts as the reply says them: "1034 passed, 26 failed (astc 15, astcimage 9, tex8k 2), 6 skipped, 3 crashed", + the failed suites most first, eight at most and how many more; owned */ +char* probe_counts(const Probe* p); +/* the machine as the reply says it: "radv, Mesa 26.1.8 (Linux)", "Nvidia 580.95.05, driver ID inferred (Windows)"; + owned */ +char* probe_machine(const Probe* p); +#endif diff --git a/tracer/src/report.c b/tracer/src/report.c index e264707..17be869 100644 --- a/tracer/src/report.c +++ b/tracer/src/report.c @@ -236,6 +236,9 @@ static cJSON* help(void) { "Mention me with a ScarletNX log attached (.log, .txt, .gz or .zip), and screenshots if you have " "them. I keep them as a report on the site, grouped by game. The log says which game it is: when it " "does not, write the game's name in the message.\n\n" + "A run of edenprobe is a report of its own, apart from the games: ScarletNX's log of the run (alone, or in " + "the Share Log zip), Eden's log of it, or its report.jsonl (the console's, as it names no machine). The " + "detail of its service, net and pad cases is left out, as it can name you.\n\n" "Home folders in a log are shown as ~, and screenshots lose their metadata. The site does not show " "who sent a report.\n\n" "To add logs, screenshots or a note to a report, reply to it (or to my answer) and mention me, or write " @@ -302,6 +305,8 @@ void tr_taken_free(Taken* k) { free(k->dir); cJSON_Delete(k->first); buf_free(&k->skipped); + probe_free(&k->probe); + free(k->probe_why); memset(k, 0, sizeof *k); } /* n bytes of data written into the folder dirfd (k->dir) as the next file's, by its name alone, as a worker shut in @@ -331,10 +336,12 @@ static int stash(Taken* k, int dirfd, const char* data, size_t n) { static void take_log(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { Buf text = {0}; - char *why = NULL, *tilded, *shown, *summary; + char *why = NULL, *tilded, *shown, *summary, *cut; size_t n; cJSON* parsed; StFile* f; + Probe probe; + int run, cases, notes, first = !k->logs && !k->logs_had && !k->base; if (tr_unpack(a->name, got->text, got->len, TR_LOG_MAX, &text, &why)) { skip(k, a->name, why); free(why); @@ -352,10 +359,15 @@ static void take_log(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { } shown = tr_public_log(tilded, n, &n); free(tilded); + cut = probe_cut(shown, n, &n, &cases, ¬es); /* what edenprobe's lines would say of the player, out */ + free(shown); + shown = cut; summary = summary_of(shown, n); parsed = summary ? cJSON_Parse(summary) : NULL; - if (!is_log(parsed)) { - skip(k, a->name, "not a ScarletNX log"); + run = probe_parse(shown, n, &probe, &why); + if (!is_log(parsed) && run != 1) { + skip(k, a->name, run < 0 ? why : "not a ScarletNX log, nor a run of edenprobe"); + free(why); cJSON_Delete(parsed); free(summary); free(shown); @@ -363,12 +375,24 @@ static void take_log(Taken* k, int dirfd, const TrAttachment* a, Buf* got) { } if (stash(k, dirfd, shown, n)) { skip(k, a->name, "it could not be written down"); + if (run == 1) probe_free(&probe); + free(why); cJSON_Delete(parsed); free(summary); free(shown); return; } free(shown); + if (first && run == 1) { /* a new report's first log: the report is the run's */ + probe.cut_cases = cases; + probe.cut_notes = notes; + k->probe = probe; + k->probed = 1; + } else { + if (first && run < 0) k->probe_why = rei_format("%s: %s", a->name, why); + if (run == 1) probe_free(&probe); + } + free(why); if (!k->first) k->first = parsed; else @@ -619,6 +643,11 @@ static cJSON* made(Tracer* t, const StReport* r, const Taken* k) { add_field(e, "Not kept", skipped); free(skipped); } + if (k->probe_why) { /* lines of edenprobe that are no whole run: kept as a log, not on the Probe pages */ + char* why = plain(k->probe_why, 1000); + add_field(e, "Not a run of edenprobe", why); + free(why); + } { cJSON* footer = cJSON_AddObjectToObject(e, "footer"); char* how = rei_format("@Tracer delete %ld deletes it", r->id); @@ -693,6 +722,148 @@ static int written(Tracer* t, long id, Taken* k) { return failed ? -1 : 0; } +/* the answer for report r, the run of edenprobe k's first log holds: "edenprobe 0.9.0 on radv, Mesa 26.1.8 (Linux): + 1034 passed, 26 failed (astc 15, ...), 6 skipped, 3 crashed", and what the run lacks or lost said under it */ +static cJSON* probe_made(Tracer* t, const StReport* r, const Taken* k) { + const Probe* p = &k->probe; + char *title = rei_format("Report #%ld: edenprobe %s on %s", r->id, p->version, p->emulator), + *cut = plain(title, 250), *url = rei_format("%s/r/%ld/", t->url, r->id), *machine = probe_machine(p), + *counts = probe_counts(p), *files; + long lines = 0, failed = 0, crashed = 0; + int i; + Buf text = {0}; + cJSON* e; + for (i = 0; i < p->ncases; ++i) { + failed += !strcmp(p->cases[i].result, "fail"); + crashed += !strcmp(p->cases[i].reason, "crashed"); + } + lines = p->ncases + p->over; + buf_printf(&text, "edenprobe %s on %s: %s", p->version, machine, counts); + if (!p->whole) + buf_printf(&text, "\nNo summary line: the run stopped before its end, after %ld case lines.", lines); + else if (p->passed + p->failed + p->skipped + p->crashed != lines) + buf_printf(&text, + "\nThe summary counts %ld cases and the log has %ld case lines: a launch that went on after a " + "crash leaves only its own; the run's report.jsonl has them all.", + p->passed + p->failed + p->skipped + p->crashed, lines); + if (p->over) buf_printf(&text, "\n%d case lines past the first %d were not kept.", p->over, PROBE_CASES); + if (p->unread) + buf_printf(&text, "\n%d of its lines were none that edenprobe writes, and were not read.", p->unread); + if (!strcmp(p->emulator, "console") && !p->driver_name) + buf_add(&text, "\nA report.jsonl names no machine: it is kept as the console's reference. If an emulator ran " + "it, send that emulator's log instead."); + if (p->inferred) + buf_printf(&text, "\n%s logs no driver ID: %s.", p->emulator, + p->driver_id ? "it is read from the driver's name" : "its driver's name says none"); + { + char* said_text = plain(text.text, 3900); + e = embed(cut, said_text, failed || p->failed > 0 ? TONE_BAD : crashed || p->crashed > 0 ? TONE_WARN : TONE_OK); + free(said_text); + } + jset(e, "url", url); + if (p->emulator_version) { + char* build = plain(p->emulator_version, 200); + add_field(e, "Build", build); + free(build); + } + files = kept(k, ""); + add_field(e, "Kept", files); + if (p->cut_cases || p->cut_notes) { + char* left = rei_format("the detail of %d service, net and pad cases and %d net notes, which can name the " + "player", + p->cut_cases, p->cut_notes); + add_field(e, "Left out", left); + free(left); + } + if (k->skipped.len) { + char* skipped = plain(k->skipped.text, 1000); + add_field(e, "Not kept", skipped); + free(skipped); + } + { + cJSON* footer = cJSON_AddObjectToObject(e, "footer"); + char* how = rei_format("@Tracer delete %ld deletes it", r->id); + jset(footer, "text", how); + free(how); + } + buf_free(&text); + free(files); + free(counts); + free(machine); + free(url); + free(cut); + free(title); + return e; +} + +/* the report of k's files, whose first log holds a run of edenprobe, sent as m: kept under PROBE_KEY with the run, or + the link of the report m's author sent of the same run before */ +static cJSON* probed(Tracer* t, const TrMessage* m, Taken* k, const char* note, long* report) { + const Probe* p = &k->probe; + char digest[17], *text; + long seen; + StReport r; + cJSON* e; + int scarletnx = !strcmp(p->emulator, "ScarletNX"); + probe_digest(p, digest); + if ((seen = st_probe_seen(t->store, m->author, digest))) { + char* url = rei_format("%s/r/%ld/", t->url, seen); + text = rei_format("This run of edenprobe is report #%ld already: its lines are the same, so nothing was kept " + "again.", + seen); + e = said(text); + jset(e, "url", url); + free(url); + free(text); + tr_taken_free(k); + return e; + } + memset(&r, 0, sizeof r); + r.key = rei_strdup(PROBE_KEY); + r.title = rei_format("edenprobe %s on %s", p->version, p->emulator); + r.named = 1; + r.when = rei_now(); + r.guild = m->guild; + r.channel = m->channel; + r.message = m->id; + r.poster = m->author; + r.note = *note ? rei_strdup(note) : NULL; + r.version = rei_strdup(p->version); + if (scarletnx) { /* the log summary's facts of ScarletNX's own log, as any report's */ + r.build = dup_of(k->first, "build"); + r.commit = dup_of(k->first, "commit"); + r.branch = dup_of(k->first, "branch"); + r.outcome = dup_of(k->first, "outcome"); + r.signature = dup_of(k->first, "signature"); + r.missed = tr_missed(k->first); + r.age = tr_age_line(t->age, t->store, r.commit, r.branch); + } else if (p->emulator_version) + r.build = rei_strdup(p->emulator_version); + r.system = p->system ? rei_strdup(p->system) : NULL; + r.gpu = p->gpu ? rei_strdup(p->gpu) : NULL; + r.driver = p->driver_text ? rei_strdup(p->driver_text) : p->driver_info ? rei_strdup(p->driver_info) : NULL; + if (st_add(t->store, &r, k->files, k->n) || st_probe_set(t->store, r.id, p, digest)) { + if (r.id) st_remove(t->store, r.id); + st_report_free(&r); + tr_taken_free(k); + return said("The report could not be kept: try again later, please."); + } + if (written(t, r.id, k)) { + site_forget(t->root, r.id, k->files, k->n); + st_remove(t->store, r.id); + st_report_free(&r); + tr_taken_free(k); + return said("The report could not be kept: try again later, please."); + } + site_update(t->store, t->root, r.id, r.key); + rei_log("report #%ld: a run of edenprobe %s on %s, %d cases", r.id, p->version, p->emulator, p->ncases); + e = probe_made(t, &r, k); + *report = r.id; + st_report_free(&r); + tr_taken_free(k); + return e; +} + /* the report of m's files, which asker asked for: m itself, or the message asker replied to (its author the one who sent the report). The hourly limit counts asker */ static cJSON* reported(Tracer* t, const TrMessage* asker, const TrMessage* m, const char* note, long* report) { @@ -716,6 +887,7 @@ static cJSON* reported(Tracer* t, const TrMessage* asker, const TrMessage* m, co tr_taken_free(&k); return e; } + if (k.probed) return probed(t, m, &k, note, report); memset(&r, 0, sizeof r); if (tr_game(k.first, note, &r.key, &r.title, &r.title_id, &r.named)) { tr_taken_free(&k); @@ -1087,7 +1259,8 @@ int tr_rescan(Tracer* t, const char* version) { for (i = 0; i < n; ++i) { StReport now, *r = &now; StFile* files; - int nfiles, k, first = 1; + Probe run; + int nfiles, k, first = 1, has_run = 0; if (st_get(t->store, all[i].id, r, &files, &nfiles) != 1) continue; for (k = 0; k < nfiles; ++k) { char *path, *text, *shown, *summary; @@ -1105,7 +1278,13 @@ int tr_rescan(Tracer* t, const char* version) { len = b.len; text = buf_take(&b); shown = tr_public_log(text, len, &shown_len); - if (shown_len != len) { /* a log kept before the site left its dumps out */ + { /* and without what edenprobe's lines would say of the player */ + int cases, notes; + char* cut = probe_cut(shown, shown_len, &shown_len, &cases, ¬es); + free(shown); + shown = cut; + } + if (shown_len != len || memcmp(shown, text, len)) { /* a log kept before the site left these out */ char* rel = rei_format("r/%ld/%s", r->id, files[k].path); if (!site_write(t->root, rel, shown, shown_len)) st_set_bytes(t->store, r->id, files[k].n, (double)shown_len); @@ -1113,13 +1292,30 @@ int tr_rescan(Tracer* t, const char* version) { } free(text); summary = summary_of(shown, shown_len); + if (first) { /* the first log's run of edenprobe makes the report the run's, read again */ + char *why = NULL, digest[17]; + if ((has_run = probe_parse(shown, shown_len, &run, &why) == 1)) { + probe_digest(&run, digest); + if (!st_probe_set(t->store, r->id, &run, digest) && strcmp(r->key, PROBE_KEY)) { + char* title = rei_format("edenprobe %s on %s", run.version, run.emulator); + if (!st_set_game(t->store, r->id, PROBE_KEY, title, NULL, 1)) { + rei_log("report #%ld is a run of edenprobe, not a report of %s", r->id, r->key); + site_update(t->store, t->root, 0, r->key); + free(r->key); + r->key = rei_strdup(PROBE_KEY); + } + free(title); + } + } + free(why); + } free(shown); if (!summary) continue; st_set_summary(t->store, r->id, files[k].n, summary); if (first) { /* the report's facts are its first log's, and so is its game when the log names another */ cJSON* s = cJSON_Parse(summary); StReport facts = *r; - refile(t, r, s); + if (strcmp(r->key, PROBE_KEY)) refile(t, r, s); facts.version = (char*)jstr(s, "game_version"); facts.build = (char*)jstr(s, "build"); facts.commit = (char*)jstr(s, "commit"); @@ -1131,6 +1327,20 @@ int tr_rescan(Tracer* t, const char* version) { facts.signature = (char*)jstr(s, "signature"); facts.missed = tr_missed(s); facts.console = (char*)jstr(s, "console"); + if (has_run) { /* a run's facts, as probed keeps them: Eden's and a report.jsonl's from the run */ + int scarletnx = !strcmp(run.emulator, "ScarletNX"); + facts.version = run.version; + facts.system = run.system; + facts.gpu = run.gpu; + facts.driver = run.driver_text ? run.driver_text : run.driver_info; + facts.console = NULL; + if (!scarletnx) { + facts.build = run.emulator_version; + facts.commit = facts.branch = facts.outcome = facts.signature = NULL; + free(facts.missed); + facts.missed = NULL; + } + } st_set_facts(t->store, &facts); free(facts.missed); cJSON_Delete(s); @@ -1138,6 +1348,7 @@ int tr_rescan(Tracer* t, const char* version) { } free(summary); } + if (has_run) probe_free(&run); st_files_free(files, nfiles); st_report_free(r); ++done; diff --git a/tracer/src/report.h b/tracer/src/report.h index 0fc0c8d..dfef97e 100644 --- a/tracer/src/report.h +++ b/tracer/src/report.h @@ -21,6 +21,9 @@ typedef struct { these */ cJSON* first; /* the first log's summary */ Buf skipped; /* a line for each attachment not taken */ + Probe probe; /* the run of edenprobe in a new report's first log (probe.h), when probed */ + int probed; /* the first log of a new report holds a run: the report is the run's */ + char* probe_why; /* owned: why a first log with lines of edenprobe holds no run of it, NULL for none */ } Taken; typedef struct Tracer Tracer; @@ -77,7 +80,7 @@ int tr_game(const cJSON* summary, const char* note, char** key, char** title, ch commands" (shaders by the shaders, the rest by the different ones); owned, NULL for nothing */ char* tr_missed(const cJSON* summary); /* what a report keeps of its logs, as a version: a new one summarizes the kept reports again (tr_rescan) */ -#define TR_FACTS "facts 5" +#define TR_FACTS "facts 6" /* the reply to m, a message that mentions the bot: an embed (owned), or NULL for a message already handled (the gateway sends a message again after a resume). *report is the report it made or updated, 0 for none: the reply, @@ -89,7 +92,9 @@ char* tr_missed(const cJSON* summary); cJSON* tr_answer(Tracer* t, const TrMessage* m, long* report); /* each kept log summarized again, each report's facts drawn again from its first log, and its game named or filed again, when the log summary or the list of names differs from the one that made them (version: TR_LOGSCAN and the - list's). The reports summarized again, -1 for an error; the site's pages are not drawn again (site_rebuild) */ + list's). A report whose first log holds a run of edenprobe becomes the run's (or keeps its run, read again); each + kept log loses what probe_cut leaves out. The reports summarized again, -1 for an error; the site's pages are not + drawn again (site_rebuild) */ int tr_rescan(Tracer* t, const char* version); /* reaction r, to a report's message: when it is the approval's emoji and its user may approve the report (the report's server's owner and administrators, and TRACER_ADMINS), the report filed as an issue once, the site drawn diff --git a/tracer/src/site.c b/tracer/src/site.c index bc8e434..1f3853c 100644 --- a/tracer/src/site.c +++ b/tracer/src/site.c @@ -736,11 +736,17 @@ static int game_page(Store* s, const char* root, const char* key, const StGame* static int lists(Store* s, const char* root, StGame* games, int ngames) { StReport* all; - int n, done = write_page(root, "index.html", site_index_html(games, ngames)); + int n, i, games_n = 0, done = write_page(root, "index.html", site_index_html(games, ngames)); done |= write_page(root, "api/games.json", site_games_json(games, ngames)); if (st_reports(s, NULL, &all, &n)) return -1; - done |= write_page(root, "all.html", site_all_html(all, n)); - done |= write_page(root, "api/reports.json", site_reports_json(all, n)); + for (i = 0; i < n; ++i) /* the game reports: the runs of edenprobe have the Probe pages */ + if (strcmp(all[i].key, PROBE_KEY)) { + StReport keep = all[i]; + all[i] = all[games_n]; + all[games_n++] = keep; + } + done |= write_page(root, "all.html", site_all_html(all, games_n)); + done |= write_page(root, "api/reports.json", site_reports_json(all, games_n)); st_reports_free(all, n); return done; } diff --git a/tracer/src/store.c b/tracer/src/store.c index 3fc5dad..e30d590 100644 --- a/tracer/src/store.c +++ b/tracer/src/store.c @@ -51,7 +51,23 @@ static const char* const UPGRADES[] = { /* 7, how far a report's build was behind main, and what GitHub said of each commit (age.h) */ "ALTER TABLE reports ADD COLUMN age TEXT;" "CREATE TABLE ages(commit_id TEXT PRIMARY KEY, asked REAL NOT NULL, found INTEGER NOT NULL, behind INTEGER NOT" - " NULL, days INTEGER NOT NULL, nightly TEXT);"}; + " NULL, days INTEGER NOT NULL, nightly TEXT);", + /* 8, the runs of edenprobe: each report's machine and mode, each case named once, each run's result of each */ + "CREATE TABLE probe_names(id INTEGER PRIMARY KEY, suite TEXT NOT NULL, name TEXT NOT NULL, key TEXT NOT NULL" + " UNIQUE, UNIQUE(suite, name));" + "CREATE TABLE probe_runs(report INTEGER PRIMARY KEY REFERENCES reports(id) ON DELETE CASCADE, emulator TEXT NOT" + " NULL, emulator_version TEXT, commit_id TEXT, built REAL NOT NULL, version TEXT NOT NULL, describe TEXT, words" + " TEXT NOT NULL, system TEXT, os TEXT NOT NULL, gpu TEXT, device TEXT, driver_name TEXT, driver_info TEXT," + " driver_id INTEGER NOT NULL, inferred INTEGER NOT NULL, driver_version INTEGER NOT NULL, vulkan TEXT, extensions" + " TEXT, passed INTEGER NOT NULL, failed INTEGER NOT NULL, skipped INTEGER NOT NULL, crashed INTEGER NOT NULL, whole" + " INTEGER NOT NULL, cut_cases INTEGER NOT NULL, cut_notes INTEGER NOT NULL, unread INTEGER NOT NULL, over INTEGER" + " NOT NULL, digest TEXT NOT NULL);" + "CREATE INDEX probe_runs_digest ON probe_runs(digest);" + "CREATE TABLE probe_cases(report INTEGER NOT NULL REFERENCES probe_runs(report) ON DELETE CASCADE, name INTEGER" + " NOT NULL REFERENCES probe_names(id), result INTEGER NOT NULL, tier TEXT, reason TEXT, detail TEXT, us REAL," + " PRIMARY KEY(report, name)) WITHOUT ROWID;" + /* by case, with the result, so the rules and a case's page read the results from the index alone */ + "CREATE INDEX probe_cases_name ON probe_cases(name, report, result);"}; /* a report's columns, in the order row_report reads them */ #define REPORT_COLUMNS \ @@ -652,7 +668,8 @@ int st_games(Store* s, StGame** games, int* n) { s, "SELECT r.game, (SELECT t.title FROM reports t WHERE t.game = r.game ORDER BY t.named DESC, t.id" " DESC LIMIT 1), (SELECT t.title_id FROM reports t WHERE t.game = r.game AND t.title_id IS NOT NULL ORDER BY" " t.id DESC LIMIT 1), c.n, r.created, r.outcome, r.missed, r.console FROM reports r JOIN (SELECT game," - " count(*) AS n, max(id) AS last FROM reports GROUP BY game) c ON r.id = c.last ORDER BY r.id DESC"); + " count(*) AS n, max(id) AS last FROM reports WHERE game != '" PROBE_KEY "' GROUP BY game) c ON r.id =" + " c.last ORDER BY r.id DESC"); return rows(q, (void**)games, n, sizeof **games, row_game); } @@ -755,3 +772,305 @@ void st_reports_free(StReport* r, int n) { for (i = 0; i < n; ++i) st_report_free(&r[i]); free(r); } + +/* ---- the runs of edenprobe ---- */ + +/* name's id in probe_names, found, else added: the id, or 0 said in the log */ +static long name_id(Store* s, sqlite3_stmt* add, sqlite3_stmt* find, const char* suite, const char* name) { + char key[17]; + long id = 0; + int added; + for (added = 0; !id && added < 2; ++added) { + if (added) { /* not there yet */ + probe_case_key(suite, name, key); + sqlite3_reset(add); + text_at(add, 1, suite); + text_at(add, 2, name); + text_at(add, 3, key); + if (sqlite3_step(add) != SQLITE_DONE) { + said(s, "a case's name added"); + return 0; + } + } + sqlite3_reset(find); + text_at(find, 1, suite); + text_at(find, 2, name); + if (sqlite3_step(find) == SQLITE_ROW) id = (long)sqlite3_column_int64(find, 0); + } + if (!id) said(s, "a case's name found"); + return id; +} +static int result_code(const ProbeCase* c) { + if (!strcmp(c->result, "pass")) return ST_PASS; + if (!strcmp(c->result, "fail")) return ST_FAIL; + return !strcmp(c->reason, "crashed") ? ST_CRASHED : ST_SKIP; +} +static const char* result_word(int code) { return code == ST_PASS ? "pass" : code == ST_FAIL ? "fail" : "skip"; } + +int st_probe_set(Store* s, long report, const Probe* p, const char* digest) { + sqlite3_stmt *q = NULL, *add = NULL, *find = NULL, *c = NULL; + int i, ok; + if (sqlite3_exec(s->db, "BEGIN", NULL, NULL, NULL) != SQLITE_OK) { + said(s, "BEGIN"); + return -1; + } + q = prepared(s, "DELETE FROM probe_runs WHERE report = ?"); + ok = q != NULL; + if (ok) { + sqlite3_bind_int64(q, 1, report); + ok = sqlite3_step(q) == SQLITE_DONE; + if (!ok) said(s, "a run taken out"); + sqlite3_finalize(q); + } + q = ok ? prepared(s, + "INSERT INTO probe_runs(report, emulator, emulator_version, commit_id, built, version," + " describe, words, system, os, gpu, device, driver_name, driver_info, driver_id, inferred," + " driver_version, vulkan, extensions, passed, failed, skipped, crashed, whole, cut_cases," + " cut_notes, unread, over, digest) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," + "?,?)") + : NULL; + ok = q != NULL; + if (ok) { + sqlite3_bind_int64(q, 1, report); + text_at(q, 2, p->emulator); + text_at(q, 3, p->emulator_version); + text_at(q, 4, p->commit); + sqlite3_bind_double(q, 5, p->built); + text_at(q, 6, p->version); + text_at(q, 7, p->describe); + text_at(q, 8, p->words); + text_at(q, 9, p->system); + text_at(q, 10, p->os ? p->os : "unknown"); + text_at(q, 11, p->gpu); + text_at(q, 12, p->device); + text_at(q, 13, p->driver_name); + text_at(q, 14, p->driver_info); + sqlite3_bind_int(q, 15, p->driver_id); + sqlite3_bind_int(q, 16, p->inferred); + sqlite3_bind_int64(q, 17, (sqlite3_int64)p->driver_version); + text_at(q, 18, p->vulkan); + text_at(q, 19, p->extensions); + sqlite3_bind_int64(q, 20, p->passed); + sqlite3_bind_int64(q, 21, p->failed); + sqlite3_bind_int64(q, 22, p->skipped); + sqlite3_bind_int64(q, 23, p->crashed); + sqlite3_bind_int(q, 24, p->whole); + sqlite3_bind_int(q, 25, p->cut_cases); + sqlite3_bind_int(q, 26, p->cut_notes); + sqlite3_bind_int(q, 27, p->unread); + sqlite3_bind_int(q, 28, p->over); + text_at(q, 29, digest); + ok = sqlite3_step(q) == SQLITE_DONE; + if (!ok) said(s, "a run added"); + } + sqlite3_finalize(q); + add = ok ? prepared(s, "INSERT OR IGNORE INTO probe_names(suite, name, key) VALUES(?,?,?)") : NULL; + find = add ? prepared(s, "SELECT id FROM probe_names WHERE suite = ? AND name = ?") : NULL; + c = find ? prepared(s, "INSERT INTO probe_cases(report, name, result, tier, reason, detail, us)" + " VALUES(?,?,?,?,?,?,?)") + : NULL; + ok = c != NULL; + for (i = 0; ok && i < p->ncases; ++i) { + const ProbeCase* k = &p->cases[i]; + long id = name_id(s, add, find, k->suite, k->name); + ok = id != 0; + if (!ok) break; + sqlite3_reset(c); + sqlite3_bind_int64(c, 1, report); + sqlite3_bind_int64(c, 2, id); + sqlite3_bind_int(c, 3, result_code(k)); + text_at(c, 4, k->tier); + text_at(c, 5, *k->reason ? k->reason : NULL); + text_at(c, 6, *k->detail ? k->detail : NULL); + if (k->us >= 0) + sqlite3_bind_double(c, 7, k->us); + else + sqlite3_bind_null(c, 7); + ok = sqlite3_step(c) == SQLITE_DONE; + if (!ok) said(s, "a case's result added"); + } + sqlite3_finalize(add); + sqlite3_finalize(find); + sqlite3_finalize(c); + if (sqlite3_exec(s->db, ok ? "COMMIT" : "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK) { + said(s, ok ? "COMMIT" : "ROLLBACK"); + ok = 0; + } + return ok ? 0 : -1; +} + +#define RUN_COLUMNS \ + "r.report, r.emulator, r.emulator_version, r.commit_id, r.built, r.version, r.describe, r.words, r.system, r.os, " \ + "r.gpu, r.device, r.driver_name, r.driver_info, r.driver_id, r.inferred, r.driver_version, r.vulkan, " \ + "r.extensions, r.passed, r.failed, r.skipped, r.crashed, r.whole, r.cut_cases, r.cut_notes, r.unread, r.over, " \ + "p.poster, p.created" +static void row_run(sqlite3_stmt* q, void* to) { + StProbeRun* r = to; + Probe* p = &r->p; + char text[32]; + r->report = (long)sqlite3_column_int64(q, 0); + p->emulator = text_of(q, 1); + p->emulator_version = text_of(q, 2); + p->commit = text_of(q, 3); + p->built = sqlite3_column_double(q, 4); + p->version = text_of(q, 5); + p->describe = text_of(q, 6); + p->words = text_of(q, 7); + p->system = text_of(q, 8); + p->os = text_of(q, 9); + p->gpu = text_of(q, 10); + p->device = text_of(q, 11); + p->driver_name = text_of(q, 12); + p->driver_info = text_of(q, 13); + p->driver_id = sqlite3_column_int(q, 14); + p->inferred = sqlite3_column_int(q, 15); + p->driver_version = (unsigned long)sqlite3_column_int64(q, 16); + p->vulkan = text_of(q, 17); + p->extensions = text_of(q, 18); + p->passed = (long)sqlite3_column_int64(q, 19); + p->failed = (long)sqlite3_column_int64(q, 20); + p->skipped = (long)sqlite3_column_int64(q, 21); + p->crashed = (long)sqlite3_column_int64(q, 22); + p->whole = sqlite3_column_int(q, 23); + p->cut_cases = sqlite3_column_int(q, 24); + p->cut_notes = sqlite3_column_int(q, 25); + p->unread = sqlite3_column_int(q, 26); + p->over = sqlite3_column_int(q, 27); + r->poster = (u64)sqlite3_column_int64(q, 28); + r->when = sqlite3_column_double(q, 29); + if (p->driver_id && p->driver_version) { + probe_version_text(p->driver_id, p->driver_version, text, sizeof text); + p->driver_text = rei_strdup(text); + } +} + +int st_probe_get(Store* s, long report, Probe* p, int cases) { + sqlite3_stmt* q = prepared(s, "SELECT " RUN_COLUMNS " FROM probe_runs r JOIN reports p ON p.id = r.report" + " WHERE r.report = ?"); + StProbeRun run; + int found, cap = 0; + memset(p, 0, sizeof *p); + if (!q) return -1; + memset(&run, 0, sizeof run); + sqlite3_bind_int64(q, 1, report); + found = sqlite3_step(q) == SQLITE_ROW; + if (found) row_run(q, &run); + sqlite3_finalize(q); + if (!found) return 0; + *p = run.p; + if (!cases) return 1; + q = prepared(s, "SELECT n.suite, n.name, c.result, c.tier, c.reason, c.detail, c.us FROM probe_cases c JOIN" + " probe_names n ON n.id = c.name WHERE c.report = ? ORDER BY n.id"); + if (!q) { + probe_free(p); + return -1; + } + sqlite3_bind_int64(q, 1, report); + while (sqlite3_step(q) == SQLITE_ROW) { + ProbeCase* c; + int code = sqlite3_column_int(q, 2); + char* reason = text_of(q, 4); + char* detail = text_of(q, 5); + if (p->ncases == cap) { + cap = cap ? cap * 2 : 256; + p->cases = realloc(p->cases, (size_t)cap * sizeof *p->cases); + if (!p->cases) { + fputs(REI_NAME ": out of memory\n", stderr); + abort(); + } + } + c = &p->cases[p->ncases++]; + c->suite = text_of(q, 0); + c->name = text_of(q, 1); + c->result = rei_strdup(result_word(code)); + c->tier = text_of(q, 3); + if (!c->tier) c->tier = rei_strdup("none"); + c->reason = reason ? reason : rei_strdup(code == ST_CRASHED ? "crashed" : ""); + c->detail = detail ? detail : rei_strdup(""); + c->us = sqlite3_column_type(q, 6) == SQLITE_NULL ? -1 : sqlite3_column_double(q, 6); + } + sqlite3_finalize(q); + return 1; +} + +long st_probe_seen(Store* s, u64 poster, const char* digest) { + sqlite3_stmt* q = prepared(s, "SELECT r.report FROM probe_runs r JOIN reports p ON p.id = r.report WHERE" + " r.digest = ? AND p.poster = ? ORDER BY r.report LIMIT 1"); + long id = 0; + if (!q) return 0; + text_at(q, 1, digest); + sqlite3_bind_int64(q, 2, (sqlite3_int64)poster); + if (sqlite3_step(q) == SQLITE_ROW) id = (long)sqlite3_column_int64(q, 0); + sqlite3_finalize(q); + return id; +} + +int st_probe_runs(Store* s, StProbeRun** runs, int* n) { + sqlite3_stmt* q = prepared(s, "SELECT " RUN_COLUMNS " FROM probe_runs r JOIN reports p ON p.id = r.report" + " ORDER BY r.report DESC"); + return rows(q, (void**)runs, n, sizeof **runs, row_run); +} +void st_probe_runs_free(StProbeRun* runs, int n) { + int i; + for (i = 0; i < n; ++i) probe_free(&runs[i].p); + free(runs); +} + +static void row_name(sqlite3_stmt* q, void* to) { + StProbeName* name = to; + const unsigned char* key = sqlite3_column_text(q, 3); + name->id = sqlite3_column_int(q, 0); + name->suite = text_of(q, 1); + name->name = text_of(q, 2); + snprintf(name->key, sizeof name->key, "%s", key ? (const char*)key : ""); +} +int st_probe_names(Store* s, StProbeName** names, int* n) { + sqlite3_stmt* q = prepared(s, "SELECT id, suite, name, key FROM probe_names WHERE id IN (SELECT DISTINCT name FROM" + " probe_cases) ORDER BY id"); + return rows(q, (void**)names, n, sizeof **names, row_name); +} +void st_probe_names_free(StProbeName* names, int n) { + int i; + for (i = 0; i < n; ++i) { + free(names[i].suite); + free(names[i].name); + } + free(names); +} + +static void row_result(sqlite3_stmt* q, void* to) { + StProbeResult* r = to; + r->report = (long)sqlite3_column_int64(q, 0); + r->name = sqlite3_column_int(q, 1); + r->result = sqlite3_column_int(q, 2); +} +int st_probe_results(Store* s, StProbeResult** results, int* n) { + sqlite3_stmt* q = prepared(s, "SELECT report, name, result FROM probe_cases ORDER BY name, report"); + return rows(q, (void**)results, n, sizeof **results, row_result); +} + +static void row_detail(sqlite3_stmt* q, void* to) { + StProbeDetail* d = to; + char* text; + d->report = (long)sqlite3_column_int64(q, 0); + d->result = sqlite3_column_int(q, 1); + d->tier = (text = text_of(q, 2)) ? text : rei_strdup(""); + d->reason = (text = text_of(q, 3)) ? text : rei_strdup(d->result == ST_CRASHED ? "crashed" : ""); + d->detail = (text = text_of(q, 4)) ? text : rei_strdup(""); + d->us = sqlite3_column_type(q, 5) == SQLITE_NULL ? -1 : sqlite3_column_double(q, 5); +} +int st_probe_details(Store* s, int name, StProbeDetail** details, int* n) { + sqlite3_stmt* q = prepared(s, "SELECT report, result, tier, reason, detail, us FROM probe_cases WHERE name = ?" + " ORDER BY report DESC"); + if (q) sqlite3_bind_int(q, 1, name); + return rows(q, (void**)details, n, sizeof **details, row_detail); +} +void st_probe_details_free(StProbeDetail* details, int n) { + int i; + for (i = 0; i < n; ++i) { + free(details[i].tier); + free(details[i].reason); + free(details[i].detail); + } + free(details); +} diff --git a/tracer/src/store.h b/tracer/src/store.h index ad963c4..e0899bf 100644 --- a/tracer/src/store.h +++ b/tracer/src/store.h @@ -6,6 +6,7 @@ connection, used by one thread at a time */ #ifndef TR_STORE_H #define TR_STORE_H +#include "probe.h" #include "tracer.h" typedef struct Store Store; @@ -111,11 +112,59 @@ int st_age(Store* s, const char* commit, StAge* a); int st_set_age(Store* s, const char* commit, const StAge* a); void st_age_free(StAge* a); -/* every game, the newest report first */ +/* every game, the newest report first; the runs of edenprobe (key PROBE_KEY) are no game's */ int st_games(Store* s, StGame** games, int* n); -/* the game's reports, or every report when key is NULL, the newest first */ +/* the game's reports, or every report when key is NULL (the runs of edenprobe too), the newest first; key PROBE_KEY + gives the runs' reports */ int st_reports(Store* s, const char* key, StReport** reports, int* n); +/* ---- the runs of edenprobe (probe.h): each a report of key PROBE_KEY, its machine and each case's result ---- */ + +/* report's run, its cases with it, kept, in place of one it had: 0, or -1 said in the log, nothing kept */ +int st_probe_set(Store* s, long report, const Probe* p, const char* digest); +/* report's run, its cases with it when cases: 1 (*p owned), 0 when it has none, -1 said in the log */ +int st_probe_get(Store* s, long report, Probe* p, int cases); +/* the report poster sent of a run with this digest (probe_digest), 0 for none */ +long st_probe_seen(Store* s, u64 poster, const char* digest); + +typedef struct { + long report; + u64 poster; /* never shown: the rules count people by it */ + double when; + Probe p; /* without its cases */ +} StProbeRun; +/* every run, the newest first */ +int st_probe_runs(Store* s, StProbeRun** runs, int* n); +void st_probe_runs_free(StProbeRun* runs, int n); + +typedef struct { + int id; + char *suite, *name; /* owned */ + char key[17]; /* probe_case_key's: the case's page */ +} StProbeName; +/* every case a run named, by id */ +int st_probe_names(Store* s, StProbeName** names, int* n); +void st_probe_names_free(StProbeName* names, int n); + +enum { ST_PASS, ST_FAIL, ST_SKIP, ST_CRASHED }; /* a case's result as kept: a skip whose reason is crashed is crashed */ +typedef struct { + long report; + int name; /* StProbeName's id */ + int result; /* ST_* */ +} StProbeResult; +/* every result of every run, by case then report */ +int st_probe_results(Store* s, StProbeResult** results, int* n); + +typedef struct { + long report; + int result; + char *tier, *reason, *detail; /* owned; "" for none */ + double us; /* -1 for none */ +} StProbeDetail; +/* each run's result of case name, the newest report first */ +int st_probe_details(Store* s, int name, StProbeDetail** details, int* n); +void st_probe_details_free(StProbeDetail* details, int n); + void st_report_free(StReport* r); void st_files_free(StFile* f, int n); void st_notes_free(StNote* notes, int n); diff --git a/tracer/src/worker.c b/tracer/src/worker.c index 7aa7c5c..386b7c1 100644 --- a/tracer/src/worker.c +++ b/tracer/src/worker.c @@ -253,6 +253,8 @@ int wk_serve(FILE* in, FILE* out, TrGet get, void* ctx) { cJSON_AddNumberToObject(a, "videos", k.videos); jset(a, "skipped", k.skipped.text ? k.skipped.text : ""); if (k.first) cJSON_AddItemToObject(a, "first", cJSON_Duplicate(k.first, 1)); + if (k.probed) cJSON_AddItemToObject(a, "probe", probe_json(&k.probe)); + jset(a, "probe_why", k.probe_why); list = cJSON_AddArrayToObject(a, "files"); for (i = 0; i < k.n; ++i) { f = cJSON_CreateObject(); @@ -324,8 +326,9 @@ static int extension_of(const char* kind, const char* ext) { /* the answer read into k, each of its claims checked, as the worker reads what strangers send: 0, or -1 with why */ static int answered(const char* text, size_t n, Taken* k, char** why) { cJSON* a = cJSON_ParseWithLength(text, n); - const cJSON *each, *first = cJSON_GetObjectItemCaseSensitive(a, "first"); - const char* skipped = jstr(a, "skipped"); + const cJSON *each, *first = cJSON_GetObjectItemCaseSensitive(a, "first"), + *probe = cJSON_GetObjectItemCaseSensitive(a, "probe"); + const char *skipped = jstr(a, "skipped"), *probe_why = jstr(a, "probe_why"); int logs = 0, images = 0, videos = 0; if (!cJSON_IsObject(a)) { *why = rei_strdup("its answer is no JSON object"); @@ -386,8 +389,15 @@ static int answered(const char* text, size_t n, Taken* k, char** why) { k->videos = videos; if (cJSON_IsObject(first)) k->first = cJSON_Duplicate(first, 1); if (skipped && *skipped) buf_printf(&k->skipped, "%.*s", SKIPPED_MAX, skipped); + if (probe_why && *probe_why) k->probe_why = rei_format("%.*s", SKIPPED_MAX, probe_why); if (logs && !k->first) *why = rei_strdup("it answered logs and no first log's summary"); } + if (!*why && probe) { /* a run of edenprobe: checked as the rest, and only for a new report's first log */ + if (!logs || k->logs_had || k->base) + *why = rei_strdup("it answered a run of edenprobe for no new report's first log"); + else if (!probe_of_json(probe, &k->probe, why)) + k->probed = 1; + } cJSON_Delete(a); return *why ? -1 : 0; } diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index f7b0d5b..9cc57e3 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -10,6 +10,7 @@ #endif #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include "issues.h" #include "mcp.h" #include "message.h" +#include "probe.h" #include "report.h" #include "site.h" #include "store.h" @@ -2850,6 +2852,550 @@ static void test_archive_download(void) { tr_message_free(&m); } +/* ---- runs of edenprobe ---- */ + +/* ScarletNX's log of a run: its machine, then the report's lines as [game] lines. The account case's detail names a + player, the nifm case's an address, the net note a session; a suite edenprobe's table lacks says nothing of what it + holds */ +static const char PROBE_LOG[] = + "[ 0.00] ScarletNX - edenprobe\n" + "[ 0.00] build: ScarletNX main 1234abc, committed 2026-11-01 (clang 23.1.3, Linux x86_64)\n" + "[ 0.00] system: 'Some Linux' (Linux 6.1.0), Some CPU 9000, 12 threads, 32 GB RAM\n" + "[ 0.18] vulkan: the driver that runs: radv, Mesa 26.1.8 (driver ID 3)\n" + "[ 0.18] vulkan: Some GPU 3000 (RADV X), Vulkan 1.4.354, driver 06801008, graphics queue family 0, compute 1\n" + "[ 0.19] game: 0100000000001000, version 0.9.0\n" + "[ 0.20] [game] {\"type\":\"note\",\"text\":\"edenprobe 0.9.0 (v0.9.0) starting\"}\n" + "[ 0.20] [game] {\"type\":\"note\",\"text\":\"folder: sdmc:/edenprobe/runs/2a3ec1e_x\"}\n" + "[ 0.20] [game] {\"type\":\"note\",\"text\":\"mode: quick, from the mode file; pictures of failures only; " + "families cpu graphics net; no timing passes; label x\"}\n" + "[ 0.21] [game] {\"type\":\"case\",\"suite\":\"clear\",\"name\":\"clear to opaque red\",\"tier\":\"exact\"," + "\"result\":\"pass\",\"detail\":\"\",\"us\":12}\n" + "[ 0.21] [game] {\"type\":\"case\",\"suite\":\"astc\",\"name\":\"a 4x4 block decodes\",\"tier\":\"exact\"," + "\"result\":\"fail\",\"detail\":\"texel 0 reads 00ff00ff, it holds ff0000ff\"}\n" + "[ 0.21] [game] {\"type\":\"case\",\"suite\":\"account\",\"name\":\"the user's nickname reads back\",\"tier\":" + "\"exact\",\"result\":\"pass\",\"detail\":\"uid 0123456789abcdeffedcba9876543210, nickname Someone\"}\n" + "[ 0.21] [game] {\"type\":\"case\",\"suite\":\"nifm\",\"name\":\"a machine has an address\",\"tier\":\"exact\"," + "\"result\":\"pass\",\"detail\":\"got 192.168.1.20\"}\n" + "[ 0.21] [game] {\"type\":\"note\",\"text\":\"net: sdmc:/edenprobe/net; session tok-abcdef; account named\"}\n" + "[ 0.22] [game] {\"type\":\"case\",\"suite\":\"index\",\"name\":\"an indexed draw\",\"tier\":\"none\",\"result\":" + "\"skip\",\"reason\":\"crashed\",\"detail\":\"the program ended inside it\"}\n" + "[ 0.22] [game] {\"type\":\"case\",\"suite\":\"newsuite\",\"name\":\"something new\",\"tier\":\"exact\"," + "\"result\":\"fail\",\"detail\":\"what it holds nobody said\"}\n" + "[ 0.23] [game] {\"type\":\"summary\",\"passed\":3,\"failed\":2,\"skipped\":0,\"crashed\":1}\n" + "[ 0.23] [game] EDENPROBE DONE passed=3 failed=2 skipped=0 crashed=1\n"; +/* Eden's log of a run, as its yuzu_cmd writes it */ +static const char EDEN_LOG[] = + "[ 0.905119] Frontend yuzu_cmd/emu_window/emu_window_sdl3_vk.cpp:91:EmuWindow_SDL3_VK: Eden Version: Eden " + "| HEAD-4534fde3aa-HEAD (Vulkan)\n" + "[ 1.320106] Render.Vulkan video_core/renderer_vulkan/renderer_vulkan.cpp:264:Report: Driver: NVIDIA " + "580.95.5.0\n" + "[ 1.320108] Render.Vulkan video_core/renderer_vulkan/renderer_vulkan.cpp:265:Report: Device: Some " + "GeForce 9000\n" + "[ 1.320109] Render.Vulkan video_core/renderer_vulkan/renderer_vulkan.cpp:266:Report: Vulkan: 1.4.329\n" + "[ 1.400000] Frontend qt_common/qt_common.cpp:265:Init: Host OS: Windows 11 Version 24H2\n" + "[ 3.092326] Debug.Emulated core/hle/kernel/svc/svc_debug_string.cpp:25:OutputDebugString: " + "{\"type\":\"note\",\"text\":\"edenprobe 0.9.0 (v0.9.0) starting\"}\n" + "[ 3.092400] Debug.Emulated core/hle/kernel/svc/svc_debug_string.cpp:25:OutputDebugString: " + "{\"type\":\"note\",\"text\":\"mode: quick, from the mode file; pictures of failures only; families graphics\"}\n" + "[ 3.130376] Debug.Emulated core/hle/kernel/svc/svc_debug_string.cpp:25:OutputDebugString: " + "{\"type\":\"case\",\"suite\":\"astc\",\"name\":\"a 4x4 block decodes\",\"tier\":\"exact\",\"result\":\"fail\"," + "\"detail\":\"texel 0 reads 0000ff00\"}\n" + "[ 3.130400] Debug.Emulated core/hle/kernel/svc/svc_debug_string.cpp:25:OutputDebugString: " + "{\"type\":\"summary\",\"passed\":0,\"failed\":1,\"skipped\":0,\"crashed\":0}\n"; +/* the report itself, as the card keeps it */ +static const char PROBE_JSONL[] = + "{\"type\":\"note\",\"text\":\"edenprobe 0.9.0 (v0.9.0) starting\"}\n" + "{\"type\":\"note\",\"text\":\"mode: quick, from the mode file; pictures of failures only; families graphics\"}\n" + "{\"type\":\"case\",\"suite\":\"astc\",\"name\":\"a 4x4 block decodes\",\"tier\":\"exact\",\"result\":\"pass\"," + "\"detail\":\"\"}\n" + "{\"type\":\"summary\",\"passed\":1,\"failed\":0,\"skipped\":0,\"crashed\":0}\n"; + +static void test_probe_parts(void) { + char text[64]; + unsigned long v = 0; + /* the families: service, net, pad and a suite the table has not lose their detail */ + CHECK(probe_family("tex8k") == PROBE_GRAPHICS && probe_family("acc-app") == PROBE_SERVICE); + CHECK(probe_family("friend") == PROBE_NET && probe_family("touch") == PROBE_PAD); + CHECK(probe_family("nonesuch") == PROBE_OTHER && probe_family(NULL) == PROBE_OTHER); + SAME(probe_family_name(PROBE_KERNEL), "kernel"); + CHECK(probe_keeps_detail("astc") && probe_keeps_detail("fs") && probe_keeps_detail("game")); + CHECK(!probe_keeps_detail("account") && !probe_keeps_detail("ldn") && !probe_keeps_detail("nifm")); + CHECK(!probe_keeps_detail("pad") && !probe_keeps_detail("nonesuch")); + /* the drivers, by the ban table's names, and by their own names as Eden logs them */ + SAME(probe_driver_name(3), "radv"); + SAME(probe_driver_name(30), "apesoft"); + CHECK(!probe_driver_name(0) && !probe_driver_name(31)); + SAME(probe_driver_label(4), "NVIDIA's driver"); + CHECK(probe_driver_id("turnip") == 18 && probe_driver_id("nonesuch") == 0); + CHECK(probe_driver_of_name("radv") == 3 && probe_driver_of_name("NVIDIA") == 4 && + probe_driver_of_name("NVK") == 24); + CHECK(probe_driver_of_name("Qualcomm Technologies Inc. Adreno Vulkan Driver") == 8); + CHECK(probe_driver_of_name("turnip Mesa driver") == 18); + CHECK(probe_driver_of_name("Intel open-source Mesa driver") == 6 && probe_driver_of_name("Intel Corporation") == 5); + CHECK(probe_driver_of_name("Some Driver") == 0 && probe_driver_of_name(NULL) == 0); + /* each driver's numbering, both ways */ + probe_version_text(4, 0x9b404000UL, text, sizeof text); + SAME(text, "621.1.00"); + probe_version_text(3, 0x06801008UL, text, sizeof text); + SAME(text, "26.1.8"); + CHECK(probe_version_parse(5, "101.4502", &v) && v == 1659286UL); + probe_version_text(5, v, text, sizeof text); + SAME(text, "101.4502"); + CHECK(probe_version_parse(14, "1.2.11", &v) && v == 10211UL); + CHECK(probe_version_parse(3, "26.1.8", &v) && v == 0x06801008UL); + CHECK(probe_version_parse(4, "580.95.5.0", &v)); + probe_version_text(4, v, text, sizeof text); + SAME(text, "580.95.05"); + CHECK(!probe_version_parse(3, "abc", &v) && !probe_version_parse(3, "26.", &v) && + !probe_version_parse(3, "1..2", &v)); + CHECK(!probe_version_parse(3, "26", &v) && !probe_version_parse(3, "2000.1.1", &v)); + /* the system's family */ + SAME(probe_os("'Gentoo Linux' (Linux 6.18.57)"), "linux"); + SAME(probe_os("Android 15 (Linux 6.1.75)"), "android"); + SAME(probe_os("Windows 11 26H2"), "windows"); + SAME(probe_os("macOS 15.1"), "macos"); + SAME(probe_os("FreeBSD 15.0-RELEASE"), "freebsd"); + SAME(probe_os("CachyOS"), "unknown"); + SAME(probe_os(NULL), "unknown"); +} + +static void test_probe_lines(void) { + size_t n; + int cases, notes, i; + char *cut, *why, digest[17], other[17], *t; + Probe p, q; + cJSON* o; + /* the cut: the details of service, net, pad and unknown suites, and the net notes; nothing else */ + cut = probe_cut(PROBE_LOG, strlen(PROBE_LOG), &n, &cases, ¬es); + CHECK(cases == 3 && notes == 1); + LACKS(cut, "nickname Someone"); + LACKS(cut, "192.168.1.20"); + LACKS(cut, "tok-abcdef"); + LACKS(cut, "what it holds nobody said"); + HAS(cut, "\"suite\":\"account\",\"name\":\"the user's nickname reads back\",\"tier\":\"exact\",\"result\":\"pass\"," + "\"detail\":\"\"}"); + HAS(cut, "net: left out by Tracer"); + HAS(cut, "texel 0 reads 00ff00ff, it holds ff0000ff"); /* graphics keeps its detail */ + HAS(cut, "\"reason\":\"crashed\",\"detail\":\"the program ended inside it\""); + HAS(cut, "[ 0.18] vulkan: the driver that runs: radv, Mesa 26.1.8 (driver ID 3)\n"); + free(cut); + cut = probe_cut(LOG, strlen(LOG), &n, &cases, ¬es); /* a game's log: as it was */ + CHECK(cases == 0 && notes == 0 && n == strlen(LOG) && !memcmp(cut, LOG, n)); + free(cut); + /* what a text holds of a run */ + CHECK(probe_marks(LOG, strlen(LOG)) == 0); + CHECK(probe_marks(PROBE_LOG, strlen(PROBE_LOG)) == 2); + CHECK(probe_marks(PROBE_LOG, (size_t)(strstr(PROBE_LOG, "[ 0.23]") - PROBE_LOG)) == 1); + CHECK(probe_marks(EDEN_LOG, strlen(EDEN_LOG)) == 2 && probe_marks(PROBE_JSONL, strlen(PROBE_JSONL)) == 2); + /* ScarletNX's log */ + cut = probe_cut(PROBE_LOG, strlen(PROBE_LOG), &n, &cases, ¬es); + CHECK(probe_parse(cut, n, &p, &why) == 1 && !why); + SAME(p.emulator, "ScarletNX"); + SAME(p.emulator_version, "main 1234abc"); + SAME(p.commit, "1234abc"); + CHECK(p.built == 1793491200.0); + SAME(p.version, "0.9.0"); + SAME(p.describe, "v0.9.0"); + SAME(p.words, "cpu graphics net notime"); + SAME(p.os, "linux"); + SAME(p.gpu, "Some GPU 3000 (RADV X)"); + SAME(p.vulkan, "1.4.354"); + SAME(p.driver_name, "radv"); + SAME(p.driver_info, "Mesa 26.1.8"); + CHECK(p.driver_id == 3 && !p.inferred && p.driver_version == 0x06801008UL); + SAME(p.driver_text, "26.1.8"); + CHECK(p.whole && p.passed == 3 && p.failed == 2 && p.skipped == 0 && p.crashed == 1 && p.ncases == 6); + CHECK(!p.unread && !p.over); + SAME(p.cases[1].suite, "astc"); + SAME(p.cases[1].result, "fail"); + SAME(p.cases[4].reason, "crashed"); + CHECK(p.cases[0].us == 12 && p.cases[1].us == -1); + SAME(p.cases[2].detail, ""); + t = probe_counts(&p); + SAME(t, "3 passed, 2 failed (astc 1, newsuite 1), 0 skipped, 1 crashed"); + free(t); + t = probe_machine(&p); + SAME(t, "radv, Mesa 26.1.8 (Linux)"); + free(t); + /* through JSON, as a worker answers it: the same run, the same mark */ + o = probe_json(&p); + CHECK(!probe_of_json(o, &q, &why) && !why); + probe_digest(&p, digest); + probe_digest(&q, other); + SAME(digest, other); + CHECK(q.ncases == 6 && q.driver_id == 3); + SAME(q.driver_text, "26.1.8"); + probe_free(&q); + /* an answer that is no run's, or keeps a detail the cut takes out */ + cJSON_ReplaceItemInObjectCaseSensitive(o, "emulator", cJSON_CreateString("Ryu")); + CHECK(probe_of_json(o, &q, &why) == -1); + HAS(why, "no emulator it may (Ryu)"); + free(why); + cJSON_ReplaceItemInObjectCaseSensitive(o, "emulator", cJSON_CreateString("ScarletNX")); + cJSON_AddStringToObject(cJSON_GetArrayItem(cJSON_GetObjectItemCaseSensitive(o, "cases"), 2), "detail", + "nickname Someone"); /* probe_json writes no empty detail */ + CHECK(probe_of_json(o, &q, &why) == -1); + HAS(why, "keeps a detail of a family that loses it (account)"); + free(why); + cJSON_AddItemToArray(cJSON_GetObjectItemCaseSensitive(o, "cases"), + cJSON_Parse("{\"suite\":\"a b;c\",\"name\":\"x\"," + "\"result\":\"pass\"}")); + cJSON_ReplaceItemInObjectCaseSensitive(cJSON_GetArrayItem(cJSON_GetObjectItemCaseSensitive(o, "cases"), 2), + "detail", cJSON_CreateString("")); + CHECK(probe_of_json(o, &q, &why) == -1); + HAS(why, "case 7 is not one edenprobe writes"); + free(why); + cJSON_Delete(o); + /* another result is another mark */ + free(p.cases[0].result); + p.cases[0].result = rei_strdup("fail"); + probe_digest(&p, other); + CHECK(strcmp(digest, other) != 0); + probe_free(&p); + free(cut); + /* Eden's log: its driver ID read from the driver's name, its version as NVIDIA numbers it */ + CHECK(probe_parse(EDEN_LOG, strlen(EDEN_LOG), &p, &why) == 1); + SAME(p.emulator, "Eden"); + SAME(p.emulator_version, "Eden | HEAD-4534fde3aa-HEAD (Vulkan)"); + SAME(p.driver_name, "NVIDIA"); + SAME(p.driver_info, "580.95.5.0"); + CHECK(p.driver_id == 4 && p.inferred); + SAME(p.driver_text, "580.95.05"); + SAME(p.gpu, "Some GeForce 9000"); + SAME(p.os, "windows"); + SAME(p.words, "graphics"); + CHECK(p.whole && p.ncases == 1 && !p.commit && p.built == 0); + t = probe_machine(&p); + SAME(t, "NVIDIA 580.95.5.0, driver ID inferred (Windows)"); + free(t); + probe_free(&p); + { /* rEden logs as Eden does, and says so in its version */ + char* reden = rei_strdup(EDEN_LOG); + memcpy(strstr(reden, "Eden | HEAD"), "rEden| HEAD", 11); + CHECK(probe_parse(reden, strlen(reden), &p, &why) == 1); + SAME(p.emulator, "rEden"); + probe_free(&p); + free(reden); + } + /* the report alone: the console's, no machine */ + CHECK(probe_parse(PROBE_JSONL, strlen(PROBE_JSONL), &p, &why) == 1); + SAME(p.emulator, "console"); + CHECK(!p.driver_name && !p.gpu && !p.driver_id); + SAME(p.os, "unknown"); + t = probe_machine(&p); + SAME(t, "the console (a report.jsonl alone names no machine)"); + free(t); + probe_free(&p); + /* two copies of a run (the Share Log's summary.txt has the run's output and its log): the later, each case once; + a run cut short before them is passed over for a whole one */ + { + char* two = rei_format("%s%s%s", PROBE_JSONL, PROBE_LOG, + "[ 9.00] [game] {\"type\":\"note\",\"text\":" + "\"edenprobe 0.8.0 (v0.8.0) starting\"}\n"); + CHECK(probe_parse(two, strlen(two), &p, &why) == 1); + SAME(p.version, "0.9.0"); + SAME(p.emulator, "ScarletNX"); + CHECK(p.ncases == 6 && p.whole); + probe_free(&p); + free(two); + } + /* a run without its summary: what it has, counted from its lines */ + { + char* part = rei_format("%.*s", (int)(strstr(PROBE_LOG, "[ 0.23]") - PROBE_LOG), PROBE_LOG); + CHECK(probe_parse(part, strlen(part), &p, &why) == 1); + CHECK(!p.whole && p.passed == -1 && p.ncases == 6); + t = probe_counts(&p); + SAME(t, "3 passed, 2 failed (astc 1, newsuite 1), 0 skipped, 1 crashed"); + free(t); + probe_free(&p); + free(part); + } + /* a launch that went on with a run: lines with no start */ + { + static const char resumed[] = + "[ 0.20] [game] {\"type\":\"note\",\"text\":\"journal: launch 2 resumes the run; the program ended " + "inside index case \\\"an indexed draw\\\"\"}\n" + "[ 0.21] [game] {\"type\":\"case\",\"suite\":\"clear\",\"name\":\"clear to opaque red\",\"tier\":" + "\"exact\",\"result\":\"pass\",\"detail\":\"\"}\n"; + CHECK(probe_parse(resumed, strlen(resumed), &p, &why) == -1); + HAS(why, "a launch that went on with a run after a crash"); + free(why); + CHECK(probe_parse(LOG, strlen(LOG), &p, &why) == 0 && !why); + } + /* lines that are not edenprobe's are counted, not read */ + { + char* odd = rei_format("%s{\"type\":\"case\",\"suite\":\"clear\",\"name\":\"\",\"result\":\"pass\"}\n" + "{\"type\":\"wobble\"}\n", + PROBE_JSONL); + CHECK(probe_parse(odd, strlen(odd), &p, &why) == 1); + CHECK(p.unread == 2 && p.ncases == 1); + probe_free(&p); + free(odd); + } + /* a case's page name: the same for the same case */ + probe_case_key("astc", "a 4x4 block decodes", digest); + probe_case_key("astc", "a 4x4 block decodes", other); + SAME(digest, other); + CHECK(strlen(digest) == 16); + probe_case_key("astc", "a 4x4 block decode", other); + CHECK(strcmp(digest, other) != 0); + for (i = 0; i < 16; ++i) CHECK(isxdigit((unsigned char)digest[i])); + /* .jsonl is a log's name now */ + CHECK(tr_kind("report.jsonl", "") == TR_LOG); + t = tr_unpacked_name("report.jsonl.gz"); + SAME(t, "report.jsonl"); + free(t); +} + +/* a zip of several files, each name and text, written by libarchive into out (64 KiB) */ +static size_t zipped(char* out, size_t cap, const char* const* names, const char* const* texts, int n) { + struct archive* a = archive_write_new(); + size_t used = 0; + int i; + archive_write_set_format_zip(a); + archive_write_open_memory(a, out, cap, &used); + for (i = 0; i < n; ++i) { + struct archive_entry* e = archive_entry_new(); + archive_entry_set_pathname(e, names[i]); + archive_entry_set_size(e, (la_int64_t)strlen(texts[i])); + archive_entry_set_filetype(e, AE_IFREG); + archive_entry_set_perm(e, 0644); + archive_write_header(a, e); + archive_write_data(a, texts[i], strlen(texts[i])); + archive_entry_free(e); + } + archive_write_close(a); + archive_write_free(a); + return used; +} + +/* the run in a Share Log zip: the entry that holds it, though other logs come first */ +static void test_probe_zip(void) { + static char zip[1 << 16]; + char* part = rei_format("%.*s", (int)(strstr(PROBE_LOG, "[ 0.23]") - PROBE_LOG), PROBE_LOG); + const char* names[] = {"summary.txt", "launcher/scarletnx-console-2026-11-07.log", "games/edenprobe/edenprobe.log", + "games/edenprobe/edenprobe-old.log"}; + const char* texts[] = {"== summary ==\nnothing here\n", LOG, PROBE_LOG, part}; + Buf out = {0}; + char* why; + size_t n = zipped(zip, sizeof zip, names, texts, 4); + CHECK(!tr_unpack("scarletnx-logs-2026-11-07.zip", zip, n, TR_LOG_MAX, &out, &why)); + CHECK(out.len == strlen(PROBE_LOG) && !memcmp(out.text, PROBE_LOG, out.len)); + /* a run begun and no whole one: that one, before the first .log */ + texts[2] = "no run here\n"; + n = zipped(zip, sizeof zip, names, texts, 4); + CHECK(!tr_unpack("logs.zip", zip, n, TR_LOG_MAX, &out, &why)); + CHECK(out.len == strlen(part) && !memcmp(out.text, part, out.len)); + /* no run at all: the first .log, .txt or .jsonl as before */ + texts[3] = "nor here\n"; + n = zipped(zip, sizeof zip, names, texts, 4); + CHECK(!tr_unpack("logs.zip", zip, n, TR_LOG_MAX, &out, &why)); + SAME(out.text, "== summary ==\nnothing here\n"); + buf_free(&out); + free(part); +} + +/* whole runs sent as reports: kept with their cases, the details that name the player left out of the database and + the log, answered with the counts, never twice from one person, gone with their message */ +static void test_probe_reports(void) { + TrMessage m; + char *t, *p, *rel, *why; + long id, eden, console; + StReport r; + Probe run; + StGame* games; + int ngames, i; + serve("https://cdn.discordapp.com/20/edenprobe.log", PROBE_LOG, strlen(PROBE_LOG)); + serve("https://cdn.discordapp.com/20/eden_log.txt", EDEN_LOG, strlen(EDEN_LOG)); + serve("https://cdn.discordapp.com/20/report.jsonl", PROBE_JSONL, strlen(PROBE_JSONL)); + m = message(9600, 960, "<@99> my run"); + attach(&m, "edenprobe.log", "https://cdn.discordapp.com/20/edenprobe.log", (double)strlen(PROBE_LOG)); + t = answer_text(respond(&m)); + HAS(t, "edenprobe 0.9.0 on radv, Mesa 26.1.8 (Linux): 3 passed, 2 failed (astc 1, newsuite 1), 0 skipped, 1 " + "crashed"); + HAS(t, "Report #"); + HAS(t, ": edenprobe 0.9.0 on ScarletNX"); + HAS(t, "the detail of 3 service, net and pad cases and 1 net notes, which can name the player"); + HAS(t, "main 1234abc"); + free(t); + tr_message_free(&m); + id = st_by_message(tracer.store, 9600); + CHECK(id > 0); + CHECK(st_get(tracer.store, id, &r, NULL, NULL) == 1); + SAME(r.key, PROBE_KEY); + SAME(r.title, "edenprobe 0.9.0 on ScarletNX"); + SAME(r.version, "0.9.0"); + SAME(r.driver, "26.1.8"); + SAME(r.commit, "1234abc"); + st_report_free(&r); + CHECK(st_probe_get(tracer.store, id, &run, 1) == 1); + CHECK(run.ncases == 6 && run.driver_id == 3 && run.cut_cases == 3 && run.cut_notes == 1); + SAME(run.words, "cpu graphics net notime"); + for (i = 0; i < run.ncases; ++i) + if (!strcmp(run.cases[i].suite, "account") || !strcmp(run.cases[i].suite, "nifm") || + !strcmp(run.cases[i].suite, "newsuite")) + SAME(run.cases[i].detail, ""); + else if (!strcmp(run.cases[i].suite, "index")) + SAME(run.cases[i].reason, "crashed"); + probe_free(&run); + /* the kept log says nothing of the player either */ + rel = rei_format("r/%ld/1.log", id); + p = page(rel); + LACKS(p, "nickname Someone"); + LACKS(p, "tok-abcdef"); + LACKS(p, "192.168"); + HAS(p, "texel 0 reads 00ff00ff"); + free(p); + free(rel); + /* no game's: the games and the lists leave it out */ + CHECK(!st_games(tracer.store, &games, &ngames)); + for (i = 0; i < ngames; ++i) CHECK(strcmp(games[i].key, PROBE_KEY) != 0); + st_games_free(games, ngames); + p = page("all.html"); + rel = rei_format("href=\"r/%ld/\"", id); + LACKS(p, rel); + free(p); + p = page("api/reports.json"); + LACKS(p, "edenprobe 0.9.0 on ScarletNX"); + free(p); + free(rel); + /* the same run again from the same person: its link, nothing kept; from another person, a report of its own */ + m = message(9601, 960, "<@99> again"); + attach(&m, "edenprobe.log", "https://cdn.discordapp.com/20/edenprobe.log", (double)strlen(PROBE_LOG)); + t = answer_text(respond(&m)); + rel = rei_format("This run of edenprobe is report #%ld already", id); + HAS(t, rel); + free(rel); + free(t); + CHECK(!st_by_message(tracer.store, 9601)); + tr_message_free(&m); + m = message(9602, 961, "<@99> mine too"); + attach(&m, "edenprobe.log", "https://cdn.discordapp.com/20/edenprobe.log", (double)strlen(PROBE_LOG)); + t = answer_text(respond(&m)); + HAS(t, "3 passed, 2 failed"); + free(t); + tr_message_free(&m); + CHECK(st_by_message(tracer.store, 9602) > id); + /* Eden's log, and the report alone */ + m = message(9603, 962, "<@99>"); + attach(&m, "eden_log.txt", "https://cdn.discordapp.com/20/eden_log.txt", (double)strlen(EDEN_LOG)); + t = answer_text(respond(&m)); + HAS(t, "edenprobe 0.9.0 on NVIDIA 580.95.5.0, driver ID inferred (Windows): 0 passed, 1 failed (astc 1)"); + HAS(t, "Eden logs no driver ID: it is read from the driver's name."); + free(t); + tr_message_free(&m); + eden = st_by_message(tracer.store, 9603); + CHECK(st_get(tracer.store, eden, &r, NULL, NULL) == 1); + SAME(r.build, "Eden | HEAD-4534fde3aa-HEAD (Vulkan)"); + SAME(r.gpu, "Some GeForce 9000"); + SAME(r.driver, "580.95.05"); + CHECK(!r.outcome && !r.commit); + st_report_free(&r); + m = message(9604, 963, "<@99> from my console"); + attach(&m, "report.jsonl", "https://cdn.discordapp.com/20/report.jsonl", (double)strlen(PROBE_JSONL)); + t = answer_text(respond(&m)); + HAS(t, "edenprobe 0.9.0 on the console (a report.jsonl alone names no machine): 1 passed, 0 failed, 0 skipped"); + HAS(t, "kept as the console's reference"); + free(t); + tr_message_free(&m); + console = st_by_message(tracer.store, 9604); + CHECK(console > 0); + /* gone with its message: its run and cases with it */ + CHECK(tr_forget(&tracer, 9604)); + CHECK(st_probe_get(tracer.store, console, &run, 1) == 0); + { + StProbeResult* results; + int nresults, left = 0; + CHECK(!st_probe_results(tracer.store, &results, &nresults)); + for (i = 0; i < nresults; ++i) left += results[i].report == console; + CHECK(left == 0 && nresults == 6 + 6 + 1); + free(results); + } + /* a launch that went on after a crash: kept as the game's log, said not to be a run */ + { + static char resumed[sizeof LOG + 512]; + snprintf(resumed, sizeof resumed, "%s%s", LOG, + "[ 2.30] [game] {\"type\":\"note\",\"text\":\"journal: launch 2 resumes the run\"}\n" + "[ 2.31] [game] {\"type\":\"case\",\"suite\":\"clear\",\"name\":\"clear to opaque red\",\"tier\":" + "\"exact\",\"result\":\"pass\",\"detail\":\"\"}\n"); + serve("https://cdn.discordapp.com/20/resumed.log", resumed, strlen(resumed)); + m = message(9605, 964, "<@99>"); + attach(&m, "resumed.log", "https://cdn.discordapp.com/20/resumed.log", 10); + t = answer_text(respond(&m)); + HAS(t, "Report #"); + HAS(t, "Not a run of edenprobe"); + HAS(t, "resumed.log: its edenprobe lines are a launch that went on with a run after a crash"); + free(t); + tr_message_free(&m); + CHECK(st_get(tracer.store, st_by_message(tracer.store, 9605), &r, NULL, NULL) == 1); + SAME(r.key, "0100AAAABBBB0000"); + st_report_free(&r); + } + /* through a worker: the run in its answer, checked, the same as one read here */ + serve_file("https://cdn.discordapp.com/21/edenprobe.log", PROBE_LOG, strlen(PROBE_LOG)); + tracer.take = test_worker_take; + worker_argv[1] = "--report"; + m = message(9606, 965, "<@99> through the worker"); + attach(&m, "edenprobe.log", "https://cdn.discordapp.com/21/edenprobe.log", 10); + t = answer_text(respond(&m)); + HAS(t, "edenprobe 0.9.0 on radv, Mesa 26.1.8 (Linux): 3 passed, 2 failed"); + HAS(t, "the detail of 3 service, net and pad cases"); + free(t); + tr_message_free(&m); + tracer.take = NULL; + CHECK(st_probe_get(tracer.store, st_by_message(tracer.store, 9606), &run, 1) == 1); + CHECK(run.ncases == 6 && run.cut_cases == 3); + probe_free(&run); + CHECK(waiting_files() == 0); + (void)why; +} + +/* a report kept before Tracer knew runs of edenprobe: the next start makes it the run's, its log cut */ +static void test_probe_rescan(void) { + StReport r; + StFile f; + Probe run; + char *rel, *p; + StReport* all; + int n; + memset(&r, 0, sizeof r); + memset(&f, 0, sizeof f); + r.when = now_is; + r.message = 9700; + r.poster = 970; + r.key = "0100000000001000"; + r.title = "edenprobe"; + r.named = 1; + f.n = 1; + strcpy(f.kind, "log"); + f.name = "edenprobe.log"; + f.path = "1.log"; + f.bytes = (double)strlen(PROBE_LOG); + CHECK(!st_add(tracer.store, &r, &f, 1)); + rel = rei_format("r/%ld/1.log", r.id); + CHECK(!site_write(site, rel, PROBE_LOG, strlen(PROBE_LOG))); + CHECK(!st_reports(tracer.store, NULL, &all, &n)); + st_reports_free(all, n); + CHECK(tr_rescan(&tracer, "probe rescan") == n); + CHECK(st_probe_get(tracer.store, r.id, &run, 1) == 1); + CHECK(run.ncases == 6); + SAME(run.emulator, "ScarletNX"); + probe_free(&run); + { + StReport now; + CHECK(st_get(tracer.store, r.id, &now, NULL, NULL) == 1); + SAME(now.key, PROBE_KEY); + SAME(now.title, "edenprobe 0.9.0 on ScarletNX"); + SAME(now.driver, "26.1.8"); + st_report_free(&now); + } + p = page(rel); + LACKS(p, "nickname Someone"); + HAS(p, "texel 0 reads 00ff00ff"); + free(p); + free(rel); +} + int main(int argc, char** argv) { char *db, *command; if (argc == 2) return as_worker(argv[1]); @@ -2885,6 +3431,9 @@ int main(int argc, char** argv) { test_public_log(); test_channels(); test_game(); + test_probe_parts(); + test_probe_lines(); + test_probe_zip(); if (tracer.store) { test_reports(); test_mcp(); @@ -2903,6 +3452,8 @@ int main(int argc, char** argv) { test_issues(); test_age(); test_archive_download(); + test_probe_reports(); + test_probe_rescan(); } st_close(tracer.store); if (getenv("TRACER_TEST_KEEP")) fprintf(stderr, "kept %s\n", site); From fe0d74fccbfdf4059b13a6bad0a8796cf209ecdf Mon Sep 17 00:00:00 2001 From: AO55 Date: Sat, 7 Nov 2026 23:48:44 -0300 Subject: [PATCH 2/4] [tracer] Ban candidates, ScarletNX's own failures and regressions Fixed rules over the runs of edenprobe: a case that fails on one driver's range of versions for several people and passes on other drivers is a candidate for ScarletNX's ban table, with a draft line in its format; one that fails on most drivers is ScarletNX's own; one that a build broke on a driver is a regression. The tests sit on each threshold, and a mutant run in CI changes the rules one way at a time to check they would notice. Signed-off-by: AO55 --- .github/workflows/test.yml | 1 + docs/TESTING.md | 15 +- docs/TRACER.md | 33 +++ scripts/test-rule-mutants.py | 157 +++++++++++ tracer/Makefile | 6 +- tracer/src/rules.c | 524 +++++++++++++++++++++++++++++++++++ tracer/src/rules.h | 95 +++++++ tracer/tests/test_tracer.c | 290 +++++++++++++++++++ 8 files changed, 1117 insertions(+), 4 deletions(-) create mode 100755 scripts/test-rule-mutants.py create mode 100644 tracer/src/rules.c create mode 100644 tracer/src/rules.h diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1a5d4a0..ed0a680 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,6 +22,7 @@ jobs: - run: sudo apt-get update -qq && sudo apt-get install -y -qq libcurl4-openssl-dev libsqlite3-dev libarchive-dev zlib1g-dev - run: make -C accordwimsy test - run: make -C tracer test + - run: python3 scripts/test-rule-mutants.py - run: sh scripts/test-install.sh - run: python3 scripts/test-check-docs.py - run: python3 scripts/check-docs.py diff --git a/docs/TESTING.md b/docs/TESTING.md index 948d746..a724b75 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -17,7 +17,7 @@ What CI runs on each pull request and each push to main (`.github/workflows/test.yml`), with no network and no Discord: - make -C rei test && make -C accordwimsy test && make -C tracer test && + make -C rei test && make -C accordwimsy test && make -C tracer test && python3 scripts/test-rule-mutants.py && sh scripts/test-install.sh && python3 scripts/test-check-docs.py && python3 scripts/check-docs.py && sh scripts/test-check-theme.sh && sh scripts/check-theme.sh @@ -82,7 +82,18 @@ temporary folder: none); the run in a Share Log zip, a run begun, none; whole runs as reports (the reply's counts and what was left out, the database and the kept log without the player, no game's list, the same run again from one person and from another, Eden's and the console's, deleted with their message, a resumed launch kept as a log, one through the - worker), and a report kept before made the run's at the next start. + worker), and a report kept before made the run's at the next start; +- the rules over the runs ([What the runs say together](./TRACER.md#what-the-runs-say-together)), on fixtures that sit + on each threshold: a candidate and its draft line, and none with one person, two failing reports, one other driver, + two passing reports, a passing build eight days before or after (seven count), a failure Eden's or of another mode; + a mixed end, no end, a range a passing version splits, another system's runs apart, the extensions every failing + run has; ScarletNX's own failure on three drivers of five (no candidate then) and on both of two, and none on one or + with a driver that passes; a regression, and none when the newest build passes once, the build before fails once, + or a published build after passes, a `-dirty` one left out. + +`python3 scripts/test-rule-mutants.py` then changes `tracer/src/rules.c` one way at a time in a copy of the tree (a +threshold one off, a comparison that lets one more in, a condition left out: 19 mutants) and expects `test_tracer +--rules` to fail on each; a mutant it passes, or one whose text `rules.c` no longer has, fails it. About 10 s. ## The docs diff --git a/docs/TRACER.md b/docs/TRACER.md index 1b73051..5556444 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -15,6 +15,7 @@ * [Commands](#commands) * [Issues](#issues) * [How old a build is](#how-old-a-build-is) +* [What the runs say together](#what-the-runs-say-together) * [What it keeps of people](#what-it-keeps-of-people) * [The site](#the-site) * [Settings](#settings) @@ -200,6 +201,38 @@ hour, as main and the nightlies move. There is no line for a build that has ever nightly, one without git, or when GitHub does not answer (said in the log, and asked again at the next report). Without the token nothing is asked, and only a `-dirty` build is said. +## What the runs say together + +Fixed rules over the runs of edenprobe (`tracer/src/rules.c`), each comparing one case of one edenprobe version run +with the same words, and counting ScarletNX's runs; Eden's are shown beside them, as a second emulator failing a case +on the same driver points at the driver. A case fails where its result is `fail`; a skip, a crash among them, says +nothing. Nothing here is applied: a person reads it and decides. + +- **A ban candidate**, for a case on a driver (its VkDriverId) and a system's family, when all three hold: + 1. it fails in 3 reports or more, from 2 people or more, in a range of that driver's versions: the versions seen in a + row, sorted, where it fails and never passes; + 2. it passes in 3 reports or more of 2 other drivers or more, whose builds are at most 7 days from a failing + report's (the day the build's commit was made, else the day the report came): without that, the failure is + ScarletNX's; + 3. the range runs from its lowest version to the next version seen above it, where the case passes (or passes and + fails: a mixed end, said so), or has no end when none is seen: failing on 26.1.0 to 26.1.8 and passing on 26.2.0 + is `>= 26.1.0 < 26.2.0`. + + With it come the reports, the people, Eden's runs of the case on that driver, the optional extensions every failing + run's log lists as on (`vulkan: optional extensions on: ...`, where the runtime logs that line), and a draft line in + the ban table's format (ScarletNX's `src/nx/gpu/vk/extension_bans.txt`), its key `` for a person to choose, as + the runs cannot say which extension or feature breaks: + + | off | radv | >= 26.1.0 < 26.2.0 | linux | * | fails edenprobe's astc case "..." | Tracer #12, #15, #18; edenprobe 0.9.0 "..." | edenprobe:astc: ... | 2026-11-07 broken on 26.1.8 | - + +- **ScarletNX's own failure**: a case that fails on 3 drivers or more, or on every driver seen when two or more are; a + driver counts as failing when its runs fail the case and none passes it. Such a case is no ban candidate. Eden's + runs on those drivers are counted beside it: where Eden passes it, the failure is ScarletNX's to fix. +- **A regression**: on one driver, one version of it and one system's family, a case that passed in every run of a + build and fails in every run of each build after it, to the newest; builds of published commits only (no `-dirty`), + in the order of their commits' days. The last build that passed and the first that failed bound the commits to look + at. + ## What it keeps of people The site does not say who sent a report. The database keeps the sender's user id (for the deletion, the updates and diff --git a/scripts/test-rule-mutants.py b/scripts/test-rule-mutants.py new file mode 100755 index 0000000..afa1737 --- /dev/null +++ b/scripts/test-rule-mutants.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-or-later +# Copyright 2026 the ScarletNX contributors +"""Tracer's rules over the runs of edenprobe (tracer/src/rules.c) changed one way at a time, each change a mutant that +its tests (tracer/tests/test_tracer.c's test_rules, run as test_tracer --rules) must fail: a threshold one off, a +comparison that lets one more in, a condition left out. A mutant the tests pass is a rule nothing holds. Each runs in +a copy of the tree in a temporary folder; the checkout is never written. + + python3 scripts/test-rule-mutants.py [--root DIR] [--cc CC] + +Exit 0 when every mutant was caught; 1 when one survived, or one's text is no longer in rules.c (said with which).""" + +import argparse +import os +import shutil +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +# each mutant: what it does, the text of rules.c it changes (found once), and what it becomes +MUTANTS = ( + ( + 'two failing reports make a candidate', + 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE)', + 'if (fails < RULE_FAIL_REPORTS - 1 || people < RULE_FAIL_PEOPLE)', + ), + ( + 'one person makes a candidate', + 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE)', + 'if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE - 1)', + ), + ( + 'each failing report is another person', + 'for (k = 0; k < people && posters[k] != who; ++k) continue;', + 'k = people;', + ), + ( + 'two passing reports clear the driver', + 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS)', + 'if (npass < RULE_PASS_REPORTS - 1 || drivers < RULE_PASS_DRIVERS)', + ), + ( + 'one other driver clears it', + 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS)', + 'if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS - 1)', + ), + ( + 'a passing build eight days after counts', + 'near = gap <= RULE_DAYS * 86400.0 && gap >= -RULE_DAYS * 86400.0;', + 'near = gap <= (RULE_DAYS + 1) * 86400.0 && gap >= -RULE_DAYS * 86400.0;', + ), + ( + 'a passing build eight days before counts', + 'near = gap <= RULE_DAYS * 86400.0 && gap >= -RULE_DAYS * 86400.0;', + 'near = gap <= RULE_DAYS * 86400.0 && gap >= -(RULE_DAYS + 1) * 86400.0;', + ), + ('the failing driver clears itself', 'run->p.driver_id == d || e[j].result != ST_PASS', 'e[j].result != ST_PASS'), + ('a passing version does not end the range', 'if (vp) break;', 'if (vp && 0) break;'), + ( + 'another system joins the range', + 'if (scarletnx(p) && p->driver_id == d && !strcmp(p->os, os) &&', + 'if (scarletnx(p) && p->driver_id == d && os &&', + ), + ( + "Eden's failures count", + 'if (scarletnx(p) && p->driver_id == d && !strcmp(p->os, os) &&', + 'if (p->driver_id == d && !strcmp(p->os, os) &&', + ), + ('a mixed end is not said', 'c->mixed |= c->high && on[j].result == ST_FAIL;', 'c->mixed |= 0;'), + ( + "four drivers make it ScarletNX's", + 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 2 && failing == nd)))', + 'if (!(failing >= RULE_GENERAL_DRIVERS + 1 || (nd >= 2 && failing == nd)))', + ), + ( + "one driver seen makes it ScarletNX's", + 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 2 && failing == nd)))', + 'if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 1 && failing == nd)))', + ), + ( + "Eden's drivers count as seen", + 'if (!scarletnx(p) || p->driver_id <= 0 || (e[i].result != ST_PASS', + 'if (p->driver_id <= 0 || (e[i].result != ST_PASS', + ), + ( + "ScarletNX's own failure is a candidate too", + 'if (!general(out, &gcap, results[i].name, e + a, b - a))', + 'if (general(out, &gcap, results[i].name, e + a, b - a) || 1)', + ), + ( + 'a build that passes and fails passed', + 'if (last >= 0 && last < nb - 1 && b[last].passes && !b[last].fails)', + 'if (last >= 0 && last < nb - 1 && b[last].passes)', + ), + ( + 'a newest build that passes once fails', + 'last >= 0 && b[last].fails && !b[last].passes; --last', + 'last >= 0 && b[last].fails; --last', + ), + ( + 'a -dirty build is a build', + 'strcmp(q->os, p->os) || !published(q->commit) || q->built <= 0 ||', + 'strcmp(q->os, p->os) || !published(q->commit ? "0000000" : NULL) || q->built <= 0 ||', + ), +) + + +def run(cmd, cwd): + return subprocess.run(cmd, check=False, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + + +def main(): + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument('--root', type=Path, default=ROOT, help='the tree (the checkout this script is in)') + ap.add_argument('--cc', default=os.environ.get('CC', 'cc'), help='the compiler (CC, else cc)') + args = ap.parse_args() + with tempfile.TemporaryDirectory(prefix='tracer-mutants-') as tmp: + tree = Path(tmp) + for part in ('rei', 'tracer'): + shutil.copytree( + args.root / part, + tree / part, + ignore=shutil.ignore_patterns('*.o', 'test_tracer', 'tracer', 'tracer-mcp'), + ) + work = tree / 'tracer' + rules = work / 'src' / 'rules.c' + original = rules.read_text() + make = ['make', '-s', 'tests/test_tracer', 'CC=' + args.cc, 'CFLAGS=-O0 -g'] + built = run(make, work) + if built.returncode or run(['./tests/test_tracer', '--rules'], work).returncode: + print('the tree as it is does not build or pass its rules tests:\n' + built.stdout, file=sys.stderr) + return 1 + failed = 0 + for what, old, new in MUTANTS: + if original.count(old) != 1: + print(f'stale: {what}: rules.c has "{old}" {original.count(old)} times, not once') + failed = 1 + continue + rules.write_text(original.replace(old, new)) + built = run(make, work) + if built.returncode: + print(f'stale: {what}: the mutant does not build:\n{built.stdout}') + failed = 1 + elif run(['./tests/test_tracer', '--rules'], work).returncode: + print(f'killed: {what}') + else: + print(f'SURVIVED: {what}') + failed = 1 + rules.write_text(original) + print(f'{len(MUTANTS)} mutants, {"one or more left" if failed else "every one caught"}') + return failed + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tracer/Makefile b/tracer/Makefile index b49e751..f3f1042 100644 --- a/tracer/Makefile +++ b/tracer/Makefile @@ -31,8 +31,8 @@ DEFS = -D_POSIX_C_SOURCE=200809L -DREI_NAME=\"tracer\" -DTR_LOGSCAN=\"`cat $(LOG OURS = $(WARN) $(DEFS) -Isrc -I$(REI)/src -I$(REI)/third_party/cjson -Ithird_party/logscan LIBS = $(SQLITE_LIBS) $(ARCHIVE_LIBS) $(ZLIB_LIBS) $(CXXRT) -lpthread -lm -LOGIC = src/message.o src/files.o src/probe.o src/store.o src/site.o src/report.o src/titles.o src/channels.o \ - src/worker.o src/issues.o src/age.o src/mcp.o src/rei_util.o third_party/cjson.o third_party/logscan.o \ +LOGIC = src/message.o src/files.o src/probe.o src/rules.o src/store.o src/site.o src/report.o src/titles.o \ + src/channels.o src/worker.o src/issues.o src/age.o src/mcp.o src/rei_util.o third_party/cjson.o third_party/logscan.o \ third_party/demangle.o all: tracer tracer-mcp @@ -62,6 +62,8 @@ src/files.o: src/files.c src/files.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/files.c src/probe.o: src/probe.c src/probe.h src/files.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/probe.c +src/rules.o: src/rules.c src/rules.h src/store.h src/probe.h src/tracer.h + $(CC) $(CFLAGS) $(OURS) -c -o $@ src/rules.c src/store.o: src/store.c src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) $(SQLITE_CFLAGS) -c -o $@ src/store.c src/site.o: src/site.c src/site.h src/files.h src/store.h src/probe.h src/tracer.h diff --git a/tracer/src/rules.c b/tracer/src/rules.c new file mode 100644 index 0000000..ff5e266 --- /dev/null +++ b/tracer/src/rules.c @@ -0,0 +1,524 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + Copyright 2026 the ScarletNX contributors */ +#include "rules.h" +#include +#include +#include +#include + +/* a case's result in one run: the run's index in the runs given, ST_* */ +typedef struct { + int run, result; +} Entry; + +/* the runs the comparators read, for one rules_make at a time */ +static const StProbeRun* g_rules; + +static void* grown(void* p, int n, int* cap, size_t size) { + if (n < *cap) return p; + *cap = *cap ? *cap * 2 : 16; + p = realloc(p, (size_t)*cap * size); + if (!p) { + fputs(REI_NAME ": out of memory\n", stderr); + abort(); + } + return p; +} +static int text_cmp(const char* a, const char* b) { return strcmp(a ? a : "", b ? b : ""); } +/* qsort, for n of 2 or more: an empty array may be NULL, which qsort may not be given */ +static void sorted(void* p, int n, size_t size, int (*cmp)(const void*, const void*)) { + if (n > 1) qsort(p, (size_t)n, size, cmp); +} +static int scarletnx(const Probe* p) { return !strcmp(p->emulator, "ScarletNX"); } +/* Eden, rEden: another emulator, on a machine its log names */ +static int other(const Probe* p) { return !scarletnx(p) && strcmp(p->emulator, "console") && p->driver_id > 0; } +/* the day a run's build was made, else the day it came */ +static double build_day(const StProbeRun* r) { return r->p.built > 0 ? r->p.built : r->when; } +static long report_of(const Entry* e) { return g_rules[e->run].report; } + +/* by edenprobe's version and words, then by report */ +static int by_mode(const void* a, const void* b) { + const Entry *x = a, *y = b; + const Probe *p = &g_rules[x->run].p, *q = &g_rules[y->run].p; + int c = text_cmp(p->version, q->version); + if (!c) c = text_cmp(p->words, q->words); + if (!c) c = report_of(x) < report_of(y) ? -1 : report_of(x) > report_of(y); + return c; +} +static int same_mode(const Entry* x, const Entry* y) { + const Probe *p = &g_rules[x->run].p, *q = &g_rules[y->run].p; + return !text_cmp(p->version, q->version) && !text_cmp(p->words, q->words); +} +/* by the driver's version, then by report */ +static int by_version(const void* a, const void* b) { + const Entry *x = a, *y = b; + unsigned long v = g_rules[x->run].p.driver_version, w = g_rules[y->run].p.driver_version; + if (v != w) return v < w ? -1 : 1; + return report_of(x) < report_of(y) ? -1 : report_of(x) > report_of(y); +} +static int by_long(const void* a, const void* b) { + long x = *(const long*)a, y = *(const long*)b; + return x < y ? -1 : x > y; +} + +/* ---- ScarletNX's own failures ---- */ + +/* the drivers of ScarletNX's runs among e[0..n): each one's id, and how many of its runs fail and pass */ +typedef struct { + int id, fails, passes; +} Driver; +static int drivers_of(const Entry* e, int n, Driver** out) { + Driver* d = NULL; + int nd = 0, cap = 0, i, k; + for (i = 0; i < n; ++i) { + const Probe* p = &g_rules[e[i].run].p; + if (!scarletnx(p) || p->driver_id <= 0 || (e[i].result != ST_PASS && e[i].result != ST_FAIL)) continue; + for (k = 0; k < nd && d[k].id != p->driver_id; ++k) continue; + if (k == nd) { + d = grown(d, nd, &cap, sizeof *d); + d[nd].id = p->driver_id; + d[nd].fails = d[nd].passes = 0; + ++nd; + } + d[k].fails += e[i].result == ST_FAIL; + d[k].passes += e[i].result == ST_PASS; + } + *out = d; + return nd; +} +static int failing_driver(const Driver* d) { return d->fails > 0 && d->passes == 0; } + +/* e[0..n), one case of one version and words: its failure, when it is ScarletNX's own, added to r. 1 when it is */ +static int general(Rules* r, int* cap, int name, const Entry* e, int n) { + Driver* d; + int nd = drivers_of(e, n, &d), failing = 0, i, k, rcap = 0; + RuleGeneral* g; + for (k = 0; k < nd; ++k) failing += failing_driver(&d[k]); + if (!(failing >= RULE_GENERAL_DRIVERS || (nd >= 2 && failing == nd))) { + free(d); + return 0; + } + r->general = grown(r->general, r->ngeneral, cap, sizeof *r->general); + g = &r->general[r->ngeneral++]; + memset(g, 0, sizeof *g); + g->name = name; + g->version = g_rules[e[0].run].p.version; + g->words = g_rules[e[0].run].p.words; + g->seen = nd; + g->drivers = malloc((size_t)failing * sizeof *g->drivers); + if (!g->drivers) abort(); + for (k = 0; k < nd; ++k) + if (failing_driver(&d[k])) g->drivers[g->ndrivers++] = d[k].id; + for (i = 0; i < n; ++i) { + const Probe* p = &g_rules[e[i].run].p; + int on = 0; + for (k = 0; k < g->ndrivers; ++k) on |= g->drivers[k] == p->driver_id; + if (!on) continue; + if (scarletnx(p) && e[i].result == ST_FAIL) { + g->reports = grown(g->reports, g->nreports, &rcap, sizeof *g->reports); + g->reports[g->nreports++] = report_of(&e[i]); + } else if (other(p) && (e[i].result == ST_PASS || e[i].result == ST_FAIL)) { + ++g->eden_runs; + g->eden_pass += e[i].result == ST_PASS; + } + } + sorted(g->reports, g->nreports, sizeof *g->reports, by_long); + free(d); + return 1; +} + +/* ---- ban candidates ---- */ + +/* whether list (comma separated, spaces around each name) has the name of n bytes at name */ +static int listed(const char* list, const char* name, size_t n) { + while (*list) { + size_t len; + while (*list == ' ') ++list; + len = strcspn(list, ","); + while (len && list[len - 1] == ' ') --len; + if (len == n && !memcmp(list, name, n)) return 1; + list += strcspn(list, ","); + if (*list == ',') ++list; + } + return 0; +} +/* the extensions every one of the runs names as on, comma separated; NULL when one names none */ +static char* common_extensions(const Entry* e, int n) { + Buf b = {0}; + const char* s; + int i; + if (!n) return NULL; + for (i = 0; i < n; ++i) + if (!g_rules[e[i].run].p.extensions) return NULL; + for (s = g_rules[e[0].run].p.extensions; *s;) { + size_t len; + int all = 1; + while (*s == ' ') ++s; + len = strcspn(s, ","); + while (len && s[len - 1] == ' ') --len; + for (i = 1; i < n && all && len; ++i) all = listed(g_rules[e[i].run].p.extensions, s, len); + if (all && len) buf_printf(&b, "%s%.*s", b.len ? ", " : "", (int)len, s); + s += strcspn(s, ","); + if (*s == ',') ++s; + } + return buf_take(&b); +} + +static int by_double(const void* a, const void* b) { + double x = *(const double*)a, y = *(const double*)b; + return x < y ? -1 : x > y; +} +/* whether day is RULE_DAYS days or less from one of the n days (sorted): the nearest are the two on either side */ +static int near_day(double day, const double* days, int n) { + int lo = 0, hi = n, k, near = 0; + while (lo < hi) { + int mid = (lo + hi) / 2; + if (days[mid] < day) + lo = mid + 1; + else + hi = mid; + } + for (k = lo - 1; k <= lo && !near; ++k) { + double gap; + if (k < 0 || k >= n) continue; + gap = day - days[k]; + near = gap <= RULE_DAYS * 86400.0 && gap >= -RULE_DAYS * 86400.0; + } + return near; +} + +/* e[0..n), one case of one version and words, ScarletNX's failure of it on driver d and system's family os: its + candidates, a range of versions each, added to r */ +static void candidates_on(Rules* r, int* cap, int name, const Entry* e, int n, int d, const char* os) { + Entry* on = NULL; /* ScarletNX's runs on the driver and system that passed or failed, by version */ + int non = 0, oncap = 0, i, k; + for (i = 0; i < n; ++i) { + const Probe* p = &g_rules[e[i].run].p; + if (scarletnx(p) && p->driver_id == d && !strcmp(p->os, os) && + (e[i].result == ST_PASS || e[i].result == ST_FAIL)) { + on = grown(on, non, &oncap, sizeof *on); + on[non++] = e[i]; + } + } + sorted(on, non, sizeof *on, by_version); + for (i = 0; i < non;) { + int start = i, end, fails = 0, j, people = 0, npass = 0, pcap = 0, fcap = 0, drivers = 0; + unsigned long v = g_rules[on[i].run].p.driver_version; + long *pass = NULL, *fail = NULL; + int *pass_driver = NULL, dcap = 0, wcap = 0; + u64* posters = NULL; + double* days; + RuleCandidate* c; + double newest = 0; + char low[32], high[32], top[32]; + /* the range: the versions in a row where it fails and never passes */ + for (end = i; end < non;) { + int vf = 0, vp = 0, at = end; + unsigned long w = g_rules[on[end].run].p.driver_version; + while (at < non && g_rules[on[at].run].p.driver_version == w) { + vf += on[at].result == ST_FAIL; + vp += on[at].result == ST_PASS; + ++at; + } + if (vp) break; + fails += vf; + end = at; + } + if (end == start) { /* a version where it passes: past it */ + while (i < non && g_rules[on[i].run].p.driver_version == v) ++i; + continue; + } + i = end; + for (j = start; j < end; ++j) { /* the people its failures come from */ + u64 who = g_rules[on[j].run].poster; + for (k = 0; k < people && posters[k] != who; ++k) continue; + if (k == people) { + posters = grown(posters, people, &wcap, sizeof *posters); + posters[people++] = who; + } + fail = grown(fail, j - start, &fcap, sizeof *fail); + fail[j - start] = report_of(&on[j]); + if (g_rules[on[j].run].when > newest) newest = g_rules[on[j].run].when; + } + free(posters); + if (fails < RULE_FAIL_REPORTS || people < RULE_FAIL_PEOPLE) { + free(fail); + continue; + } + /* the other drivers' runs that pass, their builds near a failing one's */ + days = malloc((size_t)(end - start) * sizeof *days); + if (!days) abort(); + for (j = start; j < end; ++j) days[j - start] = build_day(&g_rules[on[j].run]); + sorted(days, end - start, sizeof *days, by_double); + for (j = 0; j < n; ++j) { + const StProbeRun* run = &g_rules[e[j].run]; + int m; + if (!scarletnx(&run->p) || run->p.driver_id <= 0 || run->p.driver_id == d || e[j].result != ST_PASS) + continue; + if (!near_day(build_day(run), days, end - start)) continue; + pass = grown(pass, npass, &pcap, sizeof *pass); + pass[npass++] = run->report; + for (m = 0; m < drivers && pass_driver[m] != run->p.driver_id; ++m) continue; + if (m == drivers) { + pass_driver = grown(pass_driver, drivers, &dcap, sizeof *pass_driver); + pass_driver[drivers++] = run->p.driver_id; + } + } + free(pass_driver); + free(days); + if (npass < RULE_PASS_REPORTS || drivers < RULE_PASS_DRIVERS) { + free(fail); + free(pass); + continue; + } + r->candidates = grown(r->candidates, r->ncandidates, cap, sizeof *r->candidates); + c = &r->candidates[r->ncandidates++]; + memset(c, 0, sizeof *c); + c->name = name; + c->version = g_rules[e[0].run].p.version; + c->words = g_rules[e[0].run].p.words; + c->driver_id = d; + c->os = g_rules[on[start].run].p.os; + c->low = g_rules[on[start].run].p.driver_version; + c->high = end < non ? g_rules[on[end].run].p.driver_version : 0; + for (j = end; j < non && g_rules[on[j].run].p.driver_version == c->high; ++j) + c->mixed |= c->high && on[j].result == ST_FAIL; + probe_version_text(d, c->low, low, sizeof low); + probe_version_text(d, g_rules[on[end - 1].run].p.driver_version, top, sizeof top); + if (c->high) { + probe_version_text(d, c->high, high, sizeof high); + c->versions = rei_format(">= %s < %s", low, high); + } else + c->versions = rei_format(">= %s", low); + c->broken = rei_strdup(top); + sorted(fail, end - start, sizeof *fail, by_long); + sorted(pass, npass, sizeof *pass, by_long); + c->failing = fail; + c->nfailing = end - start; + c->people = people; + c->passing = pass; + c->npassing = npass; + c->pass_drivers = drivers; + c->newest = newest; + c->extensions = common_extensions(on + start, end - start); + for (j = 0; j < n; ++j) { /* Eden's runs of the case on this driver */ + const Probe* p = &g_rules[e[j].run].p; + if (!other(p) || p->driver_id != d) continue; + c->eden_fail += e[j].result == ST_FAIL; + c->eden_pass += e[j].result == ST_PASS; + } + } + free(on); +} + +static void candidates(Rules* r, int* cap, int name, const Entry* e, int n) { + const Probe** seen = NULL; /* a run of each driver and system ScarletNX fails the case on */ + int i, k, nseen = 0, scap = 0; + for (i = 0; i < n; ++i) { + const Probe* p = &g_rules[e[i].run].p; + if (!scarletnx(p) || p->driver_id <= 0 || e[i].result != ST_FAIL) continue; + for (k = 0; k < nseen && !(seen[k]->driver_id == p->driver_id && !strcmp(seen[k]->os, p->os)); ++k) continue; + if (k < nseen) continue; + seen = grown(seen, nseen, &scap, sizeof *seen); + seen[nseen++] = p; + candidates_on(r, cap, name, e, n, p->driver_id, p->os); + } + free(seen); +} + +/* ---- regressions ---- */ + +/* a commit as builds name a published one: hex digits, no -dirty */ +static int published(const char* commit) { + size_t n = commit ? strlen(commit) : 0, i; + if (n < 7) return 0; + for (i = 0; i < n; ++i) + if (!((commit[i] >= '0' && commit[i] <= '9') || (commit[i] >= 'a' && commit[i] <= 'f'))) return 0; + return 1; +} +typedef struct { + const char* commit; + double day; + long first; /* its first report, to order builds of one day */ + int fails, passes; +} Build; +/* by commit, then report */ +static int by_commit(const void* a, const void* b) { + const Entry *x = a, *y = b; + int c = strcmp(g_rules[x->run].p.commit, g_rules[y->run].p.commit); + return c ? c : report_of(x) < report_of(y) ? -1 : report_of(x) > report_of(y); +} +static int by_build(const void* a, const void* b) { + const Build *x = a, *y = b; + if (x->day != y->day) return x->day < y->day ? -1 : 1; + return x->first < y->first ? -1 : x->first > y->first; +} + +static void regressions(Rules* r, int* cap, int name, const Entry* e, int n) { + const Probe** seen = NULL; /* a run of each driver, version of it and system, once */ + Entry* group = NULL; + int i, k, nseen = 0, scap = 0, gcap = 0; + for (i = 0; i < n; ++i) { + const Probe* p = &g_rules[e[i].run].p; + Build* b = NULL; + int nb = 0, bcap = 0, j, last, ng; + if (!scarletnx(p) || p->driver_id <= 0) continue; + for (k = 0; k < nseen && !(seen[k]->driver_id == p->driver_id && seen[k]->driver_version == p->driver_version && + !strcmp(seen[k]->os, p->os)); + ++k) + continue; + if (k < nseen) continue; + seen = grown(seen, nseen, &scap, sizeof *seen); + seen[nseen++] = p; + for (j = 0, ng = 0; j < n; ++j) { /* the group's runs of published builds that passed or failed */ + const Probe* q = &g_rules[e[j].run].p; + if (!scarletnx(q) || q->driver_id != p->driver_id || q->driver_version != p->driver_version || + strcmp(q->os, p->os) || !published(q->commit) || q->built <= 0 || + (e[j].result != ST_PASS && e[j].result != ST_FAIL)) + continue; + group = grown(group, ng, &gcap, sizeof *group); + group[ng++] = e[j]; + } + sorted(group, ng, sizeof *group, by_commit); + for (j = 0; j < ng; ++j) { /* a build for each commit, the group's runs being by commit */ + const StProbeRun* run = &g_rules[group[j].run]; + if (!nb || strcmp(b[nb - 1].commit, run->p.commit)) { + b = grown(b, nb, &bcap, sizeof *b); + b[nb].commit = run->p.commit; + b[nb].day = run->p.built; + b[nb].first = run->report; + b[nb].fails = b[nb].passes = 0; + ++nb; + } + b[nb - 1].fails += group[j].result == ST_FAIL; + b[nb - 1].passes += group[j].result == ST_PASS; + } + sorted(b, nb, sizeof *b, by_build); + for (last = nb - 1; last >= 0 && b[last].fails && !b[last].passes; --last) continue; + if (last >= 0 && last < nb - 1 && b[last].passes && !b[last].fails) { + RuleRegression* g; + r->regressions = grown(r->regressions, r->nregressions, cap, sizeof *r->regressions); + g = &r->regressions[r->nregressions++]; + memset(g, 0, sizeof *g); + g->name = name; + g->version = p->version; + g->words = p->words; + g->driver_id = p->driver_id; + g->driver_version = p->driver_version; + g->os = p->os; + g->passed_commit = b[last].commit; + g->passed_built = b[last].day; + g->passed_report = b[last].first; + g->failed_commit = b[last + 1].commit; + g->failed_built = b[last + 1].day; + g->failed_report = b[last + 1].first; + g->builds = nb - 1 - last; + } + free(b); + } + free(group); + free(seen); +} + +/* ---- the whole ---- */ + +static int by_report(const void* a, const void* b) { + long x = g_rules[*(const int*)a].report, y = g_rules[*(const int*)b].report; + return x < y ? -1 : x > y; +} + +int rules_make(const StProbeRun* runs, int nruns, const StProbeResult* results, int nresults, Rules* out) { + int *order = malloc((size_t)(nruns ? nruns : 1) * sizeof *order), i, j, gcap = 0, ccap = 0, rcap = 0; + Entry* e = malloc((size_t)(nresults ? nresults : 1) * sizeof *e); + memset(out, 0, sizeof *out); + if (!order || !e) { + free(order); + free(e); + return -1; + } + g_rules = runs; + for (i = 0; i < nruns; ++i) order[i] = i; + sorted(order, nruns, sizeof *order, by_report); + for (i = 0; i < nresults; i = j) { + int n = 0, a, b; + for (j = i; j < nresults && results[j].name == results[i].name; ++j) { /* the case's results, each run's */ + int lo = 0, hi = nruns - 1; + while (lo <= hi) { + int mid = (lo + hi) / 2; + long at = runs[order[mid]].report; + if (at == results[j].report) { + e[n].run = order[mid]; + e[n++].result = results[j].result; + break; + } + if (at < results[j].report) + lo = mid + 1; + else + hi = mid - 1; + } + } + sorted(e, n, sizeof *e, by_mode); + for (a = 0; a < n; a = b) { /* each version and words of edenprobe apart */ + for (b = a; b < n && same_mode(&e[a], &e[b]); ++b) continue; + if (!general(out, &gcap, results[i].name, e + a, b - a)) + candidates(out, &ccap, results[i].name, e + a, b - a); + regressions(out, &rcap, results[i].name, e + a, b - a); + } + } + free(order); + free(e); + g_rules = NULL; + return 0; +} + +void rules_free(Rules* r) { + int i; + for (i = 0; i < r->ncandidates; ++i) { + free(r->candidates[i].versions); + free(r->candidates[i].broken); + free(r->candidates[i].failing); + free(r->candidates[i].passing); + free(r->candidates[i].extensions); + } + for (i = 0; i < r->ngeneral; ++i) { + free(r->general[i].drivers); + free(r->general[i].reports); + } + free(r->candidates); + free(r->general); + free(r->regressions); + memset(r, 0, sizeof *r); +} + +/* text for a field of the ban table: no |, which ends a field, and no line end */ +static void table_text(Buf* b, const char* s) { + for (; s && *s; ++s) buf_addn(b, *s == '|' ? "/" : (*s == '\n' || *s == '\r') ? " " : s, 1); +} + +char* rules_draft(const RuleCandidate* c, const char* suite, const char* name) { + Buf b = {0}; + char day[16]; + time_t t = (time_t)c->newest; + struct tm tm; + int i; + gmtime_r(&t, &tm); + strftime(day, sizeof day, "%Y-%m-%d", &tm); + buf_printf(&b, " | off | %s | %s | %s | * | fails edenprobe's ", + probe_driver_name(c->driver_id) ? probe_driver_name(c->driver_id) : "?", c->versions, + strcmp(c->os, "unknown") ? c->os : "any"); + table_text(&b, suite); + buf_add(&b, " case \""); + table_text(&b, name); + buf_add(&b, "\" | Tracer"); + for (i = 0; i < c->nfailing; ++i) buf_printf(&b, "%s #%ld", i ? "," : "", c->failing[i]); + buf_add(&b, "; edenprobe "); + table_text(&b, c->version); + buf_add(&b, " \""); + table_text(&b, name); + buf_add(&b, "\" | edenprobe:"); + table_text(&b, suite); + buf_add(&b, ": "); + table_text(&b, name); + buf_printf(&b, " | %s broken on %s | -", day, c->broken); + return buf_take(&b); +} diff --git a/tracer/src/rules.h b/tracer/src/rules.h new file mode 100644 index 0000000..4487616 --- /dev/null +++ b/tracer/src/rules.h @@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + Copyright 2026 the ScarletNX contributors */ +/* What the runs of edenprobe say together, by fixed rules (no judgment): the drivers that break a case, as candidates + for ScarletNX's ban table (src/nx/gpu/vk/extension_bans.txt), never applied but by a person; the cases ScarletNX + gets wrong everywhere; and the cases a ScarletNX build broke on a driver. Each compares the same case of the same + edenprobe version run with the same words, and counts ScarletNX's runs; Eden's are shown beside, as a second + emulator failing a case on the same driver points at the driver. + + A ban candidate, for a case on a driver (VkDriverId) and a system's family, when all three hold: + 1. it fails in RULE_FAIL_REPORTS reports or more, from RULE_FAIL_PEOPLE people or more, in a range of that driver's + versions: the versions seen in a row, sorted, where it fails and never passes; + 2. it passes in RULE_PASS_REPORTS reports or more of RULE_PASS_DRIVERS other drivers or more, whose builds are at + most RULE_DAYS days from a failing report's (the day the build's commit was made, else the day the report came): + without that, the failure is ScarletNX's; + 3. the range runs from its lowest version to the next version seen above it, where the case passes (or passes and + fails: the range is then said to end at a mixed version), or has no end when none is seen. + A case that is ScarletNX's own failure is no candidate. + + ScarletNX's own failure: a case that fails on RULE_GENERAL_DRIVERS drivers or more, or on every driver seen when two + or more are; a driver counts as failing when its runs fail the case and none passes it. + + A regression: on one driver, one version of it and one system's family, a case that passed in every run of a build + and fails in every run of each build after it, to the newest; builds of a published commit only (no -dirty), in the + order of their commits' days */ +#ifndef TR_RULES_H +#define TR_RULES_H +#include "store.h" + +#define RULE_FAIL_REPORTS 3 +#define RULE_FAIL_PEOPLE 2 +#define RULE_PASS_REPORTS 3 +#define RULE_PASS_DRIVERS 2 +#define RULE_DAYS 7 +#define RULE_GENERAL_DRIVERS 3 + +typedef struct { + int name; /* the case, StProbeName's id */ + const char *version, *words; /* edenprobe's version and the words that ran, the runs' */ + int driver_id; + const char* os; /* the system's family, the runs' */ + unsigned long low, high; /* the range: from low, up to high, which it leaves out; high 0 for no end */ + int mixed; /* high is a version where the case passes and fails */ + char* versions; /* owned: the range as the ban table writes it, ">= 26.1.0 < 26.2.0" */ + char* broken; /* owned: the highest version that fails, as its vendor numbers it */ + long* failing; /* owned: the reports that fail, the oldest first */ + int nfailing, people; + long* passing; /* owned: the other drivers' reports that pass, the oldest first */ + int npassing, pass_drivers; + int eden_fail, eden_pass; /* Eden's runs (any emulator but ScarletNX with a driver) on this driver: fail, pass */ + char* extensions; /* owned: the optional extensions on in every failing run, NULL where one names none */ + double newest; /* the newest failing report's day */ +} RuleCandidate; + +typedef struct { + int name; + const char *version, *words; + int* drivers; /* owned: the drivers it fails on */ + int ndrivers, seen; + long* reports; /* owned: ScarletNX's reports that fail it, the oldest first */ + int nreports; + int eden_runs, eden_pass; /* Eden's runs on those drivers, and of them those that pass */ +} RuleGeneral; + +typedef struct { + int name; + const char *version, *words; + int driver_id; + unsigned long driver_version; + const char* os; + const char *passed_commit, *failed_commit; /* the last build that passed, the first that failed after it */ + double passed_built, failed_built; + long passed_report, failed_report; /* a report of each */ + int builds; /* the builds that fail, to the newest */ +} RuleRegression; + +typedef struct { + RuleCandidate* candidates; + int ncandidates; + RuleGeneral* general; + int ngeneral; + RuleRegression* regressions; + int nregressions; +} Rules; + +/* the rules over runs (any order) and their results (st_probe_results' order: by case, then report), into out; the + runs' strings are pointed at, not copied, so runs outlives out. 0, or -1 out of memory */ +int rules_make(const StProbeRun* runs, int nruns, const StProbeResult* results, int nresults, Rules* out); +void rules_free(Rules* r); + +/* candidate c's line in the ban table's format, its key "" for a person to choose, as the runs cannot say which + extension or feature it is: " | off | radv | >= 26.1.0 < 26.2.0 | linux | * | fails edenprobe's astc case + \"...\" | Tracer #12, #15, #18; edenprobe 0.9.0 \"...\" | edenprobe:astc: ... | 2026-11-07 broken on 26.1.8 | -". + suite and name are the case's; owned */ +char* rules_draft(const RuleCandidate* c, const char* suite, const char* name); +#endif diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index 9cc57e3..c84c5a7 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -37,6 +37,7 @@ #include "message.h" #include "probe.h" #include "report.h" +#include "rules.h" #include "site.h" #include "store.h" #include "titles.h" @@ -3396,8 +3397,296 @@ static void test_probe_rescan(void) { free(rel); } +/* ---- the rules over the runs ---- */ + +#define DAY 86400.0 +#define D0 1793491200.0 /* 2026-11-01 */ +#define V(a, b, c) (((unsigned long)(a) << 22) | ((unsigned long)(b) << 12) | (unsigned long)(c)) +/* a run as the rules read it: its report, who sent it, the emulator, the driver, its version, the system's family, the + build's commit and day (0 for none), edenprobe's words */ +static StProbeRun rule_run(long report, u64 poster, const char* emulator, int driver, unsigned long version, + const char* os, const char* commit, double built, const char* words) { + StProbeRun r; + memset(&r, 0, sizeof r); + r.report = report; + r.poster = poster; + r.when = built ? built + 3600 : D0; + r.p.emulator = (char*)emulator; + r.p.version = (char*)"0.9.0"; + r.p.words = (char*)words; + r.p.os = (char*)os; + r.p.driver_id = driver; + r.p.inferred = strcmp(emulator, "ScarletNX") != 0; + r.p.driver_version = version; + r.p.commit = (char*)commit; + r.p.built = built; + return r; +} +/* the rules over runs, each one's result of case 1 given in results (ST_*), in the runs' order */ +static Rules rules_of(const StProbeRun* runs, int n, const int* results) { + StProbeResult r[64]; + Rules out; + int i; + for (i = 0; i < n; ++i) { + r[i].report = runs[i].report; + r[i].name = 1; + r[i].result = results[i]; + } + for (i = 1; i < n; ++i) /* st_probe_results' order: by case, then report */ + CHECK(r[i - 1].report < r[i].report); + CHECK(!rules_make(runs, n, r, n, &out)); + return out; +} + +static void test_rules(void) { + /* radv fails the case from 26.1.0 to 26.1.8 for two people, and passes on 26.2.0; two other drivers pass it */ + StProbeRun base[] = { + rule_run(1, 101, "ScarletNX", 3, V(26, 1, 0), "linux", "1111111", D0, "graphics"), + rule_run(2, 102, "ScarletNX", 3, V(26, 1, 8), "linux", "1111111", D0 + DAY, "graphics"), + rule_run(3, 101, "ScarletNX", 3, V(26, 1, 8), "linux", "2222222", D0 + 2 * DAY, "graphics"), + rule_run(4, 103, "ScarletNX", 3, V(26, 2, 0), "linux", "2222222", D0 + 3 * DAY, "graphics"), + rule_run(5, 104, "ScarletNX", 4, 0x9b404000UL, "windows", "1111111", D0, "graphics"), + rule_run(6, 105, "ScarletNX", 4, 0x9b404000UL, "windows", "1111111", D0 + DAY, "graphics"), + rule_run(7, 106, "ScarletNX", 6, V(25, 3, 5), "linux", "2222222", D0 + 2 * DAY, "graphics"), + rule_run(8, 107, "Eden", 3, V(26, 1, 8), "unknown", NULL, 0, "graphics"), + rule_run(9, 108, "console", 0, 0, "unknown", NULL, 0, "graphics"), + }; + int results[] = {ST_FAIL, ST_FAIL, ST_FAIL, ST_PASS, ST_PASS, ST_PASS, ST_PASS, ST_FAIL, ST_PASS}; + StProbeRun runs[16]; + int res[16]; + Rules r = rules_of(base, 9, results); + char* line; + CHECK(r.ncandidates == 1 && r.ngeneral == 0); + if (r.ncandidates == 1) { + RuleCandidate* c = &r.candidates[0]; + CHECK(c->name == 1 && c->driver_id == 3 && !c->mixed && c->low == V(26, 1, 0) && c->high == V(26, 2, 0)); + SAME(c->os, "linux"); + SAME(c->versions, ">= 26.1.0 < 26.2.0"); + SAME(c->broken, "26.1.8"); + CHECK(c->nfailing == 3 && c->failing[0] == 1 && c->failing[2] == 3 && c->people == 2); + CHECK(c->npassing == 3 && c->pass_drivers == 2 && c->passing[0] == 5); + CHECK(c->eden_fail == 1 && c->eden_pass == 0); + CHECK(!c->extensions); + line = rules_draft(c, "astc", "a 4x4 block | decodes"); + SAME(line, " | off | radv | >= 26.1.0 < 26.2.0 | linux | * | fails edenprobe's astc case \"a 4x4 block / " + "decodes\" | Tracer #1, #2, #3; edenprobe 0.9.0 \"a 4x4 block / decodes\" | edenprobe:astc: a 4x4 " + "block / decodes | 2026-11-03 broken on 26.1.8 | -"); + free(line); + } + rules_free(&r); + /* one person's failures are not enough */ + memcpy(runs, base, sizeof base); + memcpy(res, results, sizeof results); + runs[1].poster = 101; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + /* nor two reports */ + memcpy(runs, base, sizeof base); + res[2] = ST_SKIP; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + memcpy(res, results, sizeof results); + /* the passes of one other driver only: the failure may be ScarletNX's */ + runs[6].p.driver_id = 4; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + /* two passing reports only */ + memcpy(runs, base, sizeof base); + res[5] = ST_SKIP; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + memcpy(res, results, sizeof results); + /* a passing build seven days from a failing one counts, eight days does not; before it as after it */ + runs[5].p.built = D0 + 9 * DAY; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 1); + rules_free(&r); + runs[5].p.built = D0 + 10 * DAY; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + runs[5].p.built = D0 - 7 * DAY; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 1); + rules_free(&r); + runs[5].p.built = D0 - 8 * DAY; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + runs[5].p.built = 0; /* no build day: the day it came */ + runs[5].when = D0 - 8 * DAY; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + /* the version above that fails too is a mixed end; with none above, no end */ + memcpy(runs, base, sizeof base); + runs[9] = rule_run(10, 109, "ScarletNX", 3, V(26, 2, 0), "linux", "2222222", D0 + 3 * DAY, "graphics"); + res[9] = ST_FAIL; + r = rules_of(runs, 10, res); + CHECK(r.ncandidates == 1 && r.candidates[0].mixed && r.candidates[0].high == V(26, 2, 0)); + rules_free(&r); + res[3] = ST_SKIP; /* 26.2.0 passes nowhere now */ + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 1 && r.candidates[0].high == 0); + if (r.ncandidates == 1) SAME(r.candidates[0].versions, ">= 26.1.0"); + rules_free(&r); + memcpy(res, results, sizeof results); + /* a version that passes splits the range: the part below has too few failures, the part above enough */ + { + StProbeRun split[] = { + rule_run(1, 101, "ScarletNX", 3, V(26, 1, 0), "linux", "1111111", D0, "graphics"), + rule_run(2, 102, "ScarletNX", 3, V(26, 1, 0), "linux", "1111111", D0, "graphics"), + rule_run(3, 103, "ScarletNX", 3, V(26, 1, 4), "linux", "1111111", D0, "graphics"), + rule_run(4, 101, "ScarletNX", 3, V(26, 1, 8), "linux", "1111111", D0, "graphics"), + rule_run(5, 102, "ScarletNX", 3, V(26, 1, 8), "linux", "1111111", D0, "graphics"), + rule_run(6, 104, "ScarletNX", 3, V(26, 1, 8), "linux", "1111111", D0, "graphics"), + rule_run(7, 105, "ScarletNX", 4, 0x9b404000UL, "windows", "1111111", D0, "graphics"), + rule_run(8, 106, "ScarletNX", 4, 0x9b404000UL, "windows", "1111111", D0, "graphics"), + rule_run(9, 107, "ScarletNX", 6, V(25, 3, 5), "linux", "1111111", D0, "graphics"), + }; + int split_res[] = {ST_FAIL, ST_FAIL, ST_PASS, ST_FAIL, ST_FAIL, ST_FAIL, ST_PASS, ST_PASS, ST_PASS}; + r = rules_of(split, 9, split_res); + CHECK(r.ncandidates == 1); + if (r.ncandidates == 1) { + SAME(r.candidates[0].versions, ">= 26.1.8"); + CHECK(r.candidates[0].nfailing == 3 && r.candidates[0].people == 3); + } + rules_free(&r); + /* the same driver on another system is another range: its runs do not join */ + split[3].p.os = (char*)"android"; + r = rules_of(split, 9, split_res); + CHECK(r.ncandidates == 0); + rules_free(&r); + } + /* Eden's failures show beside a candidate and count for none; another mode is another comparison */ + memcpy(runs, base, sizeof base); + runs[2].p.emulator = (char*)"Eden"; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + memcpy(runs, base, sizeof base); + runs[2].p.words = (char*)"graphics notime"; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 0); + rules_free(&r); + /* the extensions on in every failing run */ + memcpy(runs, base, sizeof base); + runs[0].p.extensions = (char*)"VK_EXT_a, VK_EXT_b, VK_EXT_c"; + runs[1].p.extensions = (char*)"VK_EXT_c,VK_EXT_a"; + runs[2].p.extensions = (char*)" VK_EXT_a , VK_EXT_c, VK_EXT_d"; + r = rules_of(runs, 9, res); + CHECK(r.ncandidates == 1); + if (r.ncandidates == 1) SAME(r.candidates[0].extensions, "VK_EXT_a, VK_EXT_c"); + rules_free(&r); + /* ScarletNX's own: failing on three drivers, which no candidate is then; on every driver seen, two of them */ + memcpy(runs, base, sizeof base); + res[3] = res[4] = res[5] = res[6] = ST_FAIL; + r = rules_of(runs, 9, res); + CHECK(r.ngeneral == 1 && r.ncandidates == 0); + if (r.ngeneral == 1) { + CHECK(r.general[0].ndrivers == 3 && r.general[0].seen == 3 && r.general[0].nreports == 7); + CHECK(r.general[0].eden_runs == 1 && r.general[0].eden_pass == 0); + } + rules_free(&r); + res[3] = ST_PASS; /* radv passes on 26.2.0: a driver with a pass is not one that fails */ + r = rules_of(runs, 9, res); + CHECK(r.ngeneral == 0); + rules_free(&r); + res[3] = ST_FAIL; + res[6] = ST_PASS; /* anv passes: two of three drivers fail, radv and nvidia */ + r = rules_of(runs, 9, res); + CHECK(r.ngeneral == 0); + rules_free(&r); + res[6] = ST_SKIP; /* anv says nothing: both drivers seen fail */ + r = rules_of(runs, 9, res); + CHECK(r.ngeneral == 1); + rules_free(&r); + { + int one[] = {ST_FAIL, ST_FAIL, ST_FAIL, ST_FAIL, ST_SKIP, ST_SKIP, ST_SKIP, ST_FAIL, ST_PASS}; + r = rules_of(runs, 9, one); /* one driver seen: no rule says whose */ + CHECK(r.ngeneral == 0 && r.ncandidates == 0); + rules_free(&r); + runs[7].p.driver_id = 24; /* Eden failing on another driver is no driver ScarletNX was seen on */ + r = rules_of(runs, 9, one); + CHECK(r.ngeneral == 0); + rules_free(&r); + runs[7].p.driver_id = 3; + } + memcpy(res, results, sizeof results); + /* three drivers of five fail it: ScarletNX's, though two others pass it often enough to clear radv */ + { + StProbeRun five[] = { + rule_run(1, 101, "ScarletNX", 3, V(26, 1, 8), "linux", "1111111", D0, "graphics"), + rule_run(2, 102, "ScarletNX", 3, V(26, 1, 8), "linux", "1111111", D0, "graphics"), + rule_run(3, 103, "ScarletNX", 3, V(26, 1, 8), "linux", "1111111", D0, "graphics"), + rule_run(4, 104, "ScarletNX", 4, 0x9b404000UL, "windows", "1111111", D0, "graphics"), + rule_run(5, 105, "ScarletNX", 6, V(25, 3, 5), "linux", "1111111", D0, "graphics"), + rule_run(6, 106, "ScarletNX", 18, V(26, 1, 8), "android", "1111111", D0, "graphics"), + rule_run(7, 107, "ScarletNX", 18, V(26, 1, 8), "android", "1111111", D0, "graphics"), + rule_run(8, 108, "ScarletNX", 24, V(26, 1, 8), "linux", "1111111", D0, "graphics"), + }; + int five_res[] = {ST_FAIL, ST_FAIL, ST_FAIL, ST_FAIL, ST_FAIL, ST_PASS, ST_PASS, ST_PASS}; + r = rules_of(five, 8, five_res); + CHECK(r.ngeneral == 1 && r.ncandidates == 0); + if (r.ngeneral == 1) CHECK(r.general[0].ndrivers == 3 && r.general[0].seen == 5); + rules_free(&r); + five_res[4] = ST_PASS; /* two drivers fail of five: radv is the candidate, and the failure no one's own */ + r = rules_of(five, 8, five_res); + CHECK(r.ngeneral == 0 && r.ncandidates == 1); + rules_free(&r); + } + /* a regression: passed on a build, failed on each after it, on one driver and version */ + { + StProbeRun builds[] = { + rule_run(1, 101, "ScarletNX", 3, V(26, 1, 8), "linux", "aaaaaaa", D0, "graphics"), + rule_run(2, 102, "ScarletNX", 3, V(26, 1, 8), "linux", "aaaaaaa", D0, "graphics"), + rule_run(3, 101, "ScarletNX", 3, V(26, 1, 8), "linux", "bbbbbbb", D0 + DAY, "graphics"), + rule_run(4, 103, "ScarletNX", 3, V(26, 1, 8), "linux", "ccccccc", D0 + 2 * DAY, "graphics"), + rule_run(5, 104, "ScarletNX", 3, V(26, 1, 8), "linux", "ccccccc", D0 + 2 * DAY, "graphics"), + rule_run(6, 105, "ScarletNX", 3, V(26, 2, 0), "linux", "ccccccc", D0 + 2 * DAY, "graphics"), + rule_run(7, 106, "ScarletNX", 3, V(26, 1, 8), "linux", "ddddddd-dirty", D0 + 3 * DAY, "graphics"), + }; + int regress[] = {ST_PASS, ST_PASS, ST_FAIL, ST_FAIL, ST_FAIL, ST_PASS, ST_PASS}; + r = rules_of(builds, 7, regress); + CHECK(r.nregressions == 1); + if (r.nregressions == 1) { + RuleRegression* g = &r.regressions[0]; + SAME(g->passed_commit, "aaaaaaa"); + SAME(g->failed_commit, "bbbbbbb"); + CHECK(g->passed_report == 1 && g->failed_report == 3 && g->builds == 2 && g->driver_id == 3); + CHECK(g->driver_version == V(26, 1, 8) && g->failed_built == D0 + DAY); + } + rules_free(&r); + regress[4] = ST_PASS; /* the newest build passes in one run: not a build that fails */ + r = rules_of(builds, 7, regress); + CHECK(r.nregressions == 0); + rules_free(&r); + regress[4] = ST_FAIL; + regress[1] = ST_FAIL; /* the build before passes in one run only: no build that passed */ + r = rules_of(builds, 7, regress); + CHECK(r.nregressions == 0); + rules_free(&r); + regress[1] = ST_PASS; + builds[6].p.commit = (char*)"ddddddd"; /* a published build after them that passes: fixed */ + r = rules_of(builds, 7, regress); + CHECK(r.nregressions == 0); + rules_free(&r); + } +} + +static int rules_only(void) { + test_rules(); + fprintf(stderr, "tracer rules: %d of %d checks passed\n", checks - failures, checks); + return failures != 0; +} + int main(int argc, char** argv) { char *db, *command; + if (argc == 2 && !strcmp(argv[1], "--rules")) return rules_only(); /* scripts/test-rule-mutants.sh's */ if (argc == 2) return as_worker(argv[1]); rei_now = clock_now; strcpy(site, "/tmp/tracer-test-XXXXXX"); @@ -3434,6 +3723,7 @@ int main(int argc, char** argv) { test_probe_parts(); test_probe_lines(); test_probe_zip(); + test_rules(); if (tracer.store) { test_reports(); test_mcp(); From c9b5aab85c71afd49bdfcacfc3a440ebae8a6898 Mon Sep 17 00:00:00 2001 From: AO55 Date: Sun, 8 Nov 2026 00:01:10 -0300 Subject: [PATCH 3/4] [tracer] The runs of edenprobe on the site and in tracer-mcp probe/ draws each case that fails somewhere by machine (the emulator, the driver and its version, the system), each case and each driver on a page of its own, and the ban candidates with their draft lines, ScarletNX's own failures and the regressions; a run's report page gives its counts and the cases that did not pass. tracer-mcp reads the same JSON in probe_matrix, probe_case and ban_candidates. Signed-off-by: AO55 --- docs/TESTING.md | 7 +- docs/TRACER-MCP.md | 3 + docs/TRACER.md | 11 +- tracer/Makefile | 2 +- tracer/src/mcp.c | 256 ++++++++- tracer/src/report.c | 7 +- tracer/src/site.c | 1004 +++++++++++++++++++++++++++++++++++- tracer/src/site.h | 22 +- tracer/src/store.c | 11 +- tracer/src/store.h | 4 +- tracer/tests/test_tracer.c | 196 ++++++- 11 files changed, 1478 insertions(+), 45 deletions(-) diff --git a/docs/TESTING.md b/docs/TESTING.md index a724b75..bc6aae0 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -89,7 +89,12 @@ temporary folder: a mixed end, no end, a range a passing version splits, another system's runs apart, the extensions every failing run has; ScarletNX's own failure on three drivers of five (no candidate then) and on both of two, and none on one or with a driver that passes; a regression, and none when the newest build passes once, the build before fails once, - or a published build after passes, a `-dirty` one left out. + or a published build after passes, a `-dirty` one left out; +- the Probe pages over those runs: the matrix by machine, a case's page with its failures, a driver's, a run's report + page and JSON without the player; a ban candidate made of seven whole reports on three drivers, drawn with its draft + line on the candidates page and the driver's, given by the MCP server's `ban_candidates`, `probe_matrix` (by driver, + words, suite, failing or not) and `probe_case` (by key, by words, several, none, a key that is none), and gone with + its reports; a case no run names any more losing its page. `python3 scripts/test-rule-mutants.py` then changes `tracer/src/rules.c` one way at a time in a copy of the tree (a threshold one off, a comparison that lets one more in, a condition left out: 19 mutants) and expects `test_tracer diff --git a/docs/TRACER-MCP.md b/docs/TRACER-MCP.md index a453df5..6465e98 100644 --- a/docs/TRACER-MCP.md +++ b/docs/TRACER-MCP.md @@ -19,6 +19,9 @@ one either. It is built and packaged with Tracer ([Build](./BUILD.md#tracer)). | `read_log` | a log's lines with their numbers, from a line on or those that hold some text, and where to go on | | `get_screenshot` | one of a report's screenshots, as an image (8 MiB at most; a larger one is named by its address) | | `signatures` | the failures grouped by where they happened, across games, the most reported first | +| `probe_matrix` | edenprobe's cases by machine (an emulator, a driver and its version, a system), each case's results on each as `[pass, fail, skip, crashed]`; by words, suite, family, driver, emulator, the failing cases alone (the default) or all | +| `probe_case` | one case of edenprobe, by its key or by words of its suite and name (words that find several list them): its results on each machine and its newest failures and skips, each with its report, machine and detail | +| `ban_candidates` | what the runs of edenprobe say together ([What the runs say together](./TRACER.md#what-the-runs-say-together)): ban candidates with their draft lines, ScarletNX's own failures and regressions; by driver and by kind | An agent adds it by its address, Claude Code with: diff --git a/docs/TRACER.md b/docs/TRACER.md index 5556444..961dcfe 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -111,7 +111,8 @@ one that is gone and one with no log are refused, each with why. [edenprobe](https://github.com/scarletnx/edenprobe) checks an emulator against the console, case by case. A report whose first log holds a run of it is the run's, kept apart from the games: in no game's list, nor `all.html` and -`api/reports.json`. A run comes in three forms: +`api/reports.json`, but on the site's Probe pages ([The site](#the-site)), by machine: the emulator, the driver and its +version, the system. A run comes in three forms: - ScarletNX's log of the run, alone or in the launcher's Share Log zip, whose entry that holds a whole run is the one kept (else one a run begins in, else its first log, as for any zip): the machine from its header (`system:`, the @@ -254,8 +255,12 @@ Static files, drawn again where a report changes them, and all of them at each s | `index.html` | each game, its latest outcome, its reports' count; a search and a filter by outcome | | `all.html` | every report, the newest first | | `g/.html` | a game's reports: `` its title ID, or `n-` and its name's letters for a game known by name | -| `r//` | a report: its facts, screenshots, and each log with its summary, to read or download (a log sent in a `.zip` or a `.gz` is kept as its text and downloads as one: `logs.zip` as `logs.log`, `game.log.gz` as `game.log`) | -| `api/` | the same as JSON: `games.json`, `reports.json`, `r/.json` (a report with its logs' summaries and the notes added later); no Discord id | +| `r//` | a report: its facts, screenshots, and each log with its summary, to read or download (a log sent in a `.zip` or a `.gz` is kept as its text and downloads as one: `logs.zip` as `logs.log`, `game.log.gz` as `game.log`); a run of edenprobe's has its counts and each case that did not pass | +| `probe/index.html` | the runs of edenprobe: the machines (an emulator, a driver and its version, a system), each case that fails somewhere with its results on each machine, each suite's, and each run | +| `probe/c/.html` | a case of edenprobe: `` 16 hex digits of its suite and name; its results on each machine, what the rules say of it, and its newest 200 failures and skips with their detail | +| `probe/d/.html` | a driver, by the ban table's name (`radv`, `nvidia`; `unknown` for the console's reports): its machines, the cases that fail on it, its ban candidates, its runs | +| `probe/candidates.html` | [what the runs say together](#what-the-runs-say-together): ban candidates with their draft lines, ScarletNX's own failures, regressions | +| `api/` | the same as JSON: `games.json`, `reports.json`, `r/.json` (a report with its logs' summaries and the notes added later, a run of edenprobe's with its run); `probe/matrix.json`, `probe/c/.json`, `probe/d/.json`, `probe/candidates.json`; no Discord id | | `style.css`, `site.js`, `tracer.svg` | copied from `TRACER_ASSETS` at each start | The lists filter in the browser (`site.js`: by words, outcome, branch, GPU; kept in the address's `#`) and work diff --git a/tracer/Makefile b/tracer/Makefile index f3f1042..f838c74 100644 --- a/tracer/Makefile +++ b/tracer/Makefile @@ -66,7 +66,7 @@ src/rules.o: src/rules.c src/rules.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/rules.c src/store.o: src/store.c src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) $(SQLITE_CFLAGS) -c -o $@ src/store.c -src/site.o: src/site.c src/site.h src/files.h src/store.h src/probe.h src/tracer.h +src/site.o: src/site.c src/site.h src/files.h src/rules.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/site.c src/worker.o: src/worker.c src/worker.h src/report.h src/age.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/worker.c diff --git a/tracer/src/mcp.c b/tracer/src/mcp.c index 5baa6a7..944206f 100644 --- a/tracer/src/mcp.c +++ b/tracer/src/mcp.c @@ -18,7 +18,10 @@ static const char INSTRUCTIONS[] = "search_reports find reports; signatures groups the failures that happened in the same place, across games; " "get_report gives a report's facts and each log's summary (how the run ended and where, its frames, the service " "commands and what else the runtime missed, the last lines); read_log reads or searches the log itself; " - "get_screenshot shows a report's screenshot. Home folders in the logs are ~. A Switch log that failed has a symbolize " + "get_screenshot shows a report's screenshot. Runs of edenprobe (its cases on each emulator, driver and system) are " + "reports of their own: probe_matrix lists the cases by machine, probe_case gives a case's results and failures, " + "ban_candidates what the runs say together (drivers to ban, ScarletNX's own failures, regressions). " + "Home folders in the logs are ~. A Switch log that failed has a symbolize " "object in get_report: its title ID, game version and game addresses. ScarletNX's own MCP server (scarletnx " "--mcp), where a copy of the game is, names them: its find_game with that title_id, the game whose version is " "game_version, then its symbolize (or disassemble) with that game's path and the addresses. This server has no " @@ -72,6 +75,40 @@ static const char TOOLS[] = "\"limit\":{\"type\":\"integer\",\"minimum\":1,\"maximum\":200,\"description\":\"30 when not given\"}}}," "\"annotations\":{\"readOnlyHint\":true,\"openWorldHint\":false}}]"; +/* the tools of the runs of edenprobe, apart: each string of the list stays within C99's 4095 bytes */ +static const char PROBE_TOOLS[] = + "[{\"name\":\"probe_matrix\",\"title\":\"The runs of edenprobe by machine\",\"description\":\"edenprobe's " + "cases by machine (an emulator, a driver and its version, a system), from the runs sent to Tracer: the machines, " + "and each case's results on each of them as [pass, fail, skip, crashed], in the machines' order. Every version and " + "mode of edenprobe counted together.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{" + "\"query\":{\"type\":\"string\",\"description\":\"words the case's suite or name holds, in any case\"}," + "\"suite\":{\"type\":\"string\",\"description\":\"one suite: astc, tex8k, nifm...\"}," + "\"family\":{\"type\":\"string\",\"description\":\"one family: judge, cpu, graphics, fs, kernel, display, " + "video, audio, service, net, pad, game\"}," + "\"driver\":{\"type\":\"string\",\"description\":\"only the machines of this driver, by the ban table's name: " + "radv, nvidia, qualcomm, turnip, mali...\"}," + "\"emulator\":{\"type\":\"string\",\"description\":\"only this emulator's machines: ScarletNX, Eden, rEden, " + "console\"}," + "\"failing\":{\"type\":\"boolean\",\"description\":\"only the cases that fail or crash on a machine shown; " + "true when not given\"}," + "\"limit\":{\"type\":\"integer\",\"minimum\":1,\"maximum\":1000,\"description\":\"100 when not given\"}}}," + "\"annotations\":{\"readOnlyHint\":true,\"openWorldHint\":false}}," + "{\"name\":\"probe_case\",\"title\":\"A case of edenprobe\",\"description\":\"One case of edenprobe: its " + "results on each machine, the rules' word on it, and its newest failures and skips, each with its report, machine " + "and detail. Given its key (16 hex digits, as probe_matrix names it), or words of its suite and name: words that " + "find several cases list them.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{" + "\"case\":{\"type\":\"string\",\"description\":\"the case's key\"}," + "\"query\":{\"type\":\"string\",\"description\":\"words its suite or name holds, in any case\"}}}," + "\"annotations\":{\"readOnlyHint\":true,\"openWorldHint\":false}}," + "{\"name\":\"ban_candidates\",\"title\":\"What the runs of edenprobe say\",\"description\":\"By fixed " + "rules over the runs: ban candidates (a case that fails on one driver's range of versions for several people and " + "passes on other drivers), each with its draft line for ScarletNX's ban table, its key left for a person; " + "ScarletNX's own failures (a case failing on most drivers); and regressions (a case a build broke on a driver). " + "Nothing is applied.\",\"inputSchema\":{\"type\":\"object\",\"properties\":{" + "\"driver\":{\"type\":\"string\",\"description\":\"only this driver's, by the ban table's name\"}," + "\"kind\":{\"type\":\"string\",\"description\":\"candidates, general or regressions; all three when not " + "given\"}}},\"annotations\":{\"readOnlyHint\":true,\"openWorldHint\":false}}]"; + /* ---- reading ---- */ static char* read_text(const char* root, const char* rel, size_t* n) { @@ -576,6 +613,209 @@ static char* signatures(const Mcp* m, const cJSON* args, int* error) { return printed(out); } +/* ---- the runs of edenprobe ---- */ + +/* a case's key, as probe_case_key makes it: 16 hex digits */ +static int case_key(const char* s) { return s && strlen(s) == 16 && strspn(s, "0123456789abcdef") == 16; } + +static char* probe_matrix(const Mcp* m, const cJSON* args, int* error) { + cJSON *all = read_json(m->root, "api/probe/matrix.json"), *out, *machines, *cases, *c, *each; + const char *suite = jstr(args, "suite"), *family = jstr(args, "family"), *driver = jstr(args, "driver"), + *emulator = jstr(args, "emulator"); + const cJSON* failing = cJSON_GetObjectItemCaseSensitive(args, "failing"); + int only_failing = !cJSON_IsFalse(failing), limit = integer(args, "limit", 100, 1, 1000), matched = 0, i; + int* shown; + Words words; + char* why; + if (words_of(&words, jstr(args, "query"), &why)) { + words_free(&words); + cJSON_Delete(all); + *error = 1; + return why; + } + if (!all) { + words_free(&words); + *error = 1; + return rei_strdup("the site has no api/probe/matrix.json yet"); + } + out = cJSON_CreateObject(); + machines = cJSON_AddArrayToObject(out, "machines"); + shown = calloc((size_t)cJSON_GetArraySize(cJSON_GetObjectItemCaseSensitive(all, "machines")) + 1, sizeof *shown); + if (!shown) abort(); + i = 0; + cJSON_ArrayForEach(each, cJSON_GetObjectItemCaseSensitive(all, "machines")) { /* the machines asked for */ + shown[i] = (!driver || !*driver || same(jstr(each, "driver"), driver)) && + (!emulator || !*emulator || same(jstr(each, "emulator"), emulator)); + if (shown[i]) cJSON_AddItemToArray(machines, cJSON_Duplicate(each, 1)); + ++i; + } + cases = cJSON_AddArrayToObject(out, "cases"); + cJSON_ArrayForEach(c, cJSON_GetObjectItemCaseSensitive(all, "cases")) { + const cJSON *results = cJSON_GetObjectItemCaseSensitive(c, "results"), *r; + cJSON *copy, *kept; + int bad = 0, any = 0; + if (!words_in(c, &words) || (suite && *suite && !same(jstr(c, "suite"), suite)) || + (family && *family && !same(jstr(c, "family"), family))) + continue; + i = 0; + cJSON_ArrayForEach(r, results) { + if (shown[i]) { + any |= cJSON_GetArraySize(r) == 4 && + (cJSON_GetArrayItem(r, 0)->valuedouble + cJSON_GetArrayItem(r, 1)->valuedouble + + cJSON_GetArrayItem(r, 2)->valuedouble + cJSON_GetArrayItem(r, 3)->valuedouble) > 0; + bad |= cJSON_GetArraySize(r) == 4 && + (cJSON_GetArrayItem(r, 1)->valuedouble + cJSON_GetArrayItem(r, 3)->valuedouble) > 0; + } + ++i; + } + if (!any || (only_failing && !bad)) continue; + if (matched++ >= limit) continue; + copy = cJSON_Duplicate(c, 1); + kept = cJSON_CreateArray(); + i = 0; + cJSON_ArrayForEach(r, results) { + if (shown[i]) cJSON_AddItemToArray(kept, cJSON_Duplicate(r, 1)); + ++i; + } + cJSON_ReplaceItemInObjectCaseSensitive(copy, "results", kept); + { + char* url = rei_format("%s/probe/c/%s.html", m->url, jstr(c, "case") ? jstr(c, "case") : ""); + jset(copy, "url", url); + free(url); + } + cJSON_AddItemToArray(cases, copy); + } + cJSON_AddNumberToObject(out, "runs", jnum(all, "runs")); + cJSON_AddNumberToObject(out, "matched", matched); + if (matched > limit) cJSON_AddNumberToObject(out, "shown", limit); + jset(out, "results", "each case's results on each machine shown, in their order: [pass, fail, skip, crashed]"); + free(shown); + cJSON_Delete(all); + words_free(&words); + return printed(out); +} + +static char* probe_case(const Mcp* m, const cJSON* args, int* error) { + const char *key = jstr(args, "case"), *query = jstr(args, "query"); + char *rel, *why, *url; + cJSON *c, *all, *list, *each, *out; + Words words; + int found = 0; + const char* only = NULL; + if (key && *key) { + if (!case_key(key)) { + *error = 1; + return rei_format("case=%.40s is not a case's key, 16 hex digits as probe_matrix names it", key); + } + only = key; + } else { + if (!query || !*query) { + *error = 1; + return rei_strdup("case, a case's key, or query, words of its suite and name, is needed"); + } + if (words_of(&words, query, &why)) { + words_free(&words); + *error = 1; + return why; + } + if (!(all = read_json(m->root, "api/probe/matrix.json"))) { + words_free(&words); + *error = 1; + return rei_strdup("the site has no api/probe/matrix.json yet"); + } + out = cJSON_CreateObject(); + list = cJSON_AddArrayToObject(out, "cases"); + cJSON_ArrayForEach(each, cJSON_GetObjectItemCaseSensitive(all, "cases")) { + cJSON* e; + if (!words_in(each, &words)) continue; + if (found++ < 20) { + e = cJSON_CreateObject(); + jset(e, "case", jstr(each, "case")); + jset(e, "suite", jstr(each, "suite")); + jset(e, "name", jstr(each, "name")); + cJSON_AddItemToArray(list, e); + only = jstr(each, "case"); + } + } + words_free(&words); + if (found != 1) { /* none, or several: the list */ + cJSON_AddNumberToObject(out, "matched", found); + cJSON_Delete(all); + if (!found) { + cJSON_Delete(out); + *error = 1; + return rei_format("no case's suite or name holds %.200s", query); + } + return printed(out); + } + if (!case_key(only)) { /* the matrix's own key, held to the same as one asked for */ + cJSON_Delete(out); + cJSON_Delete(all); + *error = 1; + return rei_strdup("the matrix names the case with no case's key"); + } + rel = rei_format("api/probe/c/%s.json", only); + cJSON_Delete(out); + c = read_json(m->root, rel); + free(rel); + cJSON_Delete(all); + if (!c) { + *error = 1; + return rei_strdup("the case's page is not on the site"); + } + url = rei_format("%s/probe/c/%s.html", m->url, jstr(c, "case") ? jstr(c, "case") : ""); + jset(c, "url", url); + free(url); + return printed(c); + } + rel = rei_format("api/probe/c/%s.json", only); + c = read_json(m->root, rel); + free(rel); + if (!c) { + *error = 1; + return rei_format("there is no case %s", only); + } + url = rei_format("%s/probe/c/%s.html", m->url, only); + jset(c, "url", url); + free(url); + return printed(c); +} + +static char* ban_candidates(const Mcp* m, const cJSON* args, int* error) { + cJSON *all = read_json(m->root, "api/probe/candidates.json"), *out, *each; + const char *driver = jstr(args, "driver"), *kind = jstr(args, "kind"); + static const char* const kinds[] = {"candidates", "general", "regressions"}; + size_t k; + if (kind && *kind && strcmp(kind, kinds[0]) && strcmp(kind, kinds[1]) && strcmp(kind, kinds[2])) { + cJSON_Delete(all); + *error = 1; + return rei_format("kind=%.40s is none of candidates, general, regressions", kind); + } + if (!all) { + *error = 1; + return rei_strdup("the site has no api/probe/candidates.json yet"); + } + out = cJSON_CreateObject(); + for (k = 0; k < sizeof kinds / sizeof *kinds; ++k) { + cJSON* list; + if (kind && *kind && strcmp(kind, kinds[k])) continue; + list = cJSON_AddArrayToObject(out, kinds[k]); + cJSON_ArrayForEach(each, cJSON_GetObjectItemCaseSensitive(all, kinds[k])) { + const cJSON *drivers = cJSON_GetObjectItemCaseSensitive(each, "drivers"), *d; + int mine = !driver || !*driver || same(jstr(each, "driver"), driver); + cJSON_ArrayForEach(d, drivers) mine |= cJSON_IsString(d) && same(d->valuestring, driver); + if (mine) cJSON_AddItemToArray(list, cJSON_Duplicate(each, 1)); + } + } + { + char* url = rei_format("%s/probe/candidates.html", m->url); + jset(out, "url", url); + free(url); + } + cJSON_Delete(all); + return printed(out); +} + /* ---- JSON-RPC ---- */ static char* answer(const cJSON* id, cJSON* result) { @@ -617,11 +857,9 @@ static char* called(const Mcp* m, const cJSON* id, const cJSON* params) { static const struct { const char* name; char* (*run)(const Mcp*, const cJSON*, int*); - } tools[] = {{"list_games", list_games}, - {"search_reports", search_reports}, - {"get_report", get_report}, - {"read_log", read_log}, - {"signatures", signatures}}; + } tools[] = {{"list_games", list_games}, {"search_reports", search_reports}, {"get_report", get_report}, + {"read_log", read_log}, {"signatures", signatures}, {"probe_matrix", probe_matrix}, + {"probe_case", probe_case}, {"ban_candidates", ban_candidates}}; const char* name = jstr(params, "name"); const cJSON* args = cJSON_GetObjectItemCaseSensitive(params, "arguments"); size_t i; @@ -686,8 +924,10 @@ char* mcp_handle(const Mcp* m, const char* body, size_t n, int* status) { else if (!strcmp(method, "ping")) text = answer(id, cJSON_CreateObject()); else if (!strcmp(method, "tools/list")) { - cJSON* r = cJSON_CreateObject(); - cJSON_AddItemToObject(r, "tools", cJSON_Parse(TOOLS)); + cJSON *r = cJSON_CreateObject(), *tools = cJSON_Parse(TOOLS), *more = cJSON_Parse(PROBE_TOOLS), *each; + while ((each = cJSON_DetachItemFromArray(more, 0))) cJSON_AddItemToArray(tools, each); + cJSON_Delete(more); + cJSON_AddItemToObject(r, "tools", tools); text = answer(id, r); } else if (!strcmp(method, "tools/call")) text = called(m, id, params); diff --git a/tracer/src/report.c b/tracer/src/report.c index 17be869..30cd583 100644 --- a/tracer/src/report.c +++ b/tracer/src/report.c @@ -769,9 +769,10 @@ static cJSON* probe_made(Tracer* t, const StReport* r, const Taken* k) { files = kept(k, ""); add_field(e, "Kept", files); if (p->cut_cases || p->cut_notes) { - char* left = rei_format("the detail of %d service, net and pad cases and %d net notes, which can name the " - "player", - p->cut_cases, p->cut_notes); + char* left = rei_format("the detail of %d %s of the service, net and pad families (or of no family edenprobe " + "names) and %d net %s, which can name the player", + p->cut_cases, p->cut_cases == 1 ? "case" : "cases", p->cut_notes, + p->cut_notes == 1 ? "note" : "notes"); add_field(e, "Left out", left); free(left); } diff --git a/tracer/src/site.c b/tracer/src/site.c index 1f3853c..15ee543 100644 --- a/tracer/src/site.c +++ b/tracer/src/site.c @@ -10,7 +10,10 @@ #include #include +#include + #include "files.h" +#include "rules.h" /* ---- pieces of a page ---- */ @@ -86,8 +89,8 @@ static void head(Buf* b, const char* root, const char* title, const char* descri "\n\n\n" SITE_THEMES "\n
\n", - root, root, root, root, root, root, root); + "Probe\n\n
\n", + root, root, root, root, root, root, root, root); } static void foot(Buf* b) { buf_add(b, "
\n
Reports that players sent to Tracer on Discord, with logs of " @@ -407,18 +410,190 @@ static void log_section(Buf* b, const StFile* f) { cJSON_Delete(s); } -char* site_report_html(const StReport* r, const StFile* files, int nfiles, const StNote* notes, int nnotes) { +/* ---- a run of edenprobe's pieces ---- */ + +static const char* os_name(const char* os) { + static const char* const names[][2] = {{"android", "Android"}, {"windows", "Windows"}, {"macos", "macOS"}, + {"ios", "iOS"}, {"freebsd", "FreeBSD"}, {"openbsd", "OpenBSD"}, + {"netbsd", "NetBSD"}, {"linux", "Linux"}}; + size_t i; + for (i = 0; os && i < sizeof names / sizeof *names; ++i) + if (!strcmp(names[i][0], os)) return names[i][1]; + return "system unknown"; +} +/* the driver's page name: the ban table's name, or "unknown" */ +static const char* driver_key(int id) { return probe_driver_name(id) ? probe_driver_name(id) : "unknown"; } +/* a machine as a column says it: "ScarletNX, RADV 26.1.8, Linux"; a report.jsonl alone, "the console" */ +static void machine_text(Buf* b, const Probe* p) { + if (!strcmp(p->emulator, "console") && !p->driver_id && !p->driver_name) { + buf_add(b, "the console"); + return; + } + esc(b, p->emulator); + buf_add(b, ", "); + if (p->driver_id) + esc(b, probe_driver_label(p->driver_id)); + else + esc(b, p->driver_name ? p->driver_name : "a driver it does not name"); + if (p->driver_text) { + buf_add(b, " "); + esc(b, p->driver_text); + } + if (p->inferred && p->driver_id) buf_add(b, " (driver ID inferred)"); + buf_add(b, ", "); + esc(b, os_name(p->os)); +} +static const char* result_name(int result) { + return result == ST_PASS ? "pass" : result == ST_FAIL ? "fail" : result == ST_CRASHED ? "crashed" : "skip"; +} +static const char* result_tone(int result) { return result == ST_PASS ? "ok" : result == ST_FAIL ? "bad" : "warn"; } +/* a case's results on a machine: its failures, crashes, skips and passes as badges, the worst first; empty for none */ +static void counts_cell(Buf* b, const int c[4]) { + static const int order[] = {ST_FAIL, ST_CRASHED, ST_SKIP, ST_PASS}; + size_t k; + int any = 0; + for (k = 0; k < sizeof order / sizeof *order; ++k) + if (c[order[k]]) { + buf_printf(b, "%s%d %s", any ? " " : "", result_tone(order[k]), c[order[k]], + result_name(order[k])); + any = 1; + } +} +static int probe_code(const ProbeCase* c) { + if (!strcmp(c->result, "pass")) return ST_PASS; + if (!strcmp(c->result, "fail")) return ST_FAIL; + return !strcmp(c->reason, "crashed") ? ST_CRASHED : ST_SKIP; +} + +/* a run of edenprobe on its report's page: what ran where, the counts, and each case that did not pass */ +static void probe_section(Buf* b, const Probe* p) { + char* counts = probe_counts(p); + char key[17]; + int i, k; + buf_add(b, "
\n

edenprobe "); + esc(b, counts); + buf_add(b, "

\n
\n"); + buf_add(b, "
edenprobe
"); + esc(b, p->version); + if (p->describe) { + buf_add(b, " ("); + esc(b, p->describe); + buf_add(b, ")"); + } + buf_add(b, "
\n"); + field(b, "What ran", *p->words ? p->words : "the families a mode file naming none runs"); + buf_add(b, "
Emulator
"); + esc(b, p->emulator); + if (p->emulator_version) { + buf_add(b, " "); + esc(b, p->emulator_version); + } + buf_add(b, "
\n"); + buf_add(b, "
Machine
"); + machine_text(b, p); + if (p->driver_id) + buf_printf(b, " the driver's page", driver_key(p->driver_id)); + buf_add(b, "
\n"); + if (p->driver_name || p->driver_info) { + buf_add(b, "
Driver
"); + esc(b, p->driver_name ? p->driver_name : ""); + if (p->driver_info) { + buf_add(b, ", "); + esc(b, p->driver_info); + } + if (p->driver_id) + buf_printf(b, " (driver ID %d%s)", p->driver_id, p->inferred ? ", inferred from its name" : ""); + buf_add(b, "
\n"); + } + field(b, "Device", p->device); + field(b, "Optional extensions on", p->extensions); + if (!p->whole) field(b, "Summary", "none: the run stopped before its end"); + if (p->cut_cases || p->cut_notes) { + char* left = rei_format("the detail of %d %s of the service, net and pad families (or of no family edenprobe " + "names) and %d net %s, which can name the player", + p->cut_cases, p->cut_cases == 1 ? "case" : "cases", p->cut_notes, + p->cut_notes == 1 ? "note" : "notes"); + field(b, "Left out", left); + free(left); + } + if (p->unread) { + char* odd = rei_format("%d lines that are none edenprobe writes", p->unread); + field(b, "Not read", odd); + free(odd); + } + buf_add(b, "
\n"); + for (k = 0; k < 3; ++k) { /* the failures, the crashes, the skips */ + static const int codes[] = {ST_FAIL, ST_CRASHED, ST_SKIP}; + static const char* const headings[] = {"Failed", "Crashed", "Skipped"}; + int n = 0; + for (i = 0; i < p->ncases; ++i) n += probe_code(&p->cases[i]) == codes[k]; + if (!n) continue; + buf_printf(b, + "

%s: %d

\n
\n" + "\n\n", + headings[k], n); + for (i = 0; i < p->ncases; ++i) { + const ProbeCase* c = &p->cases[i]; + if (probe_code(c) != codes[k]) continue; + probe_case_key(c->suite, c->name, key); + buf_add(b, "\n"); + } + buf_add(b, "\n
SuiteCaseTierDetail
"); + esc(b, c->suite); + buf_printf(b, "", key); + esc(b, c->name); + buf_add(b, ""); + esc(b, c->tier); + buf_add(b, ""); + if (*c->reason) { + esc(b, c->reason); + if (*c->detail) buf_add(b, ": "); + } + esc(b, c->detail); + buf_add(b, "
\n"); + } + buf_add(b, "
\n"); + free(counts); +} + +/* a run of edenprobe in its report's JSON: the run without its passes, each other case with its page */ +static cJSON* probe_object(const Probe* p) { + cJSON *o = probe_json(p), *cases = cJSON_DetachItemFromObject(o, "cases"), *kept = cJSON_CreateArray(), *c; + char* counts = probe_counts(p); + char key[17]; + jset(o, "counts", counts); + jset(o, "driver", probe_driver_name(p->driver_id)); + cJSON_ArrayForEach(c, cases) { + const char* result = jstr(c, "result"); + if (result && !strcmp(result, "pass")) continue; + probe_case_key(jstr(c, "suite"), jstr(c, "name"), key); + jset(c, "case", key); + cJSON_AddItemToArray(kept, cJSON_Duplicate(c, 1)); + } + cJSON_AddNumberToObject(o, "cases", (double)p->ncases); + cJSON_AddItemToObject(o, "not_passed", kept); + cJSON_Delete(cases); + free(counts); + return o; +} + +char* site_report_html(const StReport* r, const StFile* files, int nfiles, const StNote* notes, int nnotes, + const Probe* probe) { Buf b = {0}, title = {0}; int i, images = 0, videos = 0; buf_printf(&title, "Report #%ld: %s", r->id, r->title); - head(&b, "../../", title.text, "A ScarletNX game report sent to Tracer."); + head(&b, "../../", title.text, + probe ? "A run of edenprobe sent to Tracer." : "A ScarletNX game report sent to Tracer."); buf_free(&title); - buf_printf(&b, - "
\n

Games / " - "", - r->key); + if (probe) + buf_add(&b, "

\n

Probe / "); + else + buf_printf(&b, + "

\n

Games / " + "", + r->key); esc(&b, r->title); - buf_printf(&b, "

\n

Report #%ld

\n

Sent ", r->id); + buf_printf(&b, "%s

\n

Report #%ld

\n

Sent ", probe ? "" : "", r->id); when(&b, r->when); buf_add(&b, " "); badge(&b, r->outcome, r->missed); @@ -461,6 +636,7 @@ char* site_report_html(const StReport* r, const StFile* files, int nfiles, const buf_printf(&b, "\">#%ld\n", r->issue); } buf_add(&b, "\n"); + if (probe) probe_section(&b, probe); for (i = 0; i < nfiles; ++i) images += !strcmp(files[i].kind, "image"); if (images) { buf_add(&b, "

\n

Screenshots

\n
\n"); @@ -576,10 +752,12 @@ char* site_reports_json(const StReport* reports, int n) { return printed(o); } -char* site_report_json(const StReport* r, const StFile* files, int nfiles, const StNote* notes, int nnotes) { +char* site_report_json(const StReport* r, const StFile* files, int nfiles, const StNote* notes, int nnotes, + const Probe* probe) { cJSON *o = report_object(r), *later = cJSON_AddArrayToObject(o, "notes_added"), *list = cJSON_AddArrayToObject(o, "files"); int i; + if (probe) cJSON_AddItemToObject(o, "probe", probe_object(probe)); for (i = 0; i < nnotes; ++i) { cJSON* n = cJSON_CreateObject(); char when[32]; @@ -699,15 +877,18 @@ static int report_page(Store* s, const char* root, long id) { StReport r; StFile* files; StNote* notes = NULL; - int nfiles, nnotes = 0, done = -1; + Probe probe; + int nfiles, nnotes = 0, done = -1, run = 0; if (st_get(s, id, &r, &files, &nfiles) == 1) { char* rel = rei_format("r/%ld/index.html", id); st_notes(s, id, ¬es, &nnotes); - done = write_page(root, rel, site_report_html(&r, files, nfiles, notes, nnotes)); + if (!strcmp(r.key, PROBE_KEY)) run = st_probe_get(s, id, &probe, 1) == 1; + done = write_page(root, rel, site_report_html(&r, files, nfiles, notes, nnotes, run ? &probe : NULL)); free(rel); rel = rei_format("api/r/%ld.json", id); - done |= write_page(root, rel, site_report_json(&r, files, nfiles, notes, nnotes)); + done |= write_page(root, rel, site_report_json(&r, files, nfiles, notes, nnotes, run ? &probe : NULL)); free(rel); + if (run) probe_free(&probe); st_report_free(&r); st_files_free(files, nfiles); st_notes_free(notes, nnotes); @@ -753,12 +934,13 @@ static int lists(Store* s, const char* root, StGame* games, int ngames) { int site_update(Store* s, const char* root, long id, const char* key) { StGame* games; - int n, done = 0; + int n, done = 0, probe = key && !strcmp(key, PROBE_KEY); if (id) done |= report_page(s, root, id); if (st_games(s, &games, &n)) return -1; - done |= game_page(s, root, key, games, n); + if (!probe) done |= game_page(s, root, key, games, n); done |= lists(s, root, games, n); st_games_free(games, n); + if (probe) done |= site_probe(s, root); /* a run came, changed or went: every page of the runs is drawn again */ return done ? -1 : 0; } @@ -802,7 +984,799 @@ int site_rebuild(Store* s, const char* root) { for (i = 0; i < n; ++i) done |= report_page(s, root, all[i].id); for (i = 0; i < ngames; ++i) done |= game_page(s, root, games[i].key, games, ngames); done |= lists(s, root, games, ngames); + done |= site_probe(s, root); st_reports_free(all, n); st_games_free(games, ngames); return done ? -1 : 0; } + +/* ---- the runs of edenprobe's pages ---- */ + +#define CASE_ROWS 200 /* a case's failures and skips its page lists, the newest */ +#define SITE_RULES \ + "https://github.com/scarletnx/wimsy-core/blob/main/docs/TRACER.md#what-the-runs-say-together" /* the rules, said */ + +typedef struct { + const Probe* p; /* a run's of it: the machine's fields */ + int runs; + double last; +} Machine; + +typedef struct { + StProbeRun* runs; + int nruns; + StProbeName* names; + int nnames; + StProbeResult* results; + int nresults; + Rules rules; + Machine* machines; + int nmachines; + int* machine_of; /* each run's machine */ + int* order; /* the runs by report, for run_of */ + int* cells; /* each case's results (4 a machine, ST_*) on each machine: nnames * nmachines * 4 */ + int* totals; /* each case's results: nnames * 4 */ +} Runs; + +static const Runs* g_site_runs; /* for the comparators, during one site_probe */ + +static int emulator_rank(const char* e) { + return !strcmp(e, "ScarletNX") ? 0 : !strcmp(e, "Eden") ? 1 : !strcmp(e, "rEden") ? 2 : 3; +} +static int same_machine(const Probe* p, const Probe* q) { + return !strcmp(p->emulator, q->emulator) && p->driver_id == q->driver_id && + p->driver_version == q->driver_version && !strcmp(p->os, q->os) && p->inferred == q->inferred && + (p->driver_id || !strcmp(p->driver_name ? p->driver_name : "", q->driver_name ? q->driver_name : "")); +} +static int by_machine(const void* a, const void* b) { + const Probe *p = ((const Machine*)a)->p, *q = ((const Machine*)b)->p; + int c = emulator_rank(p->emulator) - emulator_rank(q->emulator); + if (!c) c = p->driver_id - q->driver_id; + if (!c && p->driver_version != q->driver_version) c = p->driver_version < q->driver_version ? -1 : 1; + if (!c) c = strcmp(p->os, q->os); + return c; +} +static int by_run_report(const void* a, const void* b) { + long x = g_site_runs->runs[*(const int*)a].report, y = g_site_runs->runs[*(const int*)b].report; + return x < y ? -1 : x > y; +} +/* the run of report, its index; -1 for none */ +static int run_of(const Runs* r, long report) { + int lo = 0, hi = r->nruns - 1; + while (lo <= hi) { + int mid = (lo + hi) / 2; + long at = r->runs[r->order[mid]].report; + if (at == report) return r->order[mid]; + if (at < report) + lo = mid + 1; + else + hi = mid - 1; + } + return -1; +} +/* the case of id, its index in names; -1 for none */ +static int name_of(const Runs* r, int id) { + int lo = 0, hi = r->nnames - 1; + while (lo <= hi) { + int mid = (lo + hi) / 2; + if (r->names[mid].id == id) return mid; + if (r->names[mid].id < id) + lo = mid + 1; + else + hi = mid - 1; + } + return -1; +} +static void runs_free(Runs* r) { + rules_free(&r->rules); + st_probe_runs_free(r->runs, r->nruns); + st_probe_names_free(r->names, r->nnames); + free(r->results); + free(r->machines); + free(r->machine_of); + free(r->order); + free(r->cells); + free(r->totals); + memset(r, 0, sizeof *r); +} +static void* zeroed(size_t n, size_t size) { + void* p = calloc(n ? n : 1, size); + if (!p) { + fputs(REI_NAME ": out of memory\n", stderr); + abort(); + } + return p; +} +/* every run, case and result, the machines they ran on, each case's results by machine, and the rules: 0, or -1 */ +static int runs_load(Store* s, Runs* r) { + int i, k; + memset(r, 0, sizeof *r); + if (st_probe_runs(s, &r->runs, &r->nruns) || st_probe_names(s, &r->names, &r->nnames) || + st_probe_results(s, &r->results, &r->nresults) || + rules_make(r->runs, r->nruns, r->results, r->nresults, &r->rules)) { + runs_free(r); + return -1; + } + r->machines = zeroed((size_t)r->nruns, sizeof *r->machines); + r->machine_of = zeroed((size_t)r->nruns, sizeof *r->machine_of); + r->order = zeroed((size_t)r->nruns, sizeof *r->order); + for (i = 0; i < r->nruns; ++i) { /* the machines, each once */ + for (k = 0; k < r->nmachines && !same_machine(r->machines[k].p, &r->runs[i].p); ++k) continue; + if (k == r->nmachines) r->machines[r->nmachines++].p = &r->runs[i].p; + } + qsort(r->machines, (size_t)r->nmachines, sizeof *r->machines, by_machine); + for (i = 0; i < r->nruns; ++i) { + for (k = 0; !same_machine(r->machines[k].p, &r->runs[i].p); ++k) continue; + r->machine_of[i] = k; + ++r->machines[k].runs; + if (r->runs[i].when > r->machines[k].last) r->machines[k].last = r->runs[i].when; + r->order[i] = i; + } + g_site_runs = r; + qsort(r->order, (size_t)r->nruns, sizeof *r->order, by_run_report); + r->cells = zeroed((size_t)r->nnames * (size_t)(r->nmachines ? r->nmachines : 1) * 4, sizeof *r->cells); + r->totals = zeroed((size_t)r->nnames * 4, sizeof *r->totals); + for (i = 0; i < r->nresults; ++i) { + int run = run_of(r, r->results[i].report), n = name_of(r, r->results[i].name), res = r->results[i].result; + if (run < 0 || n < 0 || res < ST_PASS || res > ST_CRASHED) continue; + ++r->cells[((size_t)n * (size_t)r->nmachines + (size_t)r->machine_of[run]) * 4 + (size_t)res]; + ++r->totals[(size_t)n * 4 + (size_t)res]; + } + return 0; +} +static const int* cell_of(const Runs* r, int n, int m) { + return &r->cells[((size_t)n * (size_t)r->nmachines + (size_t)m) * 4]; +} +static int fails_somewhere(const Runs* r, int n) { + return r->totals[(size_t)n * 4 + ST_FAIL] || r->totals[(size_t)n * 4 + ST_CRASHED]; +} +/* a machine's label for a column's head: the emulator, then the driver and its version, then the system */ +static void machine_head(Buf* b, const Probe* p) { + if (!strcmp(p->emulator, "console") && !p->driver_id && !p->driver_name) { + buf_add(b, "the console"); + return; + } + esc(b, p->emulator); + buf_add(b, "
"); + esc(b, p->driver_id ? probe_driver_name(p->driver_id) : p->driver_name ? p->driver_name : "driver unknown"); + if (p->driver_text) { + buf_add(b, " "); + esc(b, p->driver_text); + } + if (p->inferred && p->driver_id) buf_add(b, "*"); + buf_add(b, "
"); + esc(b, os_name(p->os)); +} +static void run_counts(Buf* b, const Probe* p) { + int c[4] = {0, 0, 0, 0}; + c[ST_PASS] = (int)p->passed; + c[ST_FAIL] = (int)p->failed; + c[ST_SKIP] = (int)p->skipped; + c[ST_CRASHED] = (int)p->crashed; + if (p->passed < 0) + buf_add(b, "no summary"); + else + counts_cell(b, c); +} +/* the runs' table: each run with its report, root before each link */ +static void runs_table(Buf* b, const char* root, const Runs* r, const int* which, int n) { + int i; + buf_add(b, + "
\n" + "\n\n"); + for (i = 0; i < n; ++i) { + const StProbeRun* run = &r->runs[which ? which[i] : i]; + buf_printf(b, "\n"); + } + buf_add(b, "\n
ReportSentedenprobeWhat ranMachineCounts
#%ld", root, run->report, run->report); + when(b, run->when); + buf_add(b, ""); + esc(b, run->p.version); + buf_add(b, ""); + esc(b, run->p.words); + buf_add(b, ""); + machine_text(b, &run->p); + buf_add(b, ""); + run_counts(b, &run->p); + buf_add(b, "
\n"); +} +static cJSON* machine_object(const Machine* m) { + cJSON* o = cJSON_CreateObject(); + Buf label = {0}; + machine_text(&label, m->p); + jset(o, "machine", label.text); + jset(o, "emulator", m->p->emulator); + jset(o, "driver", probe_driver_name(m->p->driver_id)); + cJSON_AddNumberToObject(o, "driver_id", m->p->driver_id); + cJSON_AddBoolToObject(o, "inferred", m->p->inferred); + jset(o, "driver_name", m->p->driver_name); + jset(o, "version", m->p->driver_text); + jset(o, "os", m->p->os); + cJSON_AddNumberToObject(o, "runs", m->runs); + buf_free(&label); + return o; +} +static cJSON* counts_array(const int c[4]) { + int k; + cJSON* a = cJSON_CreateArray(); + for (k = 0; k < 4; ++k) cJSON_AddItemToArray(a, cJSON_CreateNumber(c[k])); + return a; +} + +/* probe/index.html and api/probe/matrix.json */ +static int probe_index(const char* root, const Runs* r) { + static const char* const keys[] = {"family", "suite"}; + static const char* const names[] = {"Family", "Suite"}; + Buf b = {0}; + cJSON *o = cJSON_CreateObject(), *machines = cJSON_AddArrayToObject(o, "machines"), + *cases = cJSON_AddArrayToObject(o, "cases"); + int i, m, failing = 0, done; + char* suites_seen = NULL; + for (i = 0; i < r->nnames; ++i) failing += fails_somewhere(r, i); + head(&b, "../", "Tracer: runs of edenprobe", + "Runs of edenprobe sent to Tracer: each case on each emulator and driver."); + buf_add(&b, "
\n

Runs of edenprobe

\n

Runs of edenprobe that players sent to Tracer on Discord: " + "which of its cases pass on each emulator, driver and system. Every version and mode of edenprobe is " + "counted together here; a case's page tells them apart. What the runs say together, by fixed rules: " + "ban candidates, ScarletNX's own failures and regressions.

\n"); + buf_printf(&b, + "

%d %s on %d %s, %d %s, %d failing somewhere

\n" + "
\n", + r->nruns, r->nruns == 1 ? "run" : "runs", r->nmachines, r->nmachines == 1 ? "machine" : "machines", + r->nnames, r->nnames == 1 ? "case" : "cases", failing); + cJSON_AddNumberToObject(o, "runs", r->nruns); + if (!r->nruns) { + buf_add(&b, "

No runs yet. Mention @Tracer with a log of a run of edenprobe " + "attached to add one.

\n"); + foot(&b); + done = write_page(root, "probe/index.html", buf_take(&b)); + done |= write_page(root, "api/probe/matrix.json", printed(o)); + return done; + } + buf_add(&b, "

Machines

\n
\n" + "\n\n"); + for (m = 0; m < r->nmachines; ++m) { + const Probe* p = r->machines[m].p; + buf_add(&b, "\n"); + cJSON_AddItemToArray(machines, machine_object(&r->machines[m])); + } + buf_add(&b, "\n
MachineRunsThe latest
"); + machine_text(&b, p); + if (p->driver_id) buf_printf(&b, " the driver", driver_key(p->driver_id)); + buf_printf(&b, "%d", r->machines[m].runs); + when(&b, r->machines[m].last); + buf_add(&b, "
\n

* the driver ID read from the driver's name: Eden logs " + "none.

\n"); + /* the cases that fail somewhere, a row each, a column for each machine */ + buf_printf(&b, "

Cases that fail somewhere %d of %d

\n", failing, r->nnames); + filters(&b, "cases", "Search cases or suites", keys, names, 2); + buf_add(&b, "
\n"); + for (m = 0; m < r->nmachines; ++m) { + buf_add(&b, ""); + } + buf_add(&b, "\n\n"); + for (i = 0; i < r->nnames; ++i) { + const StProbeName* n = &r->names[i]; + cJSON *c = cJSON_CreateObject(), *results; + const char* family = probe_family_name(probe_family(n->suite)); + jset(c, "case", n->key); + jset(c, "suite", n->suite); + jset(c, "family", family); + jset(c, "name", n->name); + cJSON_AddItemToObject(c, "total", counts_array(&r->totals[(size_t)i * 4])); + results = cJSON_AddArrayToObject(c, "results"); + for (m = 0; m < r->nmachines; ++m) cJSON_AddItemToArray(results, counts_array(cell_of(r, i, m))); + cJSON_AddItemToArray(cases, c); + if (!fails_somewhere(r, i)) continue; + buf_add(&b, "suite); + esc_lower(&b, n->name); + buf_printf(&b, "\" data-family=\"%s\" data-suite=\"", family); + esc(&b, n->suite); + buf_printf(&b, "\">"); + for (m = 0; m < r->nmachines; ++m) { + buf_add(&b, ""); + } + buf_add(&b, "\n"); + } + buf_add(&b, "\n
Case"); + machine_head(&b, r->machines[m].p); + buf_add(&b, "
"); + esc(&b, n->suite); + buf_printf(&b, "
", n->key); + esc(&b, n->name); + buf_add(&b, "
"); + counts_cell(&b, cell_of(r, i, m)); + buf_add(&b, "
\n\n"); + /* each suite: its cases' results summed on each machine */ + buf_add(&b, "

Suites

\n
\n"); + for (m = 0; m < r->nmachines; ++m) { + buf_add(&b, ""); + } + buf_add(&b, "\n\n"); + suites_seen = zeroed((size_t)r->nnames, 1); + for (i = 0; i < r->nnames; ++i) { + int k; + if (suites_seen[i]) continue; + buf_add(&b, "", probe_family_name(probe_family(r->names[i].suite))); + for (m = 0; m < r->nmachines; ++m) { + int sum[4] = {0, 0, 0, 0}, x; + for (k = i; k < r->nnames; ++k) + if (!strcmp(r->names[k].suite, r->names[i].suite)) + for (x = 0; x < 4; ++x) sum[x] += cell_of(r, k, m)[x]; + buf_add(&b, ""); + } + for (k = i; k < r->nnames; ++k) suites_seen[k] |= !strcmp(r->names[k].suite, r->names[i].suite); + buf_add(&b, "\n"); + } + free(suites_seen); + buf_add(&b, "\n
Suite"); + machine_head(&b, r->machines[m].p); + buf_add(&b, "
"); + esc(&b, r->names[i].suite); + buf_printf(&b, " %s"); + counts_cell(&b, sum); + buf_add(&b, "
\n

Runs

\n"); + runs_table(&b, "../", r, NULL, r->nruns); + foot(&b); + done = write_page(root, "probe/index.html", buf_take(&b)); + done |= write_page(root, "api/probe/matrix.json", printed(o)); + return done; +} + +/* the rules' entries about case n: links into candidates.html */ +static void rules_of_case(Buf* b, const Runs* r, int id) { + int i, any = 0; + for (i = 0; i < r->rules.ncandidates; ++i) + if (r->rules.candidates[i].name == id) { + const RuleCandidate* c = &r->rules.candidates[i]; + buf_printf(b, "%s
  • a ban candidate on %s %s, %s
  • \n", + any++ ? "" : "

    What the runs say

    \n
      \n", i + 1, probe_driver_label(c->driver_id), + c->versions, os_name(c->os)); + } + for (i = 0; i < r->rules.ngeneral; ++i) + if (r->rules.general[i].name == id) + buf_printf(b, + "%s
    • ScarletNX's own failure, on %d drivers " + "(edenprobe %s)
    • \n", + any++ ? "" : "

      What the runs say

      \n
        \n", i + 1, r->rules.general[i].ndrivers, + r->rules.general[i].version); + for (i = 0; i < r->rules.nregressions; ++i) + if (r->rules.regressions[i].name == id) + buf_printf(b, "%s
      • a regression on %s
      • \n", + any++ ? "" : "

        What the runs say

        \n
          \n", i + 1, + probe_driver_label(r->rules.regressions[i].driver_id)); + if (any) buf_add(b, "
        \n"); +} + +/* probe/c/.html and its JSON, case n */ +static int case_page(Store* s, const char* root, const Runs* r, int n) { + const StProbeName* name = &r->names[n]; + const char* family = probe_family_name(probe_family(name->suite)); + StProbeDetail* d = NULL; + int nd = 0, i, m, done; + Buf b = {0}, title = {0}; + char* rel; + cJSON *o = cJSON_CreateObject(), *machines = cJSON_AddArrayToObject(o, "machines"), *rows; + st_probe_details(s, name->id, CASE_ROWS, &d, &nd); + buf_printf(&title, "%s: %s", name->suite, name->name); + head(&b, "../../", title.text, "A case of edenprobe on each emulator and driver, from the runs sent to Tracer."); + buf_free(&title); + buf_add(&b, "
        \n

        Probe

        \n

        "); + esc(&b, name->name); + buf_add(&b, "

        \n

        "); + esc(&b, name->suite); + buf_printf(&b, " · %s

        \n

        ", family); + counts_cell(&b, &r->totals[(size_t)n * 4]); + buf_add(&b, "

        \n
        \n"); + jset(o, "case", name->key); + jset(o, "suite", name->suite); + jset(o, "family", family); + jset(o, "name", name->name); + cJSON_AddItemToObject(o, "total", counts_array(&r->totals[(size_t)n * 4])); + buf_add(&b, "

        By machine

        \n
        \n" + "\n\n"); + for (m = 0; m < r->nmachines; ++m) { + const int* c = cell_of(r, n, m); + cJSON* e; + if (!c[0] && !c[1] && !c[2] && !c[3]) continue; + buf_add(&b, "\n"); + e = machine_object(&r->machines[m]); + cJSON_AddItemToObject(e, "results", counts_array(c)); + cJSON_AddItemToArray(machines, e); + } + buf_add(&b, "\n
        MachineResults
        "); + machine_text(&b, r->machines[m].p); + buf_add(&b, ""); + counts_cell(&b, c); + buf_add(&b, "
        \n"); + rules_of_case(&b, r, name->id); + rows = cJSON_AddArrayToObject(o, "not_passed"); + if (nd) { + buf_printf(&b, + "

        Failures and skips the newest %d at most

        \n
        \n" + "\n\n", + CASE_ROWS); + for (i = 0; i < nd; ++i) { + int run = run_of(r, d[i].report); + const StProbeRun* x = run >= 0 ? &r->runs[run] : NULL; + cJSON* e = cJSON_CreateObject(); + Buf label = {0}; + if (!x) { + cJSON_Delete(e); + continue; + } + machine_text(&label, &x->p); + buf_printf(&b, "\n"); + cJSON_AddNumberToObject(e, "report", (double)x->report); + jset(e, "machine", label.text); + jset(e, "emulator", x->p.emulator); + jset(e, "edenprobe", x->p.version); + jset(e, "words", x->p.words); + jset(e, "result", result_name(d[i].result)); + if (*d[i].reason) jset(e, "reason", d[i].reason); + if (*d[i].detail) jset(e, "detail", d[i].detail); + cJSON_AddItemToArray(rows, e); + buf_free(&label); + } + buf_add(&b, "\n
        ReportSentMachineedenprobeResultDetail
        #%ld", x->report, x->report); + when(&b, x->when); + buf_printf(&b, "%s", label.text); + esc(&b, x->p.version); + buf_add(&b, " "); + esc(&b, x->p.words); + buf_printf(&b, "%s", + result_tone(d[i].result), result_name(d[i].result)); + if (*d[i].reason) { + esc(&b, d[i].reason); + if (*d[i].detail) buf_add(&b, ": "); + } + esc(&b, d[i].detail); + buf_add(&b, "
        \n"); + } + foot(&b); + st_probe_details_free(d, nd); + rel = rei_format("probe/c/%s.html", name->key); + done = write_page(root, rel, buf_take(&b)); + free(rel); + rel = rei_format("api/probe/c/%s.json", name->key); + done |= write_page(root, rel, printed(o)); + free(rel); + return done; +} + +/* a candidate's facts: its case, driver, range, the reports either way, Eden, the extensions, the draft line */ +static void candidate_block(Buf* b, const char* root, const Runs* r, int i) { + const RuleCandidate* c = &r->rules.candidates[i]; + int n = name_of(r, c->name), k; + char* draft = n >= 0 ? rules_draft(c, r->names[n].suite, r->names[n].name) : NULL; + if (n < 0) return; + buf_printf(b, "

        ", i + 1, root, r->names[n].key); + esc(b, r->names[n].suite); + buf_add(b, ": "); + esc(b, r->names[n].name); + buf_printf(b, + "

        \n
        \n
        Driver
        %s on %s
        \n", + root, driver_key(c->driver_id), probe_driver_label(c->driver_id), os_name(c->os)); + buf_add(b, "
        Versions
        "); + esc(b, c->versions); + if (c->mixed) buf_add(b, " (it both passes and fails on the version that ends it)"); + buf_add(b, "
        \n
        edenprobe
        "); + esc(b, c->version); + buf_add(b, " "); + esc(b, c->words); + buf_printf(b, "
        \n
        Fails
        %d reports from %d people:", c->nfailing, c->people); + for (k = 0; k < c->nfailing; ++k) + buf_printf(b, " #%ld", root, c->failing[k], c->failing[k]); + buf_printf(b, "
        \n
        Passes elsewhere
        %d reports of %d other drivers:", c->npassing, c->pass_drivers); + for (k = 0; k < c->npassing; ++k) + buf_printf(b, " #%ld", root, c->passing[k], c->passing[k]); + buf_printf(b, "
        \n
        Eden on this driver
        %d %s, %d %s
        \n", c->eden_fail, + c->eden_fail == 1 ? "run fails it" : "runs fail it", c->eden_pass, + c->eden_pass == 1 ? "passes it" : "pass it"); + buf_add(b, "
        Optional extensions on in every failing run
        "); + esc(b, c->extensions ? (*c->extensions ? c->extensions : "none in common") + : "a failing run's log does not list them (vulkan: optional extensions on)"); + buf_add(b, "
        \n
        \n
        ");
        +    esc(b, draft);
        +    buf_add(b, "
        \n"); + free(draft); +} +static cJSON* candidate_object(const Runs* r, const RuleCandidate* c) { + cJSON *o = cJSON_CreateObject(), *fail = cJSON_AddArrayToObject(o, "failing"), *pass; + int n = name_of(r, c->name), k; + char* draft = n >= 0 ? rules_draft(c, r->names[n].suite, r->names[n].name) : NULL; + if (n >= 0) { + jset(o, "case", r->names[n].key); + jset(o, "suite", r->names[n].suite); + jset(o, "name", r->names[n].name); + } + jset(o, "driver", probe_driver_name(c->driver_id)); + cJSON_AddNumberToObject(o, "driver_id", c->driver_id); + jset(o, "os", c->os); + jset(o, "versions", c->versions); + cJSON_AddBoolToObject(o, "mixed", c->mixed); + jset(o, "broken", c->broken); + jset(o, "edenprobe", c->version); + jset(o, "words", c->words); + for (k = 0; k < c->nfailing; ++k) cJSON_AddItemToArray(fail, cJSON_CreateNumber((double)c->failing[k])); + cJSON_AddNumberToObject(o, "people", c->people); + pass = cJSON_AddArrayToObject(o, "passing"); + for (k = 0; k < c->npassing; ++k) cJSON_AddItemToArray(pass, cJSON_CreateNumber((double)c->passing[k])); + cJSON_AddNumberToObject(o, "pass_drivers", c->pass_drivers); + cJSON_AddNumberToObject(o, "eden_fail", c->eden_fail); + cJSON_AddNumberToObject(o, "eden_pass", c->eden_pass); + jset(o, "extensions", c->extensions); + jset(o, "draft", draft); + free(draft); + return o; +} + +/* probe/candidates.html and api/probe/candidates.json */ +static int candidates_page(const char* root, const Runs* r) { + Buf b = {0}; + cJSON *o = cJSON_CreateObject(), *list = cJSON_AddArrayToObject(o, "candidates"), + *general = cJSON_AddArrayToObject(o, "general"), *regressions = cJSON_AddArrayToObject(o, "regressions"); + int i, k, done; + head(&b, "../", "Tracer: what the runs of edenprobe say", + "Ban candidates, ScarletNX's own failures and regressions, from the runs of edenprobe sent to Tracer."); + buf_printf( + &b, + "
        \n

        Probe

        \n

        What the runs " + "say together

        \n

        By fixed rules over ScarletNX's runs of each case " + "of each version and mode of edenprobe, Eden's beside them. Nothing here is applied: a ban candidate's " + "line goes into ScarletNX's ban table (src/nx/gpu/vk/extension_bans.txt) once a person has chosen its key " + "and checked it.

        \n

        %d ban %s, %d of ScarletNX's own %s, %d " + "%s

        \n
        \n", + r->rules.ncandidates, r->rules.ncandidates == 1 ? "candidate" : "candidates", r->rules.ngeneral, + r->rules.ngeneral == 1 ? "failure" : "failures", r->rules.nregressions, + r->rules.nregressions == 1 ? "regression" : "regressions"); + buf_printf(&b, "

        Ban candidates %d

        \n", r->rules.ncandidates); + if (!r->rules.ncandidates) + buf_printf(&b, + "

        None: no case fails on one driver in %d reports from %d people and passes on " + "%d others.

        \n", + RULE_FAIL_REPORTS, RULE_FAIL_PEOPLE, RULE_PASS_DRIVERS); + for (i = 0; i < r->rules.ncandidates; ++i) { + candidate_block(&b, "../", r, i); + cJSON_AddItemToArray(list, candidate_object(r, &r->rules.candidates[i])); + } + buf_printf(&b, "

        ScarletNX's own failures %d

        \n", r->rules.ngeneral); + if (r->rules.ngeneral) + buf_add(&b, "
        \n" + "\n\n"); + for (i = 0; i < r->rules.ngeneral; ++i) { + const RuleGeneral* g = &r->rules.general[i]; + int n = name_of(r, g->name); + cJSON *e = cJSON_CreateObject(), *drivers = cJSON_AddArrayToObject(e, "drivers"), *reports; + if (n < 0) { + cJSON_Delete(e); + continue; + } + buf_printf(&b, "\n", + !g->eden_runs ? "no run" + : g->eden_pass == g->eden_runs ? "passes it: the failure is ScarletNX's to fix" + : g->eden_pass ? "passes it in some runs" + : "fails it too"); + jset(e, "case", r->names[n].key); + jset(e, "suite", r->names[n].suite); + jset(e, "name", r->names[n].name); + jset(e, "edenprobe", g->version); + jset(e, "words", g->words); + cJSON_AddNumberToObject(e, "seen", g->seen); + reports = cJSON_AddArrayToObject(e, "reports"); + for (k = 0; k < g->nreports; ++k) cJSON_AddItemToArray(reports, cJSON_CreateNumber((double)g->reports[k])); + cJSON_AddNumberToObject(e, "eden_runs", g->eden_runs); + cJSON_AddNumberToObject(e, "eden_pass", g->eden_pass); + cJSON_AddItemToArray(general, e); + } + if (r->rules.ngeneral) buf_add(&b, "\n
        CaseedenprobeFails onReportsEden on those drivers
        ", i + 1); + esc(&b, r->names[n].suite); + buf_printf(&b, "
        ", r->names[n].key); + esc(&b, r->names[n].name); + buf_add(&b, "
        "); + esc(&b, g->version); + buf_add(&b, " "); + esc(&b, g->words); + buf_add(&b, ""); + for (k = 0; k < g->ndrivers; ++k) { + buf_printf(&b, "%s%s", k ? ", " : "", driver_key(g->drivers[k]), + driver_key(g->drivers[k])); + cJSON_AddItemToArray(drivers, cJSON_CreateString(driver_key(g->drivers[k]))); + } + buf_printf(&b, " of the %d seen", g->seen); + for (k = 0; k < g->nreports && k < 12; ++k) + buf_printf(&b, "%s#%ld", k ? " " : "", g->reports[k], g->reports[k]); + if (g->nreports > 12) buf_printf(&b, " and %d more", g->nreports - 12); + buf_printf(&b, "%s
        \n"); + buf_printf(&b, "

        Regressions %d

        \n", r->rules.nregressions); + if (r->rules.nregressions) + buf_add(&b, "
        \n" + "\n\n"); + for (i = 0; i < r->rules.nregressions; ++i) { + const RuleRegression* g = &r->rules.regressions[i]; + int n = name_of(r, g->name); + char version[32]; + cJSON* e = cJSON_CreateObject(); + if (n < 0) { + cJSON_Delete(e); + continue; + } + probe_version_text(g->driver_id, g->driver_version, version, sizeof version); + buf_printf(&b, "\n", g->builds); + jset(e, "case", r->names[n].key); + jset(e, "suite", r->names[n].suite); + jset(e, "name", r->names[n].name); + jset(e, "edenprobe", g->version); + jset(e, "words", g->words); + jset(e, "driver", probe_driver_name(g->driver_id)); + jset(e, "version", version); + jset(e, "os", g->os); + jset(e, "passed_commit", g->passed_commit); + jset(e, "failed_commit", g->failed_commit); + cJSON_AddNumberToObject(e, "passed_report", (double)g->passed_report); + cJSON_AddNumberToObject(e, "failed_report", (double)g->failed_report); + cJSON_AddNumberToObject(e, "builds", g->builds); + cJSON_AddItemToArray(regressions, e); + } + if (r->rules.nregressions) buf_add(&b, "\n
        CaseDriverPassed onFails fromBuilds that fail
        ", i + 1); + esc(&b, r->names[n].suite); + buf_printf(&b, "
        ", r->names[n].key); + esc(&b, r->names[n].name); + buf_printf(&b, "
        %s %s, %s", + driver_key(g->driver_id), driver_key(g->driver_id), version, os_name(g->os), g->passed_report); + esc(&b, g->passed_commit); + buf_add(&b, "", g->failed_report); + esc(&b, g->failed_commit); + buf_printf(&b, " (passed_commit); + buf_add(&b, "..."); + esc(&b, g->failed_commit); + buf_printf(&b, "\">the commits between)%d
        \n"); + foot(&b); + done = write_page(root, "probe/candidates.html", buf_take(&b)); + done |= write_page(root, "api/probe/candidates.json", printed(o)); + return done; +} + +/* probe/d/.html and its JSON: driver id's versions, runs, the cases that fail on it and its candidates */ +static int driver_page(const char* root, const Runs* r, int id) { + Buf b = {0}, title = {0}; + cJSON *o = cJSON_CreateObject(), *versions = cJSON_AddArrayToObject(o, "versions"), + *failing = cJSON_AddArrayToObject(o, "failing"), *list = cJSON_AddArrayToObject(o, "candidates"), + *reports = cJSON_AddArrayToObject(o, "runs"); + int *mine = zeroed((size_t)r->nruns, sizeof(int)), nmine = 0, i, m, k, done, any = 0; + const char* label = id ? probe_driver_label(id) : "drivers no log names"; + char* rel; + for (i = 0; i < r->nruns; ++i) + if (r->runs[i].p.driver_id == id) { + mine[nmine++] = i; + cJSON_AddItemToArray(reports, cJSON_CreateNumber((double)r->runs[i].report)); + } + buf_printf(&title, "%s: runs of edenprobe", label); + head(&b, "../../", title.text, + "A driver's runs of edenprobe sent to Tracer: its versions and the cases that fail."); + buf_free(&title); + buf_add(&b, "
        \n

        Probe

        \n

        "); + esc(&b, label); + buf_add(&b, "

        \n

        "); + if (id) + buf_printf(&b, "%s · VkDriverId %d", driver_key(id), id); + else + buf_add(&b, "the console's reports, and logs that name no driver ID"); + buf_printf(&b, "

        \n

        %d %s

        \n
        \n", nmine, nmine == 1 ? "run" : "runs"); + jset(o, "driver", probe_driver_name(id)); + cJSON_AddNumberToObject(o, "driver_id", id); + jset(o, "label", label); + buf_add(&b, "

        Its machines

        \n
        \n" + "\n\n"); + for (m = 0; m < r->nmachines; ++m) { + if (r->machines[m].p->driver_id != id) continue; + buf_add(&b, "\n"); + cJSON_AddItemToArray(versions, machine_object(&r->machines[m])); + } + buf_add(&b, "\n
        MachineRunsThe latest
        "); + machine_text(&b, r->machines[m].p); + buf_printf(&b, "%d", r->machines[m].runs); + when(&b, r->machines[m].last); + buf_add(&b, "
        \n

        Cases that fail on it

        \n"); + for (i = 0; i < r->nnames; ++i) { + int c[4] = {0, 0, 0, 0}; + cJSON* e; + for (m = 0; m < r->nmachines; ++m) + if (r->machines[m].p->driver_id == id) + for (k = 0; k < 4; ++k) c[k] += cell_of(r, i, m)[k]; + if (!c[ST_FAIL] && !c[ST_CRASHED]) continue; + if (!any++) + buf_add(&b, "
        \n" + "\n\n"); + buf_add(&b, "\n"); + e = cJSON_CreateObject(); + jset(e, "case", r->names[i].key); + jset(e, "suite", r->names[i].suite); + jset(e, "name", r->names[i].name); + cJSON_AddItemToObject(e, "results", counts_array(c)); + cJSON_AddItemToArray(failing, e); + } + buf_add(&b, any ? "\n
        CaseResults
        "); + esc(&b, r->names[i].suite); + buf_printf(&b, "
        ", r->names[i].key); + esc(&b, r->names[i].name); + buf_add(&b, "
        "); + counts_cell(&b, c); + buf_add(&b, "
        \n" : "

        None.

        \n"); + for (i = 0, any = 0; i < r->rules.ncandidates; ++i) + if (r->rules.candidates[i].driver_id == id) { + if (!any++) buf_add(&b, "

        Ban candidates

        \n"); + candidate_block(&b, "../../", r, i); + cJSON_AddItemToArray(list, candidate_object(r, &r->rules.candidates[i])); + } + buf_add(&b, "

        Runs

        \n"); + runs_table(&b, "../../", r, mine, nmine); + foot(&b); + free(mine); + rel = rei_format("probe/d/%s.html", driver_key(id)); + done = write_page(root, rel, buf_take(&b)); + free(rel); + rel = rei_format("api/probe/d/%s.json", driver_key(id)); + done |= write_page(root, rel, printed(o)); + free(rel); + return done; +} + +/* the files of root/folder whose name is none of keep's with its ending, removed: the pages of cases and drivers no run + names any more */ +static void prune(const char* root, const char* folder, const char* ending, char* const* keep, int nkeep) { + char* path = rei_format("%s/%s", root, folder); + DIR* d = opendir(path); + struct dirent* e; + size_t tail = strlen(ending); + while (d && (e = readdir(d))) { + size_t n = strlen(e->d_name); + int i, kept = 0; + if (n <= tail || strcmp(e->d_name + n - tail, ending)) continue; + for (i = 0; i < nkeep && !kept; ++i) + kept = strlen(keep[i]) == n - tail && !strncmp(keep[i], e->d_name, n - tail); + if (!kept) { + char* gone = rei_format("%s/%s", path, e->d_name); + unlink(gone); + free(gone); + } + } + if (d) closedir(d); + free(path); +} + +int site_probe(Store* s, const char* root) { + Runs r; + int i, done = 0, ndrivers = 0, k; + char** keys; + char* drivers[64]; + if (runs_load(s, &r)) return -1; + done |= probe_index(root, &r); + done |= candidates_page(root, &r); + keys = zeroed((size_t)r.nnames, sizeof *keys); + for (i = 0; i < r.nnames; ++i) { + done |= case_page(s, root, &r, i); + keys[i] = r.names[i].key; + } + for (i = 0; i < r.nruns; ++i) { /* each driver once */ + const char* key = driver_key(r.runs[i].p.driver_id); + for (k = 0; k < ndrivers && strcmp(drivers[k], key); ++k) continue; + if (k == ndrivers && ndrivers < (int)(sizeof drivers / sizeof *drivers)) { + drivers[ndrivers++] = (char*)key; + done |= driver_page(root, &r, r.runs[i].p.driver_id); + } + } + prune(root, "probe/c", ".html", keys, r.nnames); + prune(root, "api/probe/c", ".json", keys, r.nnames); + prune(root, "probe/d", ".html", drivers, ndrivers); + prune(root, "api/probe/d", ".json", drivers, ndrivers); + free(keys); + runs_free(&r); + g_site_runs = NULL; + return done ? -1 : 0; +} diff --git a/tracer/src/site.h b/tracer/src/site.h index e8f05f1..9887fb4 100644 --- a/tracer/src/site.h +++ b/tracer/src/site.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: GPL-3.0-or-later Copyright 2026 the ScarletNX contributors */ /* The site: static pages drawn from the database into a folder a web server serves as it is. index.html lists the - games, all.html every report, g/.html a game's reports, r// a report with its screenshots and logs, api/ - the same as JSON. + games, all.html every report, g/.html a game's reports, r// a report with its screenshots and logs, probe/ + the runs of edenprobe, api/ the same as JSON. Everything a log or a message says is escaped; site.js filters the lists in the browser, and the pages work without it */ #ifndef TR_SITE_H @@ -27,12 +27,15 @@ char* site_index_html(const StGame* games, int n); char* site_all_html(const StReport* reports, int n); char* site_game_html(const StGame* game, const StReport* reports, int n); -char* site_report_html(const StReport* r, const StFile* files, int nfiles, const StNote* notes, int nnotes); +/* a run of edenprobe's report is given its run (with its cases), NULL for any other */ +char* site_report_html(const StReport* r, const StFile* files, int nfiles, const StNote* notes, int nnotes, + const Probe* probe); /* the same as JSON, for programs (tracer-mcp, scripts): api/games.json, api/reports.json and api/r/.json. No Discord id is in them, as none is on the pages */ char* site_games_json(const StGame* games, int n); char* site_reports_json(const StReport* reports, int n); -char* site_report_json(const StReport* r, const StFile* files, int nfiles, const StNote* notes, int nnotes); +char* site_report_json(const StReport* r, const StFile* files, int nfiles, const StNote* notes, int nnotes, + const Probe* probe); /* text written to root/rel through rel.new, its folders made: 0, or -1 said in the log */ int site_write(const char* root, const char* rel, const char* text, size_t n); @@ -41,8 +44,17 @@ int site_write(const char* root, const char* rel, const char* text, size_t n); int site_move(const char* root, const char* rel, const char* from); /* style.css, site.js and tracer.svg copied from the folder from into root: 0, or -1 said in the log */ int site_assets(const char* from, const char* root); -/* a report's page, its game's page (gone when the game has no report left) and the lists drawn again: 0, or -1 */ +/* a report's page, its game's page (gone when the game has no report left) and the lists drawn again, and every page + of the runs of edenprobe when key is PROBE_KEY: 0, or -1 */ int site_update(Store* s, const char* root, long id, const char* key); +/* the pages of the runs of edenprobe, every one drawn again from the database: probe/index.html (each case that fails + somewhere, by machine: the emulator, the driver and its version, the system; each suite; each run), + probe/c/.html (a case on each machine, and its failures and skips with their detail, the newest 200), + probe/d/.html (a driver's machines, the cases that fail on it, its candidates, its runs), + probe/candidates.html (rules.h's ban candidates with their draft lines, ScarletNX's own failures and the + regressions), and the same as JSON in api/probe/ (matrix.json, c/.json, d/.json, candidates.json); a + case's or a driver's page that no run names any more removed. 0, or -1 */ +int site_probe(Store* s, const char* root); /* a report's folder gone: its files and its page */ void site_forget(const char* root, long id, const StFile* files, int nfiles); /* some files of report id gone from its folder */ diff --git a/tracer/src/store.c b/tracer/src/store.c index e30d590..e7eedf6 100644 --- a/tracer/src/store.c +++ b/tracer/src/store.c @@ -1059,10 +1059,13 @@ static void row_detail(sqlite3_stmt* q, void* to) { d->detail = (text = text_of(q, 4)) ? text : rei_strdup(""); d->us = sqlite3_column_type(q, 5) == SQLITE_NULL ? -1 : sqlite3_column_double(q, 5); } -int st_probe_details(Store* s, int name, StProbeDetail** details, int* n) { - sqlite3_stmt* q = prepared(s, "SELECT report, result, tier, reason, detail, us FROM probe_cases WHERE name = ?" - " ORDER BY report DESC"); - if (q) sqlite3_bind_int(q, 1, name); +int st_probe_details(Store* s, int name, int limit, StProbeDetail** details, int* n) { + sqlite3_stmt* q = prepared(s, "SELECT report, result, tier, reason, detail, us FROM probe_cases WHERE name = ? AND" + " result != 0 ORDER BY report DESC LIMIT ?"); + if (q) { + sqlite3_bind_int(q, 1, name); + sqlite3_bind_int(q, 2, limit); + } return rows(q, (void**)details, n, sizeof **details, row_detail); } void st_probe_details_free(StProbeDetail* details, int n) { diff --git a/tracer/src/store.h b/tracer/src/store.h index e0899bf..bca2035 100644 --- a/tracer/src/store.h +++ b/tracer/src/store.h @@ -161,8 +161,8 @@ typedef struct { char *tier, *reason, *detail; /* owned; "" for none */ double us; /* -1 for none */ } StProbeDetail; -/* each run's result of case name, the newest report first */ -int st_probe_details(Store* s, int name, StProbeDetail** details, int* n); +/* the runs' results of case name but its passes, the newest report first, limit at most */ +int st_probe_details(Store* s, int name, int limit, StProbeDetail** details, int* n); void st_probe_details_free(StProbeDetail* details, int n); void st_report_free(StReport* r); diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index c84c5a7..42704af 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -1192,7 +1192,7 @@ static void test_mcp(void) { free(t); t = ask(&m, "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/list\"}", &status); o = cJSON_Parse(t); - CHECK(cJSON_GetArraySize(jpath(o, "result.tools")) == 6); + CHECK(cJSON_GetArraySize(jpath(o, "result.tools")) == 9); /* the reports' six, the runs' three */ cJSON_Delete(o); HAS(t, "\"read_log\""); free(t); @@ -3216,7 +3216,8 @@ static void test_probe_reports(void) { "crashed"); HAS(t, "Report #"); HAS(t, ": edenprobe 0.9.0 on ScarletNX"); - HAS(t, "the detail of 3 service, net and pad cases and 1 net notes, which can name the player"); + HAS(t, "the detail of 3 cases of the service, net and pad families (or of no family edenprobe names) and 1 net " + "note, which can name the player"); HAS(t, "main 1234abc"); free(t); tr_message_free(&m); @@ -3340,7 +3341,7 @@ static void test_probe_reports(void) { attach(&m, "edenprobe.log", "https://cdn.discordapp.com/21/edenprobe.log", 10); t = answer_text(respond(&m)); HAS(t, "edenprobe 0.9.0 on radv, Mesa 26.1.8 (Linux): 3 passed, 2 failed"); - HAS(t, "the detail of 3 service, net and pad cases"); + HAS(t, "the detail of 3 cases of the service, net and pad families"); free(t); tr_message_free(&m); tracer.take = NULL; @@ -3351,6 +3352,194 @@ static void test_probe_reports(void) { (void)why; } +/* a run of edenprobe on a machine: the driver's line (name, info, ID), the raw driverVersion, the system, the build's + commit and day, and the astc case's result */ +static char* machine_log(const char* driver, int id, const char* raw, const char* system, const char* commit, + const char* day, const char* result) { + int pass = !strcmp(result, "pass"); + return rei_format( + "[ 0.00] ScarletNX - edenprobe\n" + "[ 0.00] build: ScarletNX main %s, committed %s (clang 23.1.3, x86_64)\n" + "[ 0.00] system: %s, Some CPU, 8 threads, 16 GB RAM\n" + "[ 0.18] vulkan: the driver that runs: %s (driver ID %d)\n" + "[ 0.18] vulkan: Some GPU, Vulkan 1.4.354, driver %s, graphics queue family 0\n" + "[ 0.20] [game] {\"type\":\"note\",\"text\":\"edenprobe 0.9.0 (v0.9.0) starting\"}\n" + "[ 0.20] [game] {\"type\":\"note\",\"text\":\"mode: quick, from the mode file; pictures of " + "failures only; families graphics\"}\n" + "[ 0.21] [game] {\"type\":\"case\",\"suite\":\"astc\",\"name\":\"a 4x4 block decodes\",\"tier\":" + "\"exact\",\"result\":\"%s\",\"detail\":\"%s\"}\n" + "[ 0.23] [game] {\"type\":\"summary\",\"passed\":%d,\"failed\":%d,\"skipped\":0,\"crashed\":0}\n", + commit, day, system, driver, id, raw, result, pass ? "" : "texel 0 reads 0000ffff", pass, !pass); +} + +/* the Probe pages and their JSON over the runs test_probe_reports left, then a ban candidate made of whole reports, + drawn, given to the MCP server, and gone with its reports */ +static void test_probe_site(void) { + static const struct { + const char *driver, *raw, *system, *commit, *day, *result; + int id; + u64 poster; + } machines[] = { + {"radv, Mesa 26.1.0", "06801000", "'Some Linux' (Linux 6.1)", "aaaa111", "2026-11-01", "fail", 3, 980}, + {"radv, Mesa 26.1.8", "06801008", "'Some Linux' (Linux 6.1)", "aaaa111", "2026-11-01", "fail", 3, 981}, + {"radv, Mesa 26.1.8", "06801008", "'Some Linux' (Linux 6.1)", "bbbb222", "2026-11-02", "fail", 3, 980}, + {"radv, Mesa 26.2.0", "06802000", "'Some Linux' (Linux 6.1)", "bbbb222", "2026-11-02", "pass", 3, 982}, + {"NVIDIA, 621.14", "9b404000", "Windows 11 26H2", "aaaa111", "2026-11-01", "pass", 4, 983}, + {"NVIDIA, 621.14", "9b404000", "Windows 11 26H2", "bbbb222", "2026-11-02", "pass", 4, 984}, + {"Intel open-source Mesa driver, Mesa 25.3.5", "06403005", "'Some Linux' (Linux 6.1)", "bbbb222", "2026-11-03", + "pass", 6, 985}, + }; + static char logs[7][1200]; + char *p, *t, *rel, key[17], url[80]; + long ids[7]; + Mcp mcp; + size_t i; + probe_case_key("astc", "a 4x4 block decodes", key); + mcp.root = site; + mcp.url = "https://reports.example"; + /* the runs so far: the matrix, a case, a driver, the report's own page and JSON */ + p = page("probe/index.html"); + HAS(p, "

        Runs of edenprobe

        "); + HAS(p, "ScarletNX
        radv 26.1.8
        Linux"); + HAS(p, "Eden
        nvidia 580.95.05*
        Windows"); + rel = rei_format("a 4x4 block decodes", key); + HAS(p, rel); + free(rel); + LACKS(p, "data-family=\"service\""); /* the account case is in no failing row: it passed */ + free(p); + rel = rei_format("probe/c/%s.html", key); + p = page(rel); + HAS(p, "

        a 4x4 block decodes

        "); + HAS(p, "

        By machine

        "); + HAS(p, "texel 0 reads 00ff00ff, it holds ff0000ff"); + free(p); + free(rel); + p = page("probe/d/radv.html"); + HAS(p, "

        RADV

        "); + HAS(p, "radv · VkDriverId 3"); + free(p); + p = page("probe/candidates.html"); + HAS(p, "

        Ban candidates 0

        "); + free(p); + { + long id = st_by_message(tracer.store, 9600); + rel = rei_format("r/%ld/index.html", id); + p = page(rel); + HAS(p, "

        edenprobe 3 passed, 2 failed (astc 1, newsuite 1), 0 skipped, 1 crashed

        "); + HAS(p, "Probe / edenprobe 0.9.0 on ScarletNX

        "); + HAS(p, "

        Failed: 2

        "); + HAS(p, "crashed: the program ended inside it"); + LACKS(p, "nickname Someone"); + free(p); + free(rel); + rel = rei_format("api/r/%ld.json", id); + p = page(rel); + HAS(p, "\"probe\":{"); + HAS(p, "\"not_passed\":["); + LACKS(p, "Someone"); /* the JSON names no player either */ + free(p); + free(rel); + } + /* a ban candidate from whole reports: radv fails it from 26.1.0 for two people and passes on 26.2.0, and NVIDIA + and ANV pass it */ + for (i = 0; i < sizeof machines / sizeof *machines; ++i) { + char *log = machine_log(machines[i].driver, machines[i].id, machines[i].raw, machines[i].system, + machines[i].commit, machines[i].day, machines[i].result), + name[32]; + TrMessage m; + snprintf(logs[i], sizeof logs[i], "%s", log); + free(log); + snprintf(url, sizeof url, "https://cdn.discordapp.com/30/%zu.log", i); + serve(rei_strdup(url), logs[i], strlen(logs[i])); + m = message(9800 + (u64)i, machines[i].poster, "<@99>"); + snprintf(name, sizeof name, "run%zu.log", i); + attach(&m, name, url, 10); + t = answer_text(respond(&m)); + HAS(t, "edenprobe 0.9.0 on"); + free(t); + tr_message_free(&m); + ids[i] = st_by_message(tracer.store, 9800 + (u64)i); + CHECK(ids[i] > 0); + } + p = page("probe/candidates.html"); + HAS(p, "

        Ban candidates 1

        "); + rel = + rei_format("<key> | off | radv | >= 26.1.0 < 26.2.0 | linux | * | fails edenprobe's astc case " + ""a 4x4 block decodes" | Tracer #%ld, #%ld, #%ld; edenprobe 0.9.0 "a 4x4 block " + "decodes" | edenprobe:astc: a 4x4 block decodes | ", + ids[0], ids[1], ids[2]); + HAS(p, rel); + free(rel); + HAS(p, "3 reports from 2 people"); + HAS(p, "3 reports of 2 other drivers"); + free(p); + p = page("probe/d/radv.html"); + HAS(p, "

        Ban candidates

        "); + free(p); + p = page("api/probe/candidates.json"); + HAS(p, "\"versions\":\">= 26.1.0 < 26.2.0\""); + free(p); + /* the MCP server's tools over it */ + t = call(&mcp, "ban_candidates", "{\"driver\":\"radv\"}"); + HAS(t, ">= 26.1.0 < 26.2.0"); + HAS(t, "probe/candidates.html"); + free(t); + t = call(&mcp, "ban_candidates", "{\"driver\":\"nvidia\",\"kind\":\"candidates\"}"); + LACKS(t, "26.1.0"); + LACKS(t, "regressions"); + free(t); + t = call(&mcp, "ban_candidates", "{\"kind\":\"bans\"}"); + HAS(t, "kind=bans is none of candidates, general, regressions"); + HAS(t, "\"isError\":true"); + free(t); + t = call(&mcp, "probe_matrix", "{\"driver\":\"radv\",\"query\":\"4x4\"}"); + HAS(t, "\\\"name\\\":\\\"a 4x4 block decodes\\\""); + HAS(t, "\\\"driver\\\":\\\"radv\\\""); + LACKS(t, "\\\"driver\\\":\\\"nvidia\\\""); + free(t); + t = call(&mcp, "probe_matrix", "{\"suite\":\"clear\"}"); /* it passes everywhere: none failing */ + HAS(t, "\\\"matched\\\":0"); + free(t); + t = call(&mcp, "probe_matrix", "{\"suite\":\"clear\",\"failing\":false}"); + HAS(t, "\\\"matched\\\":1"); + free(t); + t = call(&mcp, "probe_case", "{\"query\":\"4x4 block\"}"); + HAS(t, "\\\"family\\\":\\\"graphics\\\""); + HAS(t, "texel 0 reads 0000ffff"); + free(t); + rel = rei_format("{\"case\":\"%s\"}", key); + t = call(&mcp, "probe_case", rel); + HAS(t, "\\\"name\\\":\\\"a 4x4 block decodes\\\""); + free(t); + free(rel); + t = call(&mcp, "probe_case", "{\"case\":\"../../etc/passwd\"}"); + HAS(t, "is not a case's key"); + free(t); + t = call(&mcp, "probe_case", "{\"query\":\"a\"}"); /* several: the list */ + HAS(t, "\\\"matched\\\":"); + free(t); + t = call(&mcp, "probe_case", "{\"query\":\"nonesuch\"}"); + HAS(t, "no case's suite or name holds nonesuch"); + free(t); + /* gone with their reports: the candidate, and a case no run names any more loses its page */ + for (i = 0; i < sizeof machines / sizeof *machines; ++i) CHECK(tr_forget(&tracer, 9800 + (u64)i)); + p = page("probe/candidates.html"); + HAS(p, "

        Ban candidates 0

        "); + free(p); + { + long left[] = {st_by_message(tracer.store, 9600), st_by_message(tracer.store, 9602), + st_by_message(tracer.store, 9603), st_by_message(tracer.store, 9606)}; + char* path; + for (i = 0; i < sizeof left / sizeof *left; ++i) CHECK(st_remove(tracer.store, left[i]) == 0); + CHECK(!site_probe(tracer.store, site)); + rel = rei_format("probe/c/%s.html", key); + path = at(rel); + CHECK(!exists(path)); /* no run names the case now */ + free(path); + free(rel); + } +} + /* a report kept before Tracer knew runs of edenprobe: the next start makes it the run's, its log cut */ static void test_probe_rescan(void) { StReport r; @@ -3743,6 +3932,7 @@ int main(int argc, char** argv) { test_age(); test_archive_download(); test_probe_reports(); + test_probe_site(); test_probe_rescan(); } st_close(tracer.store); From f35edbfcf517ada6f48c757d09e857e06b034ba9 Mon Sep 17 00:00:00 2001 From: AO55 Date: Sun, 8 Nov 2026 00:17:59 -0300 Subject: [PATCH 4/4] [tracer] Measure what the runs of edenprobe cost: make bench tests/bench_probe keeps a thousand runs of 1069 cases on fifteen machines in a new database and says, at each mark, the database's size, the Probe pages' and the time the rules and the pages take, so the cost where Tracer runs is a number to read again rather than a guess. make test builds it. Signed-off-by: AO55 --- docs/TESTING.md | 6 + tracer/.gitignore | 1 + tracer/Makefile | 17 ++- tracer/tests/bench_probe.c | 228 +++++++++++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 tracer/tests/bench_probe.c diff --git a/docs/TESTING.md b/docs/TESTING.md index bc6aae0..ee2e2d7 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -100,6 +100,12 @@ temporary folder: threshold one off, a comparison that lets one more in, a condition left out: 19 mutants) and expects `test_tracer --rules` to fail on each; a mutant it passes, or one whose text `rules.c` no longer has, fails it. About 10 s. +`make -C tracer bench [RUNS=1000] [FOLDER=/tmp/tracer-bench]` (`tracer/tests/bench_probe.c`, built by `make test`, +run by hand) keeps RUNS runs like edenprobe 0.9.0's graphics run (1069 cases) on fifteen machines in a new database in +FOLDER and, at 1, 10, 100, 250, 500, 1000 runs and on, says the database's size, the Probe pages' and their JSON's, and +the time the rules and every Probe page take, in the processor's seconds and, in brackets, the clock's (which a busy +disk lengthens): what the runs cost where Tracer runs. + ## The docs `scripts/check-docs.py` holds `README.md` and `docs/` to the checkout, each failure a line naming its file and line: diff --git a/tracer/.gitignore b/tracer/.gitignore index 6ad7653..96f2c23 100644 --- a/tracer/.gitignore +++ b/tracer/.gitignore @@ -1,4 +1,5 @@ *.o /tracer /tests/test_tracer +/tests/bench_probe /tracer-mcp diff --git a/tracer/Makefile b/tracer/Makefile index f838c74..350ba41 100644 --- a/tracer/Makefile +++ b/tracer/Makefile @@ -4,6 +4,9 @@ # make [CONCORD=prefix] tracer, linked with Concord v3.0.1 as make install PREFIX=prefix put it, libcurl, SQLite # and libarchive; and tracer-mcp, its MCP server, with libmicrohttpd # make test the tests: no Discord, no network, no Concord, no libcurl +# make bench [RUNS=1000] [FOLDER=/tmp/tracer-bench] +# what RUNS runs of edenprobe cost: the database's size, the Probe pages', and the time they +# take (tests/bench_probe.c); FOLDER must not be there # make test-gateway tracer (CONCORD as above) against a fake Discord whose gateway dies under it: Linux, as # root or with user namespaces (../rei/tests/test_gateway.sh) # @@ -44,9 +47,15 @@ tracer: $(LOGIC) src/rei_http.o src/rei_rest.o src/rei_watch.o src/fetch.o src/m tracer-mcp: src/mcp.o src/mcp_main.o src/rei_util.o third_party/cjson.o $(CC) $(CFLAGS) -o $@ src/mcp.o src/mcp_main.o src/rei_util.o third_party/cjson.o $(MHD_LIBS) -lm -test: tests/test_tracer +RUNS ?= 1000 +FOLDER ?= /tmp/tracer-bench + +test: tests/test_tracer tests/bench_probe ./tests/test_tracer +bench: tests/bench_probe + ./tests/bench_probe $(RUNS) $(FOLDER) + test-gateway: tracer sh $(REI)/tests/test_gateway.sh tracer ./tracer sh $(REI)/tests/test_gateway.sh tracer-all ./tracer @@ -55,6 +64,8 @@ test-gateway: tracer tests/test_tracer: $(LOGIC) tests/test_tracer.c $(CC) $(CFLAGS) $(OURS) $(SQLITE_CFLAGS) -o $@ tests/test_tracer.c $(LOGIC) $(LIBS) +tests/bench_probe: $(LOGIC) tests/bench_probe.c + $(CC) $(CFLAGS) $(OURS) $(SQLITE_CFLAGS) -o $@ tests/bench_probe.c $(LOGIC) $(LIBS) src/message.o: src/message.c src/message.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/message.c @@ -109,6 +120,6 @@ third_party/demangle.o: third_party/logscan/common/utilities/demangle.c clean: rm -f $(LOGIC) src/rei_http.o src/rei_rest.o src/rei_watch.o src/fetch.o src/main.o src/mcp_main.o tracer tracer-mcp \ - tests/test_tracer + tests/test_tracer tests/bench_probe -.PHONY: all test test-gateway clean +.PHONY: all test bench test-gateway clean diff --git a/tracer/tests/bench_probe.c b/tracer/tests/bench_probe.c new file mode 100644 index 0000000..ed53d8b --- /dev/null +++ b/tracer/tests/bench_probe.c @@ -0,0 +1,228 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + Copyright 2026 the ScarletNX contributors */ +/* What the runs of edenprobe cost where Tracer runs: RUNS runs of a run like edenprobe 0.9.0's graphics run (1069 + cases, a few with a detail) on fifteen machines (ScarletNX on twelve drivers and systems, Eden on two, the console), + each machine failing cases of its own and a few that come and go, kept in a new database in FOLDER; at 1, 10, 100, + 250, 500, 1000, 2000... runs it says the database's size, the Probe pages' and their JSON's, the time the rules take + and the time every Probe page takes, as a new run makes them drawn again: the processor's seconds, and in brackets + the clock's, which a busy disk lengthens. No log is written: a run's log costs what + its file weighs (Tracer keeps it as it came, less what it cuts). + + make bench [RUNS=1000] [FOLDER=/tmp/tracer-bench] or tests/bench_probe RUNS FOLDER + + FOLDER must not be there; it is left for a look, and removed by hand */ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include +#include +#include +#include +#include + +#include "probe.h" +#include "rules.h" +#include "site.h" +#include "store.h" + +static double clock_s(void) { + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + return (double)t.tv_sec + (double)t.tv_nsec / 1e9; +} +/* the processor's seconds this program has taken, its own and the system's for it */ +static double cpu_s(void) { + struct rusage u; + getrusage(RUSAGE_SELF, &u); + return (double)u.ru_utime.tv_sec + (double)u.ru_utime.tv_usec / 1e6 + (double)u.ru_stime.tv_sec + + (double)u.ru_stime.tv_usec / 1e6; +} +static double day0(void) { return 1793491200.0 + 86400.0 * 5; } /* the reports' clock: 2026-11-06 */ +/* the bytes and the files under path */ +static long long weigh(const char* path, long* files) { + struct stat st; + long long n = 0; + DIR* d; + struct dirent* e; + if (lstat(path, &st)) return 0; + if (!S_ISDIR(st.st_mode)) { + ++*files; + return (long long)st.st_size; + } + d = opendir(path); + while (d && (e = readdir(d))) { + char* sub; + if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) continue; + sub = rei_format("%s/%s", path, e->d_name); + n += weigh(sub, files); + free(sub); + } + if (d) closedir(d); + return n; +} +static unsigned long g_bench = 12345; /* the pseudo-random state: the same runs every time */ +static unsigned long next(void) { + g_bench = g_bench * 6364136223846793005UL + 1442695040888963407UL; + return g_bench >> 33; +} + +/* the machines, as a run names them */ +static const struct { + const char *emulator, *os, *name, *info; + int id; + unsigned long version; + int own; /* the cases that fail on it alone, of 1069 */ +} MACHINES[] = { + {"ScarletNX", "linux", "radv", "Mesa 26.1.8", 3, (26UL << 22) | (1UL << 12) | 8, 5}, + {"ScarletNX", "linux", "radv", "Mesa 26.2.6", 3, (26UL << 22) | (2UL << 12) | 6, 3}, + {"ScarletNX", "linux", "radv", "Mesa 25.3.5", 3, (25UL << 22) | (3UL << 12) | 5, 8}, + {"ScarletNX", "windows", "NVIDIA", "621.14", 4, 0x9b404000UL, 12}, + {"ScarletNX", "windows", "NVIDIA", "580.95", 4, 0x9117c000UL, 15}, + {"ScarletNX", "linux", "NVIDIA", "580.95.05", 4, 0x9117c140UL, 14}, + {"ScarletNX", "android", "Mali-G52", "v1.r48p0", 9, 48UL << 22, 40}, + {"ScarletNX", "android", "Qualcomm", "512.800.48", 8, (512UL << 22) | (800UL << 12) | 48, 30}, + {"ScarletNX", "android", "turnip", "Mesa 26.1.0", 18, (26UL << 22) | (1UL << 12), 20}, + {"ScarletNX", "linux", "Intel open-source Mesa driver", "Mesa 25.3.5", 6, (25UL << 22) | (3UL << 12) | 5, 10}, + {"ScarletNX", "android", "Samsung Xclipse", "2.0.3", 21, (2UL << 22) | 3, 25}, + {"ScarletNX", "windows", "AMD proprietary driver", "2.0.302", 1, (2UL << 22) | 302, 18}, + {"Eden", "unknown", "radv", "26.1.8", 3, (26UL << 22) | (1UL << 12) | 8, 6}, + {"Eden", "unknown", "NVIDIA", "580.95.5.0", 4, 0x9117c140UL, 9}, + {"console", "unknown", NULL, NULL, 0, 0, 0}, +}; + +/* a run like edenprobe 0.9.0's quick graphics run: 1069 cases over its judge, cpu and graphics suites */ +static void base_run(Probe* p) { + static const char* const suites[] = {"selfcheck", "support", "reference", "cpu", "clear", "format", + "raster", "intmath", "blend", "depth", "texture", "coherence", + "fmath", "order", "index", "astc", "etc2", "bcn", + "zeta", "swizzle", "query", "tex8k", "dma", "blit2d"}; + int i; + memset(p, 0, sizeof *p); + p->version = rei_strdup("0.9.0"); + p->describe = rei_strdup("v0.9.0"); + p->words = rei_strdup("graphics"); + p->system = rei_strdup("'Some Linux' (Linux 6.18), Some CPU, 12 threads, 32 GB RAM"); + p->gpu = rei_strdup("Some GPU"); + p->vulkan = rei_strdup("1.4.354"); + p->emulator_version = rei_strdup("main aaaa111"); + p->passed = 1069; + p->failed = p->skipped = p->crashed = 0; + p->whole = 1; + p->ncases = 1069; + p->cases = calloc((size_t)p->ncases, sizeof *p->cases); + if (!p->cases) abort(); + for (i = 0; i < p->ncases; ++i) { + const char* suite = suites[i % (int)(sizeof suites / sizeof *suites)]; + p->cases[i].suite = rei_strdup(suite); + p->cases[i].name = rei_format("case %d of the %s suite, drawn and read back at sixteen texels", i, suite); + p->cases[i].tier = rei_strdup("exact"); + p->cases[i].result = rei_strdup("pass"); + p->cases[i].reason = rei_strdup(""); + p->cases[i].detail = rei_strdup(i % 18 ? "" : "the blit 505 us; the processor's reads 153 us"); + p->cases[i].us = i % 3 ? -1 : 120.0 + i; + } +} + +int main(int argc, char** argv) { + int runs = argc > 1 ? atoi(argv[1]) : 1000, i, k, nm = (int)(sizeof MACHINES / sizeof *MACHINES), mark = 1; + const char* root = argc > 2 ? argv[2] : "/tmp/tracer-bench"; + char *path, fail[] = "fail", pass[] = "pass", detail[] = "texel 0 reads 0000ffff, it holds ffff0000"; + Probe base; + Store* s; + if (runs < 1 || access(root, F_OK) == 0) { + fprintf(stderr, "usage: %s RUNS FOLDER, RUNS 1 or more and FOLDER not there (%s is)\n", argv[0], root); + return 2; + } + rei_now = day0; + mkdir(root, 0755); + path = rei_format("%s/tracer.db", root); + if (!(s = st_open(path))) return 1; + base_run(&base); + printf("%d runs of %d cases on %d machines, in %s\n", runs, base.ncases, nm, root); + for (i = 1; i <= runs; ++i) { + int m = (int)(next() % (unsigned long)nm); + Probe p = base; + ProbeCase* cases = malloc((size_t)base.ncases * sizeof *cases); + StReport r; + char digest[17]; + double kept, kept_cpu; + if (!cases) abort(); + memcpy(cases, base.cases, (size_t)base.ncases * sizeof *cases); + p.cases = cases; + p.emulator = (char*)MACHINES[m].emulator; + p.os = (char*)MACHINES[m].os; + p.driver_name = (char*)MACHINES[m].name; + p.driver_info = (char*)MACHINES[m].info; + p.driver_id = MACHINES[m].id; + p.inferred = strcmp(MACHINES[m].emulator, "ScarletNX") != 0; + p.driver_version = MACHINES[m].version; + p.commit = (char*)(i % 3 ? "aaaa111" : "bbbb222"); + p.built = 1793491200.0 + 86400.0 * (i % 5); + for (k = 0; k < MACHINES[m].own; ++k) { /* the machine's own failures */ + ProbeCase* c = &cases[(m * 7919 + k * 104729) % base.ncases]; + c->result = fail; + c->detail = detail; + } + if (next() % 4 == 0) cases[next() % (unsigned long)base.ncases].result = fail; /* one that comes and goes */ + if (next() % 9 == 0) cases[next() % (unsigned long)base.ncases].result = pass; + memset(&r, 0, sizeof r); + r.key = PROBE_KEY; + r.title = "edenprobe 0.9.0"; + r.named = 1; + r.when = day0() - (runs - i) * 600.0; + r.message = 1000000 + (u64)i; + r.poster = 1 + next() % 300; + probe_digest(&p, digest); + kept = clock_s(); + kept_cpu = cpu_s(); + if (st_add(s, &r, NULL, 0) || st_probe_set(s, r.id, &p, digest)) { + fprintf(stderr, "run %d was not kept\n", i); + return 1; + } + kept = clock_s() - kept; + kept_cpu = cpu_s() - kept_cpu; + free(cases); + if (i == mark || i == runs) { /* a mark: 1, 10, 100, 250, 500, 1000, 2000... */ + double rules_s = clock_s(), rules_cpu = cpu_s(), pages_s, pages_cpu; + StProbeRun* all; + StProbeResult* results; + int nall, nresults; + Rules rules; + long db_files = 0, page_files = 0, api_files = 0; + long long db, pages, api; + char *pages_path = rei_format("%s/probe", root), *api_path = rei_format("%s/api/probe", root); + st_probe_runs(s, &all, &nall); + st_probe_results(s, &results, &nresults); + rules_make(all, nall, results, nresults, &rules); + rules_s = clock_s() - rules_s; + rules_cpu = cpu_s() - rules_cpu; + pages_s = clock_s(); + pages_cpu = cpu_s(); + site_probe(s, root); + pages_s = clock_s() - pages_s; + pages_cpu = cpu_s() - pages_cpu; + st_close(s); /* the database's write-ahead log folded in, then weighed */ + db = weigh(path, &db_files); + s = st_open(path); + pages = weigh(pages_path, &page_files); + api = weigh(api_path, &api_files); + printf("%5d runs: database %6.1f MB (%4.1f KB a run); probe/ %5.1f MB in %ld files, api/probe/ %5.1f MB; " + "the rules %.2f s [%.2f s] (%d candidates, %d own failures); every Probe page %.2f s [%.2f s]; the " + "last run kept in %.0f ms [%.0f ms]\n", + i, db / 1048576.0, db / 1024.0 / i, pages / 1048576.0, page_files, api / 1048576.0, rules_cpu, + rules_s, rules.ncandidates, rules.ngeneral, pages_cpu, pages_s, kept_cpu * 1000, kept * 1000); + fflush(stdout); + rules_free(&rules); + free(results); + st_probe_runs_free(all, nall); + free(pages_path); + free(api_path); + mark = mark == 1 ? 10 : mark == 10 ? 100 : mark == 100 ? 250 : mark == 250 ? 500 : mark * 2; + } + } + st_close(s); + probe_free(&base); + free(path); + return 0; +}
    \n" "\"\"" "Tracer\n\n