diff --git a/internal/lookup/root/cuda_test.go b/internal/lookup/root/cuda_test.go index 7584a7233..80a24bdc8 100644 --- a/internal/lookup/root/cuda_test.go +++ b/internal/lookup/root/cuda_test.go @@ -33,10 +33,11 @@ func TestLocate(t *testing.T) { logger, _ := testlog.NewNullLogger() testCases := []struct { - description string - libPaths []string - expected []string - expectedError error + description string + libPaths []string + driverRootSuffix string + expected []string + expectedError error }{ { description: "no libcuda does not resolve library", @@ -68,6 +69,13 @@ func TestLocate(t *testing.T) { }, expectedError: nil, }, + { + description: "driver root with a trailing slash returns absolute directories", + libPaths: []string{"/usr/lib64/libcuda.so.123.34"}, + driverRootSuffix: "/", + expected: []string{"/usr/lib64"}, + expectedError: nil, + }, } for _, tc := range testCases { @@ -77,7 +85,7 @@ func TestLocate(t *testing.T) { l := New( WithLogger(logger), - WithDriverRoot(driverRoot), + WithDriverRoot(driverRoot+tc.driverRootSuffix), ) driverLibraryPaths, err := l.GetDriverLibDirectories() diff --git a/internal/lookup/root/root.go b/internal/lookup/root/root.go index 2866e1d52..ef7a25d21 100644 --- a/internal/lookup/root/root.go +++ b/internal/lookup/root/root.go @@ -57,6 +57,11 @@ func New(opts ...Option) *Driver { if o.logger == nil { o.logger = logger.New() } + // A root such as /run/nvidia/driver/ would otherwise leave relative paths + // when the root is trimmed from located paths. + if o.Root != "" { + o.Root = filepath.Clean(o.Root) + } if o.DevRoot == "" { o.DevRoot = o.Root }