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 <tin@aayy.com.ar>
This commit is contained in:
Agustin Henze 2025-06-03 16:13:16 +02:00
parent 890db82b46
commit a85af1d78f
2 changed files with 5 additions and 1 deletions

View File

@ -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)

View File

@ -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"},