Files
Loki/internal/loki/backend_build_cuda_test.go
T
Loki de6551a153 Rebaptise AJEAN en Loki (fork, lignée conservée)
- module github.com/R0m1k3/Loki, cmd/loki, internal/loki (package loki)
- LOKI_HOME, LOKI_MODEL_DIRS, LOKI_SERVICE, LOKI_DL_CONNS ; /etc/loki ;
  units loki-engine / loki-ui ; binaire et aide CLI
- updateRepo pointe sur R0m1k3/Loki (l'auto-update ne tirera plus les
  binaires AJEAN amont)

Conservé à l'identique : le domaine ajean.link (service de tunnel amont),
les littéraux de migration 0.7.x (migrate_07.go), RELEASE_NOTES.md et
LICENSE (historique et licence de l'amont).

go build/vet/test : verts.
2026-08-14 21:33:15 +00:00

51 lines
1.9 KiB
Go

package loki
import (
"errors"
"path/filepath"
"testing"
)
// Le shim /usr/bin/nvcc d'Ubuntu ne doit JAMAIS l'emporter sur un vrai toolkit :
// CMake déduit la racine du toolkit du chemin de nvcc, et /usr ne contient ni
// cuda_runtime.h ni cudart → « CUDA Toolkit not found » alors que nvcc est là.
func TestFindNvccUnixIgnoreLeShimQuandUnToolkitExiste(t *testing.T) {
if !isFile("/usr/local/cuda/bin/nvcc") {
t.Skip("pas de toolkit /usr/local/cuda sur cette machine")
}
got := findNvccUnix(func(string) (string, error) { return "/usr/bin/nvcc", nil })
if got == "/usr/bin/nvcc" {
t.Error("le shim /usr/bin/nvcc a été préféré au toolkit /usr/local/cuda")
}
}
// Sans toolkit installé, on retombe sur le PATH plutôt que de renoncer à CUDA.
func TestFindNvccUnixRetombeSurLePath(t *testing.T) {
if isFile("/usr/local/cuda/bin/nvcc") {
t.Skip("un toolkit est installé ici : le repli n'est pas exerçable")
}
if got := findNvccUnix(func(string) (string, error) { return "/usr/bin/nvcc", nil }); got != "/usr/bin/nvcc" {
t.Errorf("repli PATH = %q, attendu /usr/bin/nvcc", got)
}
if got := findNvccUnix(func(string) (string, error) { return "", errors.New("absent") }); got != "" {
t.Errorf("aucun nvcc nulle part : %q, attendu \"\"", got)
}
}
// cudaToolkitRoot remonte <root>/bin/nvcc → <root>, et refuse les racines qui
// n'apprennent rien à CMake (/usr, layout inattendu).
func TestCudaToolkitRoot(t *testing.T) {
cases := map[string]string{
"/usr/local/cuda/bin/nvcc": "/usr/local/cuda",
"/usr/local/cuda-12.8/bin/nvcc": "/usr/local/cuda-12.8",
"/usr/bin/nvcc": "", // racine déduite = /usr : inutile
"/opt/nvcc": "", // pas de dossier bin
"": "",
}
for in, want := range cases {
if got := filepath.ToSlash(cudaToolkitRoot(filepath.FromSlash(in))); got != want {
t.Errorf("cudaToolkitRoot(%q) = %q, attendu %q", in, got, want)
}
}
}