stable-diffusion.cpp/test
Claude f2a6bd674b
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
2026-10-14 23:36:05 +02:00
..
api_robustness.cpp feat: report why a call failed and expose system memory 2026-10-11 07:09:28 +02:00
backend_fit_plan_test.cpp test: cover the multi-GPU placement without GPUs 2026-10-14 01:03:42 +02:00
file_handle_pool_test.cpp fix: keep model file handles open between tensor loads 2026-10-11 06:09:49 +02:00
fuzz_model_loader.py implemented stable diffusions regular and specific with margin of limits of CPU/GPU 2026-10-07 19:23:28 +02:00
pe_imports_test.cpp feat: log why a GPU backend module could not be used 2026-10-11 05:52:43 +02:00
profile_test.cpp test: cover the multi-GPU placement without GPUs 2026-10-14 01:03:42 +02:00
README.md test: cover the thermal diagnostics with a fake GPU 2026-10-14 23:36:05 +02:00
security_smoke.sh feat: add --profile to choose a resource footprint 2026-10-11 07:19:14 +02:00
server_cancel_e2e.py test: check that cancel answers a POST without Content-Length at once 2026-10-14 22:15:52 +02:00
server_recovery_test.cpp test: cover stopping a generation that is running 2026-10-14 21:54:02 +02:00
termico_test.py test: cover the thermal diagnostics with a fake GPU 2026-10-14 23:36:05 +02:00

Test di robustezza e sicurezza (fork)

Script locali di questo fork per verificare che il motore fallisca in modo pulito con input ostili, senza crash né errori di memoria. Istruzioni complete in italiano: docs/integrazione_progetti.md, sezione "Sicurezza".

Test Cosa verifica Come si esegue
security_smoke.sh file modello ostili + opzioni CLI estreme → mai crash (exit < 128) ./test/security_smoke.sh build/bin/sd-cli
api_robustness.cpp API C: puntatori nulli, indici fuori range, buffer piccoli, stress multi-thread (con ASan/UBSan) vedi intestazione del file
pe_imports_test.cpp lettore della tabella di importazione dei file PE (diagnostica delle DLL mancanti su Windows): file validi, troncati e corrotti (con ASan/UBSan) vedi intestazione del file
file_handle_pool_test.cpp pool dei flussi aperti sui file modello: riuso, file modificato o sostituito, flussi in errore, limiti, uso concorrente (con ASan/UBSan e TSan) vedi intestazione del file
profile_test.cpp profili di risorse (--profile): scelta automatica da dimensione del modello e memoria (anche sommando la memoria di più GPU), ordine dei livelli, opzioni esplicite che vincono sul profilo vedi intestazione del file
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/ (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:

cmake -B build_asan -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSD_WEBP=OFF -DSD_WEBM=OFF \
      -DCMAKE_C_FLAGS=-fsanitize=address -DCMAKE_CXX_FLAGS=-fsanitize=address \
      -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address
cmake --build build_asan -j --target sd-cli
python3 test/fuzz_model_loader.py build_asan/bin/sd-cli --seconds 600

Gli input che causano una scoperta vengono salvati in test/fuzz_findings/ (da non committare). Questi test riducono il rischio ma non dimostrano l'assenza di vulnerabilità.