44 "errors"
55 "testing"
66
7+ nvidiaproduct "github.com/leptonai/gpud/pkg/nvidia/product"
78 nvmllib "github.com/leptonai/gpud/pkg/nvidia-query/nvml/lib"
89)
910
@@ -17,3 +18,98 @@ func TestInstanceV2(t *testing.T) {
1718 }
1819 t .Logf ("instance mem cap %+v" , inst .GetMemoryErrorManagementCapabilities ())
1920}
21+
22+ func TestNewNoOpInstance (t * testing.T ) {
23+ inst := NewNoOp ()
24+
25+ if inst .NVMLExists () {
26+ t .Fatalf ("expected NVMLExists to be false" )
27+ }
28+ if inst .Library () != nil {
29+ t .Fatalf ("expected nil library" )
30+ }
31+ if inst .Devices () != nil {
32+ t .Fatalf ("expected nil devices map" )
33+ }
34+ if inst .ProductName () != "" {
35+ t .Fatalf ("expected empty product name" )
36+ }
37+ if inst .Architecture () != "" {
38+ t .Fatalf ("expected empty architecture" )
39+ }
40+ if inst .Brand () != "" {
41+ t .Fatalf ("expected empty brand" )
42+ }
43+ if inst .DriverVersion () != "" {
44+ t .Fatalf ("expected empty driver version" )
45+ }
46+ if inst .DriverMajor () != 0 {
47+ t .Fatalf ("expected driver major 0" )
48+ }
49+ if inst .CUDAVersion () != "" {
50+ t .Fatalf ("expected empty CUDA version" )
51+ }
52+ if inst .FabricManagerSupported () {
53+ t .Fatalf ("expected FabricManagerSupported false" )
54+ }
55+ if inst .FabricStateSupported () {
56+ t .Fatalf ("expected FabricStateSupported false" )
57+ }
58+ if inst .GetMemoryErrorManagementCapabilities () != (nvidiaproduct.MemoryErrorManagementCapabilities {}) {
59+ t .Fatalf ("expected empty memory error management capabilities" )
60+ }
61+ if err := inst .Shutdown (); err != nil {
62+ t .Fatalf ("expected Shutdown to return nil, got %v" , err )
63+ }
64+ if inst .InitError () != nil {
65+ t .Fatalf ("expected InitError nil" )
66+ }
67+ }
68+
69+ func TestNewErroredInstance (t * testing.T ) {
70+ initErr := errors .New ("nvml init failed" )
71+ inst := NewErrored (initErr )
72+
73+ if ! inst .NVMLExists () {
74+ t .Fatalf ("expected NVMLExists to be true" )
75+ }
76+ if inst .Library () != nil {
77+ t .Fatalf ("expected nil library" )
78+ }
79+ if inst .Devices () != nil {
80+ t .Fatalf ("expected nil devices map" )
81+ }
82+ if inst .ProductName () != "" {
83+ t .Fatalf ("expected empty product name" )
84+ }
85+ if inst .Architecture () != "" {
86+ t .Fatalf ("expected empty architecture" )
87+ }
88+ if inst .Brand () != "" {
89+ t .Fatalf ("expected empty brand" )
90+ }
91+ if inst .DriverVersion () != "" {
92+ t .Fatalf ("expected empty driver version" )
93+ }
94+ if inst .DriverMajor () != 0 {
95+ t .Fatalf ("expected driver major 0" )
96+ }
97+ if inst .CUDAVersion () != "" {
98+ t .Fatalf ("expected empty CUDA version" )
99+ }
100+ if inst .FabricManagerSupported () {
101+ t .Fatalf ("expected FabricManagerSupported false" )
102+ }
103+ if inst .FabricStateSupported () {
104+ t .Fatalf ("expected FabricStateSupported false" )
105+ }
106+ if inst .GetMemoryErrorManagementCapabilities () != (nvidiaproduct.MemoryErrorManagementCapabilities {}) {
107+ t .Fatalf ("expected empty memory error management capabilities" )
108+ }
109+ if err := inst .Shutdown (); err != nil {
110+ t .Fatalf ("expected Shutdown to return nil, got %v" , err )
111+ }
112+ if ! errors .Is (inst .InitError (), initErr ) {
113+ t .Fatalf ("expected InitError %v, got %v" , initErr , inst .InitError ())
114+ }
115+ }
0 commit comments