Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit test to replicate error nvidia device rename #334

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 29 additions & 2 deletions internal/system/nvdevices/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,26 @@ func TestCreateControlDevices(t *testing.T) {
},
}

// nvidiaDevices550 represents the device map from the nvidia gpu drivers >= 550.40.x
nvidiaDevices550 := &devices.DevicesMock{
GetFunc: func(name devices.Name) (devices.Major, bool) {
devices := map[devices.Name]devices.Major{
"nvidia": 195,
"nvidia-uvm": 243,
}
d, ok := devices[name]
return d, ok
},
}

mknodeError := errors.New("mknode error")

testCases := []struct {
description string
root string
devices devices.Devices
mknodeError error
hasError bool
expectedError error
expectedCalls []struct {
S string
Expand All @@ -58,6 +71,7 @@ func TestCreateControlDevices(t *testing.T) {
root: "",
devices: nvidiaDevices,
mknodeError: nil,
hasError: false,
expectedCalls: []struct {
S string
N1 int
Expand All @@ -73,6 +87,7 @@ func TestCreateControlDevices(t *testing.T) {
description: "some root specified",
root: "/some/root",
devices: nvidiaDevices,
hasError: false,
mknodeError: nil,
expectedCalls: []struct {
S string
Expand All @@ -88,6 +103,7 @@ func TestCreateControlDevices(t *testing.T) {
{
description: "mknod error returns error",
devices: nvidiaDevices,
hasError: true,
mknodeError: mknodeError,
expectedError: mknodeError,
// We expect the first call to this to fail, and the rest to be skipped
Expand All @@ -106,8 +122,16 @@ func TestCreateControlDevices(t *testing.T) {
return 0, false
},
},
hasError: true,
expectedError: errInvalidDeviceNode,
},
{
description: "nvidia device renamed from nvidia-frontend to nvidia",
devices: nvidiaDevices550,
hasError: true,
expectedError: errors.New("failed to create device node nvidiactl"),
expectedCalls: nil,
},
}

for _, tc := range testCases {
Expand All @@ -126,9 +150,12 @@ func TestCreateControlDevices(t *testing.T) {
d.mknoder = mknode

err := d.CreateNVIDIAControlDevices()
require.ErrorIs(t, err, tc.expectedError)
if tc.hasError {
require.ErrorContains(t, err, tc.expectedError.Error())
} else {
require.Nil(t, err)
}
require.EqualValues(t, tc.expectedCalls, mknode.MknodeCalls())
})
}

}
Loading