Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions internal/discover/graphics.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,17 @@ func newVulkanConfigsDiscover(logger logger.Interface, driver *root.Driver) Disc

type graphicsDriverLibraries struct {
Discover
logger logger.Interface
hookCreator HookCreator
logger logger.Interface
hookCreator HookCreator
driverVersion string
}

var _ Discover = (*graphicsDriverLibraries)(nil)

func newGraphicsLibrariesDiscoverer(logger logger.Interface, driver *root.Driver, hookCreator HookCreator) (Discover, error) {
cudaVersionPattern, err := driver.Version()
// We use the driver version as a suffix for matching libraries that are
// part of the driver.
driverVersion, err := driver.Version()
if err != nil {
return nil, fmt.Errorf("failed to get driver version: %w", err)
}
Expand All @@ -143,8 +146,8 @@ func newGraphicsLibrariesDiscoverer(logger logger.Interface, driver *root.Driver
// * libnvidia-allocator.so.RM_VERSION
// * libnvidia-vulkan-producer.so.RM_VERSION
// but need to be handled for the legacy case too.
"libnvidia-allocator.so." + cudaVersionPattern,
"libnvidia-vulkan-producer.so." + cudaVersionPattern,
"libnvidia-allocator.so." + driverVersion,
"libnvidia-vulkan-producer.so." + driverVersion,
},
)

Expand All @@ -159,14 +162,15 @@ func newGraphicsLibrariesDiscoverer(logger logger.Interface, driver *root.Driver
driver.Root,
[]string{
"nvidia_drv.so",
"libglxserver_nvidia.so." + cudaVersionPattern,
"libglxserver_nvidia.so." + driverVersion,
},
)

return &graphicsDriverLibraries{
Discover: Merge(libraries, xorgLibraries),
logger: logger,
hookCreator: hookCreator,
Discover: Merge(libraries, xorgLibraries),
logger: logger,
hookCreator: hookCreator,
driverVersion: driverVersion,
}, nil
}

Expand Down Expand Up @@ -234,10 +238,7 @@ func (d graphicsDriverLibraries) Hooks() ([]Hook, error) {

// isDriverLibrary checks whether the specified filename is a specific driver library.
func (d graphicsDriverLibraries) isDriverLibrary(filename string, libraryName string) bool {
// TODO: Instead of `.*.*` we could use the driver version.
pattern := strings.TrimSuffix(libraryName, ".") + ".*.*"
match, _ := filepath.Match(pattern, filename)
return match
return filename == strings.TrimSuffix(libraryName, ".")+"."+d.driverVersion
}

// buildXOrgSearchPaths returns search paths from all roots
Expand Down
68 changes: 65 additions & 3 deletions internal/discover/graphics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ func TestGraphicsLibrariesDiscoverer(t *testing.T) {
},
},
},
{
description: "libnvidia-allocator not filtered out when version does not equal driver version",
libraries: &DiscoverMock{
MountsFunc: func() ([]Mount, error) {
mounts := []Mount{
{
Path: "/usr/lib64/libnvidia-allocator.so.999.99.99",
},
}
return mounts, nil
},
},
expectedMounts: []Mount{
{
Path: "/usr/lib64/libnvidia-allocator.so.999.99.99",
},
Comment thread
tariq1890 marked this conversation as resolved.
},
expectedHooks: nil,
},
{
description: "libnvidia-allocator and libnvidia-vulkan-producer discovered",
libraries: &DiscoverMock{
Expand Down Expand Up @@ -145,9 +164,10 @@ func TestGraphicsLibrariesDiscoverer(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
d := &graphicsDriverLibraries{
Discover: tc.libraries,
logger: logger,
hookCreator: hookCreator,
Discover: tc.libraries,
logger: logger,
hookCreator: hookCreator,
driverVersion: "123.45.67",
}

devices, err := d.Devices()
Expand Down Expand Up @@ -249,3 +269,45 @@ func TestDrmDevicesByPath(t *testing.T) {
})
}
}

func TestIsDriverLibrary(t *testing.T) {
testCases := []struct {
description string
filename string
libraryName string
driverVersion string
expectedResult bool
}{
{
description: "driver library file matched",
libraryName: "libnvidia-vulkan-producer.so",
filename: "libnvidia-vulkan-producer.so.123.45.67",
driverVersion: "123.45.67",
expectedResult: true,
},
{
description: "driver library file matched with extraneous \".\"",
libraryName: "libnvidia-vulkan-producer.so.",
filename: "libnvidia-vulkan-producer.so.123.45.67",
driverVersion: "123.45.67",
expectedResult: true,
},
{
description: "driver library file not matched due to mismatching driver version",
libraryName: "libnvidia-vulkan-producer.so",
filename: "libnvidia-vulkan-producer.so.123.45.67",
driverVersion: "999.99.99",
expectedResult: false,
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
gdl := graphicsDriverLibraries{
driverVersion: tc.driverVersion,
}
result := gdl.isDriverLibrary(tc.filename, tc.libraryName)
require.Equal(t, tc.expectedResult, result)
})

}
}
Loading