Skip to content

Commit f175aa8

Browse files
committed
test: cover nvml init error paths
1 parent 6ca32de commit f175aa8

21 files changed

Lines changed: 638 additions & 1 deletion

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package clockspeed
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ecc
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package fabricmanager
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package gpm
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package gpucounts
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package hwslowdown
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package infiniband
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
ibtypes "github.com/leptonai/gpud/components/accelerator/nvidia/infiniband/types"
11+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
12+
)
13+
14+
func TestInitErrorUnhealthy(t *testing.T) {
15+
initErr := errors.New("nvml init failed")
16+
comp, err := New(&components.GPUdInstance{
17+
RootCtx: context.Background(),
18+
NVMLInstance: nvidianvml.NewErrored(initErr),
19+
})
20+
if err != nil {
21+
t.Fatalf("failed to create component: %v", err)
22+
}
23+
24+
if !comp.IsSupported() {
25+
t.Fatalf("expected IsSupported true when NVML init error is present")
26+
}
27+
28+
ibComp, ok := comp.(*component)
29+
if !ok {
30+
t.Fatalf("expected infiniband component type, got %T", comp)
31+
}
32+
ibComp.getThresholdsFunc = func() ibtypes.ExpectedPortStates {
33+
return ibtypes.ExpectedPortStates{AtLeastPorts: 1, AtLeastRate: 1}
34+
}
35+
36+
if got := ibComp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
37+
t.Fatalf("expected unhealthy, got %v", got)
38+
}
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package memory
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package nccl
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package nvlink
2+
3+
import (
4+
"context"
5+
"errors"
6+
"testing"
7+
8+
apiv1 "github.com/leptonai/gpud/api/v1"
9+
"github.com/leptonai/gpud/components"
10+
nvidianvml "github.com/leptonai/gpud/pkg/nvidia-query/nvml"
11+
)
12+
13+
func TestInitErrorUnhealthy(t *testing.T) {
14+
initErr := errors.New("nvml init failed")
15+
comp, err := New(&components.GPUdInstance{
16+
RootCtx: context.Background(),
17+
NVMLInstance: nvidianvml.NewErrored(initErr),
18+
})
19+
if err != nil {
20+
t.Fatalf("failed to create component: %v", err)
21+
}
22+
23+
if !comp.IsSupported() {
24+
t.Fatalf("expected IsSupported true when NVML init error is present")
25+
}
26+
27+
if got := comp.Check().HealthStateType(); got != apiv1.HealthStateTypeUnhealthy {
28+
t.Fatalf("expected unhealthy, got %v", got)
29+
}
30+
}

0 commit comments

Comments
 (0)