testutils

package
v0.0.0-...-1204702 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MockGPUInstanceInfo1 = deviceinfo.GPUInstanceInfo{
		Info:        dcgm.MigEntityInfo{GpuUuid: "fake", NvmlProfileSlices: 3},
		ProfileName: fakeProfileName,
		EntityId:    0,
	}

	MockGPUInstanceInfo2 = deviceinfo.GPUInstanceInfo{
		Info:        dcgm.MigEntityInfo{GpuUuid: "fake", NvmlInstanceId: 1, NvmlProfileSlices: 3},
		ProfileName: fakeProfileName,
		EntityId:    14,
	}

	MockNVLinkVal1 = dcgm.NvLinkStatus{
		State: 2,
		Index: 0,
	}

	MockNVLinkVal2 = dcgm.NvLinkStatus{
		State: 3,
		Index: 1,
	}
)
View Source
var (
	SampleGPUTempCounter = counters.Counter{
		FieldID:   dcgm.DCGM_FI_DEV_GPU_TEMP,
		FieldName: "DCGM_FI_DEV_GPU_TEMP",
		PromType:  "gauge",
		Help:      "Temperature Help info",
	}

	SampleGPUTotalEnergyCounter = counters.Counter{
		FieldID:   dcgm.DCGM_FI_DEV_TOTAL_ENERGY_CONSUMPTION,
		FieldName: "DCGM_FI_DEV_TOTAL_ENERGY_CONSUMPTION",
		PromType:  "gauge",
		Help:      "Energy help info",
	}

	SampleGPUPowerUsageCounter = counters.Counter{
		FieldID:   dcgm.DCGM_FI_DEV_POWER_USAGE,
		FieldName: "DCGM_FI_DEV_POWER_USAGE",
		PromType:  "gauge",
		Help:      "Power help info",
	}

	SampleVGPULicenseStatusCounter = counters.Counter{
		FieldID:   dcgm.DCGM_FI_DEV_VGPU_LICENSE_STATUS,
		FieldName: "DCGM_FI_DEV_VGPU_LICENSE_STATUS",
		PromType:  "gauge",
		Help:      "vgpu license status",
	}

	SampleDriverVersionCounter = counters.Counter{
		FieldID:   dcgm.DCGM_FI_DRIVER_VERSION,
		FieldName: "DCGM_FI_DRIVER_VERSION",
		PromType:  "label",
		Help:      "Driver version",
	}

	SampleSwitchCurrentTempCounter = counters.Counter{
		FieldID:   dcgm.DCGM_FI_DEV_NVSWITCH_TEMPERATURE_CURRENT,
		FieldName: "DCGM_FI_DEV_NVSWITCH_TEMPERATURE_CURRENT",
		PromType:  "gauge",
		Help:      "switch temperature",
	}

	SampleSwitchLinkFlitErrorsCounter = counters.Counter{
		FieldID:   dcgm.DCGM_FI_DEV_NVSWITCH_LINK_FLIT_ERRORS,
		FieldName: "DCGM_FI_DEV_NVSWITCH_LINK_FLIT_ERRORS",
		PromType:  "gauge",
		Help:      "per-link flit errors",
	}

	SampleCPUUtilTotalCounter = counters.Counter{
		FieldID:   dcgm.DCGM_FI_DEV_CPU_UTIL_TOTAL,
		FieldName: "DCGM_FI_DEV_CPU_UTIL_TOTAL",
		PromType:  "gauge",
		Help:      "Total CPU utilization",
	}

	SampleCounters = []counters.Counter{
		SampleGPUTempCounter,
		SampleGPUTotalEnergyCounter,
		SampleGPUPowerUsageCounter,
		SampleDriverVersionCounter,

		SampleSwitchCurrentTempCounter,
		SampleSwitchLinkFlitErrorsCounter,

		SampleVGPULicenseStatusCounter,

		SampleCPUUtilTotalCounter,
	}

	SampleAllFieldIDs = []dcgm.Short{
		SampleGPUTempCounter.FieldID, SampleGPUTotalEnergyCounter.FieldID,
		SampleGPUPowerUsageCounter.FieldID, SampleVGPULicenseStatusCounter.FieldID,
		SampleDriverVersionCounter.FieldID, SampleSwitchCurrentTempCounter.FieldID,
		SampleSwitchLinkFlitErrorsCounter.FieldID, SampleCPUUtilTotalCounter.FieldID,
	}

	SampleGPUFieldIDs = []dcgm.Short{
		SampleGPUTempCounter.FieldID, SampleGPUTotalEnergyCounter.FieldID,
		SampleGPUPowerUsageCounter.FieldID, SampleVGPULicenseStatusCounter.FieldID,
	}

	SampleFieldIDToFieldMeta = map[dcgm.Short]dcgm.FieldMeta{
		SampleGPUTempCounter.FieldID: {
			FieldId:     SampleGPUTempCounter.FieldID,
			EntityLevel: dcgm.FE_GPU,
		},
		SampleGPUTotalEnergyCounter.FieldID: {
			FieldId:     SampleGPUTotalEnergyCounter.FieldID,
			EntityLevel: dcgm.FE_GPU,
		},
		SampleGPUPowerUsageCounter.FieldID: {
			FieldId:     SampleGPUPowerUsageCounter.FieldID,
			EntityLevel: dcgm.FE_GPU_I,
		},
		SampleVGPULicenseStatusCounter.FieldID: {
			FieldId:     SampleVGPULicenseStatusCounter.FieldID,
			EntityLevel: dcgm.FE_VGPU,
		},
		SampleDriverVersionCounter.FieldID: {
			FieldId:     SampleDriverVersionCounter.FieldID,
			EntityLevel: dcgm.FE_NONE,
		},
		SampleSwitchCurrentTempCounter.FieldID: {
			FieldId:     SampleSwitchCurrentTempCounter.FieldID,
			EntityLevel: dcgm.FE_SWITCH,
		},
		SampleSwitchLinkFlitErrorsCounter.FieldID: {
			FieldId:     SampleSwitchLinkFlitErrorsCounter.FieldID,
			EntityLevel: dcgm.FE_LINK,
		},
		SampleCPUUtilTotalCounter.FieldID: {
			FieldId:     SampleCPUUtilTotalCounter.FieldID,
			EntityLevel: dcgm.FE_CPU_CORE,
		},
	}
)

