Skip to content

Commit

Permalink
Add mocks for all interfaces under pkg/nvml/testing
Browse files Browse the repository at this point in the history
We should eventually expand this package to include a unified mock server like
we have in the go-nvlib testing and mig-parted testing.

Signed-off-by: Kevin Klues <kklues@nvidia.com>
  • Loading branch information
klueska committed Apr 10, 2024
1 parent 2bfdabf commit ac090b6
Show file tree
Hide file tree
Showing 10 changed files with 24,431 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/nvml/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func SetLibraryOptions(opts ...LibraryOption) error {
}

// Interface represents the interface for the top-level NVML library.
//
//go:generate moq -out testing/nvml_mock.go -pkg testing . Interface
type Interface interface {
// Library API
GetLibrary() Library
Expand Down Expand Up @@ -352,6 +354,7 @@ type Interface interface {
GetVgpuDriverCapabilities(capability VgpuDriverCapability) (bool, Return)
}

//go:generate moq -out testing/device_mock.go -pkg testing . Device
type Device interface {
GetName() (string, Return)
GetBrand() (BrandType, Return)
Expand Down Expand Up @@ -556,6 +559,7 @@ type Device interface {
VgpuTypeGetMaxInstances(vgpuTypeId VgpuTypeId) (int, Return)
}

//go:generate moq -out testing/gpuinstance_mock.go -pkg testing . GpuInstance
type GpuInstance interface {
Destroy() Return
GetInfo() (GpuInstanceInfo, Return)
Expand All @@ -569,22 +573,26 @@ type GpuInstance interface {
CreateComputeInstanceWithPlacement(info *ComputeInstanceProfileInfo, placement *ComputeInstancePlacement) (ComputeInstance, Return)
}

//go:generate moq -out testing/computeinstance_mock.go -pkg testing . ComputeInstance
type ComputeInstance interface {
Destroy() Return
GetInfo() (ComputeInstanceInfo, Return)
}

//go:generate moq -out testing/eventset_mock.go -pkg testing . EventSet
type EventSet interface {
Wait(timeoutms uint32) (EventData, Return)
Free() Return
}

//go:generate moq -out testing/gpmsample_mock.go -pkg testing . GpmSample
type GpmSample interface {
Free() Return
Get(device Device) Return
MigGet(device Device, gpuInstanceId int) Return
}

//go:generate moq -out testing/unit_mock.go -pkg testing . Unit
type Unit interface {
GetUnitInfo() (UnitInfo, Return)
GetLedState() (LedState, Return)
Expand All @@ -595,6 +603,7 @@ type Unit interface {
SetLedState(color LedColor) Return
}

//go:generate moq -out testing/vgpuinstance_mock.go -pkg testing . VgpuInstance
type VgpuInstance interface {
GetVmID() (string, VgpuVmIdType, Return)
GetUUID() (string, Return)
Expand All @@ -621,6 +630,7 @@ type VgpuInstance interface {
GetMdevUUID() (string, Return)
}

//go:generate moq -out testing/vgputypeid_mock.go -pkg testing . VgpuTypeId
type VgpuTypeId interface {
GetClass() (string, Return)
GetName() (string, Return)
Expand Down
105 changes: 105 additions & 0 deletions pkg/nvml/testing/computeinstance_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ac090b6

Please sign in to comment.