From a85af1d78f92723373b8d3687a68d91dde2ec63d Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Tue, 3 Jun 2025 16:13:16 +0200 Subject: [PATCH] Sort links to get consistent and repeateable output When you run sudo nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml multiple times, you get small differences between each run, but only because the output of links is not sorted. Sorting the links solve the problem of reproducibility among runs. Signed-off-by: Agustin Henze --- internal/discover/symlinks.go | 4 ++++ internal/discover/symlinks_test.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/discover/symlinks.go b/internal/discover/symlinks.go index a9cd811a..36310c56 100644 --- a/internal/discover/symlinks.go +++ b/internal/discover/symlinks.go @@ -19,6 +19,7 @@ package discover import ( "fmt" "path/filepath" + "sort" ) type additionalSymlinks struct { @@ -73,6 +74,9 @@ func (d *additionalSymlinks) Hooks() ([]Hook, error) { return hooks, nil } + // Sort the links to ensure consistent output + sort.Strings(links) + createSymlinkHooks, err := d.hookCreator.Create("create-symlinks", links...).Hooks() if err != nil { return nil, fmt.Errorf("failed to create symlink hook: %v", err) diff --git a/internal/discover/symlinks_test.go b/internal/discover/symlinks_test.go index 52d4a04b..d6b60a63 100644 --- a/internal/discover/symlinks_test.go +++ b/internal/discover/symlinks_test.go @@ -301,8 +301,8 @@ func TestWithWithDriverDotSoSymlinks(t *testing.T) { Path: "/path/to/nvidia-cdi-hook", Args: []string{ "nvidia-cdi-hook", "create-symlinks", - "--link", "libcuda.so.1::/usr/lib/libcuda.so", "--link", "libGLX_nvidia.so.1.2.3::/usr/lib/libGLX_indirect.so.0", + "--link", "libcuda.so.1::/usr/lib/libcuda.so", "--link", "libnvidia-opticalflow.so.1::/usr/lib/libnvidia-opticalflow.so", }, Env: []string{"NVIDIA_CTK_DEBUG=false"},