Functions

func CreateTmpDir

func CreateTmpDir(t *testing.T) (string, func())

func GetFields

func GetFields(input interface{}, fieldType FieldType) map[string]interface{}

GetFields returns a map of fields of a struct, including unexported fields, based on the specified field type.

func GetStructPrivateFieldValue

func GetStructPrivateFieldValue[T any](t *testing.T, v any, fieldName string) T

GetStructPrivateFieldValue returns private field value

func MockCPUDeviceInfo

func MockCPUDeviceInfo(
	ctrl *gomock.Controller, cpuCount int, cpuToCores map[int][]uint, watchedCPUs map[uint]bool,
	watchedCores map[WatchedEntityKey]bool, infoType dcgm.Field_Entity_Group,
) *mockdeviceinfo.MockProvider

func MockGPUDeviceInfo

func MockGPUDeviceInfo(
	ctrl *gomock.Controller, gpuCount int, gpuToGpuInstanceInfos map[int][]deviceinfo.GPUInstanceInfo,
) *mockdeviceinfo.MockProvider

func MockSwitchDeviceInfo

func MockSwitchDeviceInfo(
	ctrl *gomock.Controller, switchCount int, switchToNvLinks map[int][]dcgm.NvLinkStatus,
	watchedSwitches map[uint]bool, watchedLinks map[WatchedEntityKey]bool, infoType dcgm.Field_Entity_Group,
) *mockdeviceinfo.MockProvider

func RequireLinux

func RequireLinux(t *testing.T)

RequireLinux checks if tests are being executed on a Linux platform or not

func StartMockServer

func StartMockServer(t *testing.T, server *grpc.Server, socket string) func()

func StrToByteArray

func StrToByteArray(str string) [4096]byte

Types

type FieldType

type FieldType int
const (
	Fields FieldType = iota
	Functions
	All
)

type MockPodResourcesServer

type MockPodResourcesServer struct {
	// contains filtered or unexported fields
}

func NewMockPodResourcesServer

func NewMockPodResourcesServer(resourceName string, gpus []string) *MockPodResourcesServer

func (*MockPodResourcesServer) List

type MockReader

type MockReader struct {
	Err error
}

MockReader is a mock implementation of rand.Reader that always returns an error

func (*MockReader) Read

func (r *MockReader) Read(_ []byte) (n int, err error)

type WatchedEntityKey

type WatchedEntityKey struct {
	ParentID uint
	ChildID  uint
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL