Skip to content

Commit 9534249

Browse files
committed
[no-relnote] Add test for libcuda lookup
This change adds a test for locating libcuda as a driver library. This includes a failing test on a system where libcuda.so.1 is in the ldcache, but not at one of the predefined library search paths. A testdata folder with sample root filesystems is included to test various combinations. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent e1ea005 commit 9534249

File tree

13 files changed

+90
-0
lines changed

13 files changed

+90
-0
lines changed

internal/lookup/root/root_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
# Copyright 2023 NVIDIA CORPORATION
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
**/
16+
17+
package root
18+
19+
import (
20+
"path/filepath"
21+
"testing"
22+
23+
testlog "github.com/sirupsen/logrus/hooks/test"
24+
"github.com/stretchr/testify/require"
25+
26+
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
27+
"github.com/NVIDIA/nvidia-container-toolkit/internal/test"
28+
)
29+
30+
func TestDriverLibrariesLocate(t *testing.T) {
31+
logger, _ := testlog.NewNullLogger()
32+
33+
moduleRoot, err := test.GetModuleRoot()
34+
require.NoError(t, err)
35+
36+
testCases := []struct {
37+
rootFs string
38+
inputs []string
39+
expected string
40+
expectedError error
41+
}{
42+
{
43+
rootFs: "rootfs-empty",
44+
inputs: []string{"libcuda.so.1", "libcuda.so.*", "libcuda.so.*.*", "libcuda.so.999.88.77"},
45+
expectedError: lookup.ErrNotFound,
46+
},
47+
{
48+
rootFs: "rootfs-no-cache-lib64",
49+
inputs: []string{"libcuda.so.1", "libcuda.so.*", "libcuda.so.*.*", "libcuda.so.999.88.77"},
50+
expected: "/usr/lib64/libcuda.so.999.88.77",
51+
},
52+
{
53+
rootFs: "rootfs-1",
54+
inputs: []string{"libcuda.so.1", "libcuda.so.*", "libcuda.so.*.*", "libcuda.so.999.88.77"},
55+
expected: "/lib/x86_64-linux-gnu/libcuda.so.999.88.77",
56+
},
57+
{
58+
rootFs: "rootfs-2",
59+
inputs: []string{"libcuda.so.1", "libcuda.so.*", "libcuda.so.*.*", "libcuda.so.999.88.77"},
60+
expected: "/var/lib/nvidia/lib64/libcuda.so.999.88.77",
61+
},
62+
}
63+
64+
for _, tc := range testCases {
65+
for _, input := range tc.inputs {
66+
t.Run(tc.rootFs+input, func(t *testing.T) {
67+
rootfs := filepath.Join(moduleRoot, "testdata", "lookup", tc.rootFs)
68+
driver := New(
69+
WithLogger(logger),
70+
WithDriverRoot(rootfs),
71+
)
72+
73+
candidates, err := driver.Libraries().Locate(input)
74+
require.ErrorIs(t, err, tc.expectedError)
75+
if tc.expectedError == nil {
76+
require.Equal(t, []string{filepath.Join(rootfs, tc.expected)}, candidates)
77+
}
78+
})
79+
}
80+
}
81+
}

testdata/go.mod

Whitespace-only changes.

testdata/lookup/rootfs-1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This rootfs represents a host with the CUDA driver libraries installed in
2+
/lib/x86_64-linux-gnu. The included /etc/ld.so.cache was copied from such as system.
55.9 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libcuda.so.999.88.77

testdata/lookup/rootfs-1/lib/x86_64-linux-gnu/libcuda.so.999.88.77

Whitespace-only changes.

testdata/lookup/rootfs-2/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This rootfs represents a host with the CUDA driver libraries installed in
2+
/var/lib/nvidia/lib64. The included /etc/ld.so.cache was generated in a container
3+
simulating such as system.
42.4 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libcuda.so.999.88.77

testdata/lookup/rootfs-2/var/lib/nvidia/lib64/libcuda.so.999.88.77

Whitespace-only changes.

0 commit comments

Comments
 (0)