test: cover the thermal diagnostics with a fake GPU

test/termico_test.py runs scripts/diagnostica_termica/termico.py and
carico_motore.py without a GPU, a driver or a model. A stand-in for
nvidia-smi (a Python file the test writes, with state files it can change
while the program runs) answers the field queries, the throttling
reasons and the slowdown limits, and small HTTP servers answer like
sd-server for /health, /resources and the job routes.

127 checks, about 80 seconds (--veloce skips the ones that start the
program): temperature bands from the driver limits and the generic ones,
judgments and when they are withheld, trend, CSV reading and writing
including truncated rows, summary and status files, comparing runs, the
exit codes of `stato`, `osserva` read continuously without ever finding
the status file half written, a run interrupted by SIGTERM and by Ctrl+C,
the guided session driven like a person (including a stray Enter during an
automatic phase), engine off, engine that stops in the middle, right and
wrong API key, a GPU that answers intermittently or not at all, and the
API key never appearing in the output or in the files. For
carico_motore.py: Retry-After, 401, a server that is off, absurd values,
and the stop of its own job at the end.

The test never leaves __pycache__ next to the scripts it loads. The file
is added to the .gitignore allowlist and to test/README.md.

During development 42 deliberate faults were put in the two programs (a
wrong threshold, a forgotten throttling bit, an API key not sent, ...) and
the test caught all of them; the script that does this is not part of the
repository.

Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC
This commit is contained in:
Claude 2026-10-14 23:36:05 +02:00
parent 65ccae284f
commit f2a6bd674b
No known key found for this signature in database
3 changed files with 1097 additions and 0 deletions

1
.gitignore vendored
View file

@ -12,6 +12,7 @@ test/*
!test/backend_fit_plan_test.cpp
!test/server_recovery_test.cpp
!test/server_cancel_e2e.py
!test/termico_test.py
!test/fuzz_model_loader.py
tests/
.vscode/

View file

@ -15,6 +15,7 @@ sezione "Sicurezza".
| `backend_fit_plan_test.cpp` | pianificatore multi-GPU dell'auto-fit (`--multi-gpu auto\|on\|off`) con GPU simulate: quale modulo va su quale GPU, quando il modello si divide per blocchi, nessun device riceve più pesi del suo budget, i moduli assegnati dall'utente non si muovono (include `src/core/backend_fit.cpp`, quindi serve la libreria compilata; nessuna GPU né modello) | vedi intestazione del file |
| `server_recovery_test.cpp` | custode del contesto del server (`examples/server/recovery.*`): scala dei profili, discesa su memoria insufficiente, risalita dopo una pausa, ricarica dopo un errore, risposte HTTP 503/400/500 con `Retry-After`, uso da più thread. Annullamento di una generazione in corso: lo stop raggiunge solo il job che lo ha chiesto, un job annullato prima di partire non genera nulla, non costa nessuna ricarica del modello e non conta come errore. Non serve nessun modello: libreria e orologio sono simulati (con ASan/UBSan e TSan) | vedi intestazione del file |
| `server_cancel_e2e.py` | annullamento di un job in corso su un vero `sd-server` (serve un modello qualsiasi, su qualunque backend): job fermato, richiesta ripetuta, job in coda, `?wait=0`, POST senza corpo né `Content-Length` (come `curl -X POST`: risposta subito, non dopo 5 secondi), richiesta sincrona in attesa che poi completa, job già finito, id sconosciuto, `wait` non valido, contatori di `/sdcpp/v1/health` e log senza righe di errore | `python3 test/server_cancel_e2e.py --server build/bin/sd-server --model <modello>` |
| `termico_test.py` | programma di diagnostica termica [`scripts/diagnostica_termica/`](../scripts/diagnostica_termica/README.md) (`termico.py` e `carico_motore.py`) con una GPU finta (un `nvidia-smi` scritto dentro il test) e un motore finto: lettura dei campi e dei motivi di throttling, fasce di temperatura, giudizi, riepilogo e file di stato, confronto fra prove, codici di uscita, interruzione con Ctrl+C e SIGTERM, motore che non risponde, chiave API. Non serve nessuna GPU, driver o modello | `python3 test/termico_test.py` (1-2 minuti; `--veloce` salta le prove che lanciano il programma) |
| `fuzz_model_loader.py` | fuzzing a mutazione del caricamento modelli (safetensors/GGUF) | `python3 test/fuzz_model_loader.py <sd-cli> --seconds 300` |
Per il fuzzing è consigliata una build con AddressSanitizer:

1095
test/termico_test.py Normal file

File diff suppressed because it is too large Load diff