Skip to content

Commit 6b5d470

Browse files
committed
[no-relnote] Add failing libcuda locate test
Signed-off-by: Evan Lezar <[email protected]>
1 parent 3fe19b8 commit 6b5d470

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package lookup
2+
3+
import (
4+
"path/filepath"
5+
"testing"
6+
7+
testlog "github.com/sirupsen/logrus/hooks/test"
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/NVIDIA/nvidia-container-toolkit/internal/test"
11+
)
12+
13+
func TestLDCacheLookup(t *testing.T) {
14+
logger, _ := testlog.NewNullLogger()
15+
16+
moduleRoot, err := test.GetModuleRoot()
17+
require.NoError(t, err)
18+
19+
testCases := []struct {
20+
rootFs string
21+
inputs []string
22+
expected string
23+
expectedError error
24+
}{
25+
{
26+
rootFs: "rootfs-empty",
27+
inputs: []string{"libcuda.so.1", "libcuda.so.*", "libcuda.so.*.*", "libcuda.so.999.88.77"},
28+
expectedError: ErrNotFound,
29+
},
30+
{
31+
rootFs: "rootfs-1",
32+
inputs: []string{"libcuda.so.1", "libcuda.so.*", "libcuda.so.*.*", "libcuda.so.999.88.77"},
33+
expected: "/lib/x86_64-linux-gnu/libcuda.so.999.88.77",
34+
},
35+
{
36+
rootFs: "rootfs-2",
37+
inputs: []string{"libcuda.so.1", "libcuda.so.*", "libcuda.so.*.*", "libcuda.so.999.88.77"},
38+
expected: "/var/lib/nvidia/lib64/libcuda.so.999.88.77",
39+
},
40+
}
41+
42+
for _, tc := range testCases {
43+
for _, input := range tc.inputs {
44+
t.Run(tc.rootFs+input, func(t *testing.T) {
45+
rootfs := filepath.Join(moduleRoot, "testdata", "lookup", tc.rootFs)
46+
l := newLdcacheLocator(
47+
WithLogger(logger),
48+
WithRoot(rootfs),
49+
)
50+
51+
candidates, err := l.Locate(input)
52+
require.ErrorIs(t, err, tc.expectedError)
53+
if tc.expectedError == nil {
54+
require.Equal(t, []string{filepath.Join(rootfs, tc.expected)}, candidates)
55+
}
56+
})
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)