diff --git a/pkg/nvcdi/lib-csv.go b/pkg/nvcdi/lib-csv.go index 603fd46bf..90c18b554 100644 --- a/pkg/nvcdi/lib-csv.go +++ b/pkg/nvcdi/lib-csv.go @@ -476,7 +476,7 @@ func (l *csvlib) getEnableCUDACompatHookOptions() (*discover.EnableCUDACompatHoo hostCUDAVersion, err := l.getCUDAVersionString() if err != nil { - return nil, fmt.Errorf("failed to get host CUDA version: %v", ret) + return nil, fmt.Errorf("failed to get host CUDA version: %w", err) } f := &discover.EnableCUDACompatHookOptions{ diff --git a/pkg/nvcdi/lib-csv_test.go b/pkg/nvcdi/lib-csv_test.go index 07a342d92..ff71b407b 100644 --- a/pkg/nvcdi/lib-csv_test.go +++ b/pkg/nvcdi/lib-csv_test.go @@ -405,3 +405,30 @@ func mockIGXServer() nvml.Interface { }, } } + +func TestGetEnableCUDACompatHookOptionsReportsWhyTheVersionFailed(t *testing.T) { + // The message used to interpolate the NVML return of the Init call above it, + // which is always SUCCESS by then, so the real failure was dropped. + nvmllib := &mock.Interface{ + InitFunc: func() nvml.Return { return nvml.SUCCESS }, + ShutdownFunc: func() nvml.Return { return nvml.SUCCESS }, + SystemGetCudaDriverVersionFunc: func() (int, nvml.Return) { + return 0, nvml.ERROR_NOT_SUPPORTED + }, + DeviceGetCountFunc: func() (int, nvml.Return) { return 0, nvml.SUCCESS }, + } + + l := &csvlib{ + platformlibs: platformlibs{ + infolib: &infoInterfaceMock{ + HasNvmlFunc: func() (bool, string) { return true, "forced" }, + }, + nvmllib: nvmllib, + devicelib: device.New(nvmllib), + }, + } + + _, err := l.getEnableCUDACompatHookOptions() + require.ErrorContains(t, err, nvml.ERROR_NOT_SUPPORTED.Error()) + require.NotContains(t, err.Error(), nvml.SUCCESS.Error()) +